1. Place all the Menus in separate Methods. 2. Place computations in separate Methods and call the methods once needed.
import java.util.Scanner;
public class Resto{
public static void main (String[] args){
//initialization and declaration
Scanner input = new Scanner (System.in);
String message;
int Option1;
int Option2;
int Quantity;
int TotalBill;
int Cash;
int Change;
final int SPECIALS = 1;
final int BREAKFAST = 2;
final int LUNCH = 3;
final int SANDWICHES = 4;
final int DRINKS = 5;
final int DESSERTS = 6;
//For the Special, Breakfast, Lunch Options
final int Meals1 = 11;
final int Meals2 = 12;
final int Meals3 = 13;
final int Meals4 = 14;
//First menu and First Option
System.out.println("\t Welcome to My Kitchen ");
System.out.println("\t\t SPECIALS");
System.out.println("\t\t [2] BREAKFAST MEALS");
System.out.println("\t\t [3] LUNCH MEALS");
System.out.println("\t\t [4] SANDWICHES");
System.out.println("\t\t [5] DRINKS");
System.out.println("\t\t [6] DESSERTS");
System.out.println("\t\t [0] EXIT");
System.out.print("Choose an option ");
Option1 = input.nextInt();
//first switch case statements
switch(Option1){
case (SPECIALS):
message = "**********[SPECIALS]**********\n\t [11] Baked Macaroni \n\t [12] Baked Spaghetti \n\t [13] Beef with Vegetables \n\t [14] Mongolian BBQ \n\n\t [0] Exit";
break;
case (BREAKFAST):
message = "**********[BREAKFAST MEALS]**********\n\t [11] Egg & Bacon with Rice \n\t [12] Egg & Longganisa with Rice \n\t [13] Omelette \n\t [14] Pancake BBQ \n\n\t [0] Exit";
break;
case (LUNCH):
message = "**********[LUNCH MEALS]**********\n\t [11] Beef Ribs \n\t [12] Burger Steak \n\t [13] Fried Chicken Fillet \n\t [14] Pork BBQ \n\n\t [0] Exit";
break;
case (SANDWICHES):
message = "**********[SANDWICHES]**********\n\t [1] Clubhouse Sandwich \n\t [2] Cheeseburger \n\t [3] Grilled Cheese Sandwich \n\t [4] Ham & Cheese Sandwich \n\n\t [0] Exit";
break;
case (DRINKS):
message = "**********[DRINKS]**********\n\t [1] Coke \n\t [2] Sprite \n\t [3] RootBeer \n\n\t [0] Exit";
break;
case (DESSERTS):
message = "**********[DESSERTS]**********\n\t [1] Fruit Salad \n\t [2] IceCream \n\t [3] Cheesecake \n\n\t [0] Exit";
break;
default:
message = "Thank You and come again";
break;
}
System.out.println(message);
//2nd Options and 2nd switch case statements
System.out.print("Choose an option: ");
Option2 = input.nextInt();
switch (Option2){
case (SPECIALS):
message = "**********[Choices]**********\n\t [11] Small \n\t [12] Medium \n\t [13] Large \n\t [14] Extra Large \n\n\t [0] Exit";
break;
case (BREAKFAST):
message = "**********[Choices]**********\n\t [11] Small \n\t [12] Medium \n\t [13] Large \n\t [14] Extra Large \n\n\t [0] Exit";
break;
case (LUNCH):
message = "**********[Choices]**********\n\t [11] Small \n\t [12] Medium \n\t [13] Large \n\t [14] Extra Large \n\n\t [0] Exit";
break;
case (SANDWICHES):
message = "**********[Choices]**********\n\t [11] Small \n\t [12] Medium \n\t [13] Large \n\t [14] Extra Large \n\n\t [0] Exit";
break;
case (DRINKS):
message = "**********[Choices]**********\n\t [11] Small \n\t [12] Medium \n\t [13] Large \n\t [14] Extra Large \n\n\t [0] Exit";
break;
case (DESSERTS):
message = "**********[Choices]**********\n\t [11] Small \n\t [12] Medium \n\t [13] Large \n\t [14] Extra Large \n\n\t [0] Exit";
break;
case (Meals1):
message = "**********[Choices]**********\n\t [11] Small \n\t [12] Medium \n\t [13] Large \n\t [14] Extra Large \n\n\t [0] Exit";
break;
case (Meals2):
message = "**********[Choices]**********\n\t [11] Small \n\t [12] Medium \n\t [13] Large \n\t [14] Extra Large \n\n\t [0] Exit";
break;
case (Meals3):
message = "**********[Choices]**********\n\t [11] Small \n\t [12] Medium \n\t [13] Large \n\t [14] Extra Large \n\n\t [0] Exit";
break;
case (Meals4):
message = "**********[Choices]**********\n\t [11] Small \n\t [12] Medium \n\t [13] Large \n\t [14] Extra Large \n\n\t [0] Exit";
break;
default:
message = "Thank you and come again";
break;
}
System.out.print(message);
System.out.print("Choose an option: ");
Option1= input.nextInt();
//Computing for the prices and giving change
System.out.print("Quantity: ");
Quantity = input.nextInt();
TotalBill = Quantity * 50;
System.out.println("Total Bill is "+TotalBill);
System.out.print("Cash: ");
Cash = input.nextInt();
Change = Cash - TotalBill;
//if statement
if (Cash < TotalBill)
System.out.print ("Not enough payment");
else
System.out.println ("Change is: "+Change);
//Outro
System.out.println("Thank You and come again at My Kitchen!");
}
}
Step by step
Solved in 2 steps