Question: How do I add the following to my base code? Java program (Object Oriented) What I need to add: ******Existing Code******* Constants package constants; public
How do I add the following to my base code? Java program (Object Oriented)
What I need to add:




******Existing Code*******
Constants
package constants;
public class Constants
{
// constant for yahtzee
public final static int MAX_YAHTZEE = 4;
// constants for the dice
public final static int NUM_DICE = 5;
public final static int MAX_DIE_VALUE = 6;
// constants for the categories
public final static int ONES = 1;
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;
// static scores
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;
}
AiPlayer
package core;
public class AiPlayer extends Player
{
@Override
public void rollDice()
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void selectCategory()
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
Die
package core;
public class Die
{
private int faceValue;
/**
* @return the faceValue
*/
public int getFaceValue()
{
return faceValue;
}
/**
* @param faceValue the faceValue to set
*/
public void setFaceValue(int faceValue)
{
this.faceValue = faceValue;
}
public String toString()
{
return Integer.toString(getFaceValue());
}
}
Game
package core;
import java.util.ArrayList;
import constants.Constants;
public class Game
{
private int gameTurn;
private ArrayList players;
private Roll dice;
public Game()
{
for(int round = 0; round
{
}
}
public Roll getDice()
{
return dice;
}
public void setDice(Roll dice)
{
this.dice = dice;
}
/**
* @return the gameTurn
*/
public int getGameTurn()
{
return gameTurn;
}
/**
* @param gameTurn the gameTurn to set
*/
public void setGameTurn(int gameTurn)
{
this.gameTurn = gameTurn;
}
/**
* @return the players
*/
public ArrayList getPlayers()
{
return players;
}
/**
* @param players the players to set
*/
public void setPlayers(ArrayList players)
{
this.players = players;
}
}
HumanPlayer
package core;
public class HumanPlayer extends Player
{
@Override
public void rollDice()
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void selectCategory()
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
IP Player
package core;
public interface IPlayer
{
public void rollDice();
public void selectCategory();
}
Lower Section
package core;
public abstract class Player implements IPlayer
{
private String name;
private ScoreCard score;
public ScoreCard getScore()
{
return score;
}
public void setScore(ScoreCard score)
{
this.score = score;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
}
Player
package core;
public abstract class Player implements IPlayer
{
private String name;
private ScoreCard score;
public ScoreCard getScore()
{
return score;
}
public void setScore(ScoreCard score)
{
this.score = score;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
}
Roll
package core;
import java.util.ArrayList;
/*
This class will replicate the state and behavior of the five dice in the
game and rolling the dice
*/
public class Roll
{
// container for the five dice
private ArrayList dice;
/**
* @return the dice
*/
public ArrayList getDice() {
return dice;
}
/**
* @param dice the dice to set
*/
public void setDice(ArrayList dice) {
this.dice = dice;
}
}
Score Card
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;
}
/**
* @return the grandTotal
*/
public int getGrandTotal() {
return grandTotal;
}
/**
* @param grandTotal the grandTotal to set
*/
public void setGrandTotal(int grandTotal) {
this.grandTotal = grandTotal;
}
}
Upper Section
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;
/**
* @return the aces
*/
public int getAces() {
return aces;
}
/**
* @param aces the aces to set
*/
public void setAces(int aces) {
this.aces = aces;
}
/**
* @return the twos
*/
public int getTwos() {
return twos;
}
/**
* @param twos the twos to set
*/
public void setTwos(int twos) {
this.twos = twos;
}
/**
* @return the threes
*/
public int getThrees() {
return threes;
}
/**
* @param threes the threes to set
*/
public void setThrees(int threes) {
this.threes = threes;
}
/**
* @return the fours
*/
public int getFours() {
return fours;
}
/**
* @param fours the fours to set
*/
public void setFours(int fours) {
this.fours = fours;
}
/**
* @return the fives
*/
public int getFives() {
return fives;
}
/**
* @param fives the fives to set
*/
public void setFives(int fives) {
this.fives = fives;
}
/**
* @return the sixes
*/
public int getSixes() {
return sixes;
}
/**
* @param sixes the sixes to set
*/
public void setSixes(int sixes) {
this.sixes = sixes;
}
/**
* @return the totalScore
*/
public int getTotalScore() {
return totalScore;
}
/**
* @param totalScore the totalScore to set
*/
public void setTotalScore(int totalScore) {
this.totalScore = totalScore;
}
/**
* @return the bonus
*/
public int getBonus() {
return bonus;
}
/**
* @param bonus the bonus to set
*/
public void setBonus(int bonus) {
this.bonus = bonus;
}
/**
* @return the total
*/
public int getTotal() {
return total;
}
/**
* @param total the total to set
*/
public void setTotal(int total) {
this.total = total;
}
}
Yahtzee.java
package yahtzee;
import javax.swing.JOptionPane;
public class Yahtzee
{
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
System.out.println("Welcome to Yahtzee!");
JOptionPane.showMessageDialog(null, "Let's Play Yahtzee");
}
}
ctivi Yahtzee class. Update the main method to do the following a. Instantiate an instance of class Game AiPlayer class. Update method rollDice to do the following a. Add the parameter of class Roll that was added in interface IPlaver b. Referencing the parameter of class Roll, get the collection of class Die by calling the getter c. Loop through the collection of class Die, for each instance call method rollDie in class Die to obtain a face value Die class. Add method rollDie to do the following a. Access level modifier public b. Return type void c. Empty parameter list d. Instantiate an instance of class Random e. Set member variable faceValue equal to method call nextInt in class Random on the instance of class random, passing as an argument the maximum face value of a six sided die then shift the result by adding one to it ctivi Yahtzee class. Update the main method to do the following a. Instantiate an instance of class Game AiPlayer class. Update method rollDice to do the following a. Add the parameter of class Roll that was added in interface IPlaver b. Referencing the parameter of class Roll, get the collection of class Die by calling the getter c. Loop through the collection of class Die, for each instance call method rollDie in class Die to obtain a face value Die class. Add method rollDie to do the following a. Access level modifier public b. Return type void c. Empty parameter list d. Instantiate an instance of class Random e. Set member variable faceValue equal to method call nextInt in class Random on the instance of class random, passing as an argument the maximum face value of a six sided die then shift the result by adding one to it
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
