public class Calculus { public static double integrate(double lowerBound, double upperBound, int numRec) { double area = 0.0; double base = (upperBound - lowerBound) / numRec; for(double midpoint = base / 2 + lowerBound; midpoint < upperBound; midpoint += base) { area += base * function(midpoint); } return area; } private static double function(double x) { return x * x; } }