You need to return
the generated value because die()
has a return type of int
but there is no return statement in the method, thus throwing a compilation error .
public static int die()
{
return generator.nextInt(6)+1; // return the value
}
And you need to assign the returned value to some int variable(so that you can use it later) in the caller method.
public static void main(String[] args)
{
int rollValue = die();
// Do something with rollValue
}
Q. Thank you, here's my current code, still giving me the compiler-error: error: cannot find symbol return generator.nextInt(6)+1; ^ symbol: variable generator
Since you don't have the generator
defined anywhere in the class, it is not able to find it. It should be defined in your class. Something like this
public class dieSimulator
{
Random generator = new Random(); //Just as an example
...