Lecture Notes on 6 Aug 2014 class Point { // attributes private double x; private double y; // methods // default constructor public Point () { x = 0.0; y = 0.0; } //non-default constructor public Point (double x, double y) { this.x = x; this.y = y; } // accessors public double getX () { return this.x; } public double getY () { return this.y; } // mutators public void setX (double x) { this.x = x; } public void setY (double y) { this.y = y; } // other methods // distance to another Point public double dist (Point p) { return Math.sqrt ((this.x - p.x) * (this.x - p.x) + (this.y - p.y) * (this.y - p.y)); } // string representation of a Point public String toString () { String s = "(" + x + ", " + y + ")"; return s; } // check equality of two points public boolean equals (Point p) { double delta = 1.0e-18; return (Math.abs(this.x - p.x) < delta) && (Math.abs(this.y - p.y) < delta); } } public class Geometry { public static void main (String[] args) { // create a default Point object Point p = new Point(); // set its coordinates p.setX(1); p.setY(2); // create a user defined Point object Point q = new Point (5, 8); // print out the coordinates of that Point System.out.println (q); // find the distance between two points System.out.println (p.dist(q)); System.out.println (q.dist(p)); } }