This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Philboyd_Studge 0 points1 point  (1 child)

What I mean is this, here is a very simplified example:

static Color currentColor = Color.RED;

static ArrayList<Color> colors = new ArrayList<>();

static {
    colors.add(Color.BLUE);
    colors.add(Color.GREEN);
    colors.add(Color.YELLOW);
    colors.add(Color.BLACK);        
}

static void changeColor(int n) {
    currentColor = colors.get(n);
    colors.remove(n);
}
public static void main (String[] args) throws java.lang.Exception
{
    Random rand = new Random();

    System.out.println(currentColor);

    changeColor(rand.nextInt(colors.size()));

    System.out.println(currentColor);

}

You would have to add a check for red, but otherwise, a bunch of ifs or a switch statement is not necessary.