The Teller bean will provide some of the services provided by a real teller in a bank. Its interface is as follows:
public int mkAccount(String account, double initialBalance)
public void transfer(int from, int to, double amt)
public String getBalances()
The
mkAccount()
method creates a new account and returns an index to the just-created BankAccount instance that can be used in other method calls such as
transfer()
.
transfer()
will move an amount from one open account to another using their indexes.
getBalances()
returns a string containing the current balances of all the BankAccount instances that it has created. As it may have been some time since you worked with the BankAccount bean, its remote interface is as follows:
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
public interface BankAccount extends EJBObject {
public double getBalance() throws RemoteException;
public void credit(double amount) throws RemoteException;
public void debit(double amount)
throws RemoteException, NSFException;
public String getInfo() throws RemoteException;
}
In this exercise, you will write the bean-managed transaction Teller bean using the skeleton provided. The provided client will create two accounts using the
mkAccount()
method and then will transfer $100 from one to the other. Then it will display the current balances. The BankAccount bean instances will only exist during the life of the container, as they are currently implemented as session beans. In later project exercises, the BankAccount bean will store the balance in a database so its state is not discarded.