import java.io.*;
import javax.swing.*;
import javax.tools.*;
import java.util.*;
import java.lang.Integer;
import java.awt.*;
import java.awt.event.*;
import java.awt.font.*;
import java.awt.geom.*;
import java.awt.image.*;
import javax.swing.*;
import java.util.Locale;
import java.text.*;
import java.util.*;
import javax.swing.table.*;

class ce2 
{ 	 public double r;	
	 public ce2(double x1,double x2) 
	 {     
        f2D ff=new f2D();
        r= bisection(ff,x1,x2);
     }

public static double bisection(f_x f,double a,double b)
{
//bisection root finding method
double test;
double p=0;
double es,ea;
double fa,fp;
int maxit=500,iter=0;
es=0.0000001;
ea=1.1*es;
while((ea>es)&&(iter<maxit))
{
    p=(a+b)/2.0;
    iter++;
    if((a+b)!=0)
        { ea=Math.abs((b-a)/(a+b))*100;}
    fa= f.func(a);
    fp= f.func(p);
    test= fa*fp;
    if(test==0.0)      ea=0;
    else if(test<0.0)  b=p;
    else              {a=p;}
} 
if(iter>=maxit) JOptionPane.showMessageDialog(null,"Maximum number of iteration is exceded \n"+
   " result might not be valid ","MAXIMUM ITERATION WARNING",JOptionPane.WARNING_MESSAGE); 
return p;
}
}
