Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Step 1) Using the Die class defined in Chapter 4, write a class called PairOfDic

ID: 3591770 • Letter: S

Question

Step 1)
Using the Die class defined in Chapter 4, write a class called PairOfDice, composed of two Die objects. Include methods to set and get each of the individual die values, a method to roll the two die, and a method that returns the current sum of the two die values. The constructor should initialize each die to 1.
Create a driver class called RollingDice2 to instantiate and use a PairOfDice object.

Note 1: Die class does not change.

Note 2: Make sure PairOfDice is working before you proceed with the remainder of assignment.

Here is the UML:

PairOfDice

- die1: Die
- die2: Die

+ PairOfDice(): PairOfDice
+ getDie1(): Die
+ getDie2(): Die
+ setDie1(int): void
+ setDie2(int): void
+sumDice(): int
+rollDice():int
+toString():String

Step 2)
Using the PairOfDice class, design and implement a program to play a game called Hog. In this game, a computer user (player 1) competes again a human user (player 2). On each turn, the current player rolls a pair of dice and accumulates points. The goal is to reach 50 points before your opponent does.
If, on any turn, the player rolls a 1 on either die, all points accumulated for that round (turn) are forfeited and control of the dice moves to the other player. The human player may voluntarily turn over the dice after each roll. Therefore, the human player must decide to either roll again and risk losing points, or relinquish control of the dice, possibly allowing the other player to win.
Implement the computer player such that it always relinquishes the dice after accumulating 20 or more points in any given round/turn.

I'll get you started by providing an algorithm (this is VERY high-level, you still have PLENTY of designing to do) and some of the variables/data you will need (feel free to add more or use less):

Data
char answer
PairOfDice dice
Die die1
Die die2
int computerTotalScore
humanTotalScore
computerRoundTotal //points for one turn
humanRoundTotal //points for one turn
Feel free to use more variables

public class Die
{
private final int MAX = 6;  
private int faceValue;  
public Die()
{
faceValue = 1;
}
public int roll()
{
faceValue = (int)(Math.random() * MAX) + 1;

return faceValue;
}

public void setFaceValue (int value)
{
faceValue = value;
}

public int getFaceValue()
{
return faceValue;
}

public String toString()
{
String result = Integer.toString(faceValue);

return result;
}
}

what is the code for this output ???

Note 1: Die class does not change.

Note 2: Make sure PairOfDice is working before you proceed with the remainder of assignment.

Explanation / Answer

PairOfDice dice
Die die1
Die die2
int computerTotalScore
humanTotalScore
computerRoundTotal //points for one turn
humanRoundTotal //points for one turn
Feel free to use more variables

public class Die
{
private final int MAX = 6;  
private int faceValue;  
public Die()
{
faceValue = 1;
}
public int roll()
{
faceValue = (int)(Math.random() * MAX) + 1;

return faceValue;
}

public void setFaceValue (int value)
{
faceValue = value;
}

public int getFaceValue()
{
return faceValue;
}

public String toString()
{
String result = Integer.toString(faceValue);

return result;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote