// TrapezoidAbs.java // Use abstract methods to use the trapezoid rule to approximate the // integral of an arbitrary function. // Use the trapezoid rule to approximate the integral of f from A to B // using N trapezoids. abstract class Trapezoid { public abstract double f(double x); public double ComputeTrapezoid(double A, double B, int N) { if ((B < A) || N < 2) return 0.0; double Delta = (B-A)/N; double Sum = (f(B)+f(A))/2; for (int i=1; i