public class Point { private int x; // fields private int y; public Point() { this(0, 0); } public Point(int x, int y) { // constructor this.x = x; this.y = y; } public double distance(Point p) { int dx = x - p.x; int dy = y - p.y; return Math.sqrt(dx*dx + dy*dy); } // Returns true if o refers to a Point object with the same x/y // coordinates as this Point; otherwise returns false. public boolean equals(Object o) { if (o != null && getClass() == o.getClass()) { Point p = (Point) o; return p != null && x == p.x && y == p.y; } else { return false; } } public int getX() { return x; } // accessor public int getY() { return y; } public void translate(int dx, int dy) { x += dx; y += dy; // mutator } public String toString() { // for printing return "(" + x + ", " + y + ")"; } }