forked from PacktPublishing/Java-Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
27 lines (22 loc) · 649 Bytes
/
Main.java
File metadata and controls
27 lines (22 loc) · 649 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package modern.challenge;
public class Main {
public enum PlayerTypes {
TENNIS,
FOOTBALL,
SNOOKER,
GOLF,
VOLLEY
}
public static void main(String[] args) {
SportType sportType = fetchSportTypeByPlayerType(PlayerTypes.VOLLEY);
System.out.println("Sport type: " + sportType);
}
private static SportType fetchSportTypeByPlayerType(PlayerTypes playerType) {
return switch (playerType) {
case TENNIS, GOLF, SNOOKER->
new Individual();
case FOOTBALL, VOLLEY->
new Team();
};
}
}