-1

I have to do a restaurant application. Can you help me and say why this code isn't working? This is what I have to do:

  1. Write the cod for an interactive menu using while loops and switch case. The user will be asked what does he want to order for entree, main course and dessert. For each of them show him a list of options displaying the name and the price for each food and save his option in a vector. After selecting the full menu, show him the order along with its price. You might treat the exceptions as you wish and also display any messages that make sense.
package tema2;
import java.util.*;

public class tema {
    public static void main(String[] args)
    {
    int mainCourse, ok1=0, dessert, ok2=0, price=0;
    String menu[];
    Scanner S = new Scanner(System.in);
    while(ok1==0)
    {
        System.out.println("Pick the mainCourse: ");
        System.out.println("1-Pizza-10, 2-Spaghetti-5, 3-Schnitzel-15");
        mainCourse = S.nextInt();
        switch(mainCourse)
        {
            case 1:
                menu[1] = "pizza";
                price=price+10;
                System.out.println("You ordered Pizza.");
                ok1=1;
            case 2: 
                menu[1] = "spaghetti";
                price=price+5;
                System.out.println("You ordered Spaghetti.");
                ok1=1;
            case 3:
                menu[1] = "schnitzel";
                price=price+15;
                System.out.println("You ordered Schnitzel.");
                ok1=1;
            default:
                System.out.println("Your order wasn't found.");
        }
    }
    while(ok2==0)
    {
        System.out.println("Pick the dessert: ");
        System.out.println("1-Ice Cream-10, 2-Pancakes-5, 3-Cake-15");
        dessert = S.nextInt();
        switch(mainCourse)
        {
            case 1:
                menu[2] = "Ice Cream";
                price=price+10;
                System.out.println("You ordered Ice Cream.");
                ok1=1;
            case 2: 
                menu[2] = "Pancakes";
                price=price+5;
                System.out.println("You ordered Pancakes.");
                ok1=1;
            case 3:
                menu[2] = "Cake";
                price=price+15;
                System.out.println("You ordered a Cake.");
                ok1=1;
            default:
                System.out.println("Your order wasn't found");
        }
    }
    System.out.println("Your order is " + menu[1] + " and " + menu[2] + ". The price is " + price);
    }
}

Robert
  • 11

1 Answers1

0

Here are some suggestions to be made:

  1. Capitalize the class name.
  2. your switch statements need to have break statements.
  3. In the second while loop ok2 should equal to 1 (ok2 = 1) to terminate the loop
Rafa
  • 467
  • 4
  • 18
  • Your first suggestion (although good advice) is not an answer to the OP's question. As this isn't CodeReview, you shouldn't begin your answer with something off-topic. – Ralf Kleberhoff Feb 18 '22 at 10:10