Class ShoppingList
java.lang.Object
edu.ntnu.stud.idatt1005.team3.model.ShoppingList
A class for the CookBook's shopping list. Works with
FoodItem class to create a list of food items.
-
Constructor Summary
ConstructorsConstructorDescriptionShoppingList
(String name, Double quantity, String unit) Constructs a new shopping list.ShoppingList
(ArrayList<FoodItem> foodItems) Constructs a new shopping list. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addFoodItem
(FoodItem foodItem) Adds a food item to the shopping list.void
addRecipeToShoppingList
(Recipe recipe) Returns the list of food items.findFoodItemById
(int id) Finds a food item in the shopping list by its ID.findFoodItemByName
(String name) Finds a food item in the shopping list by its name.Returns the list of food items.getName()
getUnit()
void
Prints the shopping list.void
removeFoodItem
(FoodItem foodItem) Removes a food item from the shopping list.void
void
setQuantity
(Double quantity) void
-
Constructor Details
-
ShoppingList
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
Constructs a new shopping list.- Parameters:
foodItems
- A list of food items.
-
-
Method Details
-
getName
-
setName
-
getQuantity
-
setQuantity
-
getUnit
-
setUnit
-
addFoodItem
Adds a food item to the shopping list.- Parameters:
foodItem
- The food item to add.- Throws:
NullPointerException
-
removeFoodItem
Removes a food item from the shopping list.- Parameters:
foodItem
- The food item to remove.- Throws:
NullPointerException
-
findFoodItemByName
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
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
Returns the list of food items.- Parameters:
recipe
- The recipe to add to the shopping list.
-
getFoodItems
Returns the list of food items.- Returns:
- The list of food items.
-