Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 2 [45 points | Calendar dates. In this problem, you are asked to implement a class called Date for calendar dates occurring on or

image text in transcribedimage text in transcribed

Problem 2 [45 points | Calendar dates. In this problem, you are asked to implement a class called Date for calendar dates occurring on or after January 1, 1800. FYI, January 1, 1800 was a Wednesday. Instances of the Date class have a month, day, and year value representing valid calendar dates on or after January 1, 1800. Create a module called problem2.py to contain your Date class implementation. Details about the class and its methods are provided below. (Python has its own datetime module, but, needless to say, you should not use that when implementing this class.) 1. Assign a class attribute called min year the value 1800. This represents the smallest year value allowed for instances of the Date class. The benefit of using a name to refer to the minimum year is that if we change our mind about the smallest allowable year value we need to change it in only one place. Use min year everywhere to refer to this value, rather than hard-coding 1800 in your code. In addition, assign another class attribute called dow-jan1 the value '"Wednesday'. This represents the day of week on January 1 of the vear min vear. 2. init: The constructor sets the values of the month, day, and year attributes of the date. You are required to make all instance attributes private. The default values for these should be 1, 1, and min year, respectively. The constructor must check for the validity of the date, and if the date is invalid, should raise an exception. This means that the month should lie between and 12 (inclusive), the day should be valid for that month, and the year should be greater than or equal to min year. For example, the dates 2/30/2008, 2/29/2009, and 9/31/2010 are all invalid. Make sure that you take leap years into account when determining the validity of the date. The method is leap will come in handy here 3. month: Returns the month of the date 4. day: Returns the day of the date. 5. year: Returns the year of the date. 6. year isleap: Returns True if the year of the date is a leap year and False otherwise A year is said to be a leap year if it is a multiple of 4. However, if it is also a multiple of 100, then it is a leap year only if it is a multiple of 400. So, for example, 1948 was a leap year, as will be 2124. However, 1800 and 1900 were not leap years, but 2000 was 7. daycount: Returns the total number of days from January 1, 1800 to the date. For example, if d is the date 2/14/1801, then d.daycount) should return 410 (there are Problem 2 [45 points | Calendar dates. In this problem, you are asked to implement a class called Date for calendar dates occurring on or after January 1, 1800. FYI, January 1, 1800 was a Wednesday. Instances of the Date class have a month, day, and year value representing valid calendar dates on or after January 1, 1800. Create a module called problem2.py to contain your Date class implementation. Details about the class and its methods are provided below. (Python has its own datetime module, but, needless to say, you should not use that when implementing this class.) 1. Assign a class attribute called min year the value 1800. This represents the smallest year value allowed for instances of the Date class. The benefit of using a name to refer to the minimum year is that if we change our mind about the smallest allowable year value we need to change it in only one place. Use min year everywhere to refer to this value, rather than hard-coding 1800 in your code. In addition, assign another class attribute called dow-jan1 the value '"Wednesday'. This represents the day of week on January 1 of the vear min vear. 2. init: The constructor sets the values of the month, day, and year attributes of the date. You are required to make all instance attributes private. The default values for these should be 1, 1, and min year, respectively. The constructor must check for the validity of the date, and if the date is invalid, should raise an exception. This means that the month should lie between and 12 (inclusive), the day should be valid for that month, and the year should be greater than or equal to min year. For example, the dates 2/30/2008, 2/29/2009, and 9/31/2010 are all invalid. Make sure that you take leap years into account when determining the validity of the date. The method is leap will come in handy here 3. month: Returns the month of the date 4. day: Returns the day of the date. 5. year: Returns the year of the date. 6. year isleap: Returns True if the year of the date is a leap year and False otherwise A year is said to be a leap year if it is a multiple of 4. However, if it is also a multiple of 100, then it is a leap year only if it is a multiple of 400. So, for example, 1948 was a leap year, as will be 2124. However, 1800 and 1900 were not leap years, but 2000 was 7. daycount: Returns the total number of days from January 1, 1800 to the date. For example, if d is the date 2/14/1801, then d.daycount) should return 410 (there are

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database Design A Practical Approach

Authors: Marilyn Campbell

1st Edition

1587193175, 978-1587193170

More Books

Students also viewed these Databases questions

Question

What are Electrophoresis?

Answered: 1 week ago