Hi guys this is an assignment which was assigned to me for my programming class. The code below asks the user what type of concert tickets they would like to buy once they select a option it say prints out you have selected ..... do you wish to proceed? once the user clicks yes "y" it goes into my loop, here is where the problem comes in, it continues to ask the user if they would like to buy more tickets, which is okay, but once they user says no "n" I want it to bring the menu back up and display the different options to the user again, so my question is how do I get out of this while loop? check out the code below. case B is where the loop is once i have figured that out I will apply the loop to the rest of the cases.
public class JohnTickets
{ // opening of the JohnTickets class
Scanner sc = new Scanner(System.in); // Declaring Scanner
String userChoice = "";
char category = 0;
String Selector = "";
String Proceed = "";
int tickets = 0;
int sum = 0;
int VIPprice = 950;
int TopDeck = 650;
int BackView = 500;
int newPurchase = 0;
int newJLsubtotal= 0;
int oldJLsubtotal = 0;
GettersandSetters johny = new GettersandSetters(); // creating a new object of the GettersandSetters class
// Declaration of variables
public void JohnLegendMenu()
{ // opening of the JohnLegendMenu method
System.out.println("====Ticket category available====");
System.out.println("==== for the Legend Concert ====");
System.out.println("A) VIP: R950.00 per person");
System.out.println("B) Top Deck View: R650.00 per person");
System.out.println("C) Back seat view: R500 per person");
System.out.println(""); // empty line
System.out.println("Please select a category using the number or enter X to go back to main menu ___");
userChoice = sc.nextLine();
category = userChoice.charAt(0);
JohnLegendTicketPrice();
} // closing of the JohnLegendMenu
public void JohnLegendTicketPrice()
{ // opening of the JohnLegendTicketPrice method
switch (category)
{ // opening of the catergory switch statement
case 'a':
{
System.out.println("You have chosen the VIP tickets");
EmptyLine();
System.out.println("Press Y to proceed or N to go back to the main menu___");
Proceed = sc.nextLine();
if(Proceed.equalsIgnoreCase("y"))
{
EmptyLine();
System.out.println("Please enter how many tickets you would like to buy");
tickets = sc.nextInt();
// creating a new object of the GettersandSetters class
johny.JohnLegendTicketsSetter(tickets); // calling the ticket class which accepts input "tickets"
sum = VIPprice * johny.JohnLegendTicketGetter();
johny.JohnLegendSetter(sum);
EmptyLine(); // skips a line
System.out.println("The subtotal of the John Legend Tickets is: " + sum);
System.out.println("Press Y to buy more Legend tickets or N to go to main menu___");
EmptyLine();
if(Proceed.equalsIgnoreCase("y"))
{
}
if(Proceed.equalsIgnoreCase("n"))
{
JohnLegendMenu();
}
break;
}
if(Proceed.equalsIgnoreCase("n"))
{
JohnLegendMenu();
}
break;
}
case 'b':
System.out.println("You have chosen top deck view");
EmptyLine();
System.out.println("Press Y to proceed or N to go back to the main menu___");
Proceed = sc.nextLine();
if(Proceed.equalsIgnoreCase("y"))
{
EmptyLine();
System.out.println("Press Y to proceed or N to go back to the main menu___");
while (Proceed != "y")
{
System.out.println("Please enter how many tickets you would like to buy");
tickets = sc.nextInt();
johny.JohnLegendTicketsSetter(tickets);
newPurchase = TopDeck * johny.JohnLegendTicketGetter();
oldJLsubtotal = johny.JohnLegendGetter();
newJLsubtotal = oldJLsubtotal + newPurchase;
johny.JohnLegendSetter(newJLsubtotal);
EmptyLine();
System.out.println("The subtotal for John Legend is: " + newJLsubtotal);
EmptyLine();
System.out.println("Press Y to proceed or N to go back to the main menu___");
break;
}
if(Proceed.equalsIgnoreCase("n"))
{
JohnLegendMenu();
}
break;
}
if(Proceed.equalsIgnoreCase("n"))
{
JohnLegendMenu();
}
break;
case 'c':
System.out.println("You have chosen the back view");
EmptyLine();
System.out.println("Press Y to proceed or N to go back to the main menu");
Proceed = sc.nextLine();
if(Proceed.equalsIgnoreCase("y"))
{
EmptyLine();
System.out.println("Please enter how many tickets you would like to buy");
tickets = sc.nextInt();
johny.JohnLegendTicketsSetter(tickets);
sum = BackView * johny.JohnLegendTicketGetter();
johny.JohnLegendSetter(sum);
System.out.println("The subtotal of the John Legend Tickets is: " + sum);
System.out.println("Press Y to proceed or N to go back to the main menu___");
if(Proceed.equalsIgnoreCase("y"))
{
}
if(Proceed.equalsIgnoreCase("n"))
{
JohnLegendMenu();
}
break;
}
if(Proceed.equalsIgnoreCase("n"))
{
JohnLegendMenu();
}
case 'x':
JohnLegendMenu();
break;
default:
System.out.println("You have chosen a invalid option");
} // closing of the catergory switch statement
} // closing of the JohnLegendTicketPrice method
public static void EmptyLine()
{
System.out.println("");
} // This method skips a line to create a more user friendly interface and experience
} // closing of the JohnTickets class