← Back to Week 1 Hub

Sandwich Shop 2

Upgrade the sandwich shop with a "loaded" option before applying the age discount

Workbook 1c, p.104 — Project name: sandwich-shop-2

In Plain English

This is an upgrade to the Sandwich Shop. Now after the customer picks a size, ask if they want the sandwich "loaded" (extra toppings). Loaded adds $1.00 for Regular or $1.75 for Large.

The age discount still applies — but it's calculated on the total price including the loaded option. So the order of operations matters: base price, then loaded add-on, then discount on the combined amount.

What a Successful Run Looks Like

Run 1 — Regular, Loaded, Student Discount (10% off)

Select sandwich size (1=Regular, 2=Large): 1 Do you want the sandwich loaded? (yes/no): yes Enter your age: 16 Sandwich cost: $5.805
Math check: Regular $5.45 + loaded $1.00 = $6.45, then 10% off = $6.45 × 0.90 = $5.805

Run 2 — Large, Not Loaded, Senior Discount (20% off)

Select sandwich size (1=Regular, 2=Large): 2 Do you want the sandwich loaded? (yes/no): no Enter your age: 70 Sandwich cost: $7.16
Math check: Large $8.95 + loaded $0.00 = $8.95, then 20% off = $8.95 × 0.80 = $7.16
What This Exercise Practices

This exercise reinforces these concepts from Week 1:

Why this matters: This exercise layers a new decision on top of an existing program. In real projects, you'll constantly add features to working code. The key skill here is getting the order of operations right — add the loaded price before calculating the discount, not after.
Flow Diagram
Step 1 Ask for size 1 = Regular, 2 = Large
Step 2 Look up base price $5.45 or $8.95
Step 3 Ask if loaded yes / no
Step 4 Add loaded price $1.00 or $1.75 if yes
Step 5 Ask for age Scanner input
Step 6 Check age discount Student / Senior / None
Step 7 Calculate final price Apply discount to total
Step 8 Display result System.out.println()

Think about it: the loaded price depends on the size, and the discount applies to the total. Order matters.

← Sandwich Shop Method Practice →