Exemplo 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);
        }
Exemplo n.º 2
0
        public static ContainableItem GetItem(int index)
        {
            ContainableItem item = new ContainableItem();

            item = listOfItems.GetItem(index);
            return(item);
        }
Exemplo n.º 3
0
        private string Dispense(int id)
        {
            ContainableItem item = listofProducts.FirstOrDefault(itemToDispense => itemToDispense.Position.Id == id);

            item.Product.Quantity--;
            DataAcquisition.GetInstance().LoadData(item.Product, DateTime.Now);
            return($"Quantity left for {item.Product.Name} is {item.Product.Quantity}");
        }
Exemplo n.º 4
0
 public void add(ContainableItem containableItem)
 {
     Size++;
     ContainableItem[] newArray = new ContainableItem[Size];
     System.Array.Copy(ContainableItems, newArray, Size - 1);
     if (Size - 1 != -1)
     {
         newArray[Size - 1] = containableItem;
     }
     ContainableItems = new ContainableItem[Size];
     ContainableItems = newArray;
 }
 public Product GetProductByID(int ID)
 {
     for (int index = 0; index < this.size; index++)
     {
         ContainableItem itemToReturn = this.items[index];
         if (itemToReturn.Position.ID.Equals(ID) && itemToReturn.Product.Quantity >= 1)
         {
             return(itemToReturn.Product);
         }
     }
     return(null);
 }
 public int GetProductID(Product product)
 {
     for (int index = 0; index < this.size; index++)
     {
         ContainableItem itemToReturn = this.items[index];
         if (itemToReturn.Product.Equals(product))
         {
             return(itemToReturn.Position.ID);
         }
     }
     return(-1);
 }
Exemplo n.º 7
0
        public Product Dispense(int index)
        {
            ContainableItem containableItem = containableItemsCollection.GetItem(index);

            if (containableItem == null)
            {
                throw new ArgumentNullException(nameof(containableItem));
            }

            containableItem.Product.Quantity--;
            return(containableItem.Product);
        }
 public void Add(ContainableItem containableItem)
 {
     if (this.capacity == this.size)
     {
         ContainableItem[] itemsCopy = this.items;
         this.items = new ContainableItem[2 * this.capacity];
         Array.Copy(itemsCopy, this.items, this.capacity);
         this.capacity *= 2;
     }
     this.items[this.size] = containableItem;
     this.size++;
 }
 public Product GetProductByID(int ID)
 {
     for (int index = 0; index < productList.Count(); index++)
     {
         ContainableItem item = productList.GetItem(index);
         if (item.Position.ID.Equals(ID) && item.Product.QuantityProduct >= 1)
         {
             return(item.Product);
         }
     }
     return(null);
 }
Exemplo n.º 10
0
        public static void RemoveByPosition(Position position)
        {
            ContainableItem itemToDelete = listOfItems.FirstOrDefault(deletedItem => deletedItem.Position.Equals(position));

            if (itemToDelete != null)
            {
                RemoveItem(itemToDelete);
            }
            else
            {
                throw new System.Exception("Item could not be found");
            }
        }
        public int SearchIndex(ContainableItem product)
        {
            int returnedValue = -1;

            for (int index = 0; index <= sizeIndex; index++)
            {
                if (products[index].Equals(product))
                {
                    return(returnedValue);
                }
            }
            return(returnedValue);
        }
        public void AddProduct(ContainableItem product)
        {
            ContainableItem[] auxiliaryList = productList;
            productList = new ContainableItem[size + 1];

            for (int i = 0; i < auxiliaryList.Length; i++)
            {
                productList[i] = auxiliaryList[i];
            }

            productList[size] = product;
            size++;
        }
Exemplo n.º 13
0
 private Product Dispense(int Id)
 {
     if (collection.Count > 0)
     {
         ContainableItem itemToDispense = collection.ItemById(Id);
         collection.RemoveById(Id);
         return(itemToDispense.Product);
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 14
0
        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();
        }
 public void Remove(ContainableItem product)
 {
     for (int i = 0; i < productList.Length; i++)
     {
         if (productList[i] == product)
         {
             for (int j = i; j < productList.Length - 1; j++)
             {
                 productList[j] = productList[j + 1];
             }
         }
     }
     size--;
 }
Exemplo n.º 16
0
        public static Product GetProduct(int id)
        {
            ContainableItem item = listofProducts.FirstOrDefault(itemToDispense => itemToDispense.Position.Id == id);

            if (item == null)
            {
                throw new System.Exception("The id dosen't exist");
            }
            if (item.Product.Quantity <= 0)
            {
                throw new System.Exception("The product is not in the stock for the moment");
            }

            return(item.Product);
        }
Exemplo n.º 17
0
        public void remove(ContainableItem containableItem)
        {
            ContainableItem[] newArray = new ContainableItem[Size];
            int j = 0;

            for (int i = 0; i < Size; i++)
            {
                if (!containableItem.Equals(ContainableItems[i]))
                {
                    newArray[j++] = ContainableItems[i];
                }
            }
            ContainableItems = new ContainableItem[j - 1];
            ContainableItems = newArray;
        }
Exemplo n.º 18
0
        public void Add(ContainableItem @new)
        {
            Node same = FindPrevious(@new);

            if (same != null)
            {
                same.To.SetQuantity(same.To.GetQuantity() + @new.Product.GetSize());
            }
            else
            {
                Size++;
                Node temp = new Node(@new, first);
                temp.ContainableItem.Position.ID1 = first.ContainableItem.Position.ID1 + 1;
                first = temp;
            }
        }
 public void Remove(ContainableItem product)
 {
     if (SearchIndex(product) < 50 && SearchIndex(product) < sizeIndex)
     {
         for (int index = SearchIndex(product); index < sizeIndex; index++)
         {
             products[index] = products[index + 1];
         }
         sizeIndex--;
     }
     if (SearchIndex(product) == sizeIndex)
     {
         products[SearchIndex(product)] = null;
         sizeIndex--;
     }
 }
        public ContainableItem GetByPosition(int idProduct)
        {
            for (int index = 0; index < productList.Count(); index++)
            {
                ContainableItem item = productList.GetItem(index);
                if (item.Position.ID.Equals(idProduct) && item.Product.QuantityProduct >= 1)
                {
                    return(item.Product);
                }
            }
            return(null);

            /* for (int i = 0; i < productList.Count(); i++)
             *   if (productList.GetItem(i).Equals(position))
             *       return productList.GetItem(i) as ContainableItem;
             * return null;*/
        }
Exemplo n.º 21
0
        public Node FindPrevious(ContainableItem other)
        {
            Node previous = first;

            for (int i = 0; i < Size; i++)
            {
                if (previous.To != null && previous.To.ContainableItem.Equals(other))
                {
                    return(previous);
                }
                else if (previous.ContainableItem.EqualsPosition(other))
                {
                    OnLocationOverlap(EventArgs.Empty);
                }
                else
                {
                    previous = previous.To;
                }
            }
            return(null);
        }
Exemplo n.º 22
0
 public void Remove(ContainableItem removing)
 {
     if (first.ContainableItem.Position.Equals(removing.Position))
     {
         first = first.To;
         Size--;
     }
     else
     {
         Node temp = first;
         for (int i = 1; i < Size; i++)
         {
             if (temp.To.ContainableItem.Position.Equals(removing.Position))
             {
                 temp.To = temp.To.To;
                 Size--;
                 break;
             }
             temp = temp.To;
         }
     }
 }
        public void Remove(ContainableItem containableItem)
        {
            int position = -1;

            for (int index = 0; index < this.size; index++)
            {
                if (this.items[index].Equals(containableItem))
                {
                    position = index;
                    break;
                }
            }
            if (position == -1)
            {
                Console.WriteLine("Object not found!");
                return;
            }
            else
            {
                Array.Copy(this.items, position + 1, this.items, position, this.size - position - 1);
                this.size--;
            }
        }
Exemplo n.º 24
0
        private static void ContainableItemCollectionFunctionalities()
        {
            VendingMachine vendingMachine = VendingMachine.Instance;

            Product coffeeProduct = new Product()
            {
                Category = new Category("Beverages"),
                Name     = "Coffee",
                Price    = 12.3,
            };

            Console.WriteLine("Add a product:");
            vendingMachine.Items.Add(new ContainableItem
            {
                Product  = coffeeProduct,
                Position = new Position(row: 2, column: 0, id: 13, size: 3)
            });

            WriteContainableItems(vendingMachine.Items);

            Console.WriteLine("Remove at position: (0,1)");
            if (!vendingMachine.Items.RemoveBy(new Position(row: 0, column: 1, id: 2)))
            {
                Console.WriteLine("No product found at this position.");
            }
            else
            {
                WriteContainableItems(vendingMachine.Items);
            }

            Console.WriteLine("Search for a coffee product:");
            try
            {
                ContainableItem coffeeContainableItem = vendingMachine.Items.FirstOrDefault(containableItem => containableItem.Product.Equals(coffeeProduct));
                if (coffeeContainableItem != null)
                {
                    Console.WriteLine(coffeeProduct.ToString());
                    Console.WriteLine("\nCoffee product was found and it will be removed.");
                    vendingMachine.Items.Remove(coffeeContainableItem);
                    WriteContainableItems(vendingMachine.Items);
                }
            }
            catch
            {
                Console.WriteLine("Product not found.");
            }

            Console.WriteLine("Remove second product: ");
            try
            {
                vendingMachine.Items.RemoveAt(1);
                WriteContainableItems(vendingMachine.Items);
            }
            catch
            {
                Console.WriteLine("Product not found.");
            }

            Product beverageProduct = vendingMachine.Items.FirstOrDefault(containableItem => containableItem.Product.Category.Name.Equals("Beverages"))?.Product;

            Console.WriteLine("Search for the first beverage product using linq:");

            string beverageMessage = beverageProduct == null
            ? "No beverage found"
            : $"Beverage Found:\t{beverageProduct.ToString()}";

            Console.WriteLine(beverageMessage);

            try
            {
                ContainableItem lastProduct = vendingMachine.Items.GetItem(vendingMachine.Items.Count - 1);
                Console.WriteLine($"\nLast product:\t{vendingMachine.Items.GetItem(vendingMachine.Items.Count - 1).Product}");
            }
            catch
            {
                Console.WriteLine("Product not found.");
            }
        }
 public void Add(ContainableItem newProduct)
 {
     productList.Add(newProduct);
 }
 public void Remove(ContainableItem product)
 {
     productList.Remove(product);
 }
Exemplo n.º 27
0
 public static void RemoveItem(ContainableItem item)
 {
     listOfItems.Remove(item);
 }
Exemplo n.º 28
0
 public static void AddItem(ContainableItem item)
 {
     listOfItems.Add(item);
 }
Exemplo n.º 29
0
 public Node()
 {
     ContainableItem = new ContainableItem();
     To = null;
 }
Exemplo n.º 30
0
 public Node(ContainableItem newItem, Node nextNode)
 {
     ContainableItem = newItem;
     To = nextNode;
 }