// Creates Accounts private static void Createaccounts(List <Account> accounts) { // The total number of accounts to be created int NumberOfAccounts = TUI.ReadInteger("How many Accounts would you like to create? "); // the creation Loop for (int i = 0; i < NumberOfAccounts; i++) { Console.WriteLine($"Account number - {++RunningAccountNumber}"); Console.WriteLine("Which account Would You Like to create?: "); Console.WriteLine("1. Savings Account"); Console.WriteLine("2. Checking Account"); int input = TUI.ReadIntegerRange(1, 2); Account account = null; // creates account according to the type switch (input) { case 1: account = new SavingsAccount(); break; case 2: account = new CheckingAccount(); break; } account.Create(RunningAccountNumber); accounts.Add(account); } }
// Handles the accounts menu private static void HandleAccounts(List <Account> accounts, bool accountsCreated = false) { int input; // User input do { // Displays Account Menu DisplayAccountsMenu(); input = TUI.ReadInteger(); switch (input) { // case 1: Createaccounts(accounts); Console.WriteLine("Accounts have been created!"); accountsCreated = true; break; case 2: if (accountsCreated) { HandleAccount(accounts); } break; case 3: break; default: Console.WriteLine("Woops! That didn't work."); break; } } while (input != 3); }
// Processes The loan // returns the status after processsing public void Process(Account account) { { bool result = false; string reason = ""; // Checks if the account already has a loan. if (!account.HasLoan) { // Verification Check if (!(TUI.ReadInteger("Please Enter Your unique accountID for verification: ") == account.AccountID)) { reason = "Verification Error"; } else { // Checks the initial Balance Before Giving Loan. if (account.Balance > Amount) { // Asks For all the details Amount = TUI.ReadDecimal("Please Enter What amount of loan would you like : "); Days = TUI.ReadInteger("For How many Days: "); Rate = TUI.ReadInteger("The intrest rate from the chart: "); Installments = TUI.ReadIntegerRange(3, 10, "How many installments would you like? (3-10): "); AmountPerInstallment = ((Rate * Days) + Amount) / Installments; account.Balance += Amount; account.HasLoan = true; DateIssued = DateTime.Now; InstallmentsLeft = Installments; LateCharge = TUI.ReadDecimal("Please Enter the Late Charge displayed on the chart."); Console.WriteLine("Loan Successfully Initiated!"); Console.WriteLine($"This is your balance now {account.Balance:C}"); Console.WriteLine($"The Loan is due on: {DateExpire.ToShortDateString()}"); result = true; } else { reason = "Low Balance"; Console.WriteLine($"This is your balance {account.Balance:C}"); Console.WriteLine($"This is your amount {Amount:C}"); } } } else { reason = "Loan Already Issued"; } if (!(result && reason == "")) { Console.WriteLine($"Loan Couldn't be processed please try again, reason: {reason}."); } } }
// Handles loans For a Given Account private static void HandleLoan(Account account) { int input; // User input do { // Displays Loan Menu DisplayLoanMenu(account); input = TUI.ReadInteger(); switch (input) { // Initiate Loan case 1: account.InitiateLoan(); break; // Initiate Payments of installments case 2: if (account.HasLoan) { account.PayInstallments(); } break; // Loan Status; Or overview case 3: if (account.HasLoan) { Console.WriteLine(account.AccLoan.ToString()); } break; // Exit case 4: break; // Failsafe default: break; } } while (input != 4); }
// Pays Specific number of installments public void PayInstallments(Account account) { int InstallmentsToPay = TUI.ReadInteger("How many installments would you like to pay? "); string reason = ""; // Checking if you pay more than installments present if (InstallmentsToPay > InstallmentsLeft && InstallmentsToPay > Installments) { reason = "Installments out of Bound. (More to pay than available)"; } else { decimal AmountToPay = InstallmentsToPay * AmountPerInstallment; // Checks for the expiry and adds extra ammount to initial if (DateTime.Compare(DateExpire, DateTime.Now) < 0) { TimeSpan TimePeriod = DateExpire - DateTime.Now; decimal Extra = (LateCharge * (int)TimePeriod.TotalDays); Console.WriteLine($"The Date of Loan has been Expired! You will have to pay {Extra.ToString():C} extra." + $" For late by {(int)TimePeriod.TotalDays} days."); AmountToPay += Extra; } // Checks if the owner is capable of paying the amount if (AmountToPay > account.Balance) { reason = "Insufficient Balance."; } else { // Verification Check if (!(TUI.ReadInteger("Please Enter Your unique accountID for verification: ") == account.AccountID)) { reason = "Verification Error"; } else { // Gives a Chance to quit if (!TUI.ReadBool("Do You want to Continue?")) { reason = "Terminated by User"; } else { account.Balance -= AmountToPay; InstallmentsLeft -= InstallmentsToPay; if (InstallmentsLeft == 0) { reason = Complete(account); } } } } } if (reason != "") { Console.WriteLine($"The action was cancelled, Reason: {reason}"); } else { Console.WriteLine("Installments Successfully paid!"); } }
// handles account menu, selecting one account private static void HandleAccount(List <Account> accounts) { bool accountSelected = false; Account account = new Account(); int input; do { if (accountSelected) { DisplayMenu(account); } else { DisplayMenu(); } Console.Title = "Account"; input = TUI.ReadInteger("write your input here: "); Console.Clear(); const string errormsg = "Please select a account first"; // TODO: make functions for each of them switch (input) { // Opens Selection Menu case 1: int account_id = TUI.ReadInteger("please enter your account id you want: "); if (account_id <= RunningAccountNumber) { var query = from _account in accounts where _account.AccountID == account_id select _account; foreach (Account _account in query) { account = _account; } accountSelected = true; } else { Console.WriteLine("Please check your account number again."); } break; // Add Deposit case 2: if (accountSelected) { decimal balance = TUI.ReadDecimal("How much you want to deposit: "); account.Deposit(balance); } else { Console.WriteLine(errormsg); } break; // Widrawl Menu case 3: if (accountSelected) { decimal amount = TUI.ReadDecimal("How much you want to widraw"); account.Widraw(amount); } else { Console.WriteLine(errormsg); } break; // Account Details case 4: if (accountSelected) { Console.WriteLine(account.ToString()); } else { Console.WriteLine(errormsg); } break; // Shows the intrest // NOTE: For Savings Account Only case 5: if (accountSelected) { if (account is SavingsAccount savingsAccount) { Console.WriteLine($"{savingsAccount.CalculateIntrest():C}"); } } else { Console.WriteLine(errormsg); } break; // Displays Loan Menu case 6: if (accountSelected) { HandleLoan(account); } else { Console.WriteLine(errormsg); } break; // The exit case 7: break; // If nothing works default: Console.WriteLine("Woops! That didn't work."); break; } } while (input != 7); }