header

Homework 14

Write an application that uses your Dice class to simulate an experiment that consists of rolling a pair of dice a specified number of times.

Output Specification

Generate a table with three columns: Dot Sum, Frequency, and Probability. The body of the table will contain the frequencies and probabilities for dot sums ranging from 2 to 12.

Input Specification

The user will enter the number of trials in the simulated experiment from the keyboard.

Process Specification

Roll the dice the specified number of times keeping track of the number of times you got 2, 3, 4, and so on. After the dice have been rolled the specified number of times, calculate the empirical probabilities by dividing the observed frequencies by the number of trials. For example, in the first experiment in the sample run shown below, a dot sum of 2 occurred 25 times in 1,000 rolls of the dice. The empirical probability of getting a dot sum of 2 is 25/1000 or 0.025. The sum of the frequencies should always be the number of trials and the sum of the probabilities should always be exactly 1.

Interface Specification

Your application should utilize a graphical user interface that has a text field for the number of trials, a text area to display the output, a button to clear the output area, a button to run the experiment, and a button to terminate the program.

Sample Runs

The first sample run represents an experiment with 1,000 trials. Your results should be similar but not exactly the same because we are simulating random events.

1000 trials

The second sample run represents an experiment with 1,000,000 trials. Your results should be similar but not exactly the same because we are simulating random events.

1000000 trials

Bonus Points

I'll give you 5 bonus points if your application looks like the illustration below without any resizing necessary.

Alternate Interface

Submitting Your Work

Submit your Hmwk14.java application and your Dice.java class file as attachments to an email message whose subject is "Hmwk14".