Lab 5
Start Now
## Overview In this assignment, you will create a program that will estimate the value of $ \pi $. ## Assignment First, consider the figure below: <figure>[<img src="lab5a.png" />](lab5a.png)</figure> 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: <figure>[<img src="lab5b.png" />](lab5b.png)</figure> 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 <kbd>y</kbd>, <kbd>Y</kbd>, <kbd>n</kbd>, or <kbd>N</kbd>, the prompt should be repeated. * If the user enters <kbd>y</kbd> or <kbd>Y</kbd>, all of the steps above are repeated. * If the user enters <kbd>n</kbd> or <kbd>N</kbd>, 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 <div class="notetip"> See your professor's instructions for details on submission guidelines and due dates. </div>

Friday, 21-Sep-2018 07:21:13 CDT