I'm writing a switch statement where the initial conditional statement is a user-inputted string: specifically either "North", "South", "East" or "West", each corresponding to a case "branch". However the problem requires that each should be non-case sensitive: i.e. users can input "north", "NORTH", "NoRTh", etc.... and each should generate the correct corresponding output.
Based on my understanding, the "case" part of switch statements can only have simple equality checks, so how would I go about implementing this? Could I use something like equalsIgnoreCase() somewhere else in my code? I've attached the switch statement I wrote below using a brute force approach, since I don't know how to account for every permutation of upper and lower-case inputs.
switch (input) {
case "NORTH":
case "North":
case "north":
System.out.println("0 degrees from North");
break;
case "SOUTH":
case "South":
case "south":
System.out.println("180 degrees from North");
break;
case "EAST":
case "East":
case "east":
System.out.println("90 degrees from North");
break;
case "WEST":
case "West":
case "west":
System.out.println("270 degrees from North");
break;
default:
System.out.println("Invalid");
}