import java.util.*;
public class WeekDay
{
private int month,day,countDay,toDay;
private String engMonth=new String();
private static boolean isTrue;
private Scanner keyboard=new Scanner(System.in);
public static void main(String args [])
{
WeekDay onedate=new WeekDay();
//boolean bb;
System.out.println("The program can calculate what date is the day you enter in 2008");
do
{ onedate.getMouth();
onedate.getDay();
onedate.swithDate();
onedate.calDate();
//bb=onedate.aa();
}while(isTrue); //在靜態方法中無法引用非靜態成員變數,所以要把isTrue設定為static
}
public void getMouth()
{
System.out.print("Enter the month(1-12)>");
month=keyboard.nextInt();
while(month>12){System.out.println("Wrong input!try again!");
System.out.print("Enter the month(1-12)>");
month=keyboard.nextInt();
}
}
public void getDay()
{
switch(month)
{ case 1 :
case 3 :
case 5 :
case 7 :
case 8 :
case 10 :
case 12 : System.out.print("Enter the day(1-31)>");
day=keyboard.nextInt();
while(day>31){System.out.println("Wrong input!try again!");
System.out.print("Enter the day(1-31)>");
day=keyboard.nextInt();
}
break;
case 2 : System.out.print("Enter the day(1-29)>");
day=keyboard.nextInt();
while(day>29){System.out.println("Wrong input!try again!");
System.out.print("Enter the day(1-29)>");
day=keyboard.nextInt();
}
break;
case 4 :
case 6 :
case 9 :
case 11 : System.out.print("Enter the day(1-30)>");
day=keyboard.nextInt();
while(day>30){System.out.println("Wrong input!try again!");
System.out.print("Enter the day(1-30)>");
day=keyboard.nextInt();
}
System.out.println(day);
break;
}
}
public void swithDate()
{
switch(month)
{
case 1 : countDay=day; engMonth="january";break;
case 2 : countDay=31+day; engMonth="February";break;
case 3 : countDay=31+29+day; engMonth="March";break;
case 4 : countDay=31*2+29+day; engMonth="Aprial";break;
case 5 : countDay=31*2+29+30+day; engMonth="mary";break;
case 6 : countDay=31*3+29+30+day; engMonth="June";break;
case 7 : countDay=31*3+29+30*2+day; engMonth="July";break;
case 8 : countDay=31*4+29+30*2+day; engMonth="August";break;
case 9 : countDay=31*5+29+30*2+day; engMonth="September";break;
case 10 : countDay=31*4+29+30*3+day; engMonth="October";break;
case 11 : countDay=31*5+29+30*3+day; engMonth="Novenmber";break;
case 12 : countDay=31*5+29+30*4+day; engMonth="December";break;
}
toDay=countDay%7;
}
public void calDate()
{
switch(toDay)
{
case 0 :System.out.println(engMonth+","+day+" 2008 is Monday.");break;
case 1 :System.out.println(engMonth+","+day+" 2008 is Teusday.");break;
case 2 :System.out.println(engMonth+","+day+" 2008 is Wensday.");break;
case 3 :System.out.println(engMonth+","+day+" 2008 is Tursday.");break;
case 4 :System.out.println(engMonth+","+day+" 2008 is Friday.");break;
case 5 :System.out.println(engMonth+","+day+" 2008 is Saturday.");break;
case 6 :System.out.println(engMonth+","+day+" 2008 is Sunday.");break;
}
System.out.print("Calculate again?(true/false)");
isTrue=keyboard.nextBoolean();
}
/*public boolean aa()
{
return(isTrue);
}*/
}