Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Reminder: Formatting is always important in your code (comments, indentation, variable names, etc.) And please always start your Java code file with a multi-line
Reminder: Formatting is always important in your code (comments, indentation, variable names, etc.) And please always start your Java code file with a multi-line comment listing the name of the developer, the date of completion and a short description of the program. And you must document each method. 1 Yahtzee If you have never played Yahtzee before, you can go play now at: http://www.yahtzeeonline.org/ Yahtzee is a game where the objective is to score points by rolling five dice to make certain combinations. The dice can be rolled up to three times in a turn to try to make various scoring combinations. A game consists of thirteen rounds. In each round, a player gets three rolls of the dice, although they can choose to end their turn after one or two rolls. After the first roll the player can save any dice they want and re-roll the other dice. This procedure is repeated after the second roll. The player has complete choice as to which dice to roll. They could re-roll a die for the third roll that was not rolled on the second roll. The Yahtzee scorecard contains 13 different category boxes and in each round, after the third roll, the player must choose one of these categories. The score entered in the box depends on how well the five dice match the scoring rule for the category. Details of the scoring rules for each category are given below. As an example, one of the categories is called Three-of-a-Kind. The scoring rule for this category means that a player only scores if at least three of the five dice are the same value. The game is completed after 13 rounds are played, with each of the 13 boxes being filled. The total score is calculated by summing all thirteen boxes, together with any bonuses. The following table demonstrates the Yahtzee Scorecard Category What the dice must be Score Aces Any combo Twos Any combo Threes Fours Fives Sixes Any combo Any combo Any combo Any combo 3 of a kind 4 of a kind Full House Small Straight Large Straight Yahtzee Chance At least 3 dice the same At least 4 dice the same 3 of a kind + 2 of a kind Four sequential dice Sum of dice with value 1 Sum of dice with value 2 Sum of dice with value 3 Sum of dice with value 4 Sum of dice with value 5 Sum of dice with value 6 Sum of all 5 dice Sum of all 5 dice 25 Example Roll 1 1 1 34 scores 3 22256 scores 6 3 3 3 3 4 scores 12 4 4 5 5 5 scores 8 11225 scores 5 23666 scores 18 2 3 4 4 4 scores 17 4 5 5 5 5 scores 24 22 5 5 5 scores 25 30 1 3 4 5 6 scores 30 5 sequential dice All 5 dice the same 40 50 Any combo Sum of all 5 dice 1 2 3 4 5 scores 40. 22222 scores 50 113 55 scores 15 1.1 Sample Output See the Yahtzee.pdf document on brightspace for an example of sample output of this assignment 2 1.2 Game Setup [25 points] To design your program: 1. Inside the main method of your class, create two integer arrays, one of size five to represent the dice being rolled, and one of size 13 to represent the scorecard. 2. Write the method void rollDice (int[] diceArray) that sets each element in the dice array to be a random number between 1 and 6 inclusive. 3. Write the method void reroll (int[] diceArray) This method should first read the number of dice the user would like to reroll, then allow the user to specify the index(es) of which dice to reroll. Now we will need to create some methods to help us fill in the score card. 4. Write the method int sumAllDice (int[] dice) that sums up the total of all the dice currently in the array and returns the sum 5. Write the method int sumOf Dice (int[] dice, int faceValue) that sums up all of the dice that have a value of faceValue. So for example calling sumOf Dice (new int[] 1,2,3,3,1, 3) would return 6. 6. Write the method void scoreDice (int () scorecard, int () dice, int category) category represents the user's selection of which category they want to score the dice for (ex. three of a kind, small straight, etc.). The method should then store the correct total in the scorecard for the given state of the dice. Note that for some categories (Yahtzee, straight, etc.) your method should store a default value, for some categories (3 of a kind, chance, etc.) your method should store the sum of all the dice, and for others (aces, twos, etc.) your method should store the sum of some of the dice. 7. Write a method called int totalScore (int[] scoreCard) that sums up the total score of all the scores stored in the score card array. So far our program assumes the user will play the game properly and not try to cheat. Let's implement some methods to check and make sure the user isn't cheating! 8. Implement a method that checks to make sure that the user isn't trying to score a category in the score card that has already been scored (i.e., stop the user from scoring 3 of a kind more than once) 1.3 Main Method [10 points] Write the main method to allow the user to play a game of Yahtzee. The main program should allow the user to take 13 turns, and on each turn the following actions should happen: 1. roll all 5 dice 2. display the dice 3. allow the user to reroll any number of dice, no more than three times 4. allow the user to choose which item on the scorecard to fill 5. display the score card 6. When the last turn has finished, display the total sum of the scorecard. 3
Step by Step Solution
There are 3 Steps involved in it
Step: 1
This program solves all the questions import javautilRandom import javautilScanner public class Yahtzee public static void mainString args int dice new int5 Array to represent the five dice int scorec...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started