Details

"To approximate the square root of a positive number n using Newton's method, you need to make an initial guess at the root and then refine this guess until it is "close enough." Your first initial approximation should be root = 1;. A sequence of approximations is generated by computing the average of root and n/root.

Use the constant:

private static final double EPSILON = .00001;

Your loop for findSquareRoot should behave like this:

make the initial guess for root

while ( EPSILON < absolute value of the difference between root squared and n )

calculate a new root

return root

Your class should have a constructor that takes the number you want to find the square root of. Implement the usual accessor method(s) and a findSquareRoot method that uses Newton's method described above to find and return the square root of the number. Add a method setNumber that takes a new number that replaces the number in the instance field. Supply a toString method that returns a string containing the number and the square root of the number. "

And here's what I have....

public class NewtonsSquareRoot{ private static final double EPSILON = .00001; private int myNumber; private double root; private double guess; public NewtonsSquareRoot(int number){ myNumber = number; } public int getNumber(){ return myNumber; } public double findSquareRoot(){ guess = 1; root = Math.sqrt(myNumber); while (EPSILON < Math.abs(Math.pow(root, 2) - myNumber)) { guess++; } return root; } public void setNumber(int number){ myNumber = number; } public String toString(){ String s = new String(); s = "The square root of " + myNumber + " is " + root + "."; return s; } }

Thanks in advance for helping