Пример #1
0
        private ContainableItem VerifyCollection(int id)
        {
            if (collection.Count < 1)
            {
                throw new Exception("Collection is empty!");
            }
            ContainableItem toDispense = collection.FindByID(id);

            if (toDispense == null)
            {
                throw new NullReferenceException();
            }
            return(toDispense);
        }
Пример #2
0
 public void Add(ContainableItem added)
 {
     if (head == null)
     {
         head      = new Node();
         head.next = null;
         head.item = added;
         current   = head;
     }
     else
     {
         Node newNode = new Node();
         newNode.item = added;
         newNode.next = null;
         current.next = newNode;
         current      = newNode;
     }
     count++;
 }
Пример #3
0
        public void Remove(ContainableItem removed)
        {
            Node temp = head;
            Node prev = new Node();

            if (count <= -1)
            {
                throw new NullReferenceException();
            }

            if (removed.Equals(head.item))
            {
                head = head.next;
                count--;
                return;
            }

            for (int i = 0; i < count; i++)
            {
                if (!temp.item.Equals(removed))
                {
                    prev = temp;
                    temp = temp.next;
                }
                else
                {
                    prev.next = temp.next;
                    count--;
                    break;
                }
            }

            if (removed.Equals(current.item))
            {
                current      = temp;
                current.next = null;
                count--;
                return;
            }
        }
Пример #4
0
        public void RemoveByPosition(Position position)
        {
            Node element = head;

            if (count <= -1)
            {
                throw new NullReferenceException();
            }
            if (element.item.position.Equals(position))
            {
                ContainableItem toDelete = element.item;
                Remove(toDelete);
                return;
            }
            while (element.next != null)
            {
                if (element.item.position.Equals(position))
                {
                    ContainableItem toDelete = element.item;
                    Remove(toDelete);
                }
                else
                {
                    element = element.next;
                }
            }
            if (element == current && element.item.position.Equals(position))
            {
                ContainableItem toDelete = element.item;
                Remove(toDelete);
            }
            else if (element == current && !element.item.position.Equals(position))
            {
                throw new Exception("Element not found!");
            }
        }
Пример #5
0
        static void Main(string[] args)
        {
            ContainableItemsCollection col = new ContainableItemsCollection();

            ProductCategory candyCategory   = new ProductCategory("Candy");
            ProductCategory utilityCategory = new ProductCategory("Utility");

            Product candybar  = new Product("Candybar", 10, 5, candyCategory);
            Product bubblegum = new Product("Bubblegum", 5, 10, candyCategory);
            Product toothpick = new Product("Toothpick", 1.1m, 900, utilityCategory);

            ContainableItem first  = new ContainableItem(new Position(0, 0, 1, 0), candybar);
            ContainableItem second = new ContainableItem(new Position(0, 1, 2, 1), bubblegum);
            ContainableItem third  = new ContainableItem(new Position(0, 2, 1, 2), toothpick);

            col.Add(first);
            col.Add(second);
            col.Add(third);

            Dispenser       dispenser = new Dispenser(col);
            PaymentTerminal terminal  = new PaymentTerminal(dispenser);

            Console.WriteLine();

            Console.WriteLine("Select a product (insert ID):");
            for (int index = 0; index < col.Count; index++)
            {
                Console.WriteLine($"{col[index].position.id}:{col[index].product.Name}");
            }

            int     choice      = Int32.Parse(Console.ReadLine());
            decimal amountToPay = col.FindByID(choice).product.Price;

            Console.WriteLine();

            System.Console.WriteLine("1.Pay with Credit Card");
            System.Console.WriteLine("2.Pay with Coins");
            System.Console.WriteLine("Select the desired payment method");

            int paymentChoice = Int32.Parse(Console.ReadLine());

            switch (paymentChoice)
            {
            case 1:
                System.Console.WriteLine("Insert your credit card pin:");
                int pin = Int32.Parse(Console.ReadLine());

                CreditCard card    = new CreditCard(pin);
                Payment    payment = new CreditCardPayment(amountToPay, card);

                System.Console.WriteLine("Confirm your credit card pin:");
                (decimal, bool)result = terminal.Pay(choice, payment);
                decimal change = result.Item1;
                if (result.Item2)
                {
                    System.Console.WriteLine("Payment succeeded!");
                }
                else
                {
                    System.Console.WriteLine("Payment failed!");
                }
                System.Console.WriteLine($"Your change is :{change}");
                break;

            case 2:
                System.Console.WriteLine("How many coins do you have in your wallet:");
                int nrOfCoins = Int32.Parse(Console.ReadLine());
                System.Console.WriteLine("How much does one coin value:");
                int coinValue = Int32.Parse(Console.ReadLine());
                payment = new CoinPayment(amountToPay, nrOfCoins, coinValue);
                result  = terminal.Pay(choice, payment);
                change  = result.Item1;
                if (result.Item2)
                {
                    System.Console.WriteLine("Payment succeeded!");
                }
                else
                {
                    System.Console.WriteLine("Payment failed!");
                }
                System.Console.WriteLine($"Your change is :{change}");
                break;

            default:
                System.Console.WriteLine("Please press 1 or 2");
                break;
            }
            DataAcquisition.Instance.ExportToCSV();
            Console.ReadKey();
        }
Пример #6
0
        public Product GetProduct(int id)
        {
            ContainableItem toDispense = VerifyCollection(id);

            return(toDispense.product);
        }
Пример #7
0
        private void Dispense(int id)
        {
            ContainableItem toDispense = VerifyCollection(id);

            toDispense.product.Quantity--;
        }