Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA Part I: Consider a group of 10 random people. What are the chances that the group has two people that share a birthday (same

JAVA

Part I: Consider a group of 10 random people. What are the chances that the group has two people that share a birthday (same date but not year). Thus, if say the 2nd person and 7th person in the group both have birthdays on March 15, then the group has such a pair. Now, it could be that three people share a birthday, which still satisfies the property (at least two people share a birthday. The goal is to evaluate the probability that a group of N people has at least two people that share a birthday.

Part II: This is a slight variation of the above problem in which we want to see if a group of N people have birthdays on successive days. Thus, we could have a shared birthday if there are two people with birthdays on March 14 and March 15, or if the group has two people with birthdays on December 31 and January 1.

***Assume 365 days in a year and think about using an array.

Write all your code IN BirthdayProblems.java, which has everything you need including the random(K). method:

import java.util.*; public class BirthdayProblems { public static void main (String[] argv) { // This is there just for you to compile and run, to see // how a random number generator is used. testRandom (); int N = 10; double p = sharedBirthdayProbability (N); System.out.println (p); // Experiment with N to see what value of N gets p closest to 0.5. int M = 10; double q = consecutiveBirthdayProbability (M); System.out.println (q); // Experiment with M to see what value of M gets q closest to 0.5. } static double sharedBirthdayProbability (int N) { // WRITE YOUR CODE HERE. // A particular case or instance is when N people have // been assigned birthdays randomly. We are interested in // whether there are any two people with a shared birthday. // Make 1000 such cases and identify in how many cases you find // two people with a shared birthday. For example, if in 151 cases // you find such shared birthdays, then the probability of a // shared birthday among N people is 151/1000 = 0.151 (which is // what you return). Assume 365 days in a year. // Temporarily (just so that it will compile): return 0; } static double consecutiveBirthdayProbability (int N) { // WRITE YOUR CODE HERE. // A slight variation of the shared birthday problem is to look // for cases where there exist two people have birthdays // on consecutive days. You also have to account for two people who // could have birthdays on the first and last days of the year. // Temporarily: return 0; } static void testRandom () { // Make 10 random choices picking between 0 and 5. for (int i=0; i<10; i++) { int k = random (6); // If we want between 0 and 5 inclusive. System.out.println (k); } } static int random (int K) { // Return a random integer between 0 to K-1 (0 and K-1 inclusive). Random rand = new Random (); int m = rand.nextInt (K); return m; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems Analysis And Synthesis Bridging Computer Science And Information Technology

Authors: Barry Dwyer

1st Edition

0128054492, 9780128054499

More Books

Students also viewed these Databases questions

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago