Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(JAVA CODING) (ERROR ON THE OUTPUT) import java.util.Scanner; public class Homework { public static void main(String[] args) { System. out .println(+++++++++++++++++++++++++++++++); System. out .println(Welcome to

(JAVA CODING)

(ERROR ON THE OUTPUT)

import java.util.Scanner;

public class Homework

{

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("");

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

choice=a.nextInt();

while (choice<1 && choice>6) {

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

choice=a.nextInt();

switch(choice)

{

case 1:

food = "Hamburger";

System.out.println("");

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

break;

case 2:

food = "Pizza";

System.out.println("");

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

break;

case 3:

food = "Noodle";

System.out.println("");

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

break;

case 4:

food = "Salad";

System.out.println("");

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

break;

case 5:

food = "Sandwich";

System.out.println("");

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

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;

}

}

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();

}

}

Above is my code:

It works fine on some parts but has some mistakes. I want the output to say the below message but most of the parts in while does not work and the question is not re-asked:

Please enter your choice (1-6): 0

That is a wrong input. Please try again!

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

Please enter your choice (1-6): 5

Your choice is: Sandwich.

Would you like to have some meat on your Sandwich? Yes

Beef or Pork? beef

Would you like to have more food? no

No need to pay the delivery fee.

Would you like to pay some tips? Please enter the amount: 5.5

The total price is 56.5.

Thank you!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Handbook Of Database Security Applications And Trends

Authors: Michael Gertz, Sushil Jajodia

1st Edition

1441943056, 978-1441943057

More Books

Students also viewed these Databases questions