Quiz1

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:

  • Part 1 - Customer Welcome (15 points): String concatenation, character counting
  • Part 2 - Menu and Ordering (25 points): Switch statement, basic calculations
  • Part 3 - Discount Calculation (25 points): If/else logic, printf formatting
  • Part 4 - Payment Processing (20 points): While loop for insufficient payment
  • Part 5 - Daily Summary (15 points): Additional switch statement usage

Technical Requirements:

  • Use Scanner for all input operations
  • Apply string concatenation and length operations
  • Use switch statements for menu selection and daily summary
  • Implement if/else statements for discount logic
  • Use while loop for payment validation
  • Apply printf for monetary formatting (2 decimal places)
  • Perform basic arithmetic calculations
  • Close Scanner when finished

Tips for Success:

  • Start simple: Get basic input/output working first
  • Use the labs: Similar examples exist in your lab materials
  • Test as you go: Run your program after completing each part
  • Focus on the format: Make sure your output matches the sample
  • Double-check math: Verify your discount and change calculations

Concepts Covered:

This quiz combines concepts from all three labs:

  • Lab 1: Basic I/O, string operations, simple calculations
  • Lab 2: Switch statements, if/else logic, printf formatting
  • Lab 3: Loops, input validation, mathematical operations

The key is applying these familiar concepts to a new, realistic scenario!

Time Management:

  • 5 minutes: Planning and understanding requirements
  • 20 minutes: Implementation (4 minutes per part)
  • 5 minutes: Testing and fixing bugs

Good luck! ☕