Question
The assignment is program a yahtzee game in java following a template, but after a few days of working on it, i still can't get
The assignment is program a yahtzee game in java following a template, but after a few days of working on it, i still can't get it to work properly. A solution to this would be helpful (Java)
To give me the outputs of the figure below.
Yahtzee class | |
AiPlayer class | Update method selectCategory() to do the following Add parameter of class Roll based on updated IPlayer interface Comment out or delete the statement that throws the UnsupportedOperationException Implements abstract method selectDice() from superclass Player, remove any autogenerated body Implements abstract method calculateScore() from superclass Player, remove any autogenerated body |
Constants class | Update the class to include two constants as follows ZERO set equal to the value of 0 MAX_ROLLS set equal to the value of 3 |
Die class | |
Game class | Update method playGame() to do the following Create a local variable of data type int called roll initialized to the value of 0 In the for loop that loops through the players of the gamePrior to the call to player.rollDice(dice)instantiate an instance of class Roll that will store the selected dice of the player for each roll for the reference object described in the previous step, call method removeDice() passing as an argument the reference object to empty the ArrayList of class Die Add a while loop based on the condition that the selected dice ArrayList size is less than the maximum number of dice AND the player has not exceeded the maximum number of rolls Inside the while loop should be the followingThe call to player.rollDice(dice) Call to method selectDice() on class Player passing as argumentsThe original Roll object reference The Roll object for the dice to keep The int for the current roll number Increment the local variable roll of data type int After the while loop, call method selectCategory() in class Player passing as an argument the reference object of class Roll that represents the kept dice by the player |
HumanPlayer class | Add a custom constructor that does the following Access level modifier public Empty parameter list Instantiates the member variable of class ScoreCard Update method selectCategory() to do the followingAdd parameter of class Roll based on updated IPlayer interface representing the dice the player selected to keep Prompt the player to select a category Using an instance of class Scanner, receive the players selection Loop until the player selects a valid category, data validation must check forUsing try/catch exception handling verify the player entered an integer Verify the player entered a valid value based on the 13 categories to select from After the player selects a valid category call method calculateScore() passing as argumentsthe instance of class roll received as a parameter the int of the category selected Add method calculateScore to do the followingAccess level modifier public Return type void Parameter listInstance of class Roll representing the dice the player selected Primitive data type int representing the selected category If the category selected is part of the upper section, referencing the member variable of class ScoreCard call the getter for UpperSection and call method evaluateCategory() passing as arguments the instance of class Roll representing the kept dice and the category selected If the category selected is part of the upper section, referencing the member variable of class ScoreCard call the getter for LowerSection and call method evaluateCategory() passing as arguments the instance of class Roll representing the kept dice and the category selected Output to the console the total score from class ScoreCard Add method selectDice() to do the followingAccess level modifier public No return type Parameter listInstance of class Roll representing the member variable instantiated in class Game Instance of class Roll representing the object instantiated for the dice to keep Primitive data type int representing the current roll number of the player Prompt the player to select the dice they want to keep based on the index value displayed in front of the die value, offer an option to end the current turn of their roll (note: each player gets three rolls per turn) Loop until the player enters that they are done selecting and their selection was validIf the player selects that they are doneCheck if all dice have been selected AND they are on their third rollIf truetransfer all remaining dice in the original Roll instance to the keep Roll instance remove each die from the original Roll instance Update the variable monitoring if the player is done by setting it to true Break out of the looping structure ElseInside a try/catch exception handlerParse the received data from the player so it is an integer representing the index to the ArrayList of Die Get the Die instance from the ArrayList and store as an instance of class Die Add the Die to the instance of class Roll representing the keep dice Remove the Die from the instance of class Roll representing the original dice Loop through the collection of Die to keep in the instance of class Roll that represents the keep dice and output to the console If the size of the ArrayList of Die in class Roll is the maximum number of dice, break out of the looping structure |
IPlayer interface | Update the method signature for method selectCategory() so that it has one parameter of class Roll |
LowerSection class | Add method evaluateCategory() to do the following Access level modifier of public Return type void Parameter listClass Roll Primitive data type int to represent the category the player selected Using conditional logic evaluate which category the player selectedEach category should evaluate the face value of each die in class RollIf the face value(s) match the rules of the selected category, call the setter for that category passing the face value or static value as an argument Add method sortDice() to do the followingAccess level modifier private Return type ArrayList only allowing for data type class Integer Parameter list receives an instance of class Roll Instantiate and instance of class ArrayList only allowing for data type class Integer as elements Loop through ArrayList in class rollInstantiate and instance of class Integer passing the face value of the die as an argument Add the instance of class Integer to the ArrayList with class Integer as elements Call static method sort() from class Collections passing the ArrayList with instances of class Integer as an argument Return the ArrayList with instances of class Integer Update method setThreeKind() so that it adds to the current value of member variable threeKind (i.e. += versus =) Update method setFourKind() so that it adds to the current value of member variable fourKind (i.e. += versus =) Update method setChance() so that it adds to the current value of member variable chance (i.e. += versus =) Update method getTotalScore() so that it adds together the eight categorys current values |
Player class | Update the class to include two abstract methods as definedselectDice() return type void parameter listData type class Roll representing the original instance of the Roll object Data type class Roll representing the dice the player will choose to keep Data type int representing the current roll number of the player calculateScore()return type void parameter listData type class Roll that represents the object reference of the kept dice Data type int representing which category the player selected |
Roll class | Add method removeDice to do the following Access level modifier public Return type void Parameter list has one parameter of class Roll Call method removeAll() in class ArrayList for the ArrayList of class Die in class Roll, passing as an argument the ArrayList of class Die in class Roll Update method displayDice to do the followingAdd a local variable of primitive data type int to act as a counter for each die Update the loop that displays the value of each die to includethe counter variable increment the counter |
ScoreCard class | Update class to do the followingAdd a custom constructor to do the following Instantiate the member variable of class UpperSection Instantiate the member variable of class LowerSection Update method getGrandTotal to do the followingSet member variable grandTotal equal to the call to methodsgetTotal() in class UpperSection added to getTotalScore() in class LowerSection |
UpperSection class | Add method evaluateCategory() to do the following Access level modifier of public Return type void Parameter listClass Roll Primitive data type int to represent the category the player selected Using conditional logic evaluate which category the player selectedEach category should evaluate the face value of each die in class RollIf the face value matched the selected category, call the setter for that category passing the face value as an argument Update method setAces() so that it adds to the member variables current value the parameter received (i.e. += versus =) Update method setTwos() so that it adds to the member variables current value the parameter received (i.e. += versus =) Update method setThrees() so that it adds to the member variables current value the parameter received (i.e. += versus =) Update method setFours() so that it adds to the member variables current value the parameter received (i.e. += versus =) Update method setFives() so that it adds to the member variables current value the parameter received (i.e. += versus =) Update method setSixes() so that it adds to the member variables current value the parameter received (i.e. += versus =) Update method getTotalScore() so that it adds together the six categorys current values Update method getScore() so that it adds together the member variable totalScore and bonus. |
Figure 5 Test Case 4
Message Let's Play Yahtzee OK Figure 1 Test Case 1 Output - Yahtzee (run) X run Welcome to Yahtzee! Enter human player name Karinl or Figure 2 Test Case 2 Players for this game are: Karin Al Player Figure 3 Test Case 3 Message Let's Play Yahtzee OK Figure 1 Test Case 1 Output - Yahtzee (run) X run Welcome to Yahtzee! Enter human player name Karinl or Figure 2 Test Case 2 Players for this game are: Karin Al Player Figure 3 Test Case 3Step by Step Solution
There are 3 Steps involved in it
Step: 1
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