diff --git a/src/main/java/CommandManager.java b/src/main/java/CommandManager.java index c36244c7e..8d1714fe2 100644 --- a/src/main/java/CommandManager.java +++ b/src/main/java/CommandManager.java @@ -55,6 +55,11 @@ public void printOutput(Tasks task) { System.out.println("\t Now you have " + Tasks.getNumberOfTasks() + " in your list.\n" + DIVIDER); break; + case "delete": + System.out.println(DIVIDER + "\n\t Got it. I've deleted this task:\n\t " + + task); + System.out.println("\t Now you have " + (Tasks.getNumberOfTasks() - 1) + " in your list.\n" + + DIVIDER); } } @@ -63,7 +68,7 @@ public void printOutput() { System.out.println(DIVIDER + "\n\t Here are the tasks in your list:"); for (int num = 1; num <= totalNumberOfTasks; ++num) { Tasks thisTask = Tasks.getTaskList().get(num - 1); - System.out.println("\t " + thisTask); + System.out.println("\t " + num + ". " + thisTask); } System.out.println(DIVIDER); } diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 2ebdb6956..96ef594e6 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -53,6 +53,7 @@ private static void readFromFile() throws FileNotFoundException, FolderNotFoundE } } + public static void main(String[] args) throws IOException { Scanner in = new Scanner(System.in); CommandManager.sayHi(); @@ -126,6 +127,12 @@ public static void main(String[] args) throws IOException { case "list": command.printOutput(); break; + case "delete": + Tasks toDelete = Tasks.getTaskList().get(Integer.parseInt(userInput[1]) - 1); + command.setKey("delete"); + command.printOutput(toDelete); + Tasks.deleteFromList(Integer.parseInt(userInput[1]) - 1); + break; default: System.out.println("Try again!"); } diff --git a/src/main/java/Tasks.java b/src/main/java/Tasks.java index 501c25255..08316b267 100644 --- a/src/main/java/Tasks.java +++ b/src/main/java/Tasks.java @@ -13,6 +13,10 @@ public Tasks(String item, boolean isMarked) { public static void addToList(Tasks task) { taskList.add(task); } + public static void deleteFromList(int pos){ + taskList.remove(pos); + numberOfTasks--; + } public static ArrayList getTaskList() { return taskList; } diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 141074060..cac695623 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -15,6 +15,7 @@ IF ERRORLEVEL 1 ( REM no error here, errorlevel == 0 REM run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT + java -classpath ..\bin Duke < input.txt, data\Duke.txt > ACTUAL.TXT REM compare the output to the expected output