File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes I need help on an equals method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "I need help on an equals method" Watch "I need help on an equals method" New topic

I need help on an equals method

ryan vines

Joined: Dec 08, 2003
Posts: 8
I am currently working on an object, and writing a class(Trangle) that extends another class of an object. I am stuck on inputting an eaquals method in the ain object method. Basically i dont know where to put it. The code i am supposed to use is
My enitre code is quite long, but here it is.

this is the methed that i need object1.equals(object2) to reference to.
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

I only had a quick look thru the whole code,
but I think you can put it anywhere in Triangle class.
Also, I think the signature of equals method should be
boolean equals(Object a),
and not boolean equals(Triangle t)
to properly over-ride the equals method in Object.
Then in the method you can do a check like
if (!(a instanceof T)) return false
hope that helps!

The future is here. It's just not evenly distributed yet. - William Gibson
Sonny Gill LinkedIn
Tom Blough
Ranch Hand

Joined: Jul 31, 2003
Posts: 263
You might want to consider two triangle objects "equal" if they both have the same color, are both filled or unfilled, and have the same verticies. This is in lieu of only considering objects equal if they are the exact same object.

Tom Blough<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt.<hr></blockquote>
ryan vines

Joined: Dec 08, 2003
Posts: 8
Thanks a lot guys. I fully understand the problem now. And again, i think all of tyou very much.
Ryan Vines
subject: I need help on an equals method
It's not a secret anymore!