public void TestCoinCount() { CurrencyRepo repo = new CurrencyRepo(); ViewModelRepo vm = new ViewModelRepo(repo); string defaultCount = vm.CoinCount; //get start count ICoin quarter = new Quarter(); //make and add quarter repo.AddCoin(quarter); string countAfterOneCoin = vm.CoinCount;//get count after adding quarter ICoin penny = new Penny(); ICoin dollar = new DollarCoin(); ICoin nickel = new Nickel(); ICoin dime = new Dime(); repo.AddCoin(penny); repo.AddCoin(dollar); repo.AddCoin(nickel); repo.AddCoin(dime); string countAfterOneOfEachCoin = vm.CoinCount; Assert.AreEqual("Coins: 0", defaultCount); Assert.AreEqual("Coins: 1", countAfterOneCoin); Assert.AreEqual("Coins: 5", countAfterOneOfEachCoin); }
public void TestCoinValue() { CurrencyRepo repo = new CurrencyRepo(); ViewModelRepo vm = new ViewModelRepo(repo); string defaultValue = vm.CoinValue; //get start count ICoin quarter = new Quarter(); //make and add quarter repo.AddCoin(quarter); string valueAfterQuarter = vm.CoinValue;//get count after adding quarter ICoin penny = new Penny(); ICoin dollar = new DollarCoin(); ICoin nickel = new Nickel(); ICoin dime = new Dime(); repo.AddCoin(penny); repo.AddCoin(dollar); repo.AddCoin(nickel); repo.AddCoin(dime); string valueAfterOneOfEachCoin = vm.CoinValue; Assert.AreEqual("Repo Value: 0", defaultValue); Assert.AreEqual("Repo Value: 0.25", valueAfterQuarter); Assert.AreEqual("Repo Value: 1.41", valueAfterOneOfEachCoin); }
public void SaveableCurrenyRepo_Saving_Load() { List <ICoin> RepoCoins() { ICoin p = new Penny(); ICoin h = new HalfDollar(); ICoin dc = new DollarCoin(); ICoin q = new Quarter(); ICoin d = new Dime(); ICoin n = new Nickel(); List <ICoin> Repo_list = new List <ICoin> { { p } }; return(Repo_list); } //Arrange List <ICoin> loadedCoins; loadedCoins = RepoCoins(); //Act repo.Save(loadedCoins); repo.Load(); //Assert Assert.AreEqual(repo.Coins.Count, loadedCoins.Count); CollectionAssert.AreEqual(repo.Coins, loadedCoins); }
ICoin ConvertStringToICoin(string str) { switch (str) { case "Penny": ICoin p = new Penny(); return(p); case "Nickel": ICoin n = new Nickel(); return(n); case "Dime": ICoin d = new Dime(); return(d); case "Quarter": ICoin q = new Quarter(); return(q); case "Dollar Coin": ICoin dc = new DollarCoin(); return(dc); default: return(null); } }
private void LoadCommand() { SerializableCurrencyRepo loadedRepo = null; OpenFileDialog dialog = new OpenFileDialog(); dialog.DefaultExt = ".bs"; dialog.Filter = $"{StaticInformation.FileExtensionName} Files (*{StaticInformation.FileExtension})|*{StaticInformation.FileExtension}"; Nullable <bool> result = dialog.ShowDialog(); if (result == true) { string filename = dialog.FileName; loadedRepo = SaveAndLoadUtility.Load <SerializableCurrencyRepo>(filename); USCurrencyRepo repo = new USCurrencyRepo(); List <ICoin> coins = new List <ICoin>(); foreach (SerializableCoin coin in loadedRepo.Coins) { USCoin usCoin; string name = coin.Name.Replace("US ", ""); switch (name) { case "Penny": usCoin = new Penny(); break; case "Nickel": usCoin = new Nickel(); break; case "Dime": usCoin = new Dime(); break; case "Quarter": usCoin = new Quarter(); break; case "Half Dollar": usCoin = new HalfDollar(); break; case "Dollar Coin": usCoin = new DollarCoin(); break; default: usCoin = new Penny(); break; } coins.Add(usCoin); } StaticInformation.MainRepo.Coins = coins; RefreshAll(); } }
public USCurrencyRepoTest() { repo = new CurrencyRepo(); penny = new Penny(); nickel = new Nickel(); dime = new Dime(); quarter = new Quarter(); dollarCoin = new DollarCoin(); }
public void NickelMonetaryValue() { //Arrange n = new Nickel(); //Act //Assert Assert.AreEqual(.05, n.MonetaryValue); }
public void NickelAbout() { //Arrange n = new Nickel(); //Act //Assert Assert.AreEqual("US Nickel is from 2017. It is worth $0.05. It was made in Denver.", n.About()); }
public void CheckNickel() { //arrange Currency nickel = new Nickel(); //act float Val = nickel.Value; //assert Assert.AreEqual(5, Val, 0.01); }
public void NickelMonetaryValue() { //Arrange Nickel p; //Act p = new Nickel(); //Assert Assert.AreEqual(.05, p.MonetaryValue); }
public void NickelAbout() { //Arrange Nickel n; //Act n = new Nickel(); //Assert Assert.AreEqual($"US Nickel is from {System.DateTime.Now.Year}. It is worth $0.05. It was made in Denver", n.About()); }
public void NickelAbout() { //Arrange Nickel n; //Act n = new Nickel(); //Assert Assert.AreEqual("Nickel is from 2019. It is worth 0.05. It was made in Denver", n.About()); }
private void ButtonAddCoin_Click(object sender, RoutedEventArgs e) { Coin tempC = new Penny(); switch (CoinList.SelectionBoxItem) { case "Penny": { tempC = new Penny(); break; } case "Nickel": { tempC = new Nickel(); break; } case "Dime": { tempC = new Dime(); break; } case "Quarter": { tempC = new Quarter(); break; } case "Half Dollar": { tempC = new HalfDollar(); break; } case "Dollar Coin": { tempC = new DollarCoin(); break; } } repo.AddCoin(tempC); ViewModelRepo = new ViewModelCreateCurrencyRepo(repo); this.DataContext = ViewModelRepo; string value = Convert.ToString(repo.TotalValue()); labelRepoValueDisplay.Content = "$" + value; }
public void NickelConstructor() { //Arrange Nickel n, philiNickel; //Act n = new Nickel(); philiNickel = new Nickel(MintMark.P); //Assert Assert.AreEqual(MintMark.D, n.USCoinMintMark);//default mark is D Assert.AreEqual(DateTime.Now.Year, n.Year); Assert.AreEqual(MintMark.P, philiNickel.USCoinMintMark); }
public void NickelConstructor() { //Arrange Nickel p, philiNickel; //Act p = new Nickel(); philiNickel = new Nickel(USCoinMintMark.P); //Assert Assert.AreEqual(USCoinMintMark.D, p.MintMark); //D is the default mint mark Assert.AreEqual(System.DateTime.Now.Year, p.Year); //Current Year is default year Assert.AreEqual(USCoinMintMark.P, philiNickel.MintMark); }
public void NickelConstructor() { //Arrange Nickel newOrleansNickel; n = new Nickel(); //Act newOrleansNickel = new Nickel(USCoinMintMark.O); //Assert //Current Year is default year Assert.AreEqual(USCoinMintMark.D, n.MintMark); Assert.AreEqual(System.DateTime.Now.Year, n.Year); Assert.AreEqual(System.DateTime.Now.Year, newOrleansNickel.Year); Assert.AreEqual(USCoinMintMark.O, newOrleansNickel.MintMark); }
//public void USCoinSerialize() //{ // //Arrange // List<ICoin> coinList, readCoinList; // coinList = getCoinList(); // //Act // IFormatter formatter = new BinaryFormatter(); // Stream stream = new MemoryStream(); // formatter.Serialize(stream, coinList); // stream.Position = 0; // readCoinList = (List<ICoin>)formatter.Deserialize(stream); // //Assert // foreach (Coin c in coinList) // { // Assert.IsTrue(c is ISerializable); // } // CollectionAssert.AreEqual(coinList, readCoinList); //} private List <ICoin> getCoinList() { ICoin n = new Nickel(); ICoin pen = new Penny(); ICoin q = new Quarter(); ICoin d = new Dime(); ICoin hd = new HalfDollar(); ICoin doll = new DollarCoin(); List <ICoin> coinList = new List <ICoin> { { doll }, { hd }, { q }, { d }, { n }, { pen } }; return(coinList.OrderByDescending(c => c.MonetaryValue).ToList()); }
public bool TryDetect(string pieceOfMetal, out Coin?coin) { switch (pieceOfMetal.ToLowerInvariant()) { case "nickel": coin = new Nickel(); return(true); case "dime": coin = new Dime(); return(true); case "quarter": coin = new Quarter(); return(true); default: coin = null; return(false); } }
/// <summary> /// Replenishes all change up to maximum amount. /// </summary> public void ReplenishChange() { int replenishQuantity = 200; Money money = null; List <decimal> denominations = new List <decimal>(validChangeDenominations); denominations.Sort(); denominations.Reverse(); foreach (decimal denomination in denominations) { if (currencyDenominations.ContainsKey(denomination)) { money = currencyDenominations[denomination]; money.SetQuantity(replenishQuantity); } else { switch (denomination) { case 0.25M: money = new Quarter(true, replenishQuantity); break; case 0.10M: money = new Dime(true, replenishQuantity); break; case 0.05M: money = new Nickel(true, replenishQuantity); break; } if (money != null) { currencyDenominations.Add(denomination, money); } } } }
public List <Currency> LoadAll_SortedByValueDescending() { List <Currency> lst = new List <Currency>(); CurrencyRow f = null; f = new Penny(); lst.Add(new Entity.Currency() { Value = f.Value, SingularDescription = f.SingularDescription, PluralDescription = f.PluralDescription }); f = new Nickel(); lst.Add(new Entity.Currency() { Value = f.Value, SingularDescription = f.SingularDescription, PluralDescription = f.PluralDescription }); f = new Dime(); lst.Add(new Entity.Currency() { Value = f.Value, SingularDescription = f.SingularDescription, PluralDescription = f.PluralDescription }); f = new Quarter(); lst.Add(new Entity.Currency() { Value = f.Value, SingularDescription = f.SingularDescription, PluralDescription = f.PluralDescription }); f = new Dollar(); lst.Add(new Entity.Currency() { Value = f.Value, SingularDescription = f.SingularDescription, PluralDescription = f.PluralDescription }); return(lst.OrderByDescending(x => x.Value).ToList()); }
static void Main(string[] args) { Console.WriteLine("Coininator 9000"); //Make some Coins Nickel n = new Nickel(); Penny p = new Penny(); Quarter q = new Quarter(); Dime d = new Dime(); HalfDollar hd = new HalfDollar(); DollarCoin doll = new DollarCoin(); Console.WriteLine("List of US Coins\n"); Console.WriteLine(n.About()); Console.WriteLine(p.About()); Console.WriteLine(q.About()); Console.WriteLine(d.About()); Console.WriteLine(hd.About()); Console.WriteLine(doll.About()); Console.ReadKey(); }
/// <summary> /// Give change back to the machine operator. /// </summary> /// <returns></returns> public List <Money> FinishTransaction() { List <Money> changeCurrency = new List <Money>(); if (TotalChangeAvailable > 0 && Balance > 0) { decimal currencyThreshold = 0.25M; if (currencyDenominations[currencyThreshold].Count > 0 && Balance >= currencyThreshold) { Money quarters = new Quarter(true); quarters.MakeChange(currencyDenominations[currencyThreshold], Balance); changeCurrency.Add(quarters); Balance -= quarters.TotalValue; } currencyThreshold = 0.10M; if (currencyDenominations[currencyThreshold].Count > 0 && Balance >= currencyThreshold) { Money dimes = new Dime(true); dimes.MakeChange(currencyDenominations[currencyThreshold], Balance); changeCurrency.Add(dimes); Balance -= dimes.TotalValue; } currencyThreshold = 0.05M; if (currencyDenominations[currencyThreshold].Count > 0 && Balance >= currencyThreshold) { Money nickels = new Nickel(true); nickels.MakeChange(currencyDenominations[currencyThreshold], Balance); changeCurrency.Add(nickels); Balance -= nickels.TotalValue; } decimal changeGiven = 0; foreach (Money currency in changeCurrency) { changeGiven += currency.TotalValue; } TransactionLog($"GIVE CHANGE: {changeGiven:C}"); } return(changeCurrency); // Old version before Money class //decimal changeGiven = Balance; //int quarters = 0; //int dimes = 0; //int nickels = 0; //while (Balance > 0) //{ // if (Balance >= (decimal).25) // { // Balance -= (decimal).25; // quarters++; // } // else if (Balance >= (decimal).10) // { // Balance -= (decimal).10; // dimes++; // } // else if (Balance >= (decimal).05) // { // Balance -= (decimal).05; // nickels++; // } //} //TransactionLog($"GIVE CHANGE: {changeGiven:C}"); //string totalChange = $"Your Change is {quarters} Quarter(s), {dimes} Dime(s), and {nickels} Nickel(s)"; //return totalChange; }
public NickelTests() { n = new Nickel(); }
public void TestPrintElectronShellCfg_All() { IElement testSubject;; testSubject = new Hydrogen(); Console.WriteLine($"Hydrogen {testSubject.PrintElectronShellCfg()}"); testSubject = new Helium(); Console.WriteLine($"Helium {testSubject.PrintElectronShellCfg()}"); testSubject = new Lithium(); Console.WriteLine($"Lithium {testSubject.PrintElectronShellCfg()}"); testSubject = new Beryllium(); Console.WriteLine($"Beryllium {testSubject.PrintElectronShellCfg()}"); testSubject = new Boron(); Console.WriteLine($"Boron {testSubject.PrintElectronShellCfg()}"); testSubject = new Carbon(); Console.WriteLine($"Carbon {testSubject.PrintElectronShellCfg()}"); testSubject = new Nitrogen(); Console.WriteLine($"Nitrogen {testSubject.PrintElectronShellCfg()}"); testSubject = new Oxygen(); Console.WriteLine($"Oxygen {testSubject.PrintElectronShellCfg()}"); testSubject = new Fluorine(); Console.WriteLine($"Fluorine {testSubject.PrintElectronShellCfg()}"); testSubject = new Neon(); Console.WriteLine($"Neon {testSubject.PrintElectronShellCfg()}"); testSubject = new Sodium(); Console.WriteLine($"Sodium {testSubject.PrintElectronShellCfg()}"); testSubject = new Magnesium(); Console.WriteLine($"Magnesium {testSubject.PrintElectronShellCfg()}"); testSubject = new Aluminum(); Console.WriteLine($"Aluminum {testSubject.PrintElectronShellCfg()}"); testSubject = new Silicon(); Console.WriteLine($"Silicon {testSubject.PrintElectronShellCfg()}"); testSubject = new Phosphorus(); Console.WriteLine($"Phosphorus {testSubject.PrintElectronShellCfg()}"); testSubject = new Sulfur(); Console.WriteLine($"Sulfur {testSubject.PrintElectronShellCfg()}"); testSubject = new Chlorine(); Console.WriteLine($"Chlorine {testSubject.PrintElectronShellCfg()}"); testSubject = new Argon(); Console.WriteLine($"Argon {testSubject.PrintElectronShellCfg()}"); testSubject = new Potassium(); Console.WriteLine($"Potassium {testSubject.PrintElectronShellCfg()}"); testSubject = new Calcium(); Console.WriteLine($"Calcium {testSubject.PrintElectronShellCfg()}"); testSubject = new Scandium(); Console.WriteLine($"Scandium {testSubject.PrintElectronShellCfg()}"); testSubject = new Titanium(); Console.WriteLine($"Titanium {testSubject.PrintElectronShellCfg()}"); testSubject = new Vanadium(); Console.WriteLine($"Vanadium {testSubject.PrintElectronShellCfg()}"); testSubject = new Chromium(); Console.WriteLine($"Chromium {testSubject.PrintElectronShellCfg()}"); testSubject = new Manganese(); Console.WriteLine($"Manganese {testSubject.PrintElectronShellCfg()}"); testSubject = new Iron(); Console.WriteLine($"Iron {testSubject.PrintElectronShellCfg()}"); testSubject = new Cobalt(); Console.WriteLine($"Cobalt {testSubject.PrintElectronShellCfg()}"); testSubject = new Nickel(); Console.WriteLine($"Nickel {testSubject.PrintElectronShellCfg()}"); testSubject = new Copper(); Console.WriteLine($"Copper {testSubject.PrintElectronShellCfg()}"); testSubject = new Zinc(); Console.WriteLine($"Zinc {testSubject.PrintElectronShellCfg()}"); testSubject = new Gallium(); Console.WriteLine($"Gallium {testSubject.PrintElectronShellCfg()}"); testSubject = new Germanium(); Console.WriteLine($"Germanium {testSubject.PrintElectronShellCfg()}"); testSubject = new Arsenic(); Console.WriteLine($"Arsenic {testSubject.PrintElectronShellCfg()}"); testSubject = new Selenium(); Console.WriteLine($"Selenium {testSubject.PrintElectronShellCfg()}"); testSubject = new Bromine(); Console.WriteLine($"Bromine {testSubject.PrintElectronShellCfg()}"); testSubject = new Krypton(); Console.WriteLine($"Krypton {testSubject.PrintElectronShellCfg()}"); testSubject = new Rubidium(); Console.WriteLine($"Rubidium {testSubject.PrintElectronShellCfg()}"); testSubject = new Strontium(); Console.WriteLine($"Strontium {testSubject.PrintElectronShellCfg()}"); testSubject = new Yttrium(); Console.WriteLine($"Yttrium {testSubject.PrintElectronShellCfg()}"); testSubject = new Zirconium(); Console.WriteLine($"Zirconium {testSubject.PrintElectronShellCfg()}"); testSubject = new Niobium(); Console.WriteLine($"Niobium {testSubject.PrintElectronShellCfg()}"); testSubject = new Molybdenum(); Console.WriteLine($"Molybdenum {testSubject.PrintElectronShellCfg()}"); testSubject = new Technetium(); Console.WriteLine($"Technetium {testSubject.PrintElectronShellCfg()}"); testSubject = new Ruthenium(); Console.WriteLine($"Ruthenium {testSubject.PrintElectronShellCfg()}"); testSubject = new Rhodium(); Console.WriteLine($"Rhodium {testSubject.PrintElectronShellCfg()}"); testSubject = new Palladium(); Console.WriteLine($"Palladium {testSubject.PrintElectronShellCfg()}"); testSubject = new Silver(); Console.WriteLine($"Silver {testSubject.PrintElectronShellCfg()}"); testSubject = new Cadmium(); Console.WriteLine($"Cadmium {testSubject.PrintElectronShellCfg()}"); testSubject = new Indium(); Console.WriteLine($"Indium {testSubject.PrintElectronShellCfg()}"); testSubject = new Tin(); Console.WriteLine($"Tin {testSubject.PrintElectronShellCfg()}"); testSubject = new Antimony(); Console.WriteLine($"Antimony {testSubject.PrintElectronShellCfg()}"); testSubject = new Tellurium(); Console.WriteLine($"Tellurium {testSubject.PrintElectronShellCfg()}"); testSubject = new Iodine(); Console.WriteLine($"Iodine {testSubject.PrintElectronShellCfg()}"); testSubject = new Xenon(); Console.WriteLine($"Xenon {testSubject.PrintElectronShellCfg()}"); testSubject = new Cesium(); Console.WriteLine($"Cesium {testSubject.PrintElectronShellCfg()}"); testSubject = new Barium(); Console.WriteLine($"Barium {testSubject.PrintElectronShellCfg()}"); }