static void Main(string[] args) { var a = new Bill(10); var b = new Bill(5); var c = new Bill(10); Console.WriteLine((int)a); Console.WriteLine(a); Console.WriteLine(a == b); Console.WriteLine(a == c); List<Bill> bills = new List<Bill> { new Bill(10), new Bill(20), new Bill(50), new Bill(100) }; TheBatchBill batch = new TheBatchBill(bills); foreach (var bill in batch) { Console.WriteLine(bill); } List<Bill> bills1 = new List<Bill> { new Bill(10), new Bill(20), new Bill(50), new Bill(100), new Bill(100) }; TheBatchBill batch1 = new TheBatchBill(bills); CashDesk.CashDesk desk = new CashDesk.CashDesk(); desk.TakeMoney(new Bill(100)); desk.TakeMoney(batch1); desk.TakeMoney(new Bill(10)); Console.WriteLine(desk.Total()); desk.Inspect(); }
public static void Tests ( ) { var a = new Bill(10); var b = new Bill(5); var c = new Bill(10); Console.WriteLine((int)a); //10 Console.WriteLine(a); // "A 10$ bill" Console.WriteLine(a == b); //False Console.WriteLine(a == c); //True Console.WriteLine(); var bills = new List<Bill> { new Bill(10) , new Bill(20) , new Bill(50) , new Bill(100) }; var batch = new BatchBill(bills); foreach(var bill in batch) { Console.WriteLine(bill); } // A 10$ bill // A 20$ bill // A 50$ bill // A 100$ bill Console.WriteLine("Batch test passed!"); var billsForCashDesk = new Bill[] { new Bill(10) , new Bill(20) , new Bill(50) , new Bill(100) , new Bill(100) }; var batchForCashDesk = new BatchBill(billsForCashDesk); CashDesk.CashDesk desk = new CashDesk.CashDesk(); desk.TakeMoney(new Bill(100)); desk.TakeMoney(batchForCashDesk); desk.TakeMoney(new Bill(10)); Console.WriteLine(desk.Total()); // 390 desk.Inspect(); // We have a total of 390$ in the desk // We have the following count of bills, sorted in ascending order: // 10$ bills - 2 // 20$ bills - 1 // 50$ bills - 1 // 100$ bills - 3 }
static void Main ( string[] args ) { CashDesk.CashDesk desk = new CashDesk.CashDesk(); bool checkForExit = false; while(true) { Console.WriteLine("takebill < number > -adds a bill with value < number > to the cashdesk"); Console.WriteLine("takebatch < number1 > < number2 > ... - adds a batch of bills to the cashdesk"); Console.WriteLine("total - prints the total money in the cash desk"); Console.WriteLine("inspect - prints detailed information of the money in the cashdesk"); Console.WriteLine("exit - exits the application"); string command = Console.ReadLine(); string[] words = command.Split(new char[] { ' ' } , StringSplitOptions.RemoveEmptyEntries); switch(words[0]) { case "takebill": desk.TakeMoney(new Bill(int.Parse(words[1]))); Console.WriteLine("Added!"); break; case "takebatch": for(int i = 1 ; i < words.Length ; i++) { desk.TakeMoney(new Bill(int.Parse(words[i]))); } Console.WriteLine("Added!"); break; case "total": Console.WriteLine(desk.Total()); break; case "inspect": desk.Inspect(); break; case "exit": checkForExit = true; break; default: Console.WriteLine("Invalid operation!"); break; } if(checkForExit) { break; } Console.ReadKey(); Console.Clear(); } }
public static void Main() { var cashDesk = new CashDesk.CashDesk(); while (true) { string[] commandInput = Console.ReadLine().Split(' '); if (commandInput[0] == "takebill") { var bill = new Bill(int.Parse(commandInput[1])); cashDesk.TakeMoney(bill); } else if (commandInput[0] == "takebatch") { List<Bill> listOfBills = new List<Bill>(); for (int i = 1; i < commandInput.Length; i++) { listOfBills.Add(new Bill(int.Parse(commandInput[i]))); } var newBatchBill = new BatchBill(listOfBills); cashDesk.TakeMoney(newBatchBill); } else if (commandInput[0] == "total") { Console.WriteLine(cashDesk.Total()); } else if (commandInput[0] == "inspect") { cashDesk.Inspect(); } else if (commandInput[0] == "exit") { break; } } }
static void Main(string[] args) { CashDesk obj = new CashDesk(); Console.WriteLine("Commandlist \ntakebill \ntakebillBatch \ntakecoins \ntakecoinBatch \ninspect \ntotal \nexit \n"); while (true) { string wholeCommand = Console.ReadLine(); string[] command = wholeCommand.Split(' '); switch (command[0]) { case "takebill": if (command.Length > 2) { Console.WriteLine("takebill command takes only 1 argument!"); break; } else { obj.TakeMoney(new Bill(int.Parse(command[1]))); break; } case "takebillBatch": if (command.Length > 2) { List <Bill> bills = new List <Bill>(); for (int i = 1; i < command.Length; i++) { bills.Add(new Bill(int.Parse((command[i])))); } obj.TakeMoney(new BatchBill(bills)); break; } else { Console.WriteLine("takebillBatch command takes more than 1 argument"); break; } case "takecoins": if (command.Length > 2) { Console.WriteLine("takecoins command takes only 1 argument"); break; } else { obj.TakeMoney(new Coins(int.Parse(command[1]))); break; } case "takecoinBatch": if (command.Length > 2) { List <Coins> coins = new List <Coins>(); for (int i = 1; i < command.Length; i++) { coins.Add(new Coins(int.Parse(command[i]))); } obj.TakeMoney(new BatchCoins(coins)); break; } else { Console.WriteLine("takecoinBatch command takes more than 1 argument!"); break; } case "inspect": obj.Inspect(); break; case "total": obj.Total(); break; case "exit": Environment.Exit(0); break; default: Console.WriteLine("Wrong option"); break; } } }
/// <summary> /// Main Method. /// </summary> public static void Main() { CashDesk obj = new CashDesk(); while (true) { // Split input command string wholeCommand = Console.ReadLine(); if (wholeCommand == null) { continue; } string[] command = wholeCommand.Split(' '); switch (command[0]) { case "takebill": if (IsInputLenghtLongerThan2(command)) { if (command.Length < 3) { obj.TakeMoney(new Bill(int.Parse(command[1]))); } else { Console.WriteLine("ERROR: takebill command takes only 1 parameter"); } } else { Console.WriteLine("Input Command lenght too short"); } break; case "takebatch": if (IsInputLenghtLongerThan2(command)) { List<Bill> billList = new List<Bill>(); for (int i = 1; i < command.Length; i++) { billList.Add(new Bill(int.Parse(command[i]))); } BatchBill batch = new BatchBill(billList); obj.TakeMoney(batch); } break; case "takecoin": if (IsInputLenghtLongerThan2(command)) { if (command.Length < 3) { obj.TakeMoney(new Coin(int.Parse(command[1]))); } else { Console.WriteLine("ERROR: Takecoin command takes only 1 parameter !"); } } break; case "takebatchcoin": if (IsInputLenghtLongerThan2(command)) { List<Coin> coinlist = new List<Coin>(); for (int i = 1; i < command.Length; i++) { coinlist.Add(new Coin(int.Parse(command[i]))); } BatchCoin coinBatch = new BatchCoin(coinlist); obj.TakeMoney(coinBatch); Console.WriteLine("SUCCESS: added new batch of coins !"); } break; case "removebill": if (IsInputLenghtLongerThan2(command)) { if (command.Length < 3) { obj.RemoveMoney(new Bill(int.Parse(command[1]))); } else { Console.WriteLine("ERROR: removebill command takes only 1 parameter !"); } } break; case "removebatch": if (IsInputLenghtLongerThan2(command)) { List<Bill> billList = new List<Bill>(); for (int i = 1; i < command.Length; i++) { billList.Add(new Bill(int.Parse(command[i]))); } BatchBill batch = new BatchBill(billList); obj.RemoveMoney(batch); } break; case "removeallbills": if (command.Length < 2) { obj.RemoveAllBills(); Console.WriteLine("SUCCES: you have removed all coins !"); } else { Console.WriteLine("ERROR: removeallbills command takes no parameters !"); } break; case "removecoin": if (IsInputLenghtLongerThan2(command)) { if (command.Length < 3) { obj.RemoveMoney(new Coin(int.Parse(command[1]))); } else { Console.WriteLine("ERROR: removecoin command takes only 1 parameter !"); } } break; case "removebatchcoin": if (IsInputLenghtLongerThan2(command)) { List<Coin> coinList = new List<Coin>(); for (int i = 1; i < command.Length; i++) { coinList.Add(new Coin(int.Parse(command[i]))); } BatchCoin batch = new BatchCoin(coinList); obj.RemoveMoney(batch); } break; case "removeallcoins": if (command.Length < 2) { obj.RemoveAllCoins(); Console.WriteLine("SUCCES: you have removed all coins !"); } else { Console.WriteLine("ERROR: removeallcoins command takes no parameters !"); } break; case "total": if (command.Length < 2) { Console.WriteLine(obj.Total()); } else { Console.WriteLine("ERROR: total command takes no parameters !"); } break; case "inspect": if (command.Length < 2) { obj.Inspect(); } else { Console.WriteLine("ERROR: inspect commands takes no parameters !"); } break; case "exit": if (command.Length < 2) { Environment.Exit(0); } else { Console.WriteLine("did you mean \"exit\" ?"); } break; default: Console.WriteLine("Unknown Command " + command); break; } } }
static void Main(string[] args) { CashDesk obj = new CashDesk(); Console.WriteLine("Commandlist \ntakebill \ntakebillBatch \ntakecoins \ntakecoinBatch \ninspect \ntotal \nexit \n"); while (true) { string wholeCommand = Console.ReadLine(); string[] command = wholeCommand.Split(' '); switch (command[0]) { case "takebill": if (command.Length > 2) { Console.WriteLine("takebill command takes only 1 argument!"); break; } else { obj.TakeMoney(new Bill(int.Parse(command[1]))); break; } case "takebillBatch": if (command.Length > 2) { List<Bill> bills = new List<Bill>(); for (int i = 1; i < command.Length; i++) { bills.Add(new Bill(int.Parse((command[i])))); } obj.TakeMoney(new BatchBill(bills)); break; } else { Console.WriteLine("takebillBatch command takes more than 1 argument"); break; } case "takecoins": if (command.Length > 2) { Console.WriteLine("takecoins command takes only 1 argument"); break; } else { obj.TakeMoney(new Coins(int.Parse(command[1]))); break; } case "takecoinBatch": if (command.Length > 2) { List<Coins> coins = new List<Coins>(); for (int i = 1; i < command.Length; i++) { coins.Add(new Coins(int.Parse(command[i]))); } obj.TakeMoney(new BatchCoins(coins)); break; } else { Console.WriteLine("takecoinBatch command takes more than 1 argument!"); break; } case "inspect": obj.Inspect(); break; case "total": obj.Total(); break; case "exit": Environment.Exit(0); break; default: Console.WriteLine("Wrong option"); break; } } }
static void Main(string[] args) { CashDesk.Bill a = new CashDesk.Bill(5); CashDesk.Bill b = new CashDesk.Bill(5); CashDesk.Bill c = new CashDesk.Bill(10); List<Bill> batch = new List<Bill>() { a, b, c }; BatchBill batchbill = new BatchBill(batch); Dictionary<int, int> billCashDesk = new Dictionary<int, int>(); CashDesk.CashDesk desk = new CashDesk.CashDesk(); bool exit = false; Console.WriteLine("CashDesk application\n"); Console.WriteLine("/help - for the full list of commands\n"); StringBuilder userInput = new StringBuilder(); while (!exit) { userInput.Append(Console.ReadLine()); if (userInput.ToString().Contains("takebill")) { userInput.Replace("takebill", ""); int amount = -1; if (int.TryParse(userInput.ToString(), out amount)) { desk.TakeMoney(new Bill(amount)); } else Console.WriteLine("ERROR: Invalid amount!"); } else if (userInput.ToString().Contains("takebatchbill")) { userInput.Replace("takebatchbill", ""); List<Bill> listOfBills = new List<Bill>(); string[] arrayOfBills = userInput.ToString().Split(' '); int amount = -1; foreach (var bill in arrayOfBills) { if (int.TryParse(bill, out amount)) { listOfBills.Add(new Bill(amount)); } } if (listOfBills.Count == 0) Console.WriteLine("ERROR: Invalid amount!"); else desk.TakeMoney(new BatchBill(listOfBills)); } else if (userInput.ToString().Contains("total")) { Console.WriteLine("${0} ", desk.Total()); } else if (userInput.ToString().Contains("inspect")) { if (desk.Total() != 0) desk.Inspect(); else Console.WriteLine("The Cash Desk is empty right now."); } else if (userInput.ToString().Contains("exit")) { exit = true; } else if (userInput.ToString().Contains("/help")) { CashDeskAplliication.Program.PrintHelp(); } else Console.WriteLine("ERROR: Invalid command!"); userInput.Clear(); } }
static void Main(string[] args) { Console.WriteLine("Hi! Input a command:"); bool exit = false; CashDesk.CashDesk desk = new CashDesk.CashDesk(); do { string[] splited = Console.ReadLine().Split(' '); switch (splited[0]) { case "takebill": desk.TakeMoney(new Bill(int.Parse(splited[1]))); break; case "takebatch": Bill[] batch = new Bill[splited.Length - 1]; for (int i = 0; i < batch.Length; i++) { batch[i] = new Bill(int.Parse(splited[i + 1])); } desk.TakeMoney(new BatchBill(batch)); break; case "takecoin": desk.TakeMoney(new Coin(int.Parse(splited[1]))); break; case "takecoinbatch": Coin[] coinBatch = new Coin[splited.Length - 1]; for (int i = 0; i < coinBatch.Length; i++) { coinBatch[i] = new Coin(int.Parse(splited[i + 1])); } desk.TakeMoney(new BatchCoin(coinBatch)); break; case "total": Console.WriteLine(desk.Total); break; case "inspect": desk.Inspect(); break; case "getchange": List <Coin> change = new List <Coin>(); for (int i = 1; i < splited.Length; i++) { int value; if (int.TryParse(splited[i], out value)) { change.Add(new Coin(value)); } } var bestChange = desk.GiveChange(change); break; case "exit": exit = true; break; default: Console.WriteLine("Unknown command."); break; } } while (!exit); }
static void Main(string[] args) { Console.WriteLine("Hi! Input a command:"); bool exit = false; CashDesk.CashDesk desk = new CashDesk.CashDesk(); do { string[] splited = Console.ReadLine().Split(' '); switch (splited[0]) { case "takebill": desk.TakeMoney(new Bill(int.Parse(splited[1]))); break; case "takebatch": Bill[] batch = new Bill[splited.Length - 1]; for (int i = 0; i < batch.Length; i++) { batch[i] = new Bill(int.Parse(splited[i + 1])); } desk.TakeMoney(new BatchBill(batch)); break; case "takecoin": desk.TakeMoney(new Coin(int.Parse(splited[1]))); break; case "takecoinbatch": Coin[] coinBatch = new Coin[splited.Length - 1]; for (int i = 0; i < coinBatch.Length; i++) { coinBatch[i] = new Coin(int.Parse(splited[i + 1])); } desk.TakeMoney(new BatchCoin(coinBatch)); break; case "total": Console.WriteLine(desk.Total); break; case "inspect": desk.Inspect(); break; case "getchange": List<Coin> change = new List<Coin>(); for (int i = 1; i < splited.Length; i++) { int value; if(int.TryParse(splited[i], out value)) { change.Add(new Coin(value)); } } var bestChange = desk.GiveChange(change); break; case "exit": exit = true; break; default: Console.WriteLine("Unknown command."); break; } } while (!exit); }