Java Reference
In-Depth Information
Display 5.19 A Person Class (part 4 of 5)
129 /**
130 Precondition: The date of death has been set, and changing the year
131 part of the date of death will give a consistent date of death.
132 Postcondition: The year of death is (changed to) newYear.
133 */
134 public void setDeathYear( int newYear)
135 {
136 if (died == null ) //Precondition is violated
137 {
138 System.out.println("Fatal Error. Aborting.");
139 System.exit(0);
140 }
141 died.setYear(newYear);
142 if (!consistent(born, died))
143 {
144 System.out.println("Inconsistent dates. Aborting.");
145 System.exit(0);
146 }
147 }
148 public String getName()
149 {
150 return name;
151 }
152 public Date getBirthDate()
153 {
154 return new Date(born);
155 }
156 public Date getDeathDate()
157 {
158 if (died == null )
159 return null ;
160 else
161 return new Date(died);
162 }
163 /**
164 To be consistent, birthDate must not be null. If there is no date of
165 death (deathDate == null), that is consistent with any birthDate.
166 Otherwise, the birthDate must come before or be equal to the deathDate.
167 */
Search WWH ::




Custom Search