Skip to content

Latest commit

 

History

History
80 lines (38 loc) · 1.13 KB

File metadata and controls

80 lines (38 loc) · 1.13 KB

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

  1. Ask the user for their name, budget, and coupon code.

  2. Generate three random item prices.

  3. Add the prices to get the subtotal.

  4. Apply a 50% discount if the coupon code is SAVE50.

  5. Calculate tax at 8%.

  6. Calculate the final total.

  7. Generate a receipt code from the first two letters of the name + random 4-digit number.

  8. Check if the total is within the budget.

  9. 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