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

Using Java Calculating the tip when you go to a restaurant is not difficult, but your...
Using Java Calculating the tip when you go to a restaurant is not difficult, but your restaurant wants to suggest a tip according to the service diners receive. Write a program that calculates a tip according to the diner’s satisfaction as follows: •Ask for bill amount •Ask for the diners’ satisfaction level using these ratings: 1 = Totally satisfied, 2 = Satisfied, 3 = Dissatisfied. •If the diner is totally satisfied, calculate a 20 percent tip. •If the diner is...
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 randomizes a list and sorts it. The list will be randomized...
Write a java program that randomizes a list and sorts it. The list will be randomized to be at least 12 elements and no more than 30 elements with values between 1 and 100. You will submit one program with two sorts done separately within the program. The list will be re-randomized before reach sort. Write a flowchart for each sort.
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 java code to implement a linked list, called CupList, to hold a list of...
write a java code to implement a linked list, called CupList, to hold a list of Cups. 1.Define and write a Cup node class, called CupNode, to hold the following information about a cup: •number (cup number) •capacity (cup capacity in ml) •Write a method size() that returns the number of elements in the linkedlist CupList. •Write a method getNodeAt() that returns the reference to cup node object at a specific position given as a parameter of the method. •Write...
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...
JAVA Write a class for a Stack of characters using a linked list implementation. Write a...
JAVA Write a class for a Stack of characters using a linked list implementation. Write a class for a Queue of characters using a linked list implementation. Write a class for a Queue of integers using a circular array implementation.
Java coding: 2. Write a method which takes a list list of int , and reverse...
Java coding: 2. Write a method which takes a list list of int , and reverse it. // recursion 3.Write a method which takes a list list of strings , and reverse it. // in different way than the previous 3. Write a two methods which take a list and find the largest integer number in it.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT