public class EmployeeTest //定义类{public static void main(String[] args){Employee[] staff=new Employee[3];//创建数组staff[0]=new Employee(“zhangsan”,75000,1987,12,15);//添加员工资料进数组staff[1]=new Employee(“lisi”,50000,1989,10,1);staff[2]=new Employee(“wangwu”,40000,1990,3,15); for(Employee e:staff){//注:不要丢掉大括号 e。
raiseSalary(5); } for(Employee e:staff){//注:不要丢掉大括号 intln(“name”+ tName()+”,salary=”+ tSalary()+”,hireDay=”+ tHireDay()); }}/***定义员工类*/class Employee{/***定义构造方法*@param n员工姓名参数*@param s员工工资参数*@param year出生年份*@param month出生月份*@param day出生日期*/public Employee(String n,double s,int year,int month,int day){name=n;//姓名赋值salary=s;//工资赋值GregorianCalendar Calendar=new GregorianCalendar(year,month-1,day);//创建日历对象(注:这里原先你在赋值时,没有定义对象名称)hireDay= tTime();//取得日历对象中的日期}/***获取姓名函数*@return String 返回姓名*/public String getName(){return name;}/***获取工资函数*@return double 返回工资*/public double getSalary(){return salary;}/***获取生日*@return Date 返回生日日期对象*/public Date getHireDay(){return hireDay;}/***设置工资增长幅度*@param byPercent工资增加百分比*/public void raiseSalary(double byPercent){double raise=salary*byPercent/100;salary+=raise;}private String name;//内部私有变量姓名private double salary;//内部私有变量工资private Date hireDay;//内部私有变量出生日期}。