package 雇员;
public class test02 {
public static void main(String[] args){
MyDate m1 = new MyDate();
m1.setYear(2001);
m1.setMonth(2);
m1.setDay(28);
Employee e1 = new Employee("小刘",500000,m1);
System.out.println("姓名:"+e1.getName());
System.out.println("年薪:"+e1.getSalry());
System.out.println("受雇时间:"+e1.getHour().getYear()+"年"+e1.getHour().getMonth()+"月"+e1.getHour().getDay()+"天");
}
}
package 雇员;
public class Employee {
private String name;
private double salry;
private MyDate hour;
public Employee(String name, double salry, MyDate hour) {
this.name = name;
this.salry = salry;
this.hour = hour;
}
public Employee() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getSalry() {
return salry;
}
public void setSalry(double salry) {
this.salry = salry;
}
public MyDate getHour() {
return hour;
}
public void setHour(MyDate hour) {
this.hour = hour;
}
}
package 雇员;
import java.util.Scanner;
public class MyDate {
private int year;
private int month;
private int day;
Scanner scan = new Scanner(System.in);
public MyDate() {
}
public int getYear() {
return year;
}
public void setYear(int year) {
if(year <= 0)
System.out.println("请输入合法年份!");
else
this.year = year;
}
public int getMonth() {
return month;
}
public void setMonth(int month) {
if(month <= 0 && month >=13)
System.out.println("请输入合法的月份!");
else
this.month = month;
}
public int getDay() {
return day;
}
public void setDay(int day) {
MyDate d1 = new MyDate();
int max_day = d1.isLeapYear(this.year);
if(day > max_day && day <= 0)
System.out.println("请输入有效的天数!");
else
this.day = day;
}
public int isLeapYear(int year){
int t = 0;
switch (this.month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
t += 31;
break;
case 2:
if ((this.year % 4 == 0 && this.year % 100 != 0) || (this.year % 400 == 0)) {
t += 29;
break;
} else {
t += 28;
break;
}
case 4:
case 6:
case 9:
case 11:
t +=30;
break;
default:
System.out.println("请输入正确的年份和月份");
break;
}
return t;
}
}