Everybody Raise
Home ] Up ] Employee Class ] Employee Raise ] Manager Class ] [ Everybody Raise ]

 

 

Now you can give all Employees (including Managers) a raise:

package company;

import java.util.Date;

public class ManagerTest
{
    public static void main(String[] args)
    {
        Employee[] staff = new Employee[3];

        staff[0] = new Employee("Charlie Chaplin",
                                34000,
                                new Date(78, 7, 9));
        staff[1] = new Employee("Florence Nightingale",
                                100,
                                new Date(71, 4, 23));
        staff[2] = new Manager("Mother Theresa",
                                120000,
                                new Date(89, 3, 5),
                                "Demi Moore" // Secretary name
                                );

        for (int i = 0; i < staff.length; i++)
            staff[i].raiseSalary(5);     // by 5 percent

        for (int i = 0; i < staff.length; i++)
            staff[i].print();
    }
}

Note that we can write:

staff[2] = new Manager("Mother Theresa",
                       120000,
                       new Date(89, 3, 5),
                       "Demi Moore" // Secretary name
                       );

even though staff[2] is of type Employee, because we declared the class Manager as extending from Employee -- that is, a Manager is a kind of Employee.

Question Would the following be legal/valid?
Manager bill = new Employee("Bill Gates",
                            20000000.00,
                            new Date(85, 1, 1));

When the above program is run, it produces the following output:

Charlie Chaplin 35700.0 1978
Florence Nightingale 105.0 1971
Mother Theresa 133800.0 1989
 

This page was last modified on 02 October, 2007