Write a method reverse that reverses the sequence of coins in a purse. Use the toString method of the preceding assignment to test your code. For example, if reverse is called with a purse

Purse[Quarter,Dime,Nickel,Dime]

then the purse is changed to

Purse[Dime,Nickel,Dime,Quarter]

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() { . . . } /** Reverses the elements in the purse. */ public void reverse() { . . . } }

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("Original purse: " + p.toString());
      System.out.println("Expected: Purse[Quarter,Dime,Nickel,Dime]");
      p.reverse();
      System.out.println("Reversed purse: " + p.toString());
      System.out.println("Expected: Purse[Dime,Nickel,Dime,Quarter]");
   }
}