private void LoadCustomCurrency() { XDocument xmlMonies = XDocument.Load("Money.xml"); foreach (XElement xmlMoney in xmlMonies.Descendants("money")) { string type = xmlMoney.Element("type").Value; string value = xmlMoney.Element("value").Value; Monies.Add(new Money(type, value)); } }
private void LoadDefaultCurrency() { Monies.Add(new Money("Note", "50")); Monies.Add(new Money("Note", "20")); Monies.Add(new Money("Note", "10")); Monies.Add(new Money("Note", "5")); Monies.Add(new Money("Coin", "2")); Monies.Add(new Money("Coin", "1")); Monies.Add(new Money("Coin", "0.5")); Monies.Add(new Money("Coin", "0.2")); Monies.Add(new Money("Coin", "0.1")); Monies.Add(new Money("Coin", "0.02")); Monies.Add(new Money("Coin", "0.01")); }
private void SelectMoney() { Console.WriteLine("\r\nPlease select a bank note to use for your purchase (type 1, 2, 3..)\r\n"); List <Money> bankNotes = Monies.Where(money => money.Type == MoneyType.BankNote).ToList(); foreach (Money money in bankNotes) { Console.WriteLine(string.Format("£{0}", money.Denomination)); } string noteNumber = Console.ReadLine(); NoteToUse = bankNotes[int.Parse(noteNumber) - 1]; ShowChange(); }
private void ShowChange() { List <Change> changeList = new List <Change>(); double changeRemaining = NoteToUse.Denomination - ProductToPurchase.Price; foreach (Money money in Monies.OrderByDescending(money => money.Denomination)) { int amount = (int)Math.Floor(changeRemaining / money.Denomination); if (amount > 0) { changeList.Add(new Change(money, amount)); } changeRemaining = Math.Round(changeRemaining - amount * money.Denomination, 2); } Console.WriteLine("\r\nYour change is:"); foreach (Change change in changeList) { Console.WriteLine(string.Format("{0} x {1}", change.Amount, change.Money.GetValueName())); } Console.WriteLine("\r\nThank you for your purchase!"); Console.WriteLine("\r\nWould you like to make another purchase? y/n"); string response = Console.ReadLine(); switch (response) { case "y": SelectProduct(); break; default: return; } }