• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I need help on an equals method

 
ryan vines
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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!
 
Tom Blough
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
ryan vines
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot guys. I fully understand the problem now. And again, i think all of tyou very much.
Ryan Vines
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic