Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me with the following Java programming project task, I hope to get a correct answer as a reference, thank you very much. The

Please help me with the following Java programming project task, I hope to get a correct answer as a reference, thank you very much.
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 two tasks:
Complete the DimSum class for storing the information of the dim sum dishesfinished
Create the ordering menuunfinished
Show the bill with the order summaryunfinished
You can type '5' and then press Enter to stop the program.
Let's first work on the first stage of the program, showing the ordering menu. To do that you need to do the following:
Printing the menu
Ordering the dish based on the input
Printing the Menu
At the moment the menu only shows the choice '5) Bill and payment'. In this part you need to complete the menu and show the first four choices, i.e. the dim sum dishes.
If you look at the DimSumOrdering class you will find that there is an attribute declared at the top like this:
// This stores the dim sum dishes in the system
DimSum[] dishes;
The attribute is an array of dim sum dishes. You will store the dim sum dishes of the system in this array. You can do that in the constructor of the class. There are four dim sum dishes that you need to assign to the array. Before assigning the dishes to the array, you need to create the array using this line of code:
dishes = new DimSum[4];
Then, for example, you can put 'Siu Mai' as the first dish in the array like this:
dishes[0]= new DimSum("Siu Mai", 30f);
The above code puts a new instance of DimSum as the first item of the array. Since we have four dim sum dishes you will put the other three dishes with appropriate names in the rest of the dishes array. For the exercise, let's set the price of the dim sum dishes to be: Barbecued Pork Bun - $25, Shrimp Dumpling - $38, Siu Mai - $30 and Spring Roll - $25.
Now, you have the array of the dim sum dishes you can print the first four choices of the menu easily using a loop. Inside the do while loop in the start method you can see the location where the menu is printed. Before printing the fifth choice, i.e.'5) Bill and payment' you need to print the dim sum dishes as the first four choices in the menu. To do that you can use a for loop like this:
for (i =0; i < dishes.length; i++){
... print the text using dishes[i].getName() and dishes[i].getPrice()...
After showing the correct menu, you can enter 1,2,3 or 4 to start to order the dim sum dishes. In the program, the input is read using this line of code:
// Read the input
choice = scanner.next();
Whatever entered by you has been stored in the choice variable. Depending on the value of the variable you can choose to increase the quantity for one of the dishes. There are many ways to do that. For example, you can use if statements to do that.
In this exercise, let's use the switch statement on the choice variable.
Here is what you need to set up after reading the input:
switch (choice){
case "1":
... order the first dish ...
break;
case "2":
... order the second dish ...
break;
case "3":
... order the third dish ...
break;
case "4":
... order the fourth dish ...
break;
}
The above switch statement uses the value of choice to order the corresponding dish. To do that, simply use the order method of that dish with a quantity of 1. However, be careful that the choice input of "1" corresponds to the first dish with an index of 0, i.e. dishes[0].
After selecting '5' in the menu you need to show the bill and the order summary.
You will do two things in this part. The first thing is to show the order summary.
Showing the Order Summary
You first display the summary of all orders. This can be done using a for loop to go through the dishes and print one at a time, like this:
for (i =0; i < dishes.length; i++){
... print the information of dishes[i]...
}
You need to show the ordered quantity, the subtotal of the dim sum dish and the name of the dish.
Finally, you will show the total amount of the bill by adding up all the orders of the dim sum dishes. Again, you can make use of a for loop to do that, like this:
total =0;
for (i =0; i < dishes.length; i++){
... add to the total using dishes[i].getQuantity() and dishes[i].getPrice()...
}
The following is the unfinished part of the code, please complete this part of the code according to the above requirements on the basis of it
public class DimSumOrdering
{
// This stores the dim sum dishes in the system
DimSum[] dishes;
// The constructor of DimSumOrdering
public DimSumOrdering()
{
//
// Task 2- Initialize the dim sum dishes in the system
//
}
// Start the ordering system
public void start(){

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Database And Transaction Processing

Authors: Philip M. Lewis, Arthur Bernstein, Michael Kifer

1st Edition

0201708728, 978-0201708721

More Books

Students also viewed these Databases questions