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: "...
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...
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.
I need a full java code. And I need it in GUI With the mathematics you...
I need a full java code. And I need it in GUI With the mathematics you have studied so far in your education you have worked with polynomials. Polynomials are used to describe curves of various types; people use them in the real world to graph curves. For example, roller coaster designers may use polynomials to describe the curves in their rides. Polynomials appear in many areas of mathematics and science. Write a program which finds an approximate solution to...
Java Searching and Sorting, please I need the Code and the Output. Write a method, remove,...
Java Searching and Sorting, please I need the Code and the Output. Write a method, remove, that takes three parameters: an array of integers, the length of the array, and an integer, say, removeItem. The method should find and delete the first occurrence of removeItem in the array. If the value does not exist or the array is empty, output an appropriate message. (After deleting an element, the number of elements in the array is reduced by 1.) Assume that...
JAVA I need to write a code that calculates mean and standard deviation using arrays and...
JAVA I need to write a code that calculates mean and standard deviation using arrays and OOP. This is what I have so far. I'm close but my deviation calculator method is throwing errors. Thanks so much :) import java.util.Scanner; import java.util.Arrays; public class STDMeanArray { private double[] tenUserNums = new double[10];//Initialize an array with ten index' private double mean; private double deviation; Scanner input = new Scanner(System.in);//create new scanner object /*//constructor public STDMeanArray(double tenUserNum [], double mean, double deviation){...
in java: In my code at have my last two methods that I cannot exactly figure...
in java: In my code at have my last two methods that I cannot exactly figure out how to execute. I have too convert a Roman number to its decimal form for the case 3 switch. The two methods I cannot figure out are the public static int valueOf(int numeral) and public static int convertRomanNumber(int total, int length, String numeral). This is what my code looks like so far: public static void main(String[] args) { // TODO Auto-generated method stub...
I need to complete this C++ program. The instructions are in the comments inside the code...
I need to complete this C++ program. The instructions are in the comments inside the code below: ------------------------------------------------------------------------- Original string is: this is a secret! Encypted string is: uijt!jt!b!tfdsfu" Decrypted string is: this is a secret! //Encoding program //Pre-_____? //other necessary stuff here int main() { //create a string to encrypt using a char array cout<< "Original string is: "<<string<<endl; encrypt(string); cout<< "Encrypted string is: "<<string<<endl; decrypt(string); cout<<"Decrypted string is: "<<string<<endl; return 0; } void encrypt(char e[]) { //Write implementation...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT