Question
Part 1 Write a Java class called LemonadeStand 1. For the following, store each item as a variable of the appropriate data type. Must use
Part 1
Write a Java class called LemonadeStand 1. For the following, store each item as a variable of the appropriate data type. Must use a different data type for each one. Get the value from the user using the Scanner class.
- Ask the customer for his or her name and store it as a variable
- Ask the customer, by their first name, how many glasses of lemonade they would like to buy, and store that value as a variable.
- Store the price of lemonade as a variable
- Get the payment type from the user, as a single character (C for credit card, D for debit card, M for cash money, or V for Venmo). Please note that we are not doing anything with this variable for now, but will in the next assignment
2. Calculate the total price which is basically the number of glasses time the price.
3. Display the total due to the user in this format: Each glass costs $(price), so the total due is $(total) !
- Where (price) is replaced with the variable you chose to store the price per glass of lemonade, and total is replaced with the variable you chose to store the total due
- Make sure the total pay always displays 2 digits after the decimal point. Also display the dollar sign "$" before the total pay.
Example Output (user input is in green)
Welcome to the Lemonade Stand, what is your name?
Amanda
Hi Amanda, how many glasses of lemonade would you like? They are $1.75 each
2
Each glass costs $1.75, so the total due is $3.50.
How will you be paying today?
C
Thanks and have a nice day!
Part 2
Update the class LemonadeStand
1. Change the price per glass of lemonade to a constant variable. Also be sure to rename the variable to show the proper naming convention for constant variables.
2. Using a switch statement:
- If the payment type is C or c, then display "Credit card transaction" on the screen
- If the payment type is D or d, then display "Debit card transaction" on the screen
- If the payment type is M or m, then display "Money transaction" on the screen
- If the payment type is V or v, then display "Venmo transaction" on the screen
- If the payment is none of the above, then display "Invalid payment type" on the screen, and end the program with System.exit(1);
3. Using a single if-else-if statement:
- If the user paid via credit card or debit card, then charge a $0.50 credit/debit fee. Add that fee to the total, and display the new total on the screen.
- If the user paid via money (cash) and the total is $5 or more, then give a 10% discount. If the total is less than $5, then no discount will be given. Subtract that discount from the total, and display that new total on the screen.
- If the user paid via Venmo and the total is more than $10, then tell the user they earned a free glass of lemonade
Example Output (user input is in green)
Welcome to the Lemonade Stand, what is your name?
Amanda
Hi Amanda, how many glasses of lemonade would you like? They are $1.75 each
2
Each glass costs $1.75, so the total due is $3.50.
How will you be paying today?
C
Credit card transaction.
There will be a $0.50 fee for using Credit Card. Your new total is $4.00. Thanks and have a nice day!
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