Question: The Date class Save your copy as date.py Notice that in this Date class there are three attributes, also known as data members: An attribute
The Date class
Save your copy as date.py
Notice that in this Date class there are three attributes, also known as data members:
An attribute holding the month this is self.month
An attribute holding the day of the month this is self.day
An attribute holding the year this is self.year
The Date class should have an init method and a str method. As we've discussed in class,
the double underscores before and after these method names indicate that these methods are special
methods that Python knows to look for. In the case of init this is the method that Python looks for
when making a new Date object. In the case of str this is the method that Python looks for when it
needs to represent the object as a string.
Qpt : implement the initself month, day, year method and
strself method. For str method, it should construct and return a string with the month,
day, and the year, formatted nicely to have exactly two digits places for the month, two digit places for the
day, and four for the year, eg
d Date
strd
Now, implement a few methods for the Date class from scratch. Be sure to add a docstringmethod
specification to each of the methods you write!
Q pt : add the method isLeapYearself to your Date class. The method should return True if
the current object represents a Leap year, return False otherwise. Please check Wikipedia for the
definition of Leap year. Eg
d Date
disLeapYear
False
d Date
disLeapYear
True
Q pt : add the method tomorrowself to your Date class. This method should NOT RETURN
ANYTHING! Rather, it should change the calling object so that it represents one calendar day after the
date it originally represented. This means that self.day will definitely change. What's
more, self.month and self.year might change. You may define the list DIM
at the very top of your python file to help you
determine how many days there are in any particular month selfmonth
d Date
strd
dtomorrow
strd
d Date
dtomorrow
strd
dtomorrow
strd
Q pt : add the method isBeforeself dto your Date class. This method should
return True if the calling object is a calendar date before the input named dwhich will always be an
object of type Date If self and d represent the same day, this method should return False. Similarly,
if self is after d this should return False.
d Date
d Date
disBefored
True
disBefored
False
disBefored
False
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
