import java.awt.*; public class Point2 { // data fields private int x; private int y; // constructor -- special method that initializes an object public Point() { // call the Point(x, y) constructor this(0, 0); } public Point(int x, int y) { this.x = x; this.y = y; } public int getX() { return this.x; } public int getY() { return this.y; } public void setLocation(int x, int y) { this.x = x; this.y = y; } // "object content" -- relative to the object it's called upon public void translate(int dx, int dy) { // 'this' -- the object that the method is being called upon this.x += dx; this.y += dy; } // tells me the distance between 'this' point and the given other point p2 public double distance(Point p2) { // this --> p1 // p2 int dx = this.x - p2.x; int dy = this.y - p2.y; double dist = Math.sqrt(dx*dx + dy*dy); return dist; } // public boolean equals(Point otherPoint) { // the parameter could be anything, so we write 'Object' as its type public boolean equals(Object o) { if (o instanceof Point) { Point o2 = (Point) o; // type-cast; 'converts' o into a Point return this.x == o2.x && this.y == o2.y; } else { return false; } } // Returns a text representation of this Point object. // e.g. "(5, -2)" public String toString() { return "(" + this.x + ", " + this.y + ")"; } public void draw(Graphics g) { g.fillOval(this.x, this.y, 2, 2); g.drawString(this.toString(), this.x, this.y); } }