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

    Fields
    Modifier and Type Field Description
    private chapter_four.Date born
    the date where the person born
    private chapter_four.Date died
    if null person alive
    private java.lang.String name
    person name
  • Constructor Summary

    Constructors
    Constructor Description
    Person​(Person original)  
    Person​(java.lang.String initialName, chapter_four.Date birthDate, chapter_four.Date deathDate)  
  • Method Summary

    Modifier and Type Method Description
    private static boolean consistent​(chapter_four.Date birthDate, chapter_four.Date deathDate)
    To be consistent, birthDate must not be null.
    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.
    boolean equals​(Person otherPerson)  
    chapter_four.Date getBorn()  
    chapter_four.Date getDied()  
    java.lang.String getName()  
    void setBirthDate​(chapter_four.Date newDate)
    Precondition: newDate is a consistent date of birth.
    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.
    void setDeathDate​(chapter_four.Date newDate)
    Precondition: newDate is a consistent date of death.
    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.
    void setName​(java.lang.String newName)
    set the name of the object
    java.lang.String toString()  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • name

      private java.lang.String name
      person name
    • born

      private chapter_four.Date born
      the date where the person born
    • died

      private chapter_four.Date died
      if 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 person
      birthDate - the birthdate of the person
      deathDate - if the date is null he still alive
    • Person

      public Person​(Person original)
      Parameters:
      original - copy info from original
  • Method Details

    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
      Returns:
      String suitable string represent the object contains the name, birthDate, diedDate if the person die
    • equals

      public boolean equals​(Person otherPerson)
      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 date2
      date2 - 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.