Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

// The Date class contains a month, day, and year, // and methods to set and dis

ID: 3634794 • Letter: #

Question

// The Date class contains a month, day, and year,
// and methods to set and display the values.
// The month cannot be set to less than 1 or more than 12,
// and the day of the month cannot be set to less than 1
// or more than the number of days in that month.
// The demonstration program instantiates four Dates and
// purposely assigns invalid values to some of the arguments;
// the class methods will correct the invalid values.
class Date
Declarations
private num month
private num day
private num year
public void setDate(num mo, num da, num yr)
num HIGH_MONTH = 12
num HIGHEST_DAYS[HIGH_MONTH] =
31, 29, 31, 20, 31, 30, 31, 31, 30, 31, 30, 31
if month > HIGH_MONTH then
month = HIGH_MONTH
else
if month < 1 then
month = 1
else
mo = month
endif
endif
if da > HIGHEST_DAYS[month] then
day = HIGHEST_DAYS[month]
else
if da < 1 then
da = 1
else
day = da
endif
yr = year
return
public void showDate()
output "Date: ", month, “/”, day, “/”, year
return
endClass

start
Declarations
Date birthday, anniversary, graduation, party
birthday.setDate(6, 24, 1982)
anniversary.setDate(10, 15, 2009)
graduation.setDate(14, 19, 2011)
party.setDate(7, 35, 2010)
output "Birthday "
birthday.showDate()
output "Anniversary "
anniversary.showDate()
output "Graduation "
graduation.showDate()
output "Party "
party.showDate()
stop

Explanation / Answer

Please Rate:Thanks

This code will help you

class Date
Declarations
private num month
private num day
private num year
public void setDate(num mo, num da, num yr)
num HIGH_MONTH = 12
num HIGHEST_DAYS[HIGH_MONTH] =
31, 29, 31, 20, 31, 30, 31, 31, 30, 31, 30, 31

If month > HIGH_MONTH then
Month = HIGH_MONTH
Else
If mo < 1 then
Month = 1
Else
mo = month
Endif
Endif

if da > HIGHEST_DAYS[month] then
day = HIGHEST_DAYS[month]
else
if da < 1 then
da = 1
else
day = da
endif
yr = year
return
public void showDate()
output "Date: ", month, “/”, day, “/”, year
return
endClass

start
Declarations
Date birthday, anniversary, graduation, party
birthday.setDate(6, 24, 1982)
anniversary.setDate(10, 15, 2009)
graduation.setDate(14, 19, 2011)
party.setDate(7, 35, 2010)
output "Birthday "
birthday.showDate()
output "Anniversary "
anniversary.showDate()
output "Graduation "
graduation.showDate()
output "Party "
party.showDate()
stop