BankAccount.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package com.zipcodewilmington.bankaccountlab;
  2. /**
  3. * Created by leon on 1/10/18.
  4. */
  5. public class BankAccount {
  6. BusinessAccount ba = new BusinessAccount();
  7. CheckingAccount ca = new CheckingAccount();
  8. SavingsAccount sa = new SavingsAccount();
  9. double amountToWithdraw;
  10. double currentAmount;
  11. double amountToDeposit;
  12. boolean isRunning = true;
  13. public BankAccount() {
  14. this.amountToWithdraw = amountToWithdraw;
  15. this.currentAmount = 4000;
  16. this.amountToDeposit = amountToDeposit;
  17. }
  18. public static void main(String[] args) {
  19. BankAccount bank = new BankAccount();
  20. bank.start();
  21. }
  22. public void start() {
  23. do {
  24. Console.print("Welcome to Tyler's ATM");
  25. String whichBankAccount = Console.stringPrompt("What bank account are you accessing today? Select either checking, Savings, or Business. Or type exit to exit.");
  26. if (whichBankAccount.equalsIgnoreCase("business")) {
  27. chooseBusinessAccount();
  28. } else if (whichBankAccount.equalsIgnoreCase("checking")) {
  29. chooseCheckingAccount();
  30. } else if (whichBankAccount.equalsIgnoreCase("savings")) {
  31. chooseSavingsAccount();
  32. } else {
  33. Console.print("Please select an option from the list.");
  34. }
  35. if(whichBankAccount.equalsIgnoreCase("exit")){
  36. isRunning = false;
  37. }
  38. } while(isRunning);
  39. }
  40. public void chooseAction() {
  41. String withdrawOrDeposit = Console.stringPrompt("Please choose either withdraw or deposit.");
  42. if (withdrawOrDeposit.equalsIgnoreCase("withdraw")) {
  43. double amountToWithdraw = Console.doublePrompt("How much money would you like to withdraw today?");
  44. Console.print("You now have $" + ba.withdraw(currentAmount, amountToWithdraw) + " in your bank account");
  45. } else if (withdrawOrDeposit.equalsIgnoreCase("deposit")) {
  46. double amountToDeposit = Console.doublePrompt("How much money would you like to deposit today?");
  47. Console.print("You now have $" + ba.deposit(currentAmount, amountToDeposit) + " in your bank account");
  48. } else {
  49. Console.print("Please choose an option from the list.");
  50. }
  51. }
  52. public void chooseBusinessAccount(){
  53. Console.doublePrompt("Please enter your pin number");
  54. Console.print("Your current balance is: $" + currentAmount);
  55. chooseAction();
  56. ba.withdraw(currentAmount, amountToWithdraw);
  57. ba.deposit(currentAmount, amountToDeposit);
  58. }
  59. public void chooseSavingsAccount(){
  60. Console.doublePrompt("Please enter your pin number");
  61. Console.print("Your current balance is: $" + currentAmount);
  62. chooseAction();
  63. ca.withdraw(currentAmount, amountToWithdraw);
  64. ca.deposit(currentAmount, amountToDeposit);
  65. }
  66. public void chooseCheckingAccount(){
  67. Console.doublePrompt("Please enter your pin number");
  68. Console.print("Your current balance is: $" + currentAmount);
  69. chooseAction();
  70. sa.withdraw(currentAmount, amountToWithdraw);
  71. sa.deposit(currentAmount, amountToDeposit);
  72. }
  73. }