日期:2014-05-20 浏览次数:20764 次
import java.util.*;
public class Test
{
public static void main(String[] args)
{
Employee[] staff = new Employee[3];
staff[0] = new Employee("abc", 3000, 1999, 10, 20);
staff[1] = new Employee("efg", 4000, 2000, 11, 12);
staff[2] = new Employee("opq", 5000, 2012, 6, 12);
for(Employee e: staff)
{
e.raiseSalary(10);
}
for(Employee e: staff)
{
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 String getName()
{
return name;
}
public double getSalary()
{
return salary;
}
public Date getHireDay()
{
return hireDay;
}
public void raiseSalary(int x)
{
salary = salary*(1 + x/100);
}
String name;
double salary;
Date hireDay;
}