<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">// modified version of http://homepage.cs.uiowa.edu/~sriram/21/spring07/code/Point.java

import java.util.*;

interface Proximity {
  // is point 'p' within distance 'd' of the implementor?
  public boolean withinRadius(Point p, double d);
}// Proximity

// A class to represent points in the Euclidean plane

public class Point implements Proximity {

 public double x;
 public double y;
 
 public Point(double newX, double newY) 
 {
  x = newX;
  y = newY;
 }


 // A constructor that constructs a randomly generated
 // point both of whose coordinates are the range 0 through d,
 // where d is a given integer parameter. Since each coordinate
 // is generated uniformly at random in the range 0 through d,
 // the result is a point that is dropped uniformly at random
 // in a d by d square
 public Point (int d)
 {
  // Random is a class in java.util
  Random rand = new Random();

  //nextDouble(), a method in the Random class
  //returns a random double in the range 0 through 1
  x = d*rand.nextFloat();
  y = d*rand.nextFloat();
 }

 public void prtPoint()
 {
  System.out.println("x = " + x + " y = " + y);
 }


 public String toString()
 {
  return "x = " + x + " y = " + y;
 }


 
 // Computes the Euclidean distance between this PointComp and the
 // given PointComp newP
 private double distance(Point newP)
 {
  // sqrt is a static method defined in the java.lang.Math class
  // It returns a double. 
  return Math.sqrt((x - newP.x)*(x - newP.x) + (y - newP.y)*(y -  newP.y));
 } 
 
 public boolean withinRadius(Point p2, double radius) {
   double d = this.distance(p2);
   
   if(d&lt;=radius) {
     //System.out.println("close: " + d);
     return true;
   }
   else {
     System.out.println("far: " + d);
     return false;
   }
   
 }// withinRadius
 
 
 // main()
 public static void main(String[] args) {
   
   Point p1 = new Point(0,0);
   
   p1.prtPoint();
   
   for(int i=0;i&lt;10;i++) {
     Point p = new Point(100);
     
     if(!p.withinRadius(p1,100)) {
       p.prtPoint();
     }
     
   }// next
   
   
 }// main()
 
}// Point
 
</pre></body></html>