Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The restaurant only has four different dishes of dim sum, as shown below: Barbecued pork bun Shrimp dumpling Siu mai Spring roll The system shows

The restaurant only has four different dishes of dim sum, as shown below:

  • Barbecued pork bun
  • Shrimp dumpling
  • Siu mai
  • Spring roll

The system shows an ordering menu for people to order dim sum dishes. When they have finished, they can ask for the bill and see the order summary.

To complete the system, you will need to finish three tasks:

  1. Complete the DimSum class for storing the information of the dim sum dishes
  2. Create the ordering menu
  3. Show the bill with the order summary

You will need to put them into the same project for the program to work correctly. The program starts from the main method in the DimSumOrdering class.

The program shows the ordering menu for the dim sum dishes. You can keep on ordering different dim sum dishes from the system. Once the ordering is finished, you can choose to show the bill with the order summary.

You need to finish the three tasks in the starting project. Here is an example output of the finished program.

Task 1. Finishing the DimSum Class

At the moment you can compile both the DimSum class and DimSumOrdering class but you won't find them useful. It is because you will need to fill up most of the content of both classes. In this task, you will complete the DimSum class before working on the DimSumOrdering class in the next task.

First, you need to add the attributes of the DimSum class and then finish the methods by putting appropriate content there.

Adding the Attributes

There are three attributes we want to add to the class:

  • name
  • price
  • quantity

The name attribute stores the name of the dim sum dish. It will be used when the dim sum is displayed in the ordering program. The price attribute stores the price of one dish of the dim sum. Finally, the quantity attribute is the quantity of the dim sum dishes that has been ordered so far. You need to create the attributes in the appropriate place in the class using appropriate data types. You can assume the price attribute is a float and the quantity attribute is an integer.

After adding the attributes you need to initialize their values in the constructor of the class. Looking at the DimSum class, the constructor has two input parameters called name and price. That implies when you create an instance of the DimSum class, you need to provide the name of the dim sum and its price as input parameters. For example, if you want to create the dim sum 'Siu Mai' you will use the following code:

DimSum siumai = new DimSum("Siu Mai", 30f);

The above example creates an instance of the DimSum class and the dimsum object stores the name as "Siu Mai" and its price as 30. For the class, you need to store the input parameters name and price to the name attribute and the price attribute. You may find that you need to use this.name and this.price when you assign the values to the attributes, for example like this:

this.name = ...; this.price = ...;

After that you also need to initialize the quantity attribute to become 0.

Finishing getName(), getPrice() and getQuantity()

Three methods in the class, getName(), getPrice() and getQuantity(), have been created so that other code can retrieve the current values of the three attributes respectively. You will need to return the corresponding attribute for each of the methods, rather than a fixed value that is returned by the starting class.

Finishing order()

The program stores the quantity that each dim sum dish has been ordered so far. When one of the dim sum dishes has been ordered, the program will use the order method to increase the ordered quantity of that dim sum dish. Therefore, the use of order() is to increase the quantity attribute of the class.


 How to fill in the code?

Task 1 create the attributes (1 The name of the dim sum // The price of the dim sum The quantity ordered // Constructor of the class public DimSun(String name, float price) { (1 // Task 1 - Initialize the attributes of the dim sum 1) // Return the name of the dim sum public String getName() { H // Task 1 Return the name of the dim sum 11 return "DimSum": // Return the price of the dim sum public float getPrice() ( // Task 1 Return the price of the din sum 11 return of; 1) // Return the quantity ordered public int getQuantity() { 1 // Task 1 - Return the quantity of the dim sum return 0; 1} Order this din sum dish public void order(int quantity) ( 0 // Task 1 - Increase the quantity ordered

Step by Step Solution

There are 3 Steps involved in it

Step: 1

DimSum class public class DimSum attributes private String name private f... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Business Communication Process and Product

Authors: Mary Ellen Guffey

6th Edition

324578679, 9780324578683, 9780324542905, 176721258, 9780324578676, 324542909, 9780176721251, 978-0324542905

More Books

Students also viewed these Programming questions

Question

What is the purpose of the journal wizard?

Answered: 1 week ago

Question

What is the difference between solicited and unsolicited proposals?

Answered: 1 week ago

Question

How can a speaker make the most effective use of visual aids?

Answered: 1 week ago