# 2implement the static method declared as follows 1 2

• 3

This preview shows page 1 - 3 out of 3 pages.

2.Implement the static method declared as follows:
1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 /** * Generates n pseudo-random points in the [0.0,2.0) x [0.0,2.0) square and * returns the number that fall in the circle of radius 1.0 centered at * the point (1.0, 1.0). * * @param n * the number of points to generate * @return the number of points that fall in the circle */ private static int numberOfPointsInCircle(int n) { ... } .Note: Use pointIsInCircle in the implementation of numberOfPointsInCircle. /** * Generates n pseudo-random points in the [0.0,2.0) x [0.0,2.0) square and * returns the number that fall in the circle of radius 1.0 centered at * the point (1.0, 1.0). * * @param n * the number of points to generate * @return the number of points that fall in the circle */ private static int numberOfPointsInCircle(int n) { int numberOfPointsInCircle = 0; int ptsInInterval = 0; while (ptsInInterval < n) { boolean point = pointIsInCircle(xCoord, yCoord); double x = (2*Math.random()); ptsInInterval++; if (point==true) { numberOfPointsInCircle++; } } return numberOfPointsInCircle; }
3.Rewrite the main method in your solution to the Monte Carlo estimation of π lab so that it uses numberOfPointsInCircle (and indirectly pointIsInCircle). );