Question: A java question. In this problem you will do a better implementation of the to do list. Write a class ToDoList that maintains a priority

A java question. In this problem you will do a better implementation of the to do list. Write a class ToDoList that maintains a priority queue to manage the items to be done.

Write a class ToDoItem. ToDoItem has a description and a priority. The constructor takes these as parameters in that order.

ToDoItem implements Comparable interface and has these methods:

1. get methods(accessors) for priority and description

2. equals method. Two items are equal if and only if they have both the same priority and description

3. compareTo method orders by priority. If priorities are equal, order by description.

4. toString returns a String representation of the ToDoItem in this format:(!!!)

ToDoItem[description=see friends,priority=1] 

Write the class ToDoList. Its constructor initializes an empty PriorityQueue.

ToDoList has these methods:

1). public void add(ToDoItem item) Adds an item for this ToDoList

2). public ToDoItem nextItem() removes and returns the next item to do. (The one with the priority closest to 1). Note that this also violates the rule about mutators not returning values

3). public boolean hasNext() returns true if there is at least one item left to do otherwise false

4). public ToDoItem peek() returns the next item to do but does not remove it from the list

Please show the full code and your output, and please separate "ToDoRunner.java", "ToDoItem.java", and "ToDoList.java" as three files. Thank you!

-------------------------------------------------------------------------------------------------

The ToDoRunner is given as follow:

ToDoRunner.java

public class ToDoRunner { public static void main(String[] args) { ToDoList todo = new ToDoList(); todo.add(new ToDoItem("sleep", 12)); todo.add(new ToDoItem("study", 3)); todo.add(new ToDoItem("see friends", 1)); todo.add(new ToDoItem("eat", 5)); todo.add(new ToDoItem("watch a movie", 4)); todo.add(new ToDoItem("eat", 5)); todo.add(new ToDoItem("see a movie", 3)); System.out.println("hasNext: " + todo.hasNext()); System.out.println("peek when queue has an item: " + todo.peek()); //remove and print System.out.println("Remove all items and print:"); while(todo.hasNext()) { System.out.println(todo.nextItem()); } System.out.println("peek when queue is empty: " + todo.peek()); System.out.println("hasNext: " + todo.hasNext()); } } 

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!