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