In: Computer Science
There is already an existing class called Sizes, with an existing main method.
Inside the Sizes class, create a method called menu. The purpose of this method is to display the menu on the screen and allow the user to make a choice from the menu.
Do not change any of the existing code in the main method, and do not add code to the main method. Changing the main method in any way will give you an automatic grade of zero on this part of the assignment.
This method does not need to accept any parameters from the main method. Choices should be read into the menu method from the keyboard as a number 1, 2, 3 or 4. This method will need to contain a loop which will repeat the process of displaying the menu and getting an input value as long as the user does not enter a correct menu option. After a correct menu option has been entered, the method should return that choice back to the main method.
Note that this method is required to verify that the entered choice is correct, so the main method does not have to do that task.
The following is an example of what your MIGHT see on the screen when your menu method executes. The exact output depends on what values that the user types in while the program runs. The user's inputted values are shown below in italics. Note that your method must display the exact formatting shown here - including the spaces and blank lines.
import java.util.Scanner; public class Sizes { public static Scanner kbd; public static void main(String[] args) { kbd = new Scanner(System.in); System.out.println("Begin test"); System.out.println("Method returned: " + menu()); System.out.println("Test complete"); kbd.close(); } // Write the menu method here public static int menu() { int num; while (true) { System.out.println("1. Calculate Hat Size"); System.out.println("2. Calculate Jacket Size"); System.out.println("3. Calculate Waist Size"); System.out.println("4. No More Calculations"); System.out.print(" Enter your choice: "); num = kbd.nextInt(); if(num >= 1 && num <= 4) { return num; } System.out.println(); } } }