// CS U2510 Fall 2009 // Lab 4: October 1, 2009 /* ;; A Boss is (make-sup String String Number [Listof Employee]) (define-struct sup (name unit tasks peons)) ;; A Worker is (make-worker String Number)) (define-struct worker (name tasks)) ;; An Employee is one of ;; -- Boss ;; -- Worker ;; A [Listof Employee] is one of ;; -- empty ;; -- (cons Employee [Listof Employee]) +-----------+ | Emp |<-----------------------------+ +-----------+ | | | | +-----------+ | | | | | /_\ | | | +-----------------------------------+ | | | | +----------------+ +------------------+ | | Worker | | Boss | | +----------------+ +------------------+ | |String name | | String name | | |int tasks | | String unit | | +----------------+ | int tasks | | +--------+ ListofEmp peons | | | +------------------+ | | | v | +--------------+ | | ListofEmp |<------------------------+--+ +--------------+ | | +--------------+ | | | | | | | | /_\ | | | | | +--------------------------------+ | | v v | | +-----------------+ +-------------------+ | | | MTListofEmp | | ConsListofEmp | | | +-----------------+ +-------------------+ | | +-----------------+ | Emp first +---+ | | ListofEmp rest +------+ +-------------------+ */ // to represent an employee of a company interface Emp { } // to represent an employee with no subordinates class Worker implements Emp { String name; int tasks; Worker(String name, int tasks){ this.name = name; this.tasks = tasks; } /* TEMPLATE: FIELDS: ... this.name ... -- String ... this.tasks ... -- int METHODS: */ } // to represent an employee in charge of a unit, // with a list of all subordinates class Boss implements Emp { String name; String unit; int tasks; ListofEmp peons; Boss(String name, String unit, int tasks, ListofEmp peons){ this.name = name; this.unit = unit; this.tasks = tasks; this.peons = peons; } /* TEMPLATE: FIELDS: ... this.name ... -- String ... this.unit ... -- String ... this.tasks ... -- int ... this.peons ... -- ListofEmp METHODS: METHODS FOR FIELDS: */ } // to represent a list of all employees interface ListofEmp { } // to represent an empty list of all employees class MTListofEmp implements ListofEmp { MTListofEmp() {} } // to represent a list of all employees class ConsListofEmp implements ListofEmp { Emp first; ListofEmp rest; ConsListofEmp(Emp first, ListofEmp rest){ this.first = first; this.rest = rest; } /* TEMPLATE: FIELDS: ... this.first ... -- Emp ... this.rest ... -- ListofEmp METHODS: METHODS FOR FIELDS: */ } // examples/tests for the classes to represent a company employee hierarchy class Examples { Examples() {} Emp wkA = new Worker("A",3); Emp wkB = new Worker("B",5); Emp wkC = new Worker("C",6); Emp wkD = new Worker("D",4); Emp wkE = new Worker("E",5); Emp wkF = new Worker("F",2); Emp wkG = new Worker("G",8); Emp wkH = new Worker("H",6); ListofEmp mtlist = new MTListofEmp(); ListofEmp grpAlist = new ConsListofEmp(this.wkC,this.mtlist); Emp mike = new Boss("Mike", "Group A", 10, this.grpAlist); ListofEmp secAlist = new ConsListofEmp(this.mike, new ConsListofEmp(this.wkD, new ConsListofEmp(this.wkE,this.mtlist))); Emp jack = new Boss("Jack", "Section A", 25, this.secAlist); ListofEmp secBlist = new ConsListofEmp(this.wkF, new ConsListofEmp(this.wkG, this.mtlist)); Emp jenn = new Boss("Jenn", "Section B", 15, this.secBlist); ListofEmp secClist = new ConsListofEmp(this.wkH,this.mtlist); Emp pat = new Boss("Pat", "Section C", 20, this.secClist); ListofEmp secDlist = new ConsListofEmp(this.wkB, this.mtlist); Emp pete = new Boss("Pete", "Section D", 10, this.secDlist); ListofEmp operList = new ConsListofEmp(this.jack, new ConsListofEmp(this.jenn, new ConsListofEmp(this.pat, this.mtlist))); Emp dave = new Boss("Dave","Operations", 70, this.operList); ListofEmp financeList = new ConsListofEmp(this.wkA, new ConsListofEmp(this.pete, this.mtlist)); Emp anne = new Boss("Anne", "Finance", 20, this.financeList); ListofEmp ceoList = new ConsListofEmp(this.dave, new ConsListofEmp(this.anne,this.mtlist)); Emp meg = new Boss("Meg","CEO", 100, this.ceoList); }