private ICoin FindTheRightCoin(string type)
        {
            ICoin coin = null;

            switch (type)
            {
            case "Penny":
                USCoins.Penny penny = new USCoins.Penny();
                coin = penny;
                break;

            case "Nickel":
                USCoins.Nickel nickel = new USCoins.Nickel();
                coin = nickel;
                break;

            case "Dime":
                USCoins.Dime dime = new USCoins.Dime();
                coin = dime;
                break;

            case "Quarter":
                USCoins.Quarter quarter = new USCoins.Quarter();
                coin = quarter;
                break;

            case "Dollar Coin":
                USCoins.DollarCoin dollarCoin = new USCoins.DollarCoin();
                coin = dollarCoin;
                break;
            }

            return(coin);
        }
示例#2
0
        public ICurrencyRepo MakeChange(double amount)
        {
            double totalAmountOfCoins = 0;


            while (amount > totalAmountOfCoins)
            {
                if (totalAmountOfCoins + 1.0 <= amount)
                {
                    USCoins.DollarCoin dc = new USCoins.DollarCoin();
                    totalAmountOfCoins += dc.monetaryValue;
                    Coins.Add(dc);
                }
                else if (totalAmountOfCoins + .25 <= amount)
                {
                    USCoins.Quarter q = new USCoins.Quarter();
                    totalAmountOfCoins += q.monetaryValue;
                    Coins.Add(q);
                }
                else if (totalAmountOfCoins + .1 <= amount)
                {
                    USCoins.Dime d = new USCoins.Dime();
                    totalAmountOfCoins += d.monetaryValue;
                    Coins.Add(d);
                }
                else if (totalAmountOfCoins + .05 <= amount)
                {
                    USCoins.Nickel n = new USCoins.Nickel();
                    totalAmountOfCoins += n.monetaryValue;
                    Coins.Add(n);
                }
                else if (totalAmountOfCoins + .01 <= amount)
                {
                    USCoins.Penny p = new USCoins.Penny();
                    totalAmountOfCoins += p.monetaryValue;
                    Coins.Add(p);
                }

                totalAmountOfCoins = Math.Round(totalAmountOfCoins, 2);
            }

            return(this);
        }
示例#3
0
        public ICurrencyRepo MakeChange(double amountTendered, double totalCost)
        {
            double change             = amountTendered - totalCost;
            double totalAmountOfCoins = 0;

            while (change > totalAmountOfCoins)
            {
                if (totalAmountOfCoins + 1 <= change)
                {
                    USCoins.DollarCoin dc = new USCoins.DollarCoin();
                    totalAmountOfCoins += dc.monetaryValue;
                    Coins.Add(dc);
                }
                else if (totalAmountOfCoins + .25 <= change)
                {
                    USCoins.Quarter q = new USCoins.Quarter();
                    totalAmountOfCoins += q.monetaryValue;
                    Coins.Add(q);
                }
                else if (totalAmountOfCoins + .1 <= change)
                {
                    USCoins.Dime d = new USCoins.Dime();
                    totalAmountOfCoins += d.monetaryValue;
                    Coins.Add(d);
                }
                else if (totalAmountOfCoins + .05 <= change)
                {
                    USCoins.Nickel n = new USCoins.Nickel();
                    totalAmountOfCoins += n.monetaryValue;
                    Coins.Add(n);
                }
                else if (totalAmountOfCoins + .01 <= change)
                {
                    USCoins.Penny p = new USCoins.Penny();
                    totalAmountOfCoins += p.monetaryValue;
                    Coins.Add(p);
                }
            }

            return(this);
        }
示例#4
0
        public ICurrencyRepo MakeChange(double amount, string tag)
        {
            double totalAmountOfCoins = 0;

            if (tag == "US Coin")
            {
                while (amount > totalAmountOfCoins)
                {
                    if (totalAmountOfCoins + 1.0 <= amount)
                    {
                        USCoins.DollarCoin dc = new USCoins.DollarCoin();
                        totalAmountOfCoins += dc.monetaryValue;
                        Coins.Add(dc);
                    }
                    else if (totalAmountOfCoins + .25 <= amount)
                    {
                        USCoins.Quarter q = new USCoins.Quarter();
                        totalAmountOfCoins += q.monetaryValue;
                        Coins.Add(q);
                    }
                    else if (totalAmountOfCoins + .1 <= amount)
                    {
                        USCoins.Dime d = new USCoins.Dime();
                        totalAmountOfCoins += d.monetaryValue;
                        Coins.Add(d);
                    }
                    else if (totalAmountOfCoins + .05 <= amount)
                    {
                        USCoins.Nickel n = new USCoins.Nickel();
                        totalAmountOfCoins += n.monetaryValue;
                        Coins.Add(n);
                    }
                    else if (totalAmountOfCoins + .01 <= amount)
                    {
                        USCoins.Penny p = new USCoins.Penny();
                        totalAmountOfCoins += p.monetaryValue;
                        Coins.Add(p);
                    }

                    totalAmountOfCoins = Math.Round(totalAmountOfCoins, 2);
                }
            }
            else if (tag == "Barbados")
            {
                while (amount > totalAmountOfCoins)
                {
                    if (totalAmountOfCoins + 1.0 <= amount)
                    {
                        OneBarbadianDollar oBD = new OneBarbadianDollar();
                        totalAmountOfCoins += oBD.monetaryValue;
                        Coins.Add(oBD);
                    }
                    else if (totalAmountOfCoins + .25 <= amount)
                    {
                        TwentyFiveCent tWC = new TwentyFiveCent();
                        totalAmountOfCoins += tWC.monetaryValue;
                        Coins.Add(tWC);
                    }
                    else if (totalAmountOfCoins + .1 <= amount)
                    {
                        TenCent tC = new TenCent();
                        totalAmountOfCoins += tC.monetaryValue;
                        Coins.Add(tC);
                    }
                    else if (totalAmountOfCoins + .05 <= amount)
                    {
                        FiveCent fC = new FiveCent();
                        totalAmountOfCoins += fC.monetaryValue;
                        Coins.Add(fC);
                    }
                    else if (totalAmountOfCoins + .01 <= amount)
                    {
                        OneCent oC = new OneCent();
                        totalAmountOfCoins += oC.monetaryValue;
                        Coins.Add(oC);
                    }

                    totalAmountOfCoins = Math.Round(totalAmountOfCoins, 2);
                }
            }

            return(this);
        }