From 335753be67980e7b690422a4b933ea9339234250 Mon Sep 17 00:00:00 2001 From: chiayuxuan Date: Wed, 15 Feb 2023 14:47:04 +0800 Subject: [PATCH 1/2] Add delete function --- src/main/java/CommandManager.java | 5 +++++ src/main/java/Duke.java | 8 ++++++++ src/main/java/Tasks.java | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/src/main/java/CommandManager.java b/src/main/java/CommandManager.java index a2c8812ee..72452efd5 100644 --- a/src/main/java/CommandManager.java +++ b/src/main/java/CommandManager.java @@ -63,6 +63,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); } } diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 4dac8da5a..d593786f7 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -70,7 +70,15 @@ public static void main(String[] args) throws NoKeyException{ 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: throw new NoKeyException("Come on, give me something that I can work with!"); } diff --git a/src/main/java/Tasks.java b/src/main/java/Tasks.java index 9f3728f16..1088a799d 100644 --- a/src/main/java/Tasks.java +++ b/src/main/java/Tasks.java @@ -17,6 +17,10 @@ public static void addToList(Tasks task) { taskList.add(task); } + public static void deleteFromList(int pos){ + taskList.remove(pos); + numberOfTasks--; + } public static ArrayList getTaskList() { From 240f4ecaf4b3f277c5b0ff6b34cd823af0dcf8d9 Mon Sep 17 00:00:00 2001 From: chiayuxuan Date: Wed, 15 Feb 2023 15:18:00 +0800 Subject: [PATCH 2/2] Added some small details --- src/main/java/CommandManager.java | 2 +- src/main/java/Duke.java | 5 +++-- text-ui-test/runtest.bat | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/CommandManager.java b/src/main/java/CommandManager.java index 72452efd5..d99377247 100644 --- a/src/main/java/CommandManager.java +++ b/src/main/java/CommandManager.java @@ -76,7 +76,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 d593786f7..20ec055bb 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -4,7 +4,9 @@ public class Duke { - public static void main(String[] args) throws NoKeyException{ + + public static void main(String[] args) throws NoKeyException { + Scanner in = new Scanner(System.in); CommandManager.sayHi(); CommandManager command = new CommandManager(); @@ -24,7 +26,6 @@ public static void main(String[] args) throws NoKeyException{ " after mark. EXAMPLE: mark 2"); } break; - case "unmark": try { Tasks unMarkTask = Tasks.getTaskList().get(Integer.parseInt(userInput[1]) - 1); diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 5be027ae1..a91e2e7eb 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -7,7 +7,7 @@ REM delete output from previous run if exist ACTUAL.TXT del ACTUAL.TXT REM compile the code into the bin folder -Duke.java -cp ..\src\main\java -Xlint:none -d ..\bin ..\src\main\java\*.java +javac -cp ..\src\main\java -Xlint:none -d ..\bin ..\src\main\java\*.java IF ERRORLEVEL 1 ( echo ********** BUILD FAILURE ********** exit /b 1 @@ -15,7 +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 -Duke.java -classpath ..\bin Duke < input.txt > ACTUAL.TXT +java -classpath ..\bin Duke > ACTUAL.TXT REM compare the output to the expected output FC ACTUAL.TXT EXPECTED.TXT