• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

I need help on an equals method

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1211
Mac IntelliJ IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
After some pecan pie, you might want to cleanse your palatte with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic