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

Design a Java interface called Priority that includes two methods: setPriority a

ID: 3535380 • Letter: D

Question

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 to-do list) that implements the Priority interface. Create a driver class to exercise some Task objects.


Here is the code from the above program:


public interface Priority
{
public void setPriority(int level);
public int getPriority();
}

public class Task implements Priority
{
private String msg, priority;
private int level;

//-----------------------------------------------------
// Constructor: Creates a task and a priority level.
//-----------------------------------------------------
public Task ()
{
this.msg = msg;
this.level = level;

if (level == 1)
priority = "Critical";
if (level == 2)
priority = "Very Important";
if (level == 3)
priority = "Normal";
if (level == 4)
priority = "Low";
if (level == 5)
priority = "Not Important";
}

public Task(String string, int i) {
// TODO Auto-generated constructor stub
}

//-----------------------------------------------------
// Sets the priority level.
//-----------------------------------------------------
public void setPriority (int level)
{
this.level = level;

if (level == 1)
priority = "Critical";
if (level == 2)
priority = "Very Important";
if (level == 3)
priority = "Normal";
if (level == 4)
priority = "Low";
if (level == 5)
priority = "Not Important";
}

//-----------------------------------------------------
// Returns the priority level.
//-----------------------------------------------------
public int getPriority()
{
return level;
}

//-----------------------------------------------------
// Returns a description of the task object.
//-----------------------------------------------------
public String toString()
{
return msg + " " + "Priority Level: " + level + " " + priority;
}

public void setmassage(String string) {
// TODO Auto-generated method stub

}
}


public class main_imp{
public static void main(String arg[]){
Task Task("one",3);
Task two = new Task();
two.setPriority (1);
two.setmassage ("two");
System.out.println(one.toString());
System.out.println(two.toString());
}


}








****I JUST NEED THE CODE FOR THE BOTTOM PROGRAM***


Modify the Task class 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.

Explanation / Answer

public class Task implements Priority

{

private String msg, priority;

private int level;



//-----------------------------------------------------

// Constructor: Creates a task and a priority level.

//-----------------------------------------------------

public Task (String msg, int level)

{

this.msg = msg;

this.level = level;



if (level == 1)

priority = "Critical";

if (level == 2)

priority = "Very Important";

if (level == 3)

priority = "Normal";

if (level == 4)

priority = "Low";

if (level == 5)

priority = "Not Important";

}



//-----------------------------------------------------

// Sets the priority level.

//-----------------------------------------------------

public void setPriority (int level)

{

this.level = level;


if (level == 1)

priority = "Critical";

if (level == 2)

priority = "Very Important";

if (level == 3)

priority = "Normal";

if (level == 4)

priority = "Low";

if (level == 5)

priority = "Not Important";

}



//-----------------------------------------------------

// Returns the priority level.

//-----------------------------------------------------

public int getPriority()

{

return level;

}



//-----------------------------------------------------

// Returns a description of the task object.

//-----------------------------------------------------

public String toString()

{

return msg + " " + "Priority Level: " + level + " " + priority;

}

}



Please rate it********************************