Question
(JAVA CODING, MINOR ERROR) import java.util.Scanner; public class Homework { public static void main(String[] args) { System. out .println(+++++++++++++++++++++++++++++++); System. out .println(Welcome to Online Order
(JAVA CODING, MINOR ERROR)
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 code works fine, however:
while(choice<1 && choice>6) {
System.out.print(" That is a wrong input. Please try again! ");
choice=a.nextInt();
part does not work. When the user puts any number other than 1-6, the program should say that "that is a wrong input. Please try again!", and it should go at the beginning of the question and asks the user again: Please enter your choice.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started