title: Point2D equals within threshold
body: <p>I have to write a <code>Point2D</code> class for an assignment and so far I have been able to write the code for all the necessary methods except the <code>equals()</code> methods.</p>
  
  <p>I'm having trouble figuring how to write the code for it. The <code>equals</code> method is supposed to detect points that represent the same location, <strong>within a distance threshold</strong>.</p>
  
  <p>Here is the code which I have so far:</p>
  
  <pre><code>public class Point2D {
  
      final private double x;
      final private double y;
  
      /**
       * Constructor to initialize coordinates
       * 
       * @param x x value
       * @param y y value
       */
      public Point2D(double x, double y) {
          this.x = x;
          this.y = y;
      }
  
      /**
       * Get the x coordinate
       * 
       * @return x coordinate
       */
      public double getX() {
          return x;
      }
  
      /**
       * Get the y coordinate
       * 
       * @return y coordinate
       */
      public double getY() {
          return y;
      }
  
      /**
       * Gets a String representation
       * of the coordinate in the form
       * "(x, y)" (each with three decimal
       * places of precision)
       * 
       * @return "(x, y)"
       */
      @Override
      public String toString() {
          return "(" + String.format("%.3f", x) + "," + String.format(" %.3f", y) + ")"; 
      }
  
      /**
       * Returns true if provided another
       * point that is at the same (x,y)
       * location (that is, the distance
       * is "close enough" according to
       * Shape2D)
       * 
       * @param o another object
       * @return true if the other object is a point and the same location (within threshold)
       */
      @Override
      public boolean equals(Object o) {
  
      }
  
      /**
       * Method to compute the Euclidean/L2
       * distance between two points in 2D
       * space
       * 
       * @param p1 point 1
       * @param p2 point 2
       * @return straightline distance between p1 and p2
       */
      public static double distance(Point2D p1, Point2D p2) {
           return Math.sqrt((p2.x - p1.x) * (p2.x - p1.x) + (p2.y - p1.y) * (p2.y - p1.y)); 
      }
  
      /**
       * Method to compute the Euclidean
       * distance between this point
       * and a supplied point
       * 
       * @param p input point
       * @return straightline distance between this point and p
       */
      public double distanceTo(Point2D p) {
          return Math.sqrt((p.x - x) * (p.x - x) + (p.y - y) * (p.y - y)); 
      }
  }
  </code></pre>