已给出如图所示程序。但是要将程序改动为显示格式为“Jan26,1985”,然后在Mainmethod的dateclass中建立一个新的Object,MyDate然后使程序显示日期Jan31,2015。publicclassDate{prote...
已给出如图所示程序。但是要将程序改动为显示格式为“Jan 26, 1985”,然后在Main method的date class中建立一个新的Object,My Date然后使程序显示日期 Jan 31, 2015。
public class Date {
protected int year;
protected int month;
protected int day;
public static final int MINYEAR = 1583;
//Constructor
public Date(int newMonth, int newDay, int newYear){
month = newMonth;
day = newDay;
year = newYear;
}
//Observers
public int getYear(){
return year;
}
public int getMonth(){
return month;
}
public int getDay(){
return day;
}
public int lilian(){
// Returns the Lilian Day Number of this date.
// Algorithm goes here.
// See Lilian Day Numbers feature section for details.
final int Subdays = 578100;
int numDays = 0;
numDays = year * 365;
if (month <= 2)
numDays = numDays + (month - 1) * 31;
else
numDays = numDays + ((month - 1)* 31)
-((4 * (month - 1) + 27) / 10);
numDays = numDays + day;
numDays = numDays + day;
numDays = numDays + (year / 4) - (year / 100) + (year / 400);
if (month < 3){
if ((year % 4) == 0) numDays = numDays - 1;
if ((year % 100) == 0) numDays = numDays + 1;
if ((year % 400) == 0) numDays = numDays -1;
}
numDays = numDays - Subdays;
return numDays;
}
public String toString(){
//Returns this date as a String
return(month + "/" + day + "/" + year);
}
}
展开