Listing 4. The Integration Class: The AbstractClass shown in Figure 6.
public abstract class Integration
	{
	private double a; // the lower limit of the integration
	private double b; // the upper limit of the integration
	private int n; // the number of points for the integration

	public Integration()
		{
		setA(0);
		setB(1);
		setN(10);
		}

	public Integration(double a,double b,int n)
		{
		setA(a);
		setB(b);
		setN(n);
		}

	public double integrate()
		{
		int n = getN();
		if(!isEven(n) && this instanceof SimpsonsRule)
			setN(++n);
		double[] endpoints = getEndpoints();
		double h = calcH(endpoints[0],endpoints[1],n);
		double area = calcArea(n,h);
		return area;
		}

	protected double getA()
		{
		return a;
		}

	protected void setA(double a)
		{
		this.a = a;
		}

	protected double getB()
		{
		return b;
		}

	protected void setB(double b)
		{
		this.b = b;
		}

	protected int getN()
		{
		return n;
		}

	protected void setN(int n)
		{
		this.n = n;
		}

	protected double[] getEndpoints()
		{
		double[] endpoints =
			{
			getA(),
			getB(),
			};
		return endpoints;
		}

	protected double calcH(double a,double b,int n)
		{
		return (a + b) / (double)n;
		}

	protected abstract double calcArea(int n,double h);

	protected double calcXi(int i,double h)
		{
		return getA() + i * h;
		}

	protected double calcFunction(double x)
		{
		return Math.sin(x);
		}

	protected boolean isEven(int n)
		{
		return true;
		}
	}

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.