【枚举三】深夜发总结。困死媛媛了··=_=
发完睡觉啦
- package enums;
- /**
- * @author 小媛
- * ① 使用带有参数的枚举
- * ②枚举中添加了属性的获取方法
- */
- public class EnumDemo3 {
- public static void main(String[] args) {
- //假定数据:一开始给的是SUN
- Week3 week = Week3.SUN;
-
- //调用方法获取明天是星期几
- week = NextWeek(week);
- System.out.println(week.getWeekName());
- }
-
- public static Week3 NextWeek(Week3 currentWeek) {
-
- switch (currentWeek) {
- case SUN:
- currentWeek = Week3.MON;
- break;
- case MON:
- currentWeek = Week3.TUES;
- break;
- case TUES:
- currentWeek = Week3.WED;
- break;
- case WED:
- currentWeek = Week3.THUR;
- break;
- case THUR:
- currentWeek = Week3.FRI;
- break;
- case FRI:
- currentWeek = Week3.SAT;
- break;
- case SAT:
- currentWeek = Week3.SUN;
- break;
- default:
- break;
- }
-
- return currentWeek;
- }
- }
- enum Week3 {
- SUN(0, "星期天"), MON(1, "星期一"), TUES(2, "星期二"), WED(3,"星期三"), THUR(4,"星期四"), FRI(5,""), SAT(6,"");
- private int index;
- private String weekName;
- private Week3(int index, String weekName) {
- this.index = index;
- this.weekName = weekName;
- }
- public int getIndex() {
- return index;
- }
- public void setIndex(int index) {
- this.index = index;
- }
- public String getWeekName() {
- return weekName;
- }
- public void setWeekName(String weekName) {
- this.weekName = weekName;
- }
- }
复制代码
|