as you might expect are sorted by either "natural" or user-defined priority sorting rules. For this assignment, you will create an interactive To-Do (Task list) application using a PriorityQueue data...


as you might expect are sorted by either "natural" or user-defined priority sorting rules. For this assignment, you will create an interactive To-Do (Task list) application using a PriorityQueue data structure. To-Do items or tasks have a priority associated with them and this priority will be the sort criteria for your PriorityQueue.


Unlike in the BinarySort exercise you did, if coded correctly, priority queue elements will sort automatically.


Your PriorityQueue will store Task objects, defined by the Task class below.


Two member attributes in Task use enum types Status and Priority, as defined as enum "classes" that will be used in your Task class. Notice the order of the
Priority enumerations. This is the sort order, your queue will use:


class Task implements Comparable {
int taskId;
String subject;
Priority priority;

Status status;

LocalDateTime startDate;
LocalDateTime dueDate;

}


enum Priority {

URGENT,
HIGH,
NORMAL,
LOW}

enum Status{

NOT_STARTED,
IN_PROGRESS,
WAITING,
DEFERRED
}


You will create an interactive test driver as we did for the BinarySearch exercise. A text-based driver is fine but if you are feeling ambitious, you are welcome to create a simple graphical UI (definitely not required).Your interactive test driver loop will allow users to:



  • Add a task. This will require you to capture the subject, priority, and dueDate.Here are some tips on using Java LocalDates.
    Use now() for the startDate. TaskId should start at 1 and increment each time a task is added.

  • View the next task in the queue using the peek() method and then optionally complete the current task using the poll() method.

  • View a list of all tasks. This will require the use of an iterator and the peek() method on each element. Use isEmpty() to check if there are items in your queue and if not, display "No tasks in queue."

  • View a single task by id. This will require iterating the task list until the id is found and then displaying it.

  • Remove a task by id. This will require you to iterate through the Task queue until you find the task with the matching id. Use remove(task) and confirm to the user that the task has been removed.

  • For readability, create a public toString method so that you can easily print queue elements:


@Override
public String toString() {
return "Id:" + taskId + "; Subject: " + subject + "; Status: " + status + "; Priority: " + priority + "; StartDate: " + startDate.toString() + "; Due date: " + dueDate;
}


  • In order to force PriorityQueue to use Priority as your sorting criterion, you should override the default comparator for the sort by adding this method to your Task class. Task should implements Comparable

  • @Override
    public intcompareTo(Tasktask) {
    return this.getPriority().compareTo(task.getPriority());
    }
    Note: If your PriorityQueue is just a list of numbers or simple strings, you won't need your own comparator, but in our case, we are using a more complex object-type, so we need to create our own.

  • Here is a priority helper method for your test-driver if you want, as a freebie:

private Priority scanForPriority() {
System.out.println("Enter priority abbreviation Normal=n,Low=l,High=h,Urgent=u): ");String abbrev = scanner.nextLine();
switch (abbrev) {
case"n":
priority =Priority.NORMAL;
break;
case"l":
priority =Priority.LOW;
break;
case"h":
priority =Priority.HIGH;
break;
case"u":
priority =Priority.URGENT;
break;
}
returnpriority;
}You should create your ownscanForStatus() method that follows the pattern above.
Use a Do-While loop to code up a test driver method for your PriorityQueue interactive testing. Here is a screenshot of a portion of one solution for your "menus" as a hint, in case you are confused.
Try it before you look:

public voidtestPriorityQueue() {
System.out.println("Welcome to My Task List\n");
System.out.println("Choose action (Add(a),Next(n),List(l),Detail(d),Edit(e),Remove(r),Quit(q): ");
StringmenuItem =scanner.nextLine();
do{
switch(menuItem) {
case"a":
addTask();
break;
case"n":
displayNextTask();
break;
case"l":
showTaskList();
break;
case"e":
System.out.println("Enter taskId: ");
inttaskId=parseInt(scanner.nextLine());
Task task= getTaskById(taskId);
editTask(task);
break;
case"d":
System.out.println("Enter taskId: ");
taskId=parseInt(scanner.nextLine());
showTaskDetail(taskId);
break;
case"r":
System.out.println("Enter taskId: ");
taskId=parseInt(scanner.nextLine());
removeTask(taskId);
case"q":
break;
}
System.out.println("Choose action (Add(a),Next(n),List(l),Detail(d),Edit(e),Remove(r),Quit(q): ");
menuItem =scanner.nextLine();
if(menuItem.equals("q"))
break;
}
while(menuItem !="q");
System.out.println("Goodbye");
}

Mar 04, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here