mardi 24 juillet 2018

Random Enum returns null

Hello i am trying to get random ENUM, but it returns null, someone can help me what's wrong in my code ? I was trying to repair it alone but i give up.

public class LotteryMachine {

protected enum Sings {
    ONE,
    TWO,
    THREE
}

private static final List<Sings> SINGS_LIST = Collections.unmodifiableList(Arrays.asList(Sings.values()));
private static final int SIZE = SINGS_LIST.size();
private static final Random RANDOM = new Random();

Sings randomSing() {
    return SINGS_LIST.get(RANDOM.nextInt(SIZE));

}
}



public class Game {

private LotteryMachine lotteryMachine = new LotteryMachine();

private LotteryMachine.Sings singOne;
private LotteryMachine.Sings singTwo;
private LotteryMachine.Sings singThree;

private void Lottery(){
    this.singOne = lotteryMachine.randomSing();
    this.singTwo = lotteryMachine.randomSing();
    this.singThree = lotteryMachine.randomSing();
}

public void viewLottery(){
    System.out.print(singOne + " " + singTwo + " " + singThree);
}

}




Aucun commentaire:

Enregistrer un commentaire