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

 

 

However, you work for a company that gives raises to its managers differently from raises to its regular employees. (Don't they all?)  Furthermore, managers have access to a secretary and other perks.

As the programmer for this company's salary application, you naturally decide to use inheritance to model these differences. So you create a class Manager (a subclass of Employee -- appropriate?):

package company;

import java.util.Date;

public class Manager extends Employee
{
    public Manager(String n, double s, Date d,
                   String secretaryName)
    {
        super(n, s, d);
        m_secretaryName = secretaryName;
    }

    public void raiseSalary(double byPercent)
    {
        // Add 1/2% bonus for every year of service
        Date today = new Date();
        double bonus =
                0.5 * (today.getYear() + 1900 - getHireYear());
        super.raiseSalary(byPercent + bonus);
    }

    public String getSecretaryName()
    {
        return m_secretaryName;
    }

    public void setSecretaryName(String name)
    {
        m_secretaryName = name;
    }

    //////////// Data //////////////////
    private String	m_secretaryName;
}

Note that the Manager class overrides the raiseSalary(double byPercent) method, which recalculates the percentage raise and then calls its superclass's (that is, the Employee class's) raiseSalary method to complete the setting of the raise

The Manager class also adds two secretary-related methods.

 

This page was last modified on 02 October, 2007