1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need Help proving equality with boolean

Discussion in 'Java' started by Maniacmike3128, Apr 8, 2011.

  1. Maniacmike3128

    Maniacmike3128 New Member

    Joined:
    Apr 8, 2011
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  2. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    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
    }
     

Share This Page