• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

How to Program a Family Tree

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, so I'm not good at programming and I'm only in a programming class because it's required for my major. At any rate, I have to write a program that will input and display a person's family tree. The professor left it broad on purpose as he wants to see what we come up with. Problem is, like I said, I'm no good at programming. Can anyone help? I graduate on Saturday and this is the last assignment I have to turn in (by Saturday) in order to graduate. I'm using BlueJ.
 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What sort of help do you need? What have you done so far to solve the assignment? Show us what you've got. We'll help you further on!
 
Amber Hisaw
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Honestly I haven't gotten anything. I'm at a loss. I've been trying to figure out where to start but I'm just blank
 
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Amber,

Welcome to CodeRanch!

Further to what Joe has mentioned, can you elaborate exactly where you are stuck?

Are you aware of tree data structure? Can you build a binary tree based on few numbers?

Also, for family tree, how the inputs would be taken? How the relations would be formed?

First, try to form a normal algorithm on paper before jumping to coding.
 
Marshal
Posts: 79938
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome again

I suggest you start with a simple family tree, and draw it on paper. Write down what the relationships between the different parts are. This Wikipedia Article might help, though you may prefer a smaller tree than Confucius'. I also doubt the bit about not being your own ancestor
 
Campbell Ritchie
Marshal
Posts: 79938
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have changed the title of this thread so it tells people what it is about.
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What have you done so far?
 
Amber Hisaw
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I haven't done anything yet. I'm not sure where to start.
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Amber Hisaw wrote:I haven't done anything yet. I'm not sure where to start.



Well, obviously, since this is your final project for the class, this isn't your first program in the class. You should start the same way as all your previous projects. You can start by envisioning what the data to look like, that can represent the family tree. And possible algorithms that you may need.

Henry

 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My recommendation: get started, and start small.

I would start by defining a Person object.
That person object should have a (as a minimum) a Name and a Date of Birth.

Have a method along the lines of
public Person inputPersonFromKeyboard();
Which will prompt the user to enter in the fields you want to capture, and create the appropriate object.
Once you have that, then you can start building up an array/list of people.

Then start worrying about how to define relationships.
Presumably you would want at the least a way to represent marriage and children.

Start small. Get one thing working.
Then build on that.


 
Amber Hisaw
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the advice. Actually, this is my first program for this class. It wasn't focused on programs, it was focused on concepts, and completely online so I haven't really caught on like I'd like.
 
Campbell Ritchie
Marshal
Posts: 79938
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stefan Evans wrote: . . . a way to represent marriage and children. . . .

For the purposes of this exercise keep it simple: Assume everybody gets married one man to one woman before they have children and nobody gets divorced and nobody has children on the “wrong side of the blanket,” as the heraldic people say.

In which case you might do well to add spouse and sex fields to the Person classYou can call Sex Gender instead if you prefer.
 
Amber Hisaw
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, so this is what I have so far. It compiles just fine and I can run it, but I cannot get past the second prompt that asks for "left/right parent child." Any suggestions? I'm not really sure where the error is...

 
Campbell Ritchie
Marshal
Posts: 79938
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you are going about it the wrong way, I am afraid.
Don't start by displaying it with a GUI. Start by creating the tree. Have you got classes representing people, or couples, or parents and children? Remember that to have children you need somebody to be mother and somebody to be father and you can have (within reason) any number of children.
 
Amber Hisaw
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was still unable to figure out the problem. But it was nearing the deadline so I ha do turn it in. I got a 90/100. Thank god I'm done. Thanks for all your advice!
 
Saloon Keeper
Posts: 15725
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Congratulations Amber!
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stefan Evans wrote:My recommendation: get started, and start small.

I would start by defining a Person object.
That person object should have a (as a minimum) a Name and a Date of Birth.

Have a method along the lines of
public Person inputPersonFromKeyboard();
Which will prompt the user to enter in the fields you want to capture, and create the appropriate object.
Once you have that, then you can start building up an array/list of people.

Then start worrying about how to define relationships.
Presumably you would want at the least a way to represent marriage and children.

Start small. Get one thing working.
Then build on that.




Hi, I have this same assignment and am in the same boat as Amber (not being great at Java, its been about a year since the last programming class). I took the advice of starting out small with a simple person class. I am not sure where to go from here. Here is my simple code.

 
Sheriff
Posts: 17678
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Programming is as much about organization and allocating responsibilities as it is about solving a problem. Think about this: you, as a person, have many body parts. Each part is designed to do something. Ears are for hearing, eyes for seeing, etc. What would it be like if you had to listen with your feet or see with your tongue? That wouldn't be right, would it? But why wouldn't it be right? Because the foot is not the best place to put a receptor for sound nor is the tongue the best place to put your ”sensors" for light.

Likewise, some of the code you have there is not properly appropriated to a method whose responsibility is ostensibly, to add a Person to a FamilyTree.

First, which of the following makes more sense?

”Hey, FamilyTree, add this Person." ( pointing at a pile of Strings )

Versus

"Hey, FamilyTree, add this Person." ( pointing at a Person )

The latter makes more sense, right? So why write line 3 like the former rather than the latter?

Second, if you decided to prompt the user differently when asking for the name of a Person, say in French or Italian instead of English, for example, does it make sense that you would have to go and change a method called addPerson? By analogy, does it make sense for you to go to an optician to get new glasses and expect him to examine your feet? No, right?

Let me put it in yet another way. Is it reasonable to expect your mouth to do everything that your digestive system as a whole is responsible for doing? No, right? The mouth is only responsible for the initial intake of food. It will then pass on what it did to the stomach for further processing, which then passes what it did to the small intestine and so on and so forth. Each organ in the chain has its own specific responsibility and contribution in the processing of food and drink to provide energy for the body.

Likewise, while prompting for user input may be part of the entire process of adding a Person to a FamilyTree, it is only one of many tasks that need to be performed. Prompting for user input is still just the initial "intake" of information and it's a different task/responsibility from actually adding a Person to the tree.

As you can see, even with so little code, there's already quite a bit of reorganization you need to do. At least now you're aware of the kind of things you need to start thinking about to organize your program better.

Aside: if you think about it, the human body, or any living thing really, is an amazingly well-designed and extremely well-organized work of programming. You really have to hand it to the Programmer who did it.
 
k lacroix
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Junilu Lacar wrote:Programming is as much about organization and allocating responsibilities as it is about solving a problem. Think about this: you, as a person, have many body parts. Each part is designed to do something. Ears are for hearing, eyes for seeing, etc. What would it be like if you had to listen with your feet or see with your tongue? That wouldn't be right, would it? But why wouldn't it be right? Because the foot is not the best place to put a receptor for sound nor is the tongue the best place to put your ”sensors" for light.

Likewise, some of the code you have there is not properly appropriated to a method whose responsibility is ostensibly, to add a Person to a FamilyTree.

First, which of the following makes more sense?

”Hey, FamilyTree, add this Person." ( pointing at a pile of Strings )

Versus

"Hey, FamilyTree, add this Person." ( pointing at a Person )

The latter makes more sense, right? So why write line 3 like the former rather than the latter?

Second, if you decided to prompt the user differently when asking for the name of a Person, say in French or Italian instead of English, for example, does it make sense that you would have to go and change a method called addPerson? By analogy, does it make sense for you to go to an optician to get new glasses and expect him to examine your feet? No, right?

Let me put it in yet another way. Is it reasonable to expect your mouth to do everything that your digestive system as a whole is responsible for doing? No, right? The mouth is only responsible for the initial intake of food. It will then pass on what it did to the stomach for further processing, which then passes what it did to the small intestine and so on and so forth. Each organ in the chain has its own specific responsibility and contribution in the processing of food and drink to provide energy for the body.

Likewise, while prompting for user input may be part of the entire process of adding a Person to a FamilyTree, it is only one of many tasks that need to be performed. Prompting for user input is still just the initial "intake" of information and it's a different task/responsibility from actually adding a Person to the tree.

As you can see, even with so little code, there's already quite a bit of reorganization you need to do. At least now you're aware of the kind of things you need to start thinking about to organize your program better.

Aside: if you think about it, the human body, or any living thing really, is an amazingly well-designed and extremely well-organized work of programming. You really have to hand it to the Programmer who did it.



FYI: I only need to worry about one person as per the specs of the assignment. The problem is that this class has done a very poor job explaining Java. No matter, I think you are saying is to have an addPerson method who's sole job is to collect information about the person but instead of storing strings, use objects. The problem is I don't know to do that. A second method could be used to actually input the information in to an ArrayList?
 
Junilu Lacar
Sheriff
Posts: 17678
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

k lacroix wrote:FYI: I only need to worry about one person as per the specs of the assignment.


Only worry about one Person? Really?

So you would have a FamilyTree with only one person in it? That doesn't seem very useful. In fact, that sounds a bit pointless, to say the least.

More likely, you were told to write code that allows a user to enter information about one person at a time. The program, however, should be able to handle multiple Person objects and manage the relationships between them so you could model a FamilyTree.

I think you are saying is to have an addPerson method who's sole job is to collect information about the person but instead of storing strings, use objects.


I must have done a poor job explaining in my previous response because, no, that's absolutely not what I was saying. In fact, I was saying the exact opposite of that. The name addPerson implies to me that the method's responsibility is simply to add a Person object to some kind of collection for storage, like a List<Person> maybe.

On the other hand, a method that is responsible for asking the user to input information about a Person would more naturally be called something like this:

That code is essentially saying this: "To ask the user to input information about a Person, call the inputInformationFor(Person) method."

That's more logical, don't you think? Do you see how "asking the user to input information about a Person" leads to that particular method signature? The name tells you what the intent is.

If instead I said, "To ask the user to input information about a Person, call the addPerson(Person) method" there would be a little bit of a disconnect there, right?

That's like telling someone any of the following:

"To ask a lady for her telephone number, add her to your contact list."
"To find out what your mother's favorite cake recipe is, add the index card to your favorite recipe file."
"To ask your teacher what your grade is, put your report card in your pocket."

Something is a little off there, right?

Is that clearer now?
 
Junilu Lacar
Sheriff
Posts: 17678
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

k lacroix wrote:The problem is that this class has done a very poor job explaining Java ... The problem is I don't know to do that.


While that may be true, don't use it as an excuse for not being able to learn Java. Many people are self-taught. In fact, many of the best programmers I know, including most if not all of the moderators on this site, are self-taught. You have the entire Internet at your disposal. Since you are posting to this site and asking questions, I assume that it's not against your class policy to use outside resources. There are so many tutorials out there that can help you find the answers that you need to figure this stuff out.

Start with the Official Java Tutorials

Learn how to use Google! In most browsers, like Chrome for example, you can just type a question in the address bar like "How do I define methods in Java?" and you'll get back a bunch of links to relevant information. Don't let poor instruction prevent you from learning. Go out and figure it out! That's what good programmers do. If you want to learn how to be good at programming, start learning how to do what good programmers do.
 
Junilu Lacar
Sheriff
Posts: 17678
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

k lacroix wrote:instead of storing strings, use objects. The problem is I don't know to do that.


This part, you understood correctly. The topics you want to read about are encapsulation and setters in Java. You should be able to write something like this:

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have a code of family tree in java
 
Marshal
Posts: 5639
329
IntelliJ IDE Python TypeScript Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, welcome to the Ranch!

You won't find anyone here who will send you the full solution. But if you show us what you've done and explain where you're stuck then you'll very likely get some help.
 
Everybody's invited. Except this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic