1. Users should be able to use to populate the following arrays:
Array Contents
Developer Contains the names of all the developers
assigned to tasks
Task Names Contains the names of all the created tasks
Task ID Contains the generated taskID’s for all tasks
Task Duration Contains the Duration of all tasks
Task Status Contains the Status of all tasks
2. Users should be able to use these arrays to:
a. Display the Developer, Task Names and Task Duration for all tasks with the status of
done.
b. Display the Developer and Duration of the class with the longest duration.
c. Search for a task with a Task Name and display the Task Name, Developer and Task
Status.
d. Search for all tasks assigned to a developer and display the Task Name and Task
Status.
e. Delete a task using the Task Name.
f. Display a report that lists the full details of all captured tasks.
in java
1 answer
```java
import java.util.ArrayList;
import java.util.List;
public class TaskManager {
private List<String> developers;
private List<String> taskNames;
private List<Integer> taskIDs;
private List<Integer> taskDuration;
private List<String> taskStatus;
public TaskManager() {
this.developers = new ArrayList<>();
this.taskNames = new ArrayList<>();
this.taskIDs = new ArrayList<>();
this.taskDuration = new ArrayList<>();
this.taskStatus = new ArrayList<>();
}
public void populateArrays() {
// Code to populate the arrays
}
public void displayDoneTasks() {
for (int i = 0; i < taskStatus.size(); i++) {
if (taskStatus.get(i).equals("done")) {
System.out.println("Developer: " + developers.get(i));
System.out.println("Task Name: " + taskNames.get(i));
System.out.println("Task Duration: " + taskDuration.get(i));
}
}
}
public void displayLongestTask() {
int longestDuration = 0;
int longestTaskIndex = -1;
for (int i = 0; i < taskDuration.size(); i++) {
if (taskDuration.get(i) > longestDuration) {
longestDuration = taskDuration.get(i);
longestTaskIndex = i;
}
}
if (longestTaskIndex != -1) {
System.out.println("Developer: " + developers.get(longestTaskIndex));
System.out.println("Task Duration: " + taskDuration.get(longestTaskIndex));
}
}
public void searchTaskByName(String taskName) {
for (int i = 0; i < taskNames.size(); i++) {
if (taskNames.get(i).equals(taskName)) {
System.out.println("Task Name: " + taskNames.get(i));
System.out.println("Developer: " + developers.get(i));
System.out.println("Task Status: " + taskStatus.get(i));
}
}
}
public void searchTasksByDeveloper(String developer) {
for (int i = 0; i < developers.size(); i++) {
if (developers.get(i).equals(developer)) {
System.out.println("Task Name: " + taskNames.get(i));
System.out.println("Task Status: " + taskStatus.get(i));
}
}
}
public void deleteTask(String taskName) {
int taskIndex = taskNames.indexOf(taskName);
if (taskIndex != -1) {
developers.remove(taskIndex);
taskNames.remove(taskIndex);
taskIDs.remove(taskIndex);
taskDuration.remove(taskIndex);
taskStatus.remove(taskIndex);
} else {
System.out.println("Task not found");
}
}
public void displayAllTasks() {
for (int i = 0; i < taskNames.size(); i++) {
System.out.println("Task Name: " + taskNames.get(i));
System.out.println("Task ID: " + taskIDs.get(i));
System.out.println("Task Duration: " + taskDuration.get(i));
System.out.println("Task Status: " + taskStatus.get(i));
}
}
}
```
You can then use the TaskManager class to perform the desired operations. Here's an example usage:
```java
public class Main {
public static void main(String[] args) {
TaskManager taskManager = new TaskManager();
taskManager.populateArrays();
// Example usage of the methods
System.out.println("Tasks with status done:");
taskManager.displayDoneTasks();
System.out.println("\nTask with longest duration:");
taskManager.displayLongestTask();
System.out.println("\nSearch task by name:");
taskManager.searchTaskByName("Task 1");
System.out.println("\nSearch tasks by developer:");
taskManager.searchTasksByDeveloper("John");
System.out.println("\nDelete task:");
taskManager.deleteTask("Task 1");
System.out.println("\nAll tasks:");
taskManager.displayAllTasks();
}
}
```
Note that you will need to implement the populateArrays() method to actually populate the arrays with data.