static bool addAccount(ref customer cust, ref List <account> allAccounts, UInt32 number, decimal startBalance, decimal FIR, ref List <customer> allCustomers) //complete add saving func { account newAccount = new account(cust, startBalance, number, FIR); allAccounts.Add(newAccount); foreach (customer alpha in allCustomers) { if (alpha == cust) { alpha.associatedAccounts.Add(number); } } return(true); }
public static void accountMaintenance(ref List <customer> allCustomers, ref List <account> allAccounts) { bool stayInFunction = true; bool firstOperation = true; while (stayInFunction) { if (firstOperation) { Console.Clear(); } Console.WriteLine("~ Account Maintenance ~\n\nWhat would you like to do?\n\n1 - Add new Account.\n2 - Close Account.\n3 - View Account Details.\n4 - Return to Main Menu."); string userInput = Console.ReadLine(); //imhere int caseCheck; Int32.TryParse(userInput, out caseCheck); // parse the selection switch (caseCheck) { case 1: { bool stillAdding = true; string name = ""; // a name for the account e.g. "My Checking Account" int type = 0; // 1 for Checking, 2 for Savings int number = 0; decimal startBal = 0m; customer Cust = null; while (stillAdding) { Console.Clear(); if (name == "") { bool acceptName = false; Console.WriteLine("Please enter a Name for the Account: "); string temp = Console.ReadLine(); Console.WriteLine("You entered: " + temp + "\n Accept Name? (Yes to Accept)"); string answer = Console.ReadLine(); if (string.Equals(answer, yes, StringComparison.OrdinalIgnoreCase)) { acceptName = true; } if (acceptName == true) { name = temp; } } if (number == 0) { bool acceptNumber = false; Console.WriteLine("Please enter Account Number: "); string temp = Console.ReadLine(); Console.WriteLine("You entered: " + temp + "\n Accept Account Number? (Yes to Accept)"); string answer = Console.ReadLine(); if (string.Equals(answer, yes, StringComparison.OrdinalIgnoreCase)) { acceptNumber = true; } if (acceptNumber == true) { Int32.TryParse(temp, out number); } } if (Cust == null) { Console.WriteLine("Please enter Customer Number: "); string temp = Console.ReadLine(); Console.WriteLine("You entered: " + temp + "\n Accept Customer Number? (Yes to Accept)"); string answer = Console.ReadLine(); if (string.Equals(answer, yes, StringComparison.OrdinalIgnoreCase)) { int tnum; Int32.TryParse(temp, out tnum); foreach (customer alpha in allCustomers) { if (alpha.customerNum == tnum) { Cust = alpha; } } } } if (startBal == 0m) { bool acceptBal = false; Console.WriteLine("Please enter a Starting Balance: "); string temp = Console.ReadLine(); Console.WriteLine("You entered: " + temp + "\nCorrect starting balance? (Yes to Accept)"); string answer = Console.ReadLine(); if (string.Equals(answer, yes, StringComparison.OrdinalIgnoreCase)) { acceptBal = true; } if (acceptBal == true) { decimal.TryParse(temp, out startBal); } } if (type == 0) { bool acceptType = false; Console.WriteLine("Please select the type of account (Enter: 1 for checking || 2 for savings): "); string temp = Console.ReadLine(); if (temp == "1") { Console.WriteLine("You selected Checking account, is this correct? (Yes to Accept)"); } else if (temp == "2") { Console.WriteLine("You selected Savings account, is this correct? (Yes to Accept)"); } else { Console.WriteLine("Invalid option selected."); break; } string answer = Console.ReadLine(); if (string.Equals(answer, yes, StringComparison.OrdinalIgnoreCase)) { acceptType = true; } if (acceptType == true) { Int32.TryParse(temp, out type); } } if (name != "" && number != 0 && Cust != null && type != 0 && startBal != 0m) { addAccount(ref Cust, ref allAccounts, name, number, startBal, type); Console.WriteLine("\n\nNew Account Created!\n\n"); stillAdding = false; } } firstOperation = false; break; } case 2: { account toBeClosed = null; bool stillClosing = true; int number = 0; //account number not customer number List <customer> cust = null; while (stillClosing) { bool acceptNumber = false; if (number == 0) { Console.WriteLine("Enter the Account Number for the account you wish to close."); string temp = Console.ReadLine(); Console.WriteLine("You entered: " + temp + " accept account number? (Yes to Accept)"); string answer = Console.ReadLine(); if (string.Equals(answer, yes, StringComparison.OrdinalIgnoreCase)) { acceptNumber = true; } if (acceptNumber == true) { Int32.TryParse(temp, out number); } } } foreach (account alpha in allAccounts) { if (alpha.accountNumber == number) { Console.WriteLine("We got here."); //imhere toBeClosed = alpha; cust = alpha.associatedCustomers; } } Console.WriteLine("Account Number" + toBeClosed.accountNumber + " belongs to " + toBeClosed.associatedCustomers[0].name + " , Customer Number: " + toBeClosed.associatedCustomers[0].customerNum + "Proceed to Close? (Yes to Close Account)"); string answer2 = Console.ReadLine(); if (string.Equals(answer2, yes, StringComparison.OrdinalIgnoreCase)) { closeAccount(ref cust, ref allAccounts, ref toBeClosed, ref allCustomers); //closes the account Console.WriteLine("\n\nAccount Closed Successfully.\n\n"); firstOperation = false; } break; } case 3: { break; } case 4: { stayInFunction = false; break; } } } }
static bool closeAccount(ref List <customer> associatedCust, ref List <account> allAccounts, ref account toBeClosed, ref List <customer> allCustomers) { foreach (customer alpha in associatedCust) { foreach (customer beta in allCustomers) { if (alpha == beta) { beta.associatedAccounts.Remove(toBeClosed.accountNumber); } } } allAccounts.Remove(toBeClosed); return(true); }
// ///////////////////////////////////// /*Start of Main Menu Option Functions */ // ///////////////////////////////////// public static bool deposit(ref List <customer> allCustomers, ref List <account> allAccounts) { bool stillDepositing = true; bool accountSelected = false; bool depositCompleted = false; account toDeposit = null; while (stillDepositing) { if (!accountSelected) //select account { Console.Clear(); Console.WriteLine("Enter the account number for which you'd like to make a deposit: "); string temp = Console.ReadLine(); Console.WriteLine("You entered " + temp + " \nCorrect account number? (Yes or No)"); string answer = Console.ReadLine(); answer = basicFunctions.yesNoOrInvalid(answer); if (answer == "Yes") { UInt32 temp2 = 0; UInt32.TryParse(temp, out temp2); foreach (account alpha in allAccounts) { if (temp2 == alpha.accountNumber) { toDeposit = alpha; } } accountSelected = true; } else if (answer == "No") { accountSelected = false; } else { basicFunctions.invalidInputEntered(); } } if (accountSelected) // account chosen, enter amount and complete deposit { Console.WriteLine("Enter the amount of the deposit, do not include extraneous symbols."); string temp = Console.ReadLine(); Console.WriteLine("You entered " + temp + " \ncorrect amount? (Yes or No)"); string answer = Console.ReadLine(); answer = basicFunctions.yesNoOrInvalid(answer); if (answer == "Yes") { decimal temp2 = 0; decimal.TryParse(temp, out temp2); foreach (account alpha in allAccounts) { if (alpha.accountNumber == toDeposit.accountNumber) { alpha.balance += temp2; depositCompleted = true; stillDepositing = false; } } } else if (answer == "No") { stillDepositing = true; } else { basicFunctions.invalidInputEntered(); } if (depositCompleted == true) { bool stillDisplaying = true; account toDisplay = null; foreach (account alpha in allAccounts) { if (alpha.accountNumber == toDeposit.accountNumber) { toDisplay = alpha; } } while (stillDisplaying) { Console.WriteLine("Deposit Completed\n\n New Balance: " + toDisplay.balance); Console.WriteLine("Enter 1 to Return to Main Menu"); int getCase = basicFunctions.getCase(); switch (getCase) { case 1: stillDisplaying = false; break; default: break; } } } } } return(true); }
public static void accountMaintenance(ref List <customer> allCustomers, ref List <account> allAccounts) { bool stayInFunction = true; bool firstOperation = true; while (stayInFunction) { if (firstOperation) { Console.Clear(); } Console.WriteLine("~ Account Maintenance ~\n\nWhat would you like to do?\n\n1 - Add new Account.\n2 - Close Account.\n3 - View Account Details.\n4 - Return to Main Menu."); int caseCheck = basicFunctions.getCase(); switch (caseCheck) { case 1: { bool stillAdding = true; int type = 0; // 1 for Checking, 2 for Savings UInt32 number = 0; decimal startBal = 0m; decimal startFIR = 0m; customer Cust = null; while (stillAdding) { Console.Clear(); if (number == 0) { bool acceptNumber = false; Console.WriteLine("Please enter Account Number: "); string temp = Console.ReadLine(); Console.WriteLine("You entered: " + temp + "\n Accept Account Number? (Yes or No)"); string answer = Console.ReadLine(); answer = basicFunctions.yesNoOrInvalid(answer); if (answer == "Yes") { acceptNumber = true; } else if (answer == "No") { acceptNumber = false; } else { basicFunctions.invalidInputEntered(); } if (acceptNumber == true) { UInt32.TryParse(temp, out number); } } if (Cust == null) { Console.WriteLine("Please enter Customer Number: "); string temp = Console.ReadLine(); Console.WriteLine("You entered: " + temp + "\n Accept Customer Number? (Yes or No)"); string answer = Console.ReadLine(); answer = basicFunctions.yesNoOrInvalid(answer); if (answer == "Yes") { UInt32 tnum; UInt32.TryParse(temp, out tnum); foreach (customer alpha in allCustomers) { if (alpha.customerNumber == tnum) { Cust = alpha; } } } } if (startBal == 0m) { bool acceptBal = false; Console.WriteLine("Please enter a Starting Balance: "); string temp = Console.ReadLine(); Console.WriteLine("You entered: " + temp + "\nCorrect starting balance? (Yes or No)"); string answer = Console.ReadLine(); answer = basicFunctions.yesNoOrInvalid(answer); if (answer == "Yes") { acceptBal = true; } else if (answer == "No") { acceptBal = false; } else { basicFunctions.invalidInputEntered(); } if (acceptBal == true) { decimal.TryParse(temp, out startBal); } } if (type == 0) { bool acceptType = false; Console.WriteLine("Please select the type of account (Enter: 1 for checking || 2 for savings): "); string temp = Console.ReadLine(); if (temp == "1") { Console.WriteLine("You selected Checking account, is this correct? (Yes to Accept)"); } else if (temp == "2") { Console.WriteLine("You selected Savings account, is this correct? (Yes to Accept)"); } else { Console.WriteLine("Invalid option selected."); break; } string answer = Console.ReadLine(); answer = basicFunctions.yesNoOrInvalid(answer); if (answer == "Yes") { acceptType = true; } else if (answer == "No") { acceptType = false; } else { basicFunctions.invalidInputEntered(); } if (acceptType == true) { Int32.TryParse(temp, out type); } } if (type == 2) { if (startFIR == 0m) { bool acceptFIR = false; Console.WriteLine("Would you like to use the default Fixed Interest Rate of 1.5%? (Yes to accept, No to set custom)."); string answer = Console.ReadLine(); answer = basicFunctions.yesNoOrInvalid(answer); if (answer == "Yes") { acceptFIR = true; startFIR = 1.5m; } else if (answer == "No") { Console.WriteLine("Enter a custom Fixed Interest Rate (Should be a number such as 1 or 1.5, do not include extraneous letters or symbols)"); string temp = Console.ReadLine(); Console.WriteLine("\nYou entered " + temp + "% Fixed Interest Rate, Accept? (Yes or No)"); string answer2 = Console.ReadLine(); answer2 = basicFunctions.yesNoOrInvalid(answer2); if (answer2 == "Yes") { acceptFIR = true; } else if (answer == "No") { acceptFIR = false; } else { basicFunctions.invalidInputEntered(); } if (acceptFIR == true) { decimal.TryParse(temp, out startFIR); } } } } if (number != 0 && Cust != null && type == 1 && startBal != 0m) { addAccount(ref Cust, ref allAccounts, number, startBal, ref allCustomers); Console.WriteLine("\n\nNew Account Created!\n\n"); stillAdding = false; } else if (number != 0 && Cust != null && type == 2 && startBal != 0m && startFIR != 0m) { addAccount(ref Cust, ref allAccounts, number, startBal, startFIR, ref allCustomers); Console.WriteLine("\n\nNew Account Created!\n\n"); stillAdding = false; } } firstOperation = false; break; } case 2: { account toBeClosed = null; bool stillClosing = true; UInt32 number = 0; //account number not customer number customer Cust = null; while (stillClosing) { bool acceptNumber = false; if (number == 0) { Console.WriteLine("Enter the Account Number for the account you wish to close."); string temp = Console.ReadLine(); Console.WriteLine("You entered: " + temp + " accept account number? (Yes or No)"); string answer = Console.ReadLine(); answer = basicFunctions.yesNoOrInvalid(answer); if (answer == "Yes") { acceptNumber = true; } else if (answer == "No") { acceptNumber = false; } else { basicFunctions.invalidInputEntered(); } if (acceptNumber == true) { UInt32.TryParse(temp, out number); } } foreach (account alpha in allAccounts) { if (alpha.accountNumber == number) { toBeClosed = alpha; Cust = alpha.owner; } } Console.WriteLine("Account Number " + toBeClosed.accountNumber + " belongs to " + toBeClosed.owner.name + " , Customer Number: " + toBeClosed.owner.customerNumber + " Proceed to Close? (Yes or No)"); string answer2 = Console.ReadLine(); answer2 = basicFunctions.yesNoOrInvalid(answer2); if (answer2 == "Yes") //imhere { closeAccount(ref allCustomers, Cust, toBeClosed, ref allAccounts); //closes the account Console.WriteLine("\n\nAccount Closed Successfully.\n\n"); firstOperation = false; stillClosing = false; } else if (answer2 == "No") { stillClosing = true; } else { basicFunctions.invalidInputEntered(); } } break; } case 3: { bool stillViewing = true; account toBeViewed = null; bool proceedToPrint = false; while (stillViewing) { Console.Clear(); Console.WriteLine("Enter an account number to print account information."); string temp = Console.ReadLine(); Console.WriteLine("You entered " + temp + "\n Correct account number? (Yes or No)"); string answer = Console.ReadLine(); answer = basicFunctions.yesNoOrInvalid(answer); if (answer == "Yes") { UInt32 temp2 = 0; UInt32.TryParse(temp, out temp2); foreach (account alpha in allAccounts) { if (alpha.accountNumber == temp2) { toBeViewed = alpha; proceedToPrint = true; } } } else if (answer == "No") { proceedToPrint = false; } else { basicFunctions.invalidInputEntered(); } if (proceedToPrint) { Console.WriteLine("Account Owner Name: " + toBeViewed.owner.name); Console.WriteLine("Account Balance: " + toBeViewed.balance); Console.WriteLine("Account Number: " + toBeViewed.accountNumber); if (toBeViewed.type == 1) { Console.WriteLine("Account Type: Checking"); } else { Console.WriteLine("Account Type: Savings"); Console.WriteLine("Fixed Interest Rate: " + toBeViewed.fixedIntered); } Console.WriteLine("Enter 1 to Return to Main Menu."); int getCase = basicFunctions.getCase(); switch (getCase) { case 1: stillViewing = false; break; default: break; } } } break; } case 4: { stayInFunction = false; break; } } } }