public ICurrencyRepo MakeChange(double Amount) { ICurrencyRepo newChange = new USCurrencyRepo(); Decimal amount = (Decimal)Amount; List <ICoin> changeReference = orderedCoins(); foreach (ICoin c in changeReference) { while (amount >= (Decimal)c.MonetaryValue) { newChange.AddCoin(c); amount -= (Decimal)c.MonetaryValue; } } return(newChange); }
public static ICurrencyRepo CreateChange(double Amount) { ICurrencyRepo returnedChagne = new USCurrencyRepo(); for (double chng = Amount; chng > 0.00;) { if (chng >= 1.00) { returnedChagne.AddCoin(new DollarCoin()); chng -= 1.00; } else if (chng >= 0.50) { returnedChagne.AddCoin(new HalfDollar()); chng -= 0.50; } else if (chng >= 0.25) { returnedChagne.AddCoin(new Quarter()); chng -= 0.25; } else if (chng >= 0.10) { returnedChagne.AddCoin(new Dime()); chng -= 0.10; } else if (chng >= 0.05) { returnedChagne.AddCoin(new Nickel()); chng -= 0.05; } else { returnedChagne.AddCoin(new Penny()); chng -= 0.01; } } return(returnedChagne); }