Building the Employee Tree in Java

Creation PDF 417 in Java Building the Employee Tree
Building the Employee Tree
Creating PDF-417 2d Barcode In Java
Using Barcode maker for Java Control to generate, create PDF-417 2d barcode image in Java applications.
We start by creating a CEO Employee and then add that employee's subordinates and their subordinates as follows:
Encoding Barcode In Java
Using Barcode encoder for Java Control to generate, create barcode image in Java applications.
private void makeEmployees() {
Bar Code Recognizer In Java
Using Barcode reader for Java Control to read, scan read, scan image in Java applications.
91 Team-Fly
Encode PDF 417 In Visual C#
Using Barcode creation for Visual Studio .NET Control to generate, create PDF-417 2d barcode image in VS .NET applications.
AM FL Y
Painting PDF 417 In Visual Studio .NET
Using Barcode creator for ASP.NET Control to generate, create PDF-417 2d barcode image in ASP.NET applications.
prez = new Boss("CEO", 200000); prezadd(marketVP = new Boss("Marketing VP", 100000)); prezadd(prodVP = new Boss("Production VP", 100000)); marketVPadd(salesMgr = new Boss("Sales Mgr", 50000)); marketVPadd(advMgr = new Boss("Advt Mgr", 50000)); //add salesmen reporting to sales manager for (int i = 0; i < 5; i++) salesMgr add(new Employee("Sales " + i, rand_sal(30000))); advMgradd(new Employee("Secy", 20000)); prodVPadd(prodMgr = new Box("Prod Mgr", 40000)); prodVPadd(shipMgr = new Boss("Ship Mgr", 35000)); //add manufacturing staff for (int i = 0; i < 4; i++) prodMgradd(new Employee("Manuf " + i, rand_sal(25000))); //add shipping clerks for (int i = 0; i < 3; i++) shipMgradd(new Employee("ShipClrk " + i, rand_sal(20000))); }
PDF 417 Creator In VS .NET
Using Barcode maker for .NET Control to generate, create PDF417 image in Visual Studio .NET applications.
Once we have constructed this Composite structure, we can load a visual JTree list by starting at the top node and calling the addNode method recursively until all of the leaves in each node are accessed
Draw PDF417 In Visual Basic .NET
Using Barcode generation for VS .NET Control to generate, create PDF 417 image in Visual Studio .NET applications.
private void addNodes(DefaultMutableTreeNode pnode, Employee emp) { DefaultMutableTreeNode node; Enumeration e = empsubordinates(); if (e != null) { while (ehasMoreElements()) { Employee newEmp = (Employee)enextElement(); node = new DefaultMutableTreeNode(newEmpgetName()); pnodeadd(node); addNodes(node, newEmp); } } }
Print Bar Code In Java
Using Barcode maker for Java Control to generate, create barcode image in Java applications.
The final program display is shown in Figure 113 Figure 113 The corporate organization shown in a TreeList control
Code 128 Code Set C Generator In Java
Using Barcode generation for Java Control to generate, create Code 128 image in Java applications.
In this implementation, the cost (sum of salaries) is shown in the bottom bar for any employee you click on This simple computation calls the getChild method recursively to obtain all of the subordinates of that employee
Paint Code 3 Of 9 In Java
Using Barcode drawer for Java Control to generate, create Code 3/9 image in Java applications.
public void valueChanged(TreeSelectionEvent evt) { TreePath path = evtgetPath(); String selectedTerm = pathgetLastPathComponent()toString(); Employee emp = prezgetChild(selectedTerm); if (emp != null) costsetText(new Float(empgetSalaries())toString()); }
Data Matrix Printer In Java
Using Barcode printer for Java Control to generate, create DataMatrix image in Java applications.
Self-Promotion
Barcode Creation In Java
Using Barcode creation for Java Control to generate, create bar code image in Java applications.
Sometimes, an Employee will stay in a current job but acquire new subordinates For example, a Salesman might be asked to supervise sales trainees For such a case, we can conveniently provide a Boss constructor that creates a Boss from an Employee
MSI Plessey Maker In Java
Using Barcode generation for Java Control to generate, create MSI Plessey image in Java applications.
public Boss(Employee emp) { //promotes an employee position to a Boss //and thus allows it to have employees super(empgetName(), empgetSalary()); employees = new Vector(); leaf = false; }
Create UPC-A In .NET Framework
Using Barcode creation for ASP.NET Control to generate, create GS1 - 12 image in ASP.NET applications.
The problem of replacing the Employee instance with the Boss instance means replacing a Vector element with a new one using the setElementAt method
Paint Barcode In VS .NET
Using Barcode generation for .NET Control to generate, create bar code image in Visual Studio .NET applications.
Doubly Linked List
Bar Code Encoder In .NET Framework
Using Barcode maker for ASP.NET Control to generate, create bar code image in ASP.NET applications.
In the previous implementation, we keep a reference to each subordinate in the Vector in each Boss class This means that you can move down the chain from the CEO to any employee, but that there is no way to move back up to identify an employee's supervisor This is easily remedied by providing a constructor for each AbstractEmployee subclass that includes a reference to the parent node
Encode Bar Code In .NET Framework
Using Barcode printer for ASP.NET Control to generate, create bar code image in ASP.NET applications.
public Employee(Employee _parent, String _name, float _salary) { name = _name; salary = _salary; parent = _parent; //save parent node leaf = true; }
USS Code 39 Generator In VS .NET
Using Barcode maker for ASP.NET Control to generate, create Code 39 Full ASCII image in ASP.NET applications.
Then you can quickly walk up the tree to produce a reporting chain
Drawing EAN / UCC - 14 In Visual Studio .NET
Using Barcode encoder for VS .NET Control to generate, create EAN / UCC - 14 image in Visual Studio .NET applications.
listadd (empgetName()); //employee name while(empgetParent() != null) { emp = empgetParent(); //get boss listadd (empgetName()); }
Code 128C Generation In .NET Framework
Using Barcode encoder for ASP.NET Control to generate, create Code 128 Code Set C image in ASP.NET applications.
This is shown in Figure 114 Figure 114 The tree list display of the composite, with a display of the parent nodes on the right
Consequences of the Composite Pattern
The Composite pattern allows you to define a class of hierarchy of simple objects and morecomplex composite objects so that they appear to be the same to the client program Because of this simplicity, the client can be that much simpler, since nodes and leaves are handled in the same way The Composite pattern also makes it easy for you to add new kinds of components to your collection, as long as they support a similar programming interface On the other hand, this has the disadvantage of making your system overly general You might find it harder to restrict certain classes, where this would normally be desirable