Class MenuItem


public class MenuItem extends Object
This class is used to hold the information of a specific menu item the user is ordering. It provides the necessary methods to retrieve the data of the menu item and place the order. It utilizes the database class to access the remote database to retrieve the information of the food items
Author:
Christopher Kim
  • Constructor Summary

    Constructors
    Constructor
    Description
    MenuItem(int menuitemId, Database database)
    Constructs a MenuItem object with the specified menu item ID and database connection.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addFoodItem(int foodItemId)
    Adds a food item ID to the list of food items associated with this menu item.
    void
    Alters the inventory quantities based on the food items associated with this menu item.
    getFoodInventoryIds(int foodItemId)
    Retrieves the inventory IDs associated with a specified food item.
    Retrieves the names of all food items associated with this menu item.
    getInventoryAmounts(int foodItemId)
    Retrieves the amounts of inventory associated with a specified food item.
    getMenuInventoryIds(int menuItemId)
    Retrieves the inventory IDs associated with a specified menu item.
    int
    Retrieves the menu item ID.
    Retrieves the name of the menu item.
    float
    Retrieves the total price of the menu item.
    boolean
    updateInStockFoodItem(int foodItemId, int inventoryId, double neededQuantity)
    Updates the in-stock status of a food item based on its available inventory.
    boolean
    updateInStockMenuItem(int menuItemId, int inventoryId)
    Updates the in-stock status of a menu item based on its available inventory.

    Methods inherited from class java.lang.Object

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

    • MenuItem

      public MenuItem(int menuitemId, Database database) throws SQLException
      Constructs a MenuItem object with the specified menu item ID and database connection. This constructor retrieves the name and price of the menu item from the database.
      Parameters:
      menuitemId - The ID of the menu item.
      database - The Database object used to connect to the database.
      Throws:
      SQLException - If the menu item cannot be found in the database.
  • Method Details

    • addFoodItem

      public void addFoodItem(int foodItemId)
      Adds a food item ID to the list of food items associated with this menu item.
      Parameters:
      foodItemId - The ID of the food item to be added.
    • getTotal

      public float getTotal()
      Retrieves the total price of the menu item.
      Returns:
      The total price of the menu item as a float.
    • getName

      public String getName()
      Retrieves the name of the menu item.
      Returns:
      The name of the menu item as a String.
    • getMenuItemId

      public int getMenuItemId()
      Retrieves the menu item ID.
      Returns:
      The ID of the menu item as an int.
    • getFoodItemNames

      public ArrayList<String> getFoodItemNames() throws SQLException
      Retrieves the names of all food items associated with this menu item.
      Returns:
      A list of food item names as an ArrayList of Strings.
      Throws:
      SQLException - If an error occurs while accessing the database.
    • alterInventory

      public void alterInventory() throws SQLException
      Alters the inventory quantities based on the food items associated with this menu item. This method updates the inventory quantities by subtracting the amounts used for the food items.
      Throws:
      SQLException - If an error occurs while accessing the database or updating inventory.
    • updateInStockFoodItem

      public boolean updateInStockFoodItem(int foodItemId, int inventoryId, double neededQuantity) throws SQLException
      Updates the in-stock status of a food item based on its available inventory.

      This method checks the current inventory quantity for the specified inventory ID. If the quantity is less than the needed quantity, it updates the in-stock status of the food item to false in the database.

      Parameters:
      foodItemId - the ID of the food item to update
      inventoryId - the ID of the inventory item to check
      neededQuantity - the quantity needed to determine in-stock status
      Returns:
      true if the food item is in stock, false if it is not
      Throws:
      SQLException - if a database access error occurs
    • updateInStockMenuItem

      public boolean updateInStockMenuItem(int menuItemId, int inventoryId) throws SQLException
      Updates the in-stock status of a menu item based on its available inventory.

      This method retrieves the current inventory quantity for the specified inventory ID. If the quantity is less than 1, it updates the in-stock status of the menu item to false in the database.

      Parameters:
      menuItemId - the ID of the menu item to update
      inventoryId - the ID of the inventory item to check
      Returns:
      true if the menu item is in stock, false if it is not
      Throws:
      SQLException - if a database access error occurs
    • getFoodInventoryIds

      public Integer[] getFoodInventoryIds(int foodItemId) throws SQLException
      Retrieves the inventory IDs associated with a specified food item.
      Parameters:
      foodItemId - The ID of the food item for which to retrieve inventory IDs.
      Returns:
      An array of inventory item IDs associated with the specified food item.
      Throws:
      SQLException - If an error occurs while accessing the database.
    • getMenuInventoryIds

      public Integer[] getMenuInventoryIds(int menuItemId) throws SQLException
      Retrieves the inventory IDs associated with a specified menu item.
      Parameters:
      menuItemId - The ID of the food item for which to retrieve inventory IDs.
      Returns:
      An array of inventory item IDs associated with the specified food item.
      Throws:
      SQLException - If an error occurs while accessing the database.
    • getInventoryAmounts

      public Double[] getInventoryAmounts(int foodItemId) throws SQLException
      Retrieves the amounts of inventory associated with a specified food item.
      Parameters:
      foodItemId - The ID of the food item for which to retrieve inventory amounts.
      Returns:
      An array of inventory amounts associated with the specified food item.
      Throws:
      SQLException - If an error occurs while accessing the database.