public void TestAddNewAccount() { SavingsAccount acc = new SavingsAccount(1120002898, Convert.ToDecimal(1000.000000000), "Nmae", DateTime.Now); BankDatabase bankDatabase = BankDatabase.GetInstance(); bankDatabase.AddNewAccount(acc); Assert.IsTrue(bankDatabase.IsValidAccount(acc.AccountNumber,acc.AccountName)); }
public void TestDepositSavings1() { SavingsAccount acc = new SavingsAccount(1120002895, Convert.ToDecimal(1000.000000000), "Nmae", DateTime.Now); decimal amount = 500000; decimal expected = acc.AvailableBalance + amount; acc.CreditAccount(amount); decimal actual = acc.AvailableBalance; Assert.AreEqual(actual, expected); }
public void TestDepositSavings2() { SavingsAccount acc = new SavingsAccount(1120002895, Convert.ToDecimal(1000.000000000), "Nmae", DateTime.Now); decimal amount = -1; acc.CreditAccount(amount); }
public void TestWithdrawalSavings1() { SavingsAccount acc = new SavingsAccount(1120002895, Convert.ToDecimal(1000.000000000), "Nmae", DateTime.Now); decimal amount = -1; acc.DebitAccount(amount); }
public void TestWithdrawalSavings() { SavingsAccount acc = new SavingsAccount(1120002895, Convert.ToDecimal(1000.000000000), "Nmae", DateTime.Now); decimal amount = 1000; decimal expected = acc.AvailableBalance - amount; acc.DebitAccount(amount); decimal actual = acc.AvailableBalance; Assert.AreEqual(actual, expected); }
static void Main(string[] args) { SavingsAccount savings = new SavingsAccount(5.00, .15); ChequingAccount chequing = new ChequingAccount(5.00, .05); GlobalSavingsAccount globalSavings = new GlobalSavingsAccount(5.00, .15); while (true) { Console.WriteLine("-----------------------------------------------------------"); Console.WriteLine("Welcome to OmegaBank, please select an account type."); Console.WriteLine("A: Savings"); Console.WriteLine("B: Checking"); Console.WriteLine("C: GlobalSavings"); Console.WriteLine("Q: Exit"); string AccountType = Console.ReadLine(); while (!(AccountType.ToUpper() == "A" || AccountType.ToUpper() == "B" || AccountType.ToUpper() == "C" || AccountType.ToUpper() == "Q")) { Console.WriteLine("-----------------------------------------------------------"); Console.WriteLine("No such options, please select a valid option."); AccountType = Console.ReadLine(); } switch (AccountType.ToUpper()) { case "A": Console.WriteLine("-----------------------------------------------------------"); Console.WriteLine("Savings Menu"); Console.WriteLine("A: Deposit"); Console.WriteLine("B: Withdraw"); Console.WriteLine("C: Close + Report"); Console.WriteLine("R: Return to Bank Menu"); string savingsOption = Console.ReadLine(); while (!(savingsOption.ToUpper() == "A" || savingsOption.ToUpper() == "B" || savingsOption.ToUpper() == "C" || savingsOption.ToUpper() == "R")) { Console.WriteLine("No such options, please select a valid option."); savingsOption = Console.ReadLine(); } switch (savingsOption.ToUpper()) { case "A": Console.WriteLine("\nHow much do you want to deposit?"); string depositAmount = Console.ReadLine(); while (!double.TryParse(depositAmount, out double enterADamnNumberPlease)) { Console.WriteLine("Enter a numeric value for the amount you deposit."); depositAmount = Console.ReadLine(); } double.TryParse(depositAmount, out double deposit); savings.MakeDeposit(deposit); break; case "B": Console.WriteLine("\nHow much do you want to withdraw?"); string withdrawAmount = Console.ReadLine(); while (!double.TryParse(withdrawAmount, out double enterADamnNumberPlease)) { Console.WriteLine("Enter a numeric value for the amount you withdraw."); withdrawAmount = Console.ReadLine(); } double.TryParse(withdrawAmount, out double withdraw); savings.MakeWithdrawal(withdraw); break; case "C": Console.WriteLine(savings.CloseAndReport()); break; case "R": break; default: break; } break; case "B": Console.WriteLine("-----------------------------------------------------------"); Console.WriteLine("Chequings Menu"); Console.WriteLine("A: Deposit"); Console.WriteLine("B: Withdraw"); Console.WriteLine("C: Close + Report"); Console.WriteLine("R: Return to Bank Menu"); string chequingOption = Console.ReadLine(); while (!(chequingOption.ToUpper() == "A" || chequingOption.ToUpper() == "B" || chequingOption.ToUpper() == "C" || chequingOption.ToUpper() == "R")) { Console.WriteLine("No such options, please select a valid option."); chequingOption = Console.ReadLine(); } switch (chequingOption.ToUpper()) { case "A": Console.WriteLine("\nHow much do you want to deposit?"); string depositAmount = Console.ReadLine(); while (!double.TryParse(depositAmount, out double enterADamnNumberPlease)) { Console.WriteLine("Enter a numeric value for the amount you deposit."); depositAmount = Console.ReadLine(); } double.TryParse(depositAmount, out double deposit); chequing.MakeDeposit(deposit); break; case "B": Console.WriteLine("\nHow much do you want to withdraw?"); string withdrawAmount = Console.ReadLine(); while (!double.TryParse(withdrawAmount, out double enterADamnNumberPlease)) { Console.WriteLine("Enter a numeric value for the amount you withdraw."); withdrawAmount = Console.ReadLine(); } double.TryParse(withdrawAmount, out double withdraw); chequing.MakeWithdrawal(withdraw); break; case "C": Console.WriteLine(chequing.CloseAndReport()); break; case "R": break; default: break; } break; case "C": Console.WriteLine("-----------------------------------------------------------"); Console.WriteLine("GlobalSavings Menu"); Console.WriteLine("A: Deposit"); Console.WriteLine("B: Withdraw"); Console.WriteLine("C: Close + Report"); Console.WriteLine("D: Report Balance in USD"); Console.WriteLine("R: Return to Bank Menu"); string globalSavingsOption = Console.ReadLine(); while (!(globalSavingsOption.ToUpper() == "A" || globalSavingsOption.ToUpper() == "B" || globalSavingsOption.ToUpper() == "C" || globalSavingsOption.ToUpper() == "D" || globalSavingsOption.ToUpper() == "R")) { Console.WriteLine("No such options, please select a valid option."); globalSavingsOption = Console.ReadLine(); } switch (globalSavingsOption.ToUpper()) { case "A": Console.WriteLine("\nHow much do you want to deposit?"); string depositAmount = Console.ReadLine(); while (!double.TryParse(depositAmount, out double enterADamnNumberPlease)) { Console.WriteLine("Enter a numeric value for the amount you deposit."); depositAmount = Console.ReadLine(); } double.TryParse(depositAmount, out double deposit); globalSavings.MakeDeposit(deposit); break; case "B": Console.WriteLine("\nHow much do you want to withdraw?"); string withdrawAmount = Console.ReadLine(); while (!double.TryParse(withdrawAmount, out double enterADamnNumberPlease)) { Console.WriteLine("Enter a numeric value for the amount you withdraw."); withdrawAmount = Console.ReadLine(); } double.TryParse(withdrawAmount, out double withdraw); globalSavings.MakeWithdrawal(withdraw); break; case "C": Console.WriteLine(globalSavings.CloseAndReport()); break; case "D": Console.WriteLine("The balance in USD is: " + ExtensionMethods.ToNAMoneyFormat(globalSavings.USValue(0.76), true)); break; case "R": break; default: break; } break; case "Q": Environment.Exit(0); break; default: break; } } }
static void Main(string[] args) { savAccount = new SavingsAccount(5, .10); cheAccount = new Chequing(5, .10); gloAccount = new GlobalSavingsAccount(5, .10); MenuTreeNode lastWorkingNode = null; MenuTreeNode tree = new MenuTreeNode("bank menu", (self) => { lastWorkingNode = self; Dictionary <string, string> optionToMenu = new Dictionary <string, string>() { { "a", "savings menu" }, { "b", "checking menu" }, { "c", "global savings menu" }, { "q", "quit" } }; GetInputFromConsole( "Welcome to the Online Bank Service! \nSelect an option from the menu: \nA: Savings \nB: Checking \nC: GlobalSavings \nQ: Exit", "\nInvalid option, please choose valid option \n", input => optionToMenu.ContainsKey(input.ToLower()), out string choice ); self.GetChild(optionToMenu[choice]); }) // Everything below this is a CHILD / BRANCH of the node "bank menu" { new MenuTreeNode("savings menu", (self) => { lastWorkingNode = self; Dictionary <string, Action> optionToAction = new Dictionary <string, Action>() { { "a", () => { DepositScenario(savAccount); self.Execute(); } }, { "b", () => { WithdrawalScenario(savAccount); self.Execute(); } }, { "c", () => { CloseAndReportScenario(savAccount); self.Parent.Execute(); } }, { "r", self.Parent.Execute } }; GetInputFromConsole( "\nSavings Menu: \nA: Deposit \nB: Withdrawal \nC: Close + Report \nR: Return to Bank Menu", "\nInvalid option, please choose valid option \n", input => optionToAction.ContainsKey(input.ToLower()), out string choice ); optionToAction[choice](); }), new MenuTreeNode("checking menu", (self) => { lastWorkingNode = self; Dictionary <string, Action> optionToAction = new Dictionary <string, Action>() { { "a", () => { DepositScenario(cheAccount); self.Execute(); } }, { "b", () => { WithdrawalScenario(cheAccount); self.Execute(); } }, { "c", () => { CloseAndReportScenario(cheAccount); self.Parent.Execute(); } }, { "r", self.Parent.Execute } }; GetInputFromConsole( "\nSavings Menu: \nA: Deposit \nB: Withdrawal \nC: Close + Report \nR: Return to Bank Menu", "\nInvalid option, please choose valid option \n", input => optionToAction.ContainsKey(input.ToLower()), out string choice ); optionToAction[choice](); }), new MenuTreeNode("global savings menu", (self) => { lastWorkingNode = self; Dictionary <string, Action> optionToAction = new Dictionary <string, Action>() { { "a", () => { DepositScenario(gloAccount); self.Execute(); } }, { "b", () => { WithdrawalScenario(gloAccount); self.Execute(); } }, { "c", () => { CloseAndReportScenario(gloAccount); self.Parent.Execute(); } }, { "d", () => { Console.WriteLine(gloAccount.USValue(0.76).ToNAMoneyFormat(true)); self.Execute(); } }, { "r", self.Parent.Execute } }; GetInputFromConsole( "\nSavings Menu: \nA: Deposit \nB: Withdrawal\nC: Close and Report \nD: Report Balance in USD\nR: Return to Bank Menu", "\nInvalid option, please choose valid option \n", input => optionToAction.ContainsKey(input.ToLower()), out string choice ); optionToAction[choice](); }), new MenuTreeNode("quit", _ => Console.WriteLine("Goodbye")) }; try { tree.Execute(); } catch (AccountDisabledException e) { Console.WriteLine(e.Message); if (lastWorkingNode != null) { lastWorkingNode.Execute(); } else { tree.Execute(); } } catch (Exception e) { Console.WriteLine("\n\n\nSomething went horribly wrong...\nReturning to start menu\n\n\n"); tree.Execute(); } System.Threading.Thread.Sleep(1500); }
/// <summary> /// Creates a New Account and Add the Account to the BankDatabase /// </summary> /// <returns>The Account Number for the New Account</returns> public static long CreateAccount() { string customerLastName; string customerFirstName; string customerPhoneNumber; string customerEmailAddress; string customerHomeAddress; Console.Clear(); Console.ForegroundColor = ConsoleColor.Yellow; UserInterface.DisplayMessageLine("\n\t\t\t\t ***Account Creation***\n"); Console.ResetColor(); Console.ForegroundColor = ConsoleColor.Cyan; UserInterface.DisplayMessageLine("\n\t\t\t\t---------Customer Details-------"); Console.ResetColor(); Console.ForegroundColor = ConsoleColor.Blue ; UserInterface.DisplayMessageLine("\n\t\t\t\t Enter Last Name "); UserInterface.DisplayMessage("\n\t\t\t\t\t "); Console.ResetColor(); customerLastName = UserInterface.GetInput(); Console.ForegroundColor = ConsoleColor.Blue; UserInterface.DisplayMessageLine("\n\t\t\t\t Enter First Name "); UserInterface.DisplayMessage("\n\t\t\t\t\t "); Console.ResetColor(); customerFirstName = UserInterface.GetInput(); Console.ForegroundColor = ConsoleColor.Blue; UserInterface.DisplayMessageLine("\n\t\t\t\t Enter Phone Number "); UserInterface.DisplayMessage("\n\t\t\t\t\t "); Console.ResetColor(); customerPhoneNumber = UserInterface.GetInput(); Console.ForegroundColor = ConsoleColor.Blue; UserInterface.DisplayMessageLine("\n\t\t\t\t Enter Email Address "); UserInterface.DisplayMessage("\n\t\t\t\t\t "); Console.ResetColor(); customerEmailAddress = UserInterface.GetInput(); Console.ForegroundColor = ConsoleColor.Blue; UserInterface.DisplayMessageLine("\n\t\t\t\t Enter Home Address "); UserInterface.DisplayMessage("\n\t\t\t\t\t "); Console.ResetColor(); customerHomeAddress = UserInterface.GetInput(); Console.ForegroundColor = ConsoleColor.Blue; UserInterface.DisplayMessageLine("\t\tEnter Account Type, 0 For Savings Account , 1 For Current Account "); UserInterface.DisplayMessage("\n\t\t\t\t\t "); Console.ResetColor(); int accountType = int.Parse(UserInterface.GetInput()); long customerNewAccountNumber = GenerateAccountNumber();//Generates A new Account Number For The Customer string fullCustomerName = customerLastName +" " + customerLastName; BankDatabase bankdatabase = BankDatabase.GetInstance(); Account newAccount = null; switch(accountType){ case (int)AccountType.Savings: newAccount = new SavingsAccount(customerNewAccountNumber, Convert.ToDecimal(0.00), fullCustomerName, DateTime.Now); break; case (int)AccountType.Current: newAccount = new CurrentAccount(customerNewAccountNumber, Convert.ToDecimal(0.00), fullCustomerName, DateTime.Now); break; } bankdatabase.AddNewAccount(newAccount); Customer newCustomer = new Customer(customerNewAccountNumber, customerLastName, customerFirstName,customerPhoneNumber, customerEmailAddress, customerEmailAddress); bankdatabase.AddNewCustomer(newCustomer); return customerNewAccountNumber; }
static void Main(string[] args) { // Creation of instances classes SavingsAccount sa = new SavingsAccount(5, 0.05); CheckingAccount ca = new CheckingAccount(5, 0.05); GlobalSavingsAccount gsa = new GlobalSavingsAccount(5, 0.05); Console.WriteLine("Hello welcome to Champlain International Bank..."); Console.WriteLine("Login to continue..."); Console.Write("Username: "******"Password (enter random things, this is just for fun): "); Console.ReadLine(); Console.WriteLine("Hello " + name + "\nSelect an option within the menu you would like to interact with: "); bool exit = false; // loop break for Bank menu bool innerExit = false; //loop break for Account menus bool goodDeposit = false; //loop break for deposits bool goodWithdraw = false; //loop break for withdraws //Start of program loop while (exit == false) { innerExit = false; try { Console.WriteLine(" ___________________________"); Console.WriteLine("| Bank Menu |"); Console.WriteLine("|---------------------------|"); Console.WriteLine("| A: Savings Account |"); Console.WriteLine("| B: Checking Account |"); Console.WriteLine("| C: Global Savings Account |"); Console.WriteLine("| Q: Exit |"); Console.WriteLine("| |"); Console.WriteLine("|___________________________|"); string letterAccount = Console.ReadLine(); string letterChoice; //Start of main switch statement switch (letterAccount.Trim().ToLower()) { case "a": case "savings": case "savings account": while (innerExit == false) { try { Console.WriteLine(" ___________________________"); Console.WriteLine("| Savings Menu |"); Console.WriteLine("|---------------------------|"); Console.WriteLine("| A: Deposit |"); Console.WriteLine("| B: Withdrawal |"); Console.WriteLine("| C: Close and Report |"); Console.WriteLine("| R: Return to Bank Menu |"); Console.WriteLine("| |"); Console.WriteLine("|___________________________|"); string balance = sa.Month_current_balance.ToNAMoneyFormat(true); Console.WriteLine("Current Balance: " + balance); letterChoice = Console.ReadLine(); goodDeposit = false; // Resets the deposit loop to keep looping the next time we enter a bad value goodWithdraw = false; // Resets the deposit loop to keep looping the next time we enter a bad value //Start of switch statement for Savings menu switch (letterChoice.Trim().ToLower()) { case "a": case "deposit": //loop for deposit validation while (goodDeposit == false) { try { Console.WriteLine("____________Deposit_____________"); Console.WriteLine("Enter the amount you want to deposit: "); string depositStr = Console.ReadLine().Trim(new char[] { '$', ' ' }); double deposit = Convert.ToDouble(depositStr); if (deposit < 0) { NegativeNumberError(); } else { sa.MakeDeposit(deposit.ToNAMoneyFormatD(true)); Console.WriteLine("Successfully deposited " + deposit.ToNAMoneyFormat(true)); goodDeposit = true; // Exit of loop allowed } } catch (NegativeNumberException e) { Console.WriteLine(e.Message); Console.WriteLine("Try Again"); } catch (FormatException) { try { NotNumberError(); } catch (NotNumberException ex) { Console.WriteLine(ex.Message); Console.WriteLine("Try Again"); } } } break; case "b": case "withdraw": //loop for withdraw validation while (goodWithdraw == false) { try { Console.WriteLine("___________Withdrawal___________"); Console.WriteLine("Enter the amount you want to withdraw"); string withdrawStr = Console.ReadLine().Trim(new char[] { '$', ' ' }); double withdraw = Convert.ToDouble(withdrawStr); if (withdraw < 0) { NegativeNumberError(); //No negative numbers } else { sa.MakeWithdraw(withdraw.ToNAMoneyFormatD(true)); goodWithdraw = true; // Exit of loop allowed } } catch (NegativeNumberException e) { Console.WriteLine(e.Message); Console.WriteLine("Try Again"); } catch (FormatException) { try { NotNumberError(); } catch (NotNumberException ex) { Console.WriteLine(ex.Message); Console.WriteLine("Try Again"); } } } break; case "c": Console.WriteLine("Closing and Giving Report..."); Console.WriteLine(sa.CloseAndReport()); break; case "r": innerExit = true; break; default: WrongMenuChoice(); break; } //End of switch statement for Savings menu } catch (WrongMenuChoiceException e) { Console.WriteLine(e.Message); Console.WriteLine("Try Again (A,B,C,R)"); } } break; case "b": case "checking": case "checking account": while (innerExit == false) { try { goodDeposit = false; goodWithdraw = false; Console.WriteLine(" ___________________________"); Console.WriteLine("| Checking Menu |"); Console.WriteLine("|---------------------------|"); Console.WriteLine("| A: Deposit |"); Console.WriteLine("| B: Withdrawal |"); Console.WriteLine("| C: Close and Report |"); Console.WriteLine("| R: Return to Bank Menu |"); Console.WriteLine("| |"); Console.WriteLine("|___________________________|"); string balance = ca.Month_current_balance.ToNAMoneyFormat(true); Console.WriteLine("Current Balance: " + balance); letterChoice = Console.ReadLine(); //Start of switch statement for Checking Menu switch (letterChoice.Trim().ToLower()) { case "a": case "deposit": //loop for deposit validation while (goodDeposit == false) { try { Console.WriteLine("____________Deposit_____________"); Console.WriteLine("Enter the amount you want to deposit: "); string depositStr = Console.ReadLine().Trim(new char[] { '$', ' ' }); double deposit = Convert.ToDouble(depositStr); if (deposit < 0) { NegativeNumberError(); } else { ca.MakeDeposit(deposit.ToNAMoneyFormatD(true)); Console.WriteLine("Successfully deposited " + deposit.ToNAMoneyFormat(true)); goodDeposit = true; // Exit of loop allowed } } catch (NegativeNumberException e) { Console.WriteLine(e.Message); Console.WriteLine("Try Again"); } catch (FormatException) { try { NotNumberError(); } catch (NotNumberException ex) { Console.WriteLine(ex.Message); Console.WriteLine("Try Again"); } } } break; case "b": case "withdraw": //loop for withdraw validation while (goodWithdraw == false) { try { Console.WriteLine("___________Withdrawal___________"); Console.WriteLine("Enter the amount you want to withdraw"); string withdrawStr = Console.ReadLine().Trim(new char[] { '$', ' ' }); double withdraw = Convert.ToDouble(withdrawStr); if (withdraw < 0) { NegativeNumberError(); //No negative numbers } else { ca.MakeWithdraw(withdraw.ToNAMoneyFormatD(true)); goodWithdraw = true; // Exit of inner-loop allowed } } catch (NegativeNumberException e) { Console.WriteLine(e.Message); Console.WriteLine("Try Again"); } catch (FormatException) { try { NotNumberError(); } catch (NotNumberException ex) { Console.WriteLine(ex.Message); Console.WriteLine("Try Again"); } } } break; case "c": Console.WriteLine("Closing and Giving Report..."); Console.WriteLine(ca.CloseAndReport()); break; case "r": innerExit = true; // Exit of loop allowed break; default: WrongMenuChoice(); break; } //End of switch statement for Checking Menu } catch (WrongMenuChoiceException e) { Console.WriteLine(e.Message); Console.WriteLine("Try Again (A,B,C,R)"); } } break; case "c": case "global": case "global savings": case "global savings account": while (innerExit == false) { try { goodDeposit = false; goodWithdraw = false; Console.WriteLine(" ___________________________ "); Console.WriteLine("| Global Savings Menu |"); Console.WriteLine("|---------------------------|"); Console.WriteLine("| A: Deposit |"); Console.WriteLine("| B: Withdrawal |"); Console.WriteLine("| C: Close and Report |"); Console.WriteLine("| D: Report Balance in USD |"); Console.WriteLine("| R: Return to Bank Menu |"); Console.WriteLine("|___________________________|"); string balance = gsa.Month_current_balance.ToNAMoneyFormat(true); Console.WriteLine("Current Balance: " + balance); letterChoice = Console.ReadLine(); //Start of switch statement for Global Savings menu switch (letterChoice.Trim().ToLower()) { case "a": case "deposit": //loop for deposit validation while (goodDeposit == false) { try { Console.WriteLine("____________Deposit_____________"); Console.WriteLine("Enter the amount you want to deposit: "); string depositStr = Console.ReadLine().Trim(new char[] { '$', ' ' }); double deposit = Convert.ToDouble(depositStr); if (deposit < 0) { NegativeNumberError(); } else { gsa.MakeDeposit(deposit.ToNAMoneyFormatD(true)); Console.WriteLine("Successfully deposited " + deposit.ToNAMoneyFormat(true)); goodDeposit = true; } } catch (NegativeNumberException e) { Console.WriteLine(e.Message); Console.WriteLine("Try Again"); } catch (FormatException) { try { NotNumberError(); } catch (NotNumberException ex) { Console.WriteLine(ex.Message); Console.WriteLine("Try Again"); } } } break; case "b": case "withdraw": //loop for withdraw validation while (goodWithdraw == false) { try { Console.WriteLine("___________Withdrawal___________"); Console.WriteLine("Enter the amount you want to withdraw"); string withdrawStr = Console.ReadLine().Trim(new char[] { '$', ' ' }); double withdraw = Convert.ToDouble(withdrawStr); if (withdraw < 0) { NegativeNumberError(); //No negative numbers } else { gsa.MakeWithdraw(withdraw.ToNAMoneyFormatD(true)); goodWithdraw = true; } } catch (NegativeNumberException e) { Console.WriteLine(e.Message); Console.WriteLine("Try Again"); } catch (FormatException) { try { NotNumberError(); } catch (NotNumberException ex) { Console.WriteLine(ex.Message); Console.WriteLine("Try Again"); } } } break; case "c": Console.WriteLine("Closing and Giving Report..."); Console.WriteLine(gsa.CloseAndReport()); break; case "d": Console.WriteLine("Total balance: " + gsa.USValue(0.76).ToNAMoneyFormat(true) + " USD"); break; case "r": innerExit = true; break; default: WrongMenuChoice(); break; } //End of switch statement for Global Savings menu } catch (WrongMenuChoiceException e) { Console.WriteLine(e.Message); Console.WriteLine("Try Again (A,B,C,D,R)"); } } break; case "q": exit = true; break; default: WrongMenuChoice(); break; } //End of main switch statement } catch (WrongMenuChoiceException e) { Console.WriteLine(e.Message); Console.WriteLine("Try Again (A,B,C,Q)"); } } }