Question: IN JAVA. i've been asking for help for over a week and i've got nothing. ): The goal of this lab is to conduct an

IN JAVA.

i've been asking for help for over a week and i've got nothing. ):

IN JAVA. i've been asking for help for over a week and

The goal of this lab is to conduct an experiment to test the Birthday Paradox, vhich states that if 23 people gather, the chances are 50-50 that there are two people in the group having the same birthdays This days; that is, for any day of the year, the proportion of the people born on that day is 1/365 of the entire population. Under these assunptions, the probability that randomly selected 23 people have distinct birthdays from each other is: 365 364* * 343 In the denominator, there is no constraint about the birthdays; each person picks up one birthday from the 365 possibilities. In the numerator, the 23 people select birthdays one after another, so that no tvo have the sane birthdays: the first person has 365 possibilities, the second has 364 because he/she must not pick the one that the first person has chosen, the third person has 363 because he/ahe nust not pick the ones that the first and the second persons have chosen, and so on. The fraction is about 0.50, so the chances are almost 50-50 that there are two people having the same birthdays The centerpiece of the code is a method, oneTrial, that, given a number of people as its paraneter, randomly selects birthdays for those people and produces for each day how many people have chosen to have that birthday. More formally, the method has the number of people, nPeople, as its formal parameter and returns an int array. The method firat instantiates an array of 365 elements, say theCounts. Then, for nPeople tines (using a for-loop)the method selects a random integer between 0 and 364, and then increases the element of thecounts at the selected integer. After that it returns the array thecounts After receiving the return value of oneTrial, we examine the alots of the array for an entry greater or equal to 2. Such a alot indicates the existence of multiple having the same birthdays. We give this task to a nethod hasAHit. This nethod has its formal parameter an integer array and returns a boolean. Using a for-loop, the method scans the slots of the fornal paraneter. On encountering a slot value >2, the method returns true, thereby ignoring the remainder of the code in the method. After the for-loop, the method returns false, indicating that no slot -2 has been encountered Using the above two methods, we write another method, experiment1. The method experimentl has two formal paraneters. The first is an int by the name of nPeople, which is loop to count the executions of oneTrial. After each execution, w feed the return array of oneTrial to hasABit. If hasAHit returns true, we increase the value of a double proportion of the repetitions in which the random birthday selections generated multiple people having the sane birthdays. The method experimentl reports this ratio before The main method receives the quantities for nPeople and nReps and calls experimentl with these two values To print the average, use ".3f" in printf so that exactly three digits appear after the decinal point

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!