请编写一个关于星期几的枚举WeekDay,要求: 枚举值:Mon,Tue,Wed,Thu,Fri,Sat,Sun 该枚举要有一个方法,调用该方法返回中文格式的星期。
package com.week.base; 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(); }
测试
package com.week.base; public class Demo1 { public static void main(String[] args) { String str = Grade.Mon.getValue(); String str1 = Grade.Mon.toLocalGrade(); System.out.println(str + "...." + str1); } }
本文出自 “点滴积累” 博客,请务必保留此出处http://tianxingzhe.blog.51cto.com/3390077/1737850