|
Homework #4: Rolling Dice. Design a Java application that will simulate the rolling of two dice. The program should use Math.random to roll the first die, and Math.random to roll the second die. The sum of the two values should then be calculated. Your program should roll the dice as many times as a user wants (up to a million rolls), so the program will need an InputDialog box to allow input for the number of rolls.
Your program should track the number of times each number was rolled by using an array. The summary information about the number of times each number was rolled should be displayed in tabbed format in a JTextArea in a MessageDialog box in the following manner:
It should also be noted next to each individual item of the tally how many occurences of that combinaton would theoretically be expected. EX: a seven can be rolled six different ways, so the expected number of "seven" rolls would be the total number of rolls divided by 36 (the total number of possible combinations) multiplied by 6. Therefore, out of a hundred rolls, one could expect sevens to appear in (100 / 36 * 6) rolls, or approximately 16 or 17 rolls. Note that rolling a pair of six-sided dice will return a total between (and including) 2 and 12 in 36 different possible combinations. The program should be as user-friendly as possible. The input field should be clearly labeled. The tallies should be clearly labeled. Turn in a printout of your source code (the .java file)and a diskette with the .java file on it. Name the program with your last name and first initial and the number "4". EX: BookA4.java Grading criteria:
| |||||||||||||||
|
all rights reserved.
copyright 2000, Ann Book
| |||||||||||||||