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); }
public int GetCoinCount(ICoin coin) { int count = 0; foreach (ICoin c in Coins) { if (c.GetType() == coin.GetType()) { count++; } } return(count); }
/// <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; }
/// <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; }
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); }
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; }