← Back to Week 3 Hub
Workshop 3w — Full Workshop Project
Online Store
Build a CLI shopping experience with products, cart, and checkout — this is the Week 3 workshop
The Workshop
Build a command-line online store. Load a catalog from products.csv and create a Product class to represent each item. The home screen offers three options: browse products, view cart, or exit. From the product screen the customer lists all products and adds one to their cart by typing its id. From the cart screen they review totals and check out. Checkout prompts for payment, gives change, prints a receipt, and clears the cart.
Your instructor is providing skeleton code. You'll get a Store.java file with the main menu loop already written and method signatures for loadInventory, displayProducts, displayCart, checkOut, and findProductById. Your job is to fill in the // TODO sections. Follow the method signatures as given and pass the Scanner/inventory/cart as parameters.
Product class — three fields:
idProduct id (String) — comes from the SKU column of the CSV
nameProduct name (String)
pricePrice (double)
The CSV file has a 4th column for Department — ignore it. Your Product class only uses the first three.
Build it one method at a time. Start by making loadInventory work and confirm your inventory list has products in it. Then wire up displayProducts. Test end-to-end after each method before moving on. Commit often.
Screens
Home Screen
Welcome to the Online Store!
1. Show Products
2. Show Cart
3. Exit
Your choice: 1
Display Products Screen
Products
--------
AV1051 JBL Bluetooth Speaker $89.95
AV1312 Mini 1000 Lumens Projector $149.95
GM1148 Retro Handheld Arcade $24.45
PW1001 Solar Powered Battery Charger $19.99
... (more products)
Enter product ID to add to cart (or X to return): AV1051
Added "JBL Bluetooth Speaker" to your cart.
If the id doesn't exist, print "That ID does not exist." and return to the home menu. Typing X goes back without adding anything.
Display Cart Screen
Your Cart
---------
JBL Bluetooth Speaker $89.95
Retro Handheld Arcade $24.45
Total: $114.40
C = Check Out, X = Return to menu: C
If the cart is empty, print "(empty)" and go back. Otherwise list items, show the total, and offer C or X.
Checkout Screen
Total amount owed: $114.40
Proceed with purchase? (Y/N): Y
Enter payment amount: $120
Change: $5.60
Items purchased:
• JBL Bluetooth Speaker $89.95
• Retro Handheld Arcade $24.45
Thank you for your purchase!
Checkout rules: If the customer answers anything other than Y, cancel the checkout and return. If payment is less than the total, print "Insufficient payment. Transaction cancelled." and return. After a successful purchase, clear the cart and go back to the home screen.
Flow
Create Product class
id, name, price
→
Load products.csv
BufferedReader, split on "|"
→
Create empty cart
ArrayList<Product>
Products screen
List all, type id to add, X to back
Cart screen
List, total, C)heck out, X) back
Exit
Goodbye message
Checkout
Y/N → payment → change → receipt
→
Clear cart
Return to home screen
Bonus Features (optional)
- Consolidate duplicate cart items. If the same product is added twice, show it once with a quantity (e.g.
JBL Bluetooth Speaker x2 $179.90) instead of two separate lines.
- Save receipt to file. After checkout, write the receipt to a file in a
Receipts/ folder. Name the file with a timestamp like 202604191148.txt using LocalDateTime and DateTimeFormatter.ofPattern("yyyyMMddHHmm").
Tip: Wrap your file reads and writes in try/catch blocks — missing files and I/O errors should never crash the store.
Workshop 3w — Online Store (v7.1Y instructor update)