// remove as many of a specified coin as possible, without going over
        private decimal removeCoinDenomiation(decimal AmountToRemove, Coin.Denomination denominationEnumeral)
        {
            var coins =
                from aCoin in box
                where aCoin.DenominationEnumeral == denominationEnumeral
                select aCoin;

            var coinArray = coins.ToArray();

            decimal amountRemoved      = 0M;
            decimal amountLeftToRemove = AmountToRemove;

            foreach (Coin aCoin in coinArray)
            {
                if (amountLeftToRemove >= Coin.ValueOfCoin(denominationEnumeral))
                {
                    box.Remove(aCoin);
                    amountRemoved      += aCoin.ValueOf;
                    amountLeftToRemove -= aCoin.ValueOf;
                }
                else
                {
                    break;
                }
            }

            return(amountRemoved);
        }
        //Take a coin of the specified denomination out of the box
        //Need to use a LINQ query here
        public Boolean Withdraw(Coin.Denomination denomination)
        {
            bool result = false;

            //Count that type of coin first
            int foundCoinsCount = CoinCount(denomination);

            //Need to find out if there are more than zero of that type of coin
            if (foundCoinsCount > 0)
            {
                //LINQ query to find the coins of this denomination within the box list
                var findCoins =
                    from possibleCandidate in box
                    where possibleCandidate.CoinEnumeral == denomination
                    select possibleCandidate;

                //Actual removal of the coin object from the list.
                box.Remove(findCoins.First());

                result = true;
            }

            //If there were zero of that type of coin, withdraw failed, return false
            else
            {
                result = false;
            }

            return(result);
        }
示例#3
0
        private int CoinCount(Coin.Denomination kindOfCoin)
        {
            var result = from coinType in box
                         where coinType.Key == kindOfCoin
                         select coinType.Value;

            return(result.Sum());
        }
示例#4
0
        private int coinCount(Coin.Denomination denominationEnumeral)
        {
            var roll =
                from coin in box
                where coin.DenominationEnumeral == denominationEnumeral
                select coin;

            return(roll.Count());
        }
示例#5
0
 public bool Withdraw(Coin.Denomination coinType)
 {
     if (CoinCount(coinType) > 0)
     {
         box[coinType]--;
         NotifyPropertyChanged();
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#6
0
        //Take a coin of the specified denomination out of the box
        public Boolean Withdraw(Coin.Denomination ACoinDenomination)
        {
            var coins = from coin in this.box
                        where coin.CoinEnumeral == ACoinDenomination
                        select coin;

            Boolean result = false;

            if (coins.Count() > 0)
            {
                result = this.box.Remove(coins.First());
            }
            return(result);
        }
示例#7
0
        // take a coin of the specified denomination out of the box
        public Boolean Withdraw(Coin.Denomination ACoinDenomination)
        {
            var aCoin =
                from firstCoin in box
                where firstCoin.DenominationEnumeral == ACoinDenomination
                select firstCoin;

            Boolean result = false;
            if (aCoin.Count() > 0)
            {
                result = box.Remove(aCoin.First());
            }
            return result;
        }
        public int CoinCount(Coin.Denomination ADenomination)
        {
            //Create a variable to store the result
            int coinCountFound = 0;

            //LINQ query to find only coins that match the demonination that was passed in
            var findCoins =
                from possibleCandidate in box
                where possibleCandidate.CoinEnumeral == ADenomination
                select possibleCandidate;

            //Now store the count of the results as the int variable
            coinCountFound = findCoins.Count();

            return(coinCountFound);
        }
示例#9
0
 private static decimal convertEnumeralToDecimal(Coin.Denomination denominationEnumeral)
 {
     return((decimal)denominationEnumeral / 100M);
 }
示例#10
0
 // decimal value of the specified coin denomination
 public static decimal ValueOfCoin(Coin.Denomination denominationEnumeral)
 {
     return(convertEnumeralToDecimal(denominationEnumeral));
 }
示例#11
0
 public void Deposit(Coin.Denomination coinType)
 {
     box[coinType]++;
     NotifyPropertyChanged();
 }