Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program in Java that: 1. will prompt user with a menu that contains opti

ID: 3798151 • Letter: W

Question

Write a program in Java that:

1. will prompt user with a menu that contains options to:

a. Add a To-Do Item to a todo list. A To-Do Item contains:

i. An arbitrary reference number (4; 44,004; etc.)

ii. A text description of the item ("Pick up dry cleaning", etc.)

iii. A priority level (1, 2, 3, 4, or 5)

b. View an item in the list (based on its reference number)

c. Delete an item from the list (based on its reference number)

d. Display all items in the list, sorted by reference number

e. Display all items in the list, sorted by priority level

2. Program must be implemented in an object-oriented fashion. You must create 2 classes:

a. A To-Do List class that stores the list itself, and has all the methods in it needed to interact with the list. All methods for adding, deleting, sorting, and viewing the list must be implemented in this class, not in main().

b. A To-Do Item class that contains the reference number, text, and priority, and any other methods as needed.

3. You may use any method you like to actually store the data, but I would humbly suggest that an ArrayList might be a good way.

4. You must use try … catch statements to check user input and catch common errors. Your program should not crash because of bad user input at any point. .

Explanation / Answer

ToDO.java

public class ToDo implements Comparable<ToDo> {
   private int referenceNumber;
   private String description;
   private int priority;

   public ToDo(int referenceNumber, String description, int priority) {
       super();
       this.referenceNumber = referenceNumber;
       this.description = description;
       this.priority = priority;
   }

   public int getReferenceNumber() {
       return referenceNumber;
   }

   public void setReferenceNumber(int referenceNumber) {
       this.referenceNumber = referenceNumber;
   }

   public String getDescription() {
       return description;
   }

   public void setDescription(String description) {
       this.description = description;
   }

   public int getPriority() {
       return priority;
   }

   public void setPriority(int priority) {
       this.priority = priority;
   }

   @Override
   public String toString() {
       return "ToDo [referenceNumber=" + referenceNumber + ", description=" + description + ", priority=" + priority
               + "]";
   }

   @Override
   public int compareTo(ToDo t) {
       if (priority == t.priority)
           return 0;
       else if (priority < t.priority)
           return 1;
       else
           return -1;
   }

}
=============================================================================================================
TodoList.java


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ToDOList {
   private static List<ToDo> tasks = new ArrayList<ToDo>();

   public static List<ToDo> getTasks() {
       return tasks;
   }

   public static void setTasks(List<ToDo> tasks) {
       ToDOList.tasks = tasks;
   }

   public ToDo getTODOByRefNum(int ref) {
       for (ToDo t : tasks) {
           if (t.getReferenceNumber() == ref) {
               return t;
           }
       }
       return null;
   }

   public void removeTODOByRefNum(int ref) {
       for (ToDo t : tasks) {
           if (t.getReferenceNumber() == ref) {
               tasks.remove(t);
           }
       }
   }

   public List<ToDo> getSortedToDoListByPriority() {
       Collections.sort(tasks);
       return tasks;
   }

   public void add(ToDo t) {
       tasks.add(t);

   }
}
===============================================================================
Main.java

import java.util.Scanner;

public class Main {

   public static void main(String[] args) {

       Scanner sc = new Scanner(System.in);
       int checkpoint;
       ToDOList tl = new ToDOList();
       try {
           do {

               options();
               checkpoint = sc.nextInt();

               switch (checkpoint) {
               case 1:
                   System.out.println(tl.getSortedToDoListByPriority());
                   break;
               case 2:
                   createToDo(sc, tl);
                   break;
               case 3:
                   System.out.println("Enter reference number to get ToDO");
                   int ref = sc.nextInt();
                   System.out.println(tl.getTODOByRefNum(ref));
                   break;
               case 4:
                   System.out.println(tl.getSortedToDoListByPriority());
                   break;
               case 5:
                   System.out.println("Enter reference number to remove ToDO");
                   int ref1 = sc.nextInt();
                   tl.removeTODOByRefNum(ref1);
                   break;
               }

           } while (checkpoint != 5);
       } catch (Exception e) {
           System.out.println("Invalid input");
       }
       sc.close();

   }

   public static void options() {

       System.out.println(" Enter the number of your choice");
       System.out.println(" 1. See all ToDo sorted by Reference Number");
       System.out.println(" 2. Enter new ToDO");
       System.out.println(" 3. Search ToDO by Reference Number");
       System.out.println(" 4. Remove ToDo by Reference Number");
       System.out.println(" 5. Exit");
   }

   public static void createToDo(Scanner sc, ToDOList tl) {
       System.out.print("Enter reference number: ");
       int referenceNumber = sc.nextInt();
       System.out.print("Enter Description");
       String description = sc.next();
       System.out.print("Enter Priority");
       int priority = sc.nextInt();

       ToDo t = new ToDo(referenceNumber, description, priority);
       tl.add(t);

   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote