Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Product product = new Product();

            product.Category = new ProductCategory("SWEETS");
            product.Name     = "Milka";
            product.Price    = 5;
            product.Size     = 1;
            Position        position        = new Position(2, 2, 1, 29);
            ContainableItem containableItem = new ContainableItem(position, product);

            Product product2 = new Product();

            product2.Category = new ProductCategory("Snacks");
            product2.Name     = "Lays";
            product2.Price    = 3;
            product2.Size     = 1;
            Position        position2        = new Position(2, 2, 1, 25);
            ContainableItem containableItem2 = new ContainableItem(position2, product2);

            ContainableItemCollection collection = new ContainableItemCollection();

            collection.add(containableItem);
            collection.add(containableItem2);
            Dispenser dispenser = new Dispenser(collection);

            Console.WriteLine(dispenser.dispense(29).Name);
        }
 public PaymentTerminal(Dispenser dispenser)
 {
     this.dispenser    = dispenser;
     this.paymentEvent = new PaymentEvent();
     this.paymentEvent.Subscribe(dispenser);
     this.paymentEvent.Subscribe(dispenser.repository);
 }
Ejemplo n.º 3
0
 public PaymentTerminal()
 {
     paymentEvent    = new PaymentEvent();
     dispenser       = new Dispenser();
     dataAcquisition = DataAcquisition.Instance;
     paymentEvent.Subscribe(dispenser);
     paymentEvent.Subscribe(dataAcquisition);
 }
Ejemplo n.º 4
0
 public PaymentTerminal(Dispenser dispenser)
 {
     this.dispenser = dispenser;
     paymentEvent   = new PaymentEvent();
     paymentEvent.Subscribe(dispenser);
     data = Data.Instance;
     paymentEvent.Subscribe(data);
     data.Collection = dispenser.Collection;
 }
Ejemplo n.º 5
0
 public float GetItem(Dispenser band, float money)
 {
     if (band.Product.price <= money)
     {
         money -= (float)band.Product.price;
         Remove(band);
     }
     return(money);
 }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            ContainableItemsCollection produse = new ContainableItemsCollection();

            produse.LocationOverlap += LocationOverlap;
            AddingProducts(produse);
            Dispenser       dispenser       = new Dispenser(produse);
            PaymentTerminal paymentTerminal = new PaymentTerminal(dispenser);

            VendingMachineConsole(produse, paymentTerminal);
        }
Ejemplo n.º 7
0
 public bool Remove(Dispenser band)
 {
     if (band.Dispose())
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 8
0
        /*
         * //Categories
         * static ProductCategory Soda = new ProductCategory("Soda");
         * static ProductCategory Snack = new ProductCategory("Snack");
         * static ProductCategory Sandwich = new ProductCategory("Sandwich");
         *
         * //Products
         * // Soda
         * static Product CocaCola = new Product("Coca-Cola 250", 0.5, 1, Soda);
         * static Product Sprite = new Product("Sprite 330", 0.75, 2, Soda);
         * static Product Fanta = new Product("Fanta 500", 1, 3, Soda);
         *
         *
         * // Snack
         * static Product Snickers = new Product("Snickers", 0.75, 1, Snack);
         * static Product Cheetos = new Product("Cheetos", 1, 2, Snack);
         * static Product Lays = new Product("Lays", 1.5, 3, Snack);
         *
         * // Sandwich
         * static Product BaconSandwich = new Product("Bacon Sandwich", 1, 1, Sandwich);
         * static Product Crisp = new Product("Crisp",1.5, 2, Sandwich);
         * static Product Kebab = new Product("Kebab", 2, 3, Sandwich);
         *
         *
         * //ContainableItem
         * ContainableItem sprite = new ContainableItem(Sprite);
         * ContainableItem cocacola = new ContainableItem(CocaCola);
         * ContainableItem fanta = new ContainableItem(Fanta);
         * ContainableItem snickers = new ContainableItem(Snickers);
         * ContainableItem cheetos = new ContainableItem(Cheetos);
         * ContainableItem lays = new ContainableItem(Lays);
         * ContainableItem baconSandwich = new ContainableItem(BaconSandwich);
         * ContainableItem crisp = new ContainableItem(Crisp);
         * ContainableItem kebab = new ContainableItem(Kebab);
         */
        //Dispensers

        /*
         * Dispenser cocaColaBand = new Dispenser(1);
         * Dispenser spriteBand = new Dispenser(2);
         * Dispenser fantaBand = new Dispenser(3);
         *
         * Dispenser snickersBand = new Dispenser(1);
         * Dispenser cheetosBand = new Dispenser(2);
         * Dispenser laysBand = new Dispenser(3);
         *
         * Dispenser baconSandwichBand = new Dispenser(1);
         * Dispenser CrispBand = new Dispenser(2);
         * Dispenser KebabBand = new Dispenser(3);
         */

        public bool Add(Dispenser band)
        {
            if (band.AddItem())
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 9
0
 static private void DeclarationsAndInitializations()
 {
     itemArray = new ContainableItem[] {
         new ContainableItem(new Product("Poiana cu lapte", 5.2m, new Category("mancare"), 5), new Position(1, 1, 1, 1)),
         new ContainableItem(new Product("Nestea 0.5L", 10m, new Category("bautura"), 2), new Position(1, 2, 2, 2)),
         new ContainableItem(new Product("Pepsi 0.5L", 4.6m, new Category("bautura"), 53), new Position(1, 3, 1, 3)),
         new ContainableItem(new Product("Mouse PC", 30.6m, new Category("altele"), 17), new Position(2, 1, 1, 4))
     };
     collection      = new ContainableItemCollection(itemArray);
     dispenser       = new Dispenser(collection);
     paymentTerminal = new PaymentTerminal();
 }
Ejemplo n.º 10
0
        public static void Main(string[] args)
        {
            List <Position>            positions  = new List <Position>();
            List <ProductCategory>     categories = new List <ProductCategory>();
            ContainableItemsCollection collection = new ContainableItemsCollection();

            VendingMachineSetup(positions, categories, collection);
            Dispenser       dispenser       = new Dispenser(collection);
            PaymentTerminal paymentTerminal = new PaymentTerminal(dispenser);

            paymentTerminal.ProductDispensed += ProductDispensed;
            MainMenu(paymentTerminal);
            dispenser.Report();
        }
        public void Pay(int id, Payment payment)
        {
            Dispenser  dispenser   = new Dispenser();
            Subscriber getNotified = new Subscriber();

            getNotified.Subscribe(dispenser);
            Product wantedProduct = null;

            try {
                wantedProduct = Dispenser.GetProduct(id);

                double change = 0, accumulate = 0;
                if (payment.GetType().Equals(new Coin().GetType()))
                {
                    payment = new Coin();
                }

                if (payment.GetType().Equals(new Banknote().GetType()))
                {
                    payment = new Banknote();
                }

                if (payment.GetType().Equals(new CreditCard().GetType()))
                {
                    payment = new CreditCard();
                    CreditCardVerification card = new CreditCardVerification();
                    bool   cardIsValid          = card.validate();
                    double moneyOnCard          = 1000;
                    change = payment.change(moneyOnCard, wantedProduct.Price);
                    if (cardIsValid && payment.IsValid)
                    {
                        getNotified.Notify(id);
                        Console.WriteLine($"You have bought {wantedProduct.Name} and your change is {change}");
                    }
                    else
                    {
                        Console.WriteLine("Your card is invalid");
                    }
                }
                if (payment.GetType().Equals(new Coin().GetType()) || payment.GetType().Equals(new Banknote().GetType()))
                {
                    change = payment.change(accumulate, wantedProduct.Price);
                    if (payment.IsValid)
                    {
                        getNotified.Notify(id);
                        Console.WriteLine($"You have bought {wantedProduct.Name} and your change is {change}");
                    }
                }
            } catch (Exception e) { Console.WriteLine("PaymentTerminal " + e); }
        }
Ejemplo n.º 12
0
 public PaymentTerminal(Dispenser dispenser)
 {
     this.dispenser = dispenser;
 }
 public PaymentTerminal()
 {
     Dispenser = new Dispenser();
 }
Ejemplo n.º 14
0
        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);
        }
        static void Main(string[] args)
        {
            //Categories
            ProductCategory Soda     = new ProductCategory("Soda");
            ProductCategory Snack    = new ProductCategory("Snack");
            ProductCategory Sandwich = new ProductCategory("Sandwich");

            //Products
            /* Soda */
            Product CocaCola = new Product("Coca-Cola 250", 0.5, 1, Soda);
            Product Sprite   = new Product("Sprite 330", 0.75, 2, Soda);
            Product Fanta    = new Product("Fanta 500", 1, 3, Soda);


            /* Snack */
            Product Snickers = new Product("Snickers", 0.75, 1, Snack);
            Product Cheetos  = new Product("Cheetos", 1, 2, Snack);
            Product Lays     = new Product("Lays", 1.5, 3, Snack);

            /* Sandwich */
            Product BaconSandwich = new Product("Bacon Sandwich", 1, 1, Sandwich);
            Product Crisp         = new Product("Crisp", 1.5, 2, Sandwich);
            Product Kebab         = new Product("Kebab", 2, 3, Sandwich);

            //Dispenser
            Dispenser cocaColaBand = new Dispenser(CocaCola);
            Dispenser spriteBand   = new Dispenser(Sprite);
            Dispenser fantaBand    = new Dispenser(Fanta);

            Dispenser snickersBand = new Dispenser(Snickers);
            Dispenser cheetosBand  = new Dispenser(Cheetos);
            Dispenser laysBand     = new Dispenser(Lays);

            Dispenser baconSandwichBand = new Dispenser(BaconSandwich);
            Dispenser CrispBand         = new Dispenser(Crisp);
            Dispenser KebabBand         = new Dispenser(Kebab);

            List <Dispenser> dispensers = new List <Dispenser>();

            dispensers.Add(cocaColaBand);
            dispensers.Add(spriteBand);
            dispensers.Add(fantaBand);
            dispensers.Add(snickersBand);
            dispensers.Add(cheetosBand);
            dispensers.Add(laysBand);
            dispensers.Add(baconSandwichBand);
            dispensers.Add(CrispBand);
            dispensers.Add(KebabBand);



            ProductCollection collection = new ProductCollection();

            collection.Add(cocaColaBand);
            collection.Add(spriteBand);
            int r = collection.Count(dispensers);

            collection.Remove(cocaColaBand);
            r = collection.Count(dispensers);

            float money = 3;

            collection.GetItem(cocaColaBand, money);
            Console.WriteLine(money);
            Console.ReadKey();
        }
 public PaymentTerminal(Dispenser dispenser)
 {
     paymentEvent.Subscribe(dispenser);
 }