Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)
-   -   Need Help proving equality with boolean (http://www.go4expert.com/forums/help-proving-equality-boolean-t25484/)

Maniacmike3128 9Apr2011 03:40

Need Help proving equality with boolean
 
Working on a school project and our professor has supplied us with three classes. we are to implement a fourth class called "Sprite" using a specified UML.
The UML part that I'm having trouble with looks like this:

+equals(other : Sprite) : boolean

how do i write this code? I know it needs to return a boolean, and I'm supposed to check if the sprite i have in my class equals the other sprite. I'm lost.

virxen 9Apr2011 03:53

Re: Need Help proving equality with boolean
 
Quote:

+equals(other : Sprite) : boolean
Code:

public boolean equals(Sprite other){
  if (this==other)
      return true;//its the same object
  if (all properties values of this object==all properties values of other)
      return true;//equal objects by value
 return false;//completely different objects
}



All times are GMT +5.5. The time now is 16:45.