/// <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); }
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(); }
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) { // Testing part one math in the various account rules. Result should be -60, 150. BankAccount checkingAccount = new CheckingAccount(); BankAccount savingsAccount = new SavingsAccount(); decimal amountToDeposit = 100.00M; decimal newBalance = checkingAccount.Deposit(amountToDeposit); decimal amountToTransfer = 50.00M; checkingAccount.Transfer(savingsAccount, amountToTransfer); amountToTransfer = 100.00M; checkingAccount.Transfer(savingsAccount, amountToTransfer); amountToTransfer = 100.00M; checkingAccount.Transfer(savingsAccount, amountToTransfer); //Testing part two results. Console.WriteLine(checkingAccount.Balance); Console.WriteLine(savingsAccount.Balance); checkingAccount = new CheckingAccount(); savingsAccount = new SavingsAccount(); BankCustomer jayGatsby = new BankCustomer(); jayGatsby.AddAccount(checkingAccount); jayGatsby.AddAccount(savingsAccount); amountToDeposit = 50000.00M; newBalance = checkingAccount.Deposit(amountToDeposit); Console.WriteLine(checkingAccount.Balance); Console.WriteLine($"Jay Gatsby has {jayGatsby.Accounts.Length} accounts."); Console.WriteLine(jayGatsby.IsVIP); }
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(); }
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(); }
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(); } }
static void Main(string[] args) { bool leave = false; Console.WriteLine("Welcome to the virtual bank!"); Console.WriteLine(); Console.Write("What is your name? "); string yourName = Console.ReadLine(); var you = new BankCustomer { Name = yourName }; Console.Write("Would you like a (C)hecking or a (S)avings account?: "); var choice = Console.ReadLine(); BankAccount yourAccount = new BankAccount(); choice = choice.ToUpper(); if (choice == "C") { Console.Write("What is the name of the checking account?: "); string name = Console.ReadLine().ToUpper(); var newCheck = new CheckingAccount(); you.AddAccount(newCheck, name); } else { Console.Write("What is the name of the savings account?: "); string name = Console.ReadLine().ToUpper(); var newSave = new SavingsAccount(); you.AddAccount(newSave, name); } Console.Clear(); while (!leave) { Console.WriteLine("Welcome to the bank " + yourName + "!"); Console.WriteLine("______________________________________"); Console.WriteLine(); Console.WriteLine("What would you like to do today?"); Console.WriteLine("1. Check your Balance"); //Check Balance Console.WriteLine("2. Withdraw money"); //Withdraw Console.WriteLine("3. Deposit money"); //Deposit Console.WriteLine("4. Transfer money to another account"); //Transfer Console.WriteLine("5. Open another account"); Console.WriteLine("6. See a list of your accounts"); //List all of your accounts opened Console.WriteLine("7. Check VIP status"); Console.WriteLine("8. Quit"); //Quit var menuChoice = decimal.Parse(Console.ReadLine()); switch (menuChoice) { case 1: Console.Clear(); Console.Write("What is the name of the account would you like the balance of? "); Console.WriteLine(); string AChoice = Console.ReadLine(); foreach (var acct in you.Accounts) { if (acct.AccountNumber == AChoice.ToUpper()) { Console.WriteLine($"Your balance in Account : {acct.AccountNumber} is {acct.Balance.ToString("C2")}"); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.ReadLine(); Console.Clear(); break; } } break; case 2: Console.Clear(); Console.WriteLine("Which account would you like to withdaraw from (Name on Account) ? "); string wAcct = Console.ReadLine().ToUpper(); for (int i = 0; i < you.Accounts.Length; i++) { if (you.Accounts[i].AccountNumber == wAcct) { Console.Write("How Much? "); decimal withdraw = decimal.Parse(Console.ReadLine()); if (you.Accounts[i] is SavingsAccount) { if (withdraw > you.Accounts[i].Balance) { Console.Clear(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("No."); Console.WriteLine(); Console.WriteLine(); Console.ReadLine(); Console.Clear(); } } else if (you.Accounts[i] is CheckingAccount) { if (withdraw > you.Accounts[i].Balance) { Console.WriteLine("...If you insist..."); Console.WriteLine(); System.Threading.Thread.Sleep(2000); Console.WriteLine("You are now overdraft by $" + Math.Abs(you.Accounts[i].Balance - withdraw)); Console.ReadLine(); Console.Clear(); } } you.Accounts[i].Withdraw(withdraw); Console.Clear(); break; } if (i == you.Accounts.Length - 1) { Console.WriteLine("You do not have that account..."); } } break; case 3: Console.Clear(); Console.WriteLine("Which account would you like to deposit to (Name on Account) ? "); string dAcct = Console.ReadLine().ToUpper(); for (int i = 0; i < you.Accounts.Length; i++) { if (you.Accounts[i].AccountNumber == dAcct) { Console.Write("How Much? "); decimal deposit = decimal.Parse(Console.ReadLine()); you.Accounts[i].Deposit(deposit); Console.WriteLine($"{deposit.ToString("C2")} has been deposited to {you.Accounts[i].AccountNumber}."); Console.ReadLine(); Console.Clear(); break; } if (i == you.Accounts.Length - 1) { Console.WriteLine("You do not have that account..."); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); } } break; case 4: Console.Clear(); bool doesNotExist = true; while (doesNotExist) { Console.Write("Which account are you transferring from (Enter Name on account)? "); string tFrom = Console.ReadLine().ToUpper(); Console.Write("How Much? "); decimal transAmount = decimal.Parse(Console.ReadLine()); for (int i = 0; i < you.Accounts.Length; i++) { if (i == you.Accounts.Length - 1 && you.Accounts[i].AccountNumber != tFrom) { Console.WriteLine("That account doesnt't exist"); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); break; } else if (you.Accounts[i].AccountNumber == tFrom) { var transferFrom = you.Accounts[i]; while (doesNotExist) { Console.WriteLine(); Console.Write("Which of your accounts are you transferring to (Enter Name on account)? "); string tTo = Console.ReadLine().ToUpper(); for (int a = 0; a < you.Accounts.Length; a++) { if (a == you.Accounts.Length - 1 && you.Accounts[a].AccountNumber != tTo) { Console.WriteLine("That account doesnt't exist"); break; } else if (you.Accounts[a].AccountNumber == tTo) { var transferTo = you.Accounts[a]; transferFrom.Transfer(transferTo, transAmount); Console.WriteLine($"Account: {transferTo.AccountNumber} has been transferred {transAmount.ToString("C2")}"); Console.ReadLine(); doesNotExist = false; Console.Clear(); break; } } } break; } } } break; case 5: Console.Clear(); Console.WriteLine("What kind of account would you like to open? (C/S) "); string aChoice = Console.ReadLine().ToUpper(); if (aChoice == "C") { Console.Write("What is the name of the account? "); string aName = Console.ReadLine().ToUpper(); var newCheck = new CheckingAccount(); you.AddAccount(newCheck, aName); Console.WriteLine(); Console.WriteLine($"You have added account: {aName}."); Console.WriteLine(); Console.WriteLine(); Console.ReadLine(); Console.Clear(); } else { Console.Write("What is the name of the account? "); string aName = Console.ReadLine().ToUpper(); var newSave = new SavingsAccount(); you.AddAccount(newSave, aName); Console.WriteLine(); Console.WriteLine($"You have added account: {aName}."); Console.WriteLine(); Console.WriteLine(); Console.ReadLine(); Console.Clear(); } break; case 6: //loop through each account in accounts and print the account name, type, and balance Console.Clear(); Console.WriteLine("Generating List of Accounts"); Console.WriteLine("..."); Console.WriteLine("..."); Console.WriteLine("..."); System.Threading.Thread.Sleep(2000); Console.WriteLine("{0,10}{1,20}{2,18}", "Account Name", "Type of Account", "Balance"); foreach (var account in you.Accounts) { var type = ""; if (account is CheckingAccount) { type = "Checking"; } if (account is SavingsAccount) { type = "Savings"; } Console.WriteLine("{0,10}{1,20}{2,25}", account.AccountNumber, type, account.Balance.ToString("C2")); } Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.ReadLine(); Console.Clear(); break; case 7: if (you.IsVIP) { for (int i = 0; i < 1000; i++) { Console.WriteLine($"CONGRATULATIONS {you.Name}! YOU ARE A VIP!!"); } Console.Write(""); Console.ReadLine(); Console.Clear(); } else { Console.WriteLine("Sorry, you are not a VIP yet."); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.ReadLine(); Console.Clear(); } break; case 8: Console.Write("Are you sure you want to leave the bank? (Y/N)"); Console.WriteLine(); var quit = Console.ReadLine(); quit = quit.ToUpper(); if (quit == "Y") { Console.WriteLine("Leaving Bank ... "); System.Threading.Thread.Sleep(1500); Console.Beep(3007, 80); // Console.Beep(3007, 80); Console.Beep(2600, 100); Console.WriteLine("Bye-Bye!"); leave = true; break; } else { break; } } } }