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

ToDoItem is a class that represents a task that needs to be done. A has a descri

ID: 3638267 • Letter: T

Question

ToDoItem is a class that represents a task that needs to be done.
A has a description, priority, category and dueDate. These instance variables are described in more detail below.
Description and category should be of type String. The description should never be empty and it should probably be fairly short for display purposes. You should provide a String constant, UNFILED or NONE perhaps, to be applied to objects that haven't been given a category. Provide a javadoc comment for your public constant.
Priority should be a number between 0 and 9 where 9 is the highest priority and zero is the lowest. that aren't given a priority will automatically have a priority of 0 because of the way Java initializes instance variables. No should have a priority that is not in this range. This should be explained in the documentation. You should assign a priority of zero if a user enters a priority that is outside this range.
Can you write a ToDoItem that has a priority?

Explanation / Answer


public class ToDoItem {
    /* If description is empty, assign UNFILED constant to description */

    private final String UNFILED = "Default";
    private String desciption;
    private String category;
    /* Automatically initiates priority instance varaible to 0 when object initiated.*/
    private int priority;
    private String dueDate;

    ToDoItem(String description, String category, String date, int priority) {
        if (this.category == null) {
            this.category = UNFILED;
        } else {
            this.category = category;
        }
        this.desciption = description;
        this.dueDate = date;
        this.priority = priority;

    }

    public static ToDoItem inputTodoItem(java.util.Scanner input) {

        String description = null, category = null, date = null;
        int priority = -1;

        System.out.print("Enter Description : ");
        description = input.nextLine();
        while (description.length() < 1) {
            System.out.print("Enter Description (cannot be empty): ");
            description = input.nextLine();
        }

        System.out.print("Enter Category    : ");
        category = input.nextLine();
        System.out.print("Enter Date        : ");
        date = input.nextLine();
        while (priority < 0 || priority > 9) {
            try {
                System.out.print("Enter Priority    : ");
                priority = Integer.parseInt(input.nextLine());
            } catch (NumberFormatException e) {
                System.out.println("Priority out of range");
            }
        }
        return new ToDoItem(description, category, date, priority);
    }

    public static void main(String args[]) {
        ToDoItem item = ToDoItem.inputTodoItem(new java.util.Scanner(System.in));

        System.out.println();
        System.out.println("Description : " + item.desciption);
        System.out.println("Category    : " + item.category);
        System.out.println("Due Date    : " + item.dueDate);
        System.out.println("Priority    : " + item.priority);
    }
}
public class ToDoItem {
    /* If description is empty, assign UNFILED constant to description */

    private final String UNFILED = "Default";
    private String desciption;
    private String category;
    /* Automatically initiates priority instance varaible to 0 when object initiated.*/
    private int priority;
    private String dueDate;

    ToDoItem(String description, String category, String date, int priority) {
        if (this.category == null) {
            this.category = UNFILED;
        } else {
            this.category = category;
        }
        this.desciption = description;
        this.dueDate = date;
        this.priority = priority;

    }

    public static ToDoItem inputTodoItem(java.util.Scanner input) {

        String description = null, category = null, date = null;
        int priority = -1;

        System.out.print("Enter Description : ");
        description = input.nextLine();
        while (description.length() < 1) {
            System.out.print("Enter Description (cannot be empty): ");
            description = input.nextLine();
        }

        System.out.print("Enter Category    : ");
        category = input.nextLine();
        System.out.print("Enter Date        : ");
        date = input.nextLine();
        while (priority < 0 || priority > 9) {
            try {
                System.out.print("Enter Priority    : ");
                priority = Integer.parseInt(input.nextLine());
            } catch (NumberFormatException e) {
                System.out.println("Priority out of range");
            }
        }
        return new ToDoItem(description, category, date, priority);
    }

    public static void main(String args[]) {
        ToDoItem item = ToDoItem.inputTodoItem(new java.util.Scanner(System.in));

        System.out.println();
        System.out.println("Description : " + item.desciption);
        System.out.println("Category    : " + item.category);
        System.out.println("Due Date    : " + item.dueDate);
        System.out.println("Priority    : " + item.priority);
    }
}
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