Implement a class Purse. A purse contains a collection of coins. For simplicity, we will only store the coin names in an ArrayList<String>. (We will discuss a better representation in Chapter 8.) Supply a method

void addCoin(String coinName)

Add a method toString to the Purse class that prints the coins in the purse in the format


Complete the following files:

import java.util.ArrayList; /** A purse holds a collection of coins. */ public class Purse { private ArrayList<String> coins; /** Constructs an empty purse. */ public Purse() { coins = new ArrayList<String>(); } /** Add a coin to the purse. @param coinName the coin to add */ public void addCoin(String coinName) { . . . } /** Returns a string describing the object. @return a string in the format "Purse[coinName1,coinName2,...]" */ public String toString() { . . . } }

Use the following file:

   This class tests the Purse class.
public class PurseTester
   public static void main(String[] args)
      Purse p = new Purse();
      System.out.println("Expected: Purse[Quarter,Dime,Nickel,Dime]");