CS 35

Program 1

due Tuesday 30 Jan by midnight

This assignment was inspired by an article on mathematical proof in the January-February issue of "American Scientist" in which columnist Brian Hayes admits to incorrectly deriving the probability that in a world series of two evenly matched teams, one will win in a four game sweep. He points out that proofs can sometimes be slippery and asserts that he discovered his error because his derived answer did not match the results of computer simulation he wrote.

The Assignment
Write, debug, and test a Java program that simulates n world-series-like playoffs. Allow the user to specify n. Also, allow the user to specify the number of games it takes to win a single series (e.g. 2 for womens tennis, 3 for men's tennis ( Australian Open ), 4 for world series ( World Series ) ), and the probability that team-a will beat team-b in any single contest.

Your output should show how many of the simulated series were won by each team. For each possible number of games in a series, your output should show how many of the simulated series took that many games.

For extra fun (but NOT required), you could show for each length series, how many were won by a and how many by b.

Here are a couple of sample runs of my solution:

Script started on Tue Jan 23 10:30:11 2007 dill% java Wseries2 This program will simulate a number of world-series-like playoffs. You may supply the number of series to simulate, the number of games it takes to win a series, and the probablility that team-a beats team-b. How many series should we simulate (1-100000)? 100000 How many games to win one series (1-5)? 4 In any single game, what is the probability that team a beats team b (0.0-1.0)? 0.5 Of the 100000 series simulated: team a won: 49901 team b won: 50099 12374 of them took 4 games. 24980 of them took 5 games. 31136 of them took 6 games. 31510 of them took 7 games. Here is a table showing series length, number of series of that length in the simulation, and for each series length, the number of each team's wins in that length series. length number awins bwins 4 12374 6093 6281 5 24980 12446 12534 6 31136 15597 15539 7 31510 15765 15745 dill% java Wseries2 This program will simulate a number of world-series-like playoffs. You may supply the number of series to simulate, the number of games it takes to win a series, and the probablility that team-a beats team-b. How many series should we simulate (1-100000)? 100000 How many games to win one series (1-5)? 4 In any single game, what is the probability that team a beats team b (0.0-1.0)? 0.6 Of the 100000 series simulated: team a won: 71060 team b won: 28940 15351 of them took 4 games. 26988 of them took 5 games. 29694 of them took 6 games. 27967 of them took 7 games. Here is a table showing series length, number of series of that length in the simulation, and for each series length, the number of each team's wins in that length series. length number awins bwins 4 15351 12828 2523 5 26988 20849 6139 6 29694 20532 9162 7 27967 16851 11116 dill% java Wseries2 This program will simulate a number of world-series-like playoffs. You may supply the number of series to simulate, the number of games it takes to win a series, and the probablility that team-a beats team-b. How many series should we simulate (1-100000)? 100000 How many games to win one series (1-5)? 2 In any single game, what is the probability that team a beats team b (0.0-1.0)? 0.5 Of the 100000 series simulated: team a won: 49957 team b won: 50043 50101 of them took 2 games. 49899 of them took 3 games. Here is a table showing series length, number of series of that length in the simulation, and for each series length, the number of each team's wins in that length series. length number awins bwins 2 50101 25097 25004 3 49899 24860 25039 dill% java Wseries2 This program will simulate a number of world-series-like playoffs. You may supply the number of series to simulate, the number of games it takes to win a series, and the probablility that team-a beats team-b. How many series should we simulate (1-100000)? 100000 How many games to win one series (1-5)? 3 In any single game, what is the probability that team a beats team b (0.0-1.0)? 0.5 Of the 100000 series simulated: team a won: 50013 team b won: 49987 25278 of them took 3 games. 37482 of them took 4 games. 37240 of them took 5 games. Here is a table showing series length, number of series of that length in the simulation, and for each series length, the number of each team's wins in that length series. length number awins bwins 3 25278 12704 12574 4 37482 18586 18896 5 37240 18723 18517 dill% java Wseries2 This program will simulate a number of world-series-like playoffs. You may supply the number of series to simulate, the number of games it takes to win a series, and the probablility that team-a beats team-b. How many series should we simulate (1-100000)? 100000 How many games to win one series (1-5)? 3 In any single game, what is the probability that team a beats team b (0.0-1.0)? 0.75 Of the 100000 series simulated: team a won: 89543 team b won: 10457 43592 of them took 3 games. 35180 of them took 4 games. 21228 of them took 5 games. Here is a table showing series length, number of series of that length in the simulation, and for each series length, the number of each team's wins in that length series. length number awins bwins 3 43592 42033 1559 4 35180 31611 3569 5 21228 15899 5329 dill% ^Dexit Script done on Tue Jan 23 10:35:30 2007 dill% Send me a tarball of a directory named by the first 4-letters of your last name. That directory should contain the Java source code for all the files needed for a solution. It should also contain a README text file that tells me what your program can do and how to run it.

See /home/cfk/pub/cs35/week1/tarballREADME for an example of building a tarball.

This week only Alex will be doing both Sunday and Monday clinic sessions.

I should receive the email with tarball attached before midnight on the due date for a program.