Enums

An enum defines a closed set of named instances. A Difficulty value can be EASY, MEDIUM, or HARD, but never arbitrary text.

Replacing loosely validated strings with an enum moves mistakes toward compile time and makes switch expressions exhaustive.

Limit the possible values

enum Difficulty {
    EASY, MEDIUM, HARD
}

public class Main {
    public static void main(String[] args) {
        String text = "medium";
        Difficulty difficulty = Difficulty.valueOf(
                text.toUpperCase());
        System.out.println(difficulty);
    }
}

Output:

MEDIUM

valueOf finds the constant whose name exactly matches the normalized input.

valueOf throws IllegalArgumentException for an unknown name. User input should be validated or handled rather than allowed to terminate a program.

Add the four compass directions and convert the input text to the matching enum value.