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

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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