-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnumWithSwitchCase.java
More file actions
53 lines (43 loc) · 1.22 KB
/
Copy pathEnumWithSwitchCase.java
File metadata and controls
53 lines (43 loc) · 1.22 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package Phase1_CoreLanguage.Enumerations;
// A Java program to demonstrate working on enum
// in switch case (Filename Test. Java)
// An Enum class
enum Day {
SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
THURSDAY, FRIDAY, SATURDAY;
}
// Driver class that contains an object of "day" and
// main().
public class EnumWithSwitchCase {
Day day;
// Constructor
public EnumWithSwitchCase(Day day) {
this.day = day;
}
// Prints a line about Day using switch
public void dayIsLike() {
switch (day) {
case MONDAY:
System.out.println("Mondays are bad.");
break;
case FRIDAY:
System.out.println("Fridays are better.");
break;
case SATURDAY:
case SUNDAY:
System.out.println("Weekends are best.");
break;
default:
System.out.println("Midweek days are so-so.");
break;
}
}
// Driver method
public static void main(String[] args) {
String str = "MONDAY";
EnumWithSwitchCase t1 = new EnumWithSwitchCase(Day.valueOf(str));
t1.dayIsLike();
}
//OUTPUT
//Mondays are bad.
}