edu.pdx.cs.joy.family.PersonMain Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of family Show documentation
Show all versions of family Show documentation
An Family Tree application for The Joy of Coding
package edu.pdx.cs.joy.family;
import java.text.DateFormat;
import java.text.ParseException;
/**
* A class with a main method for testing {@link Person}. Once upon a time,
* this functionality was part of the Person
class.
*
* @since Summer 2008
*/
public class PersonMain {
/**
* A simple test program.
*/
public static void main(String[] args) {
// Make some people and fill in information
Person me = me();
Person dad = dad(me);
Person mom = mom(me);
me.setMother(mom);
me.setFather(dad);
// Print out descriptions of these people
System.out.println(me + "\n");
System.out.println(mom + "\n");
System.out.println(dad + "\n");
}
/**
* Returns a Person representing me.
*/
static Person me() {
Person me = new Person(1, Person.MALE);
me.setFirstName("David");
me.setMiddleName("Michael");
me.setLastName("Whitlock");
return me;
}
/**
* Returns a Person representing my mom.
*/
static Person mom(Person me) {
Person mom = new Person(2, Person.FEMALE);
mom.setFirstName("Carolyn");
mom.setMiddleName("Joyce");
mom.setLastName("Granger");
try {
DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
mom.setDateOfBirth(df.parse("May 17, 1945"));
} catch (ParseException ex) {
System.err.println("** Malformatted mom's birthday?");
System.exit(1);
}
return mom;
}
/**
* Returns a Person representing my dad.
*/
static Person dad(Person me) {
Person dad = new Person(3, Person.MALE);
dad.setFirstName("Stanley");
dad.setMiddleName("Jay");
dad.setLastName("Whitlock");
try {
DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
dad.setDateOfBirth(df.parse("Feb 27, 1948"));
} catch (ParseException ex) {
System.err.println("** Malformatted dad's birthday?");
System.exit(1);
}
return dad;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy