Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Die Class, My problem is at the bottem in the Driver ******************************************************************** //Die.java Author: Lewis/Loftus // //Represents one die (singular of dice) with faces showing

Die Class, My problem is at the bottem in the Driver

********************************************************************

//Die.java Author: Lewis/Loftus

//

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

//between 1 and 6.

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

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;

}

}

This is the pair od dice program

// Java class that hold pair of dice

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

class PairOfDice

{

//Public instance variables

private Die die1;

private Die die2;

//Constructor

public PairOfDice()

{

die1 = new Die();

die2 = new Die();

}

//Setter method that gets face value

public void setDie1(int val)

{

die1.setFaceValue(val);

}

public void setDie2(int val)

{

die2.setFaceValue(val);

}

//Getter method that returns value of two dice

public int getDie1()

{

return die1.getFaceValue();

}

public int getDie2()

{

return die2.getFaceValue();

}

// Roll two dice method

public int roll()

{

die1.roll();

die2.roll();

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

}

public String toString()

{

String result = (die1.toString() + " " + die2.toString());

return result;

}

}

This is where I am having a problem, I need to test everything with this Driver class. I was doing fine until I tried working with manual values. Need help completing full test of PairOfDice. This is all part of the standard Die class

/* Driver Class testing dice*/ public class Driver { public static void main(String args[]) { //Object pair of dice PairOfDice dice = new PairOfDice();

//Dice rolling dice.roll();

//Print values of two dice System.out.println("Die1 Outcome:" + dice.getDie1()); System.out.println("Die2 Outcome:" + dice.getDie2()); //Print sum of two dice System.out.println("Die1 + Die2 Outcome: " + (dice.getDie1() + dice.getDie2()));

// set two manual dice dice.setDie1(3); dice.setDie2(6);

// display the manual values of two dice and their sum System.out.println(dice.Die1); } }

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

More Books

Students also viewed these Databases questions

Question

=+Is the humor appropriate for the organization?

Answered: 1 week ago