QuestionQuestion

1 Objectives
• Practice writing and testing a programmer-defined class
• Practice writing code that uses arrays of primitives
• Practice using conditional statements and for loops
• Gain experience in developing program logic
• Practice writing documentation that explains what individual parts of a programmer defined class do

2 Overview
The goal of this project is to write a simulation of the dice-rolling game Yahtzee.

3 About The Game
Yahtzee is a dice-rolling game. In each round of the game, the player has three chances to roll some or all of the five dice. The goal of each round is to have as many dice as possible have the same value; the sum of the values of the matching dice is stored in the appropriate place in the player’s scorecard, which has six entries numbered one through six. If, after the first round, the player has four 3s and a 5, the player would likely choose to record a score of 12 (the sum of all the threes that were rolled) in entry #3 on the scorecard.
Once a score has been recorded on the scorecard, it can’t be changed – so if the player has three 3s, a 2, and a 6 at the end of the second round, the player must choose to record a 2 in entry #2, or a 6 in entry #6, or even a 0 in one of the other three entries, but he/she can’t replace the previous score in entry #3.
At the end of the sixth round, the player’s final score is the sum of the six scores on the scorecard.

4 About The Project
For ease of planning and implementation, I have split this project into two parts. There is only one deadline, and you will only submit your code once, but it is strongly recommended that you finish Part 1 by the unofficial deadline, because you will need the remaining time to complete the second part successfully.

You will be creating a DiceArray class, which can contain any number of six-sided dice. Operations that can be performed on this class will include rolling some or all of the dice,
“keeping” some of the dice values (so that, on the next roll, only the dice that are not “kept” will be re-rolled), resetting the dice (so that the next roll will roll all the dice), and calculating a total.
In Part 1 of the project, you will be creating a class called Project5Testing with a main method that calls all the methods of the DiceArray class to make sure they work. Then, in Part 2 of the project, you will be creating the GUI application in the class Project5.

5 Specifications
• Your DiceArray class should contain two instance variables:
An array reference that will refer to an array storing the face values of the dice
An array reference that will refer to an array that keeps track of which dice are being “kept”
• Write a parameterized constructor which accepts the number of dice needed in the game, and then instantiates and initializes the two arrays. The values array should be initialized with all zeroes, and the keeper array should be initialized to indicate that no dice will be kept.
• Write a toString method which returns a String containing the values of the dice, and which ones are being kept. You may choose to use this format (which uses K for “keep” and R for “roll”), or something else:
2 4 3 2 6
K R R K R

• Write a roll method that rolls the dice that aren’t being kept.
• Write a getDice method that returns a reference to the values array.
• Write a reset method that resets the keeper array, so that all dice will be rolled on the next roll.
• Write a keep method that allows the caller to indicate which dice should be kept. Make sure that every element of the keeper array is updated – not just the ones that are changing to “keep”. If the user has indicated that die #2 should not be kept, don’t just do nothing to that element of the keeper array; it might have been set to “keep” before the previous roll!
• Write a calculateTotal method that accepts an int indicating which entry on the scorecard to calculate a total for, and returns a point total for that face value.
• Write a main method in the Project5Testing class that calls each of the methods above enough times to convince yourself that you’ve testing everything sufficiently.
• Thoroughly comment both classes – at the top and above each method in the DiceArray class, and at the top of the Project5Testing class.
5.2 Part 2 Specifications
Before you begin, think about what must happen in a single round of the Yahtzee game. Remember that one round starts with rolling all five dice. After this, the player must choose which dice to keep, and then the other dice are re-rolled. The player then chooses keepers and re-rolls a third time. Finally, after the third roll, the game must show the user his/her scorecard, and ask the user where to store the score from this round.

The player might want to score this under “Threes”. If no score has been recorded there before, then add up all the threes, and record a score of 9.
• Read the documentation provided on the project web site.
• Create a new application class called Project5, and a new class called GUI. Download the GUI.java file from the project web page, and replace the one you created with it.
• Create a directory in your workspace/proj5 directory called diceImages. (Your code will fail if the name doesn’t match this precisely.) Download the six image files from the project web page and store them in this directory.
• In the Project5 class, declare and instantiate a GUI. You should be able to call the methods and have the dice appear. Don’t go on until this is true. (If you aren’t getting the images, make sure your diceImages directory is properly named, with the capital ‘I’ and everything.)
• Write enough code to play one round of Yahtzee:
-Roll all the dice and display them.
-Ask the user which dice to keep, and roll the others.
-Ask the user which dice to keep again, and roll for a third time.
-Display the scorecard in a JOptionPane, and ask the user where to record this score. If the user chooses a part of the scorecard that has already been used, re-display the scorecard and have the user choose again.

You may wish to format the scorecard like this:
1: 0
2: 0
3: 0
4: 0
5: 0
6: 0

• Once one round is working, it should be trivial to make the game play six rounds. Remember, after the last one, to add up all the scores on the scorecard and display the final score.

6 Analysis
In addition to your source code, you must submit a plain text file called analysis.txt that contains your answers to the following questions:
• How much time did you spend working on this project?
• Who, if anyone, helped you with this project?
• What was the most difficult part of this project?
• Describe how you convinced yourself that your program works.
Your responses to these questions will be graded based upon grammar and spelling as well as on content. Please use complete sentences.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

public class DiceArray {

    private int [] face ;
    private boolean [] kept;
   
    /**
    * constructor
    * @param number
    */
    public DiceArray(int number) {
       face = new int[number];
       kept = new boolean[number];
       for (int i = 0; i < number; i++) {
            face[i] = 0;
            kept[i] = false;
       }
    }

    /**
    *
    * @return dice content
    */
    @Override
    public String toString() {
       String s = "";
       for (int i = 0; i < face.length; i++) {
            s += face[i] + " ";            
       }
       s += "\n";
       for (int i = 0; i < kept.length; i++) {
            if (kept[i]) {
                s += "K ";
            } else {
                s += "R ";
            }            
       }      
       return s;
    }...
$31.25 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats