package com.net.firstjava; //引入此单元,调用GregorianCalendar import java.util.*; public class EmployeeTest { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub //将三个员工对象的数据赋值给职工数组 Employee[] staff = new Employee[3]; staff[0] = new Employee("张三", 7500, 1987, 6, 26); staff[1] = new Employee("李四", 650, 1999, 10, 28); staff[2] = new Employee("小张", 830, 2001, 9, 11); for (int i = 0; i < staff.length; i++) staff[i].raiseSalary(5);//每个员工的工资增长5% for (int i = 0; i < staff.length; i++)// 打印输出员工信息 { Employee e = staff[i]; System.out.println("姓名=" + e.getName() + ",工资=" + e.getSalary() + ",工作日期=" + e.getHireDay()); } } } //声明一个雇员类 class Employee{ 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 = calendar.getTime(); } //工资计算函数 public void raiseSalary(double byPrecent){ double raise = salary*byPrecent / 100; salary += raise; } //Get*通过 菜单->Source->Generate Getters and Setters... /** * @return the hireDay */ public Date getHireDay() { return hireDay; } /** * @return the name */ public String getName() { return name; } /** * @return the salary */ public Double getSalary() { return salary; } private String name; private Double salary; private Date hireDay; }