Question: Problem 2 (40 points ] Time class. In this problem, you are asked to design a class for Time objects. (Note that Python has a

 Problem 2 (40 points ] Time class. In this problem, you

Problem 2 (40 points ] Time class. In this problem, you are asked to design a class for Time objects. (Note that Python has a datetime module that contains a datetime class for time and date objects. You should not use the datetime module anywhere in this problem. ) You will implement your own Time class to represent objects that are times of day. Implement the Time class in a module called problem2.py. In addition, you are provided a test file called test-time.py to test your implementation of the class. 1. init.-: The constructor initializes three attributes of the time: the hour, the minute, and a string indicating whether it's an 'AM' or 'PM' time. The default value for a Time object should be 12:00AM. The constructor must check for validity of the time, and should raise an exception if it is invalid. Note that the only valid values for the hour are integers lying between 1 and 12 (inclusive) and the only valid minute values are integers lying between 0 an 59 (inclusive). 2. hour: Returns the hour of the Time instance. 3. minute: Returns the minute of the Time instance. 4. am-pm: Returns a string ("AM" or "PM") indicating whether the Time instance is an AM or PM time. 5. total minutes: Returns the total number of minutes from midnight until the Time instance. For example, if T is the Time instance 12:30PM, then T.total minutes () should return 750. 6. minute ahead: Returns the time that is one minute ahead. For example, if t is the time 11:59AM, then t.minute_ahead() should return the time 12:00PM. Note: This method returns a Time object. 7. minute_back: Returns the time that is one minute behind. For example, if t is the time 11:59AM, then t.minute_back() should return the time 11:58 AM. Note: This method returns a Time object. 8. --str--- Returns a printable version of the Time instance, which is a string representation of that instance. Keep in mind that the printable version of a Time instance must always use two digits for the minute. For example, if T = Time(9, 7, "am"), then print (T) should print 9:07AM. 9. --repr--- Returns a meaningful representation of the Time instance. This should be the string representation in the form described for the str.- method

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!