public class Point { //state or instance variable private int x; private int y; //signature: list of types in the argment list public Point(int x, int y) { this.x = x; this.y = y; } //method name overloading. Two methods can have //the same name if their sigs are different. public Point() { this(0,0); } @Override public String toString() { return String.format("(%s, %s)", x, y); } @Override public boolean equals(Object o) { //the species test if( !(o instanceof Point)) { return false; } Point that = (Point) o; return that.x == x && that.y == y; } public int getX() { return x; } public int getY() { return y; } public void setX(int x) { this.x = x; } public void setY(int y) { this.y = y; } public double distanceTo(Point that) { return Math.hypot(x - that.x, y - that.y); } public int taxiCabDistance(Point that) { return abs(x - that.x) + abs(y - that.y); } //poopsmith private int abs(int x) { // ternary operator: P? ifTrue: ifFalse // predicate: boolean valued expression. // P is one of these return x < 0? -x : x; } public static void main(String[] args) { Point p = new Point(3,4); Point origin = new Point(); Point q = new Point(3,4); System.out.println(p); System.out.println(origin); System.out.println(origin.distanceTo(p)); System.out.println(p.distanceTo(origin)); System.out.println(origin.taxiCabDistance(p)); System.out.println(p.taxiCabDistance(origin)); System.out.println(p == q); System.out.println(p.equals(q)); } }