Question: Complete Task 1 ( after completing Task 2 ) . Complete Task 3 ( after completing Task 1 ) . Complete Task 4 ( after

Complete Task 1(after completing Task 2).
Complete Task 3(after completing Task 1).
Complete Task 4(after completing both Tasks 5 and 6).
Please ignore task ID num 0
ID, Name, PreReq
7, A,
5, B,7
6, C,7
4, D,5+6
2, A,5
3, F,6
1, G,2+3
0, A,1
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 pre-requisite 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 pre-requisite 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 isConsistent(int 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 tsk.startTime, and the end-time of its prerequisites, is at least k.
E) Now write a function isConsistent2 which has the same purpose as isConsistent, but its implementation is different. The function isConsistent2 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: 7,2,0
B: 5
C: 6
D: 4
F: 3
G: 1
Implement this so that the running time is O(n), 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 O(n log(n)), as that is the time taken by sorting. However, we need a running time of O(n)).

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 Programming Questions!