public class Point { public static final Point ORIGIN; static { ORIGIN = new Point(0,0); } private int x; private int y; //giving state to the class public Point(int x, int y) { this.x = x; this.y = y; } /* def __init__(self, x = 0, y = 0): self.x = x self.y = y ##attachihng x and y to me. */ /* def __str__(self): return f"({self.x}, {self.y})" */ public String toString() { return String.format("(%s, %s)", x, y); } /* def distance_to(self, other): return math.hypot(self.x - other.x, self.y -other.y) */ public double distanceTo(Point other) { return Math.hypot(x - other.x, this.y - other.y); } /* def reflection_across_x(self): return Point(self.x, -self.y) */ public Point reflectionAcrossX() { return new Point(x, -y); } public double distanceToOrigin() { return distanceTo(Point.ORIGIN); } /* def reflection_across_y(self): return Point(-self.x, self.y) */ public static void main(String[] args) { Point p = new Point(3,4); System.out.println(p); Point q = new Point(0,0); System.out.println(p.distanceTo(q)); System.out.println(q.distanceTo(p)); System.out.println(p.reflectionAcrossX()); System.out.println(Point.ORIGIN); //System.out.println(x);//don't use naked variables in main! } /* def main(): p = Point(3,4) print(p) q = Point() print(p.distance_to(q)) print(q.distance_to(p)) print(p.reflection_across_x()) main()*/ }