Quiz 1 - Coffee Shop Calculator
Duration: 30 minutes
Total Points: 100 points
Open Book: You may reference lab materials and solutions
Scenario
You’re helping your friend manage their new coffee shop! Create a program that handles customer orders, calculates prices, and provides daily reports.
The Program: Coffee Shop Manager (100 points)
Write a complete Java program called CoffeeShop.java
that performs the following tasks:
Part 1: Customer Welcome (15 points)
- Ask for the customer’s first and last name
- Create a personalized greeting: “Welcome to Java Beans, [Full Name]!”
- Count the total number of letters in their full name (no spaces)
- Display: “Your loyalty number is: [letter count]“
Part 2: Menu and Ordering (25 points)
- Display this menu:
1. Coffee - $3.50 2. Tea - $2.25 3. Muffin - $4.00 4. Sandwich - $6.75
- Ask the customer to select an item by number (1-4)
- Use a switch statement to display their selection and price
- Ask how many of that item they want
- Calculate and display the subtotal
Part 3: Discount Calculation (25 points)
- If the loyalty number (from Part 1) is:
- Even number: Apply 10% discount
- Odd number greater than 10: Apply 5% discount
- Otherwise: No discount
- Calculate the discount amount and final total
- Display all amounts with 2 decimal places using printf
Part 4: Payment Processing (20 points)
- Ask the customer how much money they’re paying
- Calculate the change needed
- If they don’t pay enough, keep asking for more money until the total is covered
- Display the change in a formatted way
Part 5: Daily Summary (15 points)
- Ask if this is order number 1, 2, or 3 of the day
- Use a switch statement to display:
- Order 1: “First customer of the day!”
- Order 2: “Morning rush!”
- Order 3: “Lunch time!”
- Default: “Busy day ahead!”
Sample Run:
=== JAVA BEANS COFFEE SHOP ===
Enter your first name: Sarah
Enter your last name: Johnson
Welcome to Java Beans, Sarah Johnson!
Your loyalty number is: 11
MENU:
1. Coffee - $3.50
2. Tea - $2.25
3. Muffin - $4.00
4. Sandwich - $6.75
Select item (1-4): 1
You selected: Coffee ($3.50)
How many would you like? 2
Subtotal: $7.00
Loyalty discount (5%): -$0.35
Final total: $6.65
Enter payment amount: $10.00
Your change: $3.35
What order number is this today (1-3)? 1
First customer of the day!
Thank you for visiting Java Beans!
Grading Criteria:
- Puzzle 1 - Name Cipher (15 points): Correctly extracts digits from names and calculates cipher key
- Puzzle 2 - Memory Bank (25 points): Implements random verification, handles retries, calculates average
- Puzzle 3 - Pattern Lock (30 points): Complex conditional logic with multiple rules and counting
- Puzzle 4 - Time Lock (20 points): Time conversion and switch statement implementation
- Final Challenge (10 points): Multi-step calculation and final condition check
Technical Requirements:
- Use
Scanner
for all input operations - Apply
while
ordo-while
loops for retries and validation - Implement nested conditionals and complex logic
- Use
Math.random()
for randomization - Apply
printf
for formatted output - Extract digits from strings using mathematical operations
- Convert between data types appropriately
- Close Scanner when done
Strategy Tips:
- Break down each puzzle - Don’t try to solve everything at once
- Test incrementally - Get each puzzle working before moving to the next
- Use the lab examples - Adapt similar patterns from the lab solutions
- Focus on logic first - Get the algorithm right, then worry about formatting
- Handle edge cases - What if cipher key is 0? What if no digits in name?
Hidden Complexity:
This challenge requires you to combine concepts in new ways:
- String processing + mathematical operations (Puzzle 1)
- Random numbers + input validation + loops (Puzzle 2)
- Complex conditional logic + counting + digit manipulation (Puzzle 3)
- Data conversion + switch statements (Puzzle 4)
- Multi-variable calculations + final decision logic (Final Challenge)
The real challenge isn’t just knowing the syntax - it’s applying multiple concepts together to solve novel problems!
Time Management: 5 min planning → 20 min coding → 5 min testing and debugging
Good luck escaping! 🚪