Skip to content

Commit 109de24

Browse files
committed
Level-6 added ability to delete tasks.
1 parent 3cc2ddc commit 109de24

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/main/java/Duke.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import java.util.Scanner;
32
import java.util.ArrayList;
43

@@ -54,7 +53,7 @@ public static void main(String[] args) {
5453

5554
System.out.println("Got it. I've added this task:");
5655
System.out.println(" " + todo);
57-
System.out.println("Now you have " + tasksList.size() + " tasks in the list");
56+
System.out.println("Now you have " + tasksList.size() + " tasks in the list.");
5857
} catch (EmptyTodoException e) {
5958
System.out.println(e.getMessage());
6059
}
@@ -82,7 +81,7 @@ public static void main(String[] args) {
8281

8382
System.out.println("Got it. I've added this deadline:");
8483
System.out.println(" " + deadlineTask);
85-
System.out.println("Now you have " + tasksList.size() + " tasks in the list");
84+
System.out.println("Now you have " + tasksList.size() + " tasks in the list.");
8685
} else {
8786
System.out.println("Invalid input format for deadline command.");
8887
}
@@ -114,19 +113,30 @@ public static void main(String[] args) {
114113
// Print confirmation message
115114
System.out.println("Got it. I've added this task:");
116115
System.out.println(" " + eventTask);
117-
System.out.println("Now you have " + tasksList.size() + " tasks in the list");
116+
System.out.println("Now you have " + tasksList.size() + " tasks in the list.");
118117
} else {
119118
System.out.println("Invalid input format for event command.");
120119
}
121120
}
121+
} else if (command.startsWith("delete")) {
122+
int taskNumber = Integer.parseInt(command.substring(7)) - 1;
123+
if (taskNumber < tasksList.size()) {
124+
Tasks task = tasksList.get(taskNumber);
125+
tasksList.remove(taskNumber);
126+
127+
System.out.println("Noted. I've removed this task: \n" + " " + task);
128+
System.out.println("Now you have " + tasksList.size() + " tasks in the list.");
129+
}
130+
131+
132+
122133
} else {
123134
try {
124135
throw new UnknownInputException();
125136
} catch (UnknownInputException e) {
126137
System.out.println(e.getMessage());
127138
}
128139
}
129-
130140
}
131141
}
132142
}

0 commit comments

Comments
 (0)