Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions java/com/aa/act/interview/org/Employee.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public class Employee {

public static int ID = 1;
private int identifier;
private Name name;

Expand Down
30 changes: 30 additions & 0 deletions java/com/aa/act/interview/org/Organization.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.aa.act.interview.org;

import java.util.ArrayList;
import java.util.Optional;

public abstract class Organization {
Expand All @@ -21,9 +22,38 @@ public Organization() {
*/
public Optional<Position> hire(Name person, String title) {
//your code here

ArrayList<Position> 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<Position> 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, "");
Expand Down