-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestenum.java
More file actions
58 lines (54 loc) · 1.06 KB
/
Copy pathTestenum.java
File metadata and controls
58 lines (54 loc) · 1.06 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
package com.example;
public class Testenum {
/**
* @param args
*/
public static void main(String[] args) {
RMB item = Enum.valueOf(RMB.class,"ONE");
System.out.println(item.toString());
for(RMB r:RMB.values())
{
System.out.println(r+",ordinal "+r.ordinal()) ;
}
RMBDescription
one =new RMBDescription(RMB.ONE),
tewnty =new RMBDescription(RMB.TWENTY);
one.describe();
tewnty.describe();
}
}
enum RMB {ONE,Five,Ten,TWENTY,FIFTY, ONEHANDRED}
class RMBDescription
{
RMB r;
public RMBDescription(RMB r)
{
this.r=r;
}
public void describe(){
//
System.out.println("style:");
switch(r)
{
case ONE:
System.out.println("一元");
break;
case Five:
System.out.println("五元");
break;
case Ten:
System.out.println("十元");
break;
case TWENTY:
System.out.println("二十元");
break;
case FIFTY:
System.out.println("五十元");
break;
case ONEHANDRED:
System.out.println("一百元");
break;
default: System.out.println("格式错误");
}
}
}