// This class defines a new type of objects named Point. // Each Point object keeps track of a pair of (x, y) coordinates // and contains methods to perform behavior on that data. // // The contents of the class describe the state and behavior // that EACH point object will have. public class Point { int x; // fields (each object's data) int y; // Describes how each Point object translates its (x, y) location. public void translate(int dx, int dy) { x += dx; y += dy; } // Returns the distance between the current point and the given // parameter p. (We only pass one Point as a parameter, because // the other is the "implicit parameter." public double distance(Point p) { int dx = x - p.x; int dy = y - p.y; return Math.sqrt(dx * dx + dy * dy); } // Computes and returns the distance between the current Point // object and the origin (0, 0). public double distanceFromOrigin() { double distance1 = Math.sqrt(x * x + y * y); return distance1; } // Sets the current Point object's (x, y) coordinates to the given values. public void setLocation(int newX, int newY) { x = newX; y = newY; } }