Question: 1. Design a Java interface called Priority that includes two methods: setPriority and getPriority. The interface should define a way to establish numeric priority among
1. Design a Java interface called Priority that includes two methods: setPriority and getPriority. The interface should define a way to establish numeric priority among a set of objects. Design and implement a class called Task that represents a task (such as on a todo list) that implements the Priority interface. Create a driver class to exercise some Task objects
2. Modify the Task class from the project in question 1 so that it also implements the Comparable interface from the Java standard class library. Implement the interface such that the tasks are ranked by priority. Create a driver class whose main method shows these new features of Task objects.
Ive got the first one working but cant seem to figure out number 2. HELP IS NEEDED THANK YOU. please provide working program.
public interface Priority { //Setters & getters methods public void setPriority(int priority); public int getPriority(); int priority=1; //default number for a task } // end of priority interface
**************************************************************
public abstract class Task implements Priority {
String taskName; int priority; //Instance Variables
public Task(String taskName) { this.taskName = taskName; //sets priority = Priority.priority; //sets default of the task
} //default constructor public Task(String taskName, int priority) { this.taskName=taskName; //set task name setPriority(priority); //calling setPriority method } @Override public final void setPriority (int prior) { this.priority=prior; //method to set the priority number of the task } @Override public int getPriority() { return priority; //method that returns the priority number of the task } public String getTaskName() { return taskName; //method that returns the task } @Override public String toString() { String taskContent=""; taskContent="Task Name: "+getTaskName()+ " Priority Name: "+getPriority()+" "; return taskContent; } } **************************************************************
public class TaskDriver { public static void main(String[] args) { Task task1=new Task("Clean Room", 3) {}; Task task2=new Task("Make Bed") {}; Task task3=new Task("Eat Breakfast", 2) {}; //creates and instantiates task objects System.out.println(task1); System.out.println(task2); System.out.println(task3); } }
*********************************************** END PROGRAM.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
