public class Point { private final int x; private final int y; //final means "cannot be reassigned" public Point(int x, int y) // sig is [int, int] { this.x = x; this.y = y; } public Point() // sig is [] { //x = 0; //y = 0; this(0,0); //calls sibling constructor } /* * method name overloading * several methods can have the same name if their * sigs are different. * * You should only use this for closely related methods. */ public double distanceTo(Point other) { return Math.hypot(x - other.x, y - other.y); } @Override public String toString() { return String.format("(%s, %s)", x, y); } @Override public boolean equals(Object o) { if(this == o) { return true; } if(!(o instanceof Point)) { return false; } //o must be a Point! Point that = (Point) o; return x == that.x && y == that.y; } public Point reflectionAcrossX() { return new Point(x, -y); } public Point reflectionAcrossY() { return new Point(-x, y); } public Point reflectionAcrossYequalsX() { return new Point(y, x); } public int getX() { return x; } public int getY() { return y; } public static void main(String[] args) { Point p = new Point(3,4); Point q = new Point(0,0); System.out.println(p.x); System.out.println(p.y); System.out.println(p.distanceTo(q)); System.out.println(p); System.out.println(p.reflectAcrossX()); } }