package formtest; public final class PersonInfo { private String firstName; private String lastName; private int birthMonth; private int birthDay; /** * Creates a person's info with default values that will have * to be set individually. */ public PersonInfo() { setFirstName(null); setLastName(null); setBirthMonth(-1); setBirthDay(-1); } /** * Creates a person's info with values given. * @param firstName * @param lastName * @param birthMonth * @param birthDay */ public PersonInfo(String firstName, String lastName, int birthMonth, int birthDay) { setFirstName(firstName); setLastName(lastName); setBirthMonth(birthMonth); setBirthDay(birthDay); } /** * Returns the person's first name. * @return */ public String getFirstName() { return firstName; } /** * Sets the person's first name. If input is null, value * is set to an empty string. * @param name */ public void setFirstName(String name) { if(name != null) this.firstName = name; else this.firstName = ""; } /** * Returns the person's last name. * @return */ public String getLastName() { return lastName; } /** * Sets the person's last name. If input is null, value * is set to an empty string. * @param name */ public void setLastName(String name) { if(name != null) this.lastName = name; else this.lastName = ""; } /** * Returns the person's birth month. * @return */ public int getBirthMonth() { return birthMonth; } /** * Sets the birth month of a person. Performs error * checking for values (0, 12]. Sets value to -1 if * input is out of bounds. * @param month */ public void setBirthMonth(int month) { if(month > 0 && month < 13) this.birthMonth = month; else this.birthMonth = -1; } /** * Returns the person's birth day. * @return int */ public int getBirthDay() { return birthDay; } /** * Sets the birth day of a person. Performs error checking * for values (0, 31]. Sets value to -1 if * input is out of bounds. * @param day */ public void setBirthDay(int day) { if(day > 0 && day < 32) this.birthDay = day; else this.birthDay = -1; } @Override public String toString() { return String.format("Person: %s, %s was born on %d/%d", getLastName(), getFirstName(), getBirthMonth(), getBirthDay()); } }