Question

In: Computer Science

I need code written in java for one of my projects the instructions are Write a...

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

Solutions

Expert Solution

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:-)


Related Solutions

JAVA JAVA JAVA Hey i need to find a java code for my homework, this is...
JAVA JAVA JAVA Hey i need to find a java code for my homework, this is my first java homework so for you i don't think it will be hard for you. (basic stuff) the problem: Write a complete Java program The transport Company in which you are the engineer responsible of operations for the optimization of the autonomous transport of liquid bulk goods, got a design contract for an automated intelligent transport management system that are autonomous trucks which...
Here is my java code. It works and has the correct output, but I need to...
Here is my java code. It works and has the correct output, but I need to add a file and I am not sure how. I cannot use the FileNotFoundException. Please help! import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Exercise { public static void main(String[] args) { Scanner input=new Scanner(System.in); int[] WordsCharsLetters = {0,0,0}; while(input.hasNext()) { String sentence=input.nextLine(); if(sentence!=null&&sentence.length()>0){ WordsCharsLetters[0] += calculateAndPrintChars(sentence)[0]; WordsCharsLetters[1] += calculateAndPrintChars(sentence)[1]; WordsCharsLetters[2] += calculateAndPrintChars(sentence)[2]; } else break; } input.close(); System.out.println("Words: " + WordsCharsLetters[0]); System.out.println("Characters: "...
Hi I have a java code for my assignment and I have problem with one of...
Hi I have a java code for my assignment and I have problem with one of my methods(slice).the error is Exception in thread "main" java.lang.StackOverflowError Slice method spec: Method Name: slice Return Type: Tuple (with proper generics) Method Parameters: Start (inclusive) and stop (exclusive) indexes. Both of these parameters are "Integer" types (not "int" types). Like "get" above, indexes may be positive or negative. Indexes may be null. Description: Positive indexes work in the normal way Negative indexes are described...
I need to translate my java code into C code. import java.util.Scanner; class CS_Lab3 { public...
I need to translate my java code into C code. import java.util.Scanner; class CS_Lab3 { public static void main( String args[] ) { Scanner input = new Scanner( System.in ); // create array to hold user input int nums[] = new int[10]; int i = 0, truthCount = 0; char result = 'F', result2 = 'F'; // ask user to enter integers System.out.print("Please Enter 10 Different integers: "); // gather input into array for ( i = 0; i <...
Hello, I need an expert answer for one of my JAVA homework assignments. I will be...
Hello, I need an expert answer for one of my JAVA homework assignments. I will be providing the instructions for this homework below: For this lab, you will write the following files: AbstractDataCalc AverageDataCalc MaximumDataCalc MinimumDataCalc As you can expect, AbstractDataCalc is an abstract class, that AverageDataCalc, MaximumDataCalc and MinimumDataCalc all inherit. We will provide the following files to you: CSVReader A simple CSV reader for Excel files DataSet This file uses CSVReader to read the data into a List>...
I need to make this into a Java Code: Write a program that prompts the user...
I need to make this into a Java Code: Write a program that prompts the user for a double value representing a radius. You will use the radius to calculate: circleCircumference = 2πr circleArea = πr2 sphereArea = 4πr2 sphereVolume = 43πr3 You must use π as defined in the java.lang.Math class. Your prompt to the user to enter the number of days must be: Enter radius: Your output must be of the format: Circle Circumference = circleCircumference Circle Area...
I need to write a java program (in eclipse) that will read my text file and...
I need to write a java program (in eclipse) that will read my text file and replace specific placeholders with information provided in a second text file. For this assignment I am given a text file and I must replace <N>, <A>, <G>, with the information in the second file. For example the information can be John 22 male, and the template will then be modified and saved into a new file or files (because there will be multiple entries...
This code has to be in java (I code in eclipse). Also these instructions have to...
This code has to be in java (I code in eclipse). Also these instructions have to be followed exactly because if not my output won't match the expected out ( this will be uploaded on zybooks). Write a program that asks the user for their age in days. The program will compute the person's age in years (you can assume that all years have 365 days) and then prints one of the following messages: If the user is 1 year...
I need a java code Write a simple program to prompt the user for a number...
I need a java code Write a simple program to prompt the user for a number between 1 and 12 (inclusive) and print out the corresponding month. For example:   The 12th month is December. Use a java "switch" statement to convert from the number (1-12) to the month. Also use a "do while" loop and conditional checking to validate that the number entered is between 1 and 12 inclusive and if not, prompt the user again until getting the correct...
In Java I need a Flowchart and Code. Write the following method that tests whether the...
In Java I need a Flowchart and Code. Write the following method that tests whether the array has four consecutive numbers with the same value: public static boolean isConsecutiveFour(int[] values) Write a test program that prompts the user to enter a series of integers and displays it if the series contains four consecutive numbers with the same value. Your program should first prompt the user to enter the input size—i.e., the number of values in the series.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT