returning a value from recursive method: what's wrong with that?
807569Aug 2 2006 — edited Aug 2 2006acme is the name of the "factory" i had to implement.
the problem is: it runs correctly, however returning always null
what to fix?
this is the piece of code:
/**
* independent
*
* returns the department with the given name
*
* Hint for implementation: define a recursive helper method.
*/
private Department independent(String departmentName){
return(helper (m_acme,departmentName));
}
/**helper procedure for findDepartment
*
* @param rootdep
* @param departmentName
* @return the deparment with the given name
*
*/
private Department helper (Department rootdep, String departmentName) {
String s = rootdep.getName();
if (s.equals(departmentName)) {return rootdep;}
else
for (int i = 0; i < rootdep.getSubDepartments().length; i++) {
helper(rootdep.getSubDepartments(),departmentName);
}
return null;
}