Approximating Pi

Consider the following thought experiment. Suppose you throw a dart at the figure below, with it landing randomly at some point inside the square. What is the probability it also finds itself inside the quarter circle?

Assuming the square has side length $x$, note the area of the quarter circle must be $(\pi / 4) x^2$, while the area of the square is of course $x^2$. The quotient of their areas should provide the probability we seek:

$$\frac{\textrm{Area of quarter circle}}{\textrm{Area of square}} \quad = \frac{(\pi / 4) x^2}{x^2} = \pi / 4$$

If we threw 100,000 darts in a similar manner, and divided the number of darts that landed in the quarter circle by the number thrown, we should then approximate $\pi / 4$. Multiplying this approximation by 4 then gives us an approximation for $\pi$ itself.

Write a class named PiApproximator that extends the OneButtonBreadboard class and prompts the user to enter some number of darts to throw; draws the landing positions of those darts, colored red or yellow depending on whether they land in the quarter circle described above; and reports the approximation for pi that results.