class GaussQuadratur6 {

	// Integrationsintervall [a, b]
	static final double a = 0.0;
	static final double b = Math.PI;

	// Ordnung, Stützstellen und Gewichte der Gauss-Quadratur
	static final int n = 6;
	static final double grid[]   = { 0.2386191861, -0.2386191861, 0.6612093865, -0.6612093865, 0.9324695142, -0.9324695142 };
	static final double weight[] = { 0.4679139346,  0.4679139346, 0.3607615730,  0.3607615730, 0.1713244924,  0.1713244924  };


	// definiert die zu integrierende Funktion f
	static double f(double x)
	{
		if( x==0.0) return 1.0;
		return (1+(Math.cos(x)*Math.cos(x)*Math.cos(x)*Math.cos(x) )/2); /// x ;
	}


	// implementiert die Gauss-Quadratur
	static double gauss(double a, double b, int n)
	{
		double sum=0.0;
		for (int j=0; j<n ; j++)
		{
			sum += weight[j] * f( ((b-a)*grid[j]+b+a)/2.0 );
		}
		return sum*(b-a)/2.0;
	}


	public static void main(String[] args)
	{
		double integral = gauss(a, b, n);

		System.out.println("\n\n");
		System.out.println(" ** Gauss-Quadratur 6. Ordnung ** " + "\n");
		System.out.print  ("    Integral( f(x), x=a..b ) = " + integral);
		System.out.println("\n\n");
	}
}