Hi, I am trying to compare two objects, but it is not working correctly. Please help.

/**
 * Compares theObject with <CODE>this</CODE> object for 
 * equivalence. Do not concern yourself with runtime
 * efficiency.
 * @param theObject to be compared with this object
 * @return true if theObject is equivalent to this
 * object.
 */
@Override public  
boolean equals( Object theObject ){
	if (theObject == null) return false;
	if(!(theObject instanceof BoundedBag)) return false;
	if (this == theObject) return true;
	
	BoundedBag obj = (BoundedBag) theObject;

	if( this.size() != obj.size() ) return false;
	
	// Fill in the remainder of the code.
	
	BoundedBag extra = (BoundedBag)thisObject;
	if(thisObject.equals (theObject))
		return true;
	else
		return false;		
}

Help us out a little. What do you expect to see, and what are you seeing instead?

Stating your problem clearly won't just help me and others to solve it, it might actually lead you to a solution.

I need to implement "equals" then throughly test it using JUnit. Two BoundedBags are equivalent if their elements are the same regardless of order. For example, true is returned from each of the following

{1,2,3}.equals ({3,1,2} )
{1,1,1,3}.equals( {1,3,1,1} )
but {1,1,1,3}.equals( {1,1,3} ) returns false.

I am getting an error from lines 2 and below. It is saying that thisObject can not be resolved to a variable.

I meant line 21 and below

Where do you declare it?

401 with Hedlund?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.