Hey everyone,
I really need help in solving a problem that I have to use recursion for.
I have a list of paper objects. Each paper object has its own author(s) objects.
Each author object knows which paper(s) objects they belong to.
I have to build a scholarly neighborhood for these authors.
The user can select an author and specify the "width" of the neighborhood that they wish to view.
The width of this neighborhood goes as follows:
If they enter "0" the neighborhood will consist of only the author that they selected.
If they enter "1" the neighborhood will consist of the author that they selected plus any additional authors that are direct co-authors in the paper(s) the author wrote.
If they enter "2" the neighborhood will consist of the author, the co-authors of that author in each paper, and the co-authors of the co-authors in the paper(s) that the co-authors wrote.
Kind of like this:
Author 0
Author Co authors 1
Author Co authors authors 2
Author Co authors authors co authors 3
Author Co authors authors co authors authors 4
Make sense yet? It makes a diagram kind of like a family tree.
Here is the code I have so far:
JOptionPane.showMessageDialog(null, model.ScholarNeighborhoodList(view.getJlScholars().getSelectedIndex(), (int)view.getJspnrWidth().getValue(), scholarNeighborhood));
public String ScholarNeighborhoodList(int selectedIndex, int selectedWidth, String scholarNeighborhood) {
if (selectedWidth == 0) {
return scholarNeighborhood; // Base case
} else {
return scholarNeighborhood + ScholarNeighborhoodList(selectedIndex, selectedWidth-1, scholarNeighborhood);
}
}
Please let me know if I need to post more information.
Thank you for taking the time to read this!
:)