Question

Display the welcome message (Student ID, Student Name) 2. Coffee base price $3.80 3. Show the...

Display the welcome message (Student ID, Student Name)
2. Coffee base price $3.80
3. Show the Add-in Menu with café title(name) using a loop structure unless a sentinel value is selected.
4. Save selected add-in item ID in an array and add the items price to the total price using selection structure
5. Error handling should take care of wrong choices/items which are not in the list.
6. Display the docket
a. Café name and address
b. Coffee price
c. Selected add-in item name and price using loop
d. Total amount due
7. Exit Message

using java
0 0
Add a comment Improve this question Transcribed image text
Answer #1

***Please upvote if you liked the answer***

(N.B:- I haven't added the welcome message as I don't know student_id,or student_name.Insert it at before line no 80)

Screenshot of java code:-

Ouput:-

Java code to copy with comments:-

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Cafe {
  
   String name;
   String address;
   double base_price;
  
  

   public Cafe(String name, String address, double base_price) {
      
       this.name = name;
       this.address = address;
       this.base_price = base_price;
   }

  

   public String getName() {
       return name;
   }

   public void setName(String name) {
       this.name = name;
   }

   public String getAddress() {
       return address;
   }

   public void setAddress(String address) {
       this.address = address;
   }

   public double getBase_price() {
       return base_price;
   }

   public void setBase_price(double base_price) {
       this.base_price = base_price;
   }

   public static void main(String[] args) {
      
       Scanner s = new Scanner(System.in);
      
       //Creating a cafe object with coffee base price 3.80
       Cafe c = new Cafe("My cafe","Kentucky",3.80);
      
       double total_price = c.getBase_price();
      
       String add_in;
      
      
       List<String> add_in_list = new ArrayList<String>();
      
      
       /*
       * Show the Add-in Menu with café title(name) using a loop structure
       * unless a sentinel value (4) is selected.
       *
       * */
      
      
       System.out.println(c.getName() + " menu");
      
       do
       {
           //Assuming there are three types of add-ins available
           System.out.println("1.Mocha");
           System.out.println("2.Latte");
           System.out.println("3.Cappuccino");
          
           System.out.println("Select the add-in item ID(select 4 to exit)");
           add_in = s.nextLine();
          
           add_in_list.add(add_in);
          
          
       }
       while(!add_in.equals("4"));
      
       /*
       * Adding the add-in prices using selection structure and handling error
       * conditions
       *
       * */
      
      
       for (String choice:add_in_list)
       {
           try {  
               switch (choice) {
                   case "1":{
                       total_price = total_price + 0.75;
                       break;
                   }
                   case "2":{
                       total_price = total_price + 0.35;
                       break;
                   }
                  
                  
                   case "3":{
                       total_price = total_price + 0.50;
                       break;
                       }
                  
                   default:{
                      
                       throw new Exception("Invalid item ID");
                      
                      
                       }
                  
                   };
          
           } catch (Exception e) {
               System.err.println(e.getMessage());
           }
       }
      
       /*
       * Printing the docket
       *
       * */
              
       System.out.println("Order details");
       System.out.println("Name: "+ c.getName());
       System.out.println("Address: "+ c.getAddress());
       System.out.println("Coffee Price: $" + c.getBase_price());
      
       for (String choice:add_in_list)
       {
           switch (choice) {
           case "1":{
               System.out.println("Add-in: Mocha,Price: $" + 0.75);
               break;
           }
           case "2":{
               System.out.println("Add-in: Latte,Price: $" + 0.35);
               break;
           }
          
          
           case "3":{
               System.out.println("Add-in: Cappuccino,Price: $" + 0.50);
               break;
               }
          
           default:{
              
               break;
              
              
               }
          
           };
  
       }
      
       System.out.println("Total Amount due: $" + String.format("%.2f", total_price));
      
       //Exit message
       System.out.println("Bye");
      
      
       //Closing the scanner
       s.close();      
       }
      
}

Add a comment
Know the answer?
Add Answer to:
Display the welcome message (Student ID, Student Name) 2. Coffee base price $3.80 3. Show the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Display a welcome message and then ask the user to enter his/her name Display a personal...

    Display a welcome message and then ask the user to enter his/her name Display a personal welcome message by addressing the user by his/her name. Declare a constant and assign a number to it as the Conference Room capacity. Ask the user how many people are attending the meeting. Display a meaningful message for each of the three different scenarios. The message informs the user whether he/she can have the requested room and also displays the number of people that...

  • Sample Execution – Level 3 Welcome to your Menu Creation system. How many items would you...

    Sample Execution – Level 3 Welcome to your Menu Creation system. How many items would you like to have on your menu? 2 Create your menu! Enter item #1: Coffee Enter the number of toppings: 2 Enter topping #1: Whipped Cream Enter topping #2: Cinnamon Enter item #2: Tea Enter the number of toppings: 2 Enter topping #1: Milk Enter topping #2: Sugar May I take your order? This is the menu: Coffee Tea Pop How many items would you...

  • Your assignment is to create a restaurant ordering system where the cashier can create the menu...

    Your assignment is to create a restaurant ordering system where the cashier can create the menu and then take in the order and display the order back to the customer Sample Execution – Level 1 Welcome to your Menu Creation system. How many items would you like to have on your menu? 2 Create your menu! Enter item #1: Coffee Enter item #2: Tea This is the menu: Coffee Tea What would you like to order? Cake That isn’t on...

  • Hw08FinalProjectStudentList.txt: (Data structure is Array List) 1,Simon,Jefferson,gy3085,4.0,2019 2,John,Johnson,xy1242,3.9,2019 3,Kayla,Anderson,as1324,3.8,2019 4,David,Kidman,re5423,3.8,2017 5,Mary,Coleman,ze7698,3.8,2018 Description: This assignment is

    Hw08FinalProjectStudentList.txt: (Data structure is Array List) 1,Simon,Jefferson,gy3085,4.0,2019 2,John,Johnson,xy1242,3.9,2019 3,Kayla,Anderson,as1324,3.8,2019 4,David,Kidman,re5423,3.8,2017 5,Mary,Coleman,ze7698,3.8,2018 Description: This assignment is going to evaluate your overall knowledge of the Java Programming. You shall implement a program which can store and retrieve student list. The program has a menu that you can take input from console, and the user can choose between the items. The program data is in the HwO8FinalProjectStudentList.txt file. Required Items: 1. The program must show a menu to user and ask the user...

  • C++ Programming

    PROGRAM DESCRIPTIONIn this project, you have to write a C++ program to keep track of grades of students using structures and files.You are provided a data file named student.dat. Open the file to view it. Keep a backup of this file all the time since you will be editing this file in the program and may lose the content.The file has multiple rows—each row represents a student. The data items are in order: last name, first name including any middle...

  • Write the following program in Java using Eclipse. A cash register is used in retail stores...

    Write the following program in Java using Eclipse. A cash register is used in retail stores to help clerks enter a number of items and calculate their subtotal and total. It usually prints a receipt with all the items in some format. Design a Receipt class and Item class. In general, one receipt can contain multiple items. Here is what you should have in the Receipt class: numberOfItems: this variable will keep track of the number of items added to...

  • 2. Write a program to prepare email address with name of person, email ID. This program...

    2. Write a program to prepare email address with name of person, email ID. This program should collect number of persons with their details menstion in the above. Finally, print all the registerd preson with their details and also print selected particular person's emails. 1. Write a program to prepare departmental store records with item name, number of items. This program should collect number of items with its details menstion in the above. Finally, print all the registerd items with...

  • Choose 3 of 5 Problems to Solve Need Soon as possible Choose 3 of5 Problems to...

    Choose 3 of 5 Problems to Solve Need Soon as possible Choose 3 of5 Problems to Solve (20 Point/Each) Problem l: Triangle Printing Program: Write an application that prints a right triangle with 1 to 8 rows. Prompt the user to enter an odd number in the range of 1 to 8 to specify the number of rows in the diamond. Add a validation loop to ensure the user does not enter an even number or a number outside the...

  • *****************USING JAVA AND JAVA FX ************** PLEASE READ THE INSTRUCTIONS BEFORE YOU GO AND DO IT...

    *****************USING JAVA AND JAVA FX ************** PLEASE READ THE INSTRUCTIONS BEFORE YOU GO AND DO IT SOME OTHER WAY... home / study / engineering / computer science / questions and answers / *****in java & java fx***** a restaurant wants ... Your question has been answered! Rate it below. Let us know if you got a helpful answer. Question *****IN JAVA & JAVA FX***** A restaurant wants an application that calculates a table’s bill. The design should include: Group Boxes,...

  • Project overview: Create a java graphics program that displays an order menu and bill from a...

    Project overview: Create a java graphics program that displays an order menu and bill from a Sandwich shop, or any other establishment you prefer. In this program the design is left up to the programmer however good object oriented design is required. Below are two images that should be used to assist in development of your program. Items are selected on the Order Calculator and the Message window that displays the Subtotal, Tax and Total is displayed when the Calculate...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT