Ejemplo n.º 1
0
        static void Main(string[] args)
        {

            //decimal dec = 2512424.12234m;
            //string coins = (dec % 1).ToString();
            //coins = coins.Remove(0, 2);
            //Coin coin = new Coin(int.Parse(coins));
            //Console.WriteLine(coin.Value);
            //BatchCoins vt = new BatchCoins(new List<Coin>() { coin });
            //Console.WriteLine(vt.GiveChange());

            CashDesk desk = new CashDesk();
            ConsoleCommands(desk);
            //BatchCoins coins = new BatchCoins(new Coin[] { new Coin(20), new Coin(50), new Coin(50), new Coin(50), new Coin(10), new Coin(20) });
            //Console.WriteLine(coins.GiveChange());

        }
Ejemplo n.º 2
0
 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");
         }
     }
 }
Ejemplo n.º 3
0
 private static void Tests()
 {
     var bills = new Bill[] { new Bill(10), new Bill(20), new Bill(50), new Bill(100), new Bill(100) };
     var batch = new BatchBill(bills);
     CashDesk desk = new CashDesk();
     desk.TakeMoney(batch);
     desk.TakeMoney(new Bill(100));
     desk.TakeMoney(new Bill(10));
     desk.Inspect();
 }