/* The Line class represents a line in two dimensional space */ public class Line { // Ideas we had for fields: // p1 p2 // p1 slope length // point angle // x1 x2 y1 y2 // // In the end we chose p1 and p2, since we already // have good point implementations. This also gives // the fastest access for the methods we've decided // to write. private Point p1; private Point p2; // Creates a new line, from p1 to p2. public Line(Point p1, Point p2) { this.p1 = p1; this.p2 = p2; } // Creates a new line, that is an exact copy of other. public Line(Line other) { this(other.p1, other.p2); } // post: returns starting point public Point getPoint1() { return p1; } // post: returns ending point public Point getPoint2() { return p2; } // returns the length of this. public int length() { return p1.distance(p2); } // post: returns a string representation // of the line, in the form // "start_point to end_point" public String toString() { return p1 + " to " + p2; } }