/**
 * CS139 - Programming Fundamentals
 * Department of Computer Science
 * James Madison University
 * @version Spring 2016
 */

PA3: Chuck-a-luck

Introduction

Chuck-a-luck is a betting game played with three dice. The player puts his or her money down on one of the possible bets, then the dealer rolls the dice. The player collects a payout if the outcome matches the bet.

The following table describes the possible bets:

Type Bet Odds
Single A specific number will appear on at least one die 1 dice, 1 to 1
2 dice, 2 to 1
3 dice, 10 to 1
Any Triple Any of the triples (all three dice show the same number) will appear 30 to 1
Big The total score will be 11 or higher with the exception of a triple 1 to 1
Small The total score will be 10 or lower with the exception of a triple 1 to 1
Field The total score will be outside the range of 8 to 12 (inclusive) 1 to 1

The final column in the table describes the payout if the player wins the corresponding bet. For example, if a player puts $5 down on single 3, and roll is [3, 3, 2], the payout will be $10 because the odds for that outcome are 2 to 1. If the dice rolled are [3, 3, 3], then the payout will be $50, because the odds for that outcome are 10 to 1.

Your goal for this assignment is to develop and test a method for determining payouts in Chuck-a-luck.

Provided Code

Start with the following source files:

Dice.java

The Dice class represents a complete set of three rolled dice. Dice objects provide several methods:

Here is a code snippet that illustrates these methods:

Dice dice = new Dice(4, 2, 4); // Create a set of dice with 4, 2, and 4 showing

System.out.println(dice.getFirst());     // 4 will be printed

System.out.println(dice.getSecond());    // 2 will be printed

System.out.println(dice.getThird());     // 4 will be printed

System.out.println(dice.addValues());    // 10 will be printed (10 = 4 + 2 + 4)

System.out.println(dice.countValues(1)); // 0 will be printed. (zero 1's) 

System.out.println(dice.countValues(4)); // 2 will be printed. (two 4's) 

Driver.java

The file Driver.java contains the implementation of a simple terminal-based Chuck-a-luck game. This code includes all of the game logic except the payout method. Once you have completed ChuckALuck.java you can use this driver to try out your code.

Since this driver generates random dice rolls, it will not be very useful for systematically testing your solution. The main mechanism for running your code for this project will be the ChuckALuckTest.java file described below.

ChuckALuck.java

Your main task for this assignment is to implement the ChuckALuck.calculatePayout method according to the provided documentation string. For full credit, your finished method must satisfy the following requirements:

ChuckALuckTest.java

You must write JUnit tests for ChuckALuck.java. Rather than writing one very long testCalculate method, you should write several smaller methods to handle distinct cases. The provided file contains two testing methods to get you started:
   @Test
   public void testCalculatePayoutSingleNoMatch() {
      Dice dice = new Dice(1, 2, 3);

      double expected;
      double result;

      result = ChuckALuck.calculatePayout(dice, ChuckALuck.SINGLE, 4, 100.0);
      expected = -100.0;
      assertEquals(expected, result, .0001);

      result = ChuckALuck.calculatePayout(dice, ChuckALuck.SINGLE, 5, 200.0);
      expected = -200.0;
      assertEquals(expected, result, .0001);

      result = ChuckALuck.calculatePayout(dice, ChuckALuck.SINGLE, 6, 300.0);
      expected = -300.0;
      assertEquals(expected, result, .0001);

      result = ChuckALuck.calculatePayout(dice, ChuckALuck.SINGLE, 6, 0.0);
      expected = 0.0;
      assertEquals(expected, result, .0001);

   }

   @Test
   public void testCalculatePayoutSingleOneMatch() {
      Dice dice1 = new Dice(4, 5, 6); // We'll try each of 4,5,6 as a single
      Dice dice2 = new Dice(1, 1, 2); // Confirm duplicates don't cause errors

      double expected;
      double result;

      result = ChuckALuck.calculatePayout(dice1, ChuckALuck.SINGLE, 4, 100.0);
      expected = 100.0;
      assertEquals(expected, result, .0001);

      result = ChuckALuck.calculatePayout(dice1, ChuckALuck.SINGLE, 5, 200.0);
      expected = 200.0;
      assertEquals(expected, result, .0001);

      result = ChuckALuck.calculatePayout(dice1, ChuckALuck.SINGLE, 6, 300.0);
      expected = 300.0;
      assertEquals(expected, result, .0001);

      result = ChuckALuck.calculatePayout(dice1, ChuckALuck.SINGLE, 6, 0.0);
      expected = 0.0;
      assertEquals(expected, result, .0001);

      result = ChuckALuck.calculatePayout(dice2, ChuckALuck.SINGLE, 2, 300.0);
      expected = 300.0;
      assertEquals(expected, result, .0001);

   }

Notice that the names of these methods describe the situations they are designed to test:

testCalculatePayoutSingleNoMatch

You are not required to provide documentation comments for your test methods, but you must select informative names. You do need to provide a documentation comment for the class as a whole. Web-CAT won't run Checkstyle on your tests, but the file should be well organized, correctly indented etc.

Web-CAT will automatically evaluate your JUnit tests on the basis of statement coverage. Your tests must be written so that every line of code in ChuckALuck.java is executed during at least one test.

Part A

Before the deadline for Part A you should read this document carefully, then look at the starter code provided above. Once you have a clear understanding of the expectations for this assignment, complete the readiness quiz in Canvas. The grading for this quiz will be all or nothing: your score on the quiz will be 0 if you miss any questions. If you do not successfully complete Part A, you cannot receive any credit for Part B.

Part B

Upload a .zip file containing both ChuckALuck.java and ChuckALuckTest.java. You should not include Driver.java or Dice.java in your submission.

Before uploading your submission to Web-CAT, be sure to complete the following steps:

Your submission will be graded using the following criteria:

Points
Web-CAT Correctness/Testing50
Web-CAT Checkstyle Tests20
Style and Code Organization20

The Web-CAT grading for this assignment will be based both on the correctness of ChuckALuck.java and on the quality of the tests in ChuckALuckTest.java. Web-CAT will test each of the following:

If Web-CAT deducts any points for correctness/testing, you will receive at most 25/50 on that component of the score.

Once again there will be a penalty for excessive submissions. The first 10 submissions are free. Each submission beyond 10 will result in a .5 reduction in the final score.

Honor Code

This assignment must be completed individually. Your submission must conform to the JMU Honor Code. Authorized help is limited to general discussion on Piazza, the lab assistants assigned to CS 139, 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.

Acknowledgments

This assignment is loosely based on a similar Yahtzee project developed by Chris Mayfield and others. Some parts of the Chuck-a-luck description above are borrowed from the Chuck-a-luck Wikipedia page. The Wikipedia article, and this assignment page, are licensed under the Creative Commons Attribution-Share-Alike License 3.0.