package com.zipcodewilmington.bankaccountlab; public class ATM { Console console = new Console(); BankAccount account1; BankAccount account2; BankAccount account3; BankAccount[] accounts = new BankAccount[]{account1,account2,account3}; public ATM(){ } public BankAccount[] getAccounts() { return accounts; } public void setAccounts(BankAccount[] accounts) { this.accounts = accounts; } public void runATM(){ console.println("Welcome to the ATM! You may type \"leave\" at any word entry to close the application"); createAccounts(); boolean run =true; while(run) { console.println("Here are your current accounts:"); for (BankAccount account : accounts) { console.println("\nOwner Name: " + account.getOwnerName()+"\nAccount Number: "+ account.getAccountNumber() + "\nCurrent Balance: " + account.getCurrentBalance()); } int currentAccount = console.getIntInput("please enter your account number"); switch(console.getIntInput("What would you like to do?\n1.Transfer Funds\n2.Change An Account Owner\n")){ case (1) : transferFunds(currentAccount); break; case (2) : changeAccountOwner(currentAccount,console.getStringInput("What is the new name on the account?")); break; default: console.println("Please enter the number associated with your choice"); } } } public void transferFunds(int account){ switch (console.getIntInput("What would you like to do?\n1.Deposit\n2.Withdraw\n3.Transfer to a different account")){ case (1) : deposit(account, console.getDoubleInput("How much would you like to deposit?")); break; case (2) : withdraw(account,console.getDoubleInput("How much would you like to withdraw?")); break; case (3) : transfer(account,console.getDoubleInput("How much would you like to transfer?"),console.getIntInput("Enter the account number you would like to transfer to")); break; default: console.println("Please enter the number associated with your choice"); } } public void withdraw(int currentAccount, double amount) { for (BankAccount account : accounts) { if (currentAccount == account.getAccountNumber()){ account.setCurrentBalance(account.getCurrentBalance()-amount); } } } public void deposit(int currentAccount, double amount) { for (BankAccount account : accounts) { if (currentAccount == account.getAccountNumber()){ account.setCurrentBalance(account.getCurrentBalance()+amount); } } } public void transfer(int currentAccount, double amount, int transferTo) { for (BankAccount account : accounts) { if (currentAccount == account.getAccountNumber()){ account.setCurrentBalance(account.getCurrentBalance()-amount); } if (transferTo == account.getAccountNumber()){ account.setCurrentBalance(account.getCurrentBalance()+amount); } } } public void changeAccountOwner(int currentAccount, String newName){ for (BankAccount account : accounts) { if (currentAccount == account.getAccountNumber()){ account.setOwnerName(newName); } } } public void createAccounts() { for (BankAccount account : accounts) { boolean creating = true; while (creating) { switch (console.getIntInput("What kind of account would you like to open?\n1.Business\n2.Checking\n3.Savings\n4.Skip")) { case (1): account = new BusinessAccount(console.getDoubleInput("How much would you like to deposit?"), console.getStringInput("What is your name?")); creating = false; break; case (2): account = new CheckingAccount(console.getDoubleInput("How much would you like to deposit?"), console.getStringInput("What is your name?")); creating = false; break; case (3): account = new SavingsAccount(console.getDoubleInput("How much would you like to deposit?"), console.getStringInput("What is your name?")); creating = false; break; case (4): account = null; creating = false; break; default: console.println("Please enter the number associated with your choice"); } } } } }