create a loop asking the user for which values to hold. It will only accept numbers 1 to 5 or the letter q

The code in the attached file has to be used as well.
public yahtzee(){//This constructor will initialize your 5 x 3 array and set it with empty values, in this case 0//It will also initialize a value to track the score for the game and how many rounds have been played}
This function will initialize the yahtzee game and then call the menu.
The menu will prompt the user if they want to play the game or not. At the completion of a game it will ask if they want to play another round. Be sure to include that phrasing in the prompt so that it is clear to the end user.
public static void menu(){//prompts user to play and if a re-play changes wording//will call function to start the game}
Start Game
This function will reset the score to zero, the number of rounds played to 0 and begin iterating through the rounds until the playRound function returns false;
Clear Array
At the end of each round you will want to set the values in the array back to 0.
Generate X random numbers (0 to 5 numbers) with a value range of 1 to 6 and place them in the last slots of the array. X will be determined by how many numbers were held in the preceding roll. If everything was held, no numbers will be generated or if no values were held, then you generate an entirely new set of numbers).
Note we are using the last slots of the array because our hold will place numbers up front first, so we start inserting after the slots we know are “held”.
This function needs to be aware of what set of rolls it is on, if its the second roll, it needs to place values in the second row.
This will create a loop asking the user for which values to hold. It will only accept numbers 1 to 5 or the letter q. Once q is selected it will copy the selected values to the next row in the array BUT it will place them sequentially in the slots starting at 0 (this will make your life easier, trust me). Then it will return a value for the number of values held.
Play Round
This function will be called at the start of each round.
It will start by clearnig the array of current values.
Then it will let the user roll 3 times and hold after the first 2 rolls. What is left after the final roll is what the user is scored on.
At the end of the round it will increment the round counter by 1. If 10 rounds have been completed, it will return falseotherwise it will return true.
Score Hand
This function will take the final row of numbers and score it based upon basic Yahtzee rules. To keep the logic simple, we will allow the program to choose the best score and regardless of whether the user has scored it before, allow that score. Note these scores are NOT traditional yahtzee scores, but simplified for this program.

3 of a kind – Sum of all the dice + 5
4 of a kind – Sum of all the dice + 10
full house (2 matching dice AND 3 matching dice) – 25 pts
small straight (4 dice in consecutive sequence) – 30 pts
large straight (all dice in consecutive sequence) – 40 pts
Yahtzee (all dice match) – 50 pts
Chance (anything) – Sum of all the dice

HINT– for scoring, it might help to order your array sequentially before attempting to logic out the score.


Get a 10 % discount on an order above $ 100


. .


The post create a loop asking the user for which values to hold. It will only accept numbers 1 to 5 or the letter q appeared first on USA Dissertation Editors.

"Get 15% discount on your first 3 orders with us"
Use the following coupon

Order Now
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *