Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Yahtzee Program in JAVA: Implement what is in bold in the table below (what is not in bold is already completed, but is referenced here).

Yahtzee Program in JAVA: Implement what is in bold in the table below (what is not in bold is already completed, but is referenced here). Extra info given below table.

Yahtzee class

main() method:

-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 Lets Play Yahtzee!

**Update the main method to do the following:

-Instantiate an instance of class Game

AiPlayer.java

Override methods from interface IPlayer

-rollDice()

-selectCategory()

**Update method rollDice to do the following:

-Add the parameter of class Roll that was added in interface IPlayer

-Referencing the parameter of class Roll, get the collection of class Die by calling the getter

-Loop through the collection of class Die, for each instance call method rollDie in class Die to obtain a face value

Die.java

Add member variables

-faceValue, data type int

Create getter/setter for member variable

**Add method rollDie to do the following:

-Access level modifier public

-Return type void

-Empty parameter list

-Instantiate an instance of class Random

-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

Game.java

Add member variables

-gameTurn, data type int

-players, datatype ArrayList

-dice, datatype class Roll

Create getter/setter for member variables

**Add a constructor to do the following:

-Access level modifier public

-Empty parameter list

-Call method createPlayers

-Call method displayPlayers

-Call method playGame

**Add method createPlayers to do the following:

-Access level modifier private

-Return type void

-Empty parameter list

-Instantiate the member variable of class ArrayList representing the collection of class Player

-Instantiate an instance of class Scanner so it takes input from the console

-Prompt the user from the console to enter their name and store the value in an instance of class String

-Instantiate an instance of class HumanPlayer

-Call method setName in class Player for the instance of class HumanPlayer passing as an argument the data read from the console

-Instantiate and instance of class AiPlayer

-Call method setName in class Player for the instance of class AiPlayer passing as an argument a string the AI players name

-Add to the member variable of class ArrayList representing the collection of class Player the instance of class HumanPlayer and AiPlayer instantiated above

**Add method displayPlayers to do the following:

-Access level modifier private

-Return type void

-Empty parameter list

-Loop through the member variable of class ArrayList representing the collection of class Player: Output to the console each players name by calling method getName in class Player for each instance

**Add method playGame to do the following:

-Access level modifier private

-Return type void

-Empty parameter list

-Instantiate the member variable of class Roll

-Loop through the member variable of class ArrayList representing the collection of class Player: Call method rollDice in class Player passing as an argument the member variable of class Roll, Call method displayDice in class Roll

HumanPlayer.java

Override methods from interface IPlayer

-rollDice()

-selectCategory()

**Update method rollDice to do the following:

-Add the parameter of class Roll that was added in interface IPlayer

-Referencing the parameter of class Roll, get the collection of class Die by calling the getter

-Loop through the collection of class Die, for each instance call method rollDie in class Die to obtain a face value

IPlayer.java

Add method signatures so that the return type is void and the parameter list is empty

-rollDice

-selectCategory

**Update the method signature for method rollDice so that it has one parameter of class Roll

LowerSection.java

Add member variables

-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 member variables

Player.java

Add member variables

-name, data type String

-score, data type ScoreCard

Create getter/setter for member variables

Roll.java

Add member variables

-dice, data type ArrayList

Create getter/setter for member variables

**Add a constructor to do the following:

-Access level modifier public

-Empty parameter list

-Calls method createDice

**Add method createDice to do the following:

-Access level modifier private

-Return type void

-Empty parameter list

-Instantiate the member variable of type ArrayList representing the collection of dice

-Loop for five iterations: Instantiate an instance of class Die, Add the instance of class Die to the member variable representing the collection of dice

**Add method displayDice to do the following:

-Access level modifier public

-Return type void

-Empty parameter list

-Loop through the member variable of type ArrayList that represents the collection of dice: Output to the console the face value of each instance of class Die in the collection

ScoreCard.java

Add member variables

-upper, data type class UppserSection

-lower, data type class LowerSection

-grandTotal, data type int

Create getter/setter for member variables

UpperSection.java

Add member variables

-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 member variables

Created: Constants package

Created: class constants with the following:

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 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;

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;

Created: Core package, which includes: class AiPlayer extends class Player, class Die, class Game, class HumanPlayer extends class Player, interface IPlayer, class LowerSection, abstract class Player implements interface IPlayer, class Roll, class ScoreCard, class UpperSection

Created: userInterface package

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g Database Administrator Implementation And Administration

Authors: Gavin Powell, Carol McCullough Dieter

2nd Edition

1418836656, 9781418836658

More Books