I am writing a program where the user inputs a choice in the main menu and it takes them to another sub-menu. I want one of the options to be "return to previous menu" i.e. the menu first shown to the user. I can not really figure out how to do this in the way I have set up my code. Here is my code for the PrintMenu method:
public static void PrintMenu(){
Scanner input = new Scanner (System.in);
int option = 0;
while(option != 3){
System.out.println("Menu Please enter an option given bellow: ");
System.out.println("Option Operation Completed");
System.out.println("--------------------------------");
System.out.println("1 Stack");
System.out.println("2 Queue");
System.out.println("3 Quit");
option = input.nextInt();
switch(option){
case 1:
{
//add code for stack
System.out.println("You are currently using a stack. \n");
System.out.println("Enter the maximum size you want for your stack: ");
maxSize = input.nextInt();
int option_stack = 0;
while(option_stack != 5){
System.out.println("Menu Please enter an option given
bellow: ");
System.out.println("Option Operation Completed");
System.out.println("--------------------------------");
System.out.println("1 Add to Stack");
System.out.println("2 Remove from Stack");
System.out.println("3 Clear Stack");
System.out.println("4 Return to previous menu");
System.out.println("5 Quit");
option_stack = input.nextInt();
switch(option_stack){
case 1:
{
//add code for Add to Stack
break;
}
case 2:
{
//add code for Remove from Stack
break;
}
case 3:
{
//add code for Clear Stack
break;
}
case 4:
{
//add code for Return to previous menu
break;
}
case 5:
System.exit(0);
break;
//Error message if user inputs anything other
than 1-5
default:
System.out.println(option + " is not a
correct choice.\n"
+ "please enter
another option. \n");
break;
}
}
break;
}
case 2:
{
//add sub-menu and corresponding code for queue in the same
//way as stack
}
}
}
What can I put in case 4 that would take the user to the main menu?