Class Ingredient
java.lang.Object
no.ntnu.idatt1002.demo.data.recipes.Ingredient
- Direct Known Subclasses:
RecipeIngredient
The Ingredient class represents an ingredient that can be part of a recipe in real life and/or be
available to the user in real life. When the ingredient is part of a recipe, the subclass called
RecipeIngredient is used. An ingredient belongs to a food type among the values of the FoodItem
enum class. Examples are onion, tomato, spaghetti, chicken etc. The ingredient is provided in a
specific amount and unit of measure.
- Author:
- hannesofie
-
Constructor Summary
ConstructorsConstructorDescriptionIngredient
(FoodItem ingredient, double amount, MeasuringUnit unit) The constructor of a new Ingredient object takes in three mandatory fields; ingredient type as defined in the enum class FoodItem, an amount and a unit of measure defined in the enum class MeasuringUnit. -
Method Summary
Modifier and TypeMethodDescriptionboolean
The method checks if a given object is equal to the ingredient object.double
The method returns the amount of an ingredient as the datatype double.The method returns the food type that the ingredient belongs to among the valid types in the FoodItem enum class.getUnit()
The method returns the unit of measure of the ingredient as a value of the MeasuringUnit enum class.void
setAmount
(double amount) The method takes in a new amount as a double and sets the ingredient's amount field equal to this value.void
setFoodType
(FoodItem foodType) The method takes in a value of the FoodItem enum and sets the ingredient's foodType field equal to this constant.void
setUnit
(MeasuringUnit unit) The method takes in a value of the MeasuringUnit enum class and sets the ingredient's unit equal to this value.toString()
The method returns a String representation of an Ingredient object, listing its type, amount and unit.
-
Constructor Details
-
Ingredient
The constructor of a new Ingredient object takes in three mandatory fields; ingredient type as defined in the enum class FoodItem, an amount and a unit of measure defined in the enum class MeasuringUnit. The amount must be a positive number.- Parameters:
ingredient
- What type of food the ingredient is.amount
- The amount of the ingredient.unit
- The unit of measure of the given amount of the ingredient.
-
-
Method Details
-
getFoodType
The method returns the food type that the ingredient belongs to among the valid types in the FoodItem enum class.- Returns:
- What type of food the ingredient is.
-
setFoodType
The method takes in a value of the FoodItem enum and sets the ingredient's foodType field equal to this constant. If null is given an IllegalArgumentException is thrown.- Parameters:
foodType
- The type of food to assign the ingredient to.
-
getAmount
public double getAmount()The method returns the amount of an ingredient as the datatype double.- Returns:
- The amount of an ingredient as double.
-
setAmount
public void setAmount(double amount) The method takes in a new amount as a double and sets the ingredient's amount field equal to this value. If the provided value is not a positive double, an IllegalArgumentException is thrown.- Parameters:
amount
- The amount of an ingredient as double.
-
getUnit
The method returns the unit of measure of the ingredient as a value of the MeasuringUnit enum class.- Returns:
- The unit of measure of the given amount of the ingredient.
-
setUnit
The method takes in a value of the MeasuringUnit enum class and sets the ingredient's unit equal to this value.- Parameters:
unit
- The unit of measure of the given amount of the ingredient.
-
toString
The method returns a String representation of an Ingredient object, listing its type, amount and unit. -
equals
The method checks if a given object is equal to the ingredient object. If the object is of the same class as well as having the same value for each class field, the object is equal to the Ingredient.
-