Class MenuItem
java.lang.Object
MenuItem
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 -
Method Summary
Modifier and TypeMethodDescriptionvoid
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.Integer[]
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.Double[]
getInventoryAmounts
(int foodItemId) Retrieves the amounts of inventory associated with a specified food item.Integer[]
getMenuInventoryIds
(int menuItemId) Retrieves the inventory IDs associated with a specified menu item.int
Retrieves the menu item ID.getName()
Retrieves the name of the menu item.float
getTotal()
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.
-
Constructor Details
-
MenuItem
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
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
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
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 updateinventoryId
- the ID of the inventory item to checkneededQuantity
- 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
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 updateinventoryId
- 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
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
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
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.
-