Homework Assignment H05: Simulate a pair of dice.

Purpose

We are going to continue our problem-solving education by writing a program that uses a function to simplify the problem solving process. The program will repeatedly call the function to get the number of times it takes to roll a particular value for a pair of dice. The program can build the table by looping over the different target values.

We will also get more practice using Eclipse to make our programming life easier.

Tasks

1. Create a package named edu.ics111.h05 in your ICS111-workspace project

This is where we will put all our classes for homework 05.

2. Using the Programming Algorithm write a program named SixSidedPair that calculates the number of times it takes to roll all the possible values for a pair of dice.

Write a program that simulates rolling a pair of dice. The program will output a table similar to the following:

Average number of tries: 
 # : tries
 2 : 40.30
 3 : 18.80
 4 : 12.29
 5 :  9.11
 6 :  7.10
 7 :  7.19
 8 :  7.44
 9 : 10.69
10 : 10.79
11 : 19.50
12 : 34.25

The program should have a function that return the number of times it takes to roll two six sided dice to get the given number. To calculate the average number of tries your program should call the function several times and sum up the number of tries. Then divide by the number of times the function was called.

Hint You can use the System.out.printf(<format string>, variables) method to format your output. You can use System.out.printf("%2s: %4.2f\n", tries, average);. The %2s means a 2 wide string with leading spaces. The %4.2f means a 5 wide floating point with 2 digits before the ‘.’ and 2 digits after. The \n means put a new line after the floating point number.

Bonus Problem: Write another program named SelectSidedPair that asks the user for the number of sides the dice and prints out the resulting table.

Write another program to have a member variable that stores the number of sides of the dice. Note: This will change the output.

Grading Rubric

CriterionExcellent (100%)Satisfactory (75%)Borderline (50%)Unsatisfactory (25%)Poor (0)
Adherence to standards - 2 points
Does it conform to standards in every detail?
No errors. Minor details of the assignment are violated, or poor choices are made where the assignment is unclear. Significant details of the assignment or the underlying program intent are violated, but the program still fulfills essential functions. Significant details of the assignment or the underlying program intent are violated, but the program still fulfills some essential functions. Misses the point of the assignment.
Breakdown (modular design) - 2 points
Does it demonstrate good modular design?
No errors. 1-3 minor errors. > 3 minor errors OR 1 major error. 2 major errors > 2 major error.
Correctness of code - 4 points
Does it work? Does it pass JUnit?
Passes all tests. Works for typical input, may fail for minor special cases. Fails for typical input, for a minor reason. Fails for typical input, for a major reason. No.
Documentation, and style - 2 points
Is it clear and maintainable? Does it pass CheckStyle?
No errors. 1-3 minor errors. > 3 minor errors OR 1 major error. 2 major errors > 2 major error.

Turning in the Assignment

The assignment is due on Friday, October 1st at 11:55pm. You may turn it in early.