import java.util.ArrayList; /**** * * This is a simple class to manage someone's bank accounts. It provides * methods to add an account, remove one, and compute the total value of all * the managed accounts. * */ public class BankAccountManager { /** The list of valuable assests */ private ArrayList accounts = new ArrayList(); /** * Add the given account to the list. */ public void add(BankAccount account) { accounts.add(account); } /** * Remove the given account from the list. */ public void remove(BankAccount account) { accounts.remove(account); } /** * Return the total value of all the accounts in the list. */ public double getTotalValue() { double value = 0; for (BankAccount account : accounts) { value += account.getBalance(); } return value; } /** * Return the string representation of this, one account per line, with * each line indented three spaces. The string format for each account is * defined by BankAccount.toString. */ public String toString() { String returnValue = ""; for (BankAccount account : accounts) { returnValue += " " + account + "\n"; } return returnValue; } }