import java.util.ArrayList;
import java.util.Collections;

/****
 *
 * This is a version of the BankAccountManager class that adds a sort method.
 * Other than this one addition, it's the same as the previous version of the
 * class.
 */
public class BankAccountManager {

    /** The list of valuable assests */
    private ArrayList<BankAccount> accounts = new ArrayList<BankAccount>();

    /**
     * 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;
    }

    /**
     * Sort the account list, based on the comparator defined in
     * BankAccount.compareTo.
     */
    public void sort() {
        Collections.sort(accounts);
    }

}