Beispiel #1
0
 public ICoin RemoveCoin(ICoin c)
 {
     for (int i = 0; i < Coins.Capacity; i++)
     {
         if (Coins[i].GetType() == c.GetType())
         {
             Coins.RemoveAt(i);
             i = Coins.Count + 1;
         }
     }
     return(c);
 }
Beispiel #2
0
        public int GetCoinCount(ICoin coin)
        {
            int count = 0;

            foreach (ICoin c in Coins)
            {
                if (c.GetType() == coin.GetType())
                {
                    count++;
                }
            }
            return(count);
        }
Beispiel #3
0
        /// <summary>
        /// Add coin to the List and set the amount and value
        /// </summary>
        /// <param name="coin"></param>
        public void AddCoin(ICoin coin)
        {
            if (coin.GetType().BaseType != typeof(UsCoin))
            {
                throw new InValidCoinException("MyCoinJar accepts only UsCoin");
            }
            if (this.TotalVolume < (this.UsedVolume + coin.Volume))
            {
                throw new CoinOverFlowException();
            }

            Coins.Add(coin);
            this.TotalAmount += coin.Amount;
            this.UsedVolume  += coin.Volume;
        }
Beispiel #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="coin"></param>
        public void AddCoin(ICoin coin)
        {
            if (coin.GetType().BaseType != typeof(UsCoin))
            {
                throw new InValidCoinException("MyCoinJar accepts only UsCoin");
            }
            if (this.TotalVolume.Unit < (this.actualVolume.Unit + coin.Volume.Unit))
            {
                throw new CoinOverFlowException();
            }

            coinHeap.Add(coin);
            actualVolume.Unit      += coin.Volume.Unit;
            actualAmount.UnitPrice += coin.Amount.UnitPrice;
        }
Beispiel #5
0
        public ICoin RemoveCoin(ICoin coin)
        {
            ICoin foundCoin = null;
            int   index     = 0;

            for (; index < Coins.Count; index++)
            {
                if (Coins[index].GetType() == coin.GetType())
                {
                    foundCoin = Coins[index];
                    break;
                }
            }
            Coins.RemoveAt(index);
            return(foundCoin);
        }
Beispiel #6
0
        public void Accept(ICoin coin)
        {
            if (coin.GetType().BaseType != typeof(UsCoin))
                throw new InValidCoinException("MyCoinJar accepts only UsCoin");
            if (this.TotalVolume.Unit < (this.actualVolume.Unit + coin.Volume.Unit))
                throw new CoinOverFlowException();

            coinHeap.Add(coin);
            actualVolume.Unit += coin.Volume.Unit;
            actualAmount.UnitPrice += coin.Value.UnitPrice;
        }