logo CodeStepByStep logo

Date_absolute_day

Language/Type: Python classes
Related Links:

Add a method named absolute_day to the Date class that returns the absolute day of the year. Suppose a class of objects named Date has been already written that contains the following members:

member name type description
Date(month, day) constructor constructs a new date representing the given month and day
d._month
d._day
data attributes attributes to store the month and day
d.month property property to get/set the month
d.day property property to get/set the day
d.advance() method advances to the next day, wrapping to the next month and/or year if necessary
d.days_in_month() method returns the number of days in the month stored by your date object
d == other method returns True if the two dates have the same state
str(d) method returns a string representation such as "7/4" for July 4

Add an accessor method to the Date class named absolute_day that returns the absolute day of the year that is represented by the given date from 1 to 365. For example, January 1 is absolute day #1; January 2 is absolute day #2; January 31 is absolute day #31; February 1 is absolute day #32; February 2 is absolute day #33; and so on, up to December 31, which is absolute day #365.

Member function: Write a member function that will become part of an existing class. You do not need to write the complete class.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.