//======================================================
// Numerical Analysis package in java
// example to show utilisation of integration (integral)
// and differentiation (derivative) functions
// Dr. Turhan Coban
// =====================================================
import java.io.*;


class f1 extends f_x
{
  public double func(double x)
  {
  return x*Math.sqrt(x);
  }
}


class integ_monte_carlo
{

public static double monte_carlo(f_x ff,double a,double b, long n)
{       //Newton-cotes integral 6 points
	    double h=(b-a);
        double sum=0.0;
        double x=0.0;
        double f;
        for(int i=0;i<n;i++)
        { x=a+(b-a)*Math.random();
          sum+=ff.func(x); 
        }
        return (b-a)*sum/(double)n;
}

  public static void main(String args[]) throws IOException
  {
  f1 b1=new f1();
  System.out.println("integral of class         f1 : "+monte_carlo(b1,0.0,1.0,1000000));
}
}
