Lab 7.4 - Slice of Pi

3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912983367336244065664308602139494639522473719070217986094370277053921717629317675238467481846766940513200056812714526356082778577134275778960917363717872146844090122495343014654958537105079227968925892354201995611212902196086403441815981362977477130996051870721134999999837297804995105973173281609631859502445945534690830264252230825334468503526193118817101000313783875288658753320838142061717766914730359825349042875546873115956286388235378759375195778185778053217122680661300192787661119590921642019893809525720106548586327886593615338182796823030195203530185296899577362259941389124972177528347913151557485724245415069595082953311686172785588907509838175463746493931925506040092

We all know that π is a mathematical constant that is the ratio of a circle's circumference to its diameter, but what is it really? We could look it up, but that's boring. Figuring it out would be more fun. Even more fun if it involves random numbers.

A "Monte Carlo" method of finding an answer involves using a lot random numbers and figuring out what your answer is from the result. There are a couple of Monte Carlo methods of finding π. The version we'll use is the inscribed circle method (the one in the pic). The basic idea is that if we draw a quarter circle on a square napkin and then sprinkle pie crumbs on it, the ratio of the pie crumbs in the quarter circle to the crumbs on the entire napkin is equal to a quarter of π. Ask your instructor if you want to know how that works; we're just going to do it.

Your program will have a napkin made out of a two-dimensional array of booleans. The array's size should be big (like 2,500 by 2,500, for example). Then, it takes a number of crumbs from the user (between 1 and about 2/3 the number of members in the array (our example's case would be about 4,166,667) and "sprinkles" them into the array. It will make sure not to sprinkle a crumb onto a place that already has a crumb. It then traverses the array, counting the number of crumbs that landed inside the arc, dividing that number by the number of total crumbs, multiplies by 4, and displays the answer. Which should be really close to the real π; the more crumbs, the closer to π it should be.

HINTS: We're going to be using large integers, so you might want to use Long variables instead of Integer variables. Of course, π is a real number, so you'll need to work in Double time (get it?). A crumb is inside the arc if the distance from the origin is equal to or less than the size of one dimension of the array (use the crumb's indicies as its coordinates).

As always, design a useful and proper interface, including tab order and access keys.