private static void BuyItemByIndex(IVendingMachine machine, int index) { int numberOfItemsThatCanBePurchased = machine.HowManyItemsCanBeBought(index); string nameOfItem = machine.GetCurrentCatalogue()[index].GetItemType().Name; if (numberOfItemsThatCanBePurchased == 0) { Console.WriteLine($"You don't have balance to purchase any {nameOfItem}! Please top up balance from Main Menu"); GoBackToMainMenu(machine); } else { Console.WriteLine($"You can at most buy {numberOfItemsThatCanBePurchased} with your balance of ${machine.GetWalletBalance()}."); Console.WriteLine("How many do you want to buy?"); string input = Console.ReadLine(); if (IsResponseInteger(input)) { int responseInt = GetResponseInteger(input); if (responseInt > 0 && responseInt <= numberOfItemsThatCanBePurchased) { List <IItem> items = machine.PurchaseItem(index, responseInt); Console.WriteLine($"Congratulations! You purchased {responseInt} {nameOfItem}"); DisplayCurrentCatalogue(machine); GoBackToMainMenu(machine); } else { Console.WriteLine("Wrong Input"); GoBackToMainMenu(machine); } } else { Console.WriteLine("Wrong Input"); GoBackToMainMenu(machine); } } }
private static void DisplayCurrentCatalogue(IVendingMachine machine) { Console.WriteLine("======================================================================================"); DisplayCatalogue(machine.GetCurrentCatalogue()); Console.WriteLine("======================================================================================"); }
private static void AddItem(IVendingMachine machine) { Console.WriteLine("1. Add Burger"); Console.WriteLine("2. Add Meatball"); Console.WriteLine("3. Add Water"); Console.WriteLine("4. Add Soda"); Console.WriteLine("5. Add Soft Drink"); Console.WriteLine("6. Add Pistol"); Console.WriteLine("7. Add Sword"); Console.WriteLine("8. Add LightSaber"); string response = Console.ReadLine(); if (IsResponseInteger(response)) { int responseInt = GetResponseInteger(response); Console.WriteLine("Enter the quantity of addition:"); string responseQuantity = Console.ReadLine(); if (IsResponseInteger(responseQuantity)) { int responseQuantityInt = GetResponseInteger(responseQuantity); if (responseQuantityInt > 0) { switch (responseInt) { case 1: AddBurger(machine, responseQuantityInt); break; case 2: AddMeatBall(machine, responseQuantityInt); break; case 3: AddWater(machine, responseQuantityInt); break; case 4: AddSoda(machine, responseQuantityInt); break; case 5: AddSoftDrink(machine, responseQuantityInt); break; case 6: AddPistol(machine, responseQuantityInt); break; case 7: AddSword(machine, responseQuantityInt); break; case 8: AddLightSaber(machine, responseQuantityInt); break; } Console.WriteLine("CONGRATULATIONS! ITEMS ADDED TO CATALOGUE"); DisplayCatalogue(machine.GetCurrentCatalogue()); GoBackToMainMenu(machine); } else { if (WillRetry("Y")) { GoBackToMainMenu(machine); } } } else { if (WillRetry("Y")) { GoBackToMainMenu(machine); } } } else { if (WillRetry("Y")) { GoBackToMainMenu(machine); } } }
private static int DisplayItemsForBuying(IVendingMachine machine) { DisplayCurrentCatalogue(machine); return(machine.GetCurrentCatalogue().Count); }