Java Reference
In-Depth Information
Display 4.9
Yet Another Date Class
(part 4 of 4)
90
return
( (monthInt >= 1) && (monthInt <= 12) &&
91 (dayInt >= 1) && (dayInt <= 31) &&
92 (yearInt >= 1000) && (yearInt <= 9999) );
93 }
94
private
String monthString(
int
monthNumber)
95 {
96
switch
(monthNumber)
97 {
98
case
1:
99
return
"January";
100
case
2:
101
return
"February";
102
case
3:
103
return
"March";
104
case
4:
105
return
"April";
106
case
5:
107
return
"May";
108
case
6:
109
return
"June";
110
case
7:
111
return
"July";
112
case
8:
113
return
"August";
114
case
9:
115
return
"September";
116
case
10:
117
return
"October";
118
case
11:
119
return
"November";
120
case
12:
121
return
"December";
122
default
:
123 System.out.println("Fatal Error");
124 System.exit(0);
125
return
"Error"; //to keep the compiler happy
126 }
127 }
128 }
The way that a well-designed class definition uses private instance variables and
public accessor and mutator methods to implement the principle of encapsulation is
diagrammed in Display 4.10.