### Solution to problem 7.12

The easy solution if we do not have to worry about creating a RootApproximator class:

```
public class Main {
public static void main(String[] args) {
System.out.println("Heron's method: successive approximations");
System.out.println(heron(101));
System.out.println("Math.sqrt");
System.out.println(Math.sqrt(101));
}

public static double heron(double n) {
double guess = 1;
while (!closeEnough(guess, n)) {
guess = (guess + (n/guess)) / 2;
System.out.println(guess);
}
return guess;
}

public static boolean closeEnough(double guess, double n) {
final double THRESHOLD = .000000001;
return (Math.abs(guess * guess - n)) < THRESHOLD;
}
}
```

The more complicated way if we need RootApproximator.java (note that the while loop is in main():

```public class RootApproximator {
private double guess;
private final double TOLERANCE = .000000001;

public RootApproximator(double n) {
guess = 1;
}

public boolean isNotCloseEnough() {
return Math.abs(guess*guess - answer) > TOLERANCE;
}

public double nextGuess() {
guess = (guess + (answer/guess)) / 2;
return guess;
}

public double firstGuess() {
return guess;
}
}
```

In Main.java:

```
public class Main {
public static void main(String[] args) {
RootApproximator r = new RootApproximator(20);
System.out.println(r.firstGuess());