static void Main(string[] args) { //Bank Account Project //Ryan Sizer //Week 3 - 04/17/2017 //Instantiate a new object of Client class Client client1 = new Client(); //Instantiate a new object of CheckingAccount class CheckingAccount checking1 = new CheckingAccount("12345", "Lord Tyrion's Checking Account", 25236755.23, 77000500.51); //Instantiate a new object of SavingsAccount class SavingsAccount savings1 = new SavingsAccount("12345", "Lord Tyrion's Savings Account", 25236755.23, 77000500.51); //client1.DisplayClientInfo(); //Greet the user Console.WriteLine("Hello, Mr. Lannister. Welcome to your Bank Account.\r\n"); //Use a do-while loop for the menu and to keep program running until user exits do { //Store menu options in a string string menu = ("BANK OF WESTEROS" + Environment.NewLine + "----------------------------------" + Environment.NewLine + "- [1] View Client Information" + Environment.NewLine + "- [2] View Account Balance" + Environment.NewLine + "- [3] Deposit Funds" + Environment.NewLine + "- [4] Withdraw Funds" + Environment.NewLine + "- [5] Exit Program" + Environment.NewLine); //Display menu options Console.WriteLine(menu); //Store user response in a string variable string menuChoice = Console.ReadLine(); //Validate if user input anything while (string.IsNullOrWhiteSpace(menuChoice)) { Console.Clear(); //Tell user what went wrong Console.WriteLine("Oops! You didn't select anything.\r\nPlease select a menu option between 1 and 5: "); Console.WriteLine(menu); menuChoice = Console.ReadLine(); } //Declare variable to hold the converted value of menu selection int menuInt; //Convert with TryParse int.TryParse(menuChoice, out menuInt); //Validate that user made a numerical choice between 1 and 5 while (menuInt < 1 || menuInt > 5) { Console.Clear(); //Tell user what went wrong Console.WriteLine("Oops! You selected something other than a number between 1 and 5.\r\nPlease try again and make a menu selection between 1 and 5."); Console.WriteLine(menu); //Re-capture user response menuChoice = Console.ReadLine(); //re-convert to an integer int.TryParse(menuChoice, out menuInt); } Console.Clear(); //Use switch case for user menu selections switch (menuInt) { //When user selects option one, client information is displayed case 1: client1.DisplayClientInfo(); break; //When user selects option two, display submenu so they can select checkings or savings case 2: //Store submenu in a string string balanceSubMenu = ("BANK OF WESTEROS" + Environment.NewLine + "----------------------------------" + Environment.NewLine + "- [1] View Checking Account Balance" + Environment.NewLine + "- [2] View Savings Account Balance" + Environment.NewLine); Console.WriteLine(balanceSubMenu); //Display submenu to console string balanceChoice = Console.ReadLine(); //Validate if user input anything while (string.IsNullOrWhiteSpace(balanceChoice)) { Console.Clear(); //Tell user what went wrong Console.WriteLine("Oops! You didn't select anything.\r\nPlease select a menu option of 1 or 2: "); Console.WriteLine(balanceSubMenu); balanceChoice = Console.ReadLine(); } //Declare variable to hold the converted value of menu selection int balanceChoiceInt; //Convert with TryParse int.TryParse(balanceChoice, out balanceChoiceInt); //Validate that user made a numerical choice between 1 and 5 while (balanceChoiceInt < 1 || balanceChoiceInt > 2) { Console.Clear(); //Tell user what went wrong Console.WriteLine("Oops! You selected something other than a number of 1 or 2.\r\nPlease try again and make a menu selection of 1 or 2.\r\n"); Console.WriteLine(balanceSubMenu); //Re-capture user response balanceChoice = Console.ReadLine(); //re-convert to an integer int.TryParse(balanceChoice, out balanceChoiceInt); } if (balanceChoiceInt == 1) { checking1.ViewBalance(); } if (balanceChoiceInt == 2) { //savings1.DefaultSavingsBal(); savings1.ViewBalance(); } break; //When user selects option three, display submenu so they can select checkings or savings case 3: //Store submenu in a string string depositSubMenu = ("BANK OF WESTEROS" + Environment.NewLine + "----------------------------------" + Environment.NewLine + "- [1] Deposit Funds into Checking Account" + Environment.NewLine + "- [2] Deposit Funds into Savings Account" + Environment.NewLine); Console.WriteLine(depositSubMenu); //Display submenu to console string depositChoice = Console.ReadLine(); //Validate if user input anything while (string.IsNullOrWhiteSpace(depositChoice)) { Console.Clear(); //Tell user what went wrong Console.WriteLine("Oops! You didn't select anything.\r\nPlease select a menu option of 1 or 2: "); Console.WriteLine(depositChoice); depositChoice = Console.ReadLine(); } //Declare variable to hold the converted value of menu selection int depositChoiceInt; //Convert with TryParse int.TryParse(depositChoice, out depositChoiceInt); //Validate that user made a numerical choice between 1 and 5 while (depositChoiceInt < 1 || depositChoiceInt > 2) { Console.Clear(); //Tell user what went wrong Console.WriteLine("Oops! You selected something other than a number of 1 or 2.\r\nPlease try again and make a menu selection of 1 or 2.\r\n"); Console.WriteLine(depositSubMenu); //Re-capture user response depositChoice = Console.ReadLine(); //re-convert to an integer int.TryParse(depositChoice, out depositChoiceInt); } if (depositChoiceInt == 1) { Console.WriteLine("Please enter the amount of money you wish to deposit into your checking account:\r\n"); string depositAmount = Console.ReadLine(); //Validate if user input anything while (string.IsNullOrWhiteSpace(depositChoice)) { Console.Clear(); //Tell user what went wrong Console.WriteLine("Oops! You didn't deposit anything.\r\nPlease enter the amount you wish to deposit: "); depositAmount = Console.ReadLine(); } //Declare variable to hold the converted value of deposit amount double depositAmountDouble; //Convert with TryParse double.TryParse(depositAmount, out depositAmountDouble); //Call methods for transactions checking1.Deposit(depositAmountDouble); checking1.PrintDepBalance(); } if (depositChoiceInt == 2) { Console.WriteLine("Please enter the amount of money you wish to deposit into your savings account:\r\n"); string depositAmount = Console.ReadLine(); //Validate if user input anything while (string.IsNullOrWhiteSpace(depositChoice)) { Console.Clear(); //Tell user what went wrong Console.WriteLine("Oops! You didn't deposit anything.\r\nPlease enter the amount you wish to deposit: "); depositAmount = Console.ReadLine(); } //Declare variable to hold the converted value of deposit amount double depositAmountDouble; //Convert with TryParse double.TryParse(depositAmount, out depositAmountDouble); //Call methods for transaction savings1.Deposit(depositAmountDouble); savings1.PrintDepBalance(); } break; case 4: //Store submenu in a string string withdrawSubMenu = ("BANK OF WESTEROS" + Environment.NewLine + "----------------------------------" + Environment.NewLine + "- [1] Withdraw Funds from Checking Account" + Environment.NewLine + "- [2] Withdraw Funds from Savings Account" + Environment.NewLine); Console.WriteLine(withdrawSubMenu); //Display submenu to console string withdrawChoice = Console.ReadLine(); //Validate if user input anything while (string.IsNullOrWhiteSpace(withdrawChoice)) { Console.Clear(); //Tell user what went wrong Console.WriteLine("Oops! You didn't select anything.\r\nPlease select a menu option of 1 or 2: "); Console.WriteLine(withdrawChoice); depositChoice = Console.ReadLine(); } //Declare variable to hold the converted value of menu selection int withdrawChoiceInt; //Convert with TryParse int.TryParse(withdrawChoice, out withdrawChoiceInt); //Validate that user made a numerical choice between 1 and 5 while (withdrawChoiceInt < 1 || withdrawChoiceInt > 2) { Console.Clear(); //Tell user what went wrong Console.WriteLine("Oops! You selected something other than a number of 1 or 2.\r\nPlease try again and make a menu selection of 1 or 2.\r\n"); Console.WriteLine(withdrawSubMenu); //Re-capture user response withdrawChoice = Console.ReadLine(); //re-convert to an integer int.TryParse(withdrawChoice, out withdrawChoiceInt); } if (withdrawChoiceInt == 1) { Console.WriteLine("Please enter the amount of money you wish to withdraw from your checking account:\r\n"); string withdrawAmount = Console.ReadLine(); //Validate if user input anything while (string.IsNullOrWhiteSpace(withdrawAmount)) { Console.Clear(); //Tell user what went wrong Console.WriteLine("Oops! You didn't withdraw anything.\r\nPlease enter the amount you wish to withdraw: "); withdrawAmount = Console.ReadLine(); } //Declare variable to hold the converted value of deposit amount double withdrawAmountDouble; //Convert with TryParse double.TryParse(withdrawAmount, out withdrawAmountDouble); //Call on methods for transaction checking1.Withdrawal(withdrawAmountDouble); checking1.TransactionFee(); checking1.PrintWithdrawBalance(); } if (withdrawChoiceInt == 2) { Console.WriteLine("Please enter the amount of money you wish to withdraw from your savings account:\r\n"); string withdrawAmount = Console.ReadLine(); //Validate if user input anything while (string.IsNullOrWhiteSpace(withdrawAmount)) { Console.Clear(); //Tell user what went wrong Console.WriteLine("Oops! You didn't withdraw anything.\r\nPlease enter the amount you wish to withdraw: "); withdrawAmount = Console.ReadLine(); } //Declare variable to hold the converted value of deposit amount double withdrawAmountDouble; //Convert with TryParse double.TryParse(withdrawAmount, out withdrawAmountDouble); //Call methods for the transaction savings1.Withdrawal(withdrawAmountDouble); savings1.TransactionFee(); savings1.PrintWithdrawBalance(); } break; case 5: Console.Clear(); Console.WriteLine("Thank you for banking with us! Goodbye!\r\n\r\n"); //Goodbye message for user return; default: break; } } while (true); }
static void Main(string[] args) { // Create an instance of each Account / Instantiate Accounts CheckingAccount Checking = new CheckingAccount(); ReserveAccount Reserve = new ReserveAccount(); SavingsAccount Savings = new SavingsAccount(); // Instantiate StreamWriter for each account & to write to a file StreamWriter wChecking = new StreamWriter("CheckingAccount.txt"); StreamWriter wReserve = new StreamWriter("ReserveAccount.txt"); StreamWriter wSavings = new StreamWriter("SavingsAccount.txt"); Console.WriteLine("Welcome to My Bank Account"); Console.WriteLine("Type your First Name"); string accountHolderFirstName = Console.ReadLine(); Console.WriteLine("Type your Last Name"); string accountHolderLastName = Console.ReadLine(); string fullAccountHolderName = string.Concat(accountHolderFirstName, " ", accountHolderLastName); { // do-while loop int usersNumber = 0; do { Console.WriteLine(" View Customer Information: choose 1 "); Console.WriteLine(" View Checking Account Balance: choose 2 "); Console.WriteLine(" View Reserve Account Balance: choose 3 "); Console.WriteLine(" View Savings Account Balance: choose 4 "); Console.WriteLine(" Make a Deposit into an Account: choose 5 "); Console.WriteLine(" Make a Withdrawal from an Account: choose 6 "); Console.WriteLine(" QUIT / EXIT Bank Account Program: choose 7 "); Console.WriteLine(" TYPE your choice as a number 1, 2, 3, 4, 5, 6, or 7 "); string usersResponse = Console.ReadLine(); usersNumber = Convert.ToInt32(usersResponse); switch (usersNumber) { case 1: Checking.BankAccountInfo(); break; case 2: Checking.AccountBalance(); break; case 3: Reserve.AccountBalance(); break; case 4: Savings.AccountBalance(); break; case 5: Console.WriteLine(" Which Account would you like to make a Deposit "); Console.WriteLine(" Checking Account (Deposit): choose 1 "); Console.WriteLine(" Reserve Account (Deposit): choose 2 "); Console.WriteLine(" Savings Account (Deposit): choose 3 "); int userChoice = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("How Much would you like to Deposit"); decimal deposit = Convert.ToDecimal(Console.ReadLine()); switch (userChoice) { case 1: Checking.Deposit(deposit); Console.WriteLine(" Checking Account New Balance: ${0} ", Checking.CheckingAccountBalance); using (wChecking) { wChecking.WriteLine(fullAccountHolderName); wChecking.WriteLine(" Checking Account No.: {0} ", Checking.CheckingAccountNo); wChecking.WriteLine(DateTime.Now); wChecking.WriteLine(" + :$ {0}", deposit); wChecking.WriteLine(" Checking Account New Balance: {0} ", Checking.CheckingAccountBalance); } break; case 2: Reserve.Deposit(deposit); Console.WriteLine(" Reserve Account New Balance: ${0} ", Reserve.ReserveAccountBalance); using (wReserve) { wReserve.WriteLine(fullAccountHolderName); wReserve.WriteLine(" Reserve Account No.: {0} ", Reserve.ReserveAccountNo); wReserve.WriteLine(DateTime.Now); wReserve.WriteLine(" + :$ {0}", deposit); wReserve.WriteLine(" Reserve Account New Balance: ${0} ", Reserve.ReserveAccountBalance); } break; case 3: Savings.Deposit(deposit); Console.WriteLine(" Savings Account New Balance: ${0} ", Savings.SavingsAccountBalance); using (wSavings) { wSavings.WriteLine(fullAccountHolderName); wSavings.WriteLine(" Reserve Account No.: {0} ", Savings.SavingsAccountNo); wSavings.WriteLine(DateTime.Now); wSavings.WriteLine(" + :$ {0}", deposit); wSavings.WriteLine(" Savings Account New Balance: ${0} ", Savings.SavingsAccountBalance); } break; default: Console.WriteLine(" Invalid selection "); Console.WriteLine(" Please choose Deposit option 1, 2, or, 3 "); break; } break; case 6: Console.WriteLine(" Which Account would you like to make a Withdrawal from "); Console.WriteLine(" Checking Account (Withdrawal): choose 1 "); Console.WriteLine(" Reserve Account (Withdrawal): choose 2 "); Console.WriteLine(" Savings Account (Withdrawal): choose 3 "); int userOption = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("How Much would you like to Withdraw"); decimal withdrawal = Convert.ToDecimal(Console.ReadLine()); switch (userOption) { case 1: Checking.Withdrawal(withdrawal); Console.WriteLine(" Check Account New Balance: ${0} ", Checking.CheckingAccountBalance); using (wChecking) { wChecking.WriteLine(fullAccountHolderName); wChecking.WriteLine(" Checking Account No.: {0} ", Checking.CheckingAccountNo); wChecking.WriteLine(DateTime.Now); wChecking.WriteLine(" - :$ {0}", withdrawal); wChecking.WriteLine(" Check Account New Balance: {0} ", Checking.CheckingAccountBalance); } break; case 2: Reserve.Withdrawal(withdrawal); Console.WriteLine(" Reserve Account New Balance: ${0} ", Reserve.ReserveAccountBalance); using (wReserve) { wReserve.WriteLine(fullAccountHolderName); wReserve.WriteLine(" Reserve Account No.: {0} ", Reserve.ReserveAccountNo); wReserve.WriteLine(DateTime.Now); wReserve.WriteLine(" + :$ {0}", withdrawal); wReserve.WriteLine(" Reserve Account New Balance: ${0} ", Reserve.ReserveAccountBalance); } break; case 3: Savings.Withdrawal(withdrawal); Console.WriteLine(" Savings Account New Balance: ${0} ", Savings.SavingsAccountBalance); using (wSavings) { wSavings.WriteLine(fullAccountHolderName); wSavings.WriteLine(" Savings Account No.: {0} ", Savings.SavingsAccountNo); wSavings.WriteLine(DateTime.Now); wSavings.WriteLine(" + :$ {0}", withdrawal); wSavings.WriteLine(" Savings Account New Balance: ${0} ", Savings.SavingsAccountBalance); } break; default: Console.WriteLine(" Invalid selection "); Console.WriteLine(" Please choose Deposit option 1, 2, or, 3 "); break; } break; case 7: Console.WriteLine(" Thank you for using My Bank Account Program "); Console.WriteLine(" , use our program anytime "); Environment.Exit(0); break; default: Console.WriteLine(" Invalid Selection "); Console.WriteLine(" Please choose number 1, 2, 3, 4, 5, 6, or, 7 "); break; } }while (usersNumber != 7); } }
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"); //ask for name Console.WriteLine("Please enter your name for your password."); string holderName = Console.ReadLine(); Console.Clear(); //create objects to use classes SavingsAccount savings = new SavingsAccount(holderName); CheckingAccount checking = new CheckingAccount(holderName); ReserveAccount reserve = new ReserveAccount(holderName); //beginning of text file for each account accountChecking.WriteLine("Account Holder: " + holderName); accountChecking.WriteLine("Account Number: " + checking.AccountNumber); accountChecking.WriteLine("Account Type: Checking Account"); accountChecking.WriteLine("Account Balance: " + checking.AccountBalance); accountSavings.WriteLine("Account Holder: " + holderName); accountSavings.WriteLine("Account Number: " + savings.AccountNumber); accountSavings.WriteLine("Account Type: Savings Account"); accountSavings.WriteLine("Account Balance: " + savings.AccountBalance); accountReserve.WriteLine("Account Holder: " + holderName); 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! What would you like to do?"); Console.WriteLine("1: View Client Information"); Console.WriteLine("View Account Balance of:"); 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"); Console.WriteLine("7: Exit"); //user choose for which action on menu int action = int.Parse(Console.ReadLine()); Console.Clear(); //action for what happens when the user makes a choose switch (action) { case 1: //calls method from account to show client info savings.ClientInfo(); break; case 2: //calls method from checking to view balance checking.ViewAccountBalance(); break; case 3: //views savings balance savings.ViewAccountBalance(); break; case 4: //views reserve balance reserve.ViewAccountBalance(); break; case 5: //asks user where they want to make a deposit and the adds funds to that account Console.WriteLine("Where would you like to make a deposit?"); Console.WriteLine("1: Checking Account"); Console.WriteLine("2: Savings Account"); Console.WriteLine("3: Reserve Account"); int choice = int.Parse(Console.ReadLine()); Console.WriteLine("How much would you like to deposit?"); int deposit = int.Parse(Console.ReadLine()); switch (choice) { case 1: checking.Deposit(deposit); Console.WriteLine("The new balance is " + checking.AccountBalance); accountChecking.WriteLine("+ " + deposit + " " + DateTime.Now); accountChecking.WriteLine("Account Balance: " + checking.AccountBalance); break; case 2: savings.Deposit(deposit); Console.WriteLine("The new balance is " + savings.AccountBalance); accountSavings.WriteLine("+ " + deposit + " " + DateTime.Now); accountSavings.WriteLine("Account Balance: " + savings.AccountBalance); break; case 3: reserve.Deposit(deposit); Console.WriteLine("The new balance is " + reserve.AccountBalance); accountReserve.WriteLine("+ " + deposit + " " + DateTime.Now); accountReserve.WriteLine("Account Balance: " + reserve.AccountBalance); break; default: break; } break; case 6: //asks user where to withdrawal and then takes funds from that account Console.WriteLine("Where would you like to make a withdrawal?"); Console.WriteLine("1: Checking Account"); Console.WriteLine("2: Savings Account"); Console.WriteLine("3: Reserve Account"); int pick = int.Parse(Console.ReadLine()); Console.WriteLine("How much would you like to withdrawal?"); int withdrawal = int.Parse(Console.ReadLine()); 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; case 7: //quits to ask if they want to do anything else break; default: //quits to ask if they want to do anything else break; } Console.WriteLine("Would you like to do something else? Y or N?"); string yesOrNo = Console.ReadLine(); if (yesOrNo.ToLower() == "y") { //clears console and goes back to the menu since in a loop Console.Clear(); } else { //breaks out of loop and quits the program Console.Clear(); break; } } //closes the streamwriters accountReserve.Close(); accountSavings.Close(); accountChecking.Close(); Quit(); }