Information About This Project The concept of task management involves these att
ID: 3839173 • Letter: I
Question
Information About This Project The concept of task management involves these attributes: processors, i.e. human employees or robots a list of tasks, which could be independent or part of a task priority list Steps to Complete This Project Open NetBeans STEP 1 Open NetBeans and create a Java project with the following details. For Project Name include Lab15 For the Main Class include lab15 Task Management In your Code window for this class, shown below, copy the program code shown in Figure 1 below, in the appropriate places, except substitute your own name in place of Sammy Student PROJECT Java Applications: Task Management Application Figure 1 Source Code for the Task Management Program import java util ArrayList import java util Arrays; import java util Scanner Programmer: Sammy Student public class TaskManagement public static void main(Stringll args
Explanation / Answer
Program
---------------
package chegg.linkedlist;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class TaskManagement {
public static void main(String[] args) {
Mutex mutex = new Mutex();
List<Task> taskList = new ArrayList<Task>();
Task task1 = new Task("Task1", 20, "Open", mutex);
Task task2 = new Task("Task2", 25, "Open", mutex);
Task task3 = new Task("Task3", 18, "Open", mutex);
Task task4 = new Task("Task4", 9, "Open", mutex);
Task task5 = new Task("Task5", 13, "Open", mutex);
taskList.add(task1);
taskList.add(task2);
taskList.add(task3);
taskList.add(task4);
taskList.add(task5);
System.out.println("Task List");
for (Task task : taskList) {
System.out.println(task.toString());
}
int sequence = 0;
int index = 0;
int[] taskOrder = new int[taskList.size()];
int totalTask = taskList.size();
Scanner scanner = new Scanner(System.in);
char choice = 'Y';
while (totalTask != 0 && (choice == 'Y' || choice == 'y')) {
System.out
.println("Enter task which you want to get the task executed");
String taskName = scanner.next();
int i = 0;
for (; i < taskList.size(); i++) {
if (taskList.get(i).getName().equalsIgnoreCase(taskName)) {
if (sequence == 0) {
taskList.get(i).setProcessor("humanEmployee");
totalTask--;
sequence = 1;
} else {
taskList.get(i).setProcessor("robot");
sequence = 0;
totalTask--;
}
break;
}
}
taskOrder[index] = i + 1;
index++;
System.err
.println("Have you submitted the task or you want to continue ? 'Y' or 'N' ");
choice = scanner.next().charAt(0);
System.out.println("You entered" + choice);
}
for (int indx = 0; indx < taskOrder.length; indx++) {
if (taskOrder[indx] > 0) {
Thread t1 = new Thread(taskList.get(taskOrder[indx]-1));
System.out.println(" Task start status :"
+ taskList.get(indx).toString());
t1.start();
}
}
if (scanner != null) {
scanner.close();
}
}
}
class Mutex {
volatile int totalSum = 0;
}
class Task implements Runnable {
private String name;
private int duration;
private String status;
private String processor = "NONE";
public Mutex mutex;
public Task(String name, int duration, String status, Mutex mutex) {
super();
this.name = name;
this.duration = duration;
this.status = status;
this.mutex = mutex;
}
public String getProcessor() {
return processor;
}
public void setProcessor(String processor) {
this.processor = processor;
}
public String getName() {
return name;
}
public int getDuration() {
return duration;
}
public String getStatus() {
return status;
}
public void setName(String name) {
this.name = name;
}
public void setDuration(int duration) {
this.duration = duration;
}
public void setStatus(String status) {
this.status = status;
}
@Override
public void run() {
synchronized (this.mutex) {
try {
this.setStatus("In Use");
this.mutex.wait(this.getDuration());
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this.setStatus("close");
this.mutex.totalSum = this.mutex.totalSum + this.getDuration();
System.out.println("totalSum" + this.mutex.totalSum);
System.out.println("Task Finished status" + this.toString()
+ "and done by processor " + this.getProcessor());
this.mutex.notifyAll();
}
}
@Override
public String toString() {
return " [ name=" + name + ", duration=" + duration + ", status="
+ status + "]";
}
}
Output
------------
Task List
[ name=Task1, duration=20, status=Open]
[ name=Task2, duration=25, status=Open]
[ name=Task3, duration=18, status=Open]
[ name=Task4, duration=9, status=Open]
[ name=Task5, duration=13, status=Open]
Enter task which you want to get the task executed
Task5
Have you submitted the task or you want to continue ? 'Y' or 'N'
Y
You enteredY
Enter task which you want to get the task executed
Task1
Have you submitted the task or you want to continue ? 'Y' or 'N'
N
You enteredN
Task start status : [ name=Task1, duration=20, status=Open]
Task start status : [ name=Task2, duration=25, status=Open]
totalSum13
Task Finished status [ name=Task5, duration=13, status=close]and done by processor humanEmployee
totalSum33
Task Finished status [ name=Task1, duration=20, status=close]and done by processor robot
Description:
1. Program has capabiltites to execute number of task given by user. Intailly arraylist has 5 task but user entered 2 out of 5 ( Task1 and Task5) .
2. Program will spown number of threads as numbers of task we have corresponding.
3. Each thread share one shared resource mutex in which we maintain the total sum of time taken by every task.
4. Need to run the program, execute main method.
Let me know if you face any challanges while making understanding on above code or flow.