title: Why do I get a wrong output of equals method?
body: <p>I am writing a code and am following all instructions given to me. All the codes and methods look fine when I run the program but the equal method! Based on the instructions, I am supposed to get false when the tested asks if point (a, b)---(c, d) is equals to (e, f)---(g, h), but I get true. Can anyone give me an idea where I am doing wrong?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>public boolean equals(Object obj) {
         //if (obj instanceof Segment) {
             //Segment other = (Segment) obj;
             //return p1 == other.getP1() &amp;&amp; p2 == other.getP2();
         //}
         //else {
            
             //throw new IllegalArgumentException("undefined");
         //}
        
         if(obj == null)
             return false;
         if(this == obj)
             return true;
         //if(!(obj instanceof Segment))
             //return false;
        
         else if(obj.getClass() != this.getClass())
             return false;
        
             else {
                 Segment S = (Segment)obj;
         if (this.getP1() == S.getP1() &amp;&amp;
                     this.getP2() == S.getP2())
             return true;
        
         else if(this.getP1() != S.getP1() &amp;&amp;
                 this.getP2() != S.getP2()){
             return true;}
        
         return false;
        
             }      
             //else if(obj.getP1() != this.getP1() &amp;&amp;
                 //   obj.getP2() != this.getP2());
         //   return false;
        
    
     }</code></pre>
  </div>
  </div>
  </p>