Question: USING PYTHON (30 pts.) Using the Time class developed in class (you can get code here), In addition to the hour , minutes , and

USING PYTHON

(30 pts.) Using the Time class developed in class (you can get code here),

  1. In addition to the hour, minutes, and secondsinstance variables, add an am_pm instance variable that denotes whether the time is in the am or the pm. You should also provide get (accessor) and set(mutator) methods for this instance variable.
  2. Incorporates a __str__ method that prints all four instance variable values of a Time object instead of the memory address of the object when a Time object variable is printed.
  3. Create a new method for the class that allows the user to set all four time instance variables with a single method call. This method should include some level of error checking so that it validates the values passed to the method. For example, the hours instance variable must be between 1-12 and the minutes and secondsinstance must be between 0-59. When invalid values are detected, your code can just not change them and instead leave them with their current value.
  4. A method that increments a Time object's secondsinstance variable value by 1. Note that you still need to make sure that this method does not create an invalid value in the seconds, minutes, hours, and am_pminstance variables.
THIS IS THE CODE: class Time: def __init__(self,h=12,m=0,s=0): self.hour = h self.minute = m self.second = s def get_hour(self): return self.hour def get_minute(self): return self.minute def get_second(self): return self.second def set_hour(self,h): self.hour = h def set_minute(self,m): self.minute = m def set_second(self,s): self.second = s def prt_time(self): print("It is currently "+str(self.hour)+":"+str(self.minute)+":"+str(self.second)) timeval = Time(10,20,30) print(timeval.get_hour(),timeval.get_minute(),timeval.get_second()) timeval.set_hour(5) timeval.set_minute(30) timeval.set_second(40) print(timeval.get_hour(),timeval.get_minute(),timeval.get_second()) timeval.prt_time()

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!