-
Family Tree in Java
Hi guys!
I have to implement a family tree in Java. I have an input file with family relations that sounds like this :
John child Ben (-> John is the child of Ben ; Ben is the parent of John)
Ben (-> if the line contains only one string that means the person is the Root )
Tim brother Mary (-> Tim is the brother of Mary; Mary has Tim as a brother)
Sarah cousin Marshall (-> Sarah is the cousin of Marshall ; Marshall is a cousin of Sarah )
Marshall brother Sophie (-> Marshall is a brother of Sophie ; Sophie is a "sister " of Marshall )
Mary parent Sarah (->Mary is the parent of Sarah; Sarah is a child of Mary)
Sophie child Tim (->Sophie is a child of Tim;Tim is Sarah's parent)
John brother Mary (->John is a brother of Mary;Mary is a "sister" of John)
Note that I have an abstract class called Person with details of name, array of children,array of uncles,array of cousins and so on.
The fact is that there is only one ROOT; anybody has only one parent; the SEX doesn't matter.
I have to implement the following classes : Brother;Cousin;Uncle;Nephew;Parent;Child that extend the abstract class Person
A child is also a PERSON;
A parent can be someone's CHILD;
A brother is also a CHILD;
An uncle is someone's BROTHER;
A nephew is also a CHILD;
A cousing is also a NEPHEW;
Please give me some ideas.I would appreciate very much!
-
Re: Family Tree in Java
What's your question? Where are you stuck? What have you tried?
This is a slightly strange example to teach Java with. This kind of stuff is what prolog is designed for.
--- Update ---
Also, please don't post multiple copies of the same question. I've deleted your duplicate post.
-
Re: Family Tree in Java
I am trying to save the input information in a <Person> ArrayList and I don't know if this is a right solution.
-
Re: Family Tree in Java
It might be fine. Another option might be to create your own tree structure, which seems like the point of this assignment. What happened when you tried?