My professor wants me to force the value of d1 (dice 1) to the value of d2 (dice 2) and the only way I can think to do it is skip all the dice ling and just println it. I guess I don't understand how to compare the 2 items and make FORCE them to equal each other. He also says, "Remember cascading (you can code a call anywhere the returned data type makes sense)" If I can only fix this by using one line of code how can I cascade? Please help.
public class Lab17A {
public static void main(
String[] args) {
Dice d1 = new Dice();
Dice d2 = new Dice();
System.out.println("Start: " + d1.getValue() + ", " + d2.getValue());
do {
d1.roll();
d2.roll();
// YOUR STATEMENT GOES HERE
System.out.println("Rolled: " + d1.getValue() + ", " + d2.getValue());
} while(d1.getValue() != d2.getValue());
System.out.println("Game over");
}
}
class Dice {
private int sides;
private int value;
public Dice() {
setSides(6);
roll();
}
public void setSides(int n) {
if (n >= 2)
sides = n;
else
sides = 6;
}
public void setValue(int n) {
if (n > 0 && n <= sides)
value = n;
}
public int getSides() {
return sides;
}
public int getValue() {
return value;
}
public void roll() {
value = (((int)(Math.random() * 1000)) % sides) + 1;
}
}