1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
spin [16.1K]
3 years ago
11

Your first job is to create a Java program that repeatedly asks the user whether they wish to calculate another square root. If

the response is "y", then the program should proceed; if it is anything else, then the program should quit. Whenever it proceeds, the program should prompt the user for a number (a positive double, and your program may simply assume the input is consistent with this requirement) and then report the square root of that number to within a relative error of no more than 0.01%. The computation must be done using Newton iteration. The intuitive idea of Newton iteration for computing square roots is fairly straightforward. Suppose you have a guess r for x1/2 that is too large; the argument is similar if it is too small. If r is too large to be the square root of x, then x/r must be too small, so the average of r and x/r should be a better guess than either r or x/r. This suggests that if you repeatedly replace your current guess r by (r + x/r)/2, then your sequence of guesses should converge to x1/2. And indeed it can be proved that it does. A good initial guess for x1/2 is simply r = x. If you continue updating r until |r2 – x |/x < ε2, then the relative error of the guess r will be less than ε. After your initial program works, there are a number of other requirements to change it slightly, one step at a time, as explained below.
Computers and Technology
1 answer:
Zinaida [17]3 years ago
7 0

Your first job is to create a Java program that repeatedly asks the user whether they wish to calculate another square root. If the response is "y", then the program should proceed; if it is anything else, then the program should quit. Whenever it proceeds, the program should prompt the user for a number (a positive double, and your program may simply assume the input is consistent with this requirement) and then report the square root of that number to within a relative error of no more than 0.01%. The computation must be done using Newton iteration.

The intuitive idea of Newton iteration for computing square roots is fairly straightforward. Suppose you have a guess r for x1/2 that is too large; the argument is similar if it is too small. If r is too large to be the square root of x, then x/r must be too small, so the average of r and x/r should be a better guess than either r or x/r. This suggests that if you repeatedly replace your current guess r by (r + x/r)/2, then your sequence of guesses should converge to x1/2. And indeed it can be proved that it does. A good initial guess for x1/2 is simply r = x. If you continue updatingr until |r2 – x |/x < ε2, then the relative error of the guess r will be less than ε.

After your initial program works, there are a number of other requirements to change it slightly, one step at a time, as explained below.

Open the src folder of this project and then open (default package). As a starting point you should useProgramWithIOAndStaticMethod.java. Rename it Newton1 and delete the other files from the project (if needed, see Creating a Program from a Skeleton (also Renaming a Java Program) for details).

Edit Newton1.java to satisfy the problem requirements stated above, including updating comments appropriately. Estimating the square root should be done in a static method declared as follows:

1

2

3

4

5

6

7

8

9

10

/**

* Computes estimate of square root of x to within relative error 0.01%.

*

* @param x

*            positive number to compute square root of

* @return estimate of square root

*/

private static double sqrt(double x) {

   ...

}

Copy Newton1.java to create Newton2.java. Change sqrt (including its Javadoc comments) so it also works when x = 0.

Copy Newton2.java to create Newton3.java. Change it so the main program prompts the user to input the value of ε (rather than assuming it is 0.0001), just once as the program begins, and so this value is also passed to sqrt.

Copy Newton3.java to create Newton4.java. Change it so the main program does not ask the user whether they wish to calculate another square root, but instead simply asks for a new value of x and interprets a negative value as an indication that it's time to quit.

Select your Eclipse project Newton (not just some of the files, but the whole project), create a zip archive of it, and submit the zip archive to the Carmen dropbox for this project, as described in Submitting a Project.

You might be interested in
Numdu
gizmo_the_mogwai [7]
The question is unclear /unfinished please send again.
4 0
3 years ago
A laptop gets replaced if there's a hardware issue. Which stage of the hardware lifecycle does this scenario belong to?
Ilya [14]

Answer: Maintenance. This is the stage where software is updated and hardware issues are fixed if and when they occur. Retirement. In this final stage, hardware becomes unusable or no longer needed and it needs to be properly removed from the fleet

Explanation:

3 0
3 years ago
Recursion occurs when a function (calls itself/ calls another function/ calls a function from the python standard library)
lesantik [10]

Answer:

Recursion is calling of a function from within that same function

5 0
3 years ago
In a word processing program, under which tab or menu option can you adjust the picture brightness?
Otrada [13]
B. format because changing the brightness of the photo is changing its default format
5 0
3 years ago
Read 2 more answers
A customer struggles with the small print of most smartphones. The customer still likes the idea of using a smartphone for phone
aliya0001 [1]

Answer:

The answer is a phablet.

Explanation:

A phablet is a class of smartphones with an intermediate size between a smartphone and a tablet. If the customer follows the recommendation, then he could still use this device for phone calls and work and not struggle anymore with the small print of the typical smartphone.

3 0
3 years ago
Read 2 more answers
Other questions:
  • Which is the most efficient way to italicize a row of text in every worksheet in a workbook?
    8·1 answer
  • Processing is handled by the computer’s central processing unit (cpu).​ <br> a. True <br> b. False
    6·1 answer
  • Which is the highest level of the hierarchy of needs model?
    7·2 answers
  • Write a program that takes a date as input and outputs the date's season. The input is a string to represent the month and an in
    6·1 answer
  • Which of the following consists of electronic components that store instructions?
    10·1 answer
  • In his article “is google making up stupid” Nicholas Carr uses a metaphor to suggest that
    11·2 answers
  • int temp; temp = 180; if ( temp &gt; 90 ) { System.out.println( "This porridge is too hot." ); // cool down temp = temp – ( temp
    9·1 answer
  • 8.5 Edhesive Code Practice
    14·1 answer
  • 6
    9·1 answer
  • What is are the most efficient ways to make a slide presentation?
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!