Advertisement
Lirbo

TaskManager

Jan 16th, 2023
562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.27 KB | None | 0 0
  1. public class Task
  2.         {
  3.             private string title;
  4.             private int priority;
  5.             private bool isComplete;
  6.             public Task(string title, int priority, bool isComplete)
  7.             {
  8.                 this.title = title;
  9.                 this.priority = priority;
  10.                 this.isComplete = isComplete;
  11.             }
  12.             public string GetTitle() { return title; }
  13.             public int GetPriority() { return priority; }
  14.             public bool GetIsComplete() { return isComplete; }
  15.             public void SetTitle(string title) { this.title = title; }
  16.             public void SetPriority(int priority) { this.priority = priority; }
  17.             public void SetIsComplete(bool isComplete) { this.isComplete = isComplete; }
  18.             public bool DoIt()
  19.             {
  20.                 if (!isComplete)
  21.                 {
  22.                     isComplete = true;
  23.                     return true;
  24.                 }
  25.                 else return false;
  26.             }
  27.         }
  28.  
  29.         public class TaskManager
  30.         {
  31.             private Task[] tasks;
  32.             private int numOfTasks;
  33.             public TaskManager()
  34.             {
  35.                 tasks = new Task[100];
  36.                 numOfTasks = 0;
  37.             }
  38.             public int ImportantTask()
  39.             {
  40.                 int importantTask = -1;
  41.                 int maxPriority = -1;
  42.                 for(int i = 0; i < numOfTasks; i++)
  43.                     if (tasks[i].GetIsComplete() && tasks[i].GetPriority() > maxPriority)
  44.                     {
  45.                         importantTask = i;
  46.                         maxPriority = tasks[i].GetPriority();
  47.                     }
  48.                 return importantTask;
  49.             }
  50.             public bool AddTask(Task task)
  51.             {
  52.                 if (numOfTasks >= tasks.Length - 1)
  53.                 {
  54.                     for(int i = 0; i < tasks.Length; i++)
  55.                         if (tasks[i].GetIsComplete())
  56.                         {
  57.                             tasks[i] = task;
  58.                             return true;
  59.                         }
  60.                     return false;
  61.                 }
  62.                 tasks[numOfTasks++] = task;
  63.                 return true;
  64.             }
  65.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement