Question: Complete Task 1 ( after completing Task 2 ) . Complete Task 3 ( after completing Task 1 ) . Complete Task 4 ( after
Complete Task after completing Task
Complete Task after completing Task
Complete Task after completing both Tasks and
Please ignore task ID num
ID Name, PreReq
A
B
C
D
A
F
G
A
Note we are assuming that the same name can be given to different tasks. The only unique identification a value that only occurs in no more than a single row is the task id
Questions:
A Making Classes:
Make a Task class, with member variables being: id name, startTime, endTime, and preReq, where preReq is a list of Integers, storing the IDs of prerequisite tasks. Use Java ArrayList for this purpose.
Make an AllTasks class, which has just one private member variable: An ArrayList of Tasks. Lets call this member variable, TaskList
B In the constructor of the AllTasks, read the given CSV file, to make all the required task objects, and insert them into TaskList member variable. The information in the CSV file would be used to populate the variables of each task object: Name, id start time, end time and preReqs.
C Write a function PrintPreRequisites in the TaskList class that has the following description:
Input: A Task object tsk You can of course, give a different variable name to the input if you want
Output: The IDs and names of all those tasks in TaskList, whose prerequisite includes tsk
D We will say that the TaskList is consistent at k if the gap between the start time of a task, and the end time of its prerequisites, is at least k That is
Make a function isConsistentint k that returns true or false, depending on whether TaskList is consistent at k
Write this function using a nested for loop: For each task t in the list, go through the entire list of tasks, and check that the gap between tskstartTime, and the endtime of its prerequisites, is at least k
E Now write a function isConsistent which has the same purpose as isConsistent, but its implementation is different. The function isConsistent uses a hashmap to reduce the running time. Make the key of this hashmap to be the Task class. I will leave you to think about what should the Value of the HashMap.
Your implementation should be such that the function runs in time where is the number of edges in the figure shown above.
Note: You will have to override a couple of functions in the Task class.
F The employees are not careful, and sometimes give the same name to different task IDs. Write a function that prints the different names of the Tasks in the TaskList, and for each name, it prints the list of TaskIDs that has this name.
For instance, once you have populated TaskList from the given CSV file, the output of this function would be:
A:
B:
C:
D:
F:
G:
Implement this so that the running time is On where n is the number of tasks. Note if you use a double loop, the running time is O On the other hand if you sort them by name first, and then print all the IDs per name. You would need only single for loop after sorting, but then the running time is On logn as that is the time taken by sorting. However, we need a running time of On
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
