/****************************************************************************
 * Test all interfaces and classes together
 ***************************************************************************/
/****************************************************************************
 * Interface APerson
 ***************************************************************************/
interface APerson
{
    String MALE   = "M";                //implies public static final
    String FEMALE = "F";                //no need to specify

    String getFullname( );              //implies public abstract              
    String getGender( );                //no need to specify
    int    getAge( );
    
    static String toLive( )             //static method with code 
    {
        return("Must breath air");
    }
    default String earnMoney( )         //default method with code 
    {
        return("Must work");
    }
}

/****************************************************************************
 * Abstract Superclass Employee - Implements APerson
 ***************************************************************************/
abstract class Employee implements APerson
{
    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( )                  //implements getGender()        
    {
        return (sex);
    }
    public int getAge( )                        //implements getSex()        
    {
        return (age);
    }

    public abstract int getWeekPay( );          //abstract method, must be
                                                //implemented in subclasses 

    public String toString ( )                  //toString method
    {
        String data = "Position: "   + position + 
                      "\t Name: "    + firstname +  " " + lastname   +  
                      "\t Sex: "     + sex + "\t Age: " + age + 
                      "\t To Live: " + APerson.toLive() +
                      "   Earn$: "   + earnMoney(); 
        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(MALE))         //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 getWeekPay() 
    {
        return(salary / 52);
    } 

    public String toString ( )                              //override the toString()
    {
        String data = super.toString()  + "\n"   +          //call the superclass toString()
                      "Salary: "        + salary + "\t " +
                      "Vacation Days: " + vacationDays;
        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(MALE))         //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 getWeekPay( )                
    {
        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();
        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","Williams","Bill","M",45,30,25);  
        emp[4] = new PartTimer("NE","Johnson","Joan","F",32,25,22);  
 

        System.out.println("---Printing using a Loop --- \n");

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