CS100J Spring 2004
Project 5
Due Thursday 4/15 at 3pm

0. Objective

Completing all tasks in this assignment will help you learn about: First skim, and then carefully read the entire assignment before starting any tasks! You must use the identifiers (variable names, method names, etc.) exactly as we specify, including capitalization. Use good programming style and observe the style guidelines that are given in the previous grading guides.

1. Our second risky experiment

We will build on the skills we learned from Project 4. In Project 5, we will have Dice, a DiceSet, and we will simulate the rolling of multiple Dice in a DiceSet and calculate some statistics. You will be implementing a class Dice that is different from the Dice class in P4, so make sure that you keep your files for P5 in a separate directory (path) from P4.

Read carefully and think about implementing the classes carefully--developing a concise implementation is part of the work in this project. Whenever possible, reduce redundancy in your code by calling other (existing) methods. Program development is an iterative process--sometimes you will write code under a method and later decide that you should take part of that code out and set it up as a separate method. This iterative process is normal--you should not expect your first implementation to be perfect. Look for improvement as (after) you write code.

Let's first look at some example output so that you know what to expect. Notice that the histogram you will draw has horizontal "bars" (rows of asterisks).

Experiment One:
Enter number of Dice you want to create: 2
Creating the 1th Die
  Enter the number of faces of for the Die: 6
  Which side is weighted more, 1-6?  Enter 0 if it's a fair die: 0
Creating the 2th Die
  Enter the number of faces of for the Die: 6
  Which side is weighted more, 1-6?  Enter 0 if it's a fair die: 0
Start simulation...
Enter the number of trials: 100000
Calculating sum of two dice...
  Enter the first die: 1
  Enter the second die: 2
The count distribution for the sum of Dice 1 and 2:
1
2   **
3   ***
4   *****
5   *******
6   ********
7   **********
8   ********
9   *******
10  *****
11  ***
12  **
Another example run is shown at the end of the project statement.

2. A new class Dice

A Dice has Class Dice has the following instance methods:

3. Class DiceSet

A DiceSet is a set of Dice, of course! A DiceSet has

A DiceSet has the following methods:

4. Class P5 for simulation

In the main method, you will run several experiments.

6. Another example run

Experiment Two:
Enter number of Dice you want to create: 2
Creating the 1th Die
  Enter the number of faces of for the Die: 6
  Which side is weighted more, 1-6?  Enter 0 if it's a fair die: 0
Creating the 2th Die
  Enter the number of faces of for the Die: 6
  Which side is weighted more, 1-6?  Enter 0 if it's a fair die: 3
  Enter the weight for side 3: 5
Start simulation...
Enter the number of runs: 100000

The count distribution of Dice 1:
1   **********
2   **********
3   **********
4   **********
5   **********
6   **********

The count distribution of Dice 2:
1   **
2   **
3   **********
4   **
5   **
6   **

7. Submitting Your Work

Submit your files Dice.java, DiceSet.java, and P5.java on-line using CMS (Course Management System) before the project deadline. Make sure you are submitting the correct, up to date, .java files (not .class or .java~). We will not accept any files after the deadline for any reason (except for documented medical reasons). See the CMS link on the web page for instructions on using CMS. If necessary, turn off the DrJava feature that saves the .java~ files (see course webpage announcement on 2/17 for instructions).