@Test public void testGetAge() { Person p = new Person(Gender.FEMALE, new Ssn("12345", Country.SWEDEN)); Calendar cal = Calendar.getInstance(); cal.add(Calendar.YEAR, -17); cal.add(Calendar.MONTH, 1); p.setBirthDate(cal.getTime()); assertEquals(new Integer(16), p.getAge()); }
public Integer getAge() { if (getBirthDate() == null) { return null; } Calendar birth = Calendar.getInstance(); birth.setTime(getBirthDate()); Calendar today = Calendar.getInstance(); int age = today.get(Calendar.YEAR) - birth.get(Calendar.YEAR); Calendar birthDay = Calendar.getInstance(); birthDay.set(Calendar.YEAR, today.get(Calendar.YEAR)); birthDay.set(Calendar.MONTH, birth.get(Calendar.MONTH)); birthDay.set(Calendar.DAY_OF_MONTH, birth.get(Calendar.DAY_OF_MONTH)); birthDay.set(Calendar.HOUR_OF_DAY, 0); birthDay.set(Calendar.MINUTE, 0); birthDay.set(Calendar.SECOND, 0); birthDay.set(Calendar.MILLISECOND, 0); boolean birthDayIsAfter = birthDay.compareTo(today) > 0; if (birthDayIsAfter) { age -= 1; } return age; }
Person extends PersonBase { public Integer getAge() { if (getBirthDate() == null) { return null; } Calendar birth = Calendar.getInstance(); birth.setTime(getBirthDate()); Calendar today = Calendar.getInstance(); int age = today.get(Calendar.YEAR) - birth.get(Calendar.YEAR); Calendar birthDay = Calendar.getInstance(); birthDay.set(Calendar.YEAR, today.get(Calendar.YEAR)); birthDay.set(Calendar.MONTH, birth.get(Calendar.MONTH)); birthDay.set(Calendar.DAY_OF_MONTH, birth.get(Calendar.DAY_OF_MONTH)); birthDay.set(Calendar.HOUR_OF_DAY, 0); birthDay.set(Calendar.MINUTE, 0); birthDay.set(Calendar.SECOND, 0); birthDay.set(Calendar.MILLISECOND, 0); boolean birthDayIsAfter = birthDay.compareTo(today) > 0; if (birthDayIsAfter) { age -= 1; } return age; } }
Person extends PersonBase { public Integer getAge() { if (getBirthDate() == null) { return null; } Calendar birth = Calendar.getInstance(); birth.setTime(getBirthDate()); Calendar today = Calendar.getInstance(); int age = today.get(Calendar.YEAR) - birth.get(Calendar.YEAR); Calendar birthDay = Calendar.getInstance(); birthDay.set(Calendar.YEAR, today.get(Calendar.YEAR)); birthDay.set(Calendar.MONTH, birth.get(Calendar.MONTH)); birthDay.set(Calendar.DAY_OF_MONTH, birth.get(Calendar.DAY_OF_MONTH)); birthDay.set(Calendar.HOUR_OF_DAY, 0); birthDay.set(Calendar.MINUTE, 0); birthDay.set(Calendar.SECOND, 0); birthDay.set(Calendar.MILLISECOND, 0); boolean birthDayIsAfter = birthDay.compareTo(today) > 0; if (birthDayIsAfter) { age -= 1; } return age; } protected  Person();  Person(Gender sex, Ssn ssn); }
Person extends PersonBase { public Integer getAge() { if (getBirthDate() == null) { return null; } Calendar birth = Calendar.getInstance(); birth.setTime(getBirthDate()); Calendar today = Calendar.getInstance(); int age = today.get(Calendar.YEAR) - birth.get(Calendar.YEAR); Calendar birthDay = Calendar.getInstance(); birthDay.set(Calendar.YEAR, today.get(Calendar.YEAR)); birthDay.set(Calendar.MONTH, birth.get(Calendar.MONTH)); birthDay.set(Calendar.DAY_OF_MONTH, birth.get(Calendar.DAY_OF_MONTH)); birthDay.set(Calendar.HOUR_OF_DAY, 0); birthDay.set(Calendar.MINUTE, 0); birthDay.set(Calendar.SECOND, 0); birthDay.set(Calendar.MILLISECOND, 0); boolean birthDayIsAfter = birthDay.compareTo(today) > 0; if (birthDayIsAfter) { age -= 1; } return age; } protected  Person();  Person(Gender sex, Ssn ssn); Integer getAge(); }
Person extends PersonBase { public Integer getAge() { if (getBirthDate() == null) { return null; } Calendar birth = Calendar.getInstance(); birth.setTime(getBirthDate()); Calendar today = Calendar.getInstance(); int age = today.get(Calendar.YEAR) - birth.get(Calendar.YEAR); Calendar birthDay = Calendar.getInstance(); birthDay.set(Calendar.YEAR, today.get(Calendar.YEAR)); birthDay.set(Calendar.MONTH, birth.get(Calendar.MONTH)); birthDay.set(Calendar.DAY_OF_MONTH, birth.get(Calendar.DAY_OF_MONTH)); birthDay.set(Calendar.HOUR_OF_DAY, 0); birthDay.set(Calendar.MINUTE, 0); birthDay.set(Calendar.SECOND, 0); birthDay.set(Calendar.MILLISECOND, 0); boolean birthDayIsAfter = birthDay.compareTo(today) > 0; if (birthDayIsAfter) { age -= 1; } return age; } protected  Person();  Person(Gender sex, Ssn ssn); Integer getAge();  }