Objective: Using Arrays
Birthday problem. What are the chances that two or more people in a room share the same birthday?
Part I:
Suppose that people enter an empty room until a
pair of people share a birthday. On average, how many people will
have to enter before there is a match?
Write a program Birthday.java to calculate this probability by simulation.
Assume birthdays are uniform random integers from 1 to 365.
Your program will place random numbers (birthdays) into an array until
a number (birthday) repeats.
Have this process repeat 100 times, print out the results each time.
Find the average of these 100 trials.
Part II:
This is a slight variation of the first progam. Now assume you
have a classroom with 28 students. What are the odds that at least two
have the same birthday? Again write a program to calculate
this probability by simulation. Fill an array with 28 random numbers
from 1 to 365. Determine if two or more birthdays are the same.
Repeat 100 times, print out the results each time, and print the total
number of times birthdays are the same.