Need help with Java - recursion
Posted: Wed Sep 26, 2018 10:00 am
Decided I'd post this here for fun (and perhaps even a helpful answer), as I know obviously that the devs are experienced in programming, and perhaps others here are too. If you are bored and/or have some free time, feel free to contribute and help me out! I'm a first year computer engineering student and having trouble with a Java method to do with recursion in one of my assignments, here is the problem:
So I have a tree structure here of an organization hierarchy - each node/employee object contains a field with the Set of the nodes/employees under him. So for example, AA has a set which in it has AS, BV, CW and DM. And BV has a set which contains BK and BL. Also, each employee has a field with their x, y coordinates.
The program has a recursive method which, when the user releases the mouse on one of the employees, it traverses the tree (starting from AA the CEO), until it find the employee with the x, y coordinates of where the mouse was released.
Here is the method: the parameters x, y are where the mouse has been released, and empl is the CEO (the root of the tree).
The problem is that the method doesn't return an employee (it returns 'null'), the only time it returns an employee is if the mouse has been released on the CEO/root of the tree. But if I release the mouse on any other employee, it returns 'null'.
I've tried to find the problem for about an hour to no avail. I think it might be something small, but so far it has eluded me.
So feel free to help me, if you have the inclination. If you solve my problem and you're on destro, I will give you a free +23 strength/WS/toughness or initiative tally of your choice. If you're on order, your reward will be for me not to kill you if I see you in-game.
*reward limited to the first person who solves it
So I have a tree structure here of an organization hierarchy - each node/employee object contains a field with the Set of the nodes/employees under him. So for example, AA has a set which in it has AS, BV, CW and DM. And BV has a set which contains BK and BL. Also, each employee has a field with their x, y coordinates.
The program has a recursive method which, when the user releases the mouse on one of the employees, it traverses the tree (starting from AA the CEO), until it find the employee with the x, y coordinates of where the mouse was released.
Here is the method: the parameters x, y are where the mouse has been released, and empl is the CEO (the root of the tree).
The problem is that the method doesn't return an employee (it returns 'null'), the only time it returns an employee is if the mouse has been released on the CEO/root of the tree. But if I release the mouse on any other employee, it returns 'null'.
I've tried to find the problem for about an hour to no avail. I think it might be something small, but so far it has eluded me.
So feel free to help me, if you have the inclination. If you solve my problem and you're on destro, I will give you a free +23 strength/WS/toughness or initiative tally of your choice. If you're on order, your reward will be for me not to kill you if I see you in-game.
*reward limited to the first person who solves it