title: Class equals method is confusing
body: <p>I'm studying object oriented programming in Java at my school and I had to do an exercise to compare Circles.</p>
  <p>I had the Circle Class with these</p>
  <blockquote>
  <p>private int id;</p>
  <p>private String bgColor;</p>
  <p>private String fgColor;</p>
  </blockquote>
  <p>And inside it I had to use the equals method to compare two circles (by using these three attributes): <strong>a circle is equal to other circle if its radius and the bg and fgColor are the same.</strong></p>
  <pre><code>public boolean equals(Object obj) {
      boolean found;
      if (obj == null) {
          found = false;
      }
      if (getClass() != obj.getClass()) {
          found = false;
      }
      final Circle other = (Circle) obj;
      if (Double.doubleToLongBits(this.radius) == Double.doubleToLongBits(other.radius)) {
          //found = false;
          
          if (Objects.equals(this.bgColor, other.bgColor)) {
              //found = false;
              
              if (Objects.equals(this.fgColor, other.fgColor)) {
                  return true;
              }//end if fgColor
              else{
                  found = false;
              }   
          }//end if bgcolor
          else{
              found = false;
          }   
      }//end if radius
      else{
          found = false;
      }   
  
      return found;
  }
  </code></pre>
  <p>But my teacher told me that the code above is &quot;confusing&quot;, but I don't understand why.</p>
  <p>Do you know a better solution?</p>
  <p>My teacher wants that we folow this structure (this case is only comparing one property):</p>
  <pre><code>public boolean equals (Object obj)
  {
        boolean b;
  
        if(obj == null)
        {
                b = false;
        }
        else
        {
                if(this == obj)//same object
                {
                        b = true;
                }
                else
                {
                        if(obj instanceof Book)                   
                        {
                                Book other = (Book) obj; 
                                b = (this.id == other.id); 
                        } 
                        else
                        {
                                b = false;
                        }
                }
        }
  
        return b;
  }
  </code></pre>