Question: Write a family database program. Create a class to represent a person and to store references to the persons mother, Father, and any children, AND

Write a family database program. Create a class to represent a person and to store references to the persons mother, Father, and any children, AND ANY SIBLINGS that the person has. Read a file of names to initialize the name and the parent-child relationships of each person. (You might want to create a file representing your own family tree. Store the overall list of persons as an ArrayList. Write an overall driver class that asks for a name and prints the maternal and paternal family line of that person.

//PROGRAM DOES NOT INCLUDE SIBLING GETTERS / SETTERS / METHODS

You need to create the following classes:

Person class: Shell has been provided

FamilyInfo class: shell has been provided

FamilyTest class: shell has been provided

You also need to create a file representing the family info such as the following:

List the name of all the people in your family and end the list with the String End

For every person in the step a, write the following

Persons name

Persons mother

Persons father

You must create a file of the information about your own family. Here is a sample file

Henry VII Arthur Catherine of Aragon Henry VIII Anne Boleyn Jane Seymour Mary I Elizabeth I Edward VI Margaret James IV James V Mary of Guise Mary, Queen of Scots Henry, Lord Darnley James VI & I Mary Charles Brandon Frances Henry Grey Lady Jane Grey Elizabeth of York Margaret Stuart END 
// This class can be used to store basic family relationship information // about a particular family. import java.util.*; import java.io.*; public class FamilyInfo { private ArrayList people; private final String LIST_END = "END"; // signals end of list // constructs an empty family list/instantiates the list public FamilyInfo() { } // returns the position of a name in the list of people, // -1 if not found private int indexOf(String name) { for(int i = 0; i < people.size(); i++) { //if the name at index i is equals to the name //return the index i } return -1; } // returns a reference to the person with the given name if // they are in the list; returns null if not found public Person getPerson(String name) { return null; } // pre : input contains a sequence of birth records and all people // have already been read into people list // post: reads birth records, updating mother/father/children info private void ProcessParents(Scanner input) { //declare string varaibles for the personName, fatherName, motherName //declare 3 Person's object for called person , mother and father for(;;) { //read the name from the file and store it in personName //if the name is "END" //break // call the method getPerson from the person class and store the result in person variable //read another name from the file and store it in motherName //read another name from the list and store it in fatherName //*********************** //if the motherNmae is not equal to unknown //call the method getPerson(motherNmae) and store the result in mother //call the method setMother(mother) on the object person //call the method addKid(person) on the mother object } // *********************************** //repeat the same thing enclosed in * to set the father of the person } // input file is open for reading and contains a legal family list //the first sets of the names in the list will be read and the array list is created //input is the pointer to the file containing the names public void read(Scanner input) throws FileNotFoundException{ //read the first name in the file //while (name is not equals to "END) { //cretae an object of person //add the object to the list //read another name from the list } //call the method processParents } 
// This program tests the FamilyInfo and Person classes by reading a // file with family information and showing the maternal line, paternal // line and children for various people. import java.io.*; import java.util.*; public class FamilyTest { public static void main (String[] args) throws FileNotFoundException { //call the method giveIntro //cretae an object of FamilyInfo //create a Scaaner object //get the file name //cretae a Scanner object for the file name //call the method read from the Family class using the object family //call the method doMatches } // program explained to the user public static void giveIntro() { } // user prompted for name of person to show info for; info shown public static void doMatches(Scanner console, FamilyInfo list) { for(;;) { //prompt the user to get the name //get the person's name //if the name is quit //break //find the person's name in the list and store it in the variable of type Person, the method //getPerson must be called . store the result in a variable called next //if next conatins null //output no match // } else { //call showMaternal //showPaternal //showChildren } } // Shows maternal ancestors for given person public static void showMaternal(Person current) { } // Shows paternal ancestors for given person. public static void showPaternal(Person current) { System.out.println("Paternal line:"); } // Shows children for given person public static void showChildren(Person current) { //if the number of the children for the current person is 0 //print none //} else { for (int i = 0; i < current.numKids(); i++) { //print the name of each child // } System.out.println(); } } } 
// This class can be used to store the family information for one person import java.util.*; public class Person { private String name; private Person mother; private Person father; private ArrayList kids; // post: person with given name is constructed */ public Person(String person) { name = person; mother = null; father = null; kids = new ArrayList(); } // post : returns the name of the person public String getName() { return name; } // post : returns a reference to the mother of the person public Person getMother() { return mother; } // post : returns a reference to the father of the person public Person getFather() { return father; } // post : returns the number of children of the person public int numKids() { return kids.size(); } // pre : 0 <= n < numKids // post: returns the nth child of this person (n = 0, 1, 2, 3, ...) public Person nthKid(int n) { return kids.get(n); } // post: sets the mother of this person public void setMother(Person mother) { this.mother = mother; } // post: sets the father of this person public void setFather(Person father) { this.father = father; } // post: adds the given kid as a child of this person public void addKid(Person kid) { kids.add(kid); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!