4 Replies Latest reply on Dec 12, 2008 6:18 AM by 843785

    can someone check my interface class?

    843785
      Design a Java interface called priority that has two methods: setPriority and getPriority. the interface should let us number a set of objects in the order of their importance. Design and implement a class called Task that implements the Priority interface. Create a driver class to use some Task objects.

      Is my work right?
      public interface Priority 
      {
          public void setPriority (int priority);
          public int getPriority();    
          
      }
      public class Task implements Priority 
      {
              
          private String myTask;
          private int myPriority;
          
          public Task (String chore, int level) 
          {
              myTask = chore;     
              myPriority = level;
          }
          
          public void setPriority (int level)
          {
              myPriority = level;
          }
          
          public int getPriority()
          {
              return myPriority;
          }
      
          public String getTask()
          {
              return myTask;
          }
          
          public String toString()
          {
              return ("Task: " + myTask + "\tPriority: " + myPriority);
          }
      }
      public class TaskDriver 
      {
              
          public static void main(String[] args) 
          {
              Task task1 = new Task ("Do homework", 1);
              Task task2 = new Task ("Sleep", 2);
              System.out.println(task1);
              System.out.println(task2);
          }
      }
      Output is:
      Task: Do homework Priority: 1
      Task: Sleep Priority: 2

      Process completed.

      Edited by: steveo0 on Dec 11, 2008 9:51 PM