Source of Activity.java


  1: //Activity.java

  3: class Activity
  4: {
  5:     public String name;
  6:     public int startTime;  // start hour in the range [0, 23]
  7:     public int finishTime; // finish hour in the range [0, 23]

  9:     public Activity
 10:     (
 11:         String activityName,
 12:         int initialStartTime,
 13:         int initialFinishTime
 14:     )
 15:     {
 16:         name = activityName;
 17:         startTime = initialStartTime;
 18:         finishTime = initialFinishTime;
 19:     }

 21:     public boolean conflictsWith(Activity otherActivity)
 22:     {
 23:         // No conflict exists if this activity's finishTime comes
 24:         // at or before the other activity's startTime
 25:         if (finishTime <= otherActivity.startTime)
 26:         {
 27:             return false;
 28:         }

 30:         // No conflict exists if the other activity's finishTime
 31:         // comes at or before this activity's startTime
 32:         else if (otherActivity.finishTime <= startTime)
 33:         {
 34:             return false;
 35:         }

 37:         // In all other cases the two activities conflict with each other
 38:         return true;
 39:     }
 40: }