import java.util.Calendar; import java.util.GregorianCalendar; /* * Class representing a person with first and last names and a birth year. */ public class Person { private String firstName; private String lastName; private int birthYear; public Person() { } public Person(String firstName, String lastName, int birthYear) { super(); this.firstName = firstName; this.lastName = lastName; this.birthYear = birthYear; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public int getBirthYear() { return birthYear; } public void setBirthYear(int birthYear) { this.birthYear = birthYear; } public int getAge() { // Note: This is a bad estimate as it can sometimes be wrong. GregorianCalendar date = new GregorianCalendar(); return date.get(Calendar.YEAR) - birthYear; } public String getFullName() { return firstName + " " + lastName; } public String toString() { StringBuffer buf = new StringBuffer(100); buf.append("First name: "+firstName); buf.append(" Last name: "+lastName); buf.append(" Year: "+birthYear); return buf.toString(); } }