static void Main(string[] args) { int paymentType = 0, id = 0, moreProducts = 1; PaymentTerminal payConsole = new PaymentTerminal(); ContainableItem lays = new ContainableItem(new Product(new ProductCategory("Snacks"), "Lays", 50, 10, 3), new Position(1, 1, 2, 2)); ContainableItem M_m = new ContainableItem(new Product(new ProductCategory("Sweets"), "M&M", 30, 20, 1), new Position(2, 1, 1, 1)); ContainableItem milk = new ContainableItem(new Product(new ProductCategory("Milk Products"), "Milk", 20, 40, 2), new Position(3, 1, 2, 3)); ContainableItemsCollection.AddItem(lays); ContainableItemsCollection.AddItem(M_m); ContainableItemsCollection.AddItem(milk); ContainableItemsCollection.ShowList(); while (moreProducts != 0) { try { Console.WriteLine("Product id:"); id = Int32.Parse(Console.ReadLine()); Console.WriteLine("How do you want to pay? 1-Coins, 2-Banknote, 3-CreditCard, 0-Back"); paymentType = Int32.Parse(Console.ReadLine()); } catch (Exception e) { Console.WriteLine(e); } switch (paymentType) { case 1: Payment payCoin = new Coin(); payConsole.Pay(id, payCoin); break; case 2: Payment payBanknote = new Banknote(); payConsole.Pay(id, payBanknote); break; case 3: Payment payCreditCard = new CreditCard(); payConsole.Pay(id, payCreditCard); break; default: break; } Console.WriteLine(Dispenser.Message); try { Console.WriteLine("Do you want to buy another product? 1-Yes 0-No"); moreProducts = Int32.Parse(Console.ReadLine()); } catch (Exception e) { Console.WriteLine(e); } } DataAcquisition.GetInstance().GenerateReports(); }
static void Main(string[] args) { BuyProduct: PaymentTerminal paymentTerminal = new PaymentTerminal(); Payment payment = paymentTerminal.GetPayment(); Console.WriteLine($"Payment type selected: {payment.ToString()}"); Console.WriteLine("\nAvailable products:"); foreach (ContainableItem containableItem in VendingMachine.Instance.Items) { Console.WriteLine($"Id: {containableItem.Position.Id}\t ProductName: {containableItem.Product.Name}" + $"\t Price: {containableItem.Product.Price}"); } int id = GetSelectedId(); paymentTerminal.Pay(id, payment); Console.WriteLine("Try again? Y/N"); string answer = Console.ReadLine(); if (answer.ToUpper().Equals("Y")) { goto BuyProduct; } GenerateReports(); Console.ReadKey(); }
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 SaleOperation(ContainableItemsCollection produse, PaymentTerminal paymentTerminal) { int idProduct = -1; int option = -1; while (option != 0 && idProduct != 0) { Node temp = produse.GetFirst(); for (int i = 0; i < produse.Count(); i++) { Console.WriteLine(temp.ContainableItem.ToString()); temp = temp.To; } Console.WriteLine("ID Product:"); int.TryParse(Console.ReadLine(), out idProduct); Console.WriteLine("Payment Option: (1-Coins;2-Banknote;3-Card)"); int.TryParse(Console.ReadLine(), out option); paymentTerminal.Pay(idProduct, option); } }
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); }