Welcome to Dream.In.Code
Become a Java Expert!

Join 150,384 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,152 people online right now. Registration is fast and FREE... Join Now!




how to create family tree in java

 
Reply to this topicStart new topic

how to create family tree in java

dhiraj75
18 Feb, 2008 - 05:05 AM
Post #1

New D.I.C Head
*

Joined: 18 Feb, 2008
Posts: 1

how to create database for family tree
what are the tables and what are the columns

User is offlineProfile CardPM
+Quote Post

oubless
RE: How To Create Family Tree In Java
18 Feb, 2008 - 07:23 AM
Post #2

New D.I.C Head
*

Joined: 28 May, 2007
Posts: 23


My Contributions
QUOTE(dhiraj75 @ 18 Feb, 2008 - 06:05 AM) *

how to create database for family tree
what are the tables and what are the columns

First - I'm not sure this is supposed to be in the Java section of the forum. Databases seems more likely.
Second - Post your attempts, we are not supposed to do your homework.

Just an idea from where to start if that is the problem. This is pseudocode:

You have families ( mother, father, kids ) and people
so I would guess something like

Person
name:String
birthDate:Date
sex:Sex
...

Family
mother:Person // check for sex:female!
father:Person // check for sex:male!
kids:Person[]

Note: Each person can be in only one Family as a kid and in several!!! as a mother/father
Note: This structure does not allow homosexual families and expects only 2 parents to be present ( supposed to be the birth ones )
eventual extension to Family is
adoptedChildren:Person[]

Hope this helps.

This post has been edited by oubless: 18 Feb, 2008 - 07:26 AM
User is offlineProfile CardPM
+Quote Post

alpha02
RE: How To Create Family Tree In Java
18 Feb, 2008 - 09:08 AM
Post #3

D.I.C Addict
Group Icon

Joined: 20 May, 2006
Posts: 687


Dream Kudos: 850
My Contributions
An acceptable structure could be:

CODE
Table: Persons

id: int auto_increment (the unique ID of this person)
fatherid: int (the ID of the father)
motherid: int (the ID of the mother)
name: varchar (the name of the person)
birth: int (a timestamp that indicates the birth date/time)
sex: tinyint (a boolean: 0 for male, 1 for female)


Hope this helps. This way, every person in the family has a unique ID (it is a good practice to assign a unique ID to everything stores in a database) for referrence. This is how motherid and fatherid fields identify which person is the mother/father. Any questions then just reply.

This post has been edited by alpha02: 18 Feb, 2008 - 09:11 AM
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: How To Create Family Tree In Java
19 Feb, 2008 - 10:14 PM
Post #4

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,660



Thanked: 314 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
I recommend you follow what alpha said. What he is describing is a unary relationship in which a record has a relationship with another record of the same table. This allows you to develop a recursive process in which starting from any record, you can recursively trace up the family tree through each parent.

While you are not exactly looking for oubless, the approach is similar taking the approach of a composition relationship in which a unit (family) is made up individual parts (persons). The problem with that approach is that it doesn't lend itself to recursion quite as easily. It is ideal however for describing how to build a family unit.

Both great replies but in case you were confused, you might want to go with alpha's recommendation.

smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 04:43PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month