Question
Python PART 1: Define a class to implement the date type as an ADT based on the following description: 1. This class has three integers
Python
PART 1:
Define a class to implement the date type as an ADT based on the following description: 1. This class has three integers as attributes: day, month, and year. Here are the constraints on
these attributes:
1?month?12
1 ? day ? 31 for the month numbers 1, 3, 5, 7, 8, 10, and 12. if month = 2 then 1 ? day ? 28, and
1 ? day ? 30 for all other months.
year ? 1900
The initializer method of this class initializes the date object with a date passed as the argument. In case that no argument exists, or an invalid argument is passed the date is initialized as 1/1/1900.
Define a method in your class to return the name of the month of the object.
Define a method to validate a day number based on a month number. This function returns
True if the day is a valid day in that month and returns False otherwise.
Define a method to move the date a specific number of days forward. For example, moving the
date 1/1/2018, 20 days forward changes the date to 21/1/2018.
Define a method to move the date a specific number of days backward. For example, moving
the date 1/1/2018, 3 days backward changes the date to 29/12/2017.
Define a method to calculate the difference between the date and another date in days.
Define a method to return the next date.
Define a method to return the previous date.
Define a method to display the date in the format dd-mm-yyyy on the screen.
Notes:
Do not consider leap years.
For each attribute and method decide if the member should be private or public. For the
private attributes, provide getter/setter methods.
PART 2:
Use the date class to write a program that asks user to enter the current date and his/her date of birth, then compares the users date of birth with the current date and prints a happy birthday message if they are equal. In case the current date is different from the users birth date, this program displays its next birthday in the format of dd-mm-yyyy along with the number of days remained to that date on the screen.
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