// Helene Martin, CSE 142 // Blueprint for creating objects of type Point // Final version is encapsulated -- clients can't directly access x and y public class Point { private int x; private int y; // builds a Point at given x and y coordinates public Point(int x, int y) { this.x = x; // many Java developers use this notation this.y = y; // in the constructor } // builds a Point at (0, 0) public Point() { this(0, 0); // call another constructor using this } // returns x coordinate public int getX() { return x; } // returns y coordinate public int getY() { return y; } // sets x coordinate public void setX(int x) { this.x = x; } // sets y coordinate public void setY(int y) { this.y = y; } // returns distance between this Point and an other Point public double distance(Point other) { return Math.sqrt(Math.pow(x - other.x, 2) + Math.pow(y - other.y, 2)); } // returns distance between this Point and the origin public double distanceFromOrigin() { return Math.sqrt(x * x + y * y); } // moves a point by dx, dy public void translate(int dx, int dy) { x = x + dx; y = y + dy; } // returns String representation of this Point public String toString() { return "(" + x + ", " + y + ")"; } }