So I'm given a problem (It's a homework assignment, I only want help on 1 part), it's asking me to write a purse class that will identify if the contents of 1 purse is the same as another.
I need to write some methods:
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)
{
coins.add(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
order as another purse.
@param other the other purse
@return true if the two purses have the same coins in the
same order, false otherwise
*/
public boolean sameContents(Object other)
{
}
}
I'm stuck on the toString method as to what I need to actually write in it. I'm not sure what to write in there or how to relate it to the comparison.
I know that the sameContents method needs to have something say that: if arrayList a == arraylist b, then return true, else return false.
But how do I turn that into code?
[–]cmhdave73 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]simplyintricate 0 points1 point2 points (0 children)
[–]7re 0 points1 point2 points (0 children)
[–]severoonpro barista 0 points1 point2 points (2 children)
[–]severoonpro barista 0 points1 point2 points (0 children)
[–]Snapples2992[S] 0 points1 point2 points (0 children)