diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index 78d35bb6ea..d716cda35c 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -35,6 +35,17 @@ public void printDeadlineTask() { "\n\t____________________________________________________________"); } + @Override + public void printDelete() { + int newTotalNumOfTasks = super.totalNumOfTasks - 1; + System.out.println("\t____________________________________________________________" + + "\n\t Noted. I've removed this task:" + + "\n\t " + this.taskType + + super.getTaskStatus() + " " + super.task + " (by: " + this.taskDeadline + ")" + + "\n\t Now you have " + newTotalNumOfTasks + " tasks in the list." + + "\n\t____________________________________________________________"); + } + @Override public String getTaskType() { return this.taskType; diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index ee8f86c51c..c2dfb2dfb8 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -113,6 +113,14 @@ public void chatDuke() { taskName, eventStartTime, eventEndTime, allTasks.size() + 1); allTasks.add(event); event.printEventTask(); + } else if (command.startsWith("delete")) { + missingIndexException(command); + invalidIndexException(command, allTasks.size()); + String[] str = command.split(" "); + int taskIndex = Integer.parseInt(str[1]) - 1; + Task task = allTasks.get(taskIndex); + task.printDelete(); + allTasks.remove(taskIndex); } else if (command.equals("bye")){ saidBye = true; this.printByeMessage(); @@ -121,6 +129,10 @@ public void chatDuke() { } } catch (DukeException d) { System.out.println(d.getMessage()); + } catch (NumberFormatException nfe) { + System.out.println("\t____________________________________________________________" + + "\n\t ☹ OOPS!!! The task index to delete or un/mark a task cannot be a non-integer." + + "\n\t____________________________________________________________"); } } } @@ -153,12 +165,6 @@ public void printCommandList(List allTasks) { System.out.println("\t____________________________________________________________"); } - public void echoCommand(String command) { - System.out.println("\t____________________________________________________________" + - "\n\t" + " added: " + command + - "\n\t____________________________________________________________"); - } - public void printByeMessage() { System.out.println("\t____________________________________________________________" + "\n\t Bye. Hope to see you again soon!" + @@ -207,24 +213,29 @@ public void missingIndexException(String command) throws DukeException { throw new DukeException("\t____________________________________________________________" + "\n\t ☹ OOPS!!! The task index to unmark a task as not done cannot be empty." + "\n\t____________________________________________________________"); + } else if (command.equals("delete")) { + throw new DukeException("\t____________________________________________________________" + + "\n\t ☹ OOPS!!! The task index to delete a task as not done cannot be empty." + + "\n\t____________________________________________________________"); } } public void invalidIndexException(String command, int taskSize) throws DukeException { - if (command.startsWith("mark") || command.startsWith("unmark")) { + if (command.startsWith("mark") || command.startsWith("unmark") + ||command.startsWith("delete")) { String index = command.split(" ")[1]; int index1 = Integer.parseInt(index); if (index1 <= 0) { throw new DukeException("\t____________________________________________________________" + - "\n\t ☹ OOPS!!! The task index to mark a task as done cannot be zero or less." + + "\n\t ☹ OOPS!!! The task index to delete or un/mark a task cannot be zero or less." + "\n\t____________________________________________________________"); } else if (index.equals("")) { throw new DukeException("\t____________________________________________________________" + - "\n\t ☹ OOPS!!! The task index to mark a task as done cannot be empty." + + "\n\t ☹ OOPS!!! The task index to delete or un/mark a task cannot be empty." + "\n\t____________________________________________________________"); } else if (index1 > taskSize) { throw new DukeException("\t____________________________________________________________" + - "\n\t ☹ OOPS!!! The task index to mark a task as done cannot be more than" + + "\n\t ☹ OOPS!!! The task index to delete or un/mark a task cannot be more than" + " number of tasks." + "\n\t____________________________________________________________"); } @@ -240,5 +251,4 @@ public void invalidCommandException(String command) throws DukeException { "\n\t____________________________________________________________"); } } - } diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 5cccac5f18..d44e27f90f 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -40,6 +40,18 @@ public void printEventTask() { "\n\t____________________________________________________________"); } + @Override + public void printDelete() { + int newTotalNumOfTasks = super.totalNumOfTasks - 1; + System.out.println("\t____________________________________________________________" + + "\n\t Noted. I've removed this task:" + + "\n\t " + this.taskType + + super.getTaskStatus() + " " + super.task + " (from: " + this.eventStartTime + + " to: " + this.eventEndTime + ")" + "\n\t Now you have " + + newTotalNumOfTasks + " tasks in the list." + + "\n\t____________________________________________________________"); + } + @Override public String getTaskType() { return this.taskType; diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 67fe31eb73..a1ad12f110 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -1,5 +1,3 @@ -import java.util.Objects; - public class Task { protected final int taskNumber; protected final boolean taskStatus; @@ -27,6 +25,13 @@ public void unmarkAsUndone() { "\n\t____________________________________________________________"); } + public void printDelete() { + System.out.println("\t____________________________________________________________" + + "\n\t Noted. I've removed this task:" + "\n\t " + + this.getTaskStatus() + " " + this.task + + "\n\t Now you have " + this.totalNumOfTasks + " tasks in the list."); + } + public int getTaskNumber() { return this.taskNumber; } diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java index 76a278d393..2f2e4e8fb6 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/Todo.java @@ -6,6 +6,7 @@ class Todo extends Task { this.taskType = "[T]"; } + @Override public void markAsDone() { System.out.println("\t____________________________________________________________" + "\n\t Nice! I've marked this task as done:\n" + @@ -13,6 +14,7 @@ public void markAsDone() { "\n\t____________________________________________________________"); } + @Override public void unmarkAsUndone() { System.out.println("\t____________________________________________________________" + "\n\t OK, I've marked this task as not done yet:\n" + @@ -28,6 +30,16 @@ public void printToDoTask() { "\n\t____________________________________________________________"); } + @Override + public void printDelete() { + int newTotalNumOfTasks = super.totalNumOfTasks - 1; + System.out.println("\t____________________________________________________________" + + "\n\t Noted. I've removed this task:" + "\n\t " + this.taskType + + super.getTaskStatus() + " " + super.task + + "\n\t Now you have " + newTotalNumOfTasks + " tasks in the list." + + "\n\t____________________________________________________________"); + } + @Override public String getTaskType() { return this.taskType;