/**
   There are two bugs in this program.
 */
public class RootApproximator
{
   public RootApproximator(double aNumber)
   {
      a = aNumber;
      x1 = aNumber;
   }

   public double nextGuess()
   {
      x1 = x0;
      x0 = (x1 + a / x1) / 2;
      return x1;
   }

   public double getRoot()
   {
      while (!Numeric.approxEqual(x0, x1))
         nextGuess();
      return x1;
   }
   
   private double a; // the number whose square root is computed
   private double x0;
   private double x1;
}
