Question
Java:: In this homework, you will have to write a shopping cart application which allows the user to enter different items to make a purchase.
Java::
In this homework, you will have to write a shopping cart application which allows the user to enter different items to make a purchase. You will first have to create a simple menu. Every option will generate a different response from the kiosk. The program starts by printing the following menu:
Please select a menu item from the list below: 1 View item menu 2 Pay total due 3 Add $5 in credit 4 Clear order
The user can input a numerical menu option between 1 and 4. If an incorrect entry is inputted then the program will print.
Please enter a valid option!
Below is an explanation of each menu option:
- 1 - Add item to shopping cart: This option will go into another menu which will display food options to the user. The user can input a numerical menu option between 1 and 5.
(1) Toaster: $19.99 (2) Coffee maker: $29.49 (3) Waffle maker: $15.79 (4) Blender: $24.99 (5) Kettle: $$24.99 (6) Go to the main menu Your current total is: $0.00
If an incorrect entry is inputted then the program will print.
Invalid item number please try again
This menu will loop until the user enters option 6 which will bring them back to the main menu. When the user inputs an option between 1 and 5 the program will display a confirmation of the selected item. Make sure that each corresponding menu option prints the exact confirmation format listed below:
You have added a Toaster to your order. You have added a Coffee maker to your order. You have added a Waffle maker to your order. You have added a Blender to your order. You have added a Kettle to your order.
Below is an example of the console output when the user chooses item 1 and then 2 (note that the input is not visible in the output).
What would you like to add to your order? (1) Toaster: $19.99 (2) Coffee maker: $29.49 (3) Waffle maker: $15.79 (4) Blender: $24.99 (5) Kettle: $24.99 (6) Go to the main menu Your current total is: $0.00 You have added a Toaster to your order. What would you like to add to your order? (1) Toaster: $19.99 (2) Coffee maker: $29.49 (3) Waffle maker: $15.79 (4) Blender: $24.99 (5) Kettle: $24.99 (6) Go to the main menu Your current total is: $19.99 You have added a Coffee maker to your order. What would you like to add to your order? (1) Toaster: $19.99 (2) Coffee maker: $29.49 (3) Waffle maker: $15.79 (4) Blender: $24.99 (5) Kettle: $24.99 (6) Go to the main menu Your current total is: $49.48
- 2 Pay total due: This option allows the user to pay the amount that is due before tax is added. For the total amount to pay all goods are taxed at 8.5%. In addition, the store offers a 20% discount if the total before taxes is greater than $50. Discount will be applied before taxes are added.The user will start from an initial budget of $100 and if the user is able to afford the total payment (incl. of taxes) then the purchase will go through and the user will see the following text:
Your total due is: $49.48 Thank you! Your change is: $46.31 Your items will be on their way soon!
Here is another example output for when the user has received the discount and the system should also show the savings (calculated before taxes) in the output:
Your total due is: $70.27 Thank you! You saved: $14.05 Your change is: $39.01 Your items will be on their way soon!
If the user cannot afford the purchase they will see the total due and receive the following console text and exit the program:
Insufficient funds!
- 3 - Add $5 in credit: This option increments the available credit by $5, and prints the new available credit (with 2 digits precision):
Credit available: $
- 4 Clear order: This menu option will reset the total balance due to $0 and show the following:
Current order balance has been cleared. Current due: $0.00
Below is an example of what the program should output based on the input 1 2 3 6 2.
Please select a menu item from the list below: 1 View item menu 2 Pay total due 3 Add $5 in credit 4 Clear order What would you like to add to your order? (1) Toaster: $19.99 (2) Coffee maker: $29.49 (3) Waffle maker: $15.79 (4) Blender: $24.99 (5) Kettle: $24.99 (6) Go to the main menu Your current total is: $0.0 You have added a Coffee maker to your order. What would you like to add to your order? (1) Toaster: $19.99 (2) Coffee maker: $29.49 (3) Waffle maker: $15.79 (4) Blender: $24.99 (5) Kettle: $24.99 (6) Go to the main menu Your current total is: $29.49 You have added a Waffle maker to your order. What would you like to add to your order? (1) Toaster: $19.99 (2) Coffee maker: $29.49 (3) Waffle maker: $15.79 (4) Blender: $24.99 (5) Kettle: $24.99 (6) Go to the main menu Your current total is: $45.28 Please select a menu item from the list below: 1 View item menu 2 Pay total due 3 Add $5 in credit 4 Clear order Your total due is: $45.28 Thank you! Your change is: $50.87 Your items will be on their way soon!
Be aware: As introduced in the first chapter in Zybooks, a lot of tests are implemented with a one line input. Please make sure your final test cases run in IntelliJ reflect this behavior: e.g. the test case using the numbers 1 2 3 6 2 must be entered with spaces between the numbers, ENTER should only be pressed at the end.
Every dollar amount must be printed with 2 digits precision. Check section 9.2 of this book for how to use printf and format to achieve this result. Non original submissions and attempts to hard code the program's output will result in a grade of 0 for the entire homework.
import java.util.Scanner;
public class Homework1 { public static void main(String[] args) {
/*/Type Your code here/*/
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started