Change.java is a simple Java program designed to assist cashiers by calculating the total cost of an item, including sales tax, and determining the change due to the customer. It provides a summary of all relevant figures, ensuring a quick and accurate checkout process.
- Prompts the user to enter the cost of an item.
- Applies a 6% sales tax to the item cost.
- Calculates the total cost, including tax.
- Prompts for the amount tendered by the customer.
- Outputs a summary showing:
- Original cost of the item
- Sales tax amount (6%)
- Total cost with tax
- Amount tendered by the customer
- Change due to the customer
- Compile the program:
javac Change.java- Run the program:
java Change- Follow the prompts:
- Enter the cost of the item (e.g.,
10.00). - Enter the amount tendered by the customer (e.g.,
20.00).
- View the output summary, which should look similar to:
Enter the cost of the item: 10.00
Enter the amount tendered by the customer: 20.00
--- Summary ---
Item Cost: $10.00
Sales Tax (6%): $0.60
Total with Tax: $10.60
Amount Tendered: $20.00
Change Due: $9.40Enter the cost of the item: 15.00
Enter the amount tendered by the customer: 20.00
--- Summary ---
Item Cost: $15.00
Sales Tax (6%): $0.90
Total with Tax: $15.90
Amount Tendered: $20.00
Change Due: $4.10- Ensure that the amount tendered by the customer is equal to or greater than the total cost. Otherwise, the change due will be a negative value, indicating an insufficient payment.
- Modify the
taxRatevariable in the code if a different sales tax rate is required.