Add a method to the Purse class

public void transfer(Purse other)

that transfers the contents of one purse to another. For example, if a is

Purse[Quarter,Dime,Nickel,Dime]

and b is

Purse[Dime,Nickel]

then after the call a.transfer(b), a is

Purse[Quarter,Dime,Nickel,Dime,Dime,Nickel]

and b is empty.

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() { . . . } /** Transfer the coins from one purse to another. @param other the other purse */ public void transfer(Purse other) { . . . } }

PurseTester2.java

Use the following file:

PurseTester.java

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