public void TakeMoney(BatchBill batch) { foreach (Bill bill in batch) { TakeMoney(bill); } }
public void TakeMoney(BatchBill batch) { bool check = false; foreach (Bill bill in batch) { if (CheckBills(bill)) { check = true; } else { check = false; break; } } if (check == true) { foreach (Bill bill in batch) { if (desk.ContainsKey(bill.Amount)) { desk[bill.Amount] = desk[bill.Amount] + 1; } else { desk.Add(bill.Amount, 1); } } } }
public void TakeMoney(BatchBill batch) { bool check = false; foreach (Bill bill in batch) { if (CheckBills(bill)) { check = true; } else { check = false; break; } } if (check == true) { foreach (Bill bill in batch) { if (desk.ContainsKey(bill.Amount)) { desk[bill.Amount] = desk[bill.Amount] + 1; } else { desk.Add(bill.Amount, 1); } } } }
public void TakeMoney(BatchBill batchBill) { foreach (Bill bill in batchBill) { if (billCashDesk.ContainsKey(bill.amount)) billCashDesk[bill.amount]++; else billCashDesk.Add(bill.amount, 1); } }
public void TakeMoney ( BatchBill batch ) { foreach(Bill item in batch) { if(!money.Keys.Contains((int)item)) { money.Add((int)item , 0); } money[item.AmountOfBill]++; } }
public void TakeMoney(BatchBill batchBill) { foreach (Bill bbill in batchBill) { if (repository.ContainsKey(bbill)) { repository[bbill]++; } else { repository.Add(bbill, 1); } } }
public void TakeMoney(BatchBill batch) { this.money += batch.Total(); foreach (Bill bill in batch) { if (this.container.ContainsKey(bill.Amount)) { this.container[bill.Amount]++; } else { this.container.Add(bill.Amount, 1); } } }
public void TakeMoney(BatchBill batch) { this.money += batch.Total(); foreach (Bill bill in batch) { if (this.container.ContainsKey(bill.Amount)) { this.container[bill.Amount]++; } else { this.container.Add(bill.Amount, 1); } } }
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 }
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; } } }
/// <summary> /// Removes a list of bills if they exist in the CashDesk object. /// </summary> /// <param name="batchList">List of bills to remove.</param> public void RemoveMoney(BatchBill batchList) { foreach (Bill bill in batchList) { if (!this.bills.ContainsKey(bill.Value)) { Console.WriteLine("ERROR: could not find a {0} bill to remove !", bill.ToString()); } else { this.bills.Remove(bill.Value); this.BillTotalProp -= bill.Value; Console.WriteLine("SUCCES: Removed {0} !", bill.Value); } } }
/// <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; } } }
private void GiveMoney(BatchBill batch) { foreach (Bill bill in batch) { GiveMoney(bill); } }
public bool TakeMoney(BatchBill batch, out List<int> rejected) { rejected = new List<int>(); bool allBillsAreCorrect = true; foreach (Bill bill in batch) { if (!TakeMoney(bill)) { allBillsAreCorrect = false; rejected.Add(bill.Amount); } } return allBillsAreCorrect; }
public string Sell(int dollarValue, int centValue, BatchBill batchOfBills, BatchCoin batchOfCoins, out List<int> rejectedBills, out List<int> rejectedCoins) { rejectedBills = new List<int>(); rejectedCoins = new List<int>(); List<Bill> validBills = new List<Bill>(); int validBillsAmount = 0; foreach (Bill bill in batchOfBills) { if (bills.ContainsKey(bill.Amount)) { validBills.Add(bill); validBillsAmount += bill.Amount; } } List<Coin> validCoins = new List<Coin>(); int validCoinsAmount = 0; foreach (Coin coin in batchOfCoins) { if (coins.ContainsKey(coin.Amount)) { validCoins.Add(coin); validCoinsAmount += coin.Amount; } } int validMoney = validBillsAmount * 100 + validCoinsAmount; int priceMoney = dollarValue * 100 + centValue; bool needToGiveChange = true; string output = String.Empty; if (validMoney < priceMoney) return "Not enough money!"; else if (validMoney == priceMoney) { needToGiveChange = false; output = "Item sold successfully! No change needed!"; } bool hasInvalidBills = !TakeMoney(batchOfCoins, out rejectedCoins); bool hasInvalidCoins = !TakeMoney(batchOfBills, out rejectedBills); if (needToGiveChange) { output = GiveChange(validMoney - priceMoney); bool changeIsGiven = output[0] == 'C' ? false : true; if (changeIsGiven) output = "Item sold successfully!\r\nGiven back change: " + output; else { GiveMoney(batchOfBills); GiveMoney(batchOfCoins); } } return output; }
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(); } }
/// <summary> /// Adds multiple Bill objects to the CashDesk object. /// </summary> /// <param name="batchList">Multiple bills to add.</param> public void TakeMoney(BatchBill batchList) { // Remove the following code to add all but the not legit bill bool isLegit = true; foreach (Bill billToAdd in batchList.Cast<Bill>().Where(billToAdd => !this.validBillValues.Contains(billToAdd.Value))) { isLegit = false; } //// foreach (Bill bill in batchList.Cast<Bill>().Where(bill => isLegit)) { if (!this.bills.ContainsKey(bill.Value)) { this.bills.Add(bill.Value, 1); this.BillTotalProp += bill.Value; } else { this.bills[bill.Value]++; this.BillTotalProp += bill.Value; } } if (isLegit) { Console.WriteLine("SUCCESS: added new batch of bills !"); } }
public void TakeMoney(BatchBill batch) { foreach (Bill bill in batch) { TakeMoney(bill); } }