Question: SAMPLE CODE----------------------------------------------------------------------------------- import java.util.Scanner; /** * Greek's method to approximate the square root of a given number. */ public class SquareRootComputer { public static void

 SAMPLE CODE----------------------------------------------------------------------------------- import java.util.Scanner; /** * Greek's method to approximate the

SAMPLE CODE-----------------------------------------------------------------------------------

import java.util.Scanner; /** * Greek's method to approximate the square root of a given number. */ public class SquareRootComputer { public static void main(String[] args) { // this is your tester // read a value from the user and print the results // along with expected value } public static double squareRoot(double x) { // from this method come up with a guess // and then make the call to the recursive method // squareRootGuesser() return 0; } private static double squareRootGuess(double x, double g) { // recursive method to compute the square root of x // you will need to have a base case and a recursive case // in this method return 0; } }

------------------------------------------------------------------------------------------------------------------------------

Some useful links: BlueJ tutorial www.bluei.org/tutorial tutorial-201 Java tutorial home page: http:docs.oracle.comjavase tutorial Start here: http://docs.oracle.com/iavase tutorial/java index.htmi Arrays http://docs.oracle.comjavase/tutorial java nutsandbolts/arrays.html Array Lists http://docs.oracle.comjavase 7/docs/api java util ArrayList.html Some helpful tips: Compile often - do it. Break up the problem into two tasks initially, your base case and then your recursive case. The base case will be much less code than the recursive case There is very limited starter code for this lab. Then again, there is not a lot of code to write to complete this lab . . Tasks: Follow the directions below to complete your lab assignmenit For today's lab we will be completing Exercise E13.11 from the book. Starter code is included on UTC Learn SquareRootComputer.java E13.11 - The following method was known to the ancient Greeks for computing square roots Given a vahue x 0, and a guess g for the square root, a better guess is (g + x/g)/2 Write a recursive helper methodprivate static squareRootGuess (double x, double g) Ifg2 1s approximately equal to x (that is, less than . 0001 difference between x and g2), return g, otherwise, return squareRootGuess with the better guess Then write a method public static squareRoot (double x) that uses the helper method. Here is a sample run from a working project: Enter a number: 27 The square root is of 27.000 is 5.19615 Expected value 5.19615 IMPORTANT!! Follow the name conventions shown in the lab documentation. For this lab you will simply need to complete the two methods described above private static squareRootGuess (double x, double g) andpublic static squareRoot (double x)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!