Menu
Coddy logo textTech

Project Setup

Part of the Logic & Flow section of Coddy's Dart journey — lesson 33 of 65.

challenge icon

Challenge

Easy

You'll be building a simple shopping cart calculator that demonstrates how different data structures work together in a real application.

Create a program that sets up the foundation for a shopping cart calculator system by initializing the essential data structures needed for an e-commerce application. Your program should:

  1. Read a string input representing the store name
  2. Read multiple pairs of inputs representing product names and their prices (the input will end when you receive "products_done")
  3. Create a Map to store available products with their names as keys and prices as values
  4. Create an empty List to represent the shopping cart
  5. Display the initial setup information and verify that the data structures are properly initialized
  6. Print the store setup report in the exact format shown below

For example, if the store name is "Fresh Market" and the products include "Apple" with price 1.50, "Banana" with price 0.80, "Orange" with price 2.00, "Milk" with price 3.25, your program should output:

Store: Fresh Market
Product Catalog Setup:
Available Products: {Apple: 1.5, Banana: 0.8, Orange: 2.0, Milk: 3.25}
Shopping Cart Initialized: []
System Status:
Total products available: 4
Cart status: Empty
Most expensive item: Milk ($3.25)
Cheapest item: Banana ($0.80)
Average product price: $1.84
Setup Status: Shopping cart system ready for customers

If the store name is "Tech Store" and the products include "Laptop" with price 999.99, "Mouse" with price 25.50, "Keyboard" with price 75.00, your program should output:

Store: Tech Store
Product Catalog Setup:
Available Products: {Laptop: 999.99, Mouse: 25.5, Keyboard: 75.0}
Shopping Cart Initialized: []
System Status:
Total products available: 3
Cart status: Empty
Most expensive item: Laptop ($999.99)
Cheapest item: Mouse ($25.50)
Average product price: $366.83
Setup Status: Shopping cart system ready for customers

If the store name is "Book Corner" and the products include "Novel" with price 12.99, "Magazine" with price 4.50, "Textbook" with price 89.00, "Comic" with price 3.99, "Journal" with price 15.75, your program should output:

Store: Book Corner
Product Catalog Setup:
Available Products: {Novel: 12.99, Magazine: 4.5, Textbook: 89.0, Comic: 3.99, Journal: 15.75}
Shopping Cart Initialized: []
System Status:
Total products available: 5
Cart status: Empty
Most expensive item: Textbook ($89.00)
Cheapest item: Comic ($3.99)
Average product price: $25.25
Setup Status: Shopping cart system ready for customers

Your program must create a Map with String keys (product names) and double values (prices), and an empty List of Strings for the shopping cart. Find the most expensive and cheapest items by comparing all prices in the product map. Calculate the average price by dividing the sum of all prices by the number of products. Round the average to 2 decimal places for display. The input format will be: store name, then alternating product names and prices (as strings that need to be converted to doubles), ending with "products_done".

Try it yourself

import 'dart:io';

void main() {
  // Read store name
  String? storeName = stdin.readLineSync();
  
  // Initialize data structures
  Map<String, double> products = {};
  List<String> shoppingCart = [];
  
  // Read products until "products_done"
  while (true) {
    String? input = stdin.readLineSync();
    if (input == "products_done") {
      break;
    }
    String productName = input!;
    String? priceInput = stdin.readLineSync();
    double price = double.parse(priceInput!);
    
    // Add product to map
    products[productName] = price;
  }
  
  // TODO: Write your code below to calculate statistics and generate the report
  
  // Print the store setup report
  // Your output should match the exact format shown in the examples
}

All lessons in Logic & Flow