Question

In: Computer Science

LastNameFirstNameWeek4.java Purpose: This program will take an order on a local beverage parlor. This beverage parlor...

LastNameFirstNameWeek4.java Purpose: This program will take an order on a local beverage parlor. This beverage parlor offers a limited set of drinks by a glass. Any day of the week (except Mondays when they are closed) they offer three possible alternatives: “Juice”, “Milk”, or “Soda”. Additionally only Fridays, Saturdays and Sundays, the beverage parlor serve also “Beer” and “Wine”. The program should ask the users for her/his beverage choices and produce a summary of the order in the end. To do so, the program will initially get the name of a day in a week (Monday, Tuesday, Wednesday, etc.) from the user. If the day is Monday, the program should print “Sorry. This establishment is closed on Mondays. Your order includes nothing.” And the program will stop. If the day is Tuesday, Wednesday or Thursday, the program will ask the user: “Which beverages would you like to drink?: juice, milk, or soda?" and receive the answer. If the day is Friday, Saturday or Sunday, the program would ask to the user: "Which beverages would you like to drink?: juice, milk, soda, beer, or wine?" and get an answer. After every new beverage order, the program will ask if the user wants to order something else. If the user wants to order something else, the requesting process is repeated within a loop, but the day given at the beginning of the session will remain. Every time the user selects one of the beverages, a corresponding counter for each of these meals should be updated (adding 1 to it). When the user indicates s/he does not want to order more, the program will print the total order with the correct count of each beverage that was ordered and stop. If a beverage was not ordered, its name must not appear in the final list. Notice that responses from the user may be entered in any combination of uppercase or lowercase letters. The best will be to read all responses using the next() method of the Scanner, convert these responses to uppercase letters with the toUpperCase() method of the String class, and use this uppercase version of the response to do comparisons with the choices (also in upper case). Your output should be similar to the samples shown below. Do not change the order of the questions neither the messages that are displayed. Sample 1 Which day are you visiting the Restaurant (Monday, Tuesday, Wednesday, etc.)?Tuesday Which beverages would you like to drink?: juice, milk, or soda?milk Do you want to add anything else to the order? (y/n) y Which beverages would you like to drink?: juice, milk, or soda?soda Do you want to add anything else to the order? (y/n) y Which beverages would you like to drink?: juice, milk, or soda?juice Do you want to add anything else to the order? (y/n) y Which beverages would you like to drink?: juice, milk, or soda?water This is an Invalid order. Do you want to add anything else to the order? (y/n) y Which beverages would you like to drink?: juice, milk, or soda?milk Do you want to add anything else to the order? (y/n) y Which beverages would you like to drink?: juice, milk, or soda?soda Do you want to add anything else to the order? (y/n) n Your order includes: 1 juice(s) 2 milk(s) 2 soda(s) Sample 2 Which day are you visiting the Restaurant (Monday, Tuesday, Wednesday, etc.)?Sunday Which beverages would you like to drink?: juice, milk, soda, beer, or wine?beer Do you want to add anything else to the order? (y/n) y Which beverages would you like to drink?: juice, milk, soda, beer, or wine?wine Do you want to add anything else to the order? (y/n) y Which beverages would you like to drink?: juice, milk, soda, beer, or wine?soda Do you want to add anything else to the order? (y/n) y Which beverages would you like to drink?: juice, milk, soda, beer, or wine?beer Do you want to add anything else to the order? (y/n) y Which beverages would you like to drink?: juice, milk, soda, beer, or wine?wine Do you want to add anything else to the order? (y/n) y Which beverages would you like to drink?: juice, milk, soda, beer, or wine?milk Do you want to add anything else to the order? (y/n) y Which beverages would you like to drink?: juice, milk, soda, beer, or wine?water This is an Invalid order. Do you want to add anything else to the order? (y/n) y Which beverages would you like to drink?: juice, milk, soda, beer, or wine?beer Do you want to add anything else to the order? (y/n) n Your order includes: 1 milk(s) 1 soda(s) 3 beer(s) 2 wine(s) Sample 3 Which day are you visiting the Restaurant (Monday, Tuesday, Wednesday, etc.)?Monday Sorry. This establishment is closed on Mondays Your order includes nothing. Sample 4 Which day are you visiting the Restaurant (Monday, Tuesday, Wednesday, etc.)?asasdadads Invalid day. Your order includes nothing.

Solutions

Expert Solution

If you have any problem with the program feel free to comment

Program

import java.util.Scanner;

public class LastNameFirstNameWeek4 {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);//for taking console input
       String result, day;
      
       day = getDay(sc).toUpperCase();
      
       //chekcing day and showing menu accordingly
       if(day.equals("FIRDAY") || day.equals("SATURDAY") || day.equals("SUNDAY"))
           result = beerWineMenu(sc);
       else
           result = normalMenu(sc);
      
       System.out.println(result);//printing the result
      
   }

   private static String getDay(Scanner sc) {
       String day;
      
       System.out.print("Which day are you visiting the Restaurant (Monday, Tuesday, Wednesday, etc.)? ");
       day = sc.nextLine();
      
       switch(day.toUpperCase()) {
       case "MONDAY": //when its monday
           System.out.println("Sorry. This establishment is closed on Mondays Your order includes nothing.");
           System.exit(0);
      
       case "TUESDAY": break;
       case "WEDNESDAY": break;
       case "THURSDAY": break;
       case "FRIDAY": break;
       case "SATURDAY": break;
       case "SUNDAY": break;
       default: //invalid input
           System.out.println("Invalid day. Your order includes nothing.");
           System.exit(0);
       }
       return day;
   }

   private static String normalMenu(Scanner sc) {
       int[] ar = {0, 0, 0};//for storing beverages count
       String choice;
      
       while(true) {
           System.out.print("Which beverages would you like to drink?: juice, milk, or soda? ");
           String order = sc.nextLine();
          
           switch(order.toUpperCase()) {
           //increamenting beverages count accordingly
           case "JUICE": ar[0]++; break;
           case "MILK": ar[1]++; break;
           case "SODA": ar[2]++; break;
           //invalid input
           default: System.out.println("This is an Invalid order."); break;
           }
           //checking if user want to order more
           System.out.print("Do you want to add anything else to the order? (y/n) ");
           choice = sc.nextLine();
           if(choice.equalsIgnoreCase("n"))
               break;
       }
      
       String result = createResult(ar);
      
       return result;
   }

   private static String beerWineMenu(Scanner sc) {
       int[] ar = {0, 0, 0, 0, 0};//for storing beverages count
       String choice;
      
       while(true) {
           System.out.print("Which beverages would you like to drink?: juice, milk, soda, beer, or wine? ");
           String order = sc.nextLine();
          
           switch(order.toUpperCase()) {
           //increamenting beverages count accordingly
           case "JUICE": ar[0]++; break;
           case "MILK": ar[1]++; break;
           case "SODA": ar[2]++; break;
           case "BEER": ar[3]++; break;
           case "WINE": ar[4]++; break;
           //invalid input
           default: System.out.println("This is an Invalid order."); break;
           }
           //checking if user want to order more
           System.out.print("Do you want to add anything else to the order? (y/n) ");
           choice = sc.nextLine();
           if(choice.equalsIgnoreCase("n"))
               break;
       }
      
       String result = createResult(ar);
      
       return result;
   }

   //for creating the result
   private static String createResult(int[] ar) {
       String result= "Your order includes: ";
      
       if(ar.length<=3) {//when normal menu is selected
           if(ar[0] > 0)
               result += ar[0]+" juice(s) ";
           if(ar[1] > 0)
               result += ar[1]+" milk(s) ";
           if(ar[2] > 0)
               result += ar[2]+" soda(s) ";
       }
       else {//when beer and wine menu is selected
           if(ar[0] > 0)
               result += ar[0]+" juice(s) ";
           if(ar[1] > 0)
               result += ar[1]+" milk(s) ";
           if(ar[2] > 0)
               result += ar[2]+" soda(s) ";
           if(ar[3] > 0)
               result += ar[3]+" beer(s) ";
           if(ar[4] > 0)
               result += ar[4]+" wine(s) ";
       }
      
       return result;
   }

}

Outputs


Related Solutions

Assignment Purpose The purpose of this lab is to write a well commented java program that...
Assignment Purpose The purpose of this lab is to write a well commented java program that demonstrates the use of one dimensional arrays and methods.(Need Comment, Write by Java Code) Instructions Write a method rotateArray that is passed to an array, x, of integers (minimum 7 numbers) and an integer rotation count, n. x is an array filled with randomly generated integers between 1 and 100. The method creates a new array with the items of x moved forward by...
Assignment Purpose The purpose of this lab is to write a well commented java program that...
Assignment Purpose The purpose of this lab is to write a well commented java program that demonstrates the use and re-use of methods with input validation. Instructions It is quite interesting that most of us are likely to be able to read and comprehend words, even if the alphabets of these words are scrambled (two of them) given the fact that the first and last alphabets remain the same. For example, “I dn'ot gvie a dman for a man taht...
Assignment Purpose The purpose of this lab is to write a well commented java program that...
Assignment Purpose The purpose of this lab is to write a well commented java program that demonstrates the use of one dimensional arrays and methods. Instructions Write a method rotateArray that is passed to an array, x, of integers (minimum 7 numbers) and an integer rotation count, n. x is an array filled with randomly generated integers between 1 and 100. The method creates a new array with the items of x moved forward by n Elements that are rotated...
Assignment Purpose The purpose of this lab is to write a well commented java program that...
Assignment Purpose The purpose of this lab is to write a well commented java program that demonstrates the use of two dimensional arrays, input validation, and methods. (Write by Java Code, Need Comment) Instructions A theater seating chart is implemented as a two-dimensional array of ticket prices, like this: Seat Ticket Price 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10...
Assignment Purpose The purpose of this lab is to write a well commented java program that...
Assignment Purpose The purpose of this lab is to write a well commented java program that demonstrates the use of one dimensional arrays and methods. Instructions Write a method rotateArray that is passed to an array, x, of integers (minimum 7 numbers) and an integer rotation count, n. x is an array filled with randomly generated integers between 1 and 100. The method creates a new array with the items of x moved forward by n Elements that are rotated...
Description: The purpose of the program is to create a Java ticket purchasing program that allows...
Description: The purpose of the program is to create a Java ticket purchasing program that allows for users to log in, purchase tickets, keep records of tickets purchased, and keep information about the user. Program Requirements: The following are the program requirements: Must be fully functioning including registration, log-in, view events, and purchase tickets Tickets should be purchased using “points”, no information should be provided via the user for payment method. Default each user to an allotted number of points...
Assignment Purpose The purpose of this lab is to write a well-commented java program that demonstrates...
Assignment Purpose The purpose of this lab is to write a well-commented java program that demonstrates the use of loops, and generation of random integers. Instructions You are taking some time off from your paint business and currently are on vacation in Bahamas. You decide to write a Java program that generates 10 random numbers between 1 and 20 (all integers). You cannot use arrays (even if you know what they are) to store these numbers. It then picks up...
in java we need to order a list , if we create a program in java...
in java we need to order a list , if we create a program in java what  are the possible ways of telling your program how to move the numbers in the list to make it sorted, where each way provides the required result. list the name of sorting with short explanation
Using a Java. 2. Write a Java program calculate_fare.java to take the input for number of...
Using a Java. 2. Write a Java program calculate_fare.java to take the input for number of miles, and the class of journey (1,2, or 3, for first, second, and third class respectively), for a train journey. The program should then calculate and display the fare of journey based on the following criteria: Note: Use Switch...case and if...else construct First (1) Class Second (1) Class Third (3) Class First 100 mile $ 3 per mile $ 2 per mile $ 1.50...
Write a program in Java that will take as input two sets A and B, and...
Write a program in Java that will take as input two sets A and B, and returns a list of all functions from A to B.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT