import javax.swing.JOptionPane;
public class colebrook
{
public static double f(double Re,double eod)
{
// Haaland equation
double f1=-1.8*Math.log10(Math.pow((eod/3.7),1.11)+6.9/Re);
f1=1.0/(f1*f1);
return f1;
}

public static double fx(double X,double Re,double eod)
{
// colebrook equation to solve
// friction factor for turbulent flow 2000 < Re
double xx=2.0*Math.log(eod/3.7+2.51/Re*X)/Math.log(10.0)+X;
return xx;
}

public  static double dfx(double X,double Re,double eod)
{
//derivative of colebrook equation
double xx;
xx = 1+2.0/(eod/3.7+2.51/Re*X)/Math.log(10.0)*2.51/Re;
return  xx;
}

public  static double fcol(double Re,double eod)
{
//solution of the colebrook equation
// by using newton method
if(Re>=2300)
{
double fi=0.01;
double x=1.0/ Math.pow(fi,0.5);
int nmax=50;
double tolerance=1.0e-10;
for(int i=0;i<nmax;i++)
{ double fx1=fx(x,Re,eod);
  x-=fx1/dfx(x,Re,eod);
  if(Math.abs(fx1)<tolerance) return 1.0/(x*x);
}
return 1.0/(x*x);
}
else
return 64.0/Re;
}
	
public static void main(String arg[])
{ double Re=Double.parseDouble(JOptionPane.showInputDialog("Re : "));
  double eod=Double.parseDouble(JOptionPane.showInputDialog("eod : "));
  double f1=f(Re,eod);
  double f2=0.316*Math.pow(Re,-0.25);
  double f=fcol(Re,eod);
  String s="f1 = "+f1+"\n"+"f colebrook = "+f+"f2="+f2+"\n";
  s+="Re ="+Re+"eps/D ="+eod;
  JOptionPane.showMessageDialog(null,s);
}

}