Question: [D2p: 20 pts] The following Java method approximates the square root of a positive integer value. It returns a root with error not higher than

 [D2p: 20 pts] The following Java method approximates the square root

[D2p: 20 pts] The following Java method approximates the square root of a positive integer value. It returns a root with error not higher than 0.000001 a. [8 pts] At which line would you insert an assert statement to ensure that the pre-condition holds. Write the assert statement which throws an AssertException with a message "Invalid Input." if the pre-condition does not hold. b. [8 pts] At which line would you insert an assert statement to ensure that the post-condition holds. Write the assert statement which throws an AssertException with a message "Invalid Output" if the post-condition does not hold. Notice that the error can be calculated as the absolute difference between the square of the result (x) and the input value (n). C. [4 pts] Name two variables in the program that you can declare them as final. float ApproximateSquareRoot (float n) { 1 2 3 4 5 6 float x = n; float y = 1; double e 0.000001; 8 9 10 11 12 13 14 15 while (x - y > e) { X = (x + y) / 2; y = n/ x; } return 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!