I'm just totally lost with my programming homework.

I was wondering if anyone can build an outline for this particular program , so I can work thru with you help!

Thank you so much again!

Description!

Calculate Square Root

This method for calculating the square root of a number N starts by making a (non zero) guess at the square root. It then uses the original guess to calculate a new guess, according to the formula

newGuess = ((N / oldGuess) + oldGuess) / 2.0;

Have two variables oldGuess and newGuess. Initialize oldGuess to N and calculate newGuess according to the above formula. Use a while loop to iterate as long as the absolute value of the difference between the oldGuess and newGuess is greater than 1.0E-06. Do not forget to reset the value of oldGuess to the newGuess value in the while loop. Use the built-in function Math.abs().

In your program you will prompt the user to enter a positive number. You will have to use a Scanner object to read the input in as a double. If the number is negative, print an error message and ask the user to try again. For a positive number, calculate the square root using the above method. Find the difference between the square root you obtained and the value obtained from Math.sqrt(). Write out the value the user entered, the square root you computed, and the difference (your square root - Math.sqrt()). Use the type double for all your calculations.

There is a piece of trivia associated with this algorithm. Professional mathematicians are familiar with this algorithm as Newton's method. But the algorithm is much older than Newton. In first century AD, the Greek mathematician Heron of Alexandria used this method to determine the square root of 720. There is evidence that this method goes even further back, as far as the Babylonians. In the Yale University Babylonian Collection, there is a cuneiform tablet that seems to use this method to calculate the square root of 2.

Entirely Optional: You can refine the initial guess so that the method converges faster. We know that the square root of 100 is 10, so a better initial guess for the square root of any 3 or 4 digit number is 10. Likewise, we know that the square root of 10,000 is 100, so a better initial guess for the square root of any 5 or 6 digit number is 100. And so on.

This post has been edited by **ds4plj**: 05 October 2006 - 02:51 PM