// More fully object-oriented implementation of the Point class. // // Note that the fields are now private, and we have added // a constructor and methods to get and set the coordinates. // Notice also the toString method has been implemented. public class Point { private int x; private int y; public Point(int newX, int newY) { x = newX; y = newY; } public int getX() { return x; } public int getY() { return y; } public void setCoordinates(int newX, int newY) { x = newX; y = newY; } public double distanceFromOrigin() { return Math.sqrt(x * x + y * y); } public double distanceTo(Point other) { return Math.sqrt(Math.pow(x - other.x, 2) + Math.pow(y - other.y, 2)); } public void translate(int dx, int dy) { x += dx; y += dy; } public String toString() { return "(" + x + ", " + y + ")"; } }