public string GiveChange() { int total = 0; string change = string.Empty; for (int i = 0; i < Coins.Count; i++) { total += Coins[i].Value; } if (total > 100) { int bill = total / 100; Bill bil = new Bill(bill); int coins = total % 100; Coin coin = new Coin(coins); change = bil.ToString() + "and " + coin.ToString(); } return change; }
private static Bill TurningItemPriceIntoBills(decimal price) { int floor = (int)Math.Floor(price); Bill biil = new Bill(floor); string takeCoins = (price % 1).ToString(); takeCoins = takeCoins.Remove(0, 2); Coin coins = new Coin(int.Parse(takeCoins)); BatchCoins batchcoins = new BatchCoins(new List<Coin>() { coins }); Bill batchttt = batchcoins.GiveBill(); biil = biil + batchttt; return biil; }
private static void ConsoleCommands(CashDesk desk) { while (true) { Item item = new Item(); string[] input = Console.ReadLine().Split(new char[] { ' ' }); if (input[0] == Command.exit.ToString()) { return; } else if (input[0] == Command.takebill.ToString()) { int validate = int.Parse(input[1]); Validate(ref validate); Bill bill = new Bill(validate); desk.TakeMoney(bill); } else if (input[0] == Command.takebatch.ToString()) { Bill[] bill = new Bill[input.Length - 1]; int validete = 0; for (int i = 0; i < input.Length - 1; i++) { validete = int.Parse(input[i + 1]); Validate(ref validete); bill[i] = new Bill(validete); } BatchBill batch = new BatchBill(bill); desk.TakeMoney(batch); } else if (input[0] == Command.total.ToString()) { Console.WriteLine(desk.Total()); } else if (input[0] == Command.inspect.ToString()) { desk.Inspect(); } else if (input[0] == Command.takecoins.ToString()) { Coin[] coin = new Coin[input.Length - 1]; for (int i = 1; i < coin.Length - 1; i++) { coin[i] = new Coin(int.Parse(input[i + 1])); } BatchCoins coins = new BatchCoins(coin); desk.TakeMoney(coins); } else if (input[0] == Command.sellitem.ToString()) { item = new Item(decimal.Parse(input[2])); } else if (input[0] == Command.buyitem.ToString()) { if (decimal.Parse(input[2]).Equals(item.Price)) { Console.WriteLine("Thanks"); } else if (decimal.Parse(input[2]) >= item.Price) { Bill turned = TurningItemPriceIntoBills(item.Price); Console.WriteLine(turned.Value-item.Price); } } else { Console.WriteLine("Wrong command"); } } }
private static Coin TurningItemPriceIntoCoins(decimal price) { string takeCoins = (price % 1).ToString(); takeCoins = takeCoins.Remove(0, 2); Coin coins = new Coin(int.Parse(takeCoins)); BatchCoins batchcoins = new BatchCoins(new List<Coin>() { coins }); coins = batchcoins.GiveCoin(); return coins; }
public Coin GiveCoin() { Coin coin = new Coin(); int total = 0; string change = string.Empty; for (int i = 0; i < Coins.Count; i++) { total += Coins[i].Value; } if (total > 100) { int coins = total % 100; coin = new Coin(coins); } return coin; }
public BatchCoins(Coin[] coins) : this(coins.ToList()) { }