/**
 * CS149 - Introduction to Programming
 * Department of Computer Science
 * James Madison University
 * @version Fall 2018
 */

PA3: Yahtzee Scores (Decisions and Logic)

Due Dates and Submission Details

See submission details below for all due dates and submission details. Note there are multiple submission parts.

Honor Code

This assignment should be completed individually to maximize learning. It is important that you adhere to the Course Policies, particularly the section on Programming Assignments. Also relevant is the JMU Honor Code.

Objectives

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 an 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 and Testing

Start with the following source files:

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.

Note that this time you will not have a main in your program. main is in the driver. By writing JUnit tests you will be able to test each of your methods individually without having a main in your class.

In this assignment, your code should be able to handle invalid categories, but you can assume if the category is valid, the set of Dice is valid.

Submission

This assignment has two parts that should be completed in order. By the first deadline you must submit your YahtzeeTest.java through AutoLab. By the second deadline you must submit your completed code for BOTH Yahtzee.java and YahtzeeTest.java through AutoLab

Part A - Friday October 5, 11:00PM

Read this entire document and complete your YahtzeeTest.java JUnit tests file. You will be scored 10 points on this initial submission of tests. Your tests will be submitted to AutoLab and run against the Instructor solution. Autolab will return a number of lines in each method that is covered by your code. You should have no missing lines for a perfect 9/10 from Autolab - 1 point is from your instructor scoring.

Part B - Friday October 12, 11:00PM

Upload your completed Yahtzee.java and YahtzeeTest.java file through AutoLab.

You must implement the above in java, creating a file called Yahtzee.java and YahtzeeTest.java. Before uploading your files, be sure to complete the following steps carefully:

Your submission will be graded using the following criteria:

RequirementPoints
PART A: Initial tests10
PART B: Checkstyle10
PART B: Instructor grading based on style, code quality, comments.10
PART B: Method calls from provided classes (Number Scores, Chance)10
PART B: Accurate use of relational and logical operators (Full House, x of a Kind)15
PART B: Accurate use of if statements (Default, Straights)15
PART B: JUnit tests 100% coverage and passing30

Don't put off submission until the last possible minute! Any submission system may become bogged down when it receives a large number of submissions. You may have some unanticipated difficulties uploading your code. It is your responsibility to take these possibilities into account and submit early enough to ensure that the submission process is completed before the deadline.

Hints

Often the way something is explained in english may not be the best way to code a solution.

Going Further

Why did we use the colors above (input/output)?

Acknowledgments

This assignment was originally developed by Chris Mayfield and repurposed by Dee Weikle.