CSC108H Fall 2022 Worksheet: Object-Oriented Programming – Class Event
For each method, if the docstring example is incomplete, complete it, and then implement the method body.
class Event:
"""A new calendar event."""
def __init__(self, start_time: int, end_time: int, event_name: str) -> None:
"""Initialize a new event that starts at start_time, ends at end_time,
and is named event_name.
Precondition: 0 <= start_time < end_time <= 23
>>> e = Event(12, 13, 'Lunch')
>>> e.start_time
12
>>> e.end_time
13
>>> e.name
'Lunch'
"""
def rename(self, new_name: str) -> None:
"""Change the name of this event to new_name.
>>> e = Event(12, 13, 'Lunch')
>>>
>>>
"""
def duration(self) -> int:
"""Return the duration of this event.
>>> e = Event(9, 10, 'Lecture')
>>> e.duration()
1
"""
For each method, if the docstring example is incomplete, complete it, and then implement the method body.
class Event:
"""A new calendar event."""
def __init__(self, start_time: int, end_time: int, event_name: str) -> None:
"""Initialize a new event that starts at start_time, ends at end_time,
and is named event_name.
Precondition: 0 <= start_time < end_time <= 23
>>> e = Event(12, 13, 'Lunch')
>>> e.start_time
12
>>> e.end_time
13
>>> e.name
'Lunch'
"""
def rename(self, new_name: str) -> None:
"""Change the name of this event to new_name.
>>> e = Event(12, 13, 'Lunch')
>>>
>>>
"""
def duration(self) -> int:
"""Return the duration of this event.
>>> e = Event(9, 10, 'Lecture')
>>> e.duration()
1
"""