|
Spring Semester 2003 |
Solve
problem P6.12 in Big Java p. 278.
Here's the text of the problem:
The Heron method is a method for computing square roots that was known to the ancient Greeks. Ifxis a guess for the valueMath.sqrt(a), then the average ofxanda/xis a better guess.The problem asks to implement a class
RootApproximatorthat starts with an initial guess of1and whosenextGuessmethod produces a sequence of increasingly better guesses. Supply a methodhasMoreGuessesthat returnsfalseif two successive guesses are sufficiently close to each other. Then test your class like this:
(Doesn't this look awfully similar to the way we useRootApproximator r = new RootApproximator(n); while (r.hasMoreGuesses()) System.out.println(r.nextGuess());StringTokenizers?The above is your Homework Three.
Needless
to say you are not allowed to make any use of Math.sqrt(...)
in your program.
Traditionally Homework Three was like that.
(However we have since posted a solution, see the link above).
Can you answer that last question though in the posted solution?