Answered step by step
Verified Expert Solution
Question
1 Approved Answer
[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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started