QUESTION

Text
Image


class WorkoutClass: "" "A workout class that can be offered at a gym. $===$ Private Attributes $==$ _name: The name of this WorkoutClass. _required_certificates: The certificates that an instructor must hold to teach this WorkoutClass. "n!" _name: str _required_certificates: List[str] def _init_(self, name: str, required_certificates: List[str]) -> None: ""Initialize a new WorkoutClass called <name> and with the <required_certificates>. $\gg>$ workout_class = WorkoutClass('Kickboxing', ['Strength Training']) $\gg>$ workout_class.get_name( ) 'Kickboxing' "n!" self._name = name self._required_certificates = required_certificates [:] def get_name(self) -> str: "" "Return the name of this Workoutclass. $\gg>$ workout_class = WorkoutClass ('Kickboxing', ['Strength Training']) $\gg>$ workout_class.get_name() 'Kickboxing' " $"$ " return self._name


def get_required_certificates(self) $\rightarrow$ List[str]: "" "Return all the certificates required to teach this Workoutclass. $\gg$ workout_class = WorkoutClass('Kickboxing', ['Strength Training']) 〉> workout_class.get_required_certificates() ['Strength Training'] "n" return self._required_certificates [:] class Instructor: "n"An instructor at a Gym. Each instructor may hold certificates that allows them to teach specific workout classes. $===$ Public Attributes $===$ name: This Instructor's name. $===$ Private Attributes $===$ _id: This Instructor's identifier. _certificates: The certificates held by this Instructor. name: str _id: int _certificates: List[str]


def _init_(self, instructor_id: int, instructor_name: str) $\rightarrow$ None: "" "Initialize a new Instructor with an 〈instructor_id> and their <instructor_name>. Initially, the instructor holds no certificates. $\gg>$ instructor $=$ Instructor $(1, '$ 'Matylda' $)$ $\gg>$ instructor.get_id() 1 $\gg>$ instructor. name 'MatyLda' " " " self._id = instructor_id self._certificates $=[]$ self.name = instructor_name self.instructor $=$ (instructor_id, instructor_name) def get_id(self) -> int: "" Return the id of this Instructor. $\gg>$ instructor = Instructor (1, 'Matylda' ) >> instructor.get_id() 1 " " " return self._id


def add_certificate(self, certificate: str) $\rightarrow$ bool: "" "Add the 〈certificate> to this instructor's list of certificates iff this instructor does not already hold the <certificate>. Return True iff the <certificate> was added. $\gg>$ instructor $=$ Instructor $(1$, 'Matylda' $)$ 〉> instructor.add_certificate('Strength Training') True 〉> instructor.add_certificate('Strength Training') False "n" if certificate in self._certificates: return False self._certificates.append(certificate) return True def get_num_certificates(self) $\rightarrow$ int: "" "Return the number of certificates held by this instructor. $\gg>$ instructor $=$ Instructor $(1$, 'Matylda' $)$ 〉> instructor.add_certificate('Strength Training') True 〉> instructor.get_num_certificates() 1 " " " return len(self._certificates)


def can_teach(self, workout_class: WorkoutClass) $->$ bool: "" "Return True iff this instructor has all the required certificates to teach the workout_class. 》matylda = Instructor(1, 'Matylda') $\gg$ kickboxing = WorkoutClass('Kickboxing', ['Strength Training']) $\gg$ matylda.can_teach(kickboxing) $\gg>$ matylda = Instructor $(1$, 'Matylda' $)$ 〉>kickboxing = WorkoutClass('Kickboxing', ['Strength Training']) 〉> matylda.can_teach(kickboxing) False 〉>matylda.add_certificate('Strength Training') True >> matylda.can_teach(kickboxing) True "n " teach $=$ True for req_certi in workout_class.get_required_certificates(): if req_certi not in self._certificates: \[ \text { teach }=\mathrm{False} \] return teach


class Gym: "" "A gym that hosts workout classes taught by instructors. All offerings of workout classes start on the hour and are 1 hour long. $===$ Public Attributes $===$ name: The name of the gym. $===$ Private Attributes $===$ instructors: The roster of instructors who work at this Gym. Each key is an instructor's ID and its value is the Instructor object representing them. _workouts: The workout classes that are taught at this Gym. Each key is the name of a workout class and its value is the WorkoutClass object representing it. _rooms: The rooms in this Gym. Each key is the name of a room and its value is its capacity, that is, the number of people who can register for a class in this room. _schedule: The schedule of classes offered at this gym. Each key is a date and time and its value is a nested dictionary describing all offerings that start then. Each key in the nested dictionary is the name of a room that has an offering scheduled then, and its value is a tuple describing the offering. The tuple elements record the instructor teaching the class, the workout class itself, and a list of registered clients. Each client is represented by a unique string. $===$ Representation Invariants $===$ - Each key in schedule is for a time that is on the hour. - No instructor is recorded as teaching two workout classes at the same time. - No client is recorded as registered for two workout classes at the same time.


- No instructor is recorded as teaching two workout classes at the same time. - No client is recorded as registered for two workout classes at the same time. - If an instructor is recorded as teaching a workout class, they have the necessary qualifications. - If there are no offerings scheduled at date and time $\langle d\rangle$ in room $\langle r\rangle$ then $\langle r\rangle$ does not occur as a key in _schedule[d] - If there are no offerings at date and time 〈d〉 in any room at all, then $\langle d\rangle$ does not occur as a key in schedule " " " name: str _instructors: Dict[int, Instructor] _workouts: Dict[str, WorkoutClass] _rooms: Dict[str, int] _schedule: Dict[datetime, Dict[str, Tuple[Instructor, WorkoutClass, List[str]]]] def init__(self, gym_name: str) -> None: ""Initialize a new Gym with 〈name> that has no instructors, workout classes, rooms, or offerings. $\gg>$ ac = Gym('Athletic Centre') $>>$ ac. name 'Athletic Centre' ""l" self.name $=$ gym_name self._instructors $=\{\}$ self._workouts $=\{\}$ self._capacity $=0$ self._rooms $=\{\}$ self._schedule $=\{\}$ " " " self.name = gym_name self._instructors $=\{\}$ self._workouts $=\{\}$ self._capacity $=0$ self._rooms $=\{\}$ self._schedule $=\{\}$


def add_instructor(self, instructor: Instructor) $->$ bool: "" "Add a new <instructor> to this Gym's roster iff the <instructor> has not already been added to this Gym's roster. Return True iff the instructor was added. $\gg>a c=$ Gym('Athletic Centre') $\gg>$ diane = Instructor(1, 'Diane') $\gg>$ ac.add_instructor(diane) True " " " added $=\mathrm{False}$ inst_id = instructor.get_id( ) if inst_id not in self._instructors: added = True self._instructors[inst_id] = instructor return added


def add_workout_class(self, workout_class: WorkoutClass) $\rightarrow$ bool: "r"ndd a 〈workout_class> to this Gym iff the 〈workout_class> has not already been added this Gym. Return True iff the workout class was added. $\gg>a c=G y m($ 'Athletic Centre') $\gg$ kickboxing = WorkoutClass('Kickboxing', ['Strength Training']) 》>ac.add_workout_class(kickboxing) True \[ \begin{array}{l} \text { added }=\text { False } \\ \text { name }=\text { workout_class.get_name( ) } \end{array} \] if name not in self._workouts: \[ \text { added }=\text { True } \] self._workouts [name] = workout_class return added def add_room(self, name: str, capacity: int) $->$ bool: "rr"Add a room with a 〈name> and 〈capacity> to this Gym iff the room has not already been added to this Gym. Return True iff the room was added. $\gg$ ac = Gym('Athletic Centre') $\gg$ ac.add_room('Dance Studio', 50) True "rur \[ \text { added }=\text { False } \] if name not in self._rooms: added $=$ True else: self__rooms[name ] = capacity return added


def schedule_workout_class(self, time_point: datetime, room_name: str, workout_name: str, instr_id: int) $\rightarrow$ bool: "rridd an offering to this Gym at a 〈time_point> iff: - the room with 〈room_name> is available, - the instructor with 〈instr_id> is qualified to teach the workout class with <workout_name>, and - the instructor is not teaching another workout class during the same 〈time_point>. A room is available iff it does not already have another workout class scheduled at that date and time. The added offering should start with no registered clients. Return True iff the offering was added. Preconditions: - The room has already been added to this Gym. - The Instructor has already been added to this Gym. - The WorkoutClass has already been added to this Gym. $\gg>$ ac $=$ Gym('Athletic Centre') $\gg$ diane = Instructor (1, 'Diane') $\gg$ ac.add_instructor(diane) True $\gg>$ diane.add_certificate('Cardio 1') True $\gg$ ac.add_room('Dance Studio', 50) True $\gg$ boot_camp = WorkoutClass('Boot Camp', ['Cardio 1']) $\gg$ ac.add_workout_class(boot_camp) True $\gg>$ sep_9_2019_12_00 = datetime $(2019,9,9,12,0)$ $\gg$ ac.schedule_workout_class(sep_9_2019_12_00, 'Dance Studio', I boot_camp.get_name(), diane.get_id()) True rurn pass


def register(self, time_point: datetime, client: str, workout_name: str) \ $\rightarrow$ bool: "r"Add 〈client> to the WorkoutClass with 〈workout_name> that is being offered at 〈time_point> iff the client has not already been registered in any course (including 〈workout_name〉) at 〈time_point>, and the room is not full. If the Workoutclass is being offered in more than one room at <time_point>, then the client is added to any one of the rooms (i.e., the room chosen does not matter). Return True iff the client was added. Precondition: the WorkoutClass with 〈workout_name> is being offered in some room at 〈time_point〉. $\gg$ ac = Gym('Athletic Centre') $\gg$ diane = Instructor (1, 'Diane') 〉 diane.add_certificate('Cardio 1') True $\gg$ ac.add_instructor(diane) True \[ \gg \text { ac.add_room('Dance Studio', 50) } \] True $\gg$ boot_camp = WorkoutClass ('Boot Camp', ['Cardio 1']) $\gg$ ac.add_workout_class(boot_camp) True \[ \gg \text { sep_9_2019_12_00 = datetime }(2019,9,9,12,0) \] 〉 ac.schedule_workout_class(sep_9_2019_12_00, 'Dance Studio', \ boot_camp.get_name(), diane.get_id()) True $\gg$ ac.register(sep_9_2019_12_00, 'Philip', 'Boot Camp') True $\gg$ ac.register(sep_9_2019_12_00, 'Philip', 'Boot Camp') False "rrit pass


def offerings_at(self, time_point: datetime) $\rightarrow$ List[Tuple[str, str, str]]: "rr"Return all the offerings that start at <time_point>. Return a list of 3-element tuples containing: the instructor's name, the workout class's name, and the room's name. If there are no offerings at <time_point>, return an empty list. The order of the elements in the returned list does not matter. $\gg>a c=$ Gym('Athletic Centre') $\gg$ diane = Instructor (1, 'Diane') 》diane.add_certificate('Cardio 1') True $\gg$ ac.add_instructor(diane) True $\gg$ ac.add_room('Dance Studio', 50) True $\gg$ boot_camp = WorkoutClass ('Boot Camp', ['Cardio 1']) 》)ac.add_workout_class(boot_camp) True $\gg \mathrm{t} 1$ = datetime $(2019,9,9,12,0)$ $\gg$ ac.schedule_workout_class(t1, 'Dance Studio', boot_camp.get_name(), diane.get_id()) True $\gg$ ('Diane', 'Boot Camp', 'Dance Studio') in ac.offerings_at(t1) True "n $n$ pass


def instructor_hours(self, time1: datetime, time2: datetime) $\rightarrow \backslash$ Dict[int, int]: "ru"Return a dictionary reporting the hours worked by instructors between 〈time1〉 and 〈time2〉, inclusive. Each key is an instructor ID and its value is the total number of hours worked by that instructor between 〈time1〉 and 〈time2〉 inclusive. Both 〈time1> and 〈time2〉 specify the start time for an hour when an instructor may have taught. Precondition: time1 $<$ time2 $\gg$ ac = Gym('Athletic Centre') $\gg$ diane = Instructor(1, 'Diane') $\gg$ david = Instructor (2, 'David') $\gg$ diane.add_certificate ('Cardio 1') True $\gg$ ac.add_instructor(diane) True $\gg$ ac.add_instructor(david) True $\gg$ ac.add_room('Dance Studio', 50) True $\gg$ boot_camp = WorkoutClass ('Boot Camp', ['Cardio 1']) $\gg$ ac.add_workout_class(boot_camp) True \[ \gg \mathrm{t} 1 \text { = datetime }(2019,9,9,12,0) \] $\gg$ ac.schedule_workout_class(t1, 'Dance Studio', boot_camp.get_name(), ...1) True \[ \begin{array}{l} \gg \mathrm{t} 2 \text { = datetime }(2019,9,10,12,0) \\ \gg \text { ac.instructor_hours }(t 1, t 2)==\{1: 1,2: 0\} \end{array} \] True ${ }^{n r} \mid$ pass


def payroll(self, time1: datetime, time2: datetime, base_rate: float) $\rightarrow$ List[Tuple[int, str, int, float]]: "r"Return a sorted List of tuples reporting the total wages earned by instructors between 〈time1> and 〈time2〉, inclusive. Each tuple contains 4 elements, in this order: - the instructor's ID, - the instructor's name, - the number of hours worked by the instructor between <time1> and <time2> inclusive, and - the instructor's total wages earned between 〈time1> and 〈time2〉 inclusive. The list is sorted by instructor ID. Both 〈time1〉 and 〈time2〉 specify the start time for an hour when an instructor may have taught. Each instructor earns $a$ <base_rate> per hour plus an additional BONUS_RATE per hour for each certificate they hold. Precondition: time1 < time2 $\gg>a c=G y m($ 'Athletic Centre') $\gg$ diane = Instructor(1, 'Diane') $\gg$ david = Instructor (2, 'David') $\gg$ diane.add_certificate("Cardio 1') True $\gg$ ac.add_instructor(diane) True ac.add_instructor(david) True $\gg$ ac.add_room('Dance studio', 50) True $\gg$ boot_camp = workoutClass('Boot Camp', ['Cardio 1']) $\gg$ ac.add_workout_class(boot_camp) True \[ \gg t_{1}=\text { datetime }(2019,9,9,12, \theta) \] $\gg$ ac.schedule_workout_class(t1, 'Dance Studio', boot_camp.get_name(), ...1) True \[ \begin{array}{l} \gg>t_{2}=\text { datetime }(2019,9,10,12, \theta) \\ \gg \text { ac.payroll(t1, t2, 25.0) } \\ \left.\left[\left(1, \text { 'Diane', }^{1}, 26.5\right) \text {, (2, 'David', } \theta, \theta .0\right)\right] \\ \end{array} \] "nn" pass

I need help with the last 5 functions that are passed. The assignment is in python. Answers were posted for this question, however, the solutions for the last 5 functions do not work when I run them. A doctest always fails, probably because I did the previous functions differently. So, the answers already posted for the last 5 functions do not work with the rest of my code.Thanks.

Public Answer

XIVQX9 The First Answerer