Purse

  1. The Purse class allows for the management of a collection of coins. The names of the coins in the purse will be kept in an ArrayList<String>. This first version of the Purse class includes a constructor which creates an empty purse object, the mutator method addCoin(String newCoin) which adds a coin to the purse, and a toString() method that returns a string displaying the contents of the purse in the format

     Purse[Quarter,Dime,Nickel,Dime]
  2. Add to the Purse class the mutator method reverse() which reverses the sequence of coins in a purse. For example, if reverse() is called with a purse

     Purse[Quarter,Dime,Nickel,Dime]  

    the purse will now be:

     Purse[Dime,Nickel,Dime,Quarter]
  3. Add a method to the Purse class

     transfer(Purse other)   

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

     Purse[Quarter,Dime,Nickel,Dime]

    and yourPurse is

     Purse[Dime,Nickel]

    then after the call myPurse.transfer(yourPurse), myPurse is

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

    and yourPurse is empty.

  4. Write a boolean method for the Purse class

     sameOrder(Purse other)

    that checks whether the other purse has the same coins, in the same order, as this one.

  5. Write a boolean method for the Purse class

     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 may wish to write a helper methods or two to assist in analyzing this situation.