Write a method for the Purse class

public boolean sameCoins(Purse other)

that checks whether the other purse has the same coins, perhaps in a different order. For example, the purses

Purse[Quarter,Dime,Nickel,Dime]

and

Purse[Nickel,Dime,Dime,Quarter]

should be considered equal. You will probably need one or more helper methods.

Complete the following file:

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() { . . . } /** Determines if a purse has the same coins in the same or different order as another purse. @param other the other purse @return true if the two purses have the same coins in the same or different order, false otherwise */ public boolean sameCoins(Purse other) { . . . } }

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("Nickel");
      b.addCoin("Dime");   
      b.addCoin("Dime");      
      b.addCoin("Quarter"); 
      
      System.out.println(a.sameCoins(b));
      System.out.println("Expected: true");
             
      Purse c = new Purse();
      c.addCoin("Quarter");
      c.addCoin("Penny");
      c.addCoin("Nickel");
      c.addCoin("Dime");        
      
      Purse d = new Purse();    
      d.addCoin("Nickel");
      d.addCoin("Dime");   
      d.addCoin("Dime");         
      d.addCoin("Quarter");

      System.out.println(c.sameCoins(d));
      System.out.println("Expected: false");
   }
}