package com.itheima;
/**
*
* 第四题 4、 自定义枚举 Week 用于表示星期,Mon,Tue,Wed...
* 要求每个枚举值都有toLocaleString 方法,
* 用于获得枚举所表示的星期的中文格式 星期一、星期二、星期三...
* @author Administrator
*
*/
public class Test4 {
public static void main(String[] args) {
Week s=new Week();
s.setName("今天");
s.setGrade(Grade.Mon);
String str=Grade.Mon.getValue();
String str1=Grade.Mon.toLocalGrade();
System.out.println(str+"...."+str1);
}
}
class Week {
private String name;
private Grade grade;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Grade getGrade() {
return grade;
}
public void setGrade(Grade grade) {
this.grade = grade;
}
}
enum Grade{
Mon("Monday") {
@Override
public String toLocalGrade() {
// TODO Auto-generated method stub
return "星期一";
}
},
Tue("Tuesday") {
@Override
public String toLocalGrade() {
// TODO Auto-generated method stub
return "星期二";
}
},
Wed("Wednesday") {
@Override
public String toLocalGrade() {
// TODO Auto-generated method stub
return "星期三";
}
},
Thu("Thursday") {
@Override
public String toLocalGrade() {
// TODO Auto-generated method stub
return "星期四";
}
},
Fri("Friday") {
@Override
public String toLocalGrade() {
// TODO Auto-generated method stub
return "星期五";
}
},
Sat("Saturday") {
@Override
public String toLocalGrade() {
// TODO Auto-generated method stub
return "星期六";
}
},
Sun("Sunday") {
@Override
public String toLocalGrade() {
// TODO Auto-generated method stub
return "星期日";
}
}, ;
private String value;
private Grade(String value){
this.value=value;
}
public String getValue() {
return value;
}
public abstract String toLocalGrade();
}
|
|