// Miya Natsuhara // 08-12-2019 // CSE142 // TA: Grace Hopper // This class represents a point in the Cartesian plane (with an x- and y-coordinate). public class Point { private int x; private int y; // Constructs a new point at the given x- and y-coordinates // int x: x-coordinate of newly-constructed Point // int y: y-coordinate of newly-constructed Point public Point(int x, int y) { // if (x >= 0 && y >= 0) { this.x = x; this.y = y; // } } // Constructs a new point at the origin (0, 0) public Point() { this.x = 0; this.y = 0; } // Translates the point by the given dx and dy. // int dx: translation of x-coordinate // int dy: translation of y-coordinate public void translate(int dx, int dy) { // if (x + dx >= 0 && y + dx >= 0) { x += dx; y += dy; // } } // Returns the distance from this point to the origin (0, 0) public double distanceFromOrigin() { return Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)); } // Returns a String representation of this point public String toString() { return "(" + x + ", " + y + ")"; } // Returns the distance between this point and the given point // Point otherPoint: the other point to find distance to public double distanceFrom(Point otherPoint) { double xTerm = Math.pow(x - otherPoint.x, 2); double yTerm = Math.pow(y - otherPoint.y, 2); return Math.sqrt(xTerm + yTerm); } // Returns the x-coordinate of this point public int getX() { return x; } // Returns the y-coordinate of this point public int getY() { return y; } // Sets the point to the given location, specified by the given x- and // y-coordinates // int x: new x-coordinate of the point // int y: new y-coordinate of the point public void setLocation(int x, int y) { // if (x >= 0 && y >= 0) { this.x = x; this.y = y; // } } }