package com.itheima;
public class Test3 {
/**
* 3、 自定义枚举 Week 用于表示星期,Mon,Tue,Wed...要求每个枚举值都有toLocaleString 方法,用于获得枚举所表示的星期的中文格式 星期一、星期二、星期三...
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
WeekDay weekDay=WeekDay.MONDAY;
System.out.println(weekDay.toLocaleString());
}
public enum WeekDay {
MONDAY("星期一"),
TUESDAY("星期二"),
WENDNESDAY("星期三"),
THURSDAY("星期四"),
FRIDAY("星期五"),
SATURDAY("星期六"),
SUNDAY("星期天");
private String cnName;
private WeekDay(String cnName) {
this.cnName = cnName;
}
public String toLocaleString() {
return cnName;
}
}
}
|
|