ashishps1 / awesome-low-level-design

Learn Low Level Design (LLD) and prepare for interviews using free resources.
https://blog.algomaster.io
GNU General Public License v3.0
5.46k stars 1.44k forks source link

Updating the ingredients for coffee vending machine #17

Open naman-ajmera opened 3 weeks ago

naman-ajmera commented 3 weeks ago

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.