HW_4_Patel.3322.pdf - HW#4 CSE 2221(Static Method 1 Checks...

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

HW #4: CSE 2221 (Static Method) 1. /** * Checks whether the given point (xCoord, yCoord) is inside the circle of * radius 1.0 centered at the point (1.0, 1.0). * * @param xCoord * the x coordinate of the point * @param yCoord * the y coordinate of the point * @return true if the point is inside the circle, false otherwise */ private static boolean pointIsInCircle( double xCoord , double yCoord ) { if ((( xCoord - 1) * ( xCoord - 1) + ( yCoord - 1) * ( yCoord - 1)) <= 1) { return true ; } else { return false ; } } 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 ) { Random rnd = new Random1L(); int ptsInInterval = 0; int ptsInSubinterval = 0; while ( ptsInInterval < n ) { double y = rnd .nextDouble() * 2; double x = rnd .nextDouble() * 2; ptsInInterval ++; if ( pointIsInCircle ( x , y )) { ptsInSubinterval ++;
} } return ptsInSubinterval ; } 3.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture