public static void MakeAPurchase(PaymentTerminal terminal) { System.Console.WriteLine("Please select the ID of the desired product from the list below:"); for (int index = 0; index < terminal.dispenser.containableItemsCollection.Count(); index++) { System.Console.WriteLine($"ID: {terminal.dispenser.containableItemsCollection.Get(index).Position.ID} -> {terminal.dispenser.containableItemsCollection.Get(index).Product.ToString()}"); } System.Console.WriteLine("Your option: "); int option = Convert.ToInt32(Console.ReadLine()); System.Console.WriteLine("Choose payment method:"); System.Console.WriteLine("1) Banknotes"); System.Console.WriteLine("2) Coins"); System.Console.WriteLine("3) Credit Card"); int paymentOption = Convert.ToInt32(Console.ReadLine()); System.Console.WriteLine("Please insert money!"); int moneyInserted = Convert.ToInt32(Console.ReadLine()); Payment payment = null; switch (paymentOption) { default: System.Console.WriteLine("Invalid option!"); break; case 1: payment = new BanknotePayment(moneyInserted); break; case 2: payment = new CoinPayment(moneyInserted); break; case 3: payment = new CreditCardPayment(moneyInserted); break; } try { terminal.Pay(option, payment); System.Console.WriteLine($"{terminal.dispenser.dispensedProduct.ToString()}"); } catch (VendingMachine.CreditCardRejectedException e) { System.Console.WriteLine("Credit card rejected!"); } catch (VendingMachine.NotEnoughMoneyException e) { System.Console.WriteLine($"Not enough money! Refund: {terminal.Refund}"); } catch (VendingMachine.ProductUnavailableException e) { System.Console.WriteLine("Product unavailable!"); } }
static void Main(string[] args) { ProductCategory productCategory1 = new ProductCategory() { Name = "Ciocolata" }; ProductCategory productCategory2 = new ProductCategory() { Name = "Suc" }; Position position1 = new Position() { Row = 1, Column = 2, Size = 3, Id = 1 }; Position position2 = new Position() { Row = 2, Column = 1, Size = 4, Id = 2 }; Product product1 = new Product() { Category = productCategory1, Price = 4.5, Quantity = 3, Name = "Milka" }; Product product2 = new Product() { Category = productCategory2, Price = 6.3, Quantity = 2, Name = "Sprite" }; Product product3 = new Product() { Category = productCategory1, Price = 3.1, Quantity = 1, Name = "Poiana" }; ContainableItem containableItem1 = new ContainableItem() { Position = position2, Product = product1 }; ContainableItem containableItem2 = new ContainableItem() { Position = position1, Product = product2 }; ContainableItem containableItem3 = new ContainableItem() { Position = position1, Product = product3 }; ContainableItemsCollection containableItemsCollection = new ContainableItemsCollection(); Dispenser dispenser = new Dispenser(containableItemsCollection); PaymentTerminal paymentTerminal = new PaymentTerminal(dispenser); Payment payment = new BanknotePayment(); containableItemsCollection.AddProduct(containableItem1); containableItemsCollection.AddProduct(containableItem2); containableItemsCollection.AddProduct(containableItem3); // containableItemsCollection.RemoveAt(2); for (int i = 0; i < containableItemsCollection.Count(); i++) { Console.WriteLine(containableItemsCollection.GetItem(i)); } Console.WriteLine("After dispense:"); paymentTerminal.Pay(0, payment, 50); //Product dispenseProduct = dispenser.Dispense(0); // Console.WriteLine(dispenseProduct); }