• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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
 
No one can make you feel inferior without your consent - Eleanor Roosevelt. tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic