Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement (i.e., provide the code for the body of) the static method declared as

ID: 3536351 • Letter: I

Question

Implement (i.e., provide the code for the body of) the static method declared as follows:

Note: Use pointIsInCircle in the implementation of numberOfPointsInCircle.

1 2 3 4 5 6 7 8 9 10 11 12 13 /** * 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) {     ... }

Explanation / Answer

private static boolean pointIsInCircle(double xCoord,double yCoord){

if(((xCoord-1.0)*(xCoord-1.0) - (yCoord-1.0)*(yCoord-1.0)) < 1.0){

return true;

}

else{

return false;

}

}


private static int numberOfPointsInCircle(int n) {

count=0;

for(int i=0;i<n;i++){

Random r = new Random();

xC = r.nextDouble()/2.0;

Random r = new Random();

yC = r.nextDouble()/2.0;

if(pointIsInCircle(xC,yC)){

count++;

}

}

return count;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote