Which I've done here:
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 (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 + "\t" + "Priority Level: " + level + "\t" + priority;
}
}
This is no problem. However, now I have to do this: Modify the task class from the previous problem 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 feature of task objects.
I understand that compareTo will return either -1, 0 or 1. I just don't understand how to sort them once they've been compared and how to print them ranked by priority. Thanks for any help :)
Edited by vctrshowalter, 08 December 2011 - 09:45 AM.


Sign In
Create Account

Back to top









