Receipt Generator in Java What It Does
This program generates a simple receipt for three items. It calculates the subtotal, applies a coupon, adds tax, checks the budget, and gives a receipt code.
• How It Works
-
Ask the user for their name, budget, and coupon code.
-
Generate three random item prices.
-
Add the prices to get the subtotal.
-
Apply a 50% discount if the coupon code is SAVE50.
-
Calculate tax at 8%.
-
Calculate the final total.
-
Generate a receipt code from the first two letters of the name + random 4-digit number.
-
Check if the total is within the budget.
-
Print a simple receipt with all the details.
• Sample Output
Enter your name: Alice
Enter your budget: 150
Enter a coupon code: SAVE50
--- Receipt ---
Receipt Code: AL4821
Item 1 Price: $42.34
Item 2 Price: $57.89
Item 3 Price: $33.12
Subtotal: $133.35
Discounted Total: $66.67
Tax: $5.33
Final Total: $72.00
Within budget: true
• Java Concepts Used
Classes and objects
Methods
Random numbers
User input with Scanner
Variables and data types
Conditional statements (if)
Printing output with System.out.println