// Second version of Point class for storing an ordered pair (x, y). This // version is encapsulated and has fields, two constructors, and additional // methods to set the location and compute the distance between two points. public class Point { private int x; private int y; // constructs a point that corresponds to the origin (0, 0) public Point() { x = 0; y = 0; } // 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 += dx; y += dy; } // returns the distance from this point to the origin (0, 0) public double distanceFromOrigin() { return Math.sqrt(x * x + y * y); } // returns this point's x coordinate public int getX() { return x; } // returns this point's y coordinate public int getY() { return y; } // sets this point's location to the given x and y coordinates public void setLocation(int newX, int newY) { x = newX; y = newY; } // returns the distance from this point to the given point public double distance(Point other) { int dx = other.x - x; int dy = other.y - y; return Math.sqrt(dx * dx + dy * dy); } }