Validating user entry by referencing to an enum in Java

Viewed 29

I have made the following enum Class.

public enum Option {
    ONE(1), TWO(2), THREE(3), FOUR(4), FIVE(5);

    private int option;

    private Option(int option) {
        this.option = option;
    }

    public int getOption() {
        return option;
    }
}

Now user is asked to input a value 1, 2, 3, 4 or 5

int value =  input.nextInt();

Can I check if the user has made a valid entry using the enum?

0 Answers
Related