Project Setup
Part of the Logic & Flow section of Coddy's Dart journey — lesson 33 of 65.
Challenge
EasyYou'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:
- Read a string input representing the store name
- Read multiple pairs of inputs representing product names and their prices (the input will end when you receive
"products_done") - Create a Map to store available products with their names as keys and prices as values
- Create an empty List to represent the shopping cart
- Display the initial setup information and verify that the data structures are properly initialized
- 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 customersIf 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 customersIf 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 customersYour 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
1Advanced List Manipulation
List Properties: first & lastList State: isEmpty & isNotEmpReversing a ListAdding to a List: insertList Removal: removeWhereFinding in a List: indexOfSorting a ListShuffling a ListRecap - List Organizer4Advanced Map Manipulation
Iterating Over a MapChecking for Keys and ValuesMap Properties: keys & valuesConditional Add: putIfAbsentRemoving Entries from a MapNested MapsRecap - Inventory Update2Functional List Operations
Transforming with 'map'Filtering with 'where'Using '.toList()'Checking Conditions with 'any'Conditions with 'every'Finding with 'firstWhere'Recap - Data Filtering5Project: Shopping Cart Calc
Project SetupAdding Items to the Cart3Sets
What is a Set?Creating a SetAdding and Removing from SetsChecking for Elements in a SetConverting a List to a SetSet UnionSet IntersectionSet DifferenceRecap - Unique Guest List