Lab 18: More on Object-Oriented Programming

Problem

You are given in this lab a couple of classes. The 'main' class is LotsOfDiceRoller.java. The code is reasonably written but not very 'object oriented'. There is also a class called Die. This class is complete and needs no additional work.

You will write a class that will be a container for a number of Die. I have given a skeleton of code for the new class, DieCollection. There are instructions in the file LotsOfDiceRoller.java in comments starting with 'TODO'. Follow the comments and make the changes suggested. The new code should use only DieCollection (and DieCollection should hold an array with a collection of Die objects.) This will make the code much more object-oriented.

Download and work on the following four files:

Start by running the existing code. The code should work. It provides a menu allowing you to change the number of faces on a die, change the number of dice, and roll the dice. Play with the program and see how it responds. After that, begin making the changes. Modify the code given for DieCollection adding in the code I describe. You may want to create a 'UseDieCollection' class to test the various methods as you write them (it is your choice.)

When DieCollection is complete, start making the modifications in LotsOfDiceRoller.java to create a DieCollection object and use that for all the functions in the program rather than a local array and local variables in main.

Make sure that your program works correctly. If you have difficulties, please get help during the lab and also outside the lab if you did not finish it in the lab. Your instructor, TAs, and tutors are available to help.

When you are done:

When you are done with these, feel free to leave the lab.