public int TakeMoney(Bill bill)
        {
            money += bill.Value();
            bills[bill.Value()]++;

            return money;
        }
        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();
        }
 //0-1 1-2 2-5 3-10 4-20 5-50 6-100
 public void TakeMoney(Bill bill)
 {
     if (billCashDesk.ContainsKey(bill.amount))
         billCashDesk[bill.amount]++;
     else
         billCashDesk.Add(bill.amount, 1);
 }
 public void TakeMoney ( Bill b )
 {
     if(!money.Keys.Contains((int)b))
     {
         money.Add((int)b , 0);
     }
     money[(int)b]++;
 }
Exemple #5
0
 public static bool CheckBills(Bill bill)
 {
     if (bill.Amount==2 || bill.Amount==5 || bill.Amount==10 || bill.Amount==20 || bill.Amount==50 || bill.Amount==100)
     {
         return true;
     }
     return false;
 }
Exemple #6
0
        public BatchBill(Bill[] bills)
        {
            this.bills = new Bill[bills.Length];

            for (int i = 0; i < bills.Length; i++)
            {
                this.bills[i] = bills[i];
            }
        }
Exemple #7
0
        public void TakeMoney(Bill bill)
        {
            this.money += bill.Amount;

            if (this.container.ContainsKey(bill.Amount))
            {
                this.container[bill.Amount]++;
            }
            else
            {
                this.container.Add(bill.Amount, 1);
            }
        }
 public void TakeMoney(Bill bill)
 {
     if (CheckBills(bill))
     {
         if (desk.ContainsKey(bill.Amount))
         {
             desk[bill.Amount] = desk[bill.Amount] + 1;
         }
         else
         {
             desk.Add(bill.Amount, 1);
         }
     }
     else
     {
         Console.WriteLine("There is no such bill!");
     }
 }
        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
        }
Exemple #10
0
        public void TakeMoney(Bill bill)
        {
            if (!Bill.Validate(bill))
            {
                Console.WriteLine("The bill {0} is not valid! Unacceptablle!!!", (int)bill);
                return;
            }

            if (bills.ContainsKey(bill))
            {
                bills[bill]++;
            }
            else
            {
                bills.Add(bill, 1);
            }

            total += bill.Value;
        }
Exemple #11
0
        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;
                }
            }
        }
 private bool CheckBills(Bill bill)
 {
     if (bill.Amount == 2 || bill.Amount == 5 || bill.Amount == 10 || bill.Amount == 20 || bill.Amount == 50 || bill.Amount == 100)
     {
         return true;
     }
     return false;
 }
 public BatchBill ( Bill[] bills ) : this(bills.ToList())
 { }
Exemple #14
0
        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();
            }
        }
Exemple #15
0
 public static int Value(Bill a)
 {
     return a.Amount;
 }
        public bool TakeMoney(Bill bill)
        {
            if (!bills.ContainsKey(bill.Amount)) return false;

            bills[bill.Amount]++;
            return true;
        }
 /// <summary>
 /// Removes a single bill from the CashDesk object.
 /// </summary>
 /// <param name="singleBill">Bill to remove.</param>
 public void RemoveMoney(Bill singleBill)
 {
     // If bill exists, removes it from CashDesk
     if (this.bills.Keys.Contains(singleBill.Value))
     {
         this.bills.Remove(singleBill.Value);
         this.BillTotalProp -= singleBill.Value;
         Console.WriteLine("SUCCES: removed {0} bill !", singleBill.ToString());
     }
     else
     {
         Console.WriteLine("ERROR: bills list does not contain a {0} bill !", singleBill.ToString());
     }
 }
Exemple #18
0
 public BatchBillEnum(Bill[] list)
 {
     this.bills = list;
 }
        /// <summary>
        /// Adds a Bill object to the CashDesk object.
        /// </summary>
        /// <param name="singleBill">Bill object to add.</param>
        public void TakeMoney(Bill singleBill)
        {
            // Check if bill is valid then add it to CashDesk
            if (this.validBillValues.Contains(singleBill.Value))
            {
                this.BillTotalProp += singleBill.Value;
                if (!this.bills.ContainsKey(singleBill.Value))
                {
                    this.bills.Add(singleBill.Value, 1);
                }
                else
                {
                    this.bills[singleBill.Value]++;
                }

                Console.WriteLine("SUCCESS: added {0} bill !", new Bill(singleBill.Value));
            }
        }
        private bool GiveMoney(Bill bill)
        {
            if (!bills.ContainsKey(bill.Amount)) return false;

            bills[bill.Amount]--;
            return true;
        }
Exemple #21
0
        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);
        }