Listing 1

public interface MoneyTransferService {

  Account transfer(String fromAccountId,
      String toAccountId, double amount);

}

public class MoneyTransferServiceImpl implements
    MoneyTransferService {

  private AccountDAO accountDAO;

  public MoneyTransferServiceImpl(AccountDAO accountDAO) {
    this.accountDAO = accountDAO;
  }

  public Account transfer(
      String fromAccountId, String toAccountId,
      double amount) {
    Account fromAccount = 
      accountDAO.findAccount(fromAccountId);
    Account toAccount = 
      accountDAO.findAccount(toAccountId);
    fromAccount.debit(amount);
    toAccount.credit(amount);
    return toAccount;
  }

}

public class Account {

  private double balance;
	 private String accountId;

  public Account(String accountId,
      double initialBalance) {
    this.accountId = accountId;
    this.balance = initialBalance;
  }

  public double getBalance() { return balance; }

  public String getAccountId() { return accountId; }

  public void debit(double amount) { balance -= amount; }

  public void credit(double amount) { balance += amount; }
}

public interface AccountDAO {

  Account findAccount(String accountId);

  Account createAccount(String accountId, 
                        double initialBalance);
}

Listing 2

@Stateless
public class MoneyTransferServiceImpl
        implements MoneyTransferService {
    @EJB
    private AccountDAO accountDAO;
...