Writing a class using conditionals that test double values

Assignment Help JAVA Programming
Reference no: EM13941071

The NewtonsSquareRoot Class

Objectives

• Writing a class using conditionals that test double values

• Writing a class using a while loop

The project directory should include the following:

• NewtonsSquareRoot.java

• NewtonsSquareRootTest.java

Details

To approximate the square root of a positive number n using Newton's method, you need to make an initial guess at the root and then refine this guess until it is "close enough." Your first initial approximation should be root = 1; A sequence of approximations is generated by computing the average of root and n/root.

Use the constant:
private static final double EPSILON = .00001;

Your loop for findSquareRoot should behave like this:
make the initial guess for root
while ( EPSILON < absolute value of the difference between root squared and n )
calculate a new root
return root

Your class should have a constructor that takes the number you want to find the square root of. Implement the usual accessor method(s) and a findSquareRoot method that uses Newton's method described above to find and return the square root of the number. Add a method setNumber that takes a new number that replaces the number in the instance field. Supply a toString method that returns a string containing the number and the square root of the number.

Your test class should:

• Instantiate a NewtonsSquareRoot object using the number 1.

• Print the square root of 1 using the toString method.

• Use a while loop to generate the numbers 2 through 100.

• In the loop use the setNumber and toString methods to find and print the square roots of all the numbers from 2 to 100 inclusive.

Reference no: EM13941071

Questions Cloud

Where does liability lie for the managed care organization : Discuss the options, if any, MCO or PPO plan members have when denied coverage for medically necessary care.
Does junes camera shop appear to have grown in size : Does June's Camera Shop appear to have grown in size during the past two years? How long should it take June's Camera Shop to pay back the $125,000?
Market entry strategies that ikea adopt : Describe the market entry strategies that IKEA adopt in China and Japan respectively.
Requirements for packaging and stowage : Determine packaging and stowage requirements (3.1, 3.2, 3.3, 3.4) Analyse and determine the best options and requirements for packaging and stowage of your product.Research and document/ record the suitability and availability of the packaging and..
Writing a class using conditionals that test double values : To approximate the square root of a positive number n using Newton's method, you need to make an initial guess at the root and then refine this guess until it is "close enough.
Oultine of risk management plan : Complete risk management planning by providing an oultine of risk management plan and providing a brief description of the project.
Company offers to buy the special order units : If Mowen Company offers to buy the special order units at $65 per unit, the effect of accepting the special order on Melville's operating income next year should be a what?
What three other sources of laws that control health care : Laws that control health care come from four sources. One source is state and federal written constitutions. What are three other sources of laws that control health care? How the laws made based on the source of that kind of law?
Apply conflict resolution strategies : 1. Apply negotiation and conflict resolution theories, including from an employment relations perspective 2. Analyse and evaluate how local and international contexts inform negotiation and conflict resolution strategies. 3. Evaluate and apply confli..

Reviews

Write a Review

JAVA Programming Questions & Answers

  How do i automatically set the input focus in my applet

How do I automatically set the input focus in my applet to a specific component/text field when the browser loads the page that contains the applet?

  Write down a program which determines the bonus that must

write a program that determines the bonus that should be paid to employees. bonuses are determined based on the years

  Develop java applet that will help elementary school student

Develop a Java applet that will help an elementary school student learn multiplication. Use the Math.random method or a Random object to produce two positive one-digit integers.

  Digit decimal seconds counter using two 7-segment displays

Write a program that implements a two digit decimal seconds counter using two 7-segment displays.  Make this program using java programming. Make this program in simple way.

  Details about the consultants and projects

A consulting firm maintains a database of its employees (a number of consultants) and a list of projects it has accomplished, has been developing, and is about to start. Details about the consultants and projects are given below:

  Write a java application that allows the user to read

Write a java application that allows the user to read, validate, store, display, sort and search the internet account number (integer number), usage (integer number) and cost (double number) for N customers. N should be declared as a constant and it ..

  Create the java code for a generic class

Create the Java code for a generic class. The class should contain at least one private data member of a generic type, a constructor which initializes the private data member to the value of a passed in argument, and a getter and setter for the ge..

  Create a two dimensional integer array in java

Create a two dimensional integer array in JAVA that produces the sum of rows and columns as selected by the user.

  Implement a client program

Implement a client program with a main method to demonstrate the evolution of the sales tax rates in the 50 US states over the last 10 years. Declare a two-dimensional array of values representing the sales tax rates. Dimension 1 represents the st..

  Primary care-secondary care and tertitary care

Discuss the differences among primary care, secondary care, and tertitary care and the 6 C's of primary care

  What is an illustration of a javascriptr framework in the

what is an example of a javascriptr framework? in the framework you have described what is an example of an application

  Create listener objects for each jcombobox

Create listener objects for each JComboBox that set the background color of the panel when the user selects an integer. Use the current values supplied by the JComboBox objects to determine the background color.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd