i have absolutely no idea what to do, can someone explain the steps, or do it and explain what they did?
/**
A purse has an array list of coin names that can
be changed by adding coins.
*/
public class Purse
{
//instance variables
private String[] coins; //the money in the purse
private int count ; // the number of coins in the purse
private int size ; // the real size of the purse
private final int SIZE = 100 ; //the default size
/**
Constructs a purse with a default size.
*/
public Purse()
{
// todo: initialize coins, count and size.
// approximate lines of code required: 3
}
/**
Constructs a purse with a given size.
@param size the size of the purse
*/
public Purse(int size)
{
// todo: initialize coins, count and size.
// approximate lines of code required: 3
}
/**
Deposits money into the purse.
@param coin the coin to deposit
@return false if the coin cannot be added (the purse is full
or the coin is not legal)
*/
public boolean addCoin(String coin)
{
// todo: fill in the method
// approximate lines of code required: 4
}
/**
Private helper method to check legality of coin
@return true if legal, false otherwise
*/
private boolean legal(String coin)
{
// todo: fill in the method
// approximate lines of code required: 4
}
/**
Produces string representation of money in purse.
@return Purse[coin,coin,...]
*/
public String toString()
{
// todo: fill in the method
// approximate lines of code required: 8
}
/**
Reverses the order of the money in the purse
*/
public void reverse()
{
// todo: fill in the method
// approximate lines of code required: 6
}
/**
Removes top coin from the purse
@return name of the coin removed, null if no coin removed
*/
public String remove()
{
// todo: fill in the method
// approximate lines of code required: 8
}
/**
Transfers all the money from a given purse to this purse
@param other the reference to the other purse
*/
public void transfer(Purse other)
{
// todo: fill in the method
// approximate lines of code required: 5
}
}
/**
A class to test the Purse class.
*/
public class PurseTester
{
/**
Tests the methods of the Purse class.
@param args not used
*/
public static void main(String[] args)
{
Purse harrysPurse = new Purse();
Tester.test(1, harrysPurse.addCoin("Dime"), true);
Tester.test(2, harrysPurse.addCoin("Nickel"), true);
harrysPurse.addCoin("Quarter");
Tester.test(3, harrysPurse.addCoin("Yen"), false);
harrysPurse.addCoin("Dime");
Tester.test(4, harrysPurse.toString(),
"Purse[Dime,Nickel,Quarter,Dime]");
harrysPurse.reverse() ;
Tester.test(5, harrysPurse.toString(),
"Purse[Dime,Quarter,Nickel,Dime]");
Purse marysPurse = new Purse(2) ;
marysPurse.addCoin("Dime") ;
marysPurse.addCoin("Nickel") ;
harrysPurse.transfer(marysPurse) ;
Tester.test(6, harrysPurse.toString(),
"Purse[Dime,Quarter,Nickel,Dime,Nickel,Dime]");
Tester.test(7, marysPurse.toString(),
"Purse[]");
}
}
/**
This class contains some static methods to compare values.
*/
public class Tester
{
/**
Compares two boolean values.
Prints a message if they are not equal.
@param number the number of the test
@param obtained the typically unknown value
@param expected the expected value
*/
public static void test(int number, boolean obtained, boolean expected)
{
System.out.println(number + ". Obtained: " + obtained) ;
System.out.println(number + ". Expected: " + expected) ;
System.out.println("--------------------------------------") ;
if (obtained != expected) {
System.out.println("ERROR! OBTAINED IS NOT EXPECTED") ;
System.out.println("--------------------------------------") ;
}
}
/**
Compares two String values.
Prints a message if they are not equal.
@param number the number of the test
@param obtained the typically unknown value
@param expected the expected value
*/
public static void test(int number, String obtained, String expected)
{
System.out.println(number + ". Obtained: " + obtained) ;
System.out.println(number + ". Expected: " + expected) ;
System.out.println("--------------------------------------") ;
if (! obtained.equals(expected)) {
System.out.println("ERROR! OBTAINED IS NOT EXPECTED") ;
System.out.println("--------------------------------------") ;
}
}
/**
Compares two integer values.
Prints a message if they are not equal.
@param number the number of the test
@param obtained the typically unknown value
@param expected the expected value
*/
public static void test(int number, int obtained, int expected)
{
System.out.println(number + ". Obtained: " + obtained) ;
System.out.println(number + ". Expected: " + expected) ;
System.out.println("--------------------------------------") ;
if (obtained != expected) {
System.out.println("ERROR! OBTAINED IS NOT EXPECTED") ;
System.out.println("--------------------------------------") ;
}
}
}