Project management system

Report a typo

We're writing a project management system with the ability to delegate the responsibility for task tracking.

We have already finished the TaskTracker interface, which contains the following functions:

  • addTask(task: String) – adds a task to the list.
  • completeTask(task: String) – marks a task as completed.
  • getTasks() – gets the list of outstanding tasks.
  • getCompletedTasks() – gets the list of completed tasks.

We've also written the SimpleTaskTracker class, which implements the TaskTracker interface. This class will track tasks using internal lists to store outstanding and completed tasks.

While writing the Project class, which uses class delegation to manage tasks, one of the programmers made an error, and your task is to fix the error for the correct operation of the program.

Write a program in Kotlin
interface TaskTracker {
fun addTask(task: String)
fun completeTask(task: String)
fun getTasks(): List<String>
fun getCompletedTasks(): List<String>
}

class SimpleTaskTracker : TaskTracker {
private val tasks = mutableListOf<String>()
private val completedTasks = mutableListOf<String>()

override fun addTask(task: String) {
tasks.add(task)
}

override fun completeTask(task: String) {
if (tasks.remove(task)) {
completedTasks.add(task)
} else {
println("Task not found.")
}
}

override fun getTasks(): List<String> = tasks
override fun getCompletedTasks(): List<String> = completedTasks
}
// fix the error here
class Project(taskTracker: SimpleTaskTracker)
___

Create a free account to access the full topic