We are going to continue our problem-solving education by writing a program that plays the Two-Dice Pig game. This will help us understand loops, branching and subroutines.
We will also get more practice using Eclipse to make our programming life easier.
This is where we will put all our classes for homework 07.
1) Write a program that allows players to play the game Two-Dice Pig. The name of the class that plays the game is TwoDicePigGame.
The rules of Two-Dice Pig are:
Each turn, a player repeatedly rolls two dice until a 1 is rolled or the player decides to “hold”:
If two 1s are rolled, the player’s entire score is lost, and the turn ends.
If a single 1 is rolled, the player scores nothing and the turn ends.
If the player rolls any other number, it is added to their turn total and the player’s turn continues.
If a double is rolled, the point total is added to the turn total as with any roll but the player is obligated to roll again.
If a player chooses to “hold”, their turn total is added to their score, and it becomes the next player’s turn.
The first player to 100 or more points wins.
The program should ask for the number of players, then create an array of Players. The Player class should have a name instance variable and a score instance variable. Once the players are initialized the program should start playing the game by giving each player a turn.
The program should have a function named playerTurn that allows the player to decide when to “hold”. The function must return the score for the player’s turn.
The program should use an instance of the class PairOfDice to do the rolling of the dice. (See the text for examples of the class.)
Criterion | Excellent (100%) | Satisfactory (75%) | Borderline (50%) | Unsatisfactory (25%) | Poor (0) |
---|---|---|---|---|---|
Adherence to standards - 2 points Does it conform to standards in every detail? |
No errors. | Minor details of the assignment are violated, or poor choices are made where the assignment is unclear. | Significant details of the assignment or the underlying program intent are violated, but the program still fulfills essential functions. | Significant details of the assignment or the underlying program intent are violated, but the program still fulfills some essential functions. | Misses the point of the assignment. |
Breakdown (modular design) - 2 points Does it demonstrate good modular design? |
No errors. | 1-3 minor errors. | > 3 minor errors OR 1 major error. | 2 major errors | > 2 major error. |
Correctness of code - 4 points Does it work? Does it pass JUnit? |
Passes all tests. | Works for typical input, may fail for minor special cases. | Fails for typical input, for a minor reason. | Fails for typical input, for a major reason. | No. |
Documentation, and style - 2 points Is it clear and maintainable? Does it pass CheckStyle? |
No errors. | 1-3 minor errors. | > 3 minor errors OR 1 major error. | 2 major errors | > 2 major error. |
The assignment is due on Friday, October 22nd at 11:55pm. You may turn it in early.
Conduct a personal review of your code before turning it in. Does your code follow the Java Coding Standard?
Test your code.
Export your ICS111-workspace project by choosing File -> Export. Name the zip file H07.zip.
Sign into Laulima, then navigate to the ICS111 site. In the left hand side of the site, there is an Assignments tab/link. Click on it and view all of the posted assignments. Select the assignment that you want to turn in and attach your H07.zip file and accept the honor pledge to submit the assignment.