/**************************************************************************
 * The Employee class
 * Added 3rd constructor (a copy constructor) 
 * Added a clone() method 
 *************************************************************************/
public class Employee
{
    private static String companyName  = "XYZ inc.";     // static fields
    private static int    employeeCount;
    
    private String position  = "";                       // instance fields
    private String lastname  = "";
    private String firstname = "";
    private String sex       = "";
    private int    age;

//-- The constructors ---------------------------------------------------------------

    Employee(String title)                                                 //1st constructor   
    {                                                 
        this.position = title;
        employeeCount++;
    }

    Employee(String title, String last, String first, String x, int old)   //2nd constructor   
    {                                                 
        this(title);                            					//call the 1st constructor

        this.lastname  = last;
        this.firstname = first;  
        this.sex       = x;
        this.age       = old;
    }

    Employee(Employee e)                                					//3rd constructor (copy constructor)    
    {
        this(e.position, e.lastname, e.firstname, e.sex, e.age);    //Call the 2nd constructor

//or	this.position  = e.position;
//      this.lastname  = e.lastname;
//      this.firstname = e.firstname;
//      this.sex       = e.sex;
//      this.age       = e.age;
    }


//-- A clone method ------------------------------------------------------------------

    public Employee clone()                     //Another way to clone an Employee
    {
        String pos   = this.position;           //copy the fields of this object  
        String last  = this.lastname  ;         //to local variables
        String first = this.firstname;           
        String sex   = this.sex;                 
        int age      = this.age;
        
        Employee e2 = new Employee(pos, last, first, sex, age);

//or    Employee e2 = new Employee(this.position, this.lastname, this.firstname, this.sex, this.age);

//or    Employee e2 = new Employee(this);       //will call the copy constructor 

        return(e2);
    }

    public void setPosition(String position)
    {
        this.position = position;
    }

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