Question I use eclipse Getting Started To start this exercise, you should 1. Open eclipse and start a new Java project named Lab06 2. 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 \( \$ 40.00 \) ), or a pair of non-prescription sunglasses (at a cost of \( \$ 25.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 \( \$ 9.99) \). Requirements At each point where the user is being presented with an option - You must display a simple menu with menu options 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. Sample Run What kind of glasses would you like: \( 1 \rightarrow \) prescription, \( 2 \rightarrow \) non-prescription : 0 \( 1 \rightarrow \) prescription, \( 2 \rightarrow \) non-prescription : 3 \( 1 \rightarrow \) prescription, 2 non-prescription : 1 What kind of coating would you like: \( 1 \rightarrow \) anti-glare, \( 2 \rightarrow \) brown tint : 0 \( 1 \rightarrow \) anti-glare, \( 2 \rightarrow \) brown tint : 3 \( 1 \rightarrow \) anti-glare, \( 2 \rightarrow \) brown tint : 1 Your total cost is \( \$ 52.5 \)

ARNDWV The Asker · Computer Science
I use eclipse
Transcribed Image Text: Getting Started To start this exercise, you should 1. Open eclipse and start a new Java project named Lab06 2. 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 \( \$ 40.00 \) ), or a pair of non-prescription sunglasses (at a cost of \( \$ 25.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 \( \$ 9.99) \). Requirements At each point where the user is being presented with an option - You must display a simple menu with menu options 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. Sample Run What kind of glasses would you like: \( 1 \rightarrow \) prescription, \( 2 \rightarrow \) non-prescription : 0 \( 1 \rightarrow \) prescription, \( 2 \rightarrow \) non-prescription : 3 \( 1 \rightarrow \) prescription, 2 non-prescription : 1 What kind of coating would you like: \( 1 \rightarrow \) anti-glare, \( 2 \rightarrow \) brown tint : 0 \( 1 \rightarrow \) anti-glare, \( 2 \rightarrow \) brown tint : 3 \( 1 \rightarrow \) anti-glare, \( 2 \rightarrow \) brown tint : 1 Your total cost is \( \$ 52.5 \)
More
Transcribed Image Text: Getting Started To start this exercise, you should 1. Open eclipse and start a new Java project named Lab06 2. 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 \( \$ 40.00 \) ), or a pair of non-prescription sunglasses (at a cost of \( \$ 25.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 \( \$ 9.99) \). Requirements At each point where the user is being presented with an option - You must display a simple menu with menu options 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. Sample Run What kind of glasses would you like: \( 1 \rightarrow \) prescription, \( 2 \rightarrow \) non-prescription : 0 \( 1 \rightarrow \) prescription, \( 2 \rightarrow \) non-prescription : 3 \( 1 \rightarrow \) prescription, 2 non-prescription : 1 What kind of coating would you like: \( 1 \rightarrow \) anti-glare, \( 2 \rightarrow \) brown tint : 0 \( 1 \rightarrow \) anti-glare, \( 2 \rightarrow \) brown tint : 3 \( 1 \rightarrow \) anti-glare, \( 2 \rightarrow \) brown tint : 1 Your total cost is \( \$ 52.5 \)
Community Answer
ODDLFQ

【General guidance】The answer provided below has been developed in a clear step by step manner.Step1/3Let's make the input checking functions for glasses and coating.Here's the code snippet for glass. private static int getValidOptionGlass(Scanner input, int min, int max) { int option; do { option = input.nextInt(); if (option < min || option > max) { System.out.print("1 -> Prescription, 2 -> Non-Prescription : "); } } while (option < min || option > max); return option; }ExplanationThis is a method that takes three parameters: a Scanner object named input, an int named min, and an int named max. The purpose of this method is to repeatedly prompt the user to enter a valid option within a specified range (inclusive of both min and max), until a valid option is entered, and then return that valid option.The method starts by declaring an integer variable option to hold the user's input. Then it enters a do-while loop, which will continue to loop as long as option is less than min or greater than max. Inside the loop, the method prompts the user to enter an option by printing a message on the console.If the user enters an invalid option, i.e., an option that is less than min or greater than max, the method will print another prompt message and loop again. If the user enters a valid option within the specified range, the loop will exit, and the method will return the valid option.Overall, this method is used to ensure that the user enters a valid option for the glasses choice (either 1 or 2) and the coating choice (either 1 or 2), and it does not allow the program to proceed until a valid input is received.Explanation:Please refer to solution in this step.Step2/3Let's make the function to check the input from the user about the coating.private static int getValidOptionCoating(Scanner input, int min, int max) { int option; do { option = input.nextInt(); if (option < min || option > max) { System.out.print("1 -> Anti-glare, 2 -> Brown tint : "); } } while (option < min || option > max); return option; }ExplanationThis is another method that is similar to the getValidOptionGlass method. It takes three parameters: a Scanner object named input, an int named min, and an int named max. The purpose of this method is to repeatedly prompt the user to enter a valid option within a specified range (inclusive of both min and max), until a valid option is entered, and then return that valid option.The method starts by declaring an integer variable option to hold the user's input. Then it enters a do-while loop, which will continue to loop as long as option is less than min or greater than max. Inside the loop, the method prompts the user to enter an option by printing a message on the console.If the user enters an invalid option, i.e., an option that is less than min or greater than max, the method will print another prompt message and loop again. If the user enters a valid option within the specified range, the loop will exit, and the method will return the valid option.Explanation:Please refer to soluti ... See the full answer