|
Bill Teter email: william.teter@plattsburgh.edu |
|
|
Lab 4 Genealogy and related questions Discussion: Specification: void addPerson(Person p) Person getPerson(String n) Set<String> getNames() Set<Person> getGrandParents(Person p) Set<Person> getGrandParents(String n) Set<Person> getSiblings(Person p) Set<Person> getSiblings(String n) Testing: -- list all names, one per line
-- list the grandparents of Sam, one per line. (Do this twice. Once for the String parameter, once for the Peron parameter. -- list the grandparents of John, one per line. Note, John doesn't have any. (Do this twice. Once for the String parameter, once for the Peron parameter. -- list the siblings of Max one per line. (Do this twice. Once for the String parameter, once for the Peron parameter. -- list the siblings of Frank one per line. (Do this twice. Once for the String parameter, once for the Peron parameter. Implementation advice: See lab 1 to review how to read from a file. Your test program will need to split each line of the data file into an array of string tokens. Examine the data file so you see how its contents are formatted. I suggest you use the date data to create a new date object. Then, check to see if the mother field is "'null" or not. If not "null" you may assume the named person has already appeared in the data file and can be retrieved from the genealogy with the getPerson() method. After the mother Person object has been retrieved, do the same for father. You are now ready to create the new Person and add that person to the genealogy.
Set<Person> siblings = new HashSet<Person>(); will create a set called siblings. The set interface includes the add() method. So you can add a Person p to the set by siblings.add(p). For the various accessor methods your code should begin by creating a set with the appropriate generic, when you have something to add to the set, add it. When you are done the method will return the the set. In the Test program you may use the following code to print everything in a set. It is called an enhanced for loop. The inside of the loop can of course be any statements. Assume that setX is a set of Person objects: for (Person p :
setX) This code will print one person per line. |