/* This file defines a new class of objects called Point. Each Point object contains two ints named x and y, as well as its own copy of each method written below. */ public class Point { // fields: the data inside of each object int x; int y; // methods: the behavior inside of each object // Each of these methods executes "inside" a particular Point object, // so it knows about and can refer to that object's fields directly by name. // Returns the distance between this Point object and the given Point p2. public double distance(Point p2) { int dx = x - p2.x; int dy = y - p2.y; return Math.sqrt(dx * dx + dy * dy); } // Returns the distance between this Point object and the origin, (0, 0). public double distanceFromOrigin() { Point origin = new Point(); // (0, 0) return distance(origin); } // Changes this Point object's (x, y) location to the given coordinates. public void setLocation(int newX, int newY) { x = newX; y = newY; } // Shifts this Point object's (x, y) location by the given amounts. public void translate(int dx, int dy) { setLocation(x + dx, y + dy); } }