public void GiveOddMoney(int value)
 {
     MoneyStorage result = new MoneyStorage();
     for(int i = result.storage.Count-1; i >= 0; i--)
     {
         KeyValuePair<Coin, int> pair = storage.ElementAt(i);
         int quantity = value / pair.Key.Value;
         quantity = quantity <= pair.Value ? quantity : pair.Value;
         result.AddCoin(pair.Key, quantity);
         value -= pair.Key.Value * quantity;
     }
     if( value!= 0)
     {
         throw new NotEnoughMoneyException();
     }
     for (int i = 0; i < result.storage.Count; i++)
     {
         this.storage[result.storage.ElementAt(i).Key] -= result.storage.ElementAt(i).Value;
     }
 }
Example #2
0
 public Machine()
 {
     bank = new MoneyStorage();
     currentBalane = 0;
     storage = new ProductStorage();
 }