Question: Using the PairOfDice class from PP 4.7, design and implement an application that rolls a pair of dice 1000 times, counting the number of box

Using the PairOfDice class from PP 4.7, design and implement an application that rolls a pair of dice 1000 times, counting the number of box cars (two sixes) that occur.

You're given -

//********************************************************************

// PairOfDice.java Author: Lewis/Loftus

//

// Solution to Programming Project 4.8

//********************************************************************

public class PairOfDice

{

private Die die1, die2;

//-----------------------------------------------------------------

// Creates two six-sided Die objects, both with an initial

// face value of one.

//-----------------------------------------------------------------

public PairOfDice()

{

die1 = new Die();

die2 = new Die();

}

//-----------------------------------------------------------------

// Rolls both dice and returns the combined result.

//-----------------------------------------------------------------

public int roll()

{

return die1.roll() + die2.roll();

}

//-----------------------------------------------------------------

// Returns the current combined dice total.

//-----------------------------------------------------------------

public int getTotalFaceValue()

{

return die1.getFaceValue() + die2.getFaceValue();

}

//-----------------------------------------------------------------

// Returns the current value of the first die.

//-----------------------------------------------------------------

public int getDie1FaceValue()

{

return die1.getFaceValue();

}

//-----------------------------------------------------------------

// Returns the current value of the second die.

//-----------------------------------------------------------------

public int getDie2FaceValue()

{

return die2.getFaceValue();

}

//-----------------------------------------------------------------

// Returns the string representation of this pair of dice.

//-----------------------------------------------------------------

public String toString()

{

return "Die 1: " + die1.getFaceValue() + " Die 2: " +

die2.getFaceValue();

}

}

AND

//********************************************************************

// Die.java Author: Lewis/Loftus

//

// Solution to Programming Project 5.10 and 5.17 and 6.5

//

// Represents one die (singular of dice) with faces showing values

// between 1 and the number of faces on the die.

//********************************************************************

public class Die

{

private final int MAX = 6; // maximum face value

private int faceValue; // current value showing on the die

//-----------------------------------------------------------------

// Constructor: sets the initial face value.

//-----------------------------------------------------------------

public Die()

{

faceValue = 1;

}

//-----------------------------------------------------------------

// Rolls the die and returns the result.

//-----------------------------------------------------------------

public int roll()

{

faceValue = (int) (Math.random() * MAX) + 1;

return faceValue;

}

//-----------------------------------------------------------------

// Face value mutator.

//-----------------------------------------------------------------

public void setFaceValue (int value)

{

faceValue = value;

}

//-----------------------------------------------------------------

// Face value accessor.

//-----------------------------------------------------------------

public int getFaceValue()

{

return faceValue;

}

//-----------------------------------------------------------------

// Returns a string representation of this die.

//-----------------------------------------------------------------

public String toString()

{

String result = Integer.toString(faceValue);

return result;

}

}

I'm just really confused on what to do. Please be descriptive in the response it would be much appreciated. Thank you so much in advance!!

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!