Java Reference
In-Depth Information
Display 5.19
A Person Class (part 3 of 5)
83 {
84 System.out.println("Inconsistent dates. Aborting.");
85 System.exit(0);
86 }
87 }
88 /**
89 Precondition: newDate is a consistent date of death.
90 Postcondition: Date of death of the calling object is newDate.
91 */
92 public void setDeathDate(Date newDate)
93 {
94
95 if (!consistent(born, newDate))
96 {
97 System.out.println("Inconsistent dates. Aborting.");
98 System.exit(0);
99 }
100
101 if (newDate == null )
102 died = null ;
103 else
104 died = new Date(newDate);
105 }
The date of death can be null . However,
there is no corresponding code in
setBirthDate because the method
consistent ensures that the date of
birth is never null .
106 public void setName(String newName)
107 {
108 name = newName;
109 }
110 /**
111 Precondition: The date of birth has been set, and changing the year
112 part of the date of birth will give a consistent date of birth.
113 Postcondition: The year of birth is (changed to) newYear.
114 */
115 public void setBirthYear( int newYear)
116 {
117 if (born == null ) //Precondition is violated.
118 {
119 System.out.println("Fatal Error. Aborting.");
120 System.exit(0);
121 }
122 born.setYear(newYear);
123 if (!consistent(born, died))
124 {
125 System.out.println("Inconsistent dates. Aborting.");
126 System.exit(0);
127 }
128 }
(continued)
Search WWH ::




Custom Search