Question: To Do-List Application (Java) For this assignment, you will create an interactive To-Do (Task list) application using a PriorityQueue data structure. To-Do items or tasks

To Do-List Application (Java)

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. Your PriorityQueue will store Task objects.Two member attributes in Task use enum types Status and Priority, as defined as enum "classes" that will be used in your Task class. You will create an interactive test driver as we did for the BinarySearch exercise. Your interactive test driver loop will allow users to:

1. Add a task. This will require you to capture the subject, priority, and dueDate. Use now() for the startDate. TaskId should start at 1 and increment each time a task is added.

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

3. 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."

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

5. 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.

Template Implementation of the Application:

To Do-List Application (Java) For this assignment, you will create an interactiveTo-Do (Task list) application using a PriorityQueue data structure. To-Do items ortasks have a priority associated with them and this priority will be

the sort criteria for your PriorityQueue. Your PriorityQueue will store Task objects.Twomember attributes in Task use enum types Status and Priority, as definedas enum "classes" that will be used in your Task class. You

1 2 3 4 5 6 7 import java.time. LocalDate; import java.time. format. DateTimeFormatter; import java.util.Iterator; import java.util.PriorityQueue; import java.util.Scanner; import java.lang. Integer; 8 9 enum Priority { URGENT, HIGH, NORMAL, LOW } 10 11 12 13 14 15 Venum Status { NOT_STARTED, IN_PROGRESS, WAITING, DEFERRED } 16 class Task implements Comparable { 17 18 19 20 21 22 23 24 25 26 27 28 29 int taskid; String subject; Priority priority; Status status; LocalDate startDate; LocalDate dueDate; public Task(int taskid, String subject, Priority priority, Status status, LocalDate startDate, LocalDate dueDate) { this.taskid - taskId; this.subject - subject; this.priority - priority; this.status = status; this.startDate - startDate; this.dueDate - du eDate; } 31 32 33 34 35 36 37 38 39 public int get TaskId { return taskid; } @Override public String toString() { return "Id:" + taskid + "; Subject: " + subject + "; status: " + status + "; Priority: " + priority + "; StartDate: + startDate.toString() + "; Due date: " + dueDate; } public Priority get Priority() { return priority; } @Override public int compareTo(Task task) { return this.getPriority().compareTo(task.getPriority(); } 41 42 43 44 45 46 47 48 49 50 51 52 53 > 54 55 56 57 58 59 60 61 62 63 ) public class ToDoListApplication { PriorityQueue Task> taskPriorityQueue = new PriorityQueue ); Scanner scanner = new Scanner(System.in); public static void main(String[] args) { TODOListApplication app = new ToDoListApplication(); app.test PriorityQueue(); } 65 66 67 public void displayNext Task() { // add your code here } 68 69 70 71 72 public void showTaskDetail(int taskId) { Task task = getTaskById(taskId); 1/ add your code here to print the task. } public Task get TaskById(int taskid) { 73 74 75 76 77 78 79 Iterator it = taskPriorityQueue.iterator(); while (((Iterator) it).hasNext()) { Task task - (Task) it.next(); if (task.getTaskId() == taskid) return task; System.out.println("Taskid not found..."); } return null; 81 82 83 84 } 85 86 87 public void removeTask (int taskId) { // Add your code here } 89 90 91 public void testPriorityQueue() { System.out.println("Welcome to My Task List "); do { System.out.println("Choose action (Add(a), Next(n), List(1), Detail(d), Edit(e), Remove(r), Quit(9):"); 92 93 94 String menuItem = scanner.nextLine(); 95 96 97 98 99 100 101 102 103 184 105 106 107 108 switch (menuItem) { case "a": addTask(); break; case "n": displayNext Task(); break; case "1": showTaskSummaryList(); break; Case "d": System.out.println("Enter taskId: "); int taskId = Integer.parseInt(scanner.nextLine(); showTaskDetail(taskId); break; case "r": System.out.println("Enter taskId: "); taskId = Integer.parseInt(scanner.nextLine()); removeTask (taskId); break; case "q" : break; } } while (true); 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 } void showTask SummaryList() { for (Task task : taskPriorityQueue) System.out.println(task); } 124 125 private Priority scanFor Priority { Priority priority - Priority.NORMAL; 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; } return priority; } 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 void addTask ) { System.out.println("Adding new Task..."); System.out.println("Enter subject:"); Scanner scanner = new Scanner(System.in); String subject = scanner.nextLine(); System.out.println("Enter due date (YYYY-MM-dd):"); String input = scanner.nextLine(); DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd"); LocalDate dueDate = LocalDate.parse(input); Priority priority = scanFor Priority(); Status status = Status. NOT_STARTED; LocalDate date = LocalDate.now(); LocalDate startDate = LocalDate.now(); Task task = new Task(taskPriorityQueue.size() + 1, subject, priority, status, startDate, dueDate); taskPriorityQueue.add(task); Sample Output Welcome to My Task List Choose action (Add(a), Next{n}, List(1), Detail(d), Edit(e),Remove(r), Quit(a): a Adding new Task... Enter subject: Square the circle Enter due date (yyyy-MM-dd): 2020-11-31 Date format exception. Try again. Enter due date (YYYY-MM-dd): 2020-10-31 Enter priority abbreviation Normal=n, Low=1,High=h, Urgent=u): I Choose action (Add(a), Next{n}, List(1), Detail(d), Edit(e),Remove(r), Quit(a): a Adding new Task... Enter subject: Remove the rubble Enter due date (YYYY-MM-dd): 2020-11-20 Enter priority abbreviation Normal=n,Low=l,High=h, Urgent=u): n Choose action (Add(a), Next(n), List(1),Detail(d), Edit(e), Remove(r), Quit(q): a Adding new Task... Enter subject: Drive the drivers Enter due date (yyyy-MM-dd): 2020-11-15 Enter priority abbreviation Normal=n,Low=1,High=h, Urgent-u): h Choose action (Add(a), Next(n), List(1),Detail(d), Edit(e), Remove(r), Quit(a): a Adding new Task... Enter subject: Circle the square Enter due date (yyyy-MM-dd): 2021-11-05 Enter priority abbreviation Normal=n, Low=1,High=h, Urgent=u): u Choose action (Add(a), Next{n}, List(I),Detail(d), Edit(e), Remove(r), Quit(g): 1 Id:4; Subject: Circle the square; Status: Not Started; Priority: Urgent; StartDate: 2020-10-30; Due date: 2021-11-05 Id:3; Subject: Drive the drivers; Status: Not Started; Priority: High; StartDate: 2020-10-30; Due date: 2020-11-15 Id:2; Subject: Remove the rubble; Status: Not Started; Priority: Normal; StartDate: 2020-10-30; Due date: 2020-11-20 Id:1; Subject: Square the circle; Status: Not Started; Priority: Low; StartDate: 2020-10-30; Due date: 2020-10-31 Choose action (Add(a), Next{n},List(1),Detail(d), Edit(e), Remove(r),Quit(a): n Id:4; Subject: Circle the square; Status: Not Started; Priority: Urgent; StartDate: 2020-10-30; Due date: 2021-11-05 Is this task complete? y: Y Choose action (Add(a), Next{n}, List(1),Detail(d), Edit(e), Remnove(r),Quit(g): 1 Id:3; Subject: Drive the drivers; Status: Not Started; Priority: High; StartDate: 2020-10-30; Due date: 2020-11-15 Id:1; Subject: Square the circle; Status: Not Started; Priority: Low; StartDate: 2020-10-30; Due date: 2020-10-31 Id:2; Subject: Remove the rubble; Status: Not Started; Priority: Normal; StartDate: 2020-10-30; Due date: 2020-11-20 Choose action (Add(a), Next{n}, List(1), Detail(d), Edit(e),Remove(r), Quit(a): e Enter taskld: 2 Taskid not found... Taskid not found... Edit Task: Enter new subject or press enter to leave unchanged: Remove the rabble Enter new due date (yyyy-MM-dd), or press enter to leave unchanged: Enter status abbreviation Not Started-n,Deferred=d, Waiting=w,Complete-c): u Enter priority abbreviation Normal=n,Low=l,High=h, Urgent=u): I Choose action (Add(a),Next(n), List(1),Detail(d), Edit(e), Remnove(r),Quit(a): 1 Id:3; Subject: Drive the drivers; Status: Not Started; Priority: High; StartDate: 2020-10-30; Due date: 2020-11-15 Id:1; Subject: Square the circle; Status: Not Started; Priority: Low; StartDate: 2020-10-30; Due date: 2020-10-31 Id:2; Subject: Remove the rabble; Status: Not Started; Priority: Low; StartDate: 2020-10-30; Due date: 2020-11-20 Choose action (Add(a), Next(n), List(l),Detail(d), Edit(e),Remove(r), Quit(a): 2 Choose action (Add(a), Next{n},List(1),Detail(d), Edit(e),Remove(r), Quit(a): e Enter taskid: 2 Taskld not found... Taskid not found... Edit Task: Enter new subject or press enter to leave unchanged: Enter new due date (YYYY-MM-dd), or press enter to leave unchanged: Enter status abbreviation Not Started=n,Deferred=d, Waiting=w,Complete=c): Enter priority abbreviation Normal-n, Low=1,High=h, Urgent-u): Choose action (Add(a), Next(n), List(1),Detail(d), Edit(e), Remove(r), Quit(a): I Id:3; Subject: Drive the drivers; Status: Not Started; Priority: High; StartDate: 2020-10-30; Due date: 2020-11-15 Id:1; Subject: Square the circle; Status: Not Started; Priority: Low; StartDate: 2020-10-30; Due date: 2020-10-31 Id:2; Subject: Remove the rabble; Status: Waiting; Priority: Urgent; StartDate: 2020-10-30; Due date: 2020-11-20 Choose action (Add(a), Next(n), List(1),Detail(d), Edit(e), Remove(r), Quit(a): 9 Goodbye 1 2 3 4 5 6 7 import java.time. LocalDate; import java.time. format. DateTimeFormatter; import java.util.Iterator; import java.util.PriorityQueue; import java.util.Scanner; import java.lang. Integer; 8 9 enum Priority { URGENT, HIGH, NORMAL, LOW } 10 11 12 13 14 15 Venum Status { NOT_STARTED, IN_PROGRESS, WAITING, DEFERRED } 16 class Task implements Comparable { 17 18 19 20 21 22 23 24 25 26 27 28 29 int taskid; String subject; Priority priority; Status status; LocalDate startDate; LocalDate dueDate; public Task(int taskid, String subject, Priority priority, Status status, LocalDate startDate, LocalDate dueDate) { this.taskid - taskId; this.subject - subject; this.priority - priority; this.status = status; this.startDate - startDate; this.dueDate - du eDate; } 31 32 33 34 35 36 37 38 39 public int get TaskId { return taskid; } @Override public String toString() { return "Id:" + taskid + "; Subject: " + subject + "; status: " + status + "; Priority: " + priority + "; StartDate: + startDate.toString() + "; Due date: " + dueDate; } public Priority get Priority() { return priority; } @Override public int compareTo(Task task) { return this.getPriority().compareTo(task.getPriority(); } 41 42 43 44 45 46 47 48 49 50 51 52 53 > 54 55 56 57 58 59 60 61 62 63 ) public class ToDoListApplication { PriorityQueue Task> taskPriorityQueue = new PriorityQueue ); Scanner scanner = new Scanner(System.in); public static void main(String[] args) { TODOListApplication app = new ToDoListApplication(); app.test PriorityQueue(); } 65 66 67 public void displayNext Task() { // add your code here } 68 69 70 71 72 public void showTaskDetail(int taskId) { Task task = getTaskById(taskId); 1/ add your code here to print the task. } public Task get TaskById(int taskid) { 73 74 75 76 77 78 79 Iterator it = taskPriorityQueue.iterator(); while (((Iterator) it).hasNext()) { Task task - (Task) it.next(); if (task.getTaskId() == taskid) return task; System.out.println("Taskid not found..."); } return null; 81 82 83 84 } 85 86 87 public void removeTask (int taskId) { // Add your code here } 89 90 91 public void testPriorityQueue() { System.out.println("Welcome to My Task List "); do { System.out.println("Choose action (Add(a), Next(n), List(1), Detail(d), Edit(e), Remove(r), Quit(9):"); 92 93 94 String menuItem = scanner.nextLine(); 95 96 97 98 99 100 101 102 103 184 105 106 107 108 switch (menuItem) { case "a": addTask(); break; case "n": displayNext Task(); break; case "1": showTaskSummaryList(); break; Case "d": System.out.println("Enter taskId: "); int taskId = Integer.parseInt(scanner.nextLine(); showTaskDetail(taskId); break; case "r": System.out.println("Enter taskId: "); taskId = Integer.parseInt(scanner.nextLine()); removeTask (taskId); break; case "q" : break; } } while (true); 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 } void showTask SummaryList() { for (Task task : taskPriorityQueue) System.out.println(task); } 124 125 private Priority scanFor Priority { Priority priority - Priority.NORMAL; 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; } return priority; } 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 void addTask ) { System.out.println("Adding new Task..."); System.out.println("Enter subject:"); Scanner scanner = new Scanner(System.in); String subject = scanner.nextLine(); System.out.println("Enter due date (YYYY-MM-dd):"); String input = scanner.nextLine(); DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd"); LocalDate dueDate = LocalDate.parse(input); Priority priority = scanFor Priority(); Status status = Status. NOT_STARTED; LocalDate date = LocalDate.now(); LocalDate startDate = LocalDate.now(); Task task = new Task(taskPriorityQueue.size() + 1, subject, priority, status, startDate, dueDate); taskPriorityQueue.add(task); Sample Output Welcome to My Task List Choose action (Add(a), Next{n}, List(1), Detail(d), Edit(e),Remove(r), Quit(a): a Adding new Task... Enter subject: Square the circle Enter due date (yyyy-MM-dd): 2020-11-31 Date format exception. Try again. Enter due date (YYYY-MM-dd): 2020-10-31 Enter priority abbreviation Normal=n, Low=1,High=h, Urgent=u): I Choose action (Add(a), Next{n}, List(1), Detail(d), Edit(e),Remove(r), Quit(a): a Adding new Task... Enter subject: Remove the rubble Enter due date (YYYY-MM-dd): 2020-11-20 Enter priority abbreviation Normal=n,Low=l,High=h, Urgent=u): n Choose action (Add(a), Next(n), List(1),Detail(d), Edit(e), Remove(r), Quit(q): a Adding new Task... Enter subject: Drive the drivers Enter due date (yyyy-MM-dd): 2020-11-15 Enter priority abbreviation Normal=n,Low=1,High=h, Urgent-u): h Choose action (Add(a), Next(n), List(1),Detail(d), Edit(e), Remove(r), Quit(a): a Adding new Task... Enter subject: Circle the square Enter due date (yyyy-MM-dd): 2021-11-05 Enter priority abbreviation Normal=n, Low=1,High=h, Urgent=u): u Choose action (Add(a), Next{n}, List(I),Detail(d), Edit(e), Remove(r), Quit(g): 1 Id:4; Subject: Circle the square; Status: Not Started; Priority: Urgent; StartDate: 2020-10-30; Due date: 2021-11-05 Id:3; Subject: Drive the drivers; Status: Not Started; Priority: High; StartDate: 2020-10-30; Due date: 2020-11-15 Id:2; Subject: Remove the rubble; Status: Not Started; Priority: Normal; StartDate: 2020-10-30; Due date: 2020-11-20 Id:1; Subject: Square the circle; Status: Not Started; Priority: Low; StartDate: 2020-10-30; Due date: 2020-10-31 Choose action (Add(a), Next{n},List(1),Detail(d), Edit(e), Remove(r),Quit(a): n Id:4; Subject: Circle the square; Status: Not Started; Priority: Urgent; StartDate: 2020-10-30; Due date: 2021-11-05 Is this task complete? y: Y Choose action (Add(a), Next{n}, List(1),Detail(d), Edit(e), Remnove(r),Quit(g): 1 Id:3; Subject: Drive the drivers; Status: Not Started; Priority: High; StartDate: 2020-10-30; Due date: 2020-11-15 Id:1; Subject: Square the circle; Status: Not Started; Priority: Low; StartDate: 2020-10-30; Due date: 2020-10-31 Id:2; Subject: Remove the rubble; Status: Not Started; Priority: Normal; StartDate: 2020-10-30; Due date: 2020-11-20 Choose action (Add(a), Next{n}, List(1), Detail(d), Edit(e),Remove(r), Quit(a): e Enter taskld: 2 Taskid not found... Taskid not found... Edit Task: Enter new subject or press enter to leave unchanged: Remove the rabble Enter new due date (yyyy-MM-dd), or press enter to leave unchanged: Enter status abbreviation Not Started-n,Deferred=d, Waiting=w,Complete-c): u Enter priority abbreviation Normal=n,Low=l,High=h, Urgent=u): I Choose action (Add(a),Next(n), List(1),Detail(d), Edit(e), Remnove(r),Quit(a): 1 Id:3; Subject: Drive the drivers; Status: Not Started; Priority: High; StartDate: 2020-10-30; Due date: 2020-11-15 Id:1; Subject: Square the circle; Status: Not Started; Priority: Low; StartDate: 2020-10-30; Due date: 2020-10-31 Id:2; Subject: Remove the rabble; Status: Not Started; Priority: Low; StartDate: 2020-10-30; Due date: 2020-11-20 Choose action (Add(a), Next(n), List(l),Detail(d), Edit(e),Remove(r), Quit(a): 2 Choose action (Add(a), Next{n},List(1),Detail(d), Edit(e),Remove(r), Quit(a): e Enter taskid: 2 Taskld not found... Taskid not found... Edit Task: Enter new subject or press enter to leave unchanged: Enter new due date (YYYY-MM-dd), or press enter to leave unchanged: Enter status abbreviation Not Started=n,Deferred=d, Waiting=w,Complete=c): Enter priority abbreviation Normal-n, Low=1,High=h, Urgent-u): Choose action (Add(a), Next(n), List(1),Detail(d), Edit(e), Remove(r), Quit(a): I Id:3; Subject: Drive the drivers; Status: Not Started; Priority: High; StartDate: 2020-10-30; Due date: 2020-11-15 Id:1; Subject: Square the circle; Status: Not Started; Priority: Low; StartDate: 2020-10-30; Due date: 2020-10-31 Id:2; Subject: Remove the rabble; Status: Waiting; Priority: Urgent; StartDate: 2020-10-30; Due date: 2020-11-20 Choose action (Add(a), Next(n), List(1),Detail(d), Edit(e), Remove(r), Quit(a): 9 Goodbye

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