homework 4.docx - Homework4 Chengyu Zheng 9:10 section 1...

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

Homework4 Chengyu Zheng 9:10 section 1 Implement (i.e., provide the code for the body of) the static method declared as follows: /** * 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 */ @SuppressWarnings("unused") private static boolean pointIsInCircle (double xCoord, double yCoord) { if(Math. sqrt ((xCoord-1)*(xCoord-1)+(yCoord-1)*(yCoord-1))<1) return true; return false; } } 2 Implement the static method declared as follows: 1 2 3 4 5 6 7 8 9 10 11 12 /** * 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 n2 = 0; double a = Math. random (); double b = Math. random (); while (a < 2.0 && b < 2.0) { pointsIsInCircle (double a, double b)

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture