super();
this.name = name;
this.sno = sno;
this.birth = birth;
this.zy = zy;
}
public static int getAge(Date birthDay) throws Exception {
Calendar cal = Calendar.getInstance();
if (cal.before(birthDay)) {
throw new IllegalArgumentException("出生时间大于当前时间!");
}
int yearNow = cal.get(Calendar.YEAR);
int monthNow = cal.get(Calendar.MONTH) + 1;
int dayOfMonthNow = cal.get(Calendar.DAY_OF_MONTH);
cal.setTime(birthDay);
int yearBirth = cal.get(Calendar.YEAR);
int monthBirth = cal.get(Calendar.MONTH);
int dayOfMonthBirth = cal.get(Calendar.DAY_OF_MONTH);
int age = yearNow - yearBirth;
if (monthNow <= monthBirth) {
if (monthNow == monthBirth) {
if (dayOfMonthNow
age--;
} else {
//do nothing
}
} else {
age--;
}
} else {
}
return age;
}
public void display() {
System.out.println("姓名:" + this.getName() + ", 学号:" + this.getSno()
+ ", 生日:" + this.getBirth() + ", 专业:" + this.getZy());
}
把这两个方法加进去