vendredi 10 mai 2019

Class Random Java: The method "roll()" is undefined for type Random. Why?

I have to use method signature: public int roll() I just don't understand why I can't call that method from my new random object. Please help.

import java.util.Random;


public class Die {

    private int faceValue;
    private Random random;

    public Die() {
        Random r = new Random();
            r.roll(); // "The method roll() is undefined for the type Random
    }

    public int getFaceValue() {
        return faceValue;
    }

    public int roll() {
        for(int i = 1; i <= 11; i++)
        {
            faceValue = random.nextInt(6) + 1;
        }
        return faceValue;
    }
}




Aucun commentaire:

Enregistrer un commentaire