-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToDoList.java
More file actions
55 lines (54 loc) · 1.46 KB
/
ToDoList.java
File metadata and controls
55 lines (54 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import java.util.ArrayList;
import java.util.List;
public class ToDoList{
private List<Task> tasks;
private int taskCounter;
public ToDoList(){
tasks = new ArrayList<>();
taskCounter = 1;
}
public void addTask(String description){
Task task = new Task(taskCounter++, description, false);
tasks.add(task);
System.out.println("Task added :"+ task);
}
public void listTasks(){
if(tasks.isEmpty()){
System.out.println("No tasks available.");
return;
}else{
for(Task task : tasks){
System.out.println(task);
}
}
}
public void markTaskCompleted(int id){
boolean found = false;
for(Task task : tasks){
if(task.getId() == id){
task.markCompleted();
System.out.println("Task marked as completed:" + task);
found = true;
break;
}
}
if(!found){
System.out.println("Task with id " + id + " not found.");
}
}
public void removeTask(int id){
Task toRemove = null;
for(Task task: tasks){
if(task.getId() == id){
toRemove = task;
break;
}
}
if(toRemove != null){
tasks.remove(toRemove);
System.out.println("Task removed successfully.");
}else{
System.out.println("Task with id" + id + " not found.");
}
}
}