Class Cart


public class Cart extends Object
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

    Constructors
    Constructor
    Description
    Initializes a new Cart object with an empty total, tax, and menu items list.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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
    Retrieves the calculated tax based on the total price of items in the cart.
    float
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Cart

      public Cart()
      Initializes a new Cart object with an empty total, tax, and menu items list.
  • Method Details

    • addMenuItem

      public void addMenuItem(MenuItem menuItem)
      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

      public ArrayList<MenuItem> completeOrder() throws SQLException
      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

      public ArrayList<Integer> 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.