Computers and Technology

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

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 01:40, Serenitybella
When the pc version of the spreadsheet program became available, the ibm pc quickly became the top-selling personal computer?
Answers: 3
image
Computers and Technology, 23.06.2019 00:50, AmbitiousAndProud
Representa os dados de um banco de dados como uma coleç? o de tabelas constituídas por um conjunto de atributos, que definem as propriedades ou características relevantes da entidade que representam. marque a alternativa que representa o modelo descrito no enunciado. escolha uma:
Answers: 3
image
Computers and Technology, 24.06.2019 22:00, sierrawalk2283
True or false technology is often discovered by accident
Answers: 2
image
Computers and Technology, 25.06.2019 07:50, joshbee2014
Assignment: permutations use the permutation formula   r ! ! n n p nr   to solve each problem. be sure to show all work leading to your answer. part i: solve real-world permutation problems choose any four (4) of the following five problems to solve. for each problem a) show how the permutation formula can be used to find the answer and b) write a sentence to explain the meaning of the answer for the situation. 1. to register for online banking services at a local credit union, you need to select a four-digit personal identification number, or pin code. the digits cannot be repeated. how many ways are there to arrange four digits out of the numerals 0 through 9 to create a code?
Answers: 3
Do you know the correct answer?
The goal of this lab is to write a code, Birthday. java, for conducting an experiment to test the Bi...

Questions in other subjects:

Konu
Spanish, 22.04.2020 03:10
Konu
Mathematics, 22.04.2020 03:10
Konu
Mathematics, 22.04.2020 03:11