You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The UpdateIngredients method is updating the ingredients used by that coffee, shouldn't it update the ingredients map and its quantity after dispensing coffee.
The text was updated successfully, but these errors were encountered:
private void updateIngredients(Coffee coffee) {
for(Map.Entry<Ingredient, Integer> ingredientMap : coffee.getRecipe().entrySet()){
Ingredient ingredient = ingredientMap.getKey();
int quantity = ingredientMap.getValue(); //this is the quantity of the ingredient in the coffee's recipe
ingredient.updateQuantity(-quantity); //here, we update the overall quantity of the ingredient in the vending machine
}
}
For example,
let's assume espresso, Recipe contains Ingredient and quantity
here, the Ingredient has a quantity, which is the overall quantity
and the quantity is the quantity in of the ingredient in espresso
private void updateIngredients(Coffee coffee) { for (Map.Entry<Ingredient, Integer> entry : coffee.getRecipe().entrySet()) { Ingredient ingredient = entry.getKey(); int requiredQuantity = entry.getValue(); ingredient.updateQuantity(-requiredQuantity); if (ingredient.getQuantity() < 3) { System.out.println("Low inventory alert: " + ingredient.getName()); } } }
The UpdateIngredients method is updating the ingredients used by that coffee, shouldn't it update the ingredients map and its quantity after dispensing coffee.
The text was updated successfully, but these errors were encountered: