public static bool FinishPurchase() { foreach (var item in shoppingCart) { Console.WriteLine($"Cart item: {item.ProductName}\tPrice: {item.Price}\nDescription: {item.Description}\n\n"); if (item is Beverage) { Console.ForegroundColor = ConsoleColor.Blue; Beverage.Use(item.ProductName); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine("\n"); } if (item is Food) { Console.ForegroundColor = ConsoleColor.Green; Food.Use(item.ProductName); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine("\n"); } if (item is Snacks) { Console.ForegroundColor = ConsoleColor.Yellow; Snacks.Use(item.ProductName); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine("\n"); } } Console.WriteLine("Here's your change! {0}", CustomerWallet); return(insert = false); }
static void Main(string[] args) { Console.ReadLine(); do { Console.WriteLine(" Main Menue "); Console.WriteLine("==========================="); Console.WriteLine("1.Drink Cost:10"); Console.WriteLine("2.Snacks Cost:30"); Console.WriteLine("3.Food Cost:30"); Console.WriteLine("4.Quite"); Console.WriteLine("1,2,5,10 (Kr) Coins are acceptable only"); Console.WriteLine("Enter your choice"); int ch = Int32.Parse(Console.ReadLine()); switch (ch) { case 1: Product d = new Drink(); d.Put(); break; case 2: Product s = new Snacks(); s.Put(); break; case 3: Product f = new Food(); f.Put(); break; case 4: break; } Console.WriteLine("You want to order again Y/N"); }while (Console.ReadLine().ToUpper() == "Y"); //} //else //{ // Console.WriteLine("invalid money"); // Console.WriteLine("try again "); // Console.ReadLine(); //} }
//Adding Prdoucts to the inventory and Displaying them. public static void InitializeProducts() { Console.WriteLine("\n Drinks In the machine"); Console.WriteLine("-----------------------"); Drinks coke = new Drinks("Coco Cola", 1011, 10, "Refreshing Drink! Enjoy it cold"); coke.Examine(); drinkslist.Add(coke); Drinks fanta = new Drinks("Fanta Lime", 1012, 10, "Refreshing Drink! Enjoy it cold"); fanta.Examine(); drinkslist.Add(fanta); Drinks water = new Drinks("Vitamin Water", 1013, 24, "Energy Drink to increase your vitamins"); water.Examine(); drinkslist.Add(water); Console.WriteLine("*******************************"); Console.WriteLine("\n Snacks In the machine"); Console.WriteLine("-----------------------"); Snacks pringles = new Snacks("Pringles", 1021, 9, "Classic Salt Flavoured Potato Chips"); pringles.Examine(); snackslist.Add(pringles); Snacks lays = new Snacks("Lays Classic", 1022, 20, "Cream and Onion Flavoured Potato Chips"); lays.Examine(); snackslist.Add(lays); Snacks cheez = new Snacks("Cheez Doodles", 1023, 13, "Cheese Flavoured Balls"); cheez.Examine(); snackslist.Add(cheez); Console.WriteLine("*******************************"); Console.WriteLine("\n Food items In the machine"); Console.WriteLine("-----------------------"); Food mealbar = new Food("Nature diet Protien Meal bar", 1031, 26, "Diet protien bar with Crunchy chocolate "); mealbar.Examine(); foodlist.Add(mealbar); Food tramezzino = new Food("Tramezzino - Tuna Sandwich", 1032, 40, "Tuna sandwich with green Olives, Can be used in Microwave"); tramezzino.Examine(); foodlist.Add(tramezzino); Food panini = new Food("Panini -Chicken Sandwich", 1033, 55, "Roasted Chicken sandwich with tomotoes, Can be used in Microwave"); panini.Examine(); foodlist.Add(panini); Console.WriteLine("*******************************"); Console.WriteLine("\n Chocolates In the machine"); Console.WriteLine("-----------------------"); Chocolate snickers = new Chocolate("Snickers", 1041, 13, "Nutty Chocolate bar!"); snickers.Examine(); chocolatelist.Add(snickers); Chocolate bounty = new Chocolate("Bounty", 1042, 13, "Coconut filled Chocolate bar!"); bounty.Examine(); chocolatelist.Add(bounty); Chocolate kex = new Chocolate("Kex Choco", 1043, 12, "Crunchy Wafer Chocolate!"); kex.Examine(); chocolatelist.Add(kex); }
static void Main(string[] args) { Fruits Banana = new Fruits { ProductName = "Banana", ProductPrice = 5, ProductInfo = "A yellow 15 cm slightly curved fruit\t", ProductId = 1, HowToConsume = "You have to peel this fruit." }; Fruits Apple = new Fruits { ProductName = "Golden Delisious", ProductPrice = 6, ProductInfo = "A yellov-green apple.\t\t\t", ProductId = 2, HowToConsume = "You have to wash this fruit before eating it." }; Drinks Coffee = new Drinks { ProductName = "Black Coffee", ProductPrice = 19, ProductInfo = "Coffee made from medium roasted beans.\t", ProductId = 3, Temperature = 40, Volume = 2, VolumeSet = "dl", HowToConsume = "Beware! This product could be warm to the touch." }; Drinks CokaCola = new Drinks { ProductName = "Coka Cola", ProductPrice = 14, ProductInfo = "Coka-cola from the Coka-Cola Company.\t", ProductId = 4, Temperature = 5, Volume = 2, VolumeSet = "dl", HowToConsume = "You need to uncork this bottle before drinking it." }; Drinks Sprite = new Drinks { ProductName = "Sprite", ProductPrice = 16, ProductInfo = "Sprite from the Coka-Cola Company.\t", ProductId = 5, Temperature = 5, Volume = 2, VolumeSet = "dl", HowToConsume = "You need to uncork this bottle before drinking it." }; Snacks Japp = new Snacks { ProductName = "Japp", ProductPrice = 7, ProductInfo = "Chocklate covered peanuts.\t\t", ProductId = 6, Weight = 200, WeightSet = "grams", HowToConsume = "You need to unwrap this chokolate bar before eating it." }; Snacks Daim = new Snacks { ProductName = "Daim", ProductPrice = 8, ProductInfo = "Chocklate covered caramell.\t\t", ProductId = 7, Weight = 150, WeightSet = "grams", HowToConsume = "You need to unwrap this chokolate bar before eating it." }; List <Products> allProducts = new List <Products> { Banana, Apple, Coffee, CokaCola, Sprite, Japp, Daim }; BuyingBasket MyBasket = new BuyingBasket(); string chosenProduct = ""; bool exitVendingMachine = false; int numberOfItemsToAdd = 0; int valueOfBasket = 0; int totalAmountOfMoney = 0; int change = 0; int menuChoise = 0; do { Console.Clear(); Console.WriteLine("Welcome to Vending Machines Inc! Have a drink and snack and be refreshed!"); Console.WriteLine($"You have {totalAmountOfMoney} SEK to buy for."); Console.WriteLine($"You have items for a value of {valueOfBasket} SEK in your basket"); Console.WriteLine("1. Insert money."); Console.WriteLine("2. List the available products."); Console.WriteLine("3. Examine a product."); Console.WriteLine("4. Show my basket."); Console.WriteLine("5. Add a product to basket."); Console.WriteLine("6. Cancel a purchase."); Console.WriteLine("7. Make a purchase."); Console.WriteLine("8. Exit the vending machine."); Console.Write($"Your choise is: "); menuChoise = 0; try { menuChoise = (Convert.ToInt32(Console.ReadLine())); } catch (FormatException) { Console.WriteLine("You typed a letter instead of a number. Try again."); } switch (menuChoise) { case 1: //lets the user add money to the vending machine totalAmountOfMoney = totalAmountOfMoney + AddMoney(totalAmountOfMoney); break; case 2: //lists the current items that can be bought. Console.Clear(); Console.WriteLine("The following products is available in this vending machine.\nName\t\t\tDescription\t\t\t\tPrice"); Products.Examine(allProducts); Console.WriteLine("Please hit any key to continue"); Console.ReadKey(); break; case 3: //shows more detailed info about a product do { Console.Clear(); Console.WriteLine("What product of the following would you like to take a closer look at? \nPlease type the name of the product."); Products.Examine(allProducts); Console.Write("What item would you like to look closer at: "); try { chosenProduct = Console.ReadLine(); } catch (FormatException) { Console.WriteLine("You have not typed in a correct name or amount. Please try again."); } } while (chosenProduct == ""); chosenProduct = ValidateChosenProduct(chosenProduct); foreach (var element in allProducts) { if ((chosenProduct == element.ProductName) && (element is Drinks)) { element.ShowProductSpecifics(chosenProduct, allProducts); } else if ((chosenProduct == element.ProductName) && (element is Fruits)) { element.ShowProductSpecifics(chosenProduct, allProducts); } else if ((chosenProduct == element.ProductName) && (element is Snacks)) { element.ShowProductSpecifics(chosenProduct, allProducts); } } //Console.ReadKey(); break; case 4: //shows the contents of the basket valueOfBasket = MyBasket.ShowBasket(MyBasket.MyBasketContents); break; case 5: //lets the user add items to the basket. do { Console.Clear(); Console.WriteLine("What product would you like to add to your buying basket? \nPlease type the name of the product."); Products.Examine(allProducts); Console.Write("What item would you like to add: "); try { chosenProduct = Console.ReadLine(); Console.Write($"How many {chosenProduct} would you like to have? "); numberOfItemsToAdd = Convert.ToInt32(Console.ReadLine()); } catch (FormatException) { Console.WriteLine("You have not typed in a correct name or amount. Please try again."); } } while (chosenProduct == ""); chosenProduct = ValidateChosenProduct(chosenProduct); MyBasket.MyBasketContents.Add(MyBasket.AddProductToBasket(chosenProduct, numberOfItemsToAdd, allProducts, MyBasket.MyBasketContents)); valueOfBasket = MyBasket.BasketValue(MyBasket.MyBasketContents); break; case 6: MyBasket.MyBasketContents.Clear(); valueOfBasket = 0; MyBasket.Purchase(totalAmountOfMoney); totalAmountOfMoney = 0; break; case 7: //let the user get the items so far chosen and subtracts the value of the items from the inserted money. if (totalAmountOfMoney <= valueOfBasket) { Console.WriteLine("You have not inserted enough money!!"); Console.ReadKey(); break; } change = totalAmountOfMoney - valueOfBasket; totalAmountOfMoney = 0; valueOfBasket = 0; //Console.ReadKey(); MyBasket.Purchase(change); Products.Use(MyBasket.MyBasketContents, allProducts); MyBasket.MyBasketContents.Clear(); break; case 8: //exits the vending machine. exitVendingMachine = true; break; default: Console.WriteLine("You typed in a choise the vending machine dont suppport, please make another choise."); Console.ReadKey(); break; } } while (exitVendingMachine == false); }