Java Reference
In-Depth Information
Display 4.13 A Class with Constructors (part 3 of 5)
78 public void setMonth( int monthNumber)
79 {
80 if ((monthNumber <= 0) || (monthNumber > 12))
81 {
82 System.out.println("Fatal Error");
83 System.exit(0);
84 }
85 else
86 month = monthString(monthNumber);
87 }
88 public void setDay( int day)
89 {
90 if ((day <= 0) || (day > 31))
91 {
92 System.out.println("Fatal Error");
93 System.exit(0);
94 }
95 else
96 this .day = day;
97 }
98 public int getMonth()
99 {
100 if (month.equals("January"))
101 return 1;
102 else if (month.equals("February"))
103 return 2;
104 else if (month.equals("March"))
105 return 3;
. . .
<The omitted cases are obvious, but if need be, you can see all the cases in Display 4.2.>
. . .
106 else if (month.equals("November"))
107 return 11;
108 else if (month.equals("December"))
109 return 12;
110 else
111 {
112 System.out.println("Fatal Error");
113 System.exit(0);
114 return 0; //Needed to keep the compiler happy
115 }
116 }
(continued)
Search WWH ::




Custom Search