title: Given four coordinates check whether it forms a square
body: <p>So I am trying to write a simple method which takes in set of four coordinates and decide whether they form a square or not.My approach is start with a point and calculate the distance between the other three points and the base point.From this we can get the two sides which have same value and the one which is a diagonal.Then I use Pythagoras theorem to find if the sides square is equal to the diagonal.If it is the isSquare method return true else false.The thing I want to find out is there some cases I might be missing out on or if something is wrong with the approach.Thanks for the all the help.</p>
  
  <pre><code>public class CoordinatesSquare {
  
  public static boolean isSquare(List&lt;Point&gt; listPoints) {
      if (listPoints != null &amp;&amp; listPoints.size() == 4) {
          int distance1 = distance(listPoints.get(0), listPoints.get(1));
          int distance2 = distance(listPoints.get(0), listPoints.get(2));
          int distance3 = distance(listPoints.get(0), listPoints.get(3));
  
          if (distance1 == distance2) {
              // checking if the sides are equal to the diagonal
              if (distance3 == distance1 + distance2) {
                  return true;
              }
  
          } else if (distance1 == distance3) {
              // checking if the sides are equal to the diagonal
              if (distance2 == distance1 + distance3) {
                  return true;
              }
  
          }
      }
      return false;
  }
  
  private static int distance(Point point, Point point2) {
                //(x2-x1)^2+(y2-y1)^2
      return (int) (Math.pow(point2.x - point.x, 2) + (Math.pow(point2.y
              - point.y, 2)));
  }
  
  public static void main(String args[]) {
      List&lt;Point&gt; pointz = new ArrayList&lt;Point&gt;();
      pointz.add(new Point(2, 2));
      pointz.add(new Point(2, 4));
      pointz.add(new Point(4, 2));
      pointz.add(new Point(4, 4));
      System.out.println(CoordinatesSquare.isSquare(pointz));
  }
  }
  
  
  //Point Class
   public class Point {
  Integer x;
  Integer y;
  boolean isVisited;
  
  public Point(Integer x, Integer y) {
      this.x = x;
      this.y = y;
  }
  
  @Override
  public boolean equals(Object obj) {
      if(obj!=null &amp;&amp; obj.getClass().equals(this.getClass())){
          return ((Point) obj).x.equals(this.x)&amp;&amp;((Point) obj).y.equals(this.y);
      }
      return false;
  
  }
  }
  </code></pre>