Question

In: Computer Science

Write in java Let's assume I go a restaurant, List of meals such as breakfast and...

Write in java

Let's assume I go a restaurant, List of meals such as breakfast and lunch and dinner is displayed to me

I can pick breakfast, lunch, and dinner after I pick any of the breakfast lunch and dinner, a list of food/prices offered for breakfast is shown

so I will see the breakfast menu such an egg, milk and their prices,

after that I pick milk.

then I am asked to two more sides from the menu which will display the meal again, I pick one from the meal, and it shows what is offered in the mealtime,

I pick that food/price too.

then I will have a subtotal and total.

Something like this

Meal> Breakfast lunch and dinner

Lunch> Rice 2.99 Beans5.99

Output: you have picked rice2.99 for lunch

Add two more sides

Meal> breakfast, Lunch and dinner

Dinner> Chinese soup 3.99, Indian soup 2.99

Indian soup 2.99

Output: Side 1 is indian soup, please select one more side:

meal> breakfast lunch and dinner

breakfast> scrambled eggs 2.99, Milk 2.44

2

Output your side 2 is milk 2.44

Your subtotal is

and total is

Solutions

Expert Solution

Java Code:

package mealpackage;

import java.util.Scanner;

public class Meal {
   //Initializing constants for the class
   static Scanner sc = new Scanner(System.in);
   static int mealchoice;
   static int side1;
   static int side2;
   static String breakfast[] = {"Scrambled Egg", "Milk"};
   static String lunch[] = {"Rice", "Beans"};
   static String dinner[] = {"Chicken Soup", "Indian Soup"};
   static double breafastPrices[] = {2.99, 2.44};
   static double lunchPrice[] = {2.99, 5.99};
   static double dinnerPrices[] = {3.99, 2.99};
   //Main method
   public static void main(String[] args) {
       //Variable to store user choice of meal
       String userChoice;
       System.out.println("Enter the meal of your choice");
      
       System.out.println("1. Breakfast, 2. Lunch, 3. Dinner");
       userChoice = sc.next();
       //Display the meals
       displayMeals(userChoice);
       System.out.println();
      
       System.out.println("1. Breakfast, 2. Lunch, 3. Dinner");
       userChoice = sc.next();
       //Display the side 1
       displaySide1(userChoice);
       System.out.println();
      
       System.out.println("1. Breakfast, 2. Lunch, 3. Dinner");
       userChoice = sc.next();
       //Display the side 2
       displaySide2(userChoice);
       System.out.println();
      
       //Calculate the total
       subTotal();
   }
  
   static void displayMeals(String userChoice) {
       //Show breakfast, lunch or dinner item to the user
       if(userChoice.toLowerCase().equals("breakfast") || userChoice.toLowerCase().equals("1")) {
           System.out.println("Breakfast items are: ");
           //We get the choice of item in another function
           pickMainMeal(breakfast, breafastPrices);
       }else if(userChoice.toLowerCase().equals("lunch") || userChoice.toLowerCase().equals("2")) {
           System.out.println("Lunch items are: ");
           pickMainMeal(lunch, lunchPrice);
       }else if(userChoice.toLowerCase().equals("dinner") || userChoice.toLowerCase().equals("3")) {
           System.out.println("Dinner items are: ");
           pickMainMeal(dinner, dinnerPrices);
       }
   }
  
   static void displaySide1(String userChoice) {
       //Show breakfast, lunch or dinner item to the user
       if(userChoice.toLowerCase().equals("breakfast") || userChoice.toLowerCase().equals("1")) {
           System.out.println("Breakfast items are: ");
           //We get the choice of item in another function
           pickSide1(breakfast, breafastPrices);
       }else if(userChoice.toLowerCase().equals("lunch") || userChoice.toLowerCase().equals("2")) {
           System.out.println("Lunch items are: ");
           pickSide1(lunch, lunchPrice);
       }else if(userChoice.toLowerCase().equals("dinner") || userChoice.toLowerCase().equals("3")) {
           System.out.println("Dinner items are: ");
           pickSide1(dinner, dinnerPrices);
       }
   }
  
   static void displaySide2(String userChoice) {
       //Show breakfast, lunch or dinner item to the user
       if(userChoice.toLowerCase().equals("breakfast") || userChoice.toLowerCase().equals("1")) {
           System.out.println("Breakfast items are: ");
           //We get the choice of item in another function
           pickSide2(breakfast, breafastPrices);
       }else if(userChoice.toLowerCase().equals("lunch") || userChoice.toLowerCase().equals("2")) {
           System.out.println("Lunch items are: ");
           pickSide2(lunch, lunchPrice);
       }else if(userChoice.toLowerCase().equals("dinner") || userChoice.toLowerCase().equals("3")) {
           System.out.println("Dinner items are: ");
           pickSide2(dinner, dinnerPrices);
       }
   }
//Show the items and get the choice of item from the user
   static void pickMainMeal(String meal[], double mealPrices[]) {
       for(int i=0; i<meal.length; i++ ) {
           System.out.println((i+1) + ". " + meal[i] + ": " + mealPrices[i]);
       }
       mealchoice = sc.nextInt();
       //Display the main meal picked
       System.out.println("You have picked " + meal[mealchoice-1] + ": " + mealPrices[mealchoice-1]);
       System.out.println("Add two more sides: ");
       System.out.println();
   }
   //Show the items and get the choice of item from the user
   static void pickSide1(String meal[], double mealPrices[]) {
       for(int i=0; i<meal.length; i++ ) {
           System.out.println((i+1) + ". " + meal[i] + ": " + mealPrices[i]);
       }
       side1 = sc.nextInt();
       //Display Side1
       System.out.println("Side 1 is " + meal[side1-1] + ", please select one more side: ");
       System.out.println();
   }
   //Show the items and get the choice of item from the user
   static void pickSide2(String meal[], double mealPrices[]) {
       for(int i=0; i<meal.length; i++ ) {
           System.out.println((i+1) + ". " + meal[i] + ": " + mealPrices[i]);
       }
       side2 = sc.nextInt();
       //Display side2
       System.out.println("You side 2 is " + meal[side2-1]);
       System.out.println();
   }
  
   static void subTotal() {
       //Calculate and display the subtotal
       System.out.println("Your subtotal is: " + (breafastPrices[mealchoice-1] + lunchPrice[mealchoice-1] + dinnerPrices[mealchoice-1]));
       System.out.println("Your total is: " + (breafastPrices[mealchoice-1] + lunchPrice[mealchoice-1] + dinnerPrices[mealchoice-1]));
   }

}

Sample Output:

Enter the meal of your choice
1. Breakfast, 2. Lunch, 3. Dinner
1
Breakfast items are:
1. Scrambled Egg: 2.99
2. Milk: 2.44
2
You have picked Milk: 2.44
Add two more sides:


1. Breakfast, 2. Lunch, 3. Dinner
2
Lunch items are:
1. Rice: 2.99
2. Beans: 5.99
1
Side 1 is Rice, please select one more side:


1. Breakfast, 2. Lunch, 3. Dinner
3
Dinner items are:
1. Chicken Soup: 3.99
2. Indian Soup: 2.99
1
You side 2 is Chicken Soup


Your subtotal is: 11.42
Your total is: 11.42


Related Solutions

Once every weekend, I go out for breakfast – usually at Sweet Paris, Mess, or First...
Once every weekend, I go out for breakfast – usually at Sweet Paris, Mess, or First Watch. However, my decision usually depends on where I ate in the prior week. Basically, my breakfast eating habits are a Markov process and I’ve summarized the transition matrix below. Sweet Paris Mess First Watch Sweet Paris 0.3 0.3 0.4 Mess 0.6 0.4   0 First Watch 0.3 0.7 0 Sweet Paris has a policy where you earn a free crepe after 16 visits –...
Write a java program that will take a line of input and go through and print...
Write a java program that will take a line of input and go through and print out that line again with all the word numbers swapped with their corresponding numeric representations (only deal with numbers from one to nine). Sample runs might look like this: Please enter a line of input to process: My four Grandparents had five grandchildren My 4 grandparents had 5 grandchildren without array and methods.
For java. It's your turn to write a test suite! Let's start out simple. Create a...
For java. It's your turn to write a test suite! Let's start out simple. Create a public class TestArraySum that provides a single void class method named test. test accepts a single parameter: an instance of ArraySum. Each ArraySum provides a method sum that accepts an int[] and returns the sum of the values as an int, or 0 if the array is null. However, some ArraySum implementations are broken! Your job is to identify all of them correctly. To...
Write a Java program for a restaurant with the following features: ◦ Customer: Name, Surname, ID...
Write a Java program for a restaurant with the following features: ◦ Customer: Name, Surname, ID (incremental ID by 1 for each new customer), Email, Phone, Address. ◦ Service: ID (incremental ID by1 for each group),CustomerID, Priority (High, Medium, Low, Other), ResolutionTimeFrame (Measured in Man hours), AssignedUser, Status(resolved or not), Fee. ◦ User (simple user of system): ID, Name, Surname, Username and Password (insert from code five fixed users), Address , PhoneNumber ◦ Manager: Name, Surname, Username and Password (insert...
Write a program in java processing. Write a program that does the following: · Assume the...
Write a program in java processing. Write a program that does the following: · Assume the canvas size of 500X500. · The program asks the user to enter a 3 digit number. · The program then checks the value of the first and last digit of the number. · If the first and last digits are even, it makes the background green and displays the three digit number at the mouse pointer. · If the two digits are odd, it...
I have created a method in java in my menu list and I have to put...
I have created a method in java in my menu list and I have to put all the work into the method but I cannot get it to print and am not sure where I am going wrong. this is my code: public static void main(String[] args) { // TODO Auto-generated method stub Scanner in = new Scanner(System.in); String fName = ""; String lName = ""; double hoursWorked; double hourlyRate; int optionOne = 1; int optionTwo = 2; int optionThree...
jgrasp environment, java write a complete program that calculates a restaurant bill. Prompt the user for...
jgrasp environment, java write a complete program that calculates a restaurant bill. Prompt the user for the check amount, then ask the user what type of tipp they would like to leave: the choices are 1 for good tip (20%), 2 for an average tip (15%), or 3 for poor tip (10%). Use their input and an if-else to calculate the tip amount. Then calculate and output the final bill: check+tip print out the bill, exactly as shown (print the...
I need this written in Java, it is a Linked List and each of it's Methods....
I need this written in Java, it is a Linked List and each of it's Methods. I am having trouble and would appreciate code written to specifications and shown how to check if each method is working with an example of one method being checked. Thank you. public interface Sequence <T> { /** * Inserts the given element at the specified index position within the sequence. The element currently at that * index position (and all subsequent elements) are shifted...
I need to write a program in python for a restaurant. The program should let the...
I need to write a program in python for a restaurant. The program should let the user enter a meal number, then it should display the meal name, meal price, and meal calories. Also, needs the appropriate output if the user enters an invalid meal number. I am supposed to use a dictionary, but my problem is it keeps giving me an error and telling me my menu is not defined. Not sure what I am doing wrong. print ("Welcome...
Write a Java program that reads a list of integers into an array. The program should...
Write a Java program that reads a list of integers into an array. The program should read this array from the file “input.txt”. You may assume that there are fewer than 50 entries in the array. Your program determines how many entries there are. The output is a two-column list. The first column is the list of the distinct array elements; the second column is the number of occurrences of each element. The list should be sorted on entries in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT