Creating a Yahtzee project in JAVA! **Yahtzee class: main( ) method is updated a
ID: 3751388 • Letter: C
Question
Creating a Yahtzee project in JAVA!
**Yahtzee class: main( ) method is updated and does the following:
-Call static method System.out.println( ) output to the console “Welcome to Yahtzee!”
-Call static method JOptionPane.showMessageDialog( ) using the method signature that receives two arguments; the first argument should be null, the second argument should be explicit text “Let’s Play Yahtzee!”
**constants package created:
Constants.java: class Constants is created with the following constants in it:
public final static int MAX_YAHTZEE = 4;
public final static int NUM_DICE = 5;
public final static int MAX_DIE_VALUE = 6;
public final static int>
public final static int TWOS = 2;
public final static int THREES = 3;
public final static int FOURS = 4;
public final static int FIVES = 5;
public final static int SIXES = 6;
public final static int THREE_KIND = 7;
public final static int FOUR_KIND = 8;
public final static int CHANCE = 9;
public final static int NUM_CATERGORY = 13;
public final static int FULL_HOUSE = 25;
public final static int SM_STRAIGHT = 30;
public final static int UPPER_BONUS = 35;
public final static int LG_STRAIGHT = 40;
public final static int YAHTZEE = 50;
public final static int YAHTZEE_BONUS = 100;
**core package created and includes the following:
AiPlayer.java: AiPlayer class created and extends class Player
Override the methods from the interface IPlayer:
-rollDice()
-selectCategory()
Die.java: Die class created
Add member variables below:
-faceValue (data type int)
Create getter/setter for the member variable
Game.java: Game class created
Add member variables below:
-gameTurn (data type int)
-players (data type ArrayList<Player>)
-dice (data type class Roll)
Create getter/setter for the member variables
HumanPlayer.java: HumanPlayer class created and extends class Player
Override the methods from the interface IPlayer:
-rollDice()
-selectCategory()
IPlayer.java: IPlayer interface created
Add method signatures so that the return type will be void and the parameter list is empty:
-rollDice
-selectCategory
LowerSection.java: LowerSection class created
Add member variables below:
-threeKind (data type int)
-fourKind (data type int)
-fullHouse (data type int)
-smStraight (data type int)
-lgStraight (data type int)
-yahtzee (data type int)
-chance (data type int)
-yahtzeeBonus (data type int)
-totalScore (data type int)
Create getter/setter for the member variables
Player.java: Player abstract class created and implements interface IPlayer
Add member variables below:
-name (data type String)
-score (data type ScoreCard)
Create getter/setter for the member variables
Roll.java: Roll class created
Add member variables below:
-dice (data type ArrayList<Die>)
Create getter/setter for the member variables
ScoreCard.java: ScoreCard class created
Add member variables below:
-upper (data type class UpperSection)
-lower (data type class LowerSection)
-grandTotal (data type int)
Create getter/setter for the member variables
UpperSection.java: UpperSection class created
Add member variables below:
-aces (data type int)
-twos (data type int)
-threes (data type int)
-fours (data type int)
-fives (data type int)
-sixes (data type int)
-totalScore (data type int)
-bonus (data type int)
-total (data type int)
Create getter/setter for the member variables
**userInterface package created
Explanation / Answer
AiPlayer.java:
public class AiPlayer extends Player{
@Override
public void rollDice() {
//Implementation
}
@Override
public void selectCategory() {
//Implementation
}
}
Die.java:
public class Die {
private int faceValue;
public int getFaceValue() {
return faceValue;
}
public void setFaceValue(int faceValue) {
this.faceValue = faceValue;
}
}
Game.java:
import java.util.ArrayList;
public class Game {
private int gameTurn;
private ArrayList<Player> players;
private Roll dice;
public int getGameTurn() {
return gameTurn;
}
public void setGameTurn(int gameTurn) {
this.gameTurn = gameTurn;
}
public ArrayList<Player> getPlayers() {
return players;
}
public void setPlayers(ArrayList<Player> players) {
this.players = players;
}
public Roll getDice() {
return dice;
}
public void setDice(Roll dice) {
this.dice = dice;
}
}
HumanPlayer.java:
public class HumanPlayer extends Player {
@Override
public void rollDice() {
//Implementation
}
@Override
public void selectCategory() {
//Implementation
}
}
IPlayer.java:
public interface IPlayer {
void rollDice();
void selectCategory();
}
LowerSection.java:
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.java:
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.java:
import java.util.ArrayList;
public class Roll {
private ArrayList<Die> dice;
public ArrayList<Die> getDice() {
return dice;
}
public void setDice(ArrayList<Die> dice) {
this.dice = dice;
}
}
ScoreCard.java:
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.java:
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;
}
}
## Any sort of doubt or problem please ask THANK YOU##
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.