public class CalenderDate {
//对象中的年份属性
private int year;
//对象中的月份属性
private int mouth;
//对象中的天属性
private int day;
public CalenderDate(int year, int mouth, int day) {
this.year = year;
this.mouth = mouth;
this.day = day;
}
public int getweek() {
int M = this.mouth >= 3 ? this.mouth - 2 : this.mouth + 10;
int D = this.day;
int year = this.mouth >= 3 ? this.year : this.year - 1;
int Y = year % 100;
int C = year / 100;
int F = (26 * M - 2) / 10 + D + Y + Y / 4 + C / 4 - 2 * C;
int W = F % 7;
return W < 0 ? W + 7 : W;
}
public boolean before(CalenderDate date) {
if (this.year > date.year) return false;
if (this.year < date.year) return true;
//然后比较月份
if (this.mouth > date.mouth) return false;
if (this.mouth < date.mouth) return true;
//最后比就天数
return this.day < date.day;
}
public boolean after(CalenderDate date) {
if (this.year > date.year) return true;
if (this.year < date.year) return false;
//然后比较月份
if (this.mouth > date.mouth) return true;
if (this.mouth < date.mouth) return false;
//最后比就天数
return this.day > date.day;
}
public int maxDay(int month){
return switch (month){
case 1,3,5,7,8,10,12 -> 31;
case 2 -> feb();
default -> 30;
};
}
public int getDate() {
int day = this.day;
for (int i = 1;i
然后我们简单的测试一下
public class Testclass {
public static void main(String[] args) {
CalenderDate cd = new CalenderDate(2022,6,13);
System.out.println(cd.getweek());
CalenderDate date = new CalenderDate(2022,7,9);
boolean before = date.before(cd);
System.out.println(before?"是":"否");
boolean after = date.after(cd);
System.out.println(after?"是":"否");
int day = cd.getDate();
System.out.println("今天是该年的第"+day+"天");
cd.showCalender();
}
}



