CSc 110 Lab Assignment 1 Part 1 solution

$24.99

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (4 votes)

Learning Outcomes:
When you have completed this assignment, you should understand:
How to design, compile, run and check a simple and complete Java program on your own.
The flow of data values (i.e. the effects of assignment statements).
How to indent and document a Java program.
How to analyze a problem to identify the input, output and intermediate values needed
for computing.
How to write and call a static method.
Assignment 1 Part 1: Approximating Pi:
The number Pi ( ) is the ratio of any circle’s circumference to its diameter. Researchers are
constantly searching for a more accurate representation of . In many programming libraries,
however, this number is approximated with the following calculation:
= 4 x ( 1 – 1/3 + 1/5 – 1/7 + 1/9 – 1/11 + 1/13 – . . . )
(Recall from your pre-requisite math course that . . . means that this series is infinite.)
1. (Hand Calculation – Simplified Problem) Use a calculator and paper/pencil to determine an
approximation for using only the first 7 terms of the sequence above.
= 4 x ( 1 – 1/3 + 1/5 – 1/7 + 1/9 – 1/11 + 1/13 ) = _________________
Write down as many decimal points as your calculator provides for you, then re-check your
calculation several times.
2. (Program – Simplified Problem) Write a Java program that approximates using the first
7 terms of the sequence above.
Sample output of this program:
Pi is
3.2837384837384844(approximately)
Press any key to continue . . .
Although this can be done by simply typing the numbers 1 – 1/3 + 1/5 – 1/7 + 1/9 – 1/11 +
1/13 into your editor (and you can try it that way at first), do not move on to step 3
(below) until you have written your program using the following to create this series:
a. Create a variable called nextTerm and assign it (initially) the value 1.
b. Create a variable called denominator and assign it (initially) the value 1.
c. Create a variable called series and assign it (initially) the value 0.
d. Do the following 7 times:
i. Add (nextTerm\denominator) to the series.
ii. Add 2 to the denominator.
iii. Multiply the nextTerm by -1.
3. (Complete Program) Write a Java program that approximates using the first 40 terms of
the sequence above.
PART 1 HAND IN: Submit your code for step 3 (above) using the ‘Assignments’ link of the
course web page. Your code must be submitted before the beginning of your scheduled lab
class in the week of September 20-24, 2010.
Sample output of this program:
Pi is 3.116596556793833(approximately)
Press any key to continue . . .