Navigating with Enum
Enums are great for representing real-world directions clearly in code. Imagine you're creating a navigation feature for an application that provides instructions to users.
Deze oefening maakt deel uit van de cursus
Input/Output and Streams in Java
Oefeninstructies
- Define an
enumnamedDirectioncontaining constants:NORTH,EAST,SOUTH, andWEST. - Create a method with a
Directionparameter. - Print the
EASTdirection usingprintDirection().
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
public class EnumDemo {
// Define enum
____ Direction {
NORTH, EAST, SOUTH, WEST
}
// Method with enum parameter
static void printDirection(____ direction) {
System.out.println("Direction: " + direction);
}
// Call method with EAST
public static void main(String[] args) {
printDirection(____.____);
}
}