예제 #1
0
        public void MakeChange()
        {
            Coin    quarter      = new Coin("quarter");
            Coin    dime         = new Coin("dime");
            Coin    nickel       = new Coin("nickel");
            decimal quarterValue = 0.25m;
            decimal dimeValue    = 0.10m;
            decimal nickelValue  = 0.05m;

            while (ValueInMachine > 0.0m)
            {
                if (ValueInMachine >= quarterValue)
                {
                    CoinReturn.Add(quarter);
                    ValueInMachine -= quarterValue;
                }
                else if (ValueInMachine >= dimeValue)
                {
                    CoinReturn.Add(dime);
                    ValueInMachine -= dimeValue;
                }
                else if (ValueInMachine >= nickelValue)
                {
                    CoinReturn.Add(nickel);
                    ValueInMachine -= nickelValue;
                }
            }
        }
예제 #2
0
 // Other methods
 public void TakeCoin(Coin insertedCoin)
 {
     if (insertedCoin.CoinType == "quarter")
     {
         ValueInMachine += 0.25m;
     }
     else if (insertedCoin.CoinType == "dime")
     {
         ValueInMachine += 0.10m;
     }
     else if (insertedCoin.CoinType == "nickel")
     {
         ValueInMachine += 0.05m;
     }
     else
     {
         CoinReturn.Add(insertedCoin);
     }
 }
예제 #3
0
        /// <summary>
        /// Issues change when a customer has entered more coins than are required
        /// </summary>
        /// <param name="amountToReturn">The amount to be returned</param>
        private void IssueChange(decimal amountToReturn)
        {
            if (CoinReturn == null)
            {
                CoinReturn = new List <Coin>();
            }

            var valCounter = 0m;

            foreach (var coin in CurrentTransaction)
            {
                valCounter += coin.Value;

                CoinReturn.Add(coin);

                if (amountToReturn == valCounter)
                {
                    return;
                }
            }
        }
 // simulate the return of a coin
 public void ReturnCoin(string coin)
 {
     CoinReturn.Add(coin);
 }