Given a group of N people, how large must N be so that there is a 50%
Fantastic news! We've Found the answer you've been seeking!
Question:
* Perform an experiment simulating the birthday problem.
* Pick random birthdays for the given number of people.
* Return the number of pairs of people that share the
* same birthday.
* @param numPeople The number of people in the experiment.
* This value must be > 0
* @param numDaysInYear The number of days in the year for this experiement.
* This value must be > 0
* @return The number of pairs of people that share a birthday
* after running the simulation.
*/
public static int sharedBirthdays(int numPeople, int numDaysInYear) {
// check preconditions
if (numPeople <= 0 || numDaysInYear <= 0) {
throw new IllegalArgumentException("Violation of precondition: " +
"sharedBirthdays. both parameters must be greater than 0. " +
"numPeople: " + numPeople +
", numDaysInYear: " + numDaysInYear);
}
}
Transcribed Image Text:
4. shared Birthdays: The birthday problem is a question where most people's intuition is proved incorrect by mathematics. The problem is: Given a group of N people, how large must N be so that there is a 50% chance that at least 2 of the N people have the same birthday? Write a method with two parameters, the number of people in a group and the number of days in the year. The method will generate random birthdays for the number of people and then determine how many pairs of people have the same birthday. You don't have to generate actual days of the year for the birthdays. You can simply use ints. Here are two ways to generate random ints in Java. One uses an object of type Random and the other uses the random method from the Math class. // fist approach Random r= new Random(); int max= 10; int x = r.nextInt (max); // x will now hold a value between 0 and 9 inclusive. // The distribution of values in uniform. // second approach int max = 10; int x = (int) (Math.random() * max); // x will now hold a value between 0 and 9 inclusive. // The distribution of values in uniform. If three people (Olivia, Kelly, Isabelle) share the same birthday, that is 3 pairs of people: pair 1: Olivia and Kelly pair 2: Olivia and Isabelle pair 3: Kelly and Isabelle /* Perform an experiment simulating the birthday problem. Pick random birthdays for the given number of people. Return the number of pairs of people that share the same birthday. pre: numPeople > 0, numDays InYear > 0 post: The number of pairs of people that share a birthday after randomly assigning birthdays. */ public static int sharedBirthdays (int numPeople, int numDays InYear) { After completing the method run the following experiments: Perform 1,000,000 experiments with 365 days per year and 182 people per experiment. What is the average number of pairs of people with shared birthdays? (Write a method to automate this experiment and put the code in CodeCamp.java.). Include your answer in a comment at the top of your CodeCamp Tester.java program. How many people do you think it takes so there is a 50% chance that at least 2 of the people have a shared birthday in a 365 day year? Perform 50,000 experiments with 365 days per year and vary the number of people from 2 to 100. 50,000 runs with 365 days, and 2 people, 50,000 runs with 365 days and 3 people, ... 50,000 runs with 365 days and 100 people. Total of 4,950,000 runs, 50,000 runs per experiments * 99 experiments = 4,950,000 runs. For each of the given number of people determine the percentage of experiments where at least one pair of people shared a birthday. At what number of people (between 2 and 100) does the percentage first exceed 50%? Does the answer surprise you? How did it compare to your predicted answer? Include a table in a comment in your CodeCampTester.java program with the results of this experiment using the following format: Num people: 2, number of experiments with one or more shared birthday: 120, percentage: 0.24 Num people: 100, number of experiments with one or more shared birthday: 50000, percentage: 100.00 At the top of the table state how many people it requires to have a 50% chance of there being at least 1 shared birthday, given a 365 day year. Note, in the version of the program you turn in, list your results in a comment, but do not include any code that calls your methods that perform these experiments. 4. shared Birthdays: The birthday problem is a question where most people's intuition is proved incorrect by mathematics. The problem is: Given a group of N people, how large must N be so that there is a 50% chance that at least 2 of the N people have the same birthday? Write a method with two parameters, the number of people in a group and the number of days in the year. The method will generate random birthdays for the number of people and then determine how many pairs of people have the same birthday. You don't have to generate actual days of the year for the birthdays. You can simply use ints. Here are two ways to generate random ints in Java. One uses an object of type Random and the other uses the random method from the Math class. // fist approach Random r= new Random(); int max= 10; int x = r.nextInt (max); // x will now hold a value between 0 and 9 inclusive. // The distribution of values in uniform. // second approach int max = 10; int x = (int) (Math.random() * max); // x will now hold a value between 0 and 9 inclusive. // The distribution of values in uniform. If three people (Olivia, Kelly, Isabelle) share the same birthday, that is 3 pairs of people: pair 1: Olivia and Kelly pair 2: Olivia and Isabelle pair 3: Kelly and Isabelle /* Perform an experiment simulating the birthday problem. Pick random birthdays for the given number of people. Return the number of pairs of people that share the same birthday. pre: numPeople > 0, numDays InYear > 0 post: The number of pairs of people that share a birthday after randomly assigning birthdays. */ public static int sharedBirthdays (int numPeople, int numDays InYear) { After completing the method run the following experiments: Perform 1,000,000 experiments with 365 days per year and 182 people per experiment. What is the average number of pairs of people with shared birthdays? (Write a method to automate this experiment and put the code in CodeCamp.java.). Include your answer in a comment at the top of your CodeCamp Tester.java program. How many people do you think it takes so there is a 50% chance that at least 2 of the people have a shared birthday in a 365 day year? Perform 50,000 experiments with 365 days per year and vary the number of people from 2 to 100. 50,000 runs with 365 days, and 2 people, 50,000 runs with 365 days and 3 people, ... 50,000 runs with 365 days and 100 people. Total of 4,950,000 runs, 50,000 runs per experiments * 99 experiments = 4,950,000 runs. For each of the given number of people determine the percentage of experiments where at least one pair of people shared a birthday. At what number of people (between 2 and 100) does the percentage first exceed 50%? Does the answer surprise you? How did it compare to your predicted answer? Include a table in a comment in your CodeCampTester.java program with the results of this experiment using the following format: Num people: 2, number of experiments with one or more shared birthday: 120, percentage: 0.24 Num people: 100, number of experiments with one or more shared birthday: 50000, percentage: 100.00 At the top of the table state how many people it requires to have a 50% chance of there being at least 1 shared birthday, given a 365 day year. Note, in the version of the program you turn in, list your results in a comment, but do not include any code that calls your methods that perform these experiments.
Expert Answer:
Related Book For
Elementary Statistics A Step By Step Approach
ISBN: 9780077665807
9th Edition
Authors: Allan G. Bluman
Posted Date:
Students also viewed these programming questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
The wedding date for a couple is quickly approaching, and the wedding planner must provide the caterer an estimate of how many people will attend the reception so that the appropriate quantity of...
-
The wedding date for a couple is quickly approaching, and the wedding planner must provide the caterer an estimate of how many people will attend the reception so that the appropriate quantity of...
-
Q1: How would a supply chain management and customer relationship management system help the company? What are limitations? 1 answer
-
The tractor has a weight of 8000 lb with center of gravity at G. Determine the greatest weight of the log that can be pushed up the incline. The coefficient of static friction between the log and the...
-
Why do critics say globalization adversely affects labor standards, environmental regulations, and future markets?
-
We shall now extend the result of Proposition 6.2.5.3 by computing the Laplace transform \[\mathbb{Q}_{x}^{\delta}\left[\exp \left(-\lambda \int_{0}^{t} d u \phi(u) ho_{u} ight) ight]\] In fact, let...
-
Selected pre-adjustment account balances and adjusting information of Sunset Cosmetics Inc. for the year ended December 31, 2011, are as follows: Retained Earnings, January 1, 2011 . . . . . . . . ....
-
Chloe consumes only books (x) and video games (y). Her preferences can be represented by the following utility function: U(x, y) = xy2. The price of books is Px, the price of video games is Py, and...
-
Mary is planning her wedding and develops the following preliminary information. For this problem, the normal times have been changed from OM3 a. Draw the network for this project. b. What is the...
-
A ball is dropped from a height of 6feet and begins bouncing as shown in the figure. The height of each bounce is three-fourths the height of the previous bounce. Find the total vertical distance the...
-
historical demand for a product goes as follows: using simple linear regression, calculate the trendline. say the x axis is 1 for april , 2 for many and so on and so on. Calculate a forecast for...
-
4. You are given a relational schema R = ABC, satisfying the following FDs 1. A B 2. AC 3. B C (a) Which normal forms are satisfied? (b) A decomposition into AB and AC is proposed. i. Which normal...
-
Discuss how personal insurance needs are similar or not similarto business needs. Choose and describe an insurance product that can be utilized in your personal life and how it can minimize your...
-
Imagine your client would like to complete a tax inversion, acquiring a foreign company in Switzerland and moving the domicile of the combined company overseas. Your client believes that this will...
-
discuss examples from your past, either at work, or university, where communication between levels caused problems. What was the cause of these issues? In what ways could this have been improved?...
-
Case Assignment: Nucor Corporation Nucor Corporations mission is to Take Care of Our Customers by being the safest, highest quality, lowest cost, most productive, and most profitable steel company in...
-
Interest Compounded Annually. When P dollars is invested at interest rate i, compounded annually, for t years, the investment grows to A dollars, where A = P(1 + i) t . Trevor's parents deposit $7800...
-
For Exercises identify the independent and dependent variables for each study. It was found that laughing can reduce your aches and pains as much as taking a pain pill.
-
Explain what is meant by a significant difference.
-
The regression line is called the________ .
-
Figure 7.18 shows a liquid-level system in which two tanks have cross-sectional areas \(A_{1}\) and \(A_{2}\), respectively. The volume flow rate into tank 1 is \(q_{\mathrm{i}}\). A pump is...
-
For the three-room house shown in Figure 7.35, all rooms are perfect squares and have the same dimensions. An air conditioner produces an equal amount of heat flow \(q_{\mathrm{ho}}\) out of each...
-
Consider the single-tank liquid-level system shown in Figure 7.19, where the volume flow rate into the tank through a pipe is \(q_{\mathrm{i}}\). The liquid leaves the tank through an orifice of area...
Study smarter with the SolutionInn App