Java Reference
In-Depth Information
public int getDay()
{
return dDay;
}
//Method to return the year
//Postcondition: The value of dYear is returned.
public int getYear()
{
return dYear;
}
//Method to return the date in the form mm-dd-yyyy
public String toString()
{
return (dMonth + "-" + dDay + "-" + dYear);
}
}
Figure 10-16 shows the UML diagram of the class Date .
Date
-dMonth: int
-dDay: int
-dYear: int
+Date()
+Date( int , int , int )
+setDate( int , int , int ): void
+toString(): String
+getMonth(): int
+getDay(): int
+getYear(): int
FIGURE 10-16 UML class diagram of the class Date
The definition of the method setDate , before storing the date into the data members,
does not check to see if the date is valid. That is, it does not confirm that month is
between 1 and 12 , year is greater than 0 , and day is valid (for example, for January, day
should be between 1 and 31 ). In Programming Exercise 2 at the end of this chapter,
you are asked to rewrite the definition of the method setDate so that the date is
validated before storing it in the data members. Similarly, in Programming Exercise 2,
you are asked to rewrite the definition of the constructor with parameters so that it
checks for valid values of month , day , and year before storing the date into the data
members.
Next, we specify the members of the class PersonalInfo .
Search WWH ::




Custom Search