Assignment 3 - Input, Output, Methods, Arithmetic, and Loops
Expansion series to approximate PI
Due Friday, April 30 by 11:59:59pm


Pi can be approximated by the following series:

4 - 4/3 + 4/5 - 4/7 + 4/9 - ...

As you add more terms of the series together, you get the value of Pi with more precision.  The drawback to this series is that it very slowly approximates Pi.  However, since we have a computer, we can overcome this to some degree because of the speed at which computers perform arithmetic.  Your task is to get an integer greater than 9 from the user (you must ensure the integer they enter is greater than 9 -- as long as the user enters an invalid number, re-prompt for input) that represents to which term to approximate Pi.  Once a valid integer is obtained, calculate the approximate value of Pi to that term.  Print the values of the 10 terms leading up to and including the last term specified, formatted to 15 digits to the right of the decimal point, preceded by the term number (see example run below).

After results have been displayed, the user should be asked if s/he wants to perform another approximation of Pi.  If the answer is yes, get another term and perform the calculation as specified above.  The user should be asked if s/he wants to go again until the answer is no. 

Example Run:

Welcome to the Pi approximation program.
This program will approximate Pi based on the following series:

4 - 4/3 + 4/5 - 4/7 + 4/9 - ...

Enter the term number to which you would like to approximate Pi
(note that 4 is term 1, 4/3 is term 2): 9
Invalid input!  Please enter a term greater than 9: -999
Invalid input!  Please enter a term greater than 9: what's up dude?
Invalid input!  Please enter a term greater than 9: 20

The values of Pi from term 11 to term 20 are
--------------------------------------------
Term 11: 3.232315809405594
Term 12: 3.058402765927333
Term 13: 3.218402765927333
Term 14: 3.070254617779185
Term 15: 3.208185652261944
Term 16: 3.079153394197428
Term 17: 3.200365515409549
Term 18: 3.086079801123835
Term 19: 3.194187909231942
Term 20: 3.091623806667840

Would you like to try again (yes/no)? yo!
Invalid input, please enter yes or no: yes

Enter the term number to which you would like to approximate Pi
(note that 4 is term 1, 4/3 is term 2): 10

The values of Pi from term 1 to term 10 are
--------------------------------------------
Term 1: 4.000000000000000
Term 2: 2.666666666666667
Term 3: 3.466666666666667
Term 4: 2.895238095238096
Term 5: 3.339682539682540
Term 6: 2.976046176046176
Term 7: 3.283738483738484
Term 8: 3.017071817071818
Term 9: 3.252365934718877
Term 10: 3.041839618929403

Would you like to try again (yes/no)? no
Good Bye!


You should create an ApproximatePi class to do the necessary interaction with the user and the approximation operations.

EXTRA CREDIT (2 points possible) Make sure that when you print the terms they are in nice columnar form.  In the example above, when terms 1 through 10 are printed, term 10 is not neatly aligned with the rest (or perhaps the rest aren't neatly aligned with term 10 ;-)

EXTRA CREDIT (5 points possible) Allow the user to enter a number that specifies how many digits of precision to calculate Pi to, and show what term produces the desired precision.  Note that the maximum digits of precision you'll want to compute is probably 10 or 11 (beyond 11 may take a significant amount of time to reach).  In addition, you'll encounter overflow if you only use and int to represent your term number.


In comments at the top of your ApproximatePi class, place your name, date, a description of what the program does, and a history of work done on the program.  Also use this area to document any items you were unable to complete. 

Include output captures of your program that show what term gives Pi to two digits of precision, five digits precision, and seven digits of precision at the very least.  Provide a description for each method in the class in the lines preceding each method.  Also use inline documentation where necessary to clarify your code.

You should have at least three different runs of the program captured.  Place your captured output in a file called ApproximatePi_output.txt -- this file should be a plain text file.

Submit to blackboard the above files (ApproximiatePi.java and ApproximatePi_output.txt) in a .zip file named according to our naming conventions.  This is hw3.

Have Fun!