Skip to content
Snippets Groups Projects
Commit bcf24370 authored by HSoreide's avatar HSoreide
Browse files

Write first draft of Ingredient class

parent 7652ca5e
No related branches found
No related tags found
1 merge request!7Create food and recipe classes with tests
package no.ntnu.idatt1002.demo.data.recipes;
public class Ingredient {
private FoodItem foodType;
private double amount;
private MeasuringUnit unit;
public Ingredient(FoodItem ingredient, double amount, MeasuringUnit unit) {
if(ingredient == null | amount < 0.0f | unit == null) {
throw new IllegalArgumentException("The ingredient must have a type, amount and measuring unit.");
}
this.foodType = ingredient;
this.amount = amount;
this.unit = unit;
}
public FoodItem getFoodType() {
return foodType;
}
public void setFoodType(FoodItem foodType) {
if(foodType == null) {
throw new IllegalArgumentException("The food type must be set to a valid value of FoodItem.");
}
this.foodType = foodType;
}
public double getAmount() {
return amount;
}
public void setAmount(double amount) {
if(amount < 0.0f) {
throw new IllegalArgumentException("The amount of an ingredient cannot be zero or negative.");
}
this.amount = amount;
}
public MeasuringUnit getUnit() {
return unit;
}
public void setUnit(MeasuringUnit unit) {
if(unit == null) {
throw new IllegalArgumentException("The food's measuring unit must be set to a valid value of MeasuringUnit.");
}
this.unit = unit;
}
@Override
public String toString() {
return "Ingredient{" +
"foodType=" + foodType.label +
", amount=" + amount +
", unit=" + unit.label +
'}';
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment