OBJECTIVE To implement a java program to display the menu of a shop and take the order from the user. The program should
Posted: Thu May 26, 2022 9:44 am
object has four attributes, i.e., the ordered items (ArrayList),
the GSTRATE (a constant), the GST tax of the order, and the total
price of the order. ◼ The +Order() is the default constructor which
will initialise the orderedItems to an empty ArrayList, GSTRATE to
0.1, both gst and totalPrice to zero. ◼ The +addItemToOrder(Item
newItem):void method will be called once the customer adds an item
to the order. If the item has no instance in the order, then the
item will be added to the order straightway. However, if the item
has an instance in the order, then the method will only update the
quantity of the item. Once the item is added to the order, the
method will also update the total price and the GST tax of the
order accordingly. ◼ The displayOrder():void method will display
the entire order using the format in the example, i.e., nine fixed
space for each column, two decimal point precision for all
numbers.
attributes, i.e., the Item array with maximal ten elements and the
actual item number the menu contains. ◼ The Menu() is the default
constructor, which will create a 1D array to contains ten Item
objects maximally and initialise the totalItem to zero. ◼ The
+addItemToMenu(Item newItem):void method will be called to add an
item to the menu (i.e., the Item array). If the menu has less ten
items and if the item is not listed in the menu, then the item will
be added to the menu. If the item already is contained in the menu,
then the method will not add the item again to the menu but just
indicate the item was in the menu already. If the menu has ten
items, no more item can be added to the menu. ◼ The
+getMenuItem(int id):Item method will return an Item object based
on the item’s id. This method can be called when to check if an
item is contained in the menu or not. ◼ The +getTotalItem():int
method will return the actual item number contained in the menu. ◼
The +displayMenu():void method will display the entire menu using
the format in the example, i.e., nine fixed space for each column,
two decimal point precision for all numbers.
and take the customer’s order. It has two attributes, i.e., the
shop menu and the customer’s order. ◼ The +main(String[] args):void
is the method to start the program. ◼ The +Shop() is the
constructor, which initialise an empty menu and an empty order. ◼
The -createMenu():void method is a private method and will be
called to create the shop menu with the hardcode. The
implementation of the -createMenu():void method is already
provided. Please download it from Moodle and DON’T modify the
method implementation. ◼ The -takeOrder():void method is a private
method and will be called to add the customer’s selection to the
order. If the item is not contained by the order, then the item
will be added to the order directly. If the item is already
contained by the order, then the quantity of the item will be
updated accordingly. The process will be repeated until the
customer inputs -1 in the item selection (see the example and the
video introduction for details). ◼ The -checkout():void method is a
private method and will be called to checkout. The method will
calculate the GST tax, the total price and the net price (GST tax +
total Price) of the order and display the order summary using the
format in the example, i.e., nine fixed space for each column, two
decimal point precision for all numbers.
OBJECTIVE To implement a java program to display the menu of a shop and take the order from the user. The program should calculate the net price of the order based on the user's selection. BACKGROUND You are required to design and implement a simple java program for a new online shop. As a new shop, it has only ten items available and can support only one customer each time. The customer can pick up different items with different qualities. The program will automatically calculate the GST tax, the total price and the net price for the customer. CODING REQUIREMENTS Write a Java program with four classes to calculate the implement the online shop
The program structure shall be based on the UML class diagram shown below. Item -int ID (read only) -String name -double unitPrice -int quantity +Item() +Item(int id, String name, double unitPrice, int quantity) +Item(Item sourceltem, int quantity) has +getID():int +getName():String +getUnitPrice():double +getQuantity():int +increaseQuantity(int more):void +displayItem():void 10 has Menu -Item[] items -int totalltem +Menu() +addItemToMenu(ltem newltem):void +getMenultem(int id):Item +get Totalltem():int +displayMenu():void 1 0..n contains Order -ArrayList<Item> ordered items -double GSTRATE=0.1 (read only) -double gst -double totalPrice +Order() +addItem ToOrder(Item newltem):void +getOrdered Items():ArrayList<Item> +getGST():double +get TotalPrice():double +displayOrder():void 1 contains Shop -Menu menu -Order order +main(String[] args):void +Shop() -createMenu():void -takeOrder():void -checkout():void
An example with one test case is shown below. Please make sure the output of your program is the same as the following examples. Examples of the program outputs: ID ID Name UnitPrice ($) iMac:A3 fenghui$ javac Shop.java iMac:A3 fenghui$ java Shop Name UnitPrice ($) Apple 0 0.99 0 Apple 0.99 1 Pear 1.49 1 Pear 1.49 2 Banana The Item Apple is added to the menu. The Item Pear is added to the menu. 2.99 9.99 2 Banana 2.99 3 Grape 3 Grape 9.99 4 Bread 3.99 Milk 5 4.99 Bread 4 3.99 The Item Banana is added to the menu. The Item Grape is added to the menu. The Item Apple is in the menu already. The Item Bread is added to the menu. 6 Salt 2.49 5 Milk 4.99 7 Pepsi 2.29 6 Salt 2.49 8 Chilli The Item Milk is added to the menu. 11.99 3.49 7 Pepsi 2.29 9 Egg The Item Salt is added to the menu. 8 Chilli 11.99 The Item Pepsi is added to the menu. 9 Egg 3.49 Please input the Item ID to add it to your order (-1 for checkout):8 The Item Chilli is added to the menu. Please input the quality for the selected item (>-1):3 The Item Egg is added to the menu. Please input the Item ID to add it to your order (-1 for checkout):2 ID Name UnitPrice ($) 0 Apple 0.99 The menu is full and the new item Coke can't be added. Welcome to the shop. Here is our menu. Please input the quality for the selected item (>-1):2 1 Pear 1.49 2 Banana ID ID Name UnitPrice ($) 2.99 Name UnitPrice ($) 3 Grape 9.99 0 Apple 0.99 0 Apple 0.99 4 Bread 3.99 1 Pear 1.49 1 Pear 1.49 5 Milk 4.99 2 Banana 2.99 2 Banana 2.99 6 Salt 2.49 3 Grape 9.99 3 Grape 9.99 7 Pepsi 2.29 8 4 Bread 4 Chilli 3.99 Bread 3.99 11.99 9 Egg 3.49 5 Milk 4.99 5 Milk 4.99 6 Salt 2.49 6 Salt 2.49 7 Pepsi 2.29 7 Pepsi Please input the Item ID to add it to your order (-1 for checkout):-1 Here is the summary of your order. 2.29 8 Chilli 11.99 8 Chilli 11.99 ID 9 3.49 Egg 9 0 3.49 Egg Name UnitPrice Quality Price ($) 0.99 Apple Banana Chilli 1 5 2 2.99 0.99 14.95 35.97 8 11.99 3 Please input the Item ID to add it to your order (-1 for checkout): 0 Please input the Item ID to add it to your order (-1 for checkout): 2 Total Price $51.91, GST- $5.19, Net Price- $57.10 Thanks for your shopping, see you next time. Please input the quality for the selected item (>=1):1 Please input the quality for the selected item (>=1):3 Page 1 Page 2 Page 3