import java.util.Random; /** *class MonteCarlo is used to use probability to solve certain types of problems. *Central Limit Theorem? * * @author John Sloan * @version 03/12/08 */ public class MonteCarlo { private Random generator; /** * Constructor for objects of class MonteCarlo. * assigns generator a new space in memory for the Ranom package. */ public MonteCarlo() { generator = new Random ( ); } /** * An example of a method - replace this comment with your own */ public void surprise() { //number o0f iterations int max = 2000000; //increment value int hits = 0; double maxD = 0; //assigned from below double hits double hitsD = 0; //assigned from local variable below in while body. double x = 0; //assigned from local variable below in while body.` double y = 0; //stored value for mathmatical equation below.` double answer = 0; //stores the value for the answer. int i = 0; //use the name of my object...is that rand?? while( i < max ) { x = generator.nextDouble( ); y = generator.nextDouble( ); if(((x*x) + (y*y)) <= 1) hits++ ; i++; } maxD = (double) max; hitsD = (double) hits; answer = (4.0 * hitsD / maxD); System.out.println(answer); } }