/***********************************************************************
 * Test all classes together
 **********************************************************************/
/***********************************************************************
 * Abstract Superclass Employee
 **********************************************************************/
abstract class Employee 
{
    private static String companyName  = "XYZ inc.";     //class fields
    private static int    employeeCount;
    
    private String position;                             //instance fields
    private String lastname;
    private String firstname;
    private String sex;
    private int    age;

    Employee(String title)                              //first constructor
    {
        position       = title;
        employeeCount += 1;         
    }

    Employee(String title, String last, String first, String x, int old)   
    {
        this(title);                                 //call first constructor
                                                     //and pass it title
        lastname  = last;
        firstname = first;  
        sex       = x;
        age       = old;
    }

    public String getFirstname( )        
    {
        return (firstname);
    }
    public String getLastname( )        
    {
        return (lastname);
    }
    public String getGender( )                           
    {
        return (sex);
    }
    public int getAge( )                           
    {
        return (age);
    }

    public abstract String getFullname( );                 //abstract methods, must be
    public abstract int getWeekPay( );                     //overridden in subclasses 

    public String toString ( )                             // toString method
    {
        String data = "Position: " + position + 
                      "\t Name:  " + firstname +  " " + lastname + 
                      "\t Sex: "   + sex + "\t Age: " + age;
        return (data);
    }
}

/***********************************************************************
 * Subclass Fulltimer
 **********************************************************************/
class FullTimer extends Employee                    //extends Employee superclass
{
    private static boolean healthPlan = true;       //add class fields
    
    private int salary;                             //add instance fields
    private int vacationDays;

    FullTimer(String title, String last, String first, String x, int old,
              int sal, int vac)   
    {
        super(title, last, first, x, old);           //call superclass constructor
                                                     //pass it title,last,first,sex,age
        salary       = sal;
        vacationDays = vac;  
    }

    public String getFullname( )                    //implements getFullname()
    {
        String salutation;
        String sex = getGender( );          

        if (sex.equalsIgnoreCase("M"))              //using the interface constants.
            salutation = "Mr.";                     //Now I no longer need the client
        else                                        //to pass me the salutation.
            salutation = "Ms.";

        return (salutation + " " + getFirstname()   + " " + getLastname());
    }

    public int getWeekPay( )                                //implements salary() 
    {
        return(salary / 52);
    } 

    public String toString ( )                              //override the toString()
    {
        String data = super.toString()  + "\n"   +          //call the superclass toString()
                      "Salary: "        + salary + "\t " +
                      "Vacation Days: " + vacationDays + "\n";
        return (data);
    }
}

/***********************************************************************
 * Subclass PartTimer
 **********************************************************************/
class PartTimer extends Employee                            //extends Employee superclass
{
    private static String  companyName = "Helper co.";      //override the companyName
                                                            //from the Employee class

    private static boolean healthPlan = false;              //add class fields      
    
    private int numHours;                                   //add instance fields
    private int hourlyRate;

    PartTimer(String title, String last, String first, String x, int old,
              int hours, int rate)   
    {
        super(title, last, first, x, old);           //call superclass constructor
                                                     //pass it title,last,first,sex,age
        numHours   = hours;
        hourlyRate = rate;  
    }

    public String getFullname( )                    //implements getFullname()
    {
        String salutation;
        String sex = getGender( );

        if (sex.equalsIgnoreCase("M"))              //using the interface constants.
            salutation = "Mr.";                     //Now I no longer need the client
        else                                        //to pass me the salutation.
            salutation = "Ms.";

        String fullname  = salutation + " " + getFirstname()   + " " + getLastname();
               fullname += "\t Part timer-Employee of " + companyName;
        return (fullname);
    }

    public int getWeekPay( )                                 //implements salary( )                
    {
        return (numHours * hourlyRate);
    }

    public String toString ( )                              //override the toString()
    {
        String data = super.toString()  + "\n" +            //call the superclass toString()
                      "Number Hours: " + numHours    + "\t" +
                      "Hourly Rate: "  + hourlyRate  + "\t" +
                      " Income: "      + getWeekPay() + "\n";
        return (data);
    }
}

/***********************************************************************
 * The tester class
 **********************************************************************/
public class xEmployeeTest
{
    public static void main (String[ ] args)
    {        

        Employee[ ] emp = new Employee[10];     //Create an array of Employees

        emp[0] = new FullTimer("Dir","Sultan","Sam","M",48,78000,12);      
        emp[1] = new FullTimer("Mgr","Smith","Mary","F",35,62400,12);   
        emp[2] = new FullTimer("Sec","Stevens","Bob","M",28,44200,10);

        emp[3] = new PartTimer("NE","William","Bill","M",45,30,25);  
        emp[4] = new PartTimer("NE","Johnson","Joan","F",32,25,22);  
 
        System.out.println(emp[0].getWeekPay() +"\t"+ emp[0].getFullname());                                                         
        System.out.println(emp[1].getWeekPay() +"\t"+ emp[1].getFullname());                                  
        System.out.println(emp[2].getWeekPay() +"\t"+ emp[2].getFullname());                                                         
        System.out.println(emp[3].getWeekPay() +"\t"+ emp[3].getFullname());                                      
        System.out.println(emp[4].getWeekPay() +"\t"+ emp[4].getFullname());              

        System.out.println("\n ---Better yet, Using a Loop ---");

        for (int i = 0; i < 5; i++)
            System.out.println(emp[i].getWeekPay() +"\t"+ emp[i].getFullname());  
    }
}