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, 22.06.2019 11:00
The isometric projection camera technique provides an illusion of perspective by using things like parallax scrolling to create the illusion of 3d in a 2d game
Answers: 3
question
Computers and Technology, 22.06.2019 18:30
Word vocabulary words: print, proofread, status line, graphics, font effects, left margin, justification, line spacing, copy/paste, data. review words: font point, bold, save, center, error. fill in the correct word for the definition and then transfer the letters to the appropriate spot by number. some numbers will be found multiple times. you will end up with a quotation about…… what else? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 k 16 17 18 19 20 21 22 23 24 25 8 27 28 29 w 31 32 k 34 35 36 w h 39 40 41 42 8 44 45 46 47 48 49 50 51 52 53 54 55 .1. a software function that records keystrokes on a disk or drive so information can be 5 4 52 9 later retrieved. p n 2. to produce a paper copy of information. 10 7 12u n 3. a display that shows the location of the cursor, pages, etc. 45 46 18 27 36 20 42p4. pictures or images, located in clip art or other files. 6 24 44 28 34 49 555. any mis-stroke of a key. 47 41 48 2 10 n6. allows major changes to the font such as shadow, emboss, etc. 21 25 46 35 23 21 29 14 22 17 n7. a feature that centers lines of text horizontally. 49 53 46 9 51 p8. size of the font 31 16 22 b l 9. a feature that prints designated text darker than the rest to add emphasis. 32 3 . p10. to compare copy on a display screen or printout to the original 24 39 25 23 54 9 50 3 and correct errors. j un 11. a feature that allows text to be aligned at the left 11 12 7 21 16 49 40 46 34 2 and right margins. leftn 12. amount of blank space on the left side of the paper. 8 18 41 6 34 linen 13. number of blank lines between lines of text. 17 4 49 13 1914. any information inputted into the computer. 3 4 46 44 p /p15. feature that duplicates text from one location and places it in another.
Answers: 2
question
Computers and Technology, 23.06.2019 09:00
The first screen you see when you open word2016 what is called?
Answers: 1
question
Computers and Technology, 23.06.2019 13:30
Spoons are designed to be used for: spring hammering. applying body filler. identifying high and low spots. sanding highly formed areas.
Answers: 3
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
English, 05.06.2020 17:58
question
History, 05.06.2020 17:58