On This Page
Overview
This assignment explores the use of object references. The lab exercies focus on static methods and object references. The assignment project uses objects to simulate a simple dice game. During the assignment, you will:
- Code a class, named
Die, that represents a die
- Code classes that hold multiple instances of the
Die class
- Optionally, construct a class that uses static methods to test a class
Note that dice come in more than the six-sided standard. Your Die class will allow for varying numbers of sides.

^ top
Lab Exercises
In these exercises you explore static methods and object references.
Specifications
- Prepare a single text file named:
exercises.txt. Record answers to all the exercises in this file, labeling each answer with the exercise number.
- Complete self-test exercises 1, 2, 3, 4, 5 and 6 on page 261 of your textbook.
- Complete self-test exercises 7, 8, 9 and 10 on page 266 of your textbook.
- Complete self-test exercises 27, 28, 29, 30 and 31 on page 291 of your textbook.
- Complete self-test exercises 32, 33, 34 and 35 on page 295 of your textbook.
- Complete self-test exercises 38, 39 and 40 on pages 312 and 313 of your textbook.
- Complete self-test exercises 43 on page 316 of your textbook.
- When finished, do not forget to upload your file to Blackboard as part of this assignment
^ top
Project Specifications
- Create a class named
Die to store the data about each die. This class must contain these constructors and methods:
public Die() // default to six-sided die
public Die(int numSides) // variable number of sides
public void roll() // randomly picks a face value
public int getValue() // returns the face value
- Create a class named
PairOfDice to store two dice. This class must contain two instance variables of the Die type, an instance variable that holds the sum of the two dice, and these constructors and methods:
public PairOfDice() // default to six-sided dice
public PairOfDice(int sides) // variable number of sides
public void roll() // roll both dice
public int getValue1() // get value of die1
public int getValue2() // get value of die2
public int getSum() // get sum of both dice
- You can use the random method of the
Math class to generate a random number from 1 to the number of sides on a die like this:
int value = (int) (Math.random() * sides) + 1;
- Your
PairOfDice class must pass all the tests of the Test Cases provided below.
- Create a class named
DiceRollerApp with a main() method that uses the PairOfDice class to roll the dice. This class must display special messages that identifies the roll for:
- snake eyes (double 1's)
- ace duece (sum of both dice is 3)
- natural (sum of both dice is 7)
- box cars (double 6's)
Have the message use the event word like those shown shown in the example operation. Also, for this application, assume that two six-sided dice are used.
- In
DiceRollerApp, keep track of the number of rolls, snake eyes, ace deuce, naturals and box cars rolled while the program is running. Display a list of totals at the end like this:
Number of rolls: 5
Snake eyes: 1
Ace duece: 1
Natural: 1
Box cars: 1
- Do not use any
package statements.
- Submit your files to Blackboard as explained in the section of this document: What to Turn In.
^ top
Example Operation
If the user chooses to roll the dice, the application rolls two six-sided dice, displays the results of each, and asks if the user wants to roll again.
Welcome to the Paradise Roller application
Roll the dice? (y/n): y
Roll 1: 2 5
Natural!
Roll again? (y/n): y
Roll 2: 2 1
Ace duece!
Roll again? (y/n): y
Roll 3: 4 6
Roll again? (y/n): y
Roll 4: 6 6
Box cars!
Roll again? (y/n): y
Roll 5: 1 1
Snake eyes!
Roll again? (y/n): n
Totals:
Number of rolls: 5
Snake eyes: 1
Ace duece: 1
Natural: 1
Box cars: 1
Also, you can download and run the asn05demo.jar file to see how it operates. Note that you cannot double-click the JAR file and must run the demo from the command line:
java -jar asn05demo.jar
Also note that the JAR file may contain some extra credit features.
^ top
Test Cases
Testing is an important part of software development. Usually, programmers develop tests for each unit of code they produce. This is know as "unit testing" and allows the programmer to verify that the code they develop works correctly.
To assist you in developing your code, I provide tests for this assignment. These tests, known collectively as "test cases", help to make sure that your assignment meets its requirements. I will use these test cases (and perhaps others) to test your assignment, and you should too. If the test cases do not pass, then you will lose points for the assignment.
Install the tests by copying the following file into the same directory as your .java source code files:
Run the tests as you would any other Java program.
^ top
Extra Credit
The following are worth extra credit points:
- Package your program as an executable JAR file following the instructions for Archive Your Files in How To Submit Homework Assignments. (1 point)
Note that you cannot double-click to run this JAR file because it is a console program. Instead, you can run it from the command line:
java -jar jarFileName.jar
- Add a separate class named
RollSimulator with a main() method that calls the roll() method of the PairOfDice class 1000 times, keeping track of the number of snake eyes, ace deuce, naturals and box cars rolled. Have the test display a table of totals at the end like this: (2 points)
Simulating roll of PairOfDice 1000 times
Totals:
Number of rolls: 1000
Snake eyes: 35
Ace duece: 56
Natural: 165
Box cars: 23
Include a main() method in the RollSimulator class to run the test.
Make certain that your README.txt file describes any extra credit attempted.
^ top
Grading Criteria
The instructor will evaluate your assignment using the following criteria. Each criteria represents a specific achievement of your assignment and has a scoring guide. The scoring guide explains the possible scores you can receive.
Some scoring guides have a list of indicators. These indicators are a sign of meeting, or a symptom of not meeting, the specific criterion. Note that a single indicator may not always be reliable or appropriate in a given context. However, as a group, they show the condition of meeting the criterion.
For information on grading policies, including interpretation of scores, see the course information page.
Lab Exercises
- 2: All exercises attempted and turned in
- 1: Some exercises completed and turned in
- 0: No exercises completed or turned in
Program Compilation
- 4: Source code compiles with no errors or warnings
- 2: Source code compiles with warnings
- 0: Does not compile
Functionality
- 10: Demonstrates mastery of the assignment
- Has extra features or demonstrates techniques beyond the assignment
- Applies concepts from the lessons appropriately
- Meets all specifications (see above) with particularly elegant solutions
- Runs to completion with no abnormal error conditions
- Generates correct output given correct input
- Behaves in a reasonable way in response to incorrect data
- All test cases pass
- 8: Has all the functionality expected of the assignment
- Demonstrates many techniques from the lesson
- Meets all specifications (see above)
- Implementation seems more complicated than necessary.
- May have one minor error
- All test cases pass
- 6: Has most of the functionality expected of the assignment
- Demonstrates some techniques from the lesson
- Meets all but one of the specifications (see above)
- Implementation seems excessively complicated.
- May have 2-3 minor errors
- All but one test case passes
- 4: Has some of the functionality expected of the assignment
- Demonstrates some techniques from the lesson
- Meets at least 1/2 of the specifications (see above)
- Implementation seems excessively complicated.
- May have more than 3 minor errors
- At least 1/2 of all test cases pass
- 2: Serious functional problems but shows some effort and understanding
- Meets less than 1/2 of the of the specifications (see above)
- Has a major error or many minor errors
- Implementation seems very convoluted
- Demonstrates few techniques from the lesson
- Less than 1/2 of all test cases pass
- 0: Does not execute
Program Style
- 4: Code is well-documented
- 3: Code has minor documentation errors
- Has 1 documentation error
- 2: Code has some documentation errors
- Has 2-3 documentation errors
- 1: Code has many documentation errors
- Has more than 3 documentation errors
- 0: No apparent attempt to document code
README.txt File
- 2: README.txt file submitted with specified information included
- 1: README.txt submitted but some information was not included
- 0: No README.txt submitted
Maximum Score: 22, plus extra credit
^ top
What to Turn In
Submit your assignment following the instructions for homework. Include the following items for grading:
README.txt file
exercises.txt
Die.java
PairOfDice.java
DiceRollerApp.java
- Optionally,
RollSimulator.java (extra credit)
- Optionally, all the class and source code files in the same JAR file
You must submit all the files needed for your assignment to compile and work correctly. Do not assume that the instructors has any files. Also, do not turn in files that are not part of your assignment, especially ones that do not compile. Your assignment must compile after removing all the .class files and running: javac *.java. In addition, your code must work as submitted.
^ top
Home
| Blackboard
| Schedule
| Room Policies
| Syllabus
Help
| FAQ's
| HowTo's
| Links
Last Updated: April 14 2010 @16:51:41
|