-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenums.java
More file actions
29 lines (29 loc) · 931 Bytes
/
enums.java
File metadata and controls
29 lines (29 loc) · 931 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
28
29
import java.util.Scanner;
public class enums {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the day: ");
String response = sc.nextLine().toUpperCase();
try {
Day day = Day.valueOf(response);
switch (day) {
case MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY -> System.out.print("weekday");
case SATURDAY, SUNDAY -> System.out.print("weekend");
default -> System.out.print("not a valid day");
}
} catch (IllegalArgumentException e) {
System.out.print("something went wrong");
}
}
}
enum Day{
SUNDAY(1),MONDAY(2),TUESDAY(3),WEDNESDAY(4),THURSDAY(5),FRIDAY(6),SATURDAY(7);
private final int daynum;
Day(int daynum)
{
this.daynum=daynum;
}
public int getday(){
return this.daynum;
}
}