import java.util.*; /** * Person - A Person within the family tree * @author David Smith **/ public class Person { //////////////////////Instance variables/fields/attributes/////////////////////////// /**the unique ID**/ private String ID; /**the name**/ private String name; /**the date of birth**/ private int dob; /**the date of death**/ private int dod; /**the unique ID of the spouse**/ private String spouse; /**the title**/ private String title; /**the LinkedList of children**/ private LinkedList children; //////////////////////////////////Constructors/////////////////////////////////////// /** * Constructor * @param ID the unique ID * @param name the name * @param dob the date of birth * @param dod the date of death * @param spouse the ID of the spouse * @param title the royal title of the person **/ public Person(String ID, String name, int dob, int dod, String spouse, String title) { this.ID = ID; this.name = name; this.dob = dob; this.dod = dod; this.spouse = spouse; this.title = title; children = new LinkedList(); } ////////////////////////////////Accessors/Getters///////////////////////////////////// /** * Retrieves the ID * @return the ID **/ public String getID() { return ID; } /** * Retrieves the name * @return the name **/ public String getName() { return name; } /** * Retrieves the date of birth * @return the date of birth **/ public int getDoB() { return dob; } /** * Retrieves the date of death * @return the date of death **/ public int getDoD() { return dod; } /** * Retrieves the ID of the spouse * @return the ID of the spouse **/ public String getSpouse() { return spouse; } /** * Retrieves the title * @return the title **/ public String getTitle() { return title; } /** * Retrieves the list of children * @return the list of children **/ public LinkedList getChildren() { return children; } ///////////////////////////////Modifiers/Setters///////////////////////////////////// //None are included because the information does not need to be modified after a constructor is called ///////////////////////////////Other Methods///////////////////////////////////// /** * Add a new child to the children list * @param tn a new TreeNode child **/ public void addChild(String str) { children.add(str); } /** * Return the age of the Person. If the person is still alive use 2008 as the death year. * @return the age of the Person **/ public int age() { int deathYear = dod; //if the person is still alive use 2008 as the date of death if(deathYear < 0) deathYear = 2008; //return the age return deathYear - dob; } /** * Return a String representation of the TreeNode * @return a String representation of the TreeNode **/ public String toString() { return title + " " + name; } public static void main(String a[]) { Person fred = new Person("fred1", "Fred Jones", 1982, -1, "Flossie", "Mr."); System.out.println(fred); } }