Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Assignment 4 - Follow the directions below to submit Assignment 4: Create a Java program. The class name for the program should be 'CalculatePI'.

Java Assignment 4

- Follow the directions below to submit Assignment 4:

Create a Java program.

The class name for the program should be 'CalculatePI'.

In the main method you should perform the following:

Create a for loop that will loop for 10,000,000 iterations that will be used to calculate the Mathematical value of PI.

You will need a variable to count the iterations.

You will need a variable that will be used in the mathematical calculation inside the loop.

The formula for PI is: PI = 4 * (1 - 1/(2*i-1) + 1/(2*i+1) . . .

Each 1000th iteration of the loop should print the iteration number and the currently calculation for PI.

At the end of the loop the program should display the value of PI as determined by the variable Math.PI and the difference between your calculated value and the value contained in Math.PI

You should then repeat the instructions above using a while( ) loop rather than a for( ) loop.

***Pseudo flowchart for the assignment program:

Create a variable to contain the PI calculation. The initial value of this variable should be 1.

Create a for( ) loop that will loop for 10,000,000 iterations. You will need a loop variable to count the number iterations.

Create a second loop variable that will be used for i in the calculation. The initial value of this varaible should be 2.

For each iteration of the loop you will need to subtract the value of 1.0/(2*i-1) from the calculation and add the value of 1.0/(2*i+1).

At the end of the loop you will increment the iteration loop variable by 1 and increment the value of i used in the calculation by 2.

Every 1000th iteration of the loop you should display the iteration number and the calculated value for PI.

When you have completed the loop you should print the value of Math.PI and the difference between Math.PI and your calculated value of PI.

You will then repeat this process using a while( ) loop.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 10g Insider Solutions

Authors: Arun R. Kumar, John Kanagaraj, Richard Stroupe

1st Edition

0672327910, 978-0672327919

More Books

Students also viewed these Databases questions

Question

well defined status and roles (class distinctions);

Answered: 1 week ago