Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

9.121352 Homework: Completing the Date class Using last week's work in lab as a starting point, complete the class called Date. - It should have

image text in transcribed

9.121352 Homework: Completing the Date class Using last week's work in lab as a starting point, complete the class called Date. - It should have an _init__ method that allows the user to set initial values of month, day and year. Give the three instance variables the exact names month, day, year. The default values should be January 1, 1970 (that specific date is referred to as the "epoch" in many programming languages). - It should have a__str_ method that returns a string. As an example, for the date November 4, 2007 the function should return the string "11/4/2007". - It should have a method called format_in_words that returns a string. As an example, for the date November 4, 2007, the function should return the string "November 4, 2007". For your convenience and accuracy, here are the spellings of the months: January, February, March, April, May, June, July, August, September, October, November, December The formatinwords method should return the string "Invalid date" if the month number is invalid - Implement a method called is_leap_year that returns a bool, indicating whether or not the year is a leap year. Return False for years before 1582, then follow the usual rules for determining whether or not a year is a leap year. Years divisible by 4 are leaps years, with the exception of years divisible by 100 , which typically are not. As a further exception, years divisible by 400 are leap years. - Implement a method called is_valid that returns a bool indicating whether or not the date is valid. For example, use the following examples to test your method: 7/4/1776,1/31/1970,2/29/1985 are all valid, but the following dates are all invalid: 13/6/2022, 0/12/2000, 4/31/2011, 8/23/-2, 4/-5/1583, 2/29/1985. - Implement a method called advance(), which modifies the instance variables, incrementing the date by one day. For example, 8/9/1924 becomes 8/10/1924. In another example, 4/30/2023 becomes 5/1/2023. The date 12/31/2022 becomes 1/1/2023. Note that 2/28/1984 becomes 2/29/1984, while 2/28/1985 becomes becomes 3/1/1985. - Implement a method called day_of_year0 that returns which day of the year the Date is. For example, 1/1/2023 is day 1 of the year, while 2/1/2023 is day 32 of the year. As another example, 11/11/1988 is day 316 of the year, while 11/11/1989 is day 315 of the year

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions