From 37dbac6f419f9cb25627e34e0d950275e10873ac Mon Sep 17 00:00:00 2001 From: gx-huang Date: Tue, 11 Feb 2020 19:58:02 +0800 Subject: [PATCH] C-Archive --- build.gradle | 8 +++-- src/main/java/Duke.java | 2 +- src/main/java/DukeParser.java | 28 ++++++++++++------ src/main/java/DukeUI.java | 13 +++++++-- src/main/java/TaskList.java | 52 ++++++++++++++++++++++++--------- src/test/java/DeadlineTest.java | 4 +-- src/test/java/ToDoTest.java | 4 +-- 7 files changed, 78 insertions(+), 33 deletions(-) diff --git a/build.gradle b/build.gradle index 22691ccd33..8583807dc7 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,4 @@ -import org.gradle.api.plugins.internal.DefaultJavaApplication -import org.gradle.internal.jvm.Jvm + plugins { id 'java' @@ -53,8 +52,11 @@ dependencies { implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'win' implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'mac' implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'linux' + + compile files("${System.properties['JAVA_HOME']}/../lib/tools.jar") } run { standardInput = System.in -} \ No newline at end of file +} + diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index d193ad95e3..aadaeb1225 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -88,7 +88,7 @@ public void start(Stage stage) { // You will need to import `javafx.scene.layout.Region` for this. dialogContainer.setPrefHeight(Region.USE_COMPUTED_SIZE); - userInput.setPrefWidth(500.0); + userInput.setPrefWidth(480.0); sendButton.setPrefWidth(55.0); diff --git a/src/main/java/DukeParser.java b/src/main/java/DukeParser.java index a9b42a23df..65b265ab97 100644 --- a/src/main/java/DukeParser.java +++ b/src/main/java/DukeParser.java @@ -35,42 +35,52 @@ public String parseCommand(String command) { String context = command_broken[1]; int taskNo = Integer.parseInt(context); - tasks.removeTask(taskNo); - return DukeUI.showDeleteMsg(); + return tasks.removeTask(taskNo); } else if (action.equalsIgnoreCase(("deadline"))) { String context = command_broken[1]; String[] context_broken = context.split(" /by ", 2); - tasks.addInput(new Deadlines(context_broken[0], false ,context_broken[1])); - return DukeUI.showCreationMsg(); + Task tempTask = tasks.addTask(new Deadlines(context_broken[0], false ,context_broken[1])); + return DukeUI.showCreationMsg(tempTask); } else if (action.equalsIgnoreCase(("todo"))) { if (command_broken.length == 1) { throw new DukeException("THE DESCRIPTION OF TODO CANNOT BE EMPTY"); } - tasks.addInput(new ToDos(command_broken[1], false)); - return DukeUI.showCreationMsg(); + Task tempTask = tasks.addTask(new ToDos(command_broken[1], false)); + return DukeUI.showCreationMsg(tempTask); } else if (action.equalsIgnoreCase(("event"))) { String context = command_broken[1]; String[] context_broken = context.split(" /at ", 2); - tasks.addInput(new Events(context_broken[0], false, context_broken[1])); - return DukeUI.showCreationMsg(); + Task tempTask = tasks.addTask(new Events(context_broken[0], false, context_broken[1])); + return DukeUI.showCreationMsg(tempTask); } else if (action.equalsIgnoreCase("find")) { int count = 1; - for (Task t: tasks.getAllTasks()) { + for (Task t : tasks.getAllTasks()) { if (t.containsSubstring(command_broken[1])) { System.out.println(count + "." + t); count++; } } return DukeUI.showFindMsg(); + } else if (action.equalsIgnoreCase("archive")) { + String context = command_broken[1]; + int taskNo = Integer.parseInt(context); + return tasks.archiveTask(taskNo); + + } else if (action.equalsIgnoreCase("archiveall")) { + + return tasks.archiveAll(); + + } else if (action.equalsIgnoreCase("showarchive")){ + return tasks.showArchived(); } else { return "UNABLE TO COMPREHEND"; } diff --git a/src/main/java/DukeUI.java b/src/main/java/DukeUI.java index ca669720b5..f888cbdf88 100644 --- a/src/main/java/DukeUI.java +++ b/src/main/java/DukeUI.java @@ -28,8 +28,9 @@ public static String showLoadingError() { public static String showDoneMsg() { return "TASK COMPLETED"; } - public static String showCreationMsg() { - return "UNDERSTOOD"; + + public static String showCreationMsg(Task task) { + return "UNDERSTOOD \n" + task.toString() + "\nADDED"; } public static String showDeleteMsg() { @@ -41,5 +42,11 @@ public static String showFindMsg() { } public static String showCurrentListSize(int size) { - return "NOW YOU HAVE " + size + " TASKS";} + return "NOW YOU HAVE " + size + " TASKS"; + } + + public static String showArchivedMsg(Task task) { + return task.toString() + "\n IS NOW ARCHIVED"; + } + } diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java index 120decacaa..06f28769d1 100644 --- a/src/main/java/TaskList.java +++ b/src/main/java/TaskList.java @@ -4,25 +4,20 @@ //Wrapper class for the list of tasks public class TaskList { private List allTasks; + private List archivedTasks; public TaskList() { allTasks = new ArrayList<>(); + archivedTasks = new ArrayList<>(); } - public void addInput(Task s) { + public Task addTask(Task s) { this.allTasks.add(s); - DukeUI.showCurrentListSize(allTasks.size()); + return s; } public String printTasks() { - int count = 1; - StringBuilder sb = new StringBuilder(); - sb.append("HERE IS YOUR LIST\n"); - for (Task s : allTasks) { - sb.append( count+ ". " + s + "\n"); - count++; - } - return sb.toString(); + return getString(allTasks); } public Task getTask(int n) { @@ -41,9 +36,40 @@ public void markDone(int taskNo) { allTasks.get(taskNo - 1).markAsDone(); } - public void removeTask(int taskNo) { + public String removeTask(int taskNo) { Task tempTask = allTasks.remove(taskNo - 1); - System.out.println(" " + tempTask); - DukeUI.showCurrentListSize(allTasks.size()); + return DukeUI.showDeleteMsg() + "\n" + + " " + tempTask + "\n" + + DukeUI.showCurrentListSize(allTasks.size()); + } + + public String archiveTask(int taskNo) { + Task tempTask = allTasks.remove(taskNo - 1); + archivedTasks.add(tempTask); + return DukeUI.showArchivedMsg(tempTask); + + } + + public String archiveAll() { + String archiveMessage = ""; + for (int i = 1; i <= allTasks.size(); i++) { + archiveMessage += this.archiveTask(i); + } + return archiveMessage; + } + + public String showArchived() { + return getString(archivedTasks); + } + + private String getString(List tasks) { + int count = 1; + StringBuilder sb = new StringBuilder(); + sb.append("HERE IS YOUR LIST\n"); + for (Task s : tasks) { + sb.append(count).append(". ").append(s).append("\n"); + count++; + } + return sb.toString(); } } diff --git a/src/test/java/DeadlineTest.java b/src/test/java/DeadlineTest.java index df6613bddf..66cf26544d 100644 --- a/src/test/java/DeadlineTest.java +++ b/src/test/java/DeadlineTest.java @@ -6,9 +6,9 @@ public class DeadlineTest { @Test public void testStringConvert() { - assertEquals("[D][X] read book (By: JAN 1 2020)", - new Deadlines("read book",false, "2020-01-01").toString()); assertEquals("[D][O] read book (By: JAN 1 2020)", + new Deadlines("read book",false, "2020-01-01").toString()); + assertEquals("[D][X] read book (By: JAN 1 2020)", new Deadlines("read book", true, "2020-01-01").toString()); } diff --git a/src/test/java/ToDoTest.java b/src/test/java/ToDoTest.java index 5b0e00efc4..ee242e62db 100644 --- a/src/test/java/ToDoTest.java +++ b/src/test/java/ToDoTest.java @@ -6,9 +6,9 @@ public class ToDoTest { @Test public void testStringConvert() { - assertEquals("[T][X] read book", - new ToDos("read book", false).toString()); assertEquals("[T][O] read book", + new ToDos("read book", false).toString()); + assertEquals("[T][X] read book", new ToDos("read book", true).toString()); } } \ No newline at end of file