/* The Point class represents a point in two dimensional space */ public class Point { private int x; // The x coordinate of the point private int y; // The y coordinate of the point // Creates a new point with the passed coordinates public Point(int x, int y) { this.x = x; this.y = y; } // post: returns the x coordinate of this point public getX() { return this.x; } // post: returns the y coordinate of this point public getY() { return this.y; } // pre : x >= 0, y >= 0 (throws IllegalArgumentException otherwise) // post: sets the point coordinates to the passed x and y public void setLocation(int x, int y) { if (x < 0 || y < 0) { throw new IllegalArgumentException(); } this.x = x; this.y = y; } // pre : other != null // post: returns the distance between this and other // on the cartesian plane public double distance(Point other) { return Math.sqrt( Math.pow(this.x - other.x, 2) + Math.pow(this.y - other.x, 2)); } // post: returns a string representation of this, in the form // (x, y) public String toString() { return "(" + this.x + ", " + this.y + ")"; } }