Esempio n. 1
0
 public static void GetMoneyBack(Machine machine, Customer customer)
 {
     bool isTest = false; //будет ли производиться возврат денег или же это просто проверка
     int customersMoneyTest = machine.ShowBalance();
     bool isReturnMoney = machine.IsReturnMoney(customersMoneyTest, isTest);
     if (isReturnMoney == true)
     {
         customer.GetMoney(customersMoneyTest);
         Console.WriteLine("Take your money!");
         Console.WriteLine("There are {0} rubles in the purse", customer.ShowPurse());
     }
     else
     {
         Console.WriteLine("Oh no! there is a mistake!");
     }
 }
Esempio n. 2
0
        public static void Pay(Machine machine, Customer customer)
        {
            while (true)
            {
                Console.WriteLine("Press 0 if you pay 1 ruble");
                Console.WriteLine("Press 1 if you pay 2 rubles");
                Console.WriteLine("Press 2 if you pay 5 rubles");
                Console.WriteLine("Press 3 if you pay 10 rubles");
                Console.WriteLine("Press 9 to exit to main menu");
                Console.WriteLine("____________________________");
                int choice;
                bool isCorrect = int.TryParse(Console.ReadLine(), out choice);

                if (isCorrect == false)
                {
                    Console.WriteLine("Your balance is {0}", machine.ShowBalance());
                    Console.WriteLine("Incorrect data. Try again");
                }
                else
                {
                    if (choice == 9)
                    {
                        return;
                    }
                    if ((choice == 0) || (choice == 1) || (choice == 2) || (choice == 3))
                    {
                        if (customer.IsEnoughMoney(choice) == true) //есть ли эта сумма в кошельке
                        {
                            machine.GetCoin(choice);
                            customer.Pay(choice);
                            Console.WriteLine("Your balance is {0}", machine.ShowBalance());
                        }
                        else
                        {
                            Console.WriteLine("You haven't got enough money in your purse!");
                            Console.WriteLine("There are only {0} rubles in purse", customer.ShowPurse());
                        }
                    }
                    else
                    {
                        Console.WriteLine("Incorrect data. Try again");
                    }
                }
            }
        }
Esempio n. 3
0
        public static void Run()
        {
            Machine machine = new Machine();
            Customer customer = new Customer();
            while (true)
            {
                Console.WriteLine("Your balance is {0}", machine.ShowBalance());
                Console.WriteLine("What do you want?");
                Console.WriteLine("Press 0 if you want to choose food");
                Console.WriteLine("Press 1 if you want to pay");
                Console.WriteLine("Press 2 to get spare money back"); //получить сдачу
                Console.WriteLine("Press 9 to exit");
                Console.WriteLine("____________________________");
                int choice;
                bool isCorrect = int.TryParse(Console.ReadLine(), out choice);

                if (isCorrect == false)
                {
                    Console.WriteLine("Incorrect data. Try again");
                }
                else
                {
                    if (choice == 9)
                    {
                        break; //выход из программы
                    }
                    else
                    {
                        switch (choice)
                        {
                            case 0:
                                ChooseFood(machine);
                                break;
                            case 1:
                                Pay(machine, customer);
                                break;
                            case 2:
                                GetMoneyBack(machine, customer);
                                break;
                            default:
                                Console.WriteLine("Incorrect data. Try again");
                                break;
                        }
                    }
                }
            }
        }