Answered step by step
Verified Expert Solution
Question
1 Approved Answer
All Date objects have the following data members: month ( an integer value between 1 and 1 2 ) day ( an integer value between
All Date objects have the following data members:
month an integer value between and
day an integer value between and
year a fourdigit, nonnegative integer
For this class provide:
a constructor:
parameters for the constructor must be provided in the following order: month, day, and year.
use the default values technique so that if no data is provided for month, day, year the date is set to January
inspectorsgettersaccessors for all the data members. Use the get convention to name your getters.
a mutatorsetter changeDate:
this setter modifies the Date object by adding a given amount of days.
this setter takes one parameter which is an integer that represents the number of days to add to a Date object.
You must be careful and make sure the resulting Date remains in the valid range. For example if you add days to the resulting date should be ; and if you add to the resulting date should be
Note: Remember that January, March, May, July, August, October and December have days. Assume February has always days. April, June, September, and November have days.
Hint: You will need to use loops and if statements for this method. You are not allowed to use the datetime module or any other materials not specifically covered in cS CS
Then proceed to overload the following operators:
The str special method, so the print function can be used with this class.
This method should return a Date object as a string in the format mmddyyyy for example
The comparison operators: and
These operators will allow us to compare two Date objects.
Note: a Date object is greater than another Date object if it's a later date. For example: is greater than Likewise is greater than
The subscript operator as an accessor.
Accessing position returns the value of the month data member.
Accessing position returns the value of the day data member.
Accessing position returns the value of the year data member.
For any other index value, raise an exception Index out of Bounds"
The code for the Date class should be saved in the date.py file.
In the main.py file you will have the main script for this assignment.
You must write a main script to make sure that your class and associated methods and operators work correctly.
At the very minimum you are expected to
create a few Date objects with the user providing data for the data members.
your main script should not accept invalid date for Date objects. For example is an invalid date because February only has days.
for your convenience the module inputroutines.py is being provided to help with input validation.
demonstrate that all the getter and setter methods work correctly
demonstrate that each one of the overloaded operators work:
You should explicitly compare two Date objects using the operators.
You should explicitly use the print function to display a Date object.
You should explicitly use the subscript operator with a Date object to access each of the object data members.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started