Ejemplo n.º 1
0
        public void withdraw()
        {
            Console.WriteLine("Insert amount of money you want to withdraw");
            int    amount;
            string writtenAmount = Console.ReadLine();

            amount = int.Parse(writtenAmount);

            if (machine.getBalance() - amount >= 0)
            {
                machine.giveCash(amount);
                machine.ejectCard();
                machine.setState(machine.getNoCardState());
            }
            else if (machine.getBalance() - amount < 0 && machine.getBalance() != 0)
            {
                Console.WriteLine("Available cash in ATM is only: " + machine.getBalance() + ". Do you want to withdraw? yes/no.");
                String writtenAnswer = Console.ReadLine();

                if (writtenAnswer.Equals("yes"))
                {
                    amount = machine.getBalance();
                    machine.giveCash(amount);
                    machine.ejectCard();
                    machine.setState(machine.getNoCashState());
                }
                else if (writtenAnswer.Equals("no"))
                {
                    Console.WriteLine("Please come later.");
                    machine.ejectCard();
                    machine.setState(machine.getNoCardState());
                }
                else
                {
                    Console.WriteLine("Answer yes or no.");
                }
            }
        }
Ejemplo n.º 2
0
        public void insertPin(Card card)
        {
            card.aboutMe();

            int i;

            for (i = 1; i < 4; i++)
            {
                Console.WriteLine("Insert pin:");
                string written = Console.ReadLine();

                try
                {
                    int format = Int16.Parse(written);
                }
                catch (FormatException)
                {
                    Console.WriteLine("Inserted PIN is not a number! Try again another time.", written);
                    Console.ReadKey();
                }


                int pin = int.Parse(written);


                if (card.cardPin == pin)
                {
                    Console.WriteLine("PIN authenticated.");
                    machine.setState(machine.getWithdrawState());
                    break;
                }
                if (card.cardPin != pin)
                {
                    Console.WriteLine("Wrong PIN!");
                    Console.WriteLine("Try " + (3 - i) + " more times.");
                }
                if (card.cardPin != pin && i == 3)
                {
                    machine.blockCard(card);
                    machine.ejectCard();
                    machine.setState(machine.getNoCardState());
                }
            }
        }