//Main method to process the inputs of current test case and return result accordingly public void ProcessBeverage(MachineVM model) { if (model != null) { List <Ingredient> itemCount = AvailableIngredient.Ingredients; int freeOutlets = model.outlet; //Check if All ingredients are present for the given beverages; IEnumerable <MissingIngredients> impossibleBeverages = CheckMissingIngredients(model); //Check if it is possible to make each given item through the coffee machine //Print result accordingly foreach (var beverage in model.beverages) { if (impossibleBeverages != null && impossibleBeverages.Any(b => b.beverageName == beverage.name)) { MissingIngredients item = impossibleBeverages.Where(b => b.beverageName == beverage.name).First(); Console.WriteLine(beverage.name + " cannot be prepared because " + item.ingredients.First() + " is not available"); } else { //Check if coffee machine outlets are available if (freeOutlets > 0) { bool canPrepare = true; bool printResult = false; foreach (var item in beverage.ingredients) { if (itemCount.Any(o => o.name == item.name)) { var currentItem = itemCount.FirstOrDefault(o => o.name == item.name); if (currentItem.quantity >= item.quantity) { currentItem.quantity -= item.quantity; } else { canPrepare = false; if (!printResult) { Console.WriteLine(beverage.name + " cannot be prepared because " + item.name + " is not sufficient"); printResult = true; } _repo.UpdateLowIngredientIndicator(currentItem); } } } if (canPrepare) { freeOutlets--; Console.WriteLine(beverage.name + " is prepared"); } } else { Console.WriteLine(beverage.name + " cannot be prepared as free outlet is not available"); } } } } else { Console.WriteLine("Invalid input data"); Console.ReadLine(); return; } Console.WriteLine(); _repo.ShowLowIngredientIndicator(); Console.WriteLine(); Console.WriteLine("Press Enter for next test case...\n\n\n"); Console.ReadLine(); }