Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Family Tree in Java

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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!


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default 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.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default 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?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Family Income Project
    By kassim05 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 7th, 2012, 07:18 AM
  2. Family Tree App Help
    By dr85 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 4th, 2011, 03:42 PM
  3. Hello Family
    By Shyamz1 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 10th, 2010, 03:10 PM
  4. Data Structures(Binary Search Tree to AVL Tree)ASAP
    By jfAdik in forum Algorithms & Recursion
    Replies: 2
    Last Post: April 5th, 2010, 03:58 AM