Lecture Notes 07 August 2013 class Point { // attributes private double x; private double y; // 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 distance (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; } 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); } } class Line { // attributes private Point p1; private Point p2; // default constructor public Line() { p1 = new Point (0, 0); p2 = new Point (1, 1); } // non-default constructors public Line (double x1, double y1, double x2, double y2) { p1 = new Point (x1, y1); p2 = new Point (x2, y2); } public Line (Point p, Point q) { p1 = new Point (p.getX(), p.getY()); p2 = new Point (q.getX(), q.getY()); } public boolean isParallelY() { double delta = 1.0e-18; return (Math.abs(p1.getX() - p2.getX()) < delta); } public double slope () { double inf = Double.POSITIVE_INFINITY; if (isParallelY()) return inf; return ((p2.getY() - p1.getY()) / (p2.getX() - p1.getX())); } } public class Geometry { public static void main (String[] args) { Point p = new Point (); Point q = new Point (3, 4); System.out.println (p.distance(q)); System.out.println (q.distance(p)); System.out.println (p); System.out.println (q); } }