### Question:
HCoordinate { public static Coordinate intersection( Coordinate p1, Coordinate p2, Coordinate q1, Coordinate q2) throws NotRepresentableException { double px = p1.y - p2.y; double py = p2.x - p1.x; double pw = p1.x * p2.y - p2.x * p1.y; double qx = q1.y - q2.y; double qy = q2.x - q1.x; double qw = q1.x * q2.y - q2.x * q1.y; double x = py * qw - qy * pw; double y = qx * pw - px * qw; double w = px * qy - qx * py; double xInt = x/w; double yInt = y/w; if ((Double.isNaN(xInt)) || (Double.isInfinite(xInt) || Double.isNaN(yInt)) || (Double.isInfinite(yInt))) { throw new NotRepresentableException(); } return new Coordinate(xInt, yInt); } HCoordinate();  HCoordinate(double x, double y, double w);  HCoordinate(double x, double y);  HCoordinate(Coordinate p);  HCoordinate(HCoordinate p1, HCoordinate p2);  HCoordinate(Coordinate p1, Coordinate p2);  HCoordinate(Coordinate p1, Coordinate p2, Coordinate q1, Coordinate q2); static Coordinate intersection(
      Coordinate p1, Coordinate p2,
      Coordinate q1, Coordinate q2); double getX(); double getY(); Coordinate getCoordinate(); public double x; public double y; public double w; }### Answer:
@Test public void testIntersection() throws NotRepresentableException { Coordinate p1 = new Coordinate(1,1); Coordinate p2 = new Coordinate(6,3); Coordinate q1 = new Coordinate(1,5); Coordinate q2 = new Coordinate(4,2); double expX = 27.0/7.0; double expY = 15.0/7.0; Coordinate c = HCoordinate.intersection(p1, p2, q1, q2); assertEquals(expX, c.x, 0.000000001); assertEquals(expY, c.y, 0.000000001); HCoordinate hc = new HCoordinate(p1, p2, q1, q2); Coordinate hcc = hc.getCoordinate(); assertEquals(expX, hcc.x, 0.000000001); assertEquals(expY, hcc.y, 0.000000001); }
@Test public void testIntersectionOutsideOfBbox() throws NotRepresentableException { Coordinate p1 = new Coordinate(1,1); Coordinate p2 = new Coordinate(6,3); Coordinate q1 = new Coordinate(1,5); Coordinate q2 = new Coordinate(2,4); Coordinate c = HCoordinate.intersection(p1, p2, q1, q2); assertEquals(27.0/7.0, c.x, 0.000000001); assertEquals(15.0/7.0, c.y, 0.000000001); }
@Test(expected = NotRepresentableException.class) public void testNoIntersection() throws NotRepresentableException { Coordinate p1 = new Coordinate(1,2); Coordinate p2 = new Coordinate(6,2); Coordinate q1 = new Coordinate(1,1); Coordinate q2 = new Coordinate(2,1); HCoordinate.intersection(p1, p2, q1, q2); }