/** * Represents a simple bank. This class illustrates one way in which * two classes can interact with one another: * 1. Methods can take objects as input arguments * 2. Methods can return objects as return values */ public class SimpleBank{ // Instance variables private int numAccountsOpened; private int nextAccountNumber; // A 9-digit number /** * Constructs a new Bank */ public SimpleBank(){ numAccountsOpened = 0; nextAccountNumber = 100000000; } /** * This method opens a new bank account with the given information * Notice that the return type of this method is SimpleBankAccount */ public SimpleBankAccount openAccount(String theName, double theInitialBalance){ // Create a new SimpleBankAccount SimpleBankAccount account = new SimpleBankAccount(theName, theInitialBalance, ""+nextAccountNumber); // Update the state of the Bank object nextAccountNumber++; numAccountsOpened++; // Return newly opened account return account; } /** * Transfers the specified amount from one account to the other * Notice that this method takes objects of type SimpleBankAccount as input arguments */ public void transfer(double amount, SimpleBankAccount from, SimpleBankAccount to){ from.withdrawal(amount); to.deposit(amount); } /** * Returns the number of accounts the bank has opened */ public int getNumAccountsOpen(){ return numAccountsOpened; } }