// Ayaz Latif // TA: Grace Hopper // CSE142 // This class represents a point in the Cartesian plane (with an x- and y-coordinate). // Second version of Point class for storing an ordered pair (x, y). This // version has fields, a method that changes the state of the object // (translate), and a method that just examines the state of the object // (distanceFromOrigin and distanceTo). public class Point { int x; int y; // 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) { x = x + dx; y = y + dy; } // returns the (double) distance from this point to the origin (0, 0) public double distanceFromOrigin() { double distance = Math.sqrt(x * x + y * y); return distance; } // returns the (double) distance from this point to a second point p2 // Point p2: second point to calculate distance to public double distanceTo(Point p2) { double distance = Math.sqrt(Math.pow(x - p2.x, 2) + Math.pow(y - p2.y, 2)); return distance; } }