| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- package com.zipcodewilmington.bankaccountlab;
- import java.util.*;
- public class ATM {
- Scanner input = new Scanner(System.in);
- BusinessAccount businessAccount;
- SavingAccount savingAccount;
- CheckingAccount checkingAccount;
-
- Boolean repeat=true;
- BankAccount[] personalAccounts;
- public ATM() {
-
- businessAccount = new BusinessAccount(7000);
- savingAccount = new SavingAccount(6000);
- checkingAccount = new CheckingAccount(500);
- personalAccounts = new BankAccount[]{businessAccount,savingAccount, checkingAccount};
- accountChoice();
- }
-
- public void accountChoice()
- {
- while(repeat) {
- System.out.println("\nWhich Account you want to operate\n1.Business Account\n2.Saving Account\n3.Checking Account\n4.Exit");
- int accountChoice = input.nextInt();
- if (accountChoice == 1) {
- BankAccount userSelection=personalAccounts[0];
- System.out.printf("Your Current Business Account balance is %d", businessAccount.getBalance());
- accountChoice(userSelection);
- }
- if (accountChoice == 2) {
- BankAccount userSelection=personalAccounts[1];
- System.out.printf("Your Current Saving Account balance is %d", savingAccount.getBalance());
- accountChoice(userSelection);
-
- }
- if (accountChoice == 3) {
- BankAccount userSelection=personalAccounts[2];
- System.out.printf("Your Current Checking Account balance is %d", checkingAccount.getBalance());
- accountChoice(userSelection);
- }
- if(accountChoice==4)
- {
- System.exit(0);
- }
- }
- }
- public void accountChoice(BankAccount userSelection)
- {
-
- System.out.println("\nWhat u wanna do\n1.Credit\n2.Debit\n3.Go back to menu");
- int choice=input.nextInt();
-
-
- if (choice == 1)//Credit
- {
- System.out.println("Enter the amount ?");
- int amount=input.nextInt();
- userSelection.credit(amount);
-
- }
- else if (choice == 2)//Debit
- {
- System.out.println("Enter the amount ?");
- int amount=input.nextInt();
- userSelection.debit(amount);
-
- }
- else if (choice == 3)//Go back to menu
- {
- accountChoice();
- }
- display(userSelection);
- }
- public void display(BankAccount userSelection)
- {
- System.out.println("Your current balance is "+userSelection.getBalance());
- }
-
-
- }
-
-
|