Java

Estimate PI 2

14 points

In this program you estimate the famous mathematical constant π by...throwing darts at a dart board. Actually you simulate throwing darts because we are programming computers, and computers are ideal for running simulations. The theory is this: start with a square that measures 2 on each side; its area is 4. Inscribe a circle inside the square with a radius of 1; its area is πr2 or π. Randomly throw a bunch of 'darts' at the square dart board and count how many of the darts land inside the circle. The ratio darts inside circle :: total darts should be close to π :: 4. So π can be estimated as equal to 4 * (darts inside circle / total darts). (Caution: don't try this with an actual dart board. You are likely to lose friends.)

Screenshots


After the program loads

 

 


After the user has thrown 100 darts

 

 


After the user has thrown another 10,000 darts

 

 

 

Starting Point

You can download EstimatePI2.java to use as a starting point in writing your program. Instructions for completing the program are inside the Java file.