public class VP extends Manager {
public String toString() {
return "I am " + getName() + ", VP";
* VP doubles the estimated amount.
public int estimateProject(String projectDescription) {
System.out.println("I am " + getName() + ", the VP, and calling for an estimate...");
final int projectEstimate = super.estimateProject(projectDescription);
System.out.println("Original estimate: " + projectEstimate);
return Math.toIntExact(Math.round(projectEstimate * 2));
public class TeamLeader extends Manager {
public TeamLeader(String name) {
public String toString() {
return "I am " + getName() + ", Team Leader";
public abstract class Manager implements Employee {
List<Employee> employees = new ArrayList<>();
public Manager(String name) {
public List<Employee> getEmployees() {
public void add(Employee e) {
public void remove(Employee e) {
this.employees.remove(e);
public int estimateProject(String projectDescription) {
if (this.employees.isEmpty()) {
return Math.round(this.employees.stream().mapToInt(e -> {
return e.estimateProject(projectDescription);
}).sum() / this.employees.size());
public String getName() {
public class Developer implements Employee {
public Developer(String name) {
public String getName() {
public void add(Employee e) {
public void remove(Employee e) {
public List<Employee> getEmployees() {
public int estimateProject(String projectDescription) {
return new Random().nextInt(24);
public String toString() {
return "I am " + getName() + ", Developer";
public static void main(String... args) {
final Developer d1 = new Developer("Jack");
final Developer d2 = new Developer("Jill");
final Developer d3 = new Developer("Brian");
final Developer d4 = new Developer("Bob");
final Manager m1 = new TeamLeader("Marc");
final Manager m2 = new TeamLeader("Christian");
final Manager m3 = new TeamLeader("Phil");
final VP vp = new VP("Joseph");
System.out.println("Our estimate is: " + vp.estimateProject("New exotic feature"));
public class VP extends Manager {
public VP(String name) {
super(name);
}
@Override
public String toString() {
return "I am " + getName() + ", VP";
}
/**
* VP doubles the estimated amount.
*/
@Override
public int estimateProject(String projectDescription) {
System.out.println("I am " + getName() + ", the VP, and calling for an estimate...");
final int projectEstimate = super.estimateProject(projectDescription);
System.out.println("Original estimate: " + projectEstimate);
return Math.toIntExact(Math.round(projectEstimate * 2));
}
}
public class TeamLeader extends Manager {
public TeamLeader(String name) {
super(name);
}
@Override
public String toString() {
return "I am " + getName() + ", Team Leader";
}
}
public abstract class Manager implements Employee {
List<Employee> employees = new ArrayList<>();
String name;
public Manager(String name) {
this.name = name;
}
@Override
public List<Employee> getEmployees() {
return this.employees;
}
@Override
public void add(Employee e) {
if (e != null) {
this.employees.add(e);
}
}
@Override
public void remove(Employee e) {
if (e != null) {
this.employees.remove(e);
}
}
@Override
public int estimateProject(String projectDescription) {
if (this.employees.isEmpty()) {
return 0;
}
return Math.round(this.employees.stream().mapToInt(e -> {
System.out.println(e);
return e.estimateProject(projectDescription);
}).sum() / this.employees.size());
}
@Override
public String getName() {
return this.name;
}
}
public class Developer implements Employee {
String name;
public Developer(String name) {
this.name = name;
}
@Override
public String getName() {
return this.name;
}
@Override
public void add(Employee e) {
}
@Override
public void remove(Employee e) {
}
@Override
public List<Employee> getEmployees() {
return null;
}
@Override
public int estimateProject(String projectDescription) {
return new Random().nextInt(24);
}
@Override
public String toString() {
return "I am " + getName() + ", Developer";
}
}
public static void main(String... args) {
final Developer d1 = new Developer("Jack");
final Developer d2 = new Developer("Jill");
final Developer d3 = new Developer("Brian");
final Developer d4 = new Developer("Bob");
final Manager m1 = new TeamLeader("Marc");
final Manager m2 = new TeamLeader("Christian");
final Manager m3 = new TeamLeader("Phil");
m1.add(d3);
m1.add(d2);
m2.add(d1);
m3.add(d4);
final VP vp = new VP("Joseph");
vp.add(m1);
vp.add(m2);
System.out.println("Our estimate is: " + vp.estimateProject("New exotic feature"));
}