-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnumDemo3.java
More file actions
60 lines (47 loc) · 1.75 KB
/
Copy pathEnumDemo3.java
File metadata and controls
60 lines (47 loc) · 1.75 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
54
55
56
57
58
59
60
enum Transport {
CAR(65), TRUCK(55), AIRPLANE(600), TRAIN(70), BOAT(22);
private int speed;
Transport(int s) { speed = s; }
int getSpeed() { return speed; }
}
class EnumDemo3 {
public static void main(String args[]) {
Transport tp, tp2, tp3;
System.out.println("Values of Transport: ");
Transport allTransports[] = Transport.values();
for(Transport t : allTransports) {
System.out.println("Speed of " + t + ": " + t.getSpeed() + " miles per hour");
System.out.println(t.ordinal());
}
System.out.println();
tp = Transport.valueOf("AIRPLANE");
System.out.println("tp equals to: " + tp);
tp2 = Transport.TRAIN;
tp3 = Transport.AIRPLANE;
if(tp.compareTo(tp2) < 0)
System.out.println(tp + " is before " + tp2);
else if(tp.compareTo(tp2) < 0)
System.out.println(tp2 + " is before " + tp);
if(tp.compareTo(tp3) == 0)
System.out.println(tp + " equals to " + tp3);
if(tp == Transport.TRAIN)
System.out.println("tp equals to TRAIN\n");
switch(tp) {
case CAR:
System.out.println("CAR transfer people");
break;
case TRUCK:
System.out.println("TRUCK transfer cargo");
break;
case AIRPLANE:
System.out.println("AIRPLANE flys");
break;
case TRAIN:
System.out.println("TRAIN rides on rails");
break;
case BOAT:
System.out.println("BOAT floats on water");
break;
}
}
}