In: Computer Science
I need code written in java for one of my projects
the instructions are
Write a program that interacts with the user via the console and lets them choose options from a food menu by using the associated item number. It is expected that your program builds an <orderString> representing the food order to be displayed at the end. (See Sample Run Below).
Please note:
Each student is required to develop their own custom menus, with unique food categories, items and toppings.
The program should begin by greeting the user with the following statement:
Welcome to the food festival!
Would you like to place an order?
The only valid inputs are “Yes” and “No” (case insensitive).
Other input should not be allowed, and the user should be prompted again for a “Yes” or “No” input as follows:
Would you like to place an order?
If the user responds “NO” (case insensitive), the user should be thanked as follows:
Thank you for stopping by, maybe next time you’ll sample our menu.
If the user responds “YES” (case insensitive), the user should be asked their name as follows:
What is your name for the order?
The user’s name should be saved in a variable to be used later.
The user should now be prompted to select from a menu of options as follows:
Select from menu, <userName>:
0 - Nothing
1 - Appetizer
2 - Main Course
3 - Dessert
Enter the number for your selection:
The menu should then be displayed with each option having a number that will be used for the selection process. (See Sample Run Below)
All menus should include at least 3 items each in addition to 0 representing nothing selected. When a selection is made the submenu should be presented until the Toppings menu is reached. That menu should be repeatedly offered to the user until 0 is selected as an option for that category. When 0 is selected as an option for a menu, the menu at the previous level should then be presented. For the top level menu shown above, a selection of 0 should result in ending the application and displaying the following:
Here is your order, <userName>:
<orderString>
Enjoy your meal!
Example: If the user selects 1 for Appetizer, the Appetizer Menu should be presented as follows:
Appetizer Menu:
0 - Nothing
1 - Oysters
2 - Grilled Octopus
3 - Hummus
Enter the number for your appetizer selection: 1
If the user selects an appetizer, the Toppings Menu should be presented as follows:
Toppings Menu:
0 - Nothing
1 - Olive Oil
2 - Paprika
3 - Olives
Enter the number for your topping selection: 2
The toppings menu should now be be presented again for the user:
Toppings Menu:
0 - Nothing
1 - Olive Oil
2 - Paprika
3 - Olives
Enter the number for your topping selection: 0
The appetizer menu should now be presented again:
Appetizer Menu:
0 - Nothing
1 - Oysters
2 - Grilled Octopus
3 - Hummus
Enter the number for your appetizer selection: 0
The top level menu should now be presented again:
Select from menu, <userName>:
0 - Nothing
1 - Appetizer
2 - Main Course
3 - Dessert
Enter the number for your selection: 0
Implementation In JAVA:
import java.util.Scanner;
public class Restaurant {
static Scanner s= new Scanner(System.in);
static String order="";
static String name;
public static void main(String[] args) {
System.out.println("Welcome to the
food festival!");
System.out.print("Would you like to
place an order? : ");
String val=s.next();
if(val.equals("Yes")) {
System.out.println();
System.out.print("What is your name
for the order? ");
name=s.next();
Topmenu();
}
else if(val.equals("No")) {
System.out.println("Thank you for stopping by, maybe next time
you’ll sample our menu.");
}
else {
System.out.println("Invalid Input");
}
}
public static void Topmenu() {
System.out.println("Select from
menu, "+name );
System.out.println("0 -
Nothing");
System.out.println("1 -
Appetizer");
System.out.println("2 - Main
Course");
System.out.println("3 -
Dessert");
System.out.print("Enter your number
of Selection : ");
int selection= s.nextInt();
switch(selection) {
case 0:
System.out.println("Here is your order, "+name);
System.out.println(order);
System.out.println("Enjoy your meal!");
break;
case 1:
System.out.println("Appetizer
Menu : ");
appetizer();
System.out.println();
break;
case 2:
System.out.println("Main Course menu : ");
main_course();
System.out.println();
break;
case 3:
System.out.println("Dessert menu : ");
desserts();
System.out.println();
break;
default:
System.out.println("Invalid choice");
System.out.println("Please
enter the valid choice");
}
}
public static void appetizer() {
System.out.println("0 -
Nothing");
System.out.println("1 - Olive
oil");
System.out.println("2 -
Paprika");
System.out.println("3 -
Olives");
System.out.print("Enter the number
for your appetizer selection: ");
int selection= s.nextInt();
switch(selection) {
case 0:
Topmenu();
break;
case 1:
order+="Olive oil, ";
System.out.println("Topping menu : ");
appetizer();
System.out.println();
break;
case 2:
order+="Paprika, ";
System.out.println("Topping menu : ");
appetizer();
System.out.println();
break;
case 3:
order+="Olives, ";
System.out.println("Topping menu : ");
appetizer();
System.out.println();
break;
default:
System.out.println("Invalid choice");
System.out.println("Please
enter the valid choice");
}
}
public static void main_course() {
System.out.println("0 -
Nothing");
System.out.println("1 -
Lasagna");
System.out.println("2 -
Goulash");
System.out.println("3 - Macaroni
and Cheese");
System.out.print("Enter the number
for your Main Course selection : ");
int selection= s.nextInt();
switch(selection) {
case 0:
Topmenu();
break;
case 1:
order+="Lasagna, ";
System.out.println("Topping menu : ");
main_course();
System.out.println();
break;
case 2:
order+="Goulash, ";
System.out.println("Topping menu : ");
main_course();
System.out.println();
break;
case 3:
order+="Macaroni and Cheese, ";
System.out.println("Topping menu : ");
main_course();
System.out.println();
break;
default:
System.out.println("Invalid choice");
System.out.println("Please
enter the valid choice");
}
}
public static void desserts() {
System.out.println("0 -
Nothing");
System.out.println("1 - Ice
Cream");
System.out.println("2 -
Custard");
System.out.println("3 -
Pancake");
System.out.print("Enter the number
for your Desserts selection : ");
int selection= s.nextInt();
switch(selection) {
case 0:
Topmenu();
break;
case 1:
order+="Ice Cream, ";
System.out.println("Topping menu : ");
desserts();
System.out.println();
break;
case 2:
order+="Custard, ";
System.out.println("Topping menu : ");
desserts();
System.out.println();
break;
case 3:
order+="Pancake, ";
System.out.println("Topping menu : ");
desserts();
System.out.println();
break;
default:
System.out.println("Invalid choice");
System.out.println("Please
enter the valid choice");
}
}
}
SAMPLE OUTPUT:
Ist half :
2nd Half :
If you have any doubt regarding this qusestion ,please ask me in comments
//THANK YOU:-)