vendredi 12 avril 2019

How come my forloop's print statement, can't find my enum roles?

I am writing a small program about the card game Mafia. So far, I've only been able to show the user, the role and their corresponding objective. Now I'm trying to get a random role from the enum, roles. The problem is that my forloop can't find the enum, roles.

So, in the line of code: System.out.println(i, roles.getRandomRole()); .... the enum, roles can't be found

Any help would be much appreciated!!

I have already tried putting everything public.

this is the main with the forloop

//Pick a random role one time.
public class Mafia_v2
{
public static void main(String[] args)
 {
       for(int i = 0; i < 2; i++)
       {
           System.out.println(i, roles.getRandomRole());
       }
 }
}

this is the class where the enum is

public class theDeck
{
    /**
    * roles enum
    */
    public enum roles
    {
        MAFIA,
        COP,
        ANGEL,
        CIVILIAN;

        /**
        * Pick a random value from the Roles enum.
        * @return a random Role
        */

        public static roles getRandomRole()
        {            
            Random randomRole = new Random();
            return values()[randomRole.nextInt(values().length)];
        }
     } 
}

I want it to print out "Your card is :" + getRandomRole




Aucun commentaire:

Enregistrer un commentaire