diff --git a/java/com/aa/act/interview/org/Employee.java b/java/com/aa/act/interview/org/Employee.java index aa9aba7..9f8e5fd 100644 --- a/java/com/aa/act/interview/org/Employee.java +++ b/java/com/aa/act/interview/org/Employee.java @@ -2,6 +2,7 @@ public class Employee { + public static int ID = 1; private int identifier; private Name name; diff --git a/java/com/aa/act/interview/org/Organization.java b/java/com/aa/act/interview/org/Organization.java index 5060509..a0dbf02 100644 --- a/java/com/aa/act/interview/org/Organization.java +++ b/java/com/aa/act/interview/org/Organization.java @@ -1,5 +1,6 @@ package com.aa.act.interview.org; +import java.util.ArrayList; import java.util.Optional; public abstract class Organization { @@ -21,9 +22,38 @@ public Organization() { */ public Optional hire(Name person, String title) { //your code here + + ArrayList thelist = new ArrayList(); + thelist.add(root); + + Position thePosition = findPosition(thelist, title); + + if (thePosition != null) { + thePosition.setEmployee(Optional.of(new Employee(Employee.ID++, person))); + return Optional.of(thePosition); + } + return Optional.empty(); } + private Position findPosition(ArrayList thelist, String title) { + Position thePosition = thelist.remove(0); + + if (thePosition.getTitle().equals(title)) { + return thePosition; + } + else { + for (Position p : thePosition.getDirectReports()) { + thelist.add(p); + } + + Position result = findPosition(thelist, title); + if (result != null) return result; + } + + return null; + } + @Override public String toString() { return printOrganization(root, "");