-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToDoList.java
More file actions
88 lines (76 loc) · 2.58 KB
/
ToDoList.java
File metadata and controls
88 lines (76 loc) · 2.58 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// ToDoList.java
import java.util.ArrayList;
import java.util.Scanner;
public class ToDoList {
private static class Tache {
String description;
boolean réalisée;
Tache(String description) {
this.description = description;
this.réalisée = false;
}
@Override
public String toString() {
return (réalisée ? "[Done] " : "[ ] ") + description;
}
}
private final ArrayList<Tache> taches = new ArrayList<>();
private final Scanner scanner = new Scanner(System.in);
private void ajouterTache(String description) {
taches.add(new Tache(description));
System.out.println("Done Tâche ajoutée !");
}
private void afficherTaches() {
if (taches.isEmpty()) {
System.out.println("Aucune tâche pour le moment.");
return;
}
System.out.println("\n--- Ma To-Do List ---");
for (int i = 0; i < taches.size(); i++) {
System.out.println((i + 1) + ". " + taches.get(i));
}
System.out.println();
}
private void terminerTache(int index) {
if (index >= 1 && index <= taches.size()) {
taches.get(index - 1).réalisée = true;
System.out.println("Done Tâche terminée !");
} else {
System.out.println("Numéro invalide.");
}
}
private void menu() {
while (true) {
System.out.println("1. Ajouter une tâche");
System.out.println("2. Voir les tâches");
System.out.println("3. Terminer une tâche");
System.out.println("4. Quitter");
System.out.print("Choisis une option : ");
int choix = scanner.nextInt();
scanner.nextLine();
switch (choix) {
case 1 -> {
System.out.print("Description : ");
ajouterTache(scanner.nextLine());
}
case 2 -> afficherTaches();
case 3 -> {
afficherTaches();
System.out.print("Numéro à terminer : ");
terminerTache(scanner.nextInt());
}
case 4 -> {
System.out.println("À bientôt !");
scanner.close();
return;
}
default -> System.out.println("Option invalide.");
}
System.out.println();
}
}
// Point d'entrée
public static void main(String[] args) {
new ToDoList().menu();
}
}