subject

The goal of this lab is to write a code, Birthday. java, for conducting an experiment to test the Birthday Paradox, which states that if 23 people gather, the chances are 50-50 that there are two people in the group having the same birthdays. This observation comes from the following analysis. Assume that there are 365 days in a year and the birthdays of people are evenly distributed on the 365 possible dates. In other words, for each day of a year, the expected proportion of the people born on that day is 1/365 of the entire population. Under these assumptions, the probability that randomly selected 23 people have 23 distinct birthdays collectively is: 365 ∗ 364 ∗ ... ∗ 343 36523 (1) The denominator represents the number of possible choices for the birthdays collectively given to the 23 people. The numerator represents the number of possibilities for the 23 people to select their birthdays so that no two people choose the same birthdays. There, 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/she must not pick the ones that the first and the second persons have chosen, and so on. The fraction has the value approximately equal to 0.50, so the chances are almost 50-50 that there are two people having the same birthdays. The program The centerpiece of the code is a method, oneTrial, that, given a number of people as its parameter, randomly selects birthdays for those people and produces for each day how many people have selected that day as their birthdays. More formally, the method receives the number of people, nPeople, as its formal parameter and returns an array of int whose length is 365. The method first instantiates an array of 365 elements, named theCounts. Then, it enters a for-loop that iterates 1, ..., nPeople with some iteration variable. In each iteration of the loop, the method selects a random integer between 0 and 364, and then increases the element of the array theCounts at the selected position by 1. After quitting the loop, the method returns the array theCounts. Since the elements of arrays of numbers are initialized with the value 0, explicit initialization is not needed. After receiving the return value of oneTrial, we examine the elements of the array, looking for an element with the value greater than or equal to 2. Such an element indicates the existence of multiple people having the same birthdays. We write a method, hasAHit, for executing this search. The method receives an int array as its parameter and returns a boolean. Using a for-loop, the method scans the elements of the array given as the formal parameter. On encountering an element whose value is greater than or equal to 2, the method immediately returns true, ignoring the remaining elements of the array. If this does not happen, the loop terminates. At that point, the method returns false. 1 Using the above two methods, we write another method, experiment1. This method has two formal parameters. The first is an int named nPeople. This is the value to be passed to oneTrial as the number of people. The second is an int as well and is named nReps. This is the number of times to execute oneTrial. Use a for-loop to count the executions of oneTrial. After each execution, feed the return array of oneTrial to hasAHit. If hasAHit returns true, increase the value of a double variable, hitRate, by 1. The initial value of hitRate is 0. After completing the loop, we divide hitRate by nReps. The value of hitRate then becomes the proportion of the repetitions in which the random birthday selections generated multiple people having the same birthdays. The method experiment1 reports this ratio before terminating. The main method receives the quantities for nPeople and nReps and calls experiment1 with these two values as the actual parameters. To print the average, use "%.3f" in printf so that exactly three digits appear after the decimal point. output example:
% java Birthday
Enter the no. of people: 23
Enter the no. of repetitions: 100
Experiment 1 Probability Of Hits: 0.490
Experiment 2
Average No. of 0s: 342.760
Average No. of 1s: 21.500
Average No. of 2s: 0.720
Average No. of >=3s: 0.020

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 24.06.2019 07:00
Into what form does the barcode reader convert individual bar patterns?
Answers: 1
question
Computers and Technology, 24.06.2019 08:00
Arah has entered data about football players from team a and team b in a worksheet. she enters names of players from team a with details about each player in different columns of the worksheet. similarly, she enters details of all the players from team b. which option will her view the data for team a and team b in two separate sections after printing? a. page break view b. freeze pane view c. split screen view d. full screen view e. zoom out view
Answers: 1
question
Computers and Technology, 24.06.2019 23:40
Which slide should you change so it reflects om all sides of your presentation
Answers: 1
question
Computers and Technology, 25.06.2019 17:20
In a display device, response rate is the time it takes for one pixel to change from black to white then back to black. a. true b. false
Answers: 1
You know the right answer?
The goal of this lab is to write a code, Birthday. java, for conducting an experiment to test the Bi...
Questions
question
Mathematics, 29.06.2019 11:30
Questions on the website: 13722361