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
  • The Jumpin Jive coffee shop charges $2 for a cup of coffee and offers add ins...

    The Jumpin Jive coffee shop charges $2 for a cup of coffee and offers add ins shown in the pseudocode. Using the following Pseudocode, Design the logic for an application that allows a user to enter ordered add ins continuously until a sentinel value is entered. After each item, display its price or the message "Sorry, we do not carry that" as an output. After all items have been entered, display the total price for the order. Please write it...

  • 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...

  • 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...

  • InventoryManagement

    Problem:A small electronics company has hired you to write an application to manage their inventory. The company requested a role-based access control (RBAC) to increase the security around using the new application. The company also requested that the application menu must be flexible enough to allow adding new menu items to the menu with minimal changes. This includes re-ordering the menu items and making changes to the description of a menu item without having to change the code.Security:The company has...

  • 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...

  • 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...

  • Programming Language is Python Need it to look just like the sample output. pls and ty!!...

    Programming Language is Python Need it to look just like the sample output. pls and ty!! Design your solution: 1. Main menu: Create a main user menu to display the main options to the user. User have the option to choose between 1 and 4. The program will display an error message if user option is not within the valid selection (less than 1 and greater than 4). Think about using a conditional structure to serve the user choice. Invalid...

  • 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...

  • In this assignment you are asked to write a python program to maintain the Student enrollment...

    In this assignment you are asked to write a python program to maintain the Student enrollment in to a class and points scored by him in a class. You need to do it by using a List of Tuples What you need to do? 1. You need to repeatedly display this menu to the user 1. Enroll into Class 2. Drop from Class 3. Calculate average of grades for a course 4. View all Students 5. Exit 2. Ask the...

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