public class Line { // Invariant: p1 and p2 are different points private Point p1, p2; public Line(Point p1, Point p2) throws IllegalArgumentException { if (!p1.equals(p2)) { this.p1 = p1; this.p2 = p2; } else { throw new IllegalArgumentException ( "Points to Line Constructor must be different: " + p1.toString() + "given twice."); } } public Point getP1() { return p1; } public Point getP2() { return p2; } public double slope () throws ArithmeticException { return ((p1.getY() - p2.getY()) / (p1.getX() - p2.getX())); } }