Skip to content

Commit

Permalink
Level-6 added ability to delete tasks.
Browse files Browse the repository at this point in the history
  • Loading branch information
qwertybox123 committed Aug 30, 2023
1 parent 3cc2ddc commit 109de24
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import java.util.Scanner;
import java.util.ArrayList;

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

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

System.out.println("Got it. I've added this deadline:");
System.out.println(" " + deadlineTask);
System.out.println("Now you have " + tasksList.size() + " tasks in the list");
System.out.println("Now you have " + tasksList.size() + " tasks in the list.");
} else {
System.out.println("Invalid input format for deadline command.");
}
Expand Down Expand Up @@ -114,19 +113,30 @@ public static void main(String[] args) {
// Print confirmation message
System.out.println("Got it. I've added this task:");
System.out.println(" " + eventTask);
System.out.println("Now you have " + tasksList.size() + " tasks in the list");
System.out.println("Now you have " + tasksList.size() + " tasks in the list.");
} else {
System.out.println("Invalid input format for event command.");
}
}
} else if (command.startsWith("delete")) {
int taskNumber = Integer.parseInt(command.substring(7)) - 1;
if (taskNumber < tasksList.size()) {
Tasks task = tasksList.get(taskNumber);
tasksList.remove(taskNumber);

System.out.println("Noted. I've removed this task: \n" + " " + task);
System.out.println("Now you have " + tasksList.size() + " tasks in the list.");
}



} else {
try {
throw new UnknownInputException();
} catch (UnknownInputException e) {
System.out.println(e.getMessage());
}
}

}
}
}

0 comments on commit 109de24

Please sign in to comment.