600.107 Introduction to Programming in Java
Homework #8 -- Due 11:30pm on Tuesday 11/7

Overview

The purpose of this assignment is gain practice writing classes to define our own data types. We will also continue to explore the use of random data, and checkstyle. You'll need to get some files from HW8start.zip file.

Deliverables: Submit a complete zip file named HW8-jhedLogin.zip, substituting your actual JHED login as the second part of the file name. Make sure that this includes all the source code (*.java) files needed for each part (ie, the class definition and the main test program).


Part A: More Time

For the first part of this assignment you will be adding some functionality to the Time class we explored in lecture. The starter zip file for this assignment contains Time.java and TimeMain.java programs (also posted on the schedule). Your job is to add the following instance methods to the Time class, as well as statements in the TimeMain.java program to test whether or not they work correctly. These are the new public methods:

The actual code to implement some of these methods are operations you have already written in other contexts for prior assignments. We are simply structuring the data differently now for an object-oriented approach. Also remember that these methods can call each other in order to reuse and simplify code. In addition to these methods, you are welcome to add other helper methods that can make programming these easier (such as a minutesSinceMidnight method that gives you the total time in minutes only). Make sure that your Time.java revised class definition is checkstyle compliant.

You must call each of the new public methods at least 2-3 times in the test program TimeMain.java so you are sure that all cases they need to handle work correctly. This main program should also be checkstyle compliant, with the exception of allowing magic numbers for testing convenience.

Make sure that you include the updated Time.java class definition and the updated TimeMain.java test file in your submitted zip.

Part B: Player Class

Suppose we want a program to play the LCR dice game (see Wikipedia for more details). Here's how the game works: there are three dice for the game. One side of each has an L (left), one an R (right), one a C (center) and the other three sides have dots. When the game starts each player has 3 chips. Taking turns, the players then roll the dice - all 3 if they have at least 3 chips, 2 if only 2 chips, 1 if only 1 chip, and no roll if no chips. Then the player moves chips according to the dice roll results. For each L you roll, you must give a chip to the player on your left, for each R a chip to the player on your right, and C to a center pile. A dot means to keep a chip. The last player to have any chips is the winner and gets the center pot. Chips that go into the center pile stay there. If you run out of chips you are still in the game because one of your neighbors (player to left or right) might give a chip(s) to you on his/her next turn.

In this part of the assignment you will only write a class called Player to hold and manipulate data for one player in the LCR game. All data members must be private. We have written a test program for you, that should clearly identify for you what the names, parameter types and return values (if any) should be for each of these methods. Start by reading that file! You must have public methods to:

In addition to those instance methods, your Player class must have a class (static) method that will simulate one roll of an LCR die and return the result as a character ('L', 'C', 'R', or '.') in accordance with the expected probabilities of each (remember: 3 sides are a dot (50%), and there is one side each (so 1/6 chance) for the other three characters).

Your class is required to work with our test program, PlayerTest.java, available in the starter zip for this assignment. You are absolutely not allowed to change PlayerTest.java in any way. Failure to successfully compile both files together will result in failing this part of the assignment. So please read the driver (test) program and make sure you understand it before you write your Player class.

Don't forget to include javadoc style comments on all the methods and data members of your class and make sure it is checkstyle compliant in all respects. Make sure that you include your Player.java class definition and the unchanged PlayerTest.java test file in your submitted zip.


General assignment requirements, style and submission details: