Package Menu

Class MenuData

java.lang.Object
Menu.MenuData

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

    Constructors
    Constructor
    Description
    Constructs a new MenuData object and loads the default menu items from the default_menu_items.txt file.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addMenuItem(int number, String item, String type, double price, boolean availability)
    Adds a new menu item to the menuData HashMap.
    void
    editItem(int itemNum, String newItem, String type, double price, boolean availability)
    Edits an item in the menuData hashmap
    boolean
    getAvailability(int item)
    Returns the item's availability.
    int
    gets the key number of an item
    getName(int itemNum)
    get the name of an item from menu data
    double
    getPrice(int item)
    Returns the item's price.
    int
    Gets the current size of the menuData hash map
    returns a list of menu categories
    boolean
    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)
     

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public void addMenuItem(int number, String item, String type, double price, boolean availability)
      Adds a new menu item to the menuData HashMap.
      Parameters:
      item - the name of the menu item
      type - the type of the menu item (appetizer, entree, side, or dessert)
      price - the price of the menu item
      availability - 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

      public String searchItem(int item)
      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

      public String getName(int itemNum)
      get the name of an item from menu data
      Parameters:
      itemNum - the item number
      Returns:
      the name of the item
    • getTypes

      public String getTypes()
      returns a list of menu categories
      Returns:
      string containing menu categories
    • editItem

      public void editItem(int itemNum, String newItem, String type, double price, boolean availability)
      Edits an item in the menuData hashmap
      Parameters:
      itemNum - The item to edit
      newItem - The new item name
      type - the new item type
      price - the new item price
      availability - the new item availability
    • remItem

      public void remItem(int itemNum)
      Removes an item from the menuData HashMap.
      Parameters:
      itemNum - The item to remove
    • itemRestore

      public void itemRestore(int itemNum, String newItem)
      Restores an item from backup into the menuData HashMap.
      Parameters:
      itemNum - The item number to restore
      newItem - The edited item to remove
    • getItemNum

      public int getItemNum(String item)
      gets the key number of an item
      Parameters:
      item - the item's name
      Returns:
      the integer place of the item in the menuData hashmap