Class Cart
java.lang.Object
Cart
This class is used to to represent the cart of the user. It stores all the menu items currently stored
in the user's cart. This class provides the total cost of the current order and gives the ability to
place orders.
- Author:
- Christopher Kim
-
Constructor Summary
ConstructorsConstructorDescriptionCart()
Initializes a new Cart object with an empty total, tax, and menu items list. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addMenuItem
(MenuItem menuItem) Adds a menu item to the cart, updating the total price and tax accordingly.Completes the order by altering the inventory for each menu item in the cart.void
Empties the cart by clearing all menu items from the list.Retrieves the menu item IDs of all items currently in the cart.float
getTax()
Retrieves the calculated tax based on the total price of items in the cart.float
getTotal()
Retrieves the total price of all items in the cart.void
Prints a summary of the cart contents, including the menu item names, prices, total, tax, and grand total.void
removeMenuItem
(int menuItemIndex) Removes a menu item from the cart by its index, updating the total price and tax accordingly.
-
Constructor Details
-
Cart
public Cart()Initializes a new Cart object with an empty total, tax, and menu items list.
-
-
Method Details
-
addMenuItem
Adds a menu item to the cart, updating the total price and tax accordingly.- Parameters:
menuItem
- The MenuItem object to be added to the cart.
-
removeMenuItem
public void removeMenuItem(int menuItemIndex) Removes a menu item from the cart by its index, updating the total price and tax accordingly.- Parameters:
menuItemIndex
- The index of the menu item to be removed from the cart.
-
getTotal
public float getTotal()Retrieves the total price of all items in the cart.- Returns:
- The total price as a float.
-
getTax
public float getTax()Retrieves the calculated tax based on the total price of items in the cart.- Returns:
- The tax amount as a float.
-
completeOrder
Completes the order by altering the inventory for each menu item in the cart.- Returns:
- A list of MenuItem objects that were in the cart.
- Throws:
SQLException
- If an error occurs while altering the inventory.
-
emptyCart
public void emptyCart()Empties the cart by clearing all menu items from the list. -
getMenuIds
Retrieves the menu item IDs of all items currently in the cart.- Returns:
- An ArrayList of Integer representing the menu item IDs.
-
printCart
public void printCart()Prints a summary of the cart contents, including the menu item names, prices, total, tax, and grand total.
-