1 package dataStyle;
2 /**
3 * 较复杂的枚举类型
4 * @author ZolRa
5 *
6 */
7 public class ComEnum {
8
9 public static void main(String[] args) {
10 WeekDay weekDay = WeekDay.FRI;
11 System.out.println(weekDay.nextDay());
12 }
13
14 public enum WeekDay{
15 //调用带参构造方法,匿名子类重写nextDay()方法
16 SUN(1){
17 public WeekDay nextDay() {
18 return MON;
19 }
20 },
21 MON(2){
22 public WeekDay nextDay() {
23 return TUE;
24 }
25 },
26 TUE(3){
27 public WeekDay nextDay() {
28 return WED;
29 }
30 },
31 WED(4){
32 public WeekDay nextDay() {
33 return THU;
34 }
35 },
36 THU(5){
37 public WeekDay nextDay() {
38 return FRI;
39 }
40 },
41 FRI(6){
42 public WeekDay nextDay() {
43 return SAT;
44 }
45 },
46 SAT(7){
47 public WeekDay nextDay() {
48 return SUN;
49 }
50 };
51
52 //星期索引,星期日为第一天
53 private int index;
54 //Constructor,必须为private
55 private WeekDay(){}
57 private WeekDay(int index){
58 this.index = index;
59 }
60
61 //获取下一天
62 public abstract WeekDay nextDay();
63
64 public String toString() {
65 StringBuffer week = new StringBuffer();
66 switch (index) {
67 case 1: week.append("星期日");break;
68 case 2: week.append("星期一");break;
69 case 3: week.append("星期二");break;
70 case 4: week.append("星期三");break;
71 case 5: week.append("星期四");break;
72 case 6: week.append("星期五");break;
73 case 7: week.append("星期六");break;
74 }
75 return week.toString();
76 }
77 }
78 }
2 /**
3 * 较复杂的枚举类型
4 * @author ZolRa
5 *
6 */
7 public class ComEnum {
8
9 public static void main(String[] args) {
10 WeekDay weekDay = WeekDay.FRI;
11 System.out.println(weekDay.nextDay());
12 }
13
14 public enum WeekDay{
15 //调用带参构造方法,匿名子类重写nextDay()方法
16 SUN(1){
17 public WeekDay nextDay() {
18 return MON;
19 }
20 },
21 MON(2){
22 public WeekDay nextDay() {
23 return TUE;
24 }
25 },
26 TUE(3){
27 public WeekDay nextDay() {
28 return WED;
29 }
30 },
31 WED(4){
32 public WeekDay nextDay() {
33 return THU;
34 }
35 },
36 THU(5){
37 public WeekDay nextDay() {
38 return FRI;
39 }
40 },
41 FRI(6){
42 public WeekDay nextDay() {
43 return SAT;
44 }
45 },
46 SAT(7){
47 public WeekDay nextDay() {
48 return SUN;
49 }
50 };
51
52 //星期索引,星期日为第一天
53 private int index;
54 //Constructor,必须为private
55 private WeekDay(){}
57 private WeekDay(int index){
58 this.index = index;
59 }
60
61 //获取下一天
62 public abstract WeekDay nextDay();
63
64 public String toString() {
65 StringBuffer week = new StringBuffer();
66 switch (index) {
67 case 1: week.append("星期日");break;
68 case 2: week.append("星期一");break;
69 case 3: week.append("星期二");break;
70 case 4: week.append("星期三");break;
71 case 5: week.append("星期四");break;
72 case 6: week.append("星期五");break;
73 case 7: week.append("星期六");break;
74 }
75 return week.toString();
76 }
77 }
78 }
打印:星期六
来源:https://www.cnblogs.com/zolra/archive/2011/02/26/1966052.html