Esempio n. 1
0
        static void Main(string[] args)
        {
            BankAccount Tim  = new BankAccount();
            BankAccount Mark = new BankAccount("Mark", true, 45.00);

            Mark.deposit(25.25);
            Tim.withdraw(76);
            Mark.display_balance();
        }
        static void Main(string[] args)
        {
            BankAccount account;

            while (true)
            {
                Console.WriteLine("How much money are you starting out with?");
                try
                {
                    account = new BankAccount(Convert.ToDouble(Console.ReadLine()));
                    break;
                } catch (Exception e)
                {
                    Console.WriteLine($"Account cannot be created. {e}");
                }
            }

            while (true)
            {
                Console.WriteLine($"You have {account.getBalance} funds in your account.");
                Console.WriteLine("Press 1 to withdraw,\npress 2 to deposit.");

                ConsoleKeyInfo pressedKey = Console.ReadKey();
                if (pressedKey.Key != ConsoleKey.D1 && pressedKey.Key != ConsoleKey.D2)
                {
                    Console.WriteLine("That was not a valid option, please try again.");
                    continue;
                }

                try
                {
                    Console.WriteLine();
                    switch (pressedKey.Key)
                    {
                    case ConsoleKey.D1:
                        Console.WriteLine("How much money would you like to withdraw?");
                        account.withdraw(Convert.ToDouble(Console.ReadLine()));
                        break;

                    case ConsoleKey.D2:
                        Console.WriteLine("How much money would you like to deposit?");
                        account.deposit(Convert.ToDouble(Console.ReadLine()));
                        break;

                    default:
                        throw new Exception("switch default encountered, something bad happend!");
                    }
                } catch (Exception e)
                {
                    Console.WriteLine($"Something went wrong. {e}\nPlease try again.");
                }
            }
        }