A line in the plane can be specified in various ways:
by giving a point (x, y) and a slope m by giving two points (x1, y1), (x2, y2) as an equation in slope-intercept form y = mx +
b as an equation x = a if the line is vertical
Implement a class Line with four constructors, corresponding to the four cases above. Implement methods
boolean intersects(Line other)
boolean equals(Line other)
boolean isParallel(Line other)
Use the following class as your tester class:
public class LineTester
{
public static void main(String[] args)
{
Line line1 = new Line(1, 1, 0.5);
Line line2 = new Line(1, 1, 1, 2);
Line line3 = new Line(0.5, -1);
Line line4 = new Line(1);
System.out.println(line1.equals(line2));
System.out.println("Expected: false");
System.out.println(line2.equals(line4));
System.out.println("Expected: true");
System.out.println(line1.intersects(line2));
System.out.println("Expected: true");
System.out.println(line1.intersects(line3));
System.out.println("Expected: false");
System.out.println(line1.isParallel(line3));
System.out.println("Expected: true");
System.out.println(line2.isParallel(line4));
System.out.println("Expected: true");
System.out.println(line1.isParallel(line2));
System.out.println("Expected: false");
}
}