CMSI 186: Homework Assignment #7

Learning Outcomes: Students will (1) implement probability calculation which solves a well-known problem; (2) be able to write their own test framework code from scratch; (3) get a chance to think analytically about a problem and use their program to verify their thinking; and (4) get practice documenting their code using the javadocs tool.

Problems About Probability Estimation

The Problem:

For this homework you must accomplish the following activities: Don't forget to javadoc your code…

  1. Make a Java program, BirthdaySolver.java, for estimating the probability that among N randomly chosen people, at least two share a birthday.

    1. The value of N will be specified as a command line argument; there is no default value
    2. You should ignore birthdays that fall on February 29, e.g., assume that they have been randomly distributed among the other 365 days of the year
    3. Solve this problem analytically in your head, as well as programmatically – and make sure that your program and your analysis confirm one another!
    4. Your program should be able to simulate one million experiments or more, and provide feedback to the user if it is taking a long time. The number of experiments will be specified as a second command line argument, with a default value of 100,000.
    5. Make sure that you handle any errors that arise from user input, as usual. NOTE: my test script will check for input errors that your code should catch!
    6. You are free to write as few or as many extra methods as you see fit.
    7. Your program must output TWO NUMBERS:
      • the actual probability calculation as described in class
      • the approximation made using the number of experiments
    8. Create a test harness batch file or shell script that will run your program at least 20 times, with varying values for N and number of experiments and output the results to a testresults.txt file using the redirection operator from the command line [>>].
    9. Write a short research report that explains, in one paragraph, how your mental analysis of the problem helped you develop your program.
    10. Use the javadocs tool to produce a set of documentation for this project; make sure there are no errors when you run the tool on your program code.

    You will submit your program, your testresults.txt file, your test harness script, and your research report as the products for this assignment.

    Notes:

    1. No notes for this assignment at this time.
    2. There are some pictures, though:
      1. birthdayproblem01
      2. birthdayproblem02
      3. birthdayproblem03
      4. birthdayproblem04
      5. birthdayproblem05
      6. birthdayproblem06

    Submission Guidelines: Make a sub-directory in your repository as mentioned above, called homework07 and commit your source code into it. DON'T FORGET TO ADD A COMMIT COMMENT!