CCSU Spring, 1999 Project 2 Posting Date: February 2, 1999 Due Date: Friday, March 9, 1999 Relevant Demos: Demo 12: Parabola.java, Demo 13: ParabolaApplet.java, Demo 14: ParabolaApplication.java This project comes in 3 parts. It covers the material covered in Chapter 3 on control structures (if else, while), plus the material covered in chapter 4 on class Random, plus the material covered in class on Applet and Application graphics, plus the material covered in class from Chapter 5 on control structures (more on if else, for). This project and demos 12 through 14 also illustrate an important class of methods for scientific computing, Monte Carlo methods. In a Monte Carlo method, one uses a random process (pseudo-random process actually) to simulate something in nature or mathematics, usually something quite complex. Monte Carlo methods are named after the famous casino in Monte Carlo. In this project, you are going to use a Monte Carlo method to approximate the area of a circle of radius 1. Since A = pi*r*r, and r = 1 here, the computed approximation to the area A will be approximately equal to the mathematical constant pi. Here is how the method works: Throw 10,000 darts at random at a square of side 2, with vertices (corners) at (-1, -1), (1, -1), (1, 1) and (-1, 1). Note that the origin (0, 0) is at the center of the square, and note also that you could draw a circle of radius 1 centered at the origin and have it just touch the edges of the square (be inscribed in the square). Count the number of darts which hit the circle, and at the end, compute the fraction of darts which hit the circle by dividing the total number of hits by 10,000. Now the fraction f of darts hitting the circle is equal to areaOfTheCircle/AreaOfTheSquare, except for statistical error. Now areaOfTheCircle = pi, and areaOfTheSquare = 4. Thus the fraction f is equal to pi/4, except for statistical error. Multiply f by 4 to get an approximation to pi, pi = 4*f approximately. (Approximately because of the statistical error.) Here are the three parts of the project: 1. Modify Demo 12 so you compute an approximation to pi by computing the area of a circle of radius 1. You will use the condition x*x + y*y <= 1 to tell when a random point lies inside the circle. Call your class PiFinder. 2. Modify Demo 13 and part 1 so your program runs as an applet. Call your class PiFinderApplet. Draw the circle inscribed in the square, and display graphically where each 100th random point hits. Hint: Drawing the circle is much simpler than drawing the parabola in demo 13. All you have to do is use g.drawOval. Look at the Storm applet in chapter 4 of the text to see an example of circle drawing using g.drawOval. But draw the circle in paint, not in start. Drawing in the Applet start method the way the text does often doesn't work in the most recent versions of the JDK. 3. Modify Demo 14 and part 2 so your program runs as a GUI application. Call your class PiFinderApplication. Notes: (1) Your files MUST be named PiFinder.java, PiFinder.class, PiFinderApplet.java, PiFinderApplet.class, PiFinderApplication.java and PiFinderApplication.class, so I can easily find them. (2) Each of your programs must begin with a remark box as described in project 1. Due: Friday, March 19, 1999 AT THE BEGINNING OF CLASS.