The Date class contains a month day and year andmethods to set and display the v

The Date class contains a month day and year andmethods to set and display the values. The month cannot be setto less than 1 or more than 12 and the day of the monthcannot be set to less than 1 or more than the number of days inthat month. The demonstration program instantiates four Dateobjects and purposely assigns invalid values to some of thearguments; the class methods will correct the invalid values.class Date Declarations private num month private num day privatenum year public void setDate(num mo num da num yr) num HIGH_MONTH= 12 num HIGHEST_DAYS[HIGH_MONTH] = 31 29 31 30 31 30 31 3130 31 30 31 if month > HIGH_MONTH then month = HIGH_MONTHelse if month < 1 then month = 1 else month = mo endif endif ifda > HIGHEST_DAYS[month 1] then day = HIGHEST_DAYS[month 1]else if da < 1 then day = 1 else day = da endif year = yr returnpublic void showDate() output Date: month / day / yearreturn endClass

You can leave a response, or trackback from your own site.
error: Content is protected !!