;; A Boss is (make-boss String String Number list-of-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 list-of-Employee is one of ;; -- empty ;; -- (cons Employee list-of-Employee)Here's a class diagram that represents the same information:
+-----------+
| 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 +------+
+-------------------+
And finally, here is an example of data (in ProfessorJ) representing the hierarchy of
employees at a certain company:
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);
}
countAll() that will count all people
supervised by this employee. Include self in the count.
Design the method allUnit() that produces a list of all subordinates of this worker employee. Include self in the list. (Hint: how would you solve
this problem if you were programming your solution in DrScheme?)
isBoss() that consumes a name and determines whether this employee or one of its subordinates is a boss with the given name.
Design the method rank() that determines the rank of this employee.
sortByRank() that uses this list of
employees to produce a list of employees sorted by rank. Ties may
be listed in any order. (Hint: remember how we did sorting in DrScheme?)
Using web-based turnin, turn in a single file containing all code and documentation for this assignment. Follow the naming conventions when naming your file. Both partners' names and wpi login names should appear in a comment at the top of the file.