关键词 > CSE214 Java代写
CSE214 Restaurant's Menu
发布时间:2026-02-02
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
CSE214 Restaurant's Menu
Requirement
In this assignment, you will write a system to keep track of a restaurant’s menu and the orders placed at the restaurant. A menu consists of up to 50 items, each of which has a name, description, and price. You will implement a class called Menu to store the menu. A driver class will be used to interact with a Menu (add/remove items, change name/description/price, etc.) and build up an “order” of items from the menu (like a shopping cart).
Write a fully-documented class named MenuItem which contains the item’s name (String), description (String), and price (double). You should provide accessor and mutator methods for each variable, as well as a constructor for the class. The mutator method for the price variable should throw an exception if the new price is nonpositive.
Write a fully-documented class named Menu which stores a list of items in an array and provides an interface to interact with this list. Note that although arrays in Java are indexed starting with 0, the items in a Menu will be indexed starting with 1. A Menu can hold up to 50 items at a time, so use the final variable MAX_ITEMS = 50. The class will be based on the following ADT specification:
public class Menu
The Menu class implements an abstract data type for a list of menu items supporting some common operations on such lists.
Constructor for Menu
Write a fully documented class named MenuOperations that is based on the following specification:
public class MenuOperations
The MenuOperations Java application tests data structure classes designed above and the operations defined on them.
1 public static void main(String[] args)
The main method runs a menu driven application which first creates an empty Menu, and then prompts the user for a command selecting the operation. Once an operation is selected, the program prompts for any additional information required to perform the operation, and then actually performs the operation. The operations and additional information required are listed below. To store the items in the current order, you can either use an array or a separate instance of the Menu class.
Add Item: A <Name> <Description> <Price> <Position> (add the item to the
Get Item: G <Position> (Print out the name, description, and price of the
Remove Item: R <Name> (Remove the item with the given name in the menu)
Print All Items: P (print the list of all items on the menu)
Size: S (print the number of items on the menu)
Update description: D <Name> <New description> (update the description of the named
Update price: C <Name> <New price> (update the price of the named item)
Add to order: O <Position> (Add the item at the specified position in the men
Remove from order: I <Position> (Remove the item at the specified position in the
View order: V (print the items in the current order)
Quit: Q (terminate the program gracefully)
You will also need classes to handle the exceptions thrown (see class specifications above for the exception classes you need).
Note: You may include additional methods in any class as necessary or as you find convenient.
INPUT FORMAT:
Each menu operation is entered on its own line and should be case insensitive (i.e. ‘q’ and ‘Q’ are the same).
Check to make sure that the position, if required, is valid. If not, print an error message and return to the menu.
For the Add Item command, if the input information is valid, construct the object accordingly. Otherwise, print an error message and return to the menu. You may assume that the lengths of the input for the item names are at most 25 characters long, and that the descriptions are at most 75 characters long.
OUTPUT FORMAT:
Echo the input information for the Add Item command in the output.
All menu operations must be accompanied by a message indicating what operation was performed and whether or not it was successful.
All lists must be printed in a nice and tabular form as shown in the sample output. You may use C style formatting as shown in the following example. The example below shows two different ways of displaying the name and address at pre-specified positions 21, 26, 19, and 6 spaces wide. If the ‘-‘ flag is given, then it will be left-justified (padding will be on the right), else the region is right-justified. The ‘s’ identifier is for strings, the ‘d’ identifier is for integers . Giving the additional ‘0’ flag pads an integer with additional zeroes in front.
1 String name = "Doe Jane";
2 String address = "32 Bayview Dr.";
3 String city = "Fishers Island, NY";
4 int zip = 6390;
5
6 System.out.println(String.format("%-21s%-26s%19s%06d", name, address, city, zip));
7 System.out.printf("%-21s%-26s%19s%06d", name, address, city, zip);
Doe Jane 32 Bayview Dr. Fishers Island, NY 06390
Doe Jane 32 Bayview Dr. Fishers Island, NY 06390
HINTS:
Remember that the position parameter to all of the methods listed in the Menu class refers to the player at a given item within a Menu (starting at position 1) and not the position inside of the array (which starts at position 0).
There are two ways that you can handle this issue:
Store item 1 in array position 0, item 2 in array position 1, and so on and so forth. Inside each method, subtract one from the position given by the parameter to find the appropriate position within the array.
Define your array such that it is of size MAX_ITEMS + 1 instead of MAX_ITEMS. Store item 1 in array position 1, item 2 in array position 2, and so on and so forth. Position 0 of the array will not be used.
SAMPLE INPUT/OUTPUT
Output shown in black. User input shown in red. Comments shown in green.
Main menu:
A) Add Item
G) Get Item
R) Remove Item
P) Print All Items
S) Size
D) Update description
C) Update price
O) Add to order
I) Remove from order
V) View order
Q) Quit
Select an operation: A
Enter the name: Chicken Parmesan
Enter the description: Breaded chicken, tomato sauce, and cheese
Enter the price: 9.50
Enter the position: 1
Added "Chicken Parmesan: Breaded chicken, tomato sauce, and cheese" for $9.50 at positio
// Menu not shown in sample input/output
Select an operation: A
Enter the name: Hot Dog
Enter the description: Beef sausage in a bun with ketchup
Enter the price: 4.50
Enter the position: 1
Added "Hot Dog: Beef sausage in a bun with ketchup" for $4.50 at position 1
// Menu not shown in sample input/output
Select an operation: P
MENU:
# Name Description Price
---------------------------------------------------------------------------------
1 Hot Dog Beef sausage in a bun with ketchup $4.50
2 Chicken Parmesan Breaded chicken, tomato sauce, and cheese $9.50
// Menu not shown in sample input/output
Select an operation: C
Enter the name of the item: Chicken Parmesan
Enter the new price: 8.50
Changed the price of "Chicken Parmesan" to $8.50
// Menu not shown in sample input/output
Select an operation: P
MENU:
# Name Description Price
---------------------------------------------------------------------------------
1 Hot Dog Beef sausage in a bun with ketchup $4.50
2 Chicken Parmesan Breaded chicken, tomato sauce, and cheese $8.50
// Menu not shown in sample input/output
Select an operation: S
There are 2 items in the menu
// Menu not shown in sample input/output
Select an operation: O
Enter position of item to add to order: 2
Added "Chicken Parmesan" to order
// Menu not shown in sample input/output
Select an operation: V
ORDER:
# Name Description Price
---------------------------------------------------------------------------------
1 Chicken Parmesan Breaded chicken, tomato sauce, and cheese $8.50
// Menu not shown in sample input/output
Select an operation: G
Enter the position: 2
# Name Description Price
---------------------------------------------------------------------------------
1 Chicken Parmesan Breaded chicken, tomato sauce, and cheese $8.50
// Menu not shown in sample input/output
Select an operation: R
Enter the Name: Chicken Parmesan
Removed "Chicken Parmesan"
// Menu not shown in sample input/output
Select an operation: D
Enter the position: 1
Enter the new description: Beef sausage in a bun with ketchup and mustard
New description set.
// Menu not shown in sample input/output
Select an operation: P
MENU:
# Name Description Price
---------------------------------------------------------------------------------
1 Hot Dog Beef sausage in a bun with ketchup and mustard $4.50
// Menu not shown in sample input/output
Select an operation: I
Enter the position: 1
Removed "Chicken Parmesan" from order.
// Menu not shown in sample input/output
Select an operation: V
ORDER:
# Name Description Price
---------------------------------------------------------------------------------
// Examples of errors:
// Menu not shown in sample input/output
Select an operation: L
No such operation
// Menu not shown in sample input/output
Select an operation: R
Enter the position: 3
No item in position 3
