I am trying to return back to the Menu(Choose Option) after each case, how can this be achieved with exception handling? right now it just starts again in the specific case, I am pretty new to java so these things don't really stick to me right now.
public void runMenu() {
int x = 1;
do {
try {
System.out.println("Choose Option");
System.out.println("");
System.out.println("1: Create Account");
System.out.println("2: Check Account");
System.out.println("3: Take Action");
System.out.println("4: Exit");
Choice = Option.nextInt();
if (Choice < 4) {
do {
switch (Choice) {
case 1:
CreateAccount();
case 2:
selectAccount();
Menu();
int choice = UserInput();
performAction(choice);
break;
case 3:
Menu();
int option = UserInput();
performAction(option);
break;
}
} while (Choice < 4);
System.out.println("Goodbye");
break;
} else {
throw new InputMismatchException();
}
} catch (InputMismatchException e) {
System.out.println("Enter a valid choice");
}
} while (x == 1);
}
Aucun commentaire:
Enregistrer un commentaire