static void Main(string[] args) { List <VendingItem> inventory = new List <VendingItem>(); // Product loader pulls the data from the loading file. inventory = ProductLoader.Loader(); // Initializes "Vending Machine" and "Money Manager" VendingMachine vendingMachine = new VendingMachine(inventory); MoneyManager moneyManager = new MoneyManager(); // Loads Main Menu to start user experience. MainMenu menu = new MainMenu(vendingMachine, moneyManager); menu.Run(); }
//method to dispense product public string DispenseProduct(string selection) { //set selection to uppercase string upperSelection = selection.ToUpper(); if (inventoryItems.ContainsKey(upperSelection)) { //variables for product in the inventory items dictionary int remainingProduct = inventoryItems[upperSelection].ProductRemaining; decimal priceOfProduct = inventoryItems[upperSelection].ProductPrice; string typeOfProduct = inventoryItems[upperSelection].ProductType; string nameOfProduct = inventoryItems[upperSelection].ProductName; //if not stock left, show sold out if (remainingProduct == 0) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("\n\nSOLD OUT"); Console.ForegroundColor = ConsoleColor.Cyan; Console.Read(); } //check to make sure enough money was entered into the machine //if product is more than balance, not enough money else if (priceOfProduct > this.Money.Balance) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("\n\nINSUFFICIENT BALANCE!"); Console.ForegroundColor = ConsoleColor.Cyan; Console.Read(); } else { //vendItem is ProductName and ProductPrice //set easier variabless string vendItem = ($"{nameOfProduct}, ${priceOfProduct}"); decimal moneySpent = this.Money.Balance - priceOfProduct; //01/01/2016 12:01:25 PM Cowtales B2 $8.50 $7.50 //generate log MoneyManager.GenerateLog($"{nameOfProduct} {upperSelection}", this.Money.Balance, moneySpent); // removes 1 from stock inventoryItems[upperSelection].ProductRemaining -= 1; //remove cost of product from balance this.Money.RemoveMoney(priceOfProduct); // return item name, cost, money remaining and message //if (typeOfProduct == "Candy") //{ // return ($"\n\nThank You! \n{vendItem}\n\tYour remaing balance is: {moneySpent:c}\n\t\t{Candy.DisplayMessage}"); //} //if (typeOfProduct == "Chip") //{ // return ($"\n\nThank You! \n{vendItem}\n\tYour remaing balance is: {moneySpent:c}\n\t\t{Chips.DisplayMessage}"); //} //if (typeOfProduct == "Drink") //{ // return ($"\n\nThank You! \n{vendItem}\n\tYour remaing balance is: {moneySpent:c}\n\t\t{Drink.DisplayMessage}"); //} //if (typeOfProduct == "Gum") //{ // return ($"\n\nThank You! \n{vendItem}\n\tYour remaing balance is: {moneySpent:c}\n\t\t{Gum.DisplayMessage}"); //} return($"\n\nThank You! \n{vendItem}\n\tYour remaing balance is: {moneySpent:c}\n\t\t{inventoryItems[upperSelection].DisplayMessage}"); } } return("Invalid Selection"); }