ATM.java 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package com.zipcodewilmington.bankaccountlab;
  2. import java.util.*;
  3. public class ATM {
  4. Scanner input = new Scanner(System.in);
  5. BusinessAccount businessAccount;
  6. SavingAccount savingAccount;
  7. CheckingAccount checkingAccount;
  8. Boolean repeat=true;
  9. BankAccount[] personalAccounts;
  10. public ATM() {
  11. businessAccount = new BusinessAccount(7000);
  12. savingAccount = new SavingAccount(6000);
  13. checkingAccount = new CheckingAccount(500);
  14. personalAccounts = new BankAccount[]{businessAccount,savingAccount, checkingAccount};
  15. accountChoice();
  16. }
  17. public void accountChoice()
  18. {
  19. while(repeat) {
  20. System.out.println("\nWhich Account you want to operate\n1.Business Account\n2.Saving Account\n3.Checking Account\n4.Exit");
  21. int accountChoice = input.nextInt();
  22. if (accountChoice == 1) {
  23. BankAccount userSelection=personalAccounts[0];
  24. System.out.printf("Your Current Business Account balance is %d", businessAccount.getBalance());
  25. accountChoice(userSelection);
  26. }
  27. if (accountChoice == 2) {
  28. BankAccount userSelection=personalAccounts[1];
  29. System.out.printf("Your Current Saving Account balance is %d", savingAccount.getBalance());
  30. accountChoice(userSelection);
  31. }
  32. if (accountChoice == 3) {
  33. BankAccount userSelection=personalAccounts[2];
  34. System.out.printf("Your Current Checking Account balance is %d", checkingAccount.getBalance());
  35. accountChoice(userSelection);
  36. }
  37. if(accountChoice==4)
  38. {
  39. System.exit(0);
  40. }
  41. }
  42. }
  43. public void accountChoice(BankAccount userSelection)
  44. {
  45. System.out.println("\nWhat u wanna do\n1.Credit\n2.Debit\n3.Go back to menu");
  46. int choice=input.nextInt();
  47. if (choice == 1)//Credit
  48. {
  49. System.out.println("Enter the amount ?");
  50. int amount=input.nextInt();
  51. userSelection.credit(amount);
  52. }
  53. else if (choice == 2)//Debit
  54. {
  55. System.out.println("Enter the amount ?");
  56. int amount=input.nextInt();
  57. userSelection.debit(amount);
  58. }
  59. else if (choice == 3)//Go back to menu
  60. {
  61. accountChoice();
  62. }
  63. display(userSelection);
  64. }
  65. public void display(BankAccount userSelection)
  66. {
  67. System.out.println("Your current balance is "+userSelection.getBalance());
  68. }
  69. }