diff --git a/java/com/aa/act/interview/org/Employee.java b/java/com/aa/act/interview/org/Employee.java index aa9aba7..6c72bba 100644 --- a/java/com/aa/act/interview/org/Employee.java +++ b/java/com/aa/act/interview/org/Employee.java @@ -4,6 +4,14 @@ public class Employee { private int identifier; private Name name; + + public Employee(){ + } + public Employee( Name name) { + if(name == null) + throw new IllegalArgumentException("name cannot be null"); + this.name = name; + } public Employee(int identifier, Name name) { if(name == null) diff --git a/java/com/aa/act/interview/org/Name.java b/java/com/aa/act/interview/org/Name.java index c9caaae..701c433 100644 --- a/java/com/aa/act/interview/org/Name.java +++ b/java/com/aa/act/interview/org/Name.java @@ -13,11 +13,16 @@ public Name(String first, String last) { this.first = first; this.last = last; } - + public void setFirst(String first) { + this.first = first; + } public String getFirst() { return first; } + public void setLast(String last) { + this.last = last; + } public String getLast() { return last; } diff --git a/java/com/aa/act/interview/org/Organization.java b/java/com/aa/act/interview/org/Organization.java index 5060509..061e41c 100644 --- a/java/com/aa/act/interview/org/Organization.java +++ b/java/com/aa/act/interview/org/Organization.java @@ -19,8 +19,28 @@ public Organization() { * @param title * @return the newly filled position or empty if no position has that title */ + public Optional findPosition(Position newPostion, String title) { + Optional newHire = Optional.of(newPosition); + if (newHire.get().getTitle().equals(title)) { + return newHire; + } else { + for (Position pos : newPosition.getDirectReports()) { + newHire = findPosition(pos, title); + if (newHire.isPresent()) { + return newHire; + } + } + } + return Optimal.empty(); + } public Optional hire(Name person, String title) { - //your code here + Optional newPosition = findPosition(root, title); + if (newPosition.isPresent()) { + Position pos = newPosition.get(); + if (!pos.isFilled()) { + newPosition.get().setEmployee(Optional.of(new Employee(person))); + } + } return Optional.empty(); } diff --git a/java/com/aa/act/interview/org/Position.java b/java/com/aa/act/interview/org/Position.java index e53e5e7..5b65590 100644 --- a/java/com/aa/act/interview/org/Position.java +++ b/java/com/aa/act/interview/org/Position.java @@ -12,6 +12,10 @@ public class Position { private Optional employee; private Set directReports; + public Position() { //default + } + + public Position(String title) { this.title = title; employee = Optional.empty();