Open naman-ajmera opened 5 months ago
No, the code is correct, Let me explain
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) { coffee.getRecipe().forEach((ingredient, requiredQuantity) -> { ingredient.updateQuantity(-requiredQuantity);
if (ingredient.getQuantity() < 3) {
System.out.println("Low inventory alert: " + ingredient.getName());
}
});
} pls check this
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.