.


RootApproximator approx = new RootApproximator(a, EPSILON);
while (approx.hasMoreGuesses())
   System.out.println(approx.nextGuess());

Complete the following file:

RootApproximator.java

Use the following files:

RootApproximatorTester.java

public class RootApproximatorTester
{
   public static void main(String[] args)
   {
      double a = 100;
      final double EPSILON = 1; 
      RootApproximator approx = new RootApproximator(a, EPSILON);
      System.out.println(approx.nextGuess());  
      System.out.println("Expected: 1");
      System.out.println(approx.nextGuess());  
      System.out.println("Expected: 50.5");
      while (approx.hasMoreGuesses())
         approx.nextGuess(); 
      System.out.println(Math.abs(approx.nextGuess() - 10) < EPSILON);
      System.out.println("Expected: true");
   }
}

RootCalculator.java

import java.util.Scanner;

/**
   This program calculates a square root without calling Math.sqrt.
*/
public class RootCalculator
{
   public static void main(String[] args)
   {
      Scanner in = new Scanner(System.in);
      System.out.print("Enter a number that you want a square root of: ");
      double a = in.nextDouble();
      final double EPSILON = 1E-12;
      
      RootApproximator r = new RootApproximator(a, EPSILON);

      while (r.hasMoreGuesses())
         System.out.println(r.nextGuess());      
   }
}