Package chapter_five
Class Person
java.lang.Object
chapter_five.Person
public class Person
extends java.lang.Object
Class for a person with a name and dates for birth and death.
Class invariant: A Person always has a date of birth, and if the Person
has a date of death, then the date of death is equal to or later than the
date of birth.
- Version:
- 1.0
- Author:
- Sharaf Qeshta
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description private static booleanconsistent(chapter_four.Date birthDate, chapter_four.Date deathDate)To be consistent, birthDate must not be null.private static booleandatesMatch(chapter_four.Date date1, chapter_four.Date date2)To match, date1 and date2 either must be the same date or must both be null.booleanequals(Person otherPerson)chapter_four.DategetBorn()chapter_four.DategetDied()java.lang.StringgetName()voidsetBirthDate(chapter_four.Date newDate)Precondition: newDate is a consistent date of birth.voidsetBirthYear(int newYear)Precondition: The date of birth has been set, and changing the year part of the date of birth will give a consistent date of birth.voidsetDeathDate(chapter_four.Date newDate)Precondition: newDate is a consistent date of death.voidsetDeathYear(int newYear)Precondition: The date of death has been set, and changing the year part of the date of death will give a consistent date of death.voidsetName(java.lang.String newName)set the name of the objectjava.lang.StringtoString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Field Details
-
name
private java.lang.String nameperson name -
born
private chapter_four.Date bornthe date where the person born -
died
private chapter_four.Date diedif null person alive
-
-
Constructor Details
-
Person
public Person(java.lang.String initialName, chapter_four.Date birthDate, chapter_four.Date deathDate)- Parameters:
initialName- the name of the personbirthDate- the birthdate of the persondeathDate- if the date is null he still alive
-
Person
- Parameters:
original- copy info from original
-
-
Method Details
-
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object- Returns:
- String suitable string represent the object contains the name, birthDate, diedDate if the person die
-
equals
- Parameters:
otherPerson- to compare with the current object- Returns:
- boolean if the objects equals return true otherwise return false
-
datesMatch
private static boolean datesMatch(chapter_four.Date date1, chapter_four.Date date2)To match, date1 and date2 either must be the same date or must both be null.- Parameters:
date1- first date to be compared with date2date2- to be compared with date1- Returns:
- boolean (date1 == date2)
-
setBirthDate
public void setBirthDate(chapter_four.Date newDate)Precondition: newDate is a consistent date of birth. Postcondition: Date of birth of the calling object is newDate.- Parameters:
newDate- to be set as the birth date
-
setDeathDate
public void setDeathDate(chapter_four.Date newDate)Precondition: newDate is a consistent date of death. Postcondition: Date of death of the calling object is newDate.- Parameters:
newDate- to be set as the death date
-
setName
public void setName(java.lang.String newName)set the name of the object- Parameters:
newName- the new name
-
setBirthYear
public void setBirthYear(int newYear)Precondition: The date of birth has been set, and changing the year part of the date of birth will give a consistent date of birth. Postcondition: The year of birth is (changed to) newYear.- Parameters:
newYear- set a new year to born object
-
setDeathYear
public void setDeathYear(int newYear)Precondition: The date of death has been set, and changing the year part of the date of death will give a consistent date of death. Postcondition: The year of death is (changed to) newYear.- Parameters:
newYear- set a new year to die object if the die object is null it will exit
-
getName
public java.lang.String getName()- Returns:
- the name of the object
-
getBorn
public chapter_four.Date getBorn()- Returns:
- return a new Date object represent the born date.
-
getDied
public chapter_four.Date getDied()- Returns:
- return null if died object is null otherwise it will return a new Date object represent the died date
-
consistent
private static boolean consistent(chapter_four.Date birthDate, chapter_four.Date deathDate)To be consistent, birthDate must not be null. If there is no date of death (deathDate == null), that is consistent with any birthDate. Otherwise, the birthDate must come before or be equal to the deathDate.- Parameters:
birthDate- the date which the person born.deathDate- the date which the person die.- Returns:
- true if the birthDate came before deathDate.
-