import java.util.*;
//本程序演示的是ArrayList 类的用法,该类是泛型类,里面 可以装 泛型的类,它主要是动态数组的能力,可以用 add remove set 等方法
public class ArrayListTest {
public static void main(String [] args)
{
//构建一个Manager 对象
//Employee[] staff=new Employee[3];
//用经理和员工来填充这个staff数组
// staff[0]=boss;
// staff[1]=new Employee("Tom Zhou",50000,2022,7,10);
// staff[2]=new Employee("Jerry Mouse",50000,2022,8,10);
ArrayList<Employee> staff_new=new ArrayList<Employee>();
staff_new.add(new Employee("Ge Bi Lao Wang",75000,2000,12,15));
staff_new.add(new Employee("YaSe",15000,2050,12,15));
staff_new.add(new Employee("JiaLuo",5000,1050,12,15));
//给每个人涨 5%的工资
for (Employee employee:staff_new)
employee.raiseSalary(5);
//打印信息
for(Employee e:staff_new)
{
System.out.println("name=" + e.getName() + ",salary=" + e.getSalary()+",hireDay="+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 String getName()
{
return name;
}
public double getSalary()
{
return salary;
}
public Date getHireDay()
{
return hireDay;
}
public void raiseSalary(double byPercent)
{
double raise=salary*byPercent/100;
salary+=raise;
}
private String name;
private double salary;
private Date hireDay;
}
运行结果:
name=Ge Bi Lao Wang,salary=78750.0,hireDay=Fri Dec 15 00:00:00 CST 2000
name=YaSe,salary=15750.0,hireDay=Thu Dec 15 00:00:00 CST 2050
name=JiaLuo,salary=5250.0,hireDay=Sat Dec 15 00:00:00 CST 1050