logo CodeStepByStep logo

Date_from_absolute_day

Language/Type: Python classes
Related Links:

Add a method named from_absolute_day to the Date class that sets the state of a Date object based on an absolute day integer parameter. 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 a mutator method to the Date class named from_absolute_day that accepts an integer parameter representing an absolute day of the year from 1 to 365. You should modify the Date object's state to represent the month and day of the year that corresponds to that absolute day. For example, if the client calls your method with the parameter value 35, you should set the date to store February 4:

d = Date(7, 4)
d.from_absolute_day(35)
# now d.month is 2, d.day is 4
					
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.