Question: (BELOW IS A JAVA CODE) import java.util.Scanner; public class Assignment2Q2 { public static void main(String[] args) { System. out .println(+++++++++++++++++++++++++++++++); System. out .println(Welcome to Online

(BELOW IS A JAVA CODE)

import java.util.Scanner;

public class Assignment2Q2

{

public static void main(String[] args)

{

System.out.println("+++++++++++++++++++++++++++++++");

System.out.println("Welcome to Online Order Program!");

System.out.println("+++++++++++++++++++++++++++++++");

String order="no";

int choice;

String type ="no";

String meat;

String food = "";

double withoutMeat=7.5;

double withBeef=25.5;

double withPork=17.5;

double totalCost=0;

double cost=0;

double totalAmount=0;

double delivery=0;

double deliveryCharge=5;

double tips=0;

Scanner a=new Scanner(System.in);

System.out.println(" 1. Hamburger");

System.out.println(" 2. Pizza");

System.out.println(" 3. Noodle");

System.out.println(" 4. Salad");

System.out.println(" 5. Sandwich");

System.out.println(" 6. Exit");

System.out.println("+++++++++++++++++++++++++++++++");

System.out.println("");

do

{

System.out.print("Please Enter your choice (1-6): ");

choice=a.nextInt();

switch(choice)

{

case 1:

food = "Hamburger";

System.out.println("");

System.out.println("Your choice is: " + food);

System.out.println("");

break;

case 2:

food = "Pizza";

System.out.println("");

System.out.println("Your choice is: "+ food);

System.out.println("");

break;

case 3:

food = "Noodle";

System.out.println("");

System.out.println("Your choice is: " + food);

System.out.println("");

break;

case 4:

food = "Salad";

System.out.println("");

System.out.println("Your choice is: " + food);

System.out.println("");

break;

case 5:

food = "Sandwich";

System.out.println("");

System.out.println("Your choice is: " + food);

System.out.println("");

break;

case 6:

System.out.println("");

System.out.println("Your choice is: Finish the Order!");

System.out.println("");

System.out.println("No need to pay the delivery fee.");

System.out.println("");

System.out.println("The total price is $0.0.");

System.out.println("");

System.out.println("Thank you for ordering!");

System.exit(0);

break;

default:

System.out.println("");

System.out.println("That is a wrong input. Please try again! ");

System.out.println("");

break;

}

}

while(choice>6||choice<1);

System.out.print("Would you like to have some meat on your " + food + "? ");

type=a.next();

if(type.equalsIgnoreCase("yes"))

{

System.out.println("");

System.out.print("Beef or Pork? ");

meat = a.next();

if(meat.equalsIgnoreCase("beef"))

cost = withBeef;

else if(meat.equalsIgnoreCase("pork"))

cost = withPork;

else

cost = 0;

}

totalCost+=cost;

System.out.println("");

System.out.print("Would you like to have more food from the menu? ");

order=a.next();

if(order.equalsIgnoreCase("no"))

{

System.out.println("");

System.out.print("The total price is less than $50. You need to pay the delivery fee $5.");

System.out.println("");

}

if(totalCost<50)

{

delivery=deliveryCharge;

}

System.out.println("");

System.out.print("Would you like to tip? Please enter the amount (if no, enter 0): ");

tips=a.nextDouble();

totalAmount=totalCost+delivery+tips;

System.out.println("");

System.out.println("The total price is $"+totalAmount);

System.out.println("");

System.out.println("Thank you for ordering!");

a.close();

}

}

My code works fine, however, when the user writes "Yes", to the question where it says "Would you like to have more food from the menu?", it does not go back and says "Please enter your choice".

The output should look like this:

Please Enter your choice (1-6): 3

Your choice is: Noodle

Would you like to have some meat on your Noodle? yes

Beef or Pork? beef

Would you like to have more food from the menu? yes

Would you like to tip? Please enter the amount (if no, enter 0):

However, after the user asks for more food, I want the program to re-ask the "Please enter your choice (1-6)" question. Right now, it just continues to the tip section. How can I fix it?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!