Here’s the relevant part of the Dice class:
import java.util.*;
class Dice
{
String name ;
int x ;
int[] sum ;
…
public Dice (String name)
{
this.name = name ;
this.x = 0 ;
this.sum = new int[7] ;
}
…
public void roll ()
{
this.x = randNum(1, this.sum.length) ;
this.sum[x] ++ ;
}
I am invoking this method in a separate class named Risk
class Risk
{
Heres the first line of the method:
public static void IdiceRoll (Dice o)
So this method takes a dice that already exists as a paramater so theres no need to create a new dice inside it.
Finaly here is how i’m trying to invoke roll on o:
o.Dice.roll () ;
In your other class, in some method, you need to get an instance of the class you’re trying to use. You need an import statement if you’re in another package.
Then it’s simple:
Also, refer to Sun’s documentation and try examples to get your feet under you.
Revision to match your changes: