There is a more recent offering of this course. This is an archive of the
course which was offered in Fall 2018.
Lab
5
Start Now
Lab 5: Library Classes
## Overview
In this assignment, you will create a program that will estimate the value
of $ \pi $.
## Assignment
First, consider the figure below:
The figure represents one quarter of a unit circle (a circle with a radius of
1). The area under the curve is equal to $ \pi / 4 $ since the area of a unit
circle is $ \pi \times r^2 = \pi \times 1^2 = \pi $. Now, if we were to
randomly plot a point in the square above, the probability that it would be
under the curve is equal to the ratio of the area under the curve to the
area of the square. The area of the square is $ 1 \times 1 = 1 $, and the
area under the curve is $ \pi / 4 $ since it is a quarter of the unit circle.
The figure below shows a number of randomly generated points plotted in the
unit square:
By taking the ratio of all of the dots that landed under the curve to the
total number of dots plotted, we can estimate the value of $ \pi $. There
are 4000 random points in the above figure. 3143 of them lie under the curve,
so we estimate $ \pi $ to be 3.143.
Write a program that
* Asks the user to enter the number of randomly generated points to be used to estimate $ \pi $.
* Generates the desired number of random points using the [Random](https://docs.oracle.com/javase/8/docs/api/java/util/Random.html) class.
* Calculates an estimate for $ \pi $ based on the generated points.
* Determines the number of correct digits in the estimate.
* Displays the estimated value and the number of correct digits.
* Asks the user if they would like to generate a new estimate for $ \pi $.
* If the user enters anything other than y, Y, n, or N, the prompt should be repeated.
* If the user enters y or Y, all of the steps above are repeated.
* If the user enters n or N, the program should display the best estimate of $ \pi $ generated while the program ran and then exit.
## Requirements
* The program must be created in a class named `Lab5` that is in a package named the same as your MSOE username.
* As long as the user enters an integer for the number of points used to generate the estimate, the program must not crash. If the user enters an invalid integer value, the program should report the error professionally and reprint the prompt again.
* The program must not crash regardless of what the user enters in response to the prompt asking if they would like to generate a new estimate.
## Acknowledgement
This laboratory assignment was developed by Dr. Chris Taylor
See your professor's instructions for details on submission guidelines and due dates.
Friday, 21-Sep-2018 08:21:13 EDT
Submission Form for Dr. Taylor
Submission (due at 11pm Monday of Week 6)
Each student must submit their program with complete functionality.