Answered step by step
Verified Expert Solution
Question
1 Approved Answer
public static void Menu() { String menu = MENU: // create String menu to simulate a menu for user to interact with + 1)
public static void Menu() { String menu = "MENU: " // create String menu to simulate a menu for user to interact with + "1) Dsiplay Customer Accounts " + "2) Delete Customer Account " + "3) Search Customer Account " + "4) Search Admin Account " + "5) Quit"; Scanner sc = new Scanner(System.in); // create a Scanner to grab user inputs boolean run = true; // set to true to keep running the below while statement until changed to false System.out.println(menu); // print menu string int selection = sc.nextInt(); while (run != false) // keep user in menu until the user quits { switch (selection) // a switch statement is used to branch the following cases { case 1: DisplayCustomerAccounts(); break; case 2: System.out.println("Please enter the id of the customer you want to delete"); int Customer_ID = sc.nextInt(); DeleteCustomerAccount(Customer_ID); break; case 3: SearchCustomerAccount(); break; case 4: SearchAdminAccount(); break; case 5: System.out.println("Bye! "); run = false; // user quits menu, setting run to false, ensuring user won't return to menu break; // NONE OF THE ABOVE default: System.out.println("Invalid option. Returning to menu."); // user input is not a valid option, therefore return user back to menu break; } if (run) // if run is still true (or if the user has not quit the program) { System.out.println(menu); selection = sc.nextInt(); // repeat process } } // } catch (InputMismatchException e) { // System.out.println("please enter a number"); // System.out.println(menu); // run = true; System.out.println("Program shutdown."); // let user know the program has officially ended sc.close(); }
how would i fix this code so that during the switch statement when someone enters a letter whern they are suppose to enter a number it tell them to enter a number and shows them the menu again
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