示例#1
0
        public static void Main()
        {
            BankAccount acc = new BankAccount();

            acc.Id = 1;
            acc.Deposit(15);
            acc.Withdraw(10);

            Console.WriteLine($"{acc.ToString()}");
        }
示例#2
0
        static void Main(string[] args)
        {
            var acc = new BankAccount();

            acc.id = 1;
            acc.Deposit(22);
            acc.Withdraw(12);

            Console.WriteLine(acc.ToString());
        }
示例#3
0
 private static void Print(string[] commands, Dictionary <int, BankAccount> accounts, int id)
 {
     if (accounts.ContainsKey(id))
     {
         BankAccount acc = accounts[id];
         Console.WriteLine(acc.ToString());
     }
     else
     {
         Console.WriteLine("Account does not exist");
     }
 }
示例#4
0
        static void Main(string[] args)
        {
            string choice;
            bool   writeMenu = true;


            //  BankAccount myAccount = GetAccountDetailsFromUser();

            BankAccount myAccount = CreateTestAccount(); // to save typing while testing.

            while (writeMenu)
            {
                choice = GetUserChoiceFromMenu();

                switch (choice)
                {
                case "1":
                    LodgeMoney(myAccount);
                    break;

                case "2":
                    WithDrawMoney(myAccount);
                    break;

                case "3":
                    CheckBalance(myAccount);
                    break;

                case "4":
                    ChangePIN(myAccount);
                    break;

                case "5":
                    writeMenu = false;
                    Console.WriteLine("Thank you for banking with us today");
                    break;

                default:
                    Console.WriteLine("Invalid choice");
                    break;
                }
            }

            Console.WriteLine(myAccount.ToString());
        }
示例#5
0
        static void Main(string[] args)
        {
            var account = new BankAccount();

            account.ID      = 1;
            account.Balance = 15;
            account.Deposit(5);
            account.Withdraw(15);

            Console.WriteLine(account.ToString());

            var person = new Person();

            person.Name = "Ivan";
            person.Age  = 10;
            person.accounts.Add(account);

            Console.WriteLine(person.GetBalance());
        }
示例#6
0
        public static void Main()
        {
            List <BankAccount> accounts = new List <BankAccount>();

            while (true)
            {
                string[] command = Console.ReadLine().Split();

                if (command[0] == "Create")
                {
                    int id = int.Parse(command[1]);

                    if (!accounts.Any(x => x.Id == id))
                    {
                        accounts.Add(new BankAccount(id));
                    }
                    else
                    {
                        Console.WriteLine("Account already exists");
                    }
                }
                else if (command[0] == "Deposit")
                {
                    int     id     = int.Parse(command[1]);
                    decimal amount = decimal.Parse(command[2]);

                    BankAccount requested = accounts.FirstOrDefault(x => x.Id == id);

                    if (requested == null)
                    {
                        Console.WriteLine("Account does not exist");
                    }
                    else
                    {
                        requested.Deposit(amount);
                    }
                }
                else if (command[0] == "Withdraw")
                {
                    int     id     = int.Parse(command[1]);
                    decimal amount = decimal.Parse(command[2]);

                    BankAccount requested = accounts.FirstOrDefault(x => x.Id == id);

                    if (requested == null)
                    {
                        Console.WriteLine("Account does not exist");
                    }
                    else if (amount > requested.Balance)
                    {
                        Console.WriteLine("Insufficient balance");
                    }
                    else
                    {
                        requested.Withdraw(amount);
                    }
                }
                else if (command[0] == "Print")
                {
                    int id = int.Parse(command[1]);

                    BankAccount requested = accounts.FirstOrDefault(x => x.Id == id);

                    if (requested == null)
                    {
                        Console.WriteLine("Account does not exist");
                    }
                    else
                    {
                        Console.WriteLine(requested.ToString());
                    }
                }
                else if (command[0] == "End")
                {
                    return;
                }
            }
        }