diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 3fc7eec1b2..ed1a32e808 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -36,6 +36,10 @@ public static void main(String[] args) { int taskNo = Integer.parseInt(context); tasks.markDone(taskNo); + } else if (action.equalsIgnoreCase("delete")) { + String context = command_broken[1]; + int taskNo = Integer.parseInt(context); + tasks.removeTask(taskNo); } else if (action.equalsIgnoreCase(("deadline"))) { String context = command_broken[1]; diff --git a/src/main/java/UserText.java b/src/main/java/UserText.java index 9b457c6f7c..f352ba5e30 100644 --- a/src/main/java/UserText.java +++ b/src/main/java/UserText.java @@ -2,32 +2,39 @@ import java.util.List; public class UserText { - private List userInput; + private List allTasks; public UserText() { - userInput = new ArrayList<>(); + allTasks = new ArrayList<>(); } public void addInput(Task s) { - this.userInput.add(s); - System.out.println("Now you have " + userInput.size() + " tasks in the list."); + this.allTasks.add(s); + System.out.println("Now you have " + allTasks.size() + " tasks in the list."); } public void printInputs() { int count = 1; System.out.println("Here is your list"); - for (Task s : userInput) { + for (Task s : allTasks) { System.out.println(count + ". " + s); count++; } } public Task getTask(int n) { - return this.userInput.get(n-1); + return this.allTasks.get(n-1); } public void markDone(int taskNo) { - userInput.get(taskNo - 1).markAsDone(); + allTasks.get(taskNo - 1).markAsDone(); System.out.println("Nice! I marked this task as done"); } + + public void removeTask(int taskNo) { + Task tempTask = allTasks.remove(taskNo - 1); + System.out.println("Noted. I have removed this task"); + System.out.println(" " + tempTask); + System.out.println("Now you have " + allTasks.size() + " tasks in the list."); + } }