Two Employee Types
The application consists of five main classes. Four of these classes are application-centric, and the fifth implements the Commons Digester construction rules. I use the Commons Digester to enable the easy creation of role-based upgrade components. (More on this later.)
I’ll describe the classes in the following sections, starting with the base class Employee.java.
The Employee class is pretty self-explanatory—with a constructor, three private data members, three setters, and a toString() method.
public class Employee { private String personName; private String socialSecurityNumber; private String employeeType; public Employee(String type) { employeeType = type; } public void setPersonName(String name) { personName = name; } public void setSocialSecurityNumber(String ssn) { socialSecurityNumber = ssn; } public void setType(String type) { employeeType = type; } public String toString() { String newline = System.getProperty("line.separator"); return employeeType + newline + "Name: " + personName + newline + "Social Security Number: " + socialSecurityNumber + newline; } }
Next up are the subclasses of Employee: ContractStaff and PermanentStaff.
public class ContractStaff extends Employee { public ContractStaff() { super("Contractor"); } } public class PermanentStaff extends Employee { public PermanentStaff() { super("Permanent"); } }
The last application-centric class is called HRStaffDetails. This class stores the details of all contractors and permanent staff.
public class HRStaffDetails { private Vector contractors; private Vector permanentFolks; public HRStaffDetails() { contractors = new Vector(); permanentFolks = new Vector(); } public void addPermanentStaff(PermanentStaff person) { permanentFolks.addElement(person); } public void addContractor(ContractStaff person) { contractors.addElement(person); } public String toString() { String newline = System.getProperty("line.separator"); StringBuffer buf = new StringBuffer(); buf.append(newline); for(int i = 0; i < permanentFolks.size(); i++) buf.append(permanentFolks.elementAt(i)).append(newline); buf.append(newline); for(int i = 0; i < contractors.size(); i++) { buf.append(contractors.elementAt(i)).append(newline); } return buf.toString(); } }
That’s the basic code. How do I now build the application?