CPE 102

Winter 2008

Lab 3

 

Errata:

      None any updates or corrections will appear here.

Objectives

 

Resources

 

 

Ground Rules

 

 

Orientation

 

You will be developing two classes to support the dice game of Threes and that work with the provided game driver (Threes.java). Note that the provided game driver expects mostly correct input from the user no guarantees if you respond to its prompts with unexpected values! The Die class will make use of the Random class from the Java Standard API to simulate random behavior of rolling an actual die. The Roller class will allow you to roll more than one die at a time and will make use of the Die class.

While developing these classes, we will introduce the idea of test-driven development. Test-driven development is a software engineering technique in which test cases are written before implementation. The primary benefit of test-driven development is that it forces developers to design and plan their classes and implementation before jumping in to code it. In test-driven development, developers write a test for a single method or piece of functionality at a time, followed by implementing the method or functionality. After the tests pass successfully and the code is sufficient, developers write tests for the next method or piece of functionality. Test-driven development does not mean writing an entire class's tests before writing its implementation.

For this lab, you will be expected to follow the given class specifications. As a result, you will not completely be following test-driven development principles (since you won't be expected to design your classes through this process). You will, however, be expected to write each test case before the associated method.

 

Part 1

 

Download the JUnit tests for the Die class (DieTest.java). Develop the Die class to meet the specification. This class uses the Java Standard Library Random class to produce the behavior of a die. Be sure to compile and run the provided unit tests (DieTest.java) to verify the class's correctness.

It is important to acknowledge that not all of these test cases are necessary; some of the tests, in fact, repeat previous cases already tested. For example, testDieEmptyConstructor() and testDieSidesConstructor() test cases are both covered in testSides(). While these tests are obviously repetitious, they are all included to demonstrate that each individual method should be tested.

 

Part 2

 

Develop the Roller class to meet the specification. This class uses the Die class and not the Random class. Following the test-driven development principles described above, you should develop this class by writing one JUnit test at a time, followed by writing the associated Roller method. Be sure that your unit tests are sufficient while making sure the constructors and methods of this class perform as specified.

 

Part 3

 

Once you think your Die and Roller classes are complete and correct download the provided copy of Threes.java, add it to your project, compile, and play the game fix anything that does not work in your code.