import java.util.Scanner; /*******************************************************************************/ /** A program to compute integrals * * Original version by Duncan Buell for CSCE 145, Spring 2008 * Local modifications by XXXXX XXXXXXX * */ public class Main { public static void main (String[] args) { final int INCSEGMENTS = 10; final int MINSEGMENTS = 10; // final int MAXSEGMENTS = 100000000; // final int MAXSEGMENTS = 1000; final int MAXSEGMENTS = 10; double leftEnd,rightEnd,integral; Scanner console = new Scanner(System.in); ComputeIntegral theIntegral = new ComputeIntegral(); /*******************************************************************************/ /** * First we get the left and right endpoints and check that they are valid **/ System.out.printf("Left Endpoint?%n"); leftEnd = console.nextDouble(); System.out.printf("Left Endpoint is %f%n",leftEnd); System.out.printf("Right Endpoint?%n"); rightEnd = console.nextDouble(); System.out.printf("Right Endpoint is %f%n",rightEnd); if(leftEnd > rightEnd) { System.out.printf("ERROR: left endpoint not lessequal right endpoint%n"); System.exit(1); } /*******************************************************************************/ /** * Compute the area by using trapezoids **/ System.out.printf("%nCompute the integral using trapezoids%n"); integral = 0.0; for(int n = MINSEGMENTS; n <= MAXSEGMENTS; n = INCSEGMENTS*n) { System.out.println("Create the data"); theIntegral.createData(leftEnd,rightEnd,n); System.out.println("Echo the data"); theIntegral.echoData(); System.out.println("Compute the integral"); integral = theIntegral.doIntegralTrapezoids(); System.out.printf("The integral using %13d panel segments is approximately %12.6f%n", n,integral); } System.out.printf("The integral using trapezoids is approximately %12.6f%n",integral); /*******************************************************************************/ /** * We're done **/ System.out.printf("Program terminating normally%n"); } } // public class Main