SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Swastik
Amber Hisaw wrote:I haven't done anything yet. I'm not sure where to start.
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.Stefan Evans wrote: . . . a way to represent marriage and children. . . .
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.
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.
k lacroix wrote:FYI: I only need to worry about one person as per the specs of the assignment.
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.
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.
k lacroix wrote:instead of storing strings, use objects. The problem is I don't know to do that.
Tim Driven Development | Test until the fear goes away
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
|