You are on page 1of 2

ArrayListTest.

java
1. import java.util.*;
2.
3. public class ArrayListTest
4. {
5.
public static void main(String[] args)
6.
{
7.
// fill the staff array list with three Employee objects
8.
ArrayList<Employee> staff = new ArrayList<Employee>();
9.
10.
staff.add(new Employee("Carl Cracker", 75000, 1987, 12, 15));
11.
staff.add(new Employee("Harry Hacker", 50000, 1989, 10, 1));
12.
staff.add(new Employee("Tony Tester", 40000, 1990, 3, 15));
13.
14.
// raise everyone's salary by 5%
15.
for (Employee e : staff)
16.
e.raiseSalary(5);
17.
18.
// print out information about all Employee objects
19.
for (Employee e : staff)
20.
System.out.println("name=" + e.getName()
21.
+ ",salary=" + e.getSalary()
22.
+ ",hireDay=" + e.getHireDay());
23.
}
24. }
25.
26. class Employee
27. {
28.
public Employee(String n, double s, int year, int month, int day)
29.
{
30.
name = n;
31.
salary = s;
32.
GregorianCalendar calendar = new GregorianCalendar(year, month - 1, da
y);
33.
hireDay = calendar.getTime();
34.
}
35.
36.
public String getName()
37.
{
38.
return name;
39.
}
40.
41.
public double getSalary()
42.
{
43.
return salary;
44.
}
45.
46.
public Date getHireDay()
47.
{
48.
return hireDay;
49.
}
50.
51.
public void raiseSalary(double byPercent)
52.
{
53.
double raise = salary * byPercent / 100;
54.
salary += raise;
55.
}
56.
57.
private String name;
58.
private double salary;

59.
private Date hireDay;
60. }

You might also like