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