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

Purse[Quarter,Dime,Nickel,Dime]

Complete the following files:

Purse.java

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() { . . . } }

PurseTester2.java

PurseTester3.java

Use the following file:

PurseTester.java

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