Package Menu
Class MenuData
java.lang.Object
Menu.MenuData
The MenuData class represents a collection of menu items and provides methods to load default menu items, add new menu items,
and print the menu in a formatted way. The class uses a HashMap to store MenuItem objects, with the name of the menu item
as the key and the MenuItem object as the value.
-
Constructor Summary
ConstructorsConstructorDescriptionMenuData()
Constructs a new MenuData object and loads the default menu items from the default_menu_items.txt file. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addMenuItem
(int number, String item, String type, double price, boolean availability) Adds a new menu item to the menuData HashMap.void
Edits an item in the menuData hashmapboolean
getAvailability
(int item) Returns the item's availability.int
getItemNum
(String item) gets the key number of an itemgetName
(int itemNum) get the name of an item from menu datadouble
getPrice
(int item) Returns the item's price.int
getSize()
Gets the current size of the menuData hash mapgetTypes()
returns a list of menu categoriesboolean
isItem
(int itemNum) Checks whether an item with the specified name exists in the menuData map.void
itemRestore
(int itemNum, String newItem) Restores an item from backup into the menuData HashMap.void
Prints the menu items in a formatted way, grouped by type (appetizers, entrees, sides, and desserts).void
remItem
(int itemNum) Removes an item from the menuData HashMap.searchItem
(int item) Searches for an item's data in the menuData HashMap.void
setAvailability
(int item, boolean availability)
-
Constructor Details
-
MenuData
public MenuData()Constructs a new MenuData object and loads the default menu items from the default_menu_items.txt file.
-
-
Method Details
-
addMenuItem
Adds a new menu item to the menuData HashMap.- Parameters:
item
- the name of the menu itemtype
- the type of the menu item (appetizer, entree, side, or dessert)price
- the price of the menu itemavailability
- the availability of the menu item (true if available, false if not available)
-
getSize
public int getSize()Gets the current size of the menuData hash map- Returns:
- the size of the menuData hashmap
-
isItem
public boolean isItem(int itemNum) Checks whether an item with the specified name exists in the menuData map.- Parameters:
itemNum
- the number of the item to check- Returns:
- true if the menuData map contains an entry with the specified item, false otherwise
-
searchItem
Searches for an item's data in the menuData HashMap.- Parameters:
item
- the item to search for- Returns:
- the item's data if found, otherwise a message that the item was not found
-
getPrice
public double getPrice(int item) Returns the item's price.- Parameters:
item
- the item to get the price of.- Returns:
- The item's price.
-
getAvailability
public boolean getAvailability(int item) Returns the item's availability.- Parameters:
item
- the item to get the availability of.- Returns:
- The item's availability.
-
setAvailability
public void setAvailability(int item, boolean availability) -
printMenu
public void printMenu()Prints the menu items in a formatted way, grouped by type (appetizers, entrees, sides, and desserts). -
getName
get the name of an item from menu data- Parameters:
itemNum
- the item number- Returns:
- the name of the item
-
getTypes
returns a list of menu categories- Returns:
- string containing menu categories
-
editItem
Edits an item in the menuData hashmap- Parameters:
itemNum
- The item to editnewItem
- The new item nametype
- the new item typeprice
- the new item priceavailability
- the new item availability
-
remItem
public void remItem(int itemNum) Removes an item from the menuData HashMap.- Parameters:
itemNum
- The item to remove
-
itemRestore
Restores an item from backup into the menuData HashMap.- Parameters:
itemNum
- The item number to restorenewItem
- The edited item to remove
-
getItemNum
gets the key number of an item- Parameters:
item
- the item's name- Returns:
- the integer place of the item in the menuData hashmap
-