You are tasked with creating a simple Grocery Store Checkout System. The system will take user inputs for items and their prices, calculate the total cost, and apply discounts based on certain conditions.
User Input:
The system should ask the user how many items they want to purchase.
For each item, the system should ask for the name and price of the item.
Store the item names and prices in separate lists.
Conditional Statements and Relational Operators:
If the total cost of all items exceeds $100, apply a 10% discount.
If the total cost is between $50 and $100 (inclusive), apply a 5% discount.
No discount is applied if the total cost is less than $50.
Iteration Statements and List Operations:
Use a loop to iterate over the items and calculate the total cost.
Use nested loops if necessary to check and apply the discounts.
String Manipulation:
The system should output the list of items with their prices in a formatted string.
Ensure proper formatting for currency (e.g., two decimal places).
Display Output:
Display the total cost before and after applying any discounts.
Display the total savings if a discount is applied.
Enter the number of items you want to purchase: 3
Enter the name of item 1: Milk
Enter the price of Milk: 2.99
Enter the name of item 2: Bread
Enter the price of Bread: 1.50
Enter the name of item 3: Eggs
Enter the price of Eggs: 3.00
Items purchased:
1. Milk - $2.99
2. Bread - $1.50
3. Eggs - $3.00
Total cost before discount: $7.49
No discount applied.
Total cost after discount: $7.49
Implement the Grocery Store Checkout System in Java. Make sure your code is well-commented and follows best practices for readability and maintainability.
Use Scanner
for taking input from the user.
Use ArrayList
to store item names and prices.
Pay attention to edge cases (e.g., entering negative prices or zero items).
Test your program with different inputs to ensure it works correctly.