Test Program
Home ] Up ] Secretary ] ExecutiveSecretary ] Manager ] Executive ] Programmer ] [ Test Program ]

 

 

Now, here's a test program to use the new features:

package company;

import java.util.Date;

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

        staff[0] = new Employee("Charlie Chaplin", 34000,
                                new Date(78, 7, 9));
        staff[1] = new Secretary("Demi Moore", 17000,
                                new Date(95, 8, 16), 15);
        staff[2] = new ExecutiveSecretary("Florence Nightingale",
                                50000, new Date(71, 4, 23), 150);
        staff[3] = new Manager("Mother Theresa", 0,
                                new Date(89, 3, 5), 
                                (Secretary)staff[1]);
        staff[4] = new Executive("Bill Gates", 42000000, 
                                new Date(90, 1, 1),
                                (ExecutiveSecretary)staff[2]);
        String[] languages = {"Java", "C++", "C" };
        staff[5] = new Programmer("Bryan Higgs", 250000,
                                new Date(76, 4, 12),
                                languages);

        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();

        Secretary sec = ((Manager)staff[3]).getSecretary();
        System.out.println(staff[3].getName() + "'s secretary: " 
                            + sec.getName());
        sec = ((Executive)staff[4]).getSecretary();
        System.out.println(staff[4].getName() + "'s secretary: "
                            + sec.getName());
        Programmer prog = (Programmer)staff[5];                    
        System.out.println(prog.getName()
                            + " knows the following languages:");
        String[] langs = prog.getLanguages();
        for (int lang = 0; lang < langs.length; lang++)
        {
            if (lang != 0)
                System.out.print(",");
            System.out.print(langs[lang]);
        }
        System.out.println();
    }
}

It produces the following output:

Charlie Chaplin 35700.0 1978
Demi Moore 17850.0 1995
Florence Nightingale 52500.0 1971
Mother Theresa 0.0 1989
Bill Gates 5.565E7 1990
Bryan Higgs 262500.0 1976
Mother Theresa's secretary: Demi Moore
Bill Gates's secretary: Florence Nightingale
Bryan Higgs knows the following languages:
Java,C++,C


This page was last modified on 02 October, 2007