PA3
James Madison University, Spring 2017 Semester
PA3: Yahtzee Scores (Decisions and Logic)
Due: Friday, Feb 24 at 11:59 PM

- -20% on Saturday, Feb 25
- -40% on Sunday, Feb 26
- Not accepted afterwards
Objectives
- Write if statements to make decisions in a program.
- Use relational and logical operators in expressions.
- Design one or more methods to simplify the code.
- Write JUnit tests that cover 100% of the program.
- Submit code to Web-CAT and interpret feedback.
Honor Code
This assignment should be viewed as a take-home exam and must be completed individually. Your work must conform to the JMU Honor Code. Authorized help is limited to general discussion on Piazza, the lab assistants assigned to CS 149/159, and the instructor. Copying work from another student or the Internet is an Honor Code violation and will be grounds for a reduced or failing grade in the course.
Background
In this program, you will implement the scoring function for Yahtzee — not the entire game, just the part that calculates how many points the dice are worth. Here is a excerpt from the Wikipedia article that explains the scoring rules for the game:
The Yahtzee scorecard contains thirteen boxes divided between two sections: the upper section, and the lower section.Upper section
In the upper section, each box is scored by summing the total number of dice faces matching that box. For example, if a player were to roll three twos among the five dice, the score for the "TWOS" box would be recorded as 6.Lower section
The lower section contains a number of poker-themed combinations with specific point values:
Category Description Score Example Three-Of-A-Kind At least three dice showing the same face Sum of all dice ![]()
![]()
![]()
![]()
Four-Of-A-Kind At least four dice showing the same face Sum of all dice ![]()
![]()
![]()
![]()
Full House A three-of-a-kind and a pair 25 ![]()
![]()
![]()
![]()
Small Straight Four sequential dice
(1-2-3-4, 2-3-4-5, or 3-4-5-6)30 ![]()
![]()
![]()
![]()
Large Straight Five sequential dice
(1-2-3-4-5 or 2-3-4-5-6)40 ![]()
![]()
![]()
![]()
Yahtzee All five dice showing the same face 50 ![]()
![]()
![]()
![]()
Chance Any combination
(often acts as discard box)Sum of all dice ![]()
![]()
![]()
![]()
Requirements
Start with the following source files:- Dice.java - DO NOT EDIT
- Driver.java - DO NOT EDIT
- Yahtzee.java
- YahtzeeTest.java
Your main task is to implement the Yahtzee.calculateScore
method. You should write additional methods to break the problem down into sub-problems. The Dice
class contains two helper methods: addValues
, which returns the sum of the dice values (e.g., Chance), and countValues
, which returns how many times a face value occurs in the dice. For example, given the dice values [1, 4, 5, 6, 4], dice.countValues(4)
will return 2 (since the value 4 occurs twice).
You must also write JUnit tests for Yahtzee.java. Think carefully about how many test cases you will need. Organize your tests into separate methods, rather than write one very long testCalculateScore
. Make sure you cover every statement of your program. Here are several examples to get you started:
Dice dice; dice = new Dice(1, 2, 3, 4, 5); // large straight assertEquals(1, Yahtzee.calculateScore(Yahtzee.ONES, dice)); assertEquals(0, Yahtzee.calculateScore(Yahtzee.THREE_OF_A_KIND, dice)); assertEquals(40, Yahtzee.calculateScore(Yahtzee.LARGE_STRAIGHT, dice));
JUnit is the recommended way to "run" this assignment. However, you may also refer to Driver.java which illustrates how your calculateScore
method might be used in an application. This driver class will also let you test your scoring interactively.
Submission
Combine your Yahtzee.java and YahtzeeTest.java into a zip file, and submit via Web-CAT. Do not include Dice.java, Driver.java, or any other files in your zip archive. There will be no Canvas submission for this assignment.
Both your files must conform to the CS 149 Style Guide. Don't forget to run Checkstyle before your final submission. For this assignment, pay special attention to the indentation rules. All blocks of code (even if one line) should be surrounded by curly braces.