/** An instance is a worker in a certain organization */
public class Worker {

    /* Class Invariant: the collection of meaning of fields and
       constraints on them, written as comments on the field below */

    private String lname; // Last name. Never null, use "" if it's unknown
    private int ssn;      // Social security no. in range 0..999999999
    private Worker boss;  // The worker's boss --null if none
    
    /** 
     * Constructor: an instance with last name n, soc sec number s, and boss b.
     * Precondition: n is not null; use "" if unknown
     *               s is in 0..999999999
     *               b is null if this Worker has none 
     */
    public Worker(String n, int s, Worker b) {
        lname = n;
        ssn   = s;
        boss  = b;
    }

    /** Set worker�s last name to n OR 
        to "<unknown>" if n is "" or null */
    public void setName(String n) {
        //System.out.println("setName 1: "+n+","+lname);
        lname = n;
        //System.out.println("setName 2: "+n+","+lname);
        if (n == null || n == ""); {
            //System.out.println("setName 3: "+n+","+lname);
            lname = "<none>";
        }
        //System.out.println("setName 4: "+n+","+lname);
    }

    /** Yields: the last name of this worker */
    public String getName() {
        return lname;
    }
    
    /** Yields: the boss of this worker */
    public Worker getBoss() {
        return boss;
    }
    
    /** Yields:  last 4 digits of soc sec number */
    public int getSSN() {
        return ssn % 10000;
    }

    /** Set SSN to num 
     *  Precondition: num is in 0 to 999999999 */
    public void setSSN(int num) {
        assert (num > 0 && num <= 999999999) : "ssn is "+num;
        ssn = num;
    }

    
    /** Yields: text representation of this Worker */
    public String toString() {
        return "Worker " + lname +
            ". Soc sec XXX-XX-" +  getSSN() +
            (boss==null ? "" : ". boss: " + boss.lname);
    }
}