You are going to create a family history program that will exercise your ability to work with collections. This lab will be due on Monday and Tuesday, Dec 6,7 in order to give you time to pass off late labs on Wednesday and Thursday.


You will write a program that performs the following functions:

  1. Read in a family history data file from a URL into an ArrayList of person objects. Each person in the data file will have personal information along with an identifier for a father and mother. Each Person object should have a father Person reference and a mother Person reference, but they will not be pointing to concrete objects when the Person is created.
  2. Sort the ArrayList by the birth year and print out the list in this order so that the user can see the chronology of the family.
  3. Put the data for each person into a Person object and insert these objects into a map based on the person identifier.
  4. Create a family tree structure by looking up the father and mother identifier for each person in the map and assigning the object you find in the map to the father and mother object reference in your person object.
  5. Input a person reference from the user and print out a pedigree chart for that person along with a family group sheet.

Program Flow:

  1. The user should be able to input the URL for the family history data file
  2. The user should be able to input a last name and the program will display the identifiers and names for all entries that have that last name.
  3. The user will pick one of these identifiers and you should generate the pedigree chart and family group sheet for that person.

Input format

Each line will look something like this.

FirstName LastName Identifier FatherIdentifier MotherIdentifier BirthYear BirthCity, BirthState, BirthCountry

So data for the Bush family might look like

George Bush 016873 001244 001243 1946 New Haven, Connecticut, USA
George Bush 001244 000364 000367 1924 Milton, Massachusetts, USA
Barbara Pierce 001243 000372 000298 1925 New York City, New York, USA
Jed Bush 07465 001244 001243 1947 Miami, Florida, USA
Mary Bush 17309 001244 001243 1948 Provo, Utah, USA
Martin Frank 99934 88845 17309 1968 Kanab, Utah, USA
Gary Haws 77745 99934 66623 1988 Nephi, Utah, USA
Margie Smith 000367 111023 111024 1926 Orem, Utah, USA
John Bush 000364 211023 211024 1927 Eugene, Oregon, USA
Wilma Flinstone 211024 311023 311876 1907 Sacramento, California, USA

You can give the URL Bushfor this data to your program for initial testing, but you will want to create some additional test cases. Notice a few things:

  • birthplaces may have spaces, so when you get to that part of the line you may want to read the rest of the line into the birthplace String.
  • Barbara has a father and mother too, but they are not in this file.
  • The two people named “George Bush” are different people (as it so happens, father and son. How do you know which is which?)
  • You should create some test cases (you can put them into your public_html folder in order to make them available through a URL). Once you have your own test cases working, you can look at some of the sample data sets at ://dna.cs.byu.edu/cs142/families.html


Requirement 1:

Compile and run your program from the command line. Some command line tips (Under Construction) FamilyHistory

Requirement 2:

Use the toString() method on your ArrayList of people. Your Person class should have a reasonable toString() method. Meaning, you shouldn't just regurgitate the line that created the person.

Requirements 3:

Print out the people grouped by birth year by using the ArrayList peoplelist.toString() method to call the toString method on each Person. You should group them by making the person class implement the “Comparable” interface, and sort your ArrayList using this comparable interface. You may want to look at Arrays.sort() (for a plain array) or Collections.sort() (for an ArrayList)

Requirement 4

Put all of your people into a map based on the person ID. Then go through each of your Person objects, look up the father and mother ID in the map and assign the object you find in the map to private Person variables in the child object. By so doing, you will have created a tree with your Person referencing the two parents.

Requirement 5

Allow the user to enter a last name. Print the names and identifiers of those who have that last name.

Requirements 6

Allow the user to input an identifier and print out the pedigree for that person. For example, if the user selected identifier 016873 from our sample data, then the following pedigree would be printed. You may want to create a more intuitive output format, but this will do if you cant think of anything else.

016873 George Bush
- George Bush
-- John Bush
--- Wilma Flinstone
-- Margie Smith
- Barbara Pierce

Requirements 7

Now print the family group sheet where that same person (016873 George Bush) appears as a child. Again, you are free to choose another format if you want to.

Father: George Bush Birth:  1924 Milton, Massachusetts, USA
Mother: Barbara Pierce Birth: 1925 New York City, New York, USA
George Bush Birth: 1946 New Haven, Connecticut, USA
Jed Bush Birth: 1947 Miami, Florida, USA
Mary Bush Birth: 1948 Provo, Utah, USA

Think before programming

  1. Plan out the elements in your Person object. Think about what instance variables will make your job easier.
  2. Break your program into small pieces and test each of them to make sure it responds correctly given simple data that you can figure out by hand
  3. Again, take a look at the examples.

Pass-off procedure

You should create some test cases (you can put them into your public_html folder in order to make them available through a URL). The TA will evaluate your program with data sets that are similar to those found here ://dna.cs.byu.edu/cs142/families.html.

The following grading criteria will be used:

  1. You have created test cases for your program (5 points)
  2. You can compile and run your program from the command line. (5 points)
  3. You have created a Person class and made the toString method for that class (use in conjunction with ArrayList) and call the toString method on the ArrayList to output your data. (5 points)
  4. You correctly print out the people sorted by the birth year (implement Comparable) (5 points)
  5. You can look up and display the identifiers for everyone with a given last name (5 points)
  6. Given an identifier, you display the pedigree chart for that person correctly (find person by looking up with a Map) (5 points)
  7. Given an identifier, you display the family group sheet for that person (find person by looking up with a Map) (5 points)
  8. Is your code properly formatted and do you use a separate file for each class? (5 points)

5 points extra credit: format the pedigree chart in a better way.

Extra Credit: Pass off early (1 point per day (excluding Sunday) up to 3 points)

Further tips

  • You can print out the tree by telling each of your parents to print themselves out (and then each of your parents can tell their parents to print themselves out), or you could put all of your parents in a queue, then as you pop them off of the queue, have them put their parents on the queue. Think about how you are going to traverse the tree before you start writing your code.
cs-142/fall-2010/labs/familyhistory.txt · Last modified: 2014/11/19 15:53 by ryancha
Back to top
CC Attribution-Share Alike 4.0 International
chimeric.de = chi`s home Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0