If more than 23 people are selected at random, the chance that two of them have birthdays on the same
day is more than 50%. While this may sound counterintuitive, it is fairly easy to verify that this indeed
is the case. Furthermore, only 14 people are needed for there to be more than a 50% chance that at least two
of them have birthdays within one day of each other.
Create a class NearBirthdays containing the method probability which calculates the probability
that at least two people among noPeople have birthdays within withinDays days (inclusive)
of each other.
The method should take as input an int noPeople, an int withinDays,
and an int daysInAYear, the number of days in a year, and return the probability
as a double. Assume that each day in a year is equally likely to be a birthday for someone.
|