1 25 26 package org.objectweb.speedo.tutorial.pobjects.additional.inheritance; 27 28 import java.util.ArrayList ; 29 import java.util.Collection ; 30 import java.util.Iterator ; 31 32 35 public class Worker extends Employee { 36 37 private boolean partTime; 38 private Collection managers; 39 40 public Worker(String name, int age, String company, boolean partTime) { 41 super(name, age, company, "worker"); 42 this.partTime = partTime; 43 this.managers = new ArrayList (); 44 } 45 46 public boolean isPartTime() { 47 return partTime; 48 } 49 50 public void setPartTime(boolean partTime) { 51 this.partTime = partTime; 52 } 53 54 public Collection getManagers() { 55 return managers; 56 } 57 public void setManagers(Collection managers) { 58 this.managers = managers; 59 } 60 public void addManager(Manager manager){ 61 managers.add(manager); 62 manager.addWorker(this); 63 } 64 65 public String toString(){ 66 String s = "Worker: Employee(" + super.toString() + "), " + (partTime?"part-time":"full time"); 67 if(managers.size() > 0){ 68 s += ", list of managers["; 69 Iterator it = managers.iterator(); 70 while(it.hasNext()){ 71 Manager manager = (Manager) it.next(); 72 s += manager.getName() + ", "; 73 } 74 s = s.substring(0, s.length()-2); 75 s += "]"; 76 } 77 return s; 78 } 79 } 80 | Popular Tags |