import java.util.Scanner;

class GeometryTest {
    private static Scanner scan = new Scanner(System.in);
    
   private static void doSlope(double x1, double y1, double x2, double y2) {
       GPoint p1 = new GPoint(x1, y1), p2 = new GPoint(x2, y2);
       GLine line = new GLine(p1, p2);
       System.out.print("The slope of the line between " + p1 + " and " + p2 + " is ");
       double m = line.getSlope();
       double b = line.getIntercept();
       if (m == Double.MAX_VALUE) {
           System.out.print("undefined");
       } else {
           System.out.printf("%.2f", m);
       }
       line = new GLine(x1, y1, x2, y2);
       m = line.getSlope();
       if (m == Double.MAX_VALUE) {
           System.out.print(" (undefined)");
       } else {
           System.out.print(" (");
           System.out.printf("%.2f", m);
           System.out.print(") ");
       }
       line = new GLine(m, b);
       m = line.getSlope();
       if (m == Double.MAX_VALUE) {
           System.out.println(" [undefined]");
       } else {
           System.out.print(" [");
           System.out.printf("%.2f", m);
           System.out.println("] ");
       }
   }
   
   private static void doIntercept(double x1, double y1, double x2, double y2) {
       GPoint p1 = new GPoint(x1, y1), p2 = new GPoint(x2, y2);
       GLine line = new GLine(p1, p2);
       double b = line.getIntercept();
       if (line.getSlope() == Double.MAX_VALUE) {
           System.out.print("The x-");
       } else {
           System.out.print("The y-");
       }
       System.out.print("intercept of the line between " + p1 + " and " + p2 + " is ");
       System.out.printf("%.2f%n", b);
   }
   
   private static void doIntersection(double x1, double y1, double x2, double y2,
                                      double x3, double y3, double x4, double y4) {
       GPoint p1 = new GPoint(x1, y1), p2 = new GPoint(x2, y2),
              p3 = new GPoint(x3, y3), p4 = new GPoint(x4, y4);
       GLine line1 = new GLine(p1, p2),
             line2 = new GLine(p3, p4);
       System.out.print("The intersection of " + line1 + " and " + line2);
       GPoint inter = line1.intersection(line2);
       if (inter.x == Double.MAX_VALUE) {
           System.out.println(" does not exist");
        } else {
            System.out.println(" is " + line1.intersection(line2));
        }
   }
   
   private static void doEquation(double x1, double y1, double x2, double y2) {
       GPoint p1 = new GPoint(x1, y1), p2 = new GPoint(x2, y2);
       GLine line = new GLine(p1, p2);
       System.out.println("The equation of the line between " + p1 + " and " + p2 + " is " + line);
   }
   
   public static void main(String[] args) {
       for (;;) {  //  Infinite loop
           double p_x1, p_y1, p_x2, p_y2, p_x3, p_y3, p_x4, p_y4;
           System.out.print("Enter the point coordinates x1, y1, x2, y2: ");
           p_x1 = scan.nextDouble();
           p_y1 = scan.nextDouble();
           p_x2 = scan.nextDouble();
           p_y2 = scan.nextDouble();
           doSlope(p_x1, p_y1, p_x2, p_y2);
           doIntercept(p_x1, p_y1, p_x2, p_y2);
           doEquation(p_x1, p_y1, p_x2, p_y2);
           System.out.print("Enter the point coordinates x3, y3, x4, y4: ");
           p_x3 = scan.nextDouble();
           p_y3 = scan.nextDouble();
           p_x4 = scan.nextDouble();
           p_y4 = scan.nextDouble();
           doIntersection(p_x1, p_y1, p_x2, p_y2, p_x3, p_y3, p_x4, p_y4);
           System.out.println("-----------------");
       }
   }
}