Class Ingredient

java.lang.Object
no.ntnu.idatt1002.demo.data.recipes.Ingredient
Direct Known Subclasses:
RecipeIngredient

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

    Constructors
    Constructor
    Description
    Ingredient(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 Type
    Method
    Description
    boolean
    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.
    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
    The method takes in a value of the FoodItem enum and sets the ingredient's foodType field equal to this constant.
    void
    The method takes in a value of the MeasuringUnit enum class and sets the ingredient's unit equal to this value.
    The method returns a String representation of an Ingredient object, listing its type, amount and unit.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Ingredient

      public Ingredient(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. 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

      public FoodItem 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

      public 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. 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

      public MeasuringUnit 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

      public 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.
      Parameters:
      unit - The unit of measure of the given amount of the ingredient.
    • toString

      public String toString()
      The method returns a String representation of an Ingredient object, listing its type, amount and unit.
      Overrides:
      toString in class Object
      Returns:
      A String representation of the ingredient object.
    • equals

      public boolean equals(Object o)
      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.
      Overrides:
      equals in class Object
      Parameters:
      o - An Object to which the Ingredient should be compared.
      Returns:
      True if the object is equivalent to the Ingredient, false otherwise.