// Third version of Point class for storing an ordered pair (x, y). This // version is encapsulated and has fields, one constructor, additional methods // to compute the distance from another point, and a toString method. public class Point { private int x; private int y; // constructs a point with given x and y coordinates public Point(int initialX, int initialY) { x = initialX; y = initialY; } // translates this points's coordinates by the given delta-x and delta-y public void translate(int dx, int dy) { x = x + dx; y = y + dy; } // returns the distance from this point to the origin (0, 0) public double distanceFromOrigin() { return Math.sqrt(x * x + y * y); } // returns a text representation of the point: (x, y) public String toString() { return "(" + x + ", " + y + ")"; } }