import java.util.ArrayList ; /** A purse holds a collection of coins. */ public class Purse { // instance var is an ArrayList that will store Coin objects private ArrayList coins ; /** Constructs an empty purse. */ public Purse() { coins = new ArrayList() ; } /** Add a coin to the purse. @param aCoin the coin to add */ public void add(Coin aCoin) { coins.add(aCoin) ; // calls ArrayList method add } /** Get the total value of the coins in the purse. @return the sum of all coin values */ public double getTotal() { double total = 0; for (int i = 0; i < coins.size() ; i++) { Coin aCoin = (Coin)coins.get(i) ; // calls ArrayList method get total = total + aCoin.getValue() ; // calls Coin method getValue } return total ; } }