<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">// discussed use of this

/** Maintain info about a worker */
public class W {
    private String lastName; // worker's last name (not null)
    private int ssn;         // worker's social security number
    private W boss;          // worker's boss (null if none)

    /** Constructor: worker with last name n, SSN s, boss b (null if none).
     * Precondition:  n not null,  s in 0..999999999 with
     *                no leading zeros.*/
    public W(String lastName, int ssn, W boss) {
    	// need to explicitly refer to this.lastName, because the inside-out rule says that
    	// otherwise we'd be talking about the argument lastName, not the field.
        this.lastName = lastName;
        this.ssn      = ssn;
        this.boss     = boss;
        
    }

    /** = worker's last name */
    public String getLname() {
    	// this is the same as "return lastName".  Prof. George prefers this.lastName because it is explicit;
    	// Prof. Gries prefers "lastName" because it is concise.
        return this.lastName;
    }

    /** = last 4 SSN digits */
    public String getSsn() {
        String s= "0000" + ssn;
        return s.substring(s.length() - 4);
    }

    /** = worker's boss (null if none) */
    public W getBoss() {
        return boss;
    }
    
    /** Set boss to b.  */
    public void setBoss(W b) {
        boss= b;
    }
    
    /** = this object is the boss of potentialUnderling */  
    
    public boolean isBossOf(W potentialUnderling) {
    	// this refers to object on which the method was called
    	// in example mike.isBossOf(fred), this is mike.
    	// in example fred.isBossOf(mike), this is fred. 
    	return potentialUnderling.boss == this;
    }
    
    /** application code for demonstration. */
    public static void main(String[] args) {
    	W mike = new W("George", 123456789, null);
    	W fred = new W("Schneider", 98765432, null);
    	
    	mike.setBoss(fred);
    	mike.isBossOf(fred); // return false (we hope)
    	fred.isBossOf(mike); // return true
    }
}</pre></body></html>