Esempio n. 1
0
        static void Main(string[] args)
        {
            Bank   bank = new Bank();
            Person p1   = new Person("  Espen  ", "99396513"); //handles whitespace
            Person p2   = new Person("Karianne", "99887766");
            Money  m1   = new Money("nok", 1000);              //handles small letters in currency
            Money  m2   = new Money("NOK  ", 9999);            //handles whitespace in currency
            Money  m3   = new Money("NOK", 1001);

            Account a1 = bank.CreateAccount(p1, m1);
            Account a2 = bank.CreateAccount(p2, m1);
            Account a3 = bank.CreateAccount(p1, m2);

            Console.WriteLine("Number of tests: 8\n");

            if (a1.GetPerson().Equals(p1) && a2.GetPerson().Equals(p2) && a3.GetPerson().Equals(p1))
            {
                Console.WriteLine("Test 1 ok");
            }

            Account[] espensAccounts = bank.GetAccountsForCustomer(p1);
            if (espensAccounts.Length == 2 && espensAccounts[0].GetAccountName() == "espen1" && espensAccounts[1].GetAccountName() == "espen2")
            {
                Console.WriteLine("Test 2 ok");
            }

            Person ingen = new Person("ingen", "66995588");

            Account[] ingenAccounts = bank.GetAccountsForCustomer(ingen);
            if (ingenAccounts.Length == 0)
            {
                Console.WriteLine("Test 3 ok");
            }

            bool withdraw1 = bank.Withdraw("espen1", m1); //withdraw less money than in account, allowed
            bool withdraw2 = bank.Withdraw("espen1", m2); // try withdraw more money than in account, not allowed
            bool deposit1  = bank.Deposit("espen1", m2);  //positive amount, allowed

            espensAccounts = bank.GetAccountsForCustomer(p1);

            if (deposit1 && withdraw1 && !withdraw2 && espensAccounts[0].GetNOK() == 9999)
            {
                Console.WriteLine("Test 4 ok");
            }

            // manipulating the accounts here does not change the actual accounts in the bank
            espensAccounts[0].Deposit(new Money("NOK", 1000000));
            Account[] espensAccounts2 = bank.GetAccountsForCustomer(p1);
            if (espensAccounts[0].GetNOK() == 1009999 && espensAccounts2[0].GetNOK() == 9999)
            {
                Console.WriteLine("Test 5 ok");
            }

            bank.Transfer("karianne1", "espen1", m2);
            espensAccounts = bank.GetAccountsForCustomer(p1);
            Account[] kariannesAccounts = bank.GetAccountsForCustomer(p2);

            if (kariannesAccounts.Length == 1 && kariannesAccounts[0].GetNOK() == 10999 && espensAccounts[0].GetNOK() == 0)
            {
                Console.WriteLine("Test 6 ok");
            }

            // Test that transfer is not compleded if the from account has insufficient funds
            bool bool1 = bank.Transfer("karianne1", "espen1", m2);

            espensAccounts    = bank.GetAccountsForCustomer(p1);
            kariannesAccounts = bank.GetAccountsForCustomer(p2);
            if (!bool1 && kariannesAccounts[0].GetNOK() == 10999 && espensAccounts[0].GetNOK() == 0)
            {
                Console.WriteLine("Test 7 ok");
            }

            Money usd = new Money("usd", 100);

            if (usd.getNOK() == 855)
            {
                Console.WriteLine("Test 8 ok");
            }

            Console.WriteLine("\nWrite bank to console\n");
            Console.WriteLine(bank.ToString());
            Console.ReadKey();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            string operation = "";

            do
            {
                Console.Write("HELLO, What Would You Like To Do Today: \n" +
                              "\n1. Register to be a new customer of the bank and open a new account - SELECT 1\n" +
                              "2. Make a Withdrawal - SELECT 2\n" +
                              "3. Make a Deposit - SELECT 3\n" +
                              "4. Print your customer and account/s details - SELECT 4\n" +
                              "5. Create a new account (for registered customers)- SELECT 5\n" +
                              "6. FOR EMPLOYEES ONLY: Print All Customers and their accounts Details - PRESS 6\n" +
                              "YOUR ANSWER:  ");

                string choice     = Console.ReadLine();
                string idNumber   = " ";
                string accountNum = " ";
                string amount     = " ";

                switch (choice)
                {
                case "1":
                {
                    Console.Write("Please Enter Your ID number (9 Digits): ");
                    idNumber = Console.ReadLine();
                    Bank.AddNewCustomer(idNumber);
                    break;
                }

                case "2":
                {
                    Console.Write("Please enter your ID Number: ");
                    idNumber = Console.ReadLine();
                    Console.Write("Please enter your Account Number: ");
                    accountNum = Console.ReadLine();
                    Console.Write("Please enter the Amount you would like to withdraw: ");
                    amount = (Console.ReadLine());
                    Bank.Withdraw(accountNum, idNumber, amount);
                    break;
                }

                case "3":
                {
                    Console.Write("Please enter your ID Number: ");
                    idNumber = Console.ReadLine();
                    Console.Write("Please enter your Account Number: ");
                    accountNum = Console.ReadLine();
                    Console.Write("Please enter the Amount you would like to deposit: ");
                    amount = (Console.ReadLine());
                    Bank.Deposit(accountNum, idNumber, amount);
                    break;
                }

                case "4":
                {
                    Console.Write("Please enter your ID Number: ");
                    idNumber = Console.ReadLine();
                    Console.Write("Please enter your Account Number: ");
                    accountNum = Console.ReadLine();
                    Console.WriteLine();
                    CustomerDetails.PrintDetails(idNumber, accountNum);
                    break;
                }

                case "5":
                {
                    Console.Write("Please enter your ID Number: ");
                    idNumber = Console.ReadLine();
                    Bank.CreateNewAccount(idNumber);
                    break;
                }

                case "6":
                {
                    Console.Write("Enter your Password: "******"OPERATION INVALID. Please select a valid operation from the main menu.");
                    break;
                }

                Console.WriteLine();
                Console.Write("If You want to do another operation press ENTER: ");
                operation = Console.ReadLine();
                Console.Clear();
            } while (String.IsNullOrWhiteSpace(operation));

            Console.WriteLine("Bye Bye, Thank you for using our Bank Application!");
        }