-
Die Rolling Program
So first I'm supposed to create a Die class for generating a random number from 1 to 6
import java.util.*;
public class Die
{
int faceValue;
final int HIGHEST_DIE_VALUE = 6;
final int LOWEST_DIE_VALUE = 1;
public int getRoll()
{
return faceValue;
}
public void setRoll(int rolled)
{
faceValue = ((int)(Math.random() * 100) % HIGHEST_DIE_VALUE + LOWEST_DIE_VALUE);
}
}
Then my next class prints out the value of rolling two dice.
public class TwoDice
{
public static void main(String[] args)
{
Die dieRoll = new Die();
System.out.println("The first die roll is " + dieRoll.getRoll());
System.out.println("The seoncd die roll is " + dieRoll.getRoll());
}
}
The number that keeps printing no matter how many runs is always 0.
-
Re: Die Rolling Program
A lot of this doesn't make sense. Why does the setRoll() method take a parameter that it never uses? When is that method ever called?
I suggest stepping through this in your head and figuring out why this doesn't do what you expect it to.
-
Re: Die Rolling Program
Ah, I see it now. Yes, I forgot to actually call the into play the set method. I'm just jumping back into programming after a about a 2 year break so I'm super rusty. It runs fine now, tyvm.