//=============================================================================
// This example combines the test/user class and the service class
//=============================================================================
// The test/user class
//=============================================================================

public class EmployeeTest
{
    public static void main (String[ ] args)
    {        
        System.out.println("Company name: "     + Employee.getCompanyName() );
        System.out.println("Number employees: " + Employee.getEmployeeCount() );

        Employee e1 = new Employee("Dir","Sultan","Sam","M",48);  //instantiate
        Employee e2 = new Employee("Mgr","Smith","Mary","F",35);  //objects
        Employee e3 = new Employee("Sec","Stevens","Bob","M",28);
        Employee x  = new Employee("???","Person","Mystery","",0);

        Employee chief = new Employee("Pres");                    //instantiate object 
                
        String name1 = e1.getFullname("Mr.");                     //call instance method 
        System.out.println(name1);

        String name2 = e2.getFullname("Ms."); 
        System.out.println(name2);

        String name3 = e3.getFullname("Mr."); 
        System.out.println(name3);

        String name4 = x.getFullname("Unknown"); 
        System.out.println(name4);

        String name5 = chief.getFullname("Mr. President"); 
        System.out.println(name5);

        System.out.println("Number employees: " + Employee.getEmployeeCount() );

        String before = x.getFirstname() + " " + x.getLastname();   //call getters 

        System.out.println("\nBefore change: " + before);

        Employee.setCompanyName("ABC Inc.");                        //call static setter

        x.setPosition("Wiz");                                       //call instance setters
        x.setLastname("Potter");                                   
        x.setFirstname("Harry");
        x.setGender("M");
        x.setAge(14);

        System.out.println("After  change: " + x.getFirstname() + 
                                         " " + x.getLastname());
        System.out.println();
        
        System.out.println("Company name: "     + Employee.getCompanyName() );
        System.out.println("Number employees: " + Employee.getEmployeeCount() );

        System.out.println(e1.toString() );         //call the toString() method
        System.out.println(e2);                     //no need to say toString()
        System.out.println(e3);
        System.out.println(x + "\n" + chief);       //you can concatenate them
    }
}

//=============================================================================
// The service class
//=============================================================================
class Employee
{
    private static String companyName  = "XYZ inc.";     // class variables
    private static int    employeeCount;
    
    private String position;                             // instance variables
    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;
   }

    static String getCompanyName( )             //class method (getter)
    {
        return (companyName);
    }
    static int getEmployeeCount( )              
    {
        return (employeeCount);
    }

    String getPosition( )                       //instance method (getter)
    {
        return (position);
    }
    String getLastname( )                 
    {
        return (lastname);
    }
    String getFirstname( )                 
    {
        return (firstname);
    }
    String getGender( )                    
    {
        return (sex);
    }
    int getAge( )                          
    {
        return (age);
    }

    static void setCompanyName(String companyName)      //static method (setter)
    {
        Employee.companyName = companyName;             //"Employee" to indicate static field
    }

    void  setPosition(String position)                  //instance method (setter)
    {
        this.position = position;                       //"this" to indicate object field
    }
    void  setLastname(String lastname)         
    {
        this.lastname = lastname;
    }
    void  setFirstname(String firstname)       
    {
        this.firstname = firstname;
    }
    void  setGender(String sex)          
    {
        this.sex = sex;
    }
    void  setAge(int age)                 
    {
        this.age = age;
    }

    String getFullname (String sal)                 // instance method
    {
        String fullname  = sal + " " + firstname + " " + lastname;
        return (fullname);
    }

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