Java Reference
In-Depth Information
Display 4.13
A Class with Constructors
(part 5 of 5)
157
else
158 System.out.println("Illegal date. Reenter input.");
159
}
160
}
161
private boolean
dateOK(
int
monthInt,
int
dayInt,
int
yearInt)
162
{
163
return
( (monthInt >= 1) && (monthInt <= 12) &&
164
(dayInt >= 1) && (dayInt <= 31) &&
165
(yearInt >= 1000) && (yearInt <= 9999) );
166
}
167
private boolean
dateOK(String monthString,
int
dayInt,
int
yearInt)
168
{
169
return
( monthOK(monthString) &&
170
(dayInt >= 1) && (dayInt <= 31) &&
171
(yearInt >= 1000) && (yearInt <= 9999) );
172
}
173
private boolean
monthOK(String month)
174 {
175
return
(month.equals("January") || month.equals("February") ||
176 month.equals("March") || month.equals("April") ||
177 month.equals("May") || month.equals("June") ||
178 month.equals("July") || month.equals("August") ||
179 month.equals("September") ||
month.equals("October") ||
180 month.equals("November") ||
month.equals("December") );
181
}
182
private
String monthString(int monthNumber)
183 {
184
switch
(monthNumber)
185 {
186
case
1:
187
return
"January";
. . .
<The omitted cases are obvious, but if need be, you can see all the cases in Display 4.9.>
. . .
188
The private methods need not be
last, but that's as good a place
as any.
default
:
189
System.out.println("Fatal Error");
190
System.exit(0);
191
return
"Error"; //
to keep the compiler happy
192
}
193
}
194 }