/*
  Suppose two line segments intersect. The two end-points for the first line
  segment are (x1, y1) and (x2, y2) and for the second line segment are
  (x3, y3) and (x4, y4). Write a program that prompts the user to enter these
  four endpoints and displays the intersecting point. As discussed in
  Programming Exercise 3.25, the intersecting point can be found by solving
  a linear equation. Use the LinearEquation class in Programming Exercise
  9.11 to solve this equation.
*/

import java.util.Scanner;

public class E9_12 {
  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    System.out.print("Enter x1, y1, x2, y2, x3, y3, x4, y4: ");
    double[][] points = new double[4][2];
    for (int i = 0; i < points.length; i++) {
      points[i][0] = input.nextDouble();
      points[i][1] = input.nextDouble();
    }

    double a = points[0][1] - points[1][1];
    double b = -1 * (points[0][0] - points[1][0]);
    double c = points[2][1] - points[3][1];
    double d = -1 * (points[2][0] - points[3][0]);
    double e = a * points[0][0] - (points[0][0] - points[1][0]) * points[0][1];
    double f = c * points[2][0] - (points[2][0] - points[3][0]) * points[2][1];

    LinearEquation lin = new LinearEquation(a, b, c, d, e, f);

    if (!lin.isSolvable()) {
      System.out.println("The two lines are parallel");
    } else {
      System.out.println("x: " + lin.getX() + " y: " + lin.getY());
    }
  }

  private static class LinearEquation {
    private double a, b, c, d, e, f;

    LinearEquation(double a, double b, double c, double d, double e, double f) {
      this.a = a;
      this.b = b;
      this.c = c;
      this.d = d;
      this.e = e;
      this.f = f;
    }

    // getters
    double getA() {
      return a;
    }

    double getB() {
      return b;
    }

    double getC() {
      return c;
    }

    double getD() {
      return d;
    }

    double getE() {
      return e;
    }

    double getF() {
      return f;
    }

    // instance methods
    boolean isSolvable() {
      return getA() * getD() - getB() * getC() != 0;
    }

    double getX() {
      return (getE() * getD() - getB() * getF()) /
             (getA() * getD() - getB() * getC());
    }

    double getY() {
      return (getA() * getF() - getE() * getC()) /
             (getA() * getD() - getB() * getC());
    }
  }
}

@@ -1448,925 +1448,7 @@
 %0A  %7D
-%0A%0A  private static class LinearEquation %7B%0A    private double a, b, c, d, e, f;%0A%0A    LinearEquation(double a, double b, double c, double d, double e, double f) %7B%0A      this.a = a;%0A      this.b = b;%0A      this.c = c;%0A      this.d = d;%0A      this.e = e;%0A      this.f = f;%0A    %7D%0A%0A    // getters%0A    double getA() %7B%0A      return a;%0A    %7D%0A%0A    double getB() %7B%0A      return b;%0A    %7D%0A%0A    double getC() %7B%0A      return c;%0A    %7D%0A%0A    double getD() %7B%0A      return d;%0A    %7D%0A%0A    double getE() %7B%0A      return e;%0A    %7D%0A%0A    double getF() %7B%0A      return f;%0A    %7D%0A%0A    // instance methods%0A    boolean isSolvable() %7B%0A      return getA() * getD() - getB() * getC() != 0;%0A    %7D%0A%0A    double getX() %7B%0A      return (getE() * getD() - getB() * getF()) /%0A             (getA() * getD() - getB() * getC());%0A    %7D%0A%0A    double getY() %7B%0A      return (getA() * getF() - getE() * getC()) /%0A             (getA() * getD() - getB() * getC());%0A    %7D%0A  %7D
 %0A%7D%0A

Use external LinearEquation class