public static ICurrencyRepo CreateChange(double Amount) { CurrencyRepo change = new CurrencyRepo(); while (Amount > 0) { /* Used Math.Round() because for some reason, during the 11 cents test, * 0.11 - 0.10 = 0.00999999999995 which != 0.01. So my program would break. :( */ Amount = Math.Round(Amount, 2); if (Amount - 1 >= 0) { Amount -= 1.00; DollarCoin c = new DollarCoin(); change.AddCoin(c); } else if (Amount - 0.5 >= 0) { Amount -= 0.5; HalfDollar c = new HalfDollar(); change.AddCoin(c); } else if (Amount - 0.25 >= 0) { Amount -= 0.25; Quarter c = new Quarter(); change.AddCoin(c); } else if (Amount - 0.1 >= 0) { Amount -= 0.10; Dime c = new Dime(); change.AddCoin(c); } else if (Amount - 0.05 >= 0) { Amount -= 0.05; Nickel c = new Nickel(); change.AddCoin(c); } else if (Amount - 0.01 >= 0) { Amount -= 0.01; Penny c = new Penny(); change.AddCoin(c); } else { // Change made } } return(change); }
public CurrencyRepo LoadRepo() { CurrencyRepo LoadedRepo = new CurrencyRepo(); try { // Get all the repo data and place it in a temporary string array; string[] RepoLoadedData = System.IO.File.ReadAllLines(SaveLocation); for (int CoinPosition = 0; CoinPosition < RepoLoadedData.Length; CoinPosition++) { // Take a single loaded item from the array and separate the components into another array for transfer string[] ReadCoin = RepoLoadedData[CoinPosition].Split(','); // Check if the ReadCoin is blank. If not, add to repo; if (ReadCoin[0] != "") { switch (ReadCoin[0]) { case "Penny": { Penny tempC = new Penny(); tempC.Year = Convert.ToInt32(ReadCoin[2]); LoadedRepo.AddCoin(tempC); break; } case "Nickel": { Nickel tempC = new Nickel(); tempC.Year = Convert.ToInt32(ReadCoin[2]); LoadedRepo.AddCoin(tempC); break; } case "Dime": { Dime tempC = new Dime(); tempC.Year = Convert.ToInt32(ReadCoin[2]); LoadedRepo.AddCoin(tempC); break; } case "Quarter": { Quarter tempC = new Quarter(); tempC.Year = Convert.ToInt32(ReadCoin[2]); LoadedRepo.AddCoin(tempC); break; } case "Half Dollar": { HalfDollar tempC = new HalfDollar(); tempC.Year = Convert.ToInt32(ReadCoin[2]); LoadedRepo.AddCoin(tempC); break; } case "Dollar Coin": { DollarCoin tempC = new DollarCoin(); tempC.Year = Convert.ToInt32(ReadCoin[2]); LoadedRepo.AddCoin(tempC); break; } } } } return(LoadedRepo); //loadInvSuccess = true; } catch (Exception e) { // Nothing to load? //ALLINVENTORYINFO.Initialize(); //loadInvSuccess = false; return(LoadedRepo); } }