import java.util.Scanner;
enum Week{ //定义一个枚举
MODAY("星期一"),TUESDAY("星期一"),
WEDNESDAY("星期一"),THURSDAY("星期一"),
FRIDAY("星期一"),SATURDAY("星期一"),
SUNDAY("星期一");
String week; //定义一个变量,作为临时变量
Week(String week){ //定义枚举构造函数
this.week=week;
}
public String getName()
{
return week;
}
public static Week getWeek(String week)
{ //定义一个静态方法,用来根据输入获取对应Week枚举值
switch(week)
{
case"mon":
return Week.MODAY;
case "tues":
return Week.TUESDAY;
case"wed":
return Week.WEDNESDAY;
case"thru":
return Week.THURSDAY;
case"fri":
return Week.FRIDAY;
case"sat":
return Week.SATURDAY;
case"sun":
return Week.SUNDAY;
default:
return Week.MODAY;
}
}
}
public class lianxi{
public static void main(String[] args)
{
System.out.println("---中英文星期对照表---");
Week weekArray[]=Week.values();//获取枚举数组
for(Week k:weekArray) {
System.out.println(k+"--"+k.getName());
}
System.out.print("\n请输入要查询的英文星期小写:");
Scanner sc=new Scanner(System.in);
Week week=Week.getWeek(sc.next());
switch(week)
{
case MODAY:
System.out.println("MODAY----"+week.getName());
break;
case TUESDAY:
System.out.println("TUESDAY----"+week.getName());
break;
case WEDNESDAY:
System.out.println("WEDNESDAY----"+week.getName());
break;
case THURSDAY:
System.out.println("THURSDAY----"+week.getName());
break;
case FRIDAY:
System.out.println("FRIDAY----"+week.getName());
break;
case SATURDAY:
System.out.println("SATURDAY----"+week.getName());
break;
case SUNDAY:
System.out.println("SUNDAY----"+week.getName());
break;
default:
System.out.println("输入有误");
break;
}
}
}