package qbb;
public class WeekDay {
public final static WeekDay SUN = new WeekDay();
public final static WeekDay MON = new WeekDay();
public final static WeekDay TUE = new WeekDay();
public final static WeekDay WES = new WeekDay();
public final static WeekDay THU = new WeekDay();
public final static WeekDay FRI = new WeekDay();
public final static WeekDay SAT = new WeekDay();
private WeekDay(){
}
public WeekDay nextDay(){
if(this == SUN){
return MON;
}else if(this == MON){
return TUE;
}else if(this == TUE){
return WES;
}else if(this == WES){
return THU;
}else if(this == THU){
return FRI;
}else if(this == FRI){
return SAT;
}else{
return SUN;
}
}
public String toString(){
if(this == SUN){
return "SUN";
}else if(this == MON){
return "MON";
}else if(this == TUE){
return "TUE";
}else if(this == WES){
return "WES";
}else if(this == THU){
return "THU";
}else if(this == FRI){
return "FRI";
}else{
return "SAT";
}
}
}
if-else太多了
除了匿名内部类,能不能用别的方法替换nextDay()和toString()中的if-else呢? |