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;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.