// This file defines a new class of objects named Point. // Today's version uses the this keyword and has a toString method. public class Point { // The following contents exist inside each Point object. private int x; // Each Point has an x and y that can be private int y; // seen by all of the methods below. public Point() { //x = 0; //y = 0; this(0, 0); // calls the (x, y) constructor } // Constructs a new Point object at the given coordinates. public Point(int x, int y) { this.x = x; this.y = y; } // Returns this Point's x coordinate. public int getX() { return x; } // Returns this Point's y coordinate. public int getY() { return y; } // Shifts the point's position by the given amounts. public void translate(int dx, int dy) { setLocation(x + dx, y + dy); // x += dx; // y += dy; } // Computes the distance between this point and the given other point. public double distance(Point otherPoint) { int dx = x - otherPoint.x; int dy = y - otherPoint.y; return Math.sqrt(dx * dx + dy * dy); } // Computes the distance between this point and the origin, (0, 0). public double distanceFromOrigin() { return Math.sqrt(x * x + y * y); // return distance(new Point(0, 0)); } // Sets the x and y coordinates of this point. public void setLocation(int x, int y) { this.x = x; this.y = y; } // Returns a string representation of this Point. public String toString() { return ( "(" + x + ", " + y + ")" ); } }