Create a to do list that manages tasks in a list Implement i

Create a to do list that manages tasks in a list. Implement it using the LinkedList API. (You may import ArrayList or List, but please do not import any other packages.) See the ToDoListADT interface which contains a description of the methods required in the to do list (this must be used). Create a Task class that implements Comparable and contains the name of the task, the due date of the task (stored as a string, since we did not cover the Date class), the time that the task is due (also stored as a string), and an integer that indicates the importance of the task (1 being least important). Make getters and a compareTo method that passes in another Task and compares the importance level of the tasks. This method should compare the importance of the two tasks and return -1 if the first task has a higher level of importance than the second task, 0 if the length of the tasks is equal, and 1 if the first task has a lower level of importance than the second task.

All tasks are added into the to do list. The highest priority task in a to do list is the task with the highest level of importance. When removing tasks, your to do list should return the highest priority task. Tasks should be removed from the to do list when the task is completed.

static interface ToDoListADT {

        /**
         * Adds one task to the to do list.
         * @param t the task to be added to the to do list.
         */
        public void add(Task t);

        /**
         * Removes and returns the highest priority task in the to do list.
         * @return the highest priority task in the buffer.
         */
        public Task remove();

        /**
         * Returns true if this to do list contains no elements.
         * @return true if this to do list is empty
         */
        public boolean isEmpty();

        /**
         * Returns the number of elements in this to do list.
         * @return the integer representation of the size of the to do list.
         */
        public int size();
    }

    static class ToDoList implements ToDoListADT {
        //TODO: complete class
    }

    public static void main(String[] args) {
        ToDoList toDoList = new ToDoList();
        Task t1 = new Task(\"Unit 11 Programming Assignment\", \"02/26/2016\", \"11:59 PM\", 2);
        Task t2 = new Task(\"Mastering Physics: Chapter 5 Assignment\", \"02/24/2016\", \"11:59 PM\", 3);
        Task t3 = new Task(\"Dentist Appointment\", \"03/05/2017\", \"2:30PM\", 1);
        toDoList.add(t1);
        toDoList.add(t2);
        toDoList.add(t3);
        System.out.println(toDoList.remove());
        System.out.println(toDoList.remove());
        System.out.println(toDoList.remove());
    }

Solution

HI, Please find my implementation.

Please let me know in case of any issue.

############### Task.java ################

public class Task implements Comparable<Task> {

   // instance variables

   private String name;

   private String duedate;

   private String time;

   private int importance;

   // constructor

   public Task(String name, String duedate,String time, int importance) {

       this.name = name;

       this.duedate = duedate;

       this.time = time;

       this.importance = importance;

   }

   public String getName() {

       return name;

   }

   public String getDuedate() {

       return duedate;

   }

   public int getImportance() {

       return importance;

   }

   public void setName(String name) {

       this.name = name;

   }

   public void setDuedate(String duedate) {

       this.duedate = duedate;

   }

   public void setImportance(int importance) {

       this.importance = importance;

   }

   public String getTime() {

       return time;

   }

   public void setTime(String time) {

       this.time = time;

   }

   @Override

   public int compareTo(Task o) {

       if(importance > o.importance)

           return 1;

       else if(importance < o.importance)

           return -1;

       else

           return 0;

   }

  

   @Override

   public String toString() {

       return name+\" \"+duedate+\" \"+time+\" \"+importance;

   }

}

#################### ToDoListADT.java ################

import java.util.ArrayList;

public interface ToDoListADT {

   /**

   * Adds one task to the to do list.

   * @param t the task to be added to the to do list.

   */

   public void add(Task t);

   /**

   * Removes and returns the highest priority task in the to do list.

   * @return the highest priority task in the buffer.

   */

   public Task remove();

   /**

   * Returns true if this to do list contains no elements.

   * @return true if this to do list is empty

   */

   public boolean isEmpty();

   /**

   * Returns the number of elements in this to do list.

   * @return the integer representation of the size of the to do list.

   */

   public int size();

}

#################### ToDoList.java ################

class ToDoList implements ToDoListADT {

   // instance variable

   private ArrayList<Task> tasks;

  

   public ToDoList() {

       tasks = new ArrayList<>();

   }

#################### ToDoListTest.java ################

public class ToDoListTest {

   public static void main(String[] args) {

       ToDoList toDoList = new ToDoList();

       Task t1 = new Task(\"Unit 11 Programming Assignment\", \"02/26/2016\", \"11:59 PM\", 2);

       Task t2 = new Task(\"Mastering Physics: Chapter 5 Assignment\", \"02/24/2016\", \"11:59 PM\", 3);

       Task t3 = new Task(\"Dentist Appointment\", \"03/05/2017\", \"2:30PM\", 1);

       toDoList.add(t1);

       toDoList.add(t2);

       toDoList.add(t3);

       System.out.println(toDoList.remove());

       System.out.println(toDoList.remove());

       System.out.println(toDoList.remove());

   }

}

/*

Sample run:

Mastering Physics: Chapter 5 Assignment 02/24/2016 11:59 PM 3

Unit 11 Programming Assignment 02/26/2016 11:59 PM 2

Dentist Appointment 03/05/2017 2:30PM 1

*/

   @Override

   public void add(Task t) {

       tasks.add(t);

   }

   @Override

   public Task remove() {

       if(tasks.size() == 0)

           return null;

      

       int index = 0;

       for(int i=1; i<tasks.size(); i++){

           if(tasks.get(i).getImportance() > tasks.get(index).getImportance())

               index = i;

       }

      

       Task task = tasks.get(index);

       tasks.remove(index);

       return task;

   }

   @Override

   public boolean isEmpty() {

       return tasks.size() == 0;

   }

   @Override

   public int size() {

       return tasks.size();

   }

  

}

Create a to do list that manages tasks in a list. Implement it using the LinkedList API. (You may import ArrayList or List, but please do not import any other p
Create a to do list that manages tasks in a list. Implement it using the LinkedList API. (You may import ArrayList or List, but please do not import any other p
Create a to do list that manages tasks in a list. Implement it using the LinkedList API. (You may import ArrayList or List, but please do not import any other p
Create a to do list that manages tasks in a list. Implement it using the LinkedList API. (You may import ArrayList or List, but please do not import any other p
Create a to do list that manages tasks in a list. Implement it using the LinkedList API. (You may import ArrayList or List, but please do not import any other p
Create a to do list that manages tasks in a list. Implement it using the LinkedList API. (You may import ArrayList or List, but please do not import any other p

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site