static void Main(string[] args) { string userOption; CheckingAccount check = new CheckingAccount(); SavingsAccount save = new SavingsAccount(); ReserveAccount reserve = new ReserveAccount(); MainMenu: Console.WriteLine("Please select a number from the list below and press enter."); List <string> clientOptions = new List <string>(); //Main Menu of options clientOptions.Add("1. View Client Information"); clientOptions.Add("2. View Account Information"); clientOptions.Add("3. Make a Deposit"); clientOptions.Add("4. Make a Withdrawal"); clientOptions.Add("5. Exit"); foreach (string option in clientOptions) { Console.WriteLine(option); } userOption = Console.ReadLine(); if (userOption == "1") { //display client information StreamReader reader = new StreamReader("ClientInfo.txt"); using (reader) { int lineNumber = 1; string line = reader.ReadLine(); while (line != null) { lineNumber++; Console.WriteLine(line); line = reader.ReadLine(); } } Console.WriteLine(); } else if (userOption == "2") //User account info { AccountBalanceMenu: Console.WriteLine("View which account balance: \n1. Checking \n2. Savings \n3. Reserve"); string accountInfoInput = Console.ReadLine(); if (accountInfoInput == "1") { check.AccountBalance(); //shows balance } else if (accountInfoInput == "2") { save.AccountBalance(); //shows balance } else if (accountInfoInput == "3") { reserve.AccountBalance(); //shows balance } else { Console.WriteLine("That is not a valid selection. Please try again."); goto AccountBalanceMenu; } } else if (userOption == "3") //Make a deposit { // AccountSelection: Console.WriteLine("Into which account: \n1. Checking \n2. Savings \n3. Reserve"); string userAccountInput = Console.ReadLine(); if (userAccountInput == "1") //Deposit -> Checking { CheckingDepositInput: Console.WriteLine("How much would you like to deposit? Do not enter a dollar sign."); try { check.CheckingDeposit = decimal.Parse(Console.ReadLine()); check.Deposit(); //shows deposit amount and new balance and writes to text file } catch (FormatException e) { Console.WriteLine("You have entered non-numeric characters. Please try again."); goto CheckingDepositInput; } } if (userAccountInput == "2") // Deposit -> Savings { SavingsDepositInput: Console.WriteLine("How much would you like to deposit? Do not enter a dollar sign."); try { save.SavingsDeposit = decimal.Parse(Console.ReadLine()); save.Deposit(); //shows deposit amount and new balance and writes to text file } catch (FormatException e) { Console.WriteLine("You entered non-numeric characters. Please try again."); goto SavingsDepositInput; } } if (userAccountInput == "3") //Deposit -> Reserve { ReserveDepositInput: Console.WriteLine("How much would you like to deposit? Do not enter a dollar sign."); try { reserve.ReserveDeposit = decimal.Parse(Console.ReadLine()); reserve.Deposit(); //shows deposit amount and new balance and writes to text file } catch (FormatException e) { Console.WriteLine("You have entered non-numeric characters. Please try again."); goto ReserveDepositInput; } } } // End of 3 .Make a deposit else if (userOption == "4") // Withdraw funds { // AccountSelection: Console.WriteLine("Into which account: \n1. Checking \n2. Savings \n3. Reserve"); string userAccountInputW = Console.ReadLine(); if (userAccountInputW == "1") //Withdraw -> Checking { CheckingWithdrawalInput: Console.WriteLine("How much would you like to withdraw? Do not enter a dollar sign."); try { check.CheckingWithdrawal = decimal.Parse(Console.ReadLine()); check.Withdrawal(); //show withdrawal amount and new balance and writes to text file } catch (FormatException e) { Console.WriteLine("You have entered non-numeric characters. Please try again."); goto CheckingWithdrawalInput; } } if (userAccountInputW == "2") // Withdraw -> Savings { SavingsWithdrawalInput: Console.WriteLine("How much would you like to withdraw? Do not enter a dollar sign."); try { save.SavingsWithdrawal = decimal.Parse(Console.ReadLine()); save.Withdrawal(); //shows withdrawal amount and new savings and writes to text file } catch (FormatException e) { Console.WriteLine("You have entered non-numeric characters. Please try again."); goto SavingsWithdrawalInput; } } if (userAccountInputW == "3") // Withdraw -> Reserve { ReserveWithdrawalInput: Console.WriteLine("How much would you like to withdraw? Do not enter a dollar sign."); try { reserve.ReserveWithdrawal = decimal.Parse(Console.ReadLine()); reserve.Withdrawal(); //show withdrawal amount and new balance and writes to text file } catch (FormatException e) { Console.WriteLine("You have entered non-numeric characters. Please try again."); goto ReserveWithdrawalInput; } } } else if (userOption == "5") // Exit { Environment.Exit(0); } else { Console.WriteLine("That is not a valid option. Please start over."); goto MainMenu; } goto MainMenu; } //static void main
static void Main(string[] args) { start: //redirect from password being incorrect Accounts account1 = new Accounts(); //instantiated each child-class CheckingAccount check1 = new CheckingAccount(); ReserveAccount reserve1 = new ReserveAccount(); SavingsAccount savings1 = new SavingsAccount(); Console.WriteLine("Thank you for visiting The First National Bank of Andy! \nDo you have an account with us?"); string existingCustomer = Console.ReadLine(); //I have a save option to bring back previous account info if (existingCustomer.ToUpper() == "Y" || existingCustomer.ToUpper() == "YES") { Console.Clear(); StreamReader retrieveSave = new StreamReader("..\\..\\BankLogin.txt"); //another input of "enter" to continue. int numberOfLines = 12; string[] lineArray = new string[numberOfLines]; //taking BankLogin.txt and turning lines into an array to read them for (int i = 1; i < numberOfLines; i++) { lineArray[i] = retrieveSave.ReadLine(); } account1.FirstName = (lineArray[1]); //these are using the properties to change the variable amounts and string name account1.LastName = (lineArray[2]); account1.UserName = (lineArray[3]); account1.PassWord = (lineArray[4]); account1.ClientNumber = int.Parse(lineArray[5]); //all lines read as a string, so Parse will get them into an int or double check1.CheckBalance = double.Parse(lineArray[6]); check1.CheckingAccountNumber = int.Parse(lineArray[7]); reserve1.ReserveBalance = double.Parse(lineArray[8]); reserve1.ReserveAccountNumber = int.Parse(lineArray[9]); savings1.SavingsBalance = double.Parse(lineArray[10]); savings1.SavingsAccountNumber = int.Parse(lineArray[11]); retrieveSave.Close(); check1.FirstName = account1.FirstName; //this is getting all the info from the base class accounts reserve1.FirstName = account1.FirstName; //into the sub-class accounts savings1.FirstName = account1.FirstName; check1.LastName = account1.LastName; reserve1.LastName = account1.LastName; savings1.LastName = account1.LastName; check1.ClientNumber = account1.ClientNumber; reserve1.ClientNumber = account1.ClientNumber; savings1.ClientNumber = account1.ClientNumber; Console.WriteLine(account1.UserName + " please enter your password."); //password was set with streamwriter previously string loginAttempt = Console.ReadLine(); if (loginAttempt.ToUpper() == account1.PassWord.ToUpper()) //uppercase or lowercase won't matter in password { Console.WriteLine("Welcome back " + account1.FirstName + "!"); goto mainmenu; //this sends it to the main menu } else { Console.WriteLine("Your password attempt is incorrect. You will be redirected to the start."); goto start; } } else //this else is for those who don't have a login and password { //creating a new profile Console.Clear(); Console.WriteLine("Let\'s set you up a new account!\nWhat is your first name?"); account1.FirstName = Console.ReadLine(); check1.FirstName = account1.FirstName; reserve1.FirstName = account1.FirstName; savings1.FirstName = account1.FirstName; Console.WriteLine("Thank you, " + account1.FirstName + ". What is your last name?"); account1.LastName = Console.ReadLine(); check1.LastName = account1.LastName; reserve1.LastName = account1.LastName; savings1.LastName = account1.LastName; Console.WriteLine("Please enter a username you would like to use."); account1.UserName = Console.ReadLine(); Console.WriteLine("Please enter a password. Please remember this password to login in the future."); account1.PassWord = Console.ReadLine(); account1.GenerateClientNumber(); check1.ClientNumber = account1.ClientNumber; reserve1.ClientNumber = account1.ClientNumber; savings1.ClientNumber = account1.ClientNumber; Console.WriteLine(account1.FirstName + ", your client ID number is " + account1.ClientNumber); Console.WriteLine("Here at FNB of Andy, we require all customers to open 3 accounts\nA Checking Account, a Reserve Account, and a Savings Account."); System.Threading.Thread.Sleep(5500); //this gives some time for the above lines to be read. Next method to be called clears all lines check1.GenerateCheckingAccount(); //these next 6 lines call to the inherited methods for initial deposits and account numbers check1.Deposit(); reserve1.GenerateReserveAccount(); reserve1.Deposit(); savings1.GenerateSavingsAccount(); savings1.Deposit(); } //main menu mainmenu: Console.WriteLine("\n" + account1.FirstName + ", please select the account you wish to view or exit."); Console.WriteLine("You may make a deposit, withdrawal, or view account balance in\nthe account you select."); Console.WriteLine("Select 1 to view Checking Account."); Console.WriteLine("Select 2 to view Reserve Account."); Console.WriteLine("Select 3 to view Savings Account."); Console.WriteLine("Select 4 to Exit and receive your receipt."); int selection = int.Parse(Console.ReadLine()); if (selection == 1) //if/else if for the 4 options. Selection 1 brings us to checking options { Console.Clear(); //console.clear is used to make console more readable Console.WriteLine("Checking Account Options:"); Console.WriteLine("Select 1 to make a deposit."); Console.WriteLine("Select 2 to make a withdrawal."); Console.WriteLine("Select 3 to check balance."); Console.WriteLine("Select 4 to return to the main menu."); int checkMenu = int.Parse(Console.ReadLine()); if (checkMenu == 1) { check1.Deposit(); } else if (checkMenu == 2) { check1.Withdraw(); } else if (checkMenu == 3) { Console.Clear(); Console.WriteLine(check1.FirstName + ", your current checking balance is $" + check1.CheckBalance + "."); } else { Console.Clear(); goto mainmenu; //takes us back to the main menu } } else if (selection == 2) //selection 2 brings us to reserve account options { Console.Clear(); Console.WriteLine("Reserve Account Options:"); Console.WriteLine("Select 1 to make a deposit."); Console.WriteLine("Select 2 to make a withdrawal."); Console.WriteLine("Select 3 to check balance."); Console.WriteLine("Select 4 to return to the main menu."); int resMenu = int.Parse(Console.ReadLine()); if (resMenu == 1) //nested if/else if to call upon particular inherited method { reserve1.Deposit(); } else if (resMenu == 2) { reserve1.Withdraw(); } else if (resMenu == 3) { Console.Clear(); Console.WriteLine(check1.FirstName + ", your current reserve balance is $" + reserve1.ReserveBalance + "."); } else { Console.Clear(); goto mainmenu; } } else if (selection == 3) //selection 3 brings us to savings account options { Console.Clear(); Console.WriteLine("Savings Account Options:"); Console.WriteLine("Select 1 to make a deposit."); Console.WriteLine("Select 2 to make a withdrawal."); Console.WriteLine("Select 3 to check balance."); Console.WriteLine("Select 4 to return to the main menu."); int savMenu = int.Parse(Console.ReadLine()); if (savMenu == 1) { savings1.Deposit(); } else if (savMenu == 2) { savings1.Withdraw(); } else if (savMenu == 3) { Console.Clear(); Console.WriteLine(check1.FirstName + ", your current savings balance is $" + savings1.SavingsBalance + "."); } else { Console.Clear(); goto mainmenu; } } else { Console.Clear(); Console.WriteLine("Thank you for banking with FNB of Andy. Have a great day!"); StreamWriter bankLogin = new StreamWriter("..\\..\\BankLogin.txt"); //this will write or overwrite the txt using (bankLogin) //that will be used to read when console is { //reopened and saved bank info is selected. bankLogin.WriteLine(account1.FirstName); bankLogin.WriteLine(account1.LastName); bankLogin.WriteLine(account1.UserName); bankLogin.WriteLine(account1.PassWord); bankLogin.WriteLine(account1.ClientNumber); bankLogin.WriteLine(check1.CheckBalance); bankLogin.WriteLine(check1.CheckingAccountNumber); bankLogin.WriteLine(reserve1.ReserveBalance); bankLogin.WriteLine(reserve1.ReserveAccountNumber); bankLogin.WriteLine(savings1.SavingsBalance); bankLogin.WriteLine(savings1.SavingsAccountNumber); } Environment.Exit(0); } goto mainmenu; //if user did not exit, this will send back to main menu }
static void Main(string[] args) { //open streamwriter to create text file StreamWriter accountReserve = new StreamWriter("ReserveAccount.txt"); StreamWriter accountSavings = new StreamWriter("SavingsAccount.txt"); StreamWriter accountChecking = new StreamWriter("CheckingAccount.txt"); //get member name Console.WriteLine("Please enter your name."); string memberName = Console.ReadLine(); Console.Clear(); //create objects to use classes SavingsAccount savings = new SavingsAccount(memberName); CheckingAccount checking = new CheckingAccount(memberName); ReserveAccount reserve = new ReserveAccount(memberName); //streamwriter .txt files accountChecking.WriteLine("Gringott's Member " + memberName); accountChecking.WriteLine("Account Number: " + checking.AccountNumber); accountChecking.WriteLine("Account Type: Checking Account"); accountChecking.WriteLine("Account Balance: " + checking.AccountBalance); accountSavings.WriteLine("Gringott's Member " + memberName); accountSavings.WriteLine("Account Number: " + savings.AccountNumber); accountSavings.WriteLine("Account Type: Savings Account"); accountSavings.WriteLine("Account Balance: " + savings.AccountBalance); accountReserve.WriteLine("Gringott's Member " + memberName); accountReserve.WriteLine("Account Number: " + reserve.AccountNumber); accountReserve.WriteLine("Account Type: Reserve Account"); accountReserve.WriteLine("Account Balance: " + reserve.AccountBalance); //loop for menu while (true) { //menu Console.WriteLine("Welcome to Gringott's Bank for Wizards and Witches. Please make a selection."); Console.WriteLine("1: View Member Info"); Console.WriteLine("View Account Balance of:" + memberName); Console.WriteLine("\t2: Checking Account"); Console.WriteLine("\t3: Savings Account"); Console.WriteLine("\t4: Reserve Account"); Console.WriteLine("5: Deposit Funds"); Console.WriteLine("6: Withdrawal Funds"); //member choice for which action on menu int action = int.Parse(Console.ReadLine()); Console.Clear(); //switch/case actions switch (action) { case 1: savings.ClientInfo(); break; case 2: checking.ViewAccountBalance(); break; case 3: savings.ViewAccountBalance(); break; case 4: reserve.ViewAccountBalance(); break; case 5: Console.WriteLine("Please make a selection."); Console.WriteLine("1: Checking Account"); Console.WriteLine("2: Savings Account"); Console.WriteLine("3: Reserve Account"); int choice = int.Parse(Console.ReadLine()); Console.WriteLine("Enter deposit amount."); int deposit = int.Parse(Console.ReadLine()); // switch/case for deposit selection switch (choice) { case 1: checking.Deposit(deposit); Console.WriteLine("Your account balance is " + checking.AccountBalance); accountChecking.WriteLine("+ " + deposit + " " + DateTime.Now); accountChecking.WriteLine("Account Balance: " + checking.AccountBalance); break; case 2: savings.Deposit(deposit); Console.WriteLine("Your account balance is " + savings.AccountBalance); accountSavings.WriteLine("+ " + deposit + " " + DateTime.Now); accountSavings.WriteLine("Account Balance: " + savings.AccountBalance); break; case 3: reserve.Deposit(deposit); Console.WriteLine("Your account balance is " + reserve.AccountBalance); accountReserve.WriteLine("+ " + deposit + " " + DateTime.Now); accountReserve.WriteLine("Account Balance: " + reserve.AccountBalance); break; default: break; } break; case 6: Console.WriteLine("Please make a selection."); Console.WriteLine("1: Checking Account"); Console.WriteLine("2: Savings Account"); Console.WriteLine("3: Reserve Account"); int pick = int.Parse(Console.ReadLine()); Console.WriteLine("Enter withdrawal amount."); int withdrawal = int.Parse(Console.ReadLine()); //switch/case for withdrawing switch (pick) { case 1: checking.Withdrawal(withdrawal); Console.WriteLine("The new balance is " + checking.AccountBalance); accountChecking.WriteLine("- " + withdrawal + " " + DateTime.Now); accountChecking.WriteLine("Account Balance: " + checking.AccountBalance); break; case 2: savings.Withdrawal(withdrawal); Console.WriteLine("The new balance is " + savings.AccountBalance); accountSavings.WriteLine("- " + withdrawal + " " + DateTime.Now); accountSavings.WriteLine("Account Balance: " + savings.AccountBalance); break; case 3: reserve.Withdrawal(withdrawal); Console.WriteLine("The new balance is " + reserve.AccountBalance); accountReserve.WriteLine("- " + withdrawal + " " + DateTime.Now); accountReserve.WriteLine("Account Balance: " + reserve.AccountBalance); break; } break; default: //quits break; } Console.WriteLine("Do you need more time?"); string yesOrNo = Console.ReadLine(); if (yesOrNo.ToLower() == "y") { Console.Clear(); } else { //quits the program if "no" Console.Clear(); break; } } //closes the streamwriters accountReserve.Close(); accountSavings.Close(); accountChecking.Close(); Quit(); }