Question: How to add the following to my existing code? Java game called yahtzee LowerSection class Add method evaluateCategory() to do the following Access level modifier

How to add the following to my existing code? Java game called yahtzee

LowerSection class

Add method evaluateCategory() to do the following

Access level modifier of public

Return type void

Parameter list

Class Roll

Primitive data type int to represent the category the player selected

Using conditional logic evaluate which category the player selected Each category should evaluate the face value of each die in class Roll

If 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 following

Access 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 roll

Instantiate 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

Existing Code

package core;

public class LowerSection {

private int threeKind;

private int fourKind;

private int fullHouse;

private int smStraight;

private int lgStraight;

private int yahtzee;

private int chance;

private int yahtzeeBonus;

private int totalScore;

public int getThreeKind() {

return threeKind;}

public void setThreeKind(int threeKind) {

this.threeKind = threeKind;}

public int getFourKind() {

return fourKind;}

public void setFourKind(int fourKind) {

this.fourKind = fourKind;}

public int getFullHouse() {

return fullHouse;}

public void setFullHouse(int fullHouse) {

this.fullHouse = fullHouse;}

public int getSmStraight() {

return smStraight;}

public void setSmStraight(int smStraight) {this.smStraight = smStraight;}

public int getLgStraight() {return lgStraight;}

public void setLgStraight(int lgStraight) {

this.lgStraight = lgStraight;}

public int getYahtzee() {return yahtzee;}

public void setYahtzee(int yahtzee) {

this.yahtzee = yahtzee;}

public int getChance() {return chance;}

public void setChance(int chance) {this.chance = chance;}

public int getYahtzeeBonus() {

return yahtzeeBonus;}

public void setYahtzeeBonus(int yahtzeeBonus) {

this.yahtzeeBonus = yahtzeeBonus;}

public int getTotalScore() {return totalScore;}

public void setTotalScore(int totalScore) {

this.totalScore = totalScore;}}

Player class

Update the class to include two abstract methods as definedselectDice()

return type void

parameter list

Data 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 list

Data type class Roll that represents the object reference of the kept dice

Data type int representing which category the player selected

package core;

public abstract class Player implements IPlayer {

private String name;

private ScoreCard score;

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public ScoreCard getScore() {

return score;

}

public void setScore(ScoreCard score) {

this.score = score;

}}

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 following

Add 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 include

the counter variable

increment the counter

package core;

import java.util.ArrayList;

import constants.Constants;

public class Roll {

private ArrayList dice;

public Roll(){

createDice();}

private void createDice(){

dice = new ArrayList();

for(int i = 0;i < Constants.NUM_DICE;i++){

Die d = new Die(); dice.add(d);}}

public void displayDice(){for(Die die : dice)

{System.out.println(die.getFaceValue());}}

public ArrayList getDice() {return dice;}

public void setDice(ArrayList dice) {

this.dice = dice;}}

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 methods

getTotal() in class UpperSection added to

getTotalScore() in class LowerSection

package core;

public class ScoreCard {

private UpperSection upper;

private LowerSection lower;

private int grandTotal;

public UpperSection getUpper() {return upper;}

public void setUpper(UpperSection upper) {this.upper = upper;}

public LowerSection getLower() {return lower;}

public void setLower(LowerSection lower) {this.lower = lower;}

public int getGrandTotal() {return grandTotal;}

public void setGrandTotal(int grandTotal) {

this.grandTotal = grandTotal;}}

UpperSection class

Add method evaluateCategory() to do the following

Access level modifier of public

Return type void

Parameter list

Class 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 Roll

If 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

package core;

public class UpperSection {

private int aces;

private int twos;

private int threes;

private int fours;

private int fives;

private int sixes;

private int totalScore;

private int bonus;

private int total;

public int getAces() {

return aces;}

public void setAces(int aces) {

this.aces = aces;}public int getTwos() {

return twos;}

public void setTwos(int twos) {

this.twos = twos;}

public int getThrees() {return threes;}

public void setThrees(int threes) {

this.threes = threes;}public int getFours() {return fours;}

public void setFours(int fours) {this.fours = fours;}

public int getFives() {return fives;}

public void setFives(int fives) {this.fives = fives;}

public int getSixes() {return sixes;}

public void setSixes(int sixes) {this.sixes = sixes;}

public int getTotalScore() {return totalScore;}

public void setTotalScore(int totalScore) {

this.totalScore = totalScore;}public int getBonus() {return bonus;}

public void setBonus(int bonus) {this.bonus = bonus;}

public int getTotal() {return total;}

public void setTotal(int total) {this.total = total;}}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!