/* Tuesday am lecture - Part 3: Extended Exercise */ /* ;; A Boss is (make-boss String String Number [Listof Employee]) (define-struct boss (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]) Class Diagram: -------------- +-----------+ | 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 in 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; } } // to represent an employee with 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; } } // to represent a list of employees in a company interface ListofEmp { } // to represent an empty list of employees in a company class MTListofEmp implements ListofEmp { MTListofEmp() {} } // to represent a nonempty list of employees in a company class ConsListofEmp implements ListofEmp { Emp first; ListofEmp rest; ConsListofEmp(Emp first, ListofEmp rest){ this.first = first; this.rest = rest; } } // data examples for the company employees 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("Mike", "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.pete, new ConsListofEmp(this.wkA, 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); }