Item -int ID (read only) -String name -double unitPrice -int quantity +Item() +Item(int id, String name, double unitPric
Posted: Sun May 15, 2022 1:47 pm
Class Item is used to model a single item. Each Item object has
four attributes, i.e., item ID, item name, the unit price of the
item, and the item quantity.
The +Item(int id, String name, double unitPrice, int quantity) is
the constructor with four formal parameters. The +Item() is the
default constructor. The +Item(Item sourceItem, int quantity) is
the clone constructor of Class Item. Once a customer selects an
item from the menu and specify the quantity, the clone constructor
will be called to create a clone Item object based on the
sourceItem (i.e., item displays in the menu) and the specified
quantity. Then the clone Item object will be added to the
customer’s order. So any further modifications on the items in the
customer’s order will not affect the items in the menu. The
+increaseQuantity(int more):void method will increase the quantity
of a selected item in the customer’s order. When the customer
selects the same item from the menu, the +increaseQuantity(int
more):void method will be called to update the quantity of the
item, i.e., each item will have only one instance in the order. The
+displayMenu():void method will display the entire menu using the
format in the example, i.e., nine fixed space for each column, and
two decimal point precision for all numbers.
Class Order is used to model the customer’s order. Each Order
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.
Class Menu is used to model the shop menu, which contains two
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.
Class Shop is the primary class and used to display the menu 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 -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
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) +get10:int +getName():String +getUnitPrice():double +getQuantity():int +increaseQuantity (int more):void +displayItem():void has 0..n Order -ArrayList<Item> ordereditems -double GSTRATE=0.1 (read only) -double gst -double totalPrice +Order() +additemToOrder(Item newItem):void +getOrdereditems():ArrayList<Item> +getGST():double +get TotalPrice():double +displayOrder():void 10 1 contains has Shop contains Menu - Item() items -int totalltem +Menu() +additemToMenuItem newltem):void +getMenultem(int id):Item +get Totalltem():int +displayMenu():void -Menu menu -Order order +main(String[] args):void +Shop -createMenu():void -takeOrder():void -checkout():void 1
four attributes, i.e., item ID, item name, the unit price of the
item, and the item quantity.
The +Item(int id, String name, double unitPrice, int quantity) is
the constructor with four formal parameters. The +Item() is the
default constructor. The +Item(Item sourceItem, int quantity) is
the clone constructor of Class Item. Once a customer selects an
item from the menu and specify the quantity, the clone constructor
will be called to create a clone Item object based on the
sourceItem (i.e., item displays in the menu) and the specified
quantity. Then the clone Item object will be added to the
customer’s order. So any further modifications on the items in the
customer’s order will not affect the items in the menu. The
+increaseQuantity(int more):void method will increase the quantity
of a selected item in the customer’s order. When the customer
selects the same item from the menu, the +increaseQuantity(int
more):void method will be called to update the quantity of the
item, i.e., each item will have only one instance in the order. The
+displayMenu():void method will display the entire menu using the
format in the example, i.e., nine fixed space for each column, and
two decimal point precision for all numbers.
Class Order is used to model the customer’s order. Each Order
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.
Class Menu is used to model the shop menu, which contains two
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.
Class Shop is the primary class and used to display the menu 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 -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
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) +get10:int +getName():String +getUnitPrice():double +getQuantity():int +increaseQuantity (int more):void +displayItem():void has 0..n Order -ArrayList<Item> ordereditems -double GSTRATE=0.1 (read only) -double gst -double totalPrice +Order() +additemToOrder(Item newItem):void +getOrdereditems():ArrayList<Item> +getGST():double +get TotalPrice():double +displayOrder():void 10 1 contains has Shop contains Menu - Item() items -int totalltem +Menu() +additemToMenuItem newltem):void +getMenultem(int id):Item +get Totalltem():int +displayMenu():void -Menu menu -Order order +main(String[] args):void +Shop -createMenu():void -takeOrder():void -checkout():void 1