码迷,mamicode.com
首页 > 其他好文 > 详细

枚举工具类until

时间:2018-11-21 12:18:43      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:stat   string   ase   枚举   efault   this   工具   tco   ati   

 1 public enum RMB {
 2 
 3 
 4     YIBAI(100,"一百"),
 5     WUSHI(50,"五十"),
 6     SHIKUAI(10,"十块"),
 7     WUKUAI(5,"五块"),
 8     YIYUAN(1,"一元");
 9 
10     private int code;
11     private String name;
12 
13     private RMB(int code, String name) {
14         this.code = code;
15         this.name = name;
16     }
17 
18 
19     public int getCode() {
20         return code;
21     }
22 
23     public void setCode(int code) {
24         this.code = code;
25     }
26 
27     public String getName() {
28         return name;
29     }
30 
31     public void setName(String name) {
32         this.name = name;
33     }
34 
35     @Override
36     public String toString() {
37         return "RMB{" +
38                 "code=‘" + code + ‘\‘‘ +
39                 ", name=‘" + name + ‘\‘‘ +
40                 ‘}‘;
41     }
42 
43     public static String getRMBName(int code) {
44         for(RMB rmbEnum:  RMB.values()) {
45             if(rmbEnum.getCode() == code)
46                 return rmbEnum.name;
47         }
48         return null;
49     }
50 
51     public static RMB getRMBByCode(int code){
52         switch (code) {
53             case 1:
54                 return YIYUAN;
55             case 5:
56                 return WUKUAI;
57             case 10:
58                 return SHIKUAI;
59             case 50:
60                 return WUSHI;
61             case 100:
62                 return YIBAI;
63             default:
64                 return null;
65         }
66     }
67 
68 }

自用until

枚举工具类until

标签:stat   string   ase   枚举   efault   this   工具   tco   ati   

原文地址:https://www.cnblogs.com/caixiaoyou/p/9993858.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!