Java Reference
In-Depth Information
Display 4.9 Yet Another Date Class (part 3 of 4)
56
public void setDay( int day)
57
{
58
if ((day <= 0) || (day > 31))
59
{
60
System.out.println("Fatal Error");
61
System.exit(0);
62
}
63
else
64
this .day = day;
65
}
66
public void setYear( int year)
67
{
68
if ( (year < 1000) || (year > 9999) )
69
{
70
System.out.println("Fatal Error");
71
System.exit(0);
72
}
73
else
74
this .year = year;
75
}
76
public boolean equals(DateFifthTry otherDate)
77
{
78
return ( (month.equalsIgnoreCase(otherDate.month))
79
&& (day == otherDate.day) && (year == otherDate.year) );
80
}
Within the definition of DateFifthTry , you can directly access private instance variables
of any object of type DateFifthTry .
81
public boolean precedes(DateFifthTry otherDate)
82
{
83
return ( (year < otherDate.year) ||
84
(year == otherDate.year && getMonth() < otherDate.getMonth()) ||
85
(year == otherDate.year && month.equals(otherDate.month)
86
&& day < otherDate.day) );
87
}
Within the definition of DateFifthTry , you can directly access private instance
variables of any object of type DateFifthTry .
<The definitions of the following methods are the same as in Display 4.2 and Display 4.7:
getMonth , getDay , getYear , and toString . >
88
private boolean dateOK( int monthInt, int dayInt, int yearInt)
89
{
(continued)
Search WWH ::




Custom Search