Question
Lab 13: Java Arrays

The Birthday Coincidence

Objectives: Java Arrays (chapter 7)

Part 1
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 BirthdayCoincidence. java to simulate one experiment
The output of this program is the number of people that were added until a pair has matching birthdays.

Assume birthdays to be uniform random integers between 1 and 365. So, 1 representsJanuary 1; *** 31 represents January 31, 32 represents February 1, 33 represents February 2; and so on until 365 representing December 31.

Part 2

Then write a program BirthdayCoincidenceAverage.java to repeat the experiment many times and estimate the average value.

The number of trials to repeat the experiment should be specified via a command-line argument args [0], or using Scanner, or JoptionPane.showInputDialog()

Try it with several very large numbers of trials, c.g. 10,000, 100,000 or 1,000,000. The output of this program is the average number of people that were added until a birthday match occurred.
Solution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references.
Students may use these solutions for personal skill-building and practice.
Unethical use is strictly forbidden.

import java.util.ArrayList;

/*
* BirthdayCoincidence class
*/
public class BirthdayCoincidence {

    // Main method for program execution
    public static void main(String[] args) {
       // ArrayList to store birthdays
       ArrayList<Integer> birthdays = new ArrayList<Integer>();
       // Run in a loop
       while (true) {
            // Person enters with random birthday 1 to 365
            int birthday = (int)(Math.
This is only a preview of the solution.
Please use the purchase button to see the entire solution.
By purchasing this solution you'll be able to access the following files:
BirthdayCoincidence.java
BirthdayCoincidenceAverage.java
Purchase Solution
$25.00
Google Pay
Amazon
Paypal
Mastercard
Visacard
Discover
Amex
View Available Computer Science Tutors 645 tutors matched
Ionut
(ionut)
Master of Computer Science
Hi! MSc Applied Informatics & Computer Science Engineer. Practical experience in many CS & IT branches.Research work & homework
5/5 (6,808+ sessions)
1 hour avg response
$15-$50 hourly rate
Pranay
(math1983)
Doctor of Philosophy (PhD)
Ph.D. in mathematics and working as an Assistant Professor in University. I can provide help in mathematics, statistics and allied areas.
4.6/5 (6,701+ sessions)
1 hour avg response
$40-$50 hourly rate
Leo
(Leo)
Doctor of Philosophy (PhD)
Hi! I have been a professor in New York and taught in a math department and in an applied math department.
4.9/5 (6,469+ sessions)
2 hours avg response

Similar Homework Solutions