Exemple #1
0
        public static void Main(string[] args)
        {
            Toy car = new Toy("Car", 3, 2014, "BiH");
            Toy plane = new Toy("Plane", 2, 2013);
            Toy ball = new Toy("Ball", 0, 2013);

            ToyStore store = new ToyStore("Camp");
            store.BuyToy(car);
            store.BuyToy(car);
            store.BuyToy(plane);
            store.BuyToy(plane);
            store.BuyToy(plane);
            store.BuyToy(ball);
            store.BuyToy(ball);
            store.BuyToy(ball);
            store.BuyToy(ball);

            store.PrintInventory();

            store.SellToy(car);
            store.PrintInventory();
            store.SellToy(car);

            store.PrintInventory();
        }
Exemple #2
0
 private int IndexOf(Toy toy)
 {
     for (int i = 0; i < size; i++)
     {
         if (array[i].Equals(toy))
         {
             return i;
         }
     }
     return -1;
 }
Exemple #3
0
        public void RemoveToy(Toy toy)
        {
            int index = IndexOf(toy);
            if (index == -1)
                throw new ArgumentException("Can't remove a toy we don't have");

            if (array[index].Amount == 1)
            {
                RemoveElement(index);
            }
            else
            {
                array[index].DecereaseAmount();
            }
        }
Exemple #4
0
        public void AddToy(Toy toy)
        {
            if (array.Length >= size)
            {
                Resize();
            }

            int index = IndexOf(toy);
            if (index >= 0)
            {
                array[index].IncreaseAmount();
            }
            else
            {
                array[size++] = toy;
            }
        }
Exemple #5
0
 public bool Contains(Toy toy)
 {
     return IndexOf(toy) >= 0;
 }
Exemple #6
0
 public void SellToy(Toy toy)
 {
     if (inventory.Contains(toy))
         inventory.RemoveToy(toy);
 }
Exemple #7
0
 public void BuyToy(Toy toy)
 {
     inventory.AddToy(toy);
 }
Exemple #8
0
 private void Resize()
 {
     Toy[] temp = new Toy[array.Length * 2];
     for (int i = 0; i < array.Length; i++)
     {
         temp[i] = array[i];
     }
     array = temp;
 }