Season.java Source code

Java tutorial

Introduction

Here is the source code for Season.java

Source

import java.util.Random;

enum Season {
    WINTER, SPRING, SUMMER, FALL
}

class RandomEnum<E extends Enum<Season>> {
    Random RND = new Random();
    E[] values;

    public RandomEnum(Class<E> token) {
        values = token.getEnumConstants();
    }

    public E random() {
        return values[RND.nextInt(values.length)];
    }
}

public class Main {
    public static void main(String[] args) {
        RandomEnum<Season> r = new RandomEnum<Season>(Season.class);
        System.out.println(r.random());
    }
}