Exemple #1
0
        /// <summary>
        /// Reads the bank from a text file
        /// </summary>
        /// <param name="filepath">The file path to read from</param>
        /// <returns>The bank</returns>
        static Bank GetBankFromFile(string filePath)
        {
            Bank bank = new Bank();

            try
            {
                using (StreamReader sr = new StreamReader(filePath))
                {
                    int numberOfCustomers = int.Parse(sr.ReadLine().Split('|')[1]);

                    for (int i = 0; i < numberOfCustomers; i++)
                    {
                        string[]     line         = sr.ReadLine().Split('|');
                        BankCustomer bankCustomer = new BankCustomer();
                        bankCustomer.Name        = line[1];
                        bankCustomer.Address     = line[2];
                        bankCustomer.PhoneNumber = line[3];
                        int numberOfAccounts = int.Parse(line[4]);
                        for (int j = 0; j < numberOfAccounts; j++)
                        {
                            line = sr.ReadLine().Split('|');
                            if (line[0][0] == 'C')
                            {
                                CheckingAccount checkingAccount = new CheckingAccount();
                                checkingAccount.AccountNumber = line[0];
                                checkingAccount.Deposit(decimal.Parse(line[1]));
                                bankCustomer.AddAccount(checkingAccount);
                            }
                            else
                            {
                                SavingsAccount savingsAccount = new SavingsAccount();
                                savingsAccount.AccountNumber = line[0];
                                savingsAccount.Deposit(decimal.Parse(line[1]));
                                bankCustomer.AddAccount(savingsAccount);
                            }
                        }
                        bank.AddCustomer(bankCustomer);
                    }
                }
            }
            catch (IOException ex)
            {
                Console.WriteLine(ex.Message);
            }

            return(bank);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            BankAccount checkingAccount   = new CheckingAccount();
            BankAccount savingsAccount    = new SavingsAccount();
            BankAccount secondSavingsAcct = new SavingsAccount();

            BankCustomer jayGatsby = new BankCustomer();

            jayGatsby.AddAccount(checkingAccount);
            jayGatsby.AddAccount(savingsAccount);
            jayGatsby.AddAccount(secondSavingsAcct);

            Console.WriteLine($"Jay Gatsby has {jayGatsby.Accounts.Length} accounts.");

            checkingAccount.AccountNumber   = "Checking";
            savingsAccount.AccountNumber    = "Savings";
            secondSavingsAcct.AccountNumber = "Second Savings";

            foreach (var item in jayGatsby.Accounts)
            {
                Console.WriteLine($"Account Number: {item.AccountNumber}");
            }

            checkingAccount.Deposit(2000M);
            savingsAccount.Deposit(2000M);
            secondSavingsAcct.Deposit(1500M);

            foreach (var item in jayGatsby.Accounts)
            {
                Console.WriteLine($"Account Name: {item.AccountNumber} - Account Balance: {item.Balance.ToString("C")}");
            }

            checkingAccount.Withdraw(500.00M);
            savingsAccount.Withdraw(1000M);

            foreach (var item in jayGatsby.Accounts)
            {
                Console.WriteLine($"Account Name: {item.AccountNumber} - Account Balance: {item.Balance.ToString("C")}");
            }
            Console.WriteLine("IsVIP: " + jayGatsby.IsVIP);


            savingsAccount.Transfer(checkingAccount, 40.00M);
            Console.WriteLine($"Checking: {checkingAccount.Balance}, Savings: {savingsAccount.Balance}");
            Console.ReadKey();
        }
Exemple #3
0
        static void Main(string[] args)
        {
            Console.WriteLine($"Welcome to the Bank Account Application");

            BankCustomer PopPop = new BankCustomer();

            ///instantiate newAccount1
            BankAccount donorAccount = new BankAccount();

            ///intantiate newAccount2
            BankAccount receiverAccount = new BankAccount();

            ///add money to both accounts using deposit method
            donorAccount.Deposit(100M);
            receiverAccount.Deposit(100M);

            CheckingAccount checkingAccount_GeorgeMichael = new CheckingAccount();

            ///write out amount $$$ in each
            Console.WriteLine($"Balance of donorAccount: ${donorAccount.Balance:C2} | Balance of Receiver Account: ${receiverAccount.Balance}");

            ///transfer $$$ from new Account 1 to new Account 2
            donorAccount.Transfer(receiverAccount, 50M);

            //////write out amount $$$ in each after transfer
            Console.WriteLine($"Balance of donorAccount: {donorAccount.Balance:C2} | ${receiverAccount.Balance}");

            // test out withdraw and overdraft scenarios
            decimal overDrawMoneyTest = checkingAccount_GeorgeMichael.Withdraw(90M);

            //get new balance and print out
            Console.WriteLine($"This the account balance: {checkingAccount_GeorgeMichael.Balance:C2}");

            //Create new savings account
            SavingsAccount brandNewSavingAccountForSomeone = new SavingsAccount();

            //Add $149 to the savings account
            brandNewSavingAccountForSomeone.Deposit(-190);

            //Print new balance
            Console.WriteLine($"Balance for savings account: {brandNewSavingAccountForSomeone.Balance:C2}");

            //Test withdraw for savings account
            brandNewSavingAccountForSomeone.Withdraw(90);
            Console.WriteLine($"Balance for savings account after withdrawing $490: {brandNewSavingAccountForSomeone.Balance:C2}");
        }
        static void Main(string[] args)
        {
            BankCustomer    testCust  = new BankCustomer();
            BankAccount     test      = new BankAccount();
            CheckingAccount testCheck = new CheckingAccount();
            SavingsAccount  testSave  = new SavingsAccount();

            testCust.AddAccount(test);
            testCust.AddAccount(testCheck);
            testCust.AddAccount(testSave);

            testCheck.Deposit(24000);
            testSave.Deposit(1000);

            Console.WriteLine(testCust.Name + "VIP Status: " + testCust.IsVIP);

            Console.WriteLine("Total Account Balance: " + testCust.sum.ToString("c"));

            Console.ReadKey();
        }
Exemple #5
0
        static void Main(string[] args)
        {
            BankAccount checkingAccount = new CheckingAccount();

            checkingAccount.Deposit(1000M);
            BankAccount savingsAccount = new SavingsAccount();

            savingsAccount.Deposit(500M);

            Console.WriteLine(checkingAccount.AccountNumber);
            Console.WriteLine(savingsAccount.AccountNumber);

            BankCustomer jayGatsby = new BankCustomer();

            jayGatsby.AddAccount(checkingAccount);
            jayGatsby.AddAccount(savingsAccount);

            bool customerBanking = true;

            while (customerBanking)
            {
                string action = BankAccount.ATM();

                if (action.Equals("b"))
                {
                    BankAccount.OutputBalances(jayGatsby.ListOfAccounts);
                    continue;
                }

                string  accountInput = BankAccount.ChooseAccount(jayGatsby.ListOfAccounts);
                decimal money        = BankAccount.AmountOfMoney();

                if (action.Equals("d"))
                {
                    foreach (BankAccount account in jayGatsby.ListOfAccounts)
                    {
                        if (account.AccountNumber == accountInput)
                        {
                            account.Deposit(money);
                        }
                    }
                }
                else if (action.Equals("w"))
                {
                    foreach (BankAccount account in jayGatsby.ListOfAccounts)
                    {
                        if (account.AccountNumber == accountInput)
                        {
                            account.Withdraw(money);
                        }
                    }
                }
                else if (action.Equals("t"))
                {
                    string accountTransfer = BankAccount.ChooseAccount(jayGatsby.ListOfAccounts);

                    foreach (BankAccount account in jayGatsby.ListOfAccounts)
                    {
                        if (account.AccountNumber == accountInput)
                        {
                            account.Withdraw(money);
                        }

                        if (account.AccountNumber == accountTransfer)
                        {
                            account.Deposit(money);
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Exiting . . . ");
                    customerBanking = false;
                }
            }



            Console.ReadKey();
        }
Exemple #6
0
        static void Main(string[] args)
        {
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("     $$$$$$$      $$$$$$$$$$$        $$$$$$$$$    $$$      $$$   $$$$$$$$$$$   $$$$$$$$$      ");
            Console.WriteLine("     $$$  $$$         $$$         $$$$$$$$$$$     $$$      $$$       $$$       $$$$$$$$     ");
            Console.WriteLine("     $$$  $$$         $$$       $$$$              $$$      $$$       $$$       $$$ ");
            Console.WriteLine("     $$$  $$          $$$       $$$$              $$$$$$$$$$$$       $$$       $$$$$$     ");
            Console.WriteLine("     $$$$$$           $$$       $$$$              $$$$$$$$$$$$       $$$       $$$$$$    ");
            Console.WriteLine("     $$$ $$$          $$$       $$$$              $$$      $$$       $$$       $$$       ");
            Console.WriteLine("     $$$  $$$         $$$       $$$$              $$$      $$$       $$$       $$$       ");
            Console.WriteLine("     $$$   $$$        $$$         $$$$$$$$$$$     $$$      $$$       $$$       $$$$$$$$   ");
            Console.WriteLine("     $$$    $$$   $$$$$$$$$$$       $$$$$$$$$$$   $$$      $$$   $$$$$$$$$$$   $$$$$$$$$        ");
            Console.WriteLine();
            Console.WriteLine("     $$$$$$$      $$$$$$$$$$$        $$$$$$$$$    $$$      $$$                 $$$$$$$$$$$   $$$$        $$$        $$$$$$$$$$     ");
            Console.WriteLine("     $$$  $$$         $$$         $$$$$$$$$$$     $$$      $$$                     $$$       $$$$$$      $$$      $$$$$$$$$$$      ");
            Console.WriteLine("     $$$  $$$         $$$       $$$$              $$$      $$$                     $$$       $$$ $$$     $$$    $$$$            ");
            Console.WriteLine("     $$$  $$          $$$       $$$$              $$$$$$$$$$$$                     $$$       $$$  $$$    $$$    $$$$            ");
            Console.WriteLine("     $$$$$$           $$$       $$$$              $$$$$$$$$$$$                     $$$       $$$   $$$   $$$    $$$$           ");
            Console.WriteLine("     $$$ $$$          $$$       $$$$              $$$      $$$                     $$$       $$$    $$$  $$$    $$$$              ");
            Console.WriteLine("     $$$  $$$         $$$       $$$$              $$$      $$$                     $$$       $$$     $$$ $$$    $$$$              ");
            Console.WriteLine("     $$$   $$$        $$$         $$$$$$$$$$$     $$$      $$$                     $$$       $$$      $$$$$$      $$$$$$$$$$$    $$   ");
            Console.WriteLine("     $$$    $$$   $$$$$$$$$$$       $$$$$$$$$$$   $$$      $$$                 $$$$$$$$$$$   $$$       $$$$$        $$$$$$$$$$   $$  ");
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("     ==============================================================================================================================");


            Console.WriteLine();
            Console.WriteLine();
            Console.Write("Are you a current customer? (answer y or n) ");
            string currentCustomer = Console.ReadLine();

            currentCustomer = currentCustomer.ToLower();
            if (currentCustomer == "n" || currentCustomer == "no")
            {
                Console.Write("Would you like to be added as a new customer? (answer y or n) ");
                string addCustomer = Console.ReadLine();
                addCustomer = addCustomer.ToLower();
                if (addCustomer == "n" || addCustomer == "no")
                {
                    System.Environment.Exit(1);
                }

                Console.Clear();
                Console.Write("What is your full name: ");

                BankCustomer newCustomer = new BankCustomer();
                newCustomer.Name = Console.ReadLine();

                Console.Write("What is your full address: ");
                newCustomer.Address = Console.ReadLine();

                Console.Write("What is your phone number: ");
                newCustomer.PhoneNumber = Console.ReadLine();

                string addAccount = "";
                Console.WriteLine("Would you like to open a new account? (answer y or n)");
                addAccount = Console.ReadLine();
                addAccount = addAccount.ToLower();
                while (addAccount == "y" || addAccount == "yes")
                {
                    string accountType = "";

                    Console.Write("Enter [1] for Checking Account or [2] for Savings Account: ");
                    accountType = Console.ReadLine();
                    if (accountType == "1")
                    {
                        CheckingAccount checkingAccount = new CheckingAccount();
                        Console.Write("How much money would you like to deposit? ");
                        string s = Console.ReadLine();
                        int    amountToDeposit = int.Parse(s);
                        amountToDeposit = amountToDeposit * 100;
                        DollarAmount x = new DollarAmount(amountToDeposit);
                        checkingAccount.Deposit(x);
                        newCustomer.AddAccount(checkingAccount);
                        Console.Write("Would you like to add another account? (answer y or n) ");
                        addAccount = Console.ReadLine();
                    }
                    else
                    {
                        SavingsAccount savingsAccount  = new SavingsAccount();
                        int            amountToDeposit = 0;
                        string         s = "";
                        Console.Write("How much money would you like to deposit? (Must be at least $150) ");
                        s = Console.ReadLine();
                        amountToDeposit = int.Parse(s);
                        amountToDeposit = amountToDeposit * 100;
                        if (amountToDeposit < 15000)
                        {
                            while (amountToDeposit < 15000)
                            {
                                Console.Write("You did not deposit enough! What is the amount you would like to deposit? ");
                                s = Console.ReadLine();
                                amountToDeposit = int.Parse(s);
                                amountToDeposit = amountToDeposit * 100;
                            }
                        }
                        DollarAmount x = new DollarAmount(amountToDeposit);
                        savingsAccount.Deposit(x);
                        newCustomer.AddAccount(savingsAccount);
                        Console.Write("Would you like to add another account? (answer y or n) ");
                        addAccount = Console.ReadLine();
                    }
                }
                Console.Clear();
                Console.WriteLine($"Name: {newCustomer.Name.PadLeft(15)}");
                Console.WriteLine($"Address: {newCustomer.Address.PadLeft(10)}");
                Console.WriteLine($"Phone Number: {newCustomer.PhoneNumber.PadLeft(5)}");
                int accountBalanceTotals = 0;
                for (int i = 0; i < newCustomer.Accounts.Length; i++)
                {
                    accountBalanceTotals += newCustomer.Accounts[i].Balance.Dollars;
                    Console.WriteLine($"Bank Account {i + 1}: {newCustomer.Accounts[i].Balance.ToString()}");
                }
                Console.WriteLine($"Total Balance: ${accountBalanceTotals}");

                Console.ReadLine();
            }
        }