员工身份信息登记系统

作者在 2016-08-23 23:06:30 发布以下内容
员工身份信息登记系统
package xiti;
class Date{
private int year;
private int month;
private int day;
public Date(int y,int m,int d){    //此处为带参数的构造方法
year=y;
month=m;
day=d;
}
public Date(){ //此处为不带参数的构造方法,所以有了下面的方法赋值
year=2016; //构造方法不含有void 不能返回值 只有public + 类名()参数{方法体}
month=8;
day=4;
}/*
public void setYear(int y){
year=y;
}
public void setMonth(int m){
month=m;
}
public void setDay(int d){
day=d;
}*/
public int getYear(){
return year;
}
public int getMonth(){
return month;
}
public int getDay(){
return day;
}
public void setDate(Date myDate){
year=myDate.getYear();
month=myDate.getMonth();
day=myDate.getDay();//此方法赋值只需3+1个函数,而用上面的方法却需要3+3个函数
}
}
class Emploee{
private String name;
private double salary;
private Date hireDate;
public Emploee(String name,double salary,Date hireDay){
this.name=name;
this.salary=salary;
this.hireDate=hireDay;

public void print(){
System.out.println(name+salary+hireYear());
}
public int hireYear(){
return hireDate.getYear();

}
public double raiseSalary(double bypercent){
return salary=salary*(1+bypercent/100);
}
}
public class myTestClass {


public static void main(String[] args) {
Emploee staff[]=new Emploee[3];
staff[0]=new Emploee("张一",10000,new Date(2017,6,6));
staff[1]=new Emploee("张二",10000,new Date(2016,6,6));
staff[2]=new Emploee("张三",10000,new Date(2016,6,6));
for(int i=0;i<staff.length;i++){
staff[i].raiseSalary(5);
}
System.out.println("The information of these Emploee is: ");
for(int i=0;i<staff.length;i++){
//System.out.println(staff[i]); 错的,因为封装了
staff[i].print();
}
}
代码-初级 | 阅读 2452 次
文章评论,共0条
游客请输入验证码
文章归档
最新评论