I have 3 methods to implement recursively. Yes this is for school so please, no plain & simple answers, i would appreciate descriptive answers so I can learn! I am new to tree structures.
the 3 methods are as follows...
public class Zombies{
public static int countPeople(Person p){...}
// counts all the people in the tree structure
// starting with Person p.
public static int countZombies(Person p){...}
// counts all the people in the tree structure
// starting with Person p that are zombies
public static void draw(Person p){...}
// draws a diagram of the people in tree structure
// starting with Person p.
// each person will be denoted by a P and
// person that is a zombie will be denoted by a Z
//
// The diagram should illustrate the family tree
// structure. Each person will be drawn with 3 minus
// signs '-' for each level below p.
I have begun my Person class and i have a few questions.
1)Am i on the right track with my person class
2)Is the tree structure mentioned in method descriptions a binary tree?
3)What am I missing to be able to implement these methods (if there is something, or are there building blocks required for this tree structure)
Below is my Person class.
public class Person{
public int id; // some identification number unique to the person
public boolean zombie; // true if the person is a zombie
public char state; // p means human, z means zombie
public ArrayList<Person> friends; // list of friends
public Person(int id, char state, boolean zombie){
this.id = id;
this.state = state;
this.zombie = zombie;
}
public boolean isZombie() {
if (state == 'p'){
return zombie=false;
}
else if (state == 'z'){
return zombie=true;
}
return zombie;
}
}
sample output of type of tree is as follows..
P (this is Person q)
---P (this is a friend of q, say q1)
------P (this is a friend of q1)
------Z (this is another friend of q1, who is a zombie)
---Z (this is a friend of q, say q2, who is a zombie)
------Z (this is a friend of q1, who is also a zombie)
------P (this is a friend of q1, who is not a zombie)
Thanks in advance for patience and help/input!
friendsat 2.