//======================================================
// 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_xj
{
public double func(double x[]) 
{
//çözümü istenen fonksiyon	
double ff;
double pi=Math.PI;
//x[0] fi 0-2pi arası değişiyor
//x[1] teta 0-pi/2 arası değişiyor.
if(x[0]>=0&&x[0]<=pi)
  {if(x[1]>=0&&x[1]<=pi/2) return 1;}
else
  return 0;
return 0;   
}
}


class integ_monte_carlo3
{

public static double monte_carlo(f_xj ff,long n)
{       //monte - carlo integral 3D (volume) küresel koordinat sistemi
	    double x[]=new double[2];
	    double a[]=new double [2];
	    double b[]=new double[2];
	    a[0]=0;
	    b[0]=2.0*Math.PI;
	    a[1]=0;
	    b[1]=Math.PI/2.0;
	    double h=1.0;
	    double sum=0;
	    for(int j=0;j<2;j++) {h*=(b[j]-a[j]);}
	    for(int i=0;i<n;i++)
        { for(int j=0;j<2;j++) {x[j]=a[j]+(b[j]-a[j])*Math.random();}
          sum+=ff.func(x); 
        }
        double c=sum/(double)n;
        return c; 
}

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