Question: USE PYTHON3; DO NOT IMPORT ANY PACKAGES I only need all of part d (core functionality) , which has two sections(can_merge_task and merge_two_tasks). Please do
USE PYTHON3; DO NOT IMPORT ANY PACKAGES
I only need all of part d (core functionality), which has two sections(can_merge_task and merge_two_tasks). Please do both sections. I just put parts a through c to make sure that you had all the necessary info. Make sure to pay attention to the requirements of assert statements in part d. Thank you!
Instance attributes of Task Class:
start_time (int): Given by the constructor's argument. After initialization, start_time indicates the start time of this task.
end_time (int): Given by the constructors argument. After initialization, end_time indicates the end time of this task.
focus_level_required (int): This value, together with focus_level from the PersonalSchedule class determines whether the person can handle this task.
task_description (str): Description might be making soup or roast turkey.



What the code looks like in the editor:

A) Constructor (init_): The constructor has parameters described in Question 1.1 and the attributes names are the same as these parameters. Note: Assert statements are not required for constructors/getters/string representations. You can assume that Task objects are always initialized correctly. B) Getters: a) get_start_time(self) Getter method that returns the start_time of the Task. This method creates the data abstraction. Example: return 1 if the task's start_time is 1 b) get_end_time(self) Getter method that returns the end_time the Task. This method creates the data abstraction. Example: return 2 if the task's end_time is 2 c) get_focus_level_required(self) Getter method that returns the focus_level_required of the Task. This method creates the data abstraction. Example: return 34 if the focus_level_required is 34. Note: All these getter methods require one line. C) String Representation Method a) __str_(self) In order to print a string representation of an object we need to write a special method (will be covered in class later). This method enables us to use print statements in the class. The special method __str]) is given to you in the starter code. It uses the getter methods that you have developed earlier. D) Core Functionality a) can_merge_task(self, other_task): Checks if two tasks can be merged. Two tasks can be merged only when they meet the following requirements: 1) their focus_level_required are the same, 2) their task_description are the same, and 3) there is an overlap in the time interval. Requirement: assert statements Parameters: self (Task): the first task to merge. other_task (Task): the second task to merge. Returns: True if merge is possible and False otherwise. For example: Task1 is (2, 5, 20, "Chopping potatoes") Task2 is (4, 6, 20, "Chopping potatoes") The merge is possible since there is an overlap between [2, 5] and [4, 6], function returns True. Taski is (2, 5, 20, "Chopping potatoes") Task2 is (6, 9, 20, "Chopping potatoes") The merge is not possible since there is no overlap between [2, 5] and [6, 9], function returns False. Note: If one interval follows right after the other, they are also considered to overlap (e.g. [2, 5] and [5, 6]). b) merge_two_tasks(self, other_task): Merges two tasks if the merge is possible. Requirement: assert statements Parameters: self (Task): the first task to merge. task (Task): the second task to merge. Returns: A new Task object after merging two tasks, where the time intervals are also merged; if merge is not possible, it returns None Example: Taski is (2, 5, 20, "Chopping potatoes") Task2 is (4, 6, 20, "Chopping potatoes") The merge is possible, so function returns new Task object (2, 6, 20, "Chopping potatoes") Taski is (2, 5, 20, "Chopping potatoes") Task2 is 6, 9, 20, "Chopping potatoes") The merge is not possible since there is no overlap between [2, 5] and [6, 9), function returns None. def can_merge_task(self, other_task): Give another Task called other_task, this function determines whether we are able to merge the current task and other_task. Requirement: Input validation Parameters other_task (Task): The other task to be merged with this task. Returns: True if we are able to merge those two tasks, False otherwise. # YOUR CODE STARTS HERE # def merge_two_tasks(self, other_task): Merge two tasks if the merge is possible. Requirement: Input validation Parameters: other_task (Task): The other task to be merged with this task. Returns: A new Task object after merging two tasks; otherwise, None is returned. # YOUR CODE STARTS HERE #
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
