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
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/jpa-buddy.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions coding-evaluation.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/java" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
4 changes: 2 additions & 2 deletions java/com/aa/act/interview/org/Employee.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ public Employee(int identifier, Name name) {
this.identifier = identifier;
this.name = name;
}

public int getIdentifier() {
return identifier;
}

public Name getName() {
return name;
}
Expand Down
4 changes: 2 additions & 2 deletions java/com/aa/act/interview/org/MyOrganization.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.aa.act.interview.org;

public class MyOrganization extends Organization {

@Override
protected Position createOrganization() {
Position ceo = new Position("CEO");
Expand All @@ -27,7 +26,7 @@ protected Position createOrganization() {
vpt.addDirectReport(dct);
Position s = new Position("Salesperson");
vps.addDirectReport(s);

return ceo;
}

Expand All @@ -44,6 +43,7 @@ public static final void main(String... args) {
myOrg.hire(new Name("Head", "Geek"), "VP Technology");
myOrg.hire(new Name("Steve", "Dent"), "VP Infrastructure");
myOrg.hire(new Name("Slick", "Willie"), "Salesperson");
//System.out.println(myOrg);
System.out.println(myOrg);
}
}
6 changes: 3 additions & 3 deletions java/com/aa/act/interview/org/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class Name {

private String first;
private String last;

public Name(String first, String last) {
if(first == null)
throw new IllegalArgumentException("first name cannot be null");
Expand All @@ -13,11 +13,11 @@ public Name(String first, String last) {
this.first = first;
this.last = last;
}

public String getFirst() {
return first;
}

public String getLast() {
return last;
}
Expand Down
34 changes: 26 additions & 8 deletions java/com/aa/act/interview/org/Organization.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,52 @@
package com.aa.act.interview.org;

import java.util.LinkedList;
import java.util.Optional;
import java.util.Queue;
import java.util.concurrent.atomic.AtomicInteger;

public abstract class Organization {

private Position root;

private AtomicInteger employeeCounter;

public Organization() {
root = createOrganization();
employeeCounter = new AtomicInteger(0);
}

protected abstract Position createOrganization();

/**
* hire the given person as an employee in the position that has that title
*
*
* @param person
* @param title
* @return the newly filled position or empty if no position has that title
*/
public Optional<Position> hire(Name person, String title) {
//your code here
return Optional.empty();
public Optional<Position> hire(Name person, String title) {
Queue<Position> queue = new LinkedList<>();
queue.add(root);

while (!queue.isEmpty()) {
Position position = queue.poll();

if (position.getTitle().equals(title) && !position.isFilled()) {
Employee newEmployee = new Employee(employeeCounter.incrementAndGet(), person);
position.setEmployee(Optional.of(newEmployee));
return Optional.of(position);
}
queue.addAll(position.getDirectReports());
}

return Optional.empty();
}

@Override
public String toString() {
return printOrganization(root, "");
}

private String printOrganization(Position pos, String prefix) {
StringBuffer sb = new StringBuffer(prefix + "+-" + pos.toString() + "\n");
for(Position p : pos.getDirectReports()) {
Expand Down