Class ShoppingList

java.lang.Object
edu.ntnu.stud.idatt1005.team3.model.ShoppingList

public class ShoppingList extends Object
A class for the CookBook's shopping list. Works with FoodItem class to create a list of food items.
  • Constructor Details

    • ShoppingList

      public ShoppingList(String name, Double quantity, String unit)
      Constructs a new shopping list.
      Parameters:
      name - The name of the food item.
      quantity - The quantity of the food item.
      unit - The unit of the food item.
    • ShoppingList

      public ShoppingList(ArrayList<FoodItem> foodItems)
      Constructs a new shopping list.
      Parameters:
      foodItems - A list of food items.
  • Method Details

    • getName

      public String getName()
    • setName

      public void setName(String name)
    • getQuantity

      public Double getQuantity()
    • setQuantity

      public void setQuantity(Double quantity)
    • getUnit

      public String getUnit()
    • setUnit

      public void setUnit(String unit)
    • addFoodItem

      public void addFoodItem(FoodItem foodItem) throws NullPointerException
      Adds a food item to the shopping list.
      Parameters:
      foodItem - The food item to add.
      Throws:
      NullPointerException
    • removeFoodItem

      public void removeFoodItem(FoodItem foodItem) throws NullPointerException
      Removes a food item from the shopping list.
      Parameters:
      foodItem - The food item to remove.
      Throws:
      NullPointerException
    • findFoodItemByName

      public FoodItem findFoodItemByName(String name)
      Finds a food item in the shopping list by its name.
      Parameters:
      name - The name of the food item to find.
      Returns:
      The food item if it is found, null if it is not found.
    • findFoodItemById

      public FoodItem findFoodItemById(int id)
      Finds a food item in the shopping list by its ID. If the ID is negative, an IllegalArgumentException is thrown.
      Parameters:
      id - The ID of the food item to find.
      Returns:
      The food item if it is found, null if it is not found.
    • printShoppingList

      public void printShoppingList()
      Prints the shopping list.
    • addRecipeToShoppingList

      public void addRecipeToShoppingList(Recipe recipe)
      Returns the list of food items.
      Parameters:
      recipe - The recipe to add to the shopping list.
    • getFoodItems

      public ArrayList<FoodItem> getFoodItems()
      Returns the list of food items.
      Returns:
      The list of food items.