Sum of two dice, one with 6 sides and one with 8 sides
Summary class diagram for DiceStatistics
Detailed class diagram DiceStatistics

ICT-4361 Homework 3b


This exercise to to provide you an opportunity to extend the previous exercise, and generalize a new client class to reuse your existing code, and generate statistically interesting information.
Extending our dice exercise will show how to create a new class which uses arbitrary collections of the Dice class. A DiceStatistics class will run combinations of Dice, collect sample runs, and print the resulting statistics.

What to Hand In

Please hand in a listing for each program requested, formatted in an easy-to-read style, and following our Java conventions.

Ensure your name, and the name of the file is available in a comment at the top of each submitted file (excepting screenshots).

Also, ensure that you have a sample of the output from the program.

If your program fails to compile, hand in your error listing as your output.

For each question asked, provide one or two sentences summarizing your answer. Please be both complete and succinct.

Submit the files comprising your submission in a "zip" or similar archive through the assignment's submission button. Preferred file types in the archive are .java, .txt, .jpg, and .png


  1. Create a class for the collection of statistics about our Dice.
    1. Create (or modify) a DiceStatistics class to allow the programmer to:
      • create a DiceStatistics object.
        Method: DiceStatistics(int numDice).
        You may optionally also create a zero parameter constructor for DiceStatistics (Method: DiceStatistics()) which creates a DiceStatistics object with 2 (two) Dice.
      • create the number of dice from a constructor parameter.
        Method: DiceStatistics(int numDice)
      • store a provided Dice into a slot (index) in an array of Dice in the DiceStatistics object.
        Method: replaceDice(int diceNum, Dice)
        The method should return the previous Dice in the array slot (if any); if there was none, it will return null.
        The method should ensure that the requested slot is legal (index greater than or equal to zero, and less than the length of the aray).
        Also note that each time a Dice is changed in the DiceStatistics, the totals array must be recreated/reset.
      • roll each of the Dice by invoking the roll method on each Dice in the array, and returning the sum total of all the Dice.
        Method: rollOnce()
        This method shows the power of delegation, used frequently in Java.
      • print the statistics to the standard output (System.out).
        Method: printStatistics()
      • reset the statistics (e.g., before making a separate run). This needs to set all the totals to zero.
        Method: initStats()
      • Keep track of the number of times each totals (sum of all the Dice in the DiceStatistics array) occurs, based on the return value from rollOnce, in the same way we did last week.
        Manage array totals
    2. Create or modify the main of the DiceStatistics class to:
      • create a DiceStatistics object
      • create different kinds of dice (using the new Dice constructor in the process), and place them in the DiceStatistics object created in the previous step.
      • call rollOnce() some large number of times to accumulate statistics.
      • print the statistics (printStatistics() to show the results of the current run.
    3. Capture the output of printing the totals statistics, using DiceStatistics, for a pair of default dice, with at least 100,000 rolls.
    4. Capture the output of printing the totals statistics, using DiceStatistics, for three Dice of 3, 4, and 5 sides, respectively, with at least 100,000 rolls.
  2. In a short text document, or in comments in your code, describe the most popular total for each of combinations of Dice, and its percentage.



Criteria Weight
DiceStatistics class, with an appropriate constructor 20%
DiceStatistics class data members implementated and properly initialized 20%
DiceStatistcs class member functions initStats, rollOnce, and printStatistics 15%
DiceStatistcs class member function replaceDice 15%
DiceStatistics main program with 2 default Dice and output 10%
DiceStatistics main program with 3 Dice of sizes 3, 4, and 5 and output 10%
Short textual answer to question II 10%