This small Java console app simulates a checkout experience at “The Dev Group’s Mystery Shack.”
It asks for your name and budget, generates a random receipt ID, creates 3 random item prices, applies a random tax rate, then tells you if you can afford the total (or how much you’re short / what your change is).
- Prompts the user for:
- Name
- Budget
- Prints a “welcome” message.
- Generates a random receipt ID and prints it in a receipt format.
- Generates 3 random item prices (between ~$10 and $50) and prints them.
- Adds them up to a subtotal.
- Generates a random tax percent (0%–9%), calculates the final total, and prints it.
- Compares the final total to your budget and prints either:
- “You don’t have enough…” + amount needed, OR
- “You have enough!” + your change
This is the entry point (main) of the program.
- Creates a
CalculateTaxobject - Uses a
Scannerto collect user input - Calls methods in this order:
receiptCode(customerName, randomIdCode())itemPrices()→ returns subtotalitemTax(subTotal)→ returns total with taxcanYouAffordIt(total, budget)
This class holds most of the “business logic”:
-
randomIdCode()- Creates a random receipt number from 100 to 999
-
receiptCode(String name, int id)- Takes the first 2 letters of the name, uppercases them, and prints something like:
DE-472
- Takes the first 2 letters of the name, uppercases them, and prints something like:
-
itemPrices()- Generates 3 random item prices (roughly $10–$50)
- Prints each item and the subtotal
- Returns the subtotal as a
double
-
itemTax(double subTotal)- Picks a random tax rate from 0 to 9
- Calculates tax amount and adds it to the subtotal
- Prints the tax percent and final total
- Returns the final total as a
double
-
canYouAffordIt(double total, double budget)- If budget < total → prints how much more you need
- Else → prints your change