Getting Started To start this exercise, you should Open eclipse and start a new
ID: 3652849 • Letter: G
Question
Getting Started To start this exercise, you should Open eclipse and start a new Java project named Lab06 Add a Class (named Lab06) to this project. Problem Description For this lab you are to write as complete Java program to run a simple cash register for a eye glass store. A customer can buy either a pair of single prescription glasses (at a cost of $25.00), or a pair of non-prescription sunglasses (at a cost of $40.00). On each pair of single prescription glasses the customer must choose either an anti-glare coating (at a cost of $12.50) or a brown tint coating (at a cost of $19.99). Finally, the customer has the option to add a hard shell case (at a cost of $5.25). Requirements At each point where the user is being presented with an option - You must display a simple menu with menu options [ this -> 1, that -> 2, etc ] and then repeatedly get the user's menu option until a "valid" option is entered. The valid menu option is then used to guide the program's logic from that point.Explanation / Answer
import java.util.Scanner; public class Labo6 { public static void main(String[] args) { char choice1, choice2, choice3; double costTyeOfGlass; double costCoating = 0.0; double costshellCase = 0.0; System.out .println("1. pair of single prescription glasses (at a cost of $25.00)"); System.out .println("2. pair of non-prescription sunglasses (at a cost of $40.00)"); do { System.out.println("Enter your choice : "); Scanner input1 = new Scanner(System.in); choice1 = (input1.nextLine()).charAt(0); } while (choice1 != '1' && choice1 != '2'); if (choice1 == '1') { costTyeOfGlass = 25.00; System.out.println("1. anti-glare coating (at a cost of $12.50)"); System.out.println("2. brown tint coating (at a cost of $19.99)"); do { System.out.println("Enter your choice : "); Scanner input2 = new Scanner(System.in); choice2 = (input2.nextLine()).charAt(0); } while (choice2 != '1' && choice2 != '2'); if (choice2 == '1') { costCoating = 12.50; } else { costCoating = 19.99; } } else { costTyeOfGlass = 40.00; } System.out .println(" Want to add a hard shell case (at a cost of $5.25)"); Scanner input3 = new Scanner(System.in); choice3 = (input3.nextLine()).charAt(0); if (choice3 == 'y' || choice3 == 'Y') { costshellCase = 5.25; } System.out.println("Final Price is :" + (costTyeOfGlass + costCoating + costshellCase)); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.