From fc8a985802d297c66bf6057c095d25e51d8ff69e Mon Sep 17 00:00:00 2001 From: striris <72813713+striris@users.noreply.github.com> Date: Thu, 3 Feb 2022 17:19:23 +0800 Subject: [PATCH 01/28] Level-0 Greeting --- src/main/java/Duke.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5d313334c..e5d270f77 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,10 +1,9 @@ public class Duke { public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); + String greeting = "Hello! I'm Duke\n" + + "What can I do for you?\n" + + "----------------------\n" + + "Bye. Hope to see you again soon!\n"; + System.out.println(greeting); } } From 14b2a5381cee4ef8d0098b876a20ec208f21cc48 Mon Sep 17 00:00:00 2001 From: striris <72813713+striris@users.noreply.github.com> Date: Thu, 3 Feb 2022 17:31:32 +0800 Subject: [PATCH 02/28] Level 1. Greet, Echo, Exit --- src/main/java/Duke.java | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index e5d270f77..3e528bfdd 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,9 +1,26 @@ +import java.util.Scanner; + public class Duke { + public static void main(String[] args) { - String greeting = "Hello! I'm Duke\n" + Scanner sc = new Scanner(System.in); + String greeting = "----------------------\n" + + "Hello! I'm Duke\n" + "What can I do for you?\n" - + "----------------------\n" - + "Bye. Hope to see you again soon!\n"; + + "----------------------\n"; + String bye = "Bye. Hope to see you again soon!\n"; System.out.println(greeting); + + String input = sc.next(); + while(true){ + if(input.equals("bye")){ + System.out.println(bye); + break; + } + else{ + System.out.println(input); + input = sc.next(); + } + } } } From 6e9acc1511be1fc999f8089032a4b66f30d9ed96 Mon Sep 17 00:00:00 2001 From: striris <72813713+striris@users.noreply.github.com> Date: Thu, 3 Feb 2022 23:26:49 +0800 Subject: [PATCH 03/28] Level 2. Add, List --- src/main/java/Duke.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 3e528bfdd..2dda0303f 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,8 +1,11 @@ +import javax.swing.plaf.basic.BasicInternalFrameTitlePane; import java.util.Scanner; public class Duke { public static void main(String[] args) { + String[] tasks = new String[100]; + int count = 0; Scanner sc = new Scanner(System.in); String greeting = "----------------------\n" + "Hello! I'm Duke\n" @@ -11,16 +14,24 @@ public static void main(String[] args) { String bye = "Bye. Hope to see you again soon!\n"; System.out.println(greeting); - String input = sc.next(); while(true){ + String input = sc.nextLine(); + System.out.println("----------------------"); if(input.equals("bye")){ System.out.println(bye); break; } + else if(input.equals("list")){ + for(int i = 0; i Date: Thu, 3 Feb 2022 23:28:32 +0800 Subject: [PATCH 04/28] deleted unnecessary package. --- src/main/java/Duke.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 2dda0303f..2b62f5c40 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,4 +1,3 @@ -import javax.swing.plaf.basic.BasicInternalFrameTitlePane; import java.util.Scanner; public class Duke { From 91a1e1dec68886d9ecfc2a496ac676a8ac4ad90d Mon Sep 17 00:00:00 2001 From: striris <72813713+striris@users.noreply.github.com> Date: Thu, 3 Feb 2022 23:53:44 +0800 Subject: [PATCH 05/28] Level 3. Mark as Done Add the ability to mark tasks as done. Optionally, add the ability to change the status back to not done. --- src/main/java/Duke.java | 33 ++++++++++++++++++++++++--------- src/main/java/Task.java | 21 +++++++++++++++++++++ 2 files changed, 45 insertions(+), 9 deletions(-) create mode 100644 src/main/java/Task.java diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 2b62f5c40..8dd67a4f1 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -3,34 +3,49 @@ public class Duke { public static void main(String[] args) { - String[] tasks = new String[100]; + Task[] tasks = new Task[100]; int count = 0; Scanner sc = new Scanner(System.in); - String greeting = "----------------------\n" + String greeting = "----------------------------------------------\n" + "Hello! I'm Duke\n" + "What can I do for you?\n" - + "----------------------\n"; + + "----------------------------------------------\n"; String bye = "Bye. Hope to see you again soon!\n"; System.out.println(greeting); while(true){ String input = sc.nextLine(); - System.out.println("----------------------"); + System.out.println("----------------------------------------------"); if(input.equals("bye")){ System.out.println(bye); break; } else if(input.equals("list")){ - for(int i = 0; i Date: Fri, 4 Feb 2022 01:34:13 +0800 Subject: [PATCH 06/28] Level 4. ToDos, Events, Deadlines Add support for tracking three types of tasks: ToDos: tasks without any date/time attached to it e.g., visit new theme park Deadlines: tasks that need to be done before a specific date/time e.g., submit report by 11/10/2019 5pm Events: tasks that start at a specific time and ends at a specific time e.g., team project meeting on 2/10/2019 2-4pm --- src/main/java/Deadline.java | 16 ++++++++++ src/main/java/Duke.java | 58 ++++++++++++++++++++++++++++--------- src/main/java/Event.java | 14 +++++++++ src/main/java/Task.java | 5 ++++ src/main/java/ToDo.java | 11 +++++++ 5 files changed, 91 insertions(+), 13 deletions(-) create mode 100644 src/main/java/Deadline.java create mode 100644 src/main/java/Event.java create mode 100644 src/main/java/ToDo.java diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java new file mode 100644 index 000000000..03998fcda --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,16 @@ +public class Deadline extends Task { + + protected String by; + + public Deadline(String description, String by) { + super(description); + this.by = by; + } + + @Override + public String toString() { + return "[D]" + super.toString() + " (by: " + by + ")"; + } +} + +//this.description = description.substring(0, description.lastIndexOf("/") + 4); \ No newline at end of file diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 8dd67a4f1..f4536c798 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -4,6 +4,8 @@ public class Duke { public static void main(String[] args) { Task[] tasks = new Task[100]; + String by = new String(); + String at = new String(); int count = 0; Scanner sc = new Scanner(System.in); String greeting = "----------------------------------------------\n" @@ -14,36 +16,66 @@ public static void main(String[] args) { System.out.println(greeting); while(true){ - String input = sc.nextLine(); + String userInput = sc.nextLine(); System.out.println("----------------------------------------------"); - if(input.equals("bye")){ + if(userInput.equals("bye")){ System.out.println(bye); break; } - else if(input.equals("list")){ + else if(userInput.equals("list")){//show list System.out.println("Here are the tasks in your list:"); for(int i = 0; i Date: Fri, 18 Feb 2022 10:34:26 +0800 Subject: [PATCH 07/28] add a new line at the end of file --- src/main/java/Deadline.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index 03998fcda..3cc9d0cbf 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -13,4 +13,4 @@ public String toString() { } } -//this.description = description.substring(0, description.lastIndexOf("/") + 4); \ No newline at end of file +//this.description = description.substring(0, description.lastIndexOf("/") + 4); From 409d603f460cefac8b4e0d13dac313df58c2dee3 Mon Sep 17 00:00:00 2001 From: striris Date: Fri, 18 Feb 2022 10:40:25 +0800 Subject: [PATCH 08/28] created a package --- README.md | 4 ++-- src/main/java/{ => duke}/Deadline.java | 2 ++ src/main/java/{ => duke}/Duke.java | 4 +++- src/main/java/{ => duke}/Event.java | 2 ++ src/main/java/{ => duke}/Task.java | 2 ++ src/main/java/{ => duke}/ToDo.java | 2 ++ text-ui-test/runtest.bat | 2 +- 7 files changed, 14 insertions(+), 4 deletions(-) rename src/main/java/{ => duke}/Deadline.java (96%) rename src/main/java/{ => duke}/Duke.java (98%) rename src/main/java/{ => duke}/Event.java (94%) rename src/main/java/{ => duke}/Task.java (97%) rename src/main/java/{ => duke}/ToDo.java (93%) diff --git a/README.md b/README.md index 8715d4d91..a8111be76 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Duke project template +# duke.duke project template This is a project template for a greenfield Java project. It's named after the Java mascot _Duke_. Given below are instructions on how to use it. @@ -13,7 +13,7 @@ Prerequisites: JDK 11, update Intellij to the most recent version. 1. If there are any further prompts, accept the defaults. 1. Configure the project to use **JDK 11** (not other versions) as explained in [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk).
In the same dialog, set the **Project language level** field to the `SDK default` option. -3. After that, locate the `src/main/java/Duke.java` file, right-click it, and choose `Run Duke.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output: +3. After that, locate the `src/main/java/duke.duke.java` file, right-click it, and choose `Run duke.duke.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output: ``` Hello from ____ _ diff --git a/src/main/java/Deadline.java b/src/main/java/duke/Deadline.java similarity index 96% rename from src/main/java/Deadline.java rename to src/main/java/duke/Deadline.java index 3cc9d0cbf..f3f5a0cb0 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/duke/Deadline.java @@ -1,3 +1,5 @@ +package duke; + public class Deadline extends Task { protected String by; diff --git a/src/main/java/Duke.java b/src/main/java/duke/Duke.java similarity index 98% rename from src/main/java/Duke.java rename to src/main/java/duke/Duke.java index f4536c798..036f55414 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,3 +1,5 @@ +package duke; + import java.util.Scanner; public class Duke { @@ -9,7 +11,7 @@ public static void main(String[] args) { int count = 0; Scanner sc = new Scanner(System.in); String greeting = "----------------------------------------------\n" - + "Hello! I'm Duke\n" + + "Hello! I'm Duke.Duke\n" + "What can I do for you?\n" + "----------------------------------------------\n"; String bye = "Bye. Hope to see you again soon!\n"; diff --git a/src/main/java/Event.java b/src/main/java/duke/Event.java similarity index 94% rename from src/main/java/Event.java rename to src/main/java/duke/Event.java index 3503fbe04..c511ff5b0 100644 --- a/src/main/java/Event.java +++ b/src/main/java/duke/Event.java @@ -1,3 +1,5 @@ +package duke; + public class Event extends Task { protected String at; diff --git a/src/main/java/Task.java b/src/main/java/duke/Task.java similarity index 97% rename from src/main/java/Task.java rename to src/main/java/duke/Task.java index 5a5ca1464..24bbd1c9d 100644 --- a/src/main/java/Task.java +++ b/src/main/java/duke/Task.java @@ -1,3 +1,5 @@ +package duke; + public class Task { protected String description; protected boolean isDone; diff --git a/src/main/java/ToDo.java b/src/main/java/duke/ToDo.java similarity index 93% rename from src/main/java/ToDo.java rename to src/main/java/duke/ToDo.java index 38788ba66..aba8928eb 100644 --- a/src/main/java/ToDo.java +++ b/src/main/java/duke/ToDo.java @@ -1,3 +1,5 @@ +package duke; + public class ToDo extends Task { public ToDo(String description) { diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 087374464..7eb6d3cdd 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -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 -java -classpath ..\bin Duke < input.txt > ACTUAL.TXT +java -classpath ..\bin duke.duke < input.txt > ACTUAL.TXT REM compare the output to the expected output FC ACTUAL.TXT EXPECTED.TXT From 3a3855f01b63e96db56d043d244bd20d49689a40 Mon Sep 17 00:00:00 2001 From: striris Date: Sun, 20 Feb 2022 12:57:45 +0800 Subject: [PATCH 09/28] created the jar file --- src/main/java/META-INF/MANIFEST.MF | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/main/java/META-INF/MANIFEST.MF diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 000000000..2c9a9745c --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: duke.Duke + From 315b90506cd78ca01a867ee5bee51ed3ca90f6f2 Mon Sep 17 00:00:00 2001 From: striris Date: Sun, 20 Feb 2022 13:55:43 +0800 Subject: [PATCH 10/28] changed array to ArrayList. added deletion function. extracted methods. --- src/main/java/duke/Duke.java | 117 ++++++++++++++++++++++------------- 1 file changed, 73 insertions(+), 44 deletions(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 036f55414..25763f1b1 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,80 +1,104 @@ package duke; +import java.util.ArrayList; import java.util.Scanner; public class Duke { - public static void main(String[] args) { - Task[] tasks = new Task[100]; - String by = new String(); - String at = new String(); - int count = 0; - Scanner sc = new Scanner(System.in); + private static ArrayList tasks = new ArrayList<>(); + + private static void greeting() { String greeting = "----------------------------------------------\n" + "Hello! I'm Duke.Duke\n" + "What can I do for you?\n" + "----------------------------------------------\n"; String bye = "Bye. Hope to see you again soon!\n"; System.out.println(greeting); + } + + private static void farewell() { + String bye = "Bye. Hope to see you again soon!\n"; + System.out.println(bye); + } + + private static void listTask() { + System.out.println("Here are the tasks in your list:"); + for(int i = 0; i Date: Sun, 20 Feb 2022 14:11:41 +0800 Subject: [PATCH 11/28] added saveTasks function to convert the list into a text file. --- src/main/java/duke/Duke.java | 18 ++++++++++++++++++ src/main/java/duke/Task.java | 4 ++++ src/main/java/duke/tasks.txt | 2 ++ 3 files changed, 24 insertions(+) create mode 100644 src/main/java/duke/tasks.txt diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 25763f1b1..a9510de64 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,5 +1,6 @@ package duke; +import java.io.FileWriter; import java.util.ArrayList; import java.util.Scanner; @@ -64,6 +65,7 @@ private static void startBot() { System.out.println("----------------------------------------------"); if(userInput.equals("bye")) { farewell(); + saveTasks(); break; } else if(userInput.equals("list")) { @@ -111,4 +113,20 @@ public static void main(String[] args) { greeting(); startBot(); } + + public static void saveTasks() { + String toFile = ""; + try { + FileWriter writer = new FileWriter("src/main/java/duke/tasks.txt"); + for (int i = 0; i < tasks.size(); i++) { + toFile += tasks.get(i).getDescription() + "\n"; + } + writer.write(toFile); + writer.close(); + System.out.println("Task saved"); + System.out.println("______________________________________"); + } catch (Exception e) { + System.out.println("Error occurred"); + } + } } diff --git a/src/main/java/duke/Task.java b/src/main/java/duke/Task.java index 24bbd1c9d..d89061e7f 100644 --- a/src/main/java/duke/Task.java +++ b/src/main/java/duke/Task.java @@ -9,6 +9,10 @@ public Task(String description) { this.isDone = false; } + public String getDescription() { + return description; + } + public String getStatusIcon() { return (isDone ? "X" : " "); // mark done task with X } diff --git a/src/main/java/duke/tasks.txt b/src/main/java/duke/tasks.txt new file mode 100644 index 000000000..fcab3e740 --- /dev/null +++ b/src/main/java/duke/tasks.txt @@ -0,0 +1,2 @@ +task1 +ddl1 From b18486bc35ab72985f7535fe53e388458965a3b9 Mon Sep 17 00:00:00 2001 From: striris Date: Wed, 2 Mar 2022 12:19:38 +0800 Subject: [PATCH 12/28] added load/save file functions. organized tasks into a package. --- data/duke.txt | 4 + src/main/java/duke/Duke.java | 120 +++++++++---------- src/main/java/duke/Event.java | 16 --- src/main/java/duke/FileManager.java | 71 +++++++++++ src/main/java/duke/ToDo.java | 13 -- src/main/java/duke/{ => tasks}/Deadline.java | 11 +- src/main/java/duke/tasks/Event.java | 21 ++++ src/main/java/duke/{ => tasks}/Task.java | 15 ++- src/main/java/duke/tasks/ToDo.java | 18 +++ 9 files changed, 192 insertions(+), 97 deletions(-) create mode 100644 data/duke.txt delete mode 100644 src/main/java/duke/Event.java create mode 100644 src/main/java/duke/FileManager.java delete mode 100644 src/main/java/duke/ToDo.java rename src/main/java/duke/{ => tasks}/Deadline.java (52%) create mode 100644 src/main/java/duke/tasks/Event.java rename src/main/java/duke/{ => tasks}/Task.java (61%) create mode 100644 src/main/java/duke/tasks/ToDo.java diff --git a/data/duke.txt b/data/duke.txt new file mode 100644 index 000000000..fe816a9e2 --- /dev/null +++ b/data/duke.txt @@ -0,0 +1,4 @@ +T | 0 | what +D | 1 | ddl1 | June +E | 0 | EVENT1 | noon +D | 1 | ddl2 | 6.7 diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index a9510de64..b83e9157a 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,6 +1,12 @@ package duke; +import duke.tasks.Deadline; +import duke.tasks.Event; +import duke.tasks.Task; +import duke.tasks.ToDo; + import java.io.FileWriter; +import java.io.IOException; import java.util.ArrayList; import java.util.Scanner; @@ -58,75 +64,65 @@ private static void startBot() { Scanner sc = new Scanner(System.in); String by = new String(); String at = new String(); - while(true){ - String userInput = sc.nextLine(); - String choice = userInput.split(" ")[0]; + try { + FileManager.loadFile(tasks); + while(true){ + String userInput = sc.nextLine(); + String choice = userInput.split(" ")[0]; - System.out.println("----------------------------------------------"); - if(userInput.equals("bye")) { - farewell(); - saveTasks(); - break; - } - else if(userInput.equals("list")) { - listTask(); - } - else if(choice.equals("mark")) { - int taskIndex = Integer.parseInt(userInput.split(" ")[1]); - markTask(taskIndex); - } - else if(choice.equals("unmark")) { - int taskIndex = Integer.parseInt(userInput.split(" ")[1]); - unmarkTask(taskIndex); - } - else if(choice.equals("todo")) { - String toDoDescription = userInput.split("todo")[1].trim(); - Task t = new ToDo(toDoDescription); - addTask(t); - } - else if(choice.equals("deadline")) { - String[] input = userInput.split("/by"); - by = input[1].trim(); - String deadlineDescription = input[0].split("deadline")[1].trim(); - Task d = new Deadline(deadlineDescription, by); - addTask(d); - } - else if(choice.equals("event")) { - String[] input = userInput.split("/at"); - at = input[1].trim(); - String eventDescription = input[0].split("event")[1].trim(); - Task e = new Event(eventDescription, at); - addTask(e); + System.out.println("----------------------------------------------"); + if(userInput.equals("bye")) { + farewell(); + FileManager.saveFile(tasks); + break; + } + else if(userInput.equals("list")) { + listTask(); + } + else if(choice.equals("mark")) { + int taskIndex = Integer.parseInt(userInput.split(" ")[1]); + markTask(taskIndex); + } + else if(choice.equals("unmark")) { + int taskIndex = Integer.parseInt(userInput.split(" ")[1]); + unmarkTask(taskIndex); + } + else if(choice.equals("todo")) { + String toDoDescription = userInput.split("todo")[1].trim(); + Task t = new ToDo(toDoDescription, false); + addTask(t); + } + else if(choice.equals("deadline")) { + String[] input = userInput.split("/by"); + by = input[1].trim(); + String deadlineDescription = input[0].split("deadline")[1].trim(); + Task d = new Deadline(deadlineDescription, false, by); + addTask(d); + } + else if(choice.equals("event")) { + String[] input = userInput.split("/at"); + at = input[1].trim(); + String eventDescription = input[0].split("event")[1].trim(); + Task e = new Event(eventDescription, false, at); + addTask(e); + } + else if(choice.equals("delete")) { + int taskIndex = Integer.parseInt(userInput.split(" ")[1]); + deleteTask(taskIndex); + } + else{ + System.out.println("I don't understand D:"); + } + System.out.println("----------------------------------------------"); } - else if(choice.equals("delete")) { - int taskIndex = Integer.parseInt(userInput.split(" ")[1]); - deleteTask(taskIndex); - } - else{ - System.out.println("I don't understand D:"); - } - System.out.println("----------------------------------------------"); + } catch (IOException e) { + e.printStackTrace(); } + } public static void main(String[] args) { greeting(); startBot(); } - - public static void saveTasks() { - String toFile = ""; - try { - FileWriter writer = new FileWriter("src/main/java/duke/tasks.txt"); - for (int i = 0; i < tasks.size(); i++) { - toFile += tasks.get(i).getDescription() + "\n"; - } - writer.write(toFile); - writer.close(); - System.out.println("Task saved"); - System.out.println("______________________________________"); - } catch (Exception e) { - System.out.println("Error occurred"); - } - } } diff --git a/src/main/java/duke/Event.java b/src/main/java/duke/Event.java deleted file mode 100644 index c511ff5b0..000000000 --- a/src/main/java/duke/Event.java +++ /dev/null @@ -1,16 +0,0 @@ -package duke; - -public class Event extends Task { - - protected String at; - - public Event(String description, String at) { - super(description); - this.at = at; - } - - @Override - public String toString() { - return "[E]" + super.toString() + " (at: " + at + ")"; - } -} \ No newline at end of file diff --git a/src/main/java/duke/FileManager.java b/src/main/java/duke/FileManager.java new file mode 100644 index 000000000..c97305006 --- /dev/null +++ b/src/main/java/duke/FileManager.java @@ -0,0 +1,71 @@ +package duke; + +import duke.tasks.Deadline; +import duke.tasks.Event; +import duke.tasks.Task; +import duke.tasks.ToDo; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Scanner; + +public class FileManager { + + protected static final char TODO = 'T'; + protected static final char EVENT = 'E'; + protected static final char DEADLINE = 'D'; + + public static void loadFile(ArrayList listArray) throws IOException { + try { + File f = new File("data/duke.txt"); + f.getParentFile().mkdirs(); + f.createNewFile(); + Scanner s = new Scanner(f); + while (s.hasNext()) { + boolean isDone = true; + String message = s.nextLine(); + String[] splitMessage = message.split(" \\| "); + char type = splitMessage[0].charAt(0); + int status = Integer.parseInt(splitMessage[1]); + if (status == 0) { + isDone = false; + } + String description = splitMessage[2]; + switch (type) { + case TODO: + listArray.add(new ToDo(description, isDone)); + break; + case EVENT: + String at = splitMessage[3]; + listArray.add(new Event(description, isDone, at)); + break; + case DEADLINE: + String by = splitMessage[3]; + listArray.add(new Deadline(description, isDone, by)); + break; + default: + break; + } + } + s.close(); + } catch (IOException e) { + System.out.println("IO exception"); + } + } + + public static void saveFile(ArrayList listArray) throws IOException { + try { + FileWriter fw = new FileWriter("data/duke.txt"); + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < listArray.size(); i++) { + sb.append(listArray.get(i).saveTasks()); + } + fw.write(sb.toString()); + fw.close(); + } catch (IOException e) { + System.out.println("IO exception"); + } + } +} diff --git a/src/main/java/duke/ToDo.java b/src/main/java/duke/ToDo.java deleted file mode 100644 index aba8928eb..000000000 --- a/src/main/java/duke/ToDo.java +++ /dev/null @@ -1,13 +0,0 @@ -package duke; - -public class ToDo extends Task { - - public ToDo(String description) { - super(description); - } - - @Override - public String toString() { - return "[T]" + super.toString(); - } -} diff --git a/src/main/java/duke/Deadline.java b/src/main/java/duke/tasks/Deadline.java similarity index 52% rename from src/main/java/duke/Deadline.java rename to src/main/java/duke/tasks/Deadline.java index f3f5a0cb0..b6bc617ac 100644 --- a/src/main/java/duke/Deadline.java +++ b/src/main/java/duke/tasks/Deadline.java @@ -1,11 +1,11 @@ -package duke; +package duke.tasks; public class Deadline extends Task { protected String by; - public Deadline(String description, String by) { - super(description); + public Deadline(String description, boolean isDone, String by) { + super(description, isDone); this.by = by; } @@ -13,6 +13,11 @@ public Deadline(String description, String by) { public String toString() { return "[D]" + super.toString() + " (by: " + by + ")"; } + + @Override + public String saveTasks() { + return "D " + super.saveTasks() + " | " + this.by + System.lineSeparator(); + } } //this.description = description.substring(0, description.lastIndexOf("/") + 4); diff --git a/src/main/java/duke/tasks/Event.java b/src/main/java/duke/tasks/Event.java new file mode 100644 index 000000000..4fb214de9 --- /dev/null +++ b/src/main/java/duke/tasks/Event.java @@ -0,0 +1,21 @@ +package duke.tasks; + +public class Event extends Task { + + protected String at; + + public Event(String description, boolean isDone, String at) { + super(description, isDone); + this.at = at; + } + + @Override + public String toString() { + return "[E]" + super.toString() + " (at: " + at + ")"; + } + + @Override + public String saveTasks() { + return "E " + super.saveTasks() + " | " + this.at + System.lineSeparator(); + } +} \ No newline at end of file diff --git a/src/main/java/duke/Task.java b/src/main/java/duke/tasks/Task.java similarity index 61% rename from src/main/java/duke/Task.java rename to src/main/java/duke/tasks/Task.java index d89061e7f..48a0646cf 100644 --- a/src/main/java/duke/Task.java +++ b/src/main/java/duke/tasks/Task.java @@ -1,18 +1,20 @@ -package duke; +package duke.tasks; public class Task { protected String description; protected boolean isDone; - public Task(String description) { + public Task(String description, boolean isDone) { this.description = description; - this.isDone = false; + this.isDone = isDone; } public String getDescription() { return description; } + public boolean getStatus() { return isDone; } + public String getStatusIcon() { return (isDone ? "X" : " "); // mark done task with X } @@ -29,4 +31,11 @@ public String toString() { return "[" + getStatusIcon() + "] " + description; } + public String saveTasks() { + int isMarked = 0; + if(this.isDone) { + isMarked = 1; + } + return "| " + isMarked + " | " + this.description ; + } } \ No newline at end of file diff --git a/src/main/java/duke/tasks/ToDo.java b/src/main/java/duke/tasks/ToDo.java new file mode 100644 index 000000000..c2b0fb4b2 --- /dev/null +++ b/src/main/java/duke/tasks/ToDo.java @@ -0,0 +1,18 @@ +package duke.tasks; + +public class ToDo extends Task { + + public ToDo(String description, boolean isDone) { + super(description, isDone); + } + + @Override + public String toString() { + return "[T]" + super.toString(); + } + + @Override + public String saveTasks() { + return "T " + super.saveTasks() + System.lineSeparator(); + } +} From 94aca1fe84eb982885655c0919ca8e6643736a8d Mon Sep 17 00:00:00 2001 From: striris Date: Thu, 3 Mar 2022 18:04:44 +0800 Subject: [PATCH 13/28] A-MoreOOP added TaskList, changed FileManager to Storage, Added Ui. --- data/duke.txt | 4 +- src/main/java/duke/Duke.java | 132 +++--------------- src/main/java/duke/Main.java | 9 ++ .../duke/{FileManager.java => Storage.java} | 20 +-- src/main/java/duke/Ui.java | 17 +++ src/main/java/duke/tasks/TaskList.java | 114 +++++++++++++++ 6 files changed, 170 insertions(+), 126 deletions(-) create mode 100644 src/main/java/duke/Main.java rename src/main/java/duke/{FileManager.java => Storage.java} (84%) create mode 100644 src/main/java/duke/Ui.java create mode 100644 src/main/java/duke/tasks/TaskList.java diff --git a/data/duke.txt b/data/duke.txt index fe816a9e2..2a95727b4 100644 --- a/data/duke.txt +++ b/data/duke.txt @@ -1,4 +1,4 @@ -T | 0 | what +T | 1 | what D | 1 | ddl1 | June E | 0 | EVENT1 | noon -D | 1 | ddl2 | 6.7 +D | 0 | ddl2 | 6.7 diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index b83e9157a..1ff3487e1 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,128 +1,28 @@ package duke; - -import duke.tasks.Deadline; -import duke.tasks.Event; -import duke.tasks.Task; -import duke.tasks.ToDo; - -import java.io.FileWriter; +import duke.tasks.TaskList; import java.io.IOException; -import java.util.ArrayList; -import java.util.Scanner; - -public class Duke { - - private static ArrayList tasks = new ArrayList<>(); - private static void greeting() { - String greeting = "----------------------------------------------\n" - + "Hello! I'm Duke.Duke\n" - + "What can I do for you?\n" - + "----------------------------------------------\n"; - String bye = "Bye. Hope to see you again soon!\n"; - System.out.println(greeting); - } - - private static void farewell() { - String bye = "Bye. Hope to see you again soon!\n"; - System.out.println(bye); - } - - private static void listTask() { - System.out.println("Here are the tasks in your list:"); - for(int i = 0; i listArray) throws IOException { + public Storage(String filePath) { + this.filePath = filePath; + } + + public static ArrayList loadFile() throws IOException { try { - File f = new File("data/duke.txt"); + File f = new File(filePath); f.getParentFile().mkdirs(); f.createNewFile(); Scanner s = new Scanner(f); + ArrayList listArray = new ArrayList<>(); while (s.hasNext()) { boolean isDone = true; String message = s.nextLine(); @@ -50,9 +52,11 @@ public static void loadFile(ArrayList listArray) throws IOException { } } s.close(); + return listArray; } catch (IOException e) { System.out.println("IO exception"); } + return null; } public static void saveFile(ArrayList listArray) throws IOException { diff --git a/src/main/java/duke/Ui.java b/src/main/java/duke/Ui.java new file mode 100644 index 000000000..fb7160c52 --- /dev/null +++ b/src/main/java/duke/Ui.java @@ -0,0 +1,17 @@ +package duke; + +public class Ui { + public static void greeting() { + String greeting = "----------------------------------------------\n" + + "Hello! I'm Duke.Duke\n" + + "What can I do for you?\n" + + "----------------------------------------------\n"; + String bye = "Bye. Hope to see you again soon!\n"; + System.out.println(greeting); + } + + public static void farewell() { + String bye = "Bye. Hope to see you again soon!\n"; + System.out.println(bye); + } +} diff --git a/src/main/java/duke/tasks/TaskList.java b/src/main/java/duke/tasks/TaskList.java new file mode 100644 index 000000000..7caed69a9 --- /dev/null +++ b/src/main/java/duke/tasks/TaskList.java @@ -0,0 +1,114 @@ +package duke.tasks; + +import duke.Storage; +import duke.Ui; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Scanner; + +public class TaskList { + private static ArrayList tasks; + private Storage storage; + private Ui ui; + + public TaskList(Storage storage) { + tasks = new ArrayList<>(); + this.storage = storage; + } + + public void loadTaskList() throws IOException { + try { + tasks = storage.loadFile(); + } catch (IOException e) { + throw e; + } + } + + public void processTasks() throws IOException { + Scanner sc = new Scanner(System.in); + String by = new String(); + String at = new String(); + + while(true){ + String userInput = sc.nextLine(); + String choice = userInput.split(" ")[0]; + + System.out.println("----------------------------------------------"); + if(userInput.equals("bye")) { + Storage.saveFile(tasks); + break; + } + else if(userInput.equals("list")) { + listTask(); + } + else if(choice.equals("mark")) { + int taskIndex = Integer.parseInt(userInput.split(" ")[1]); + markTask(taskIndex); + } + else if(choice.equals("unmark")) { + int taskIndex = Integer.parseInt(userInput.split(" ")[1]); + unmarkTask(taskIndex); + } + else if(choice.equals("todo")) { + String toDoDescription = userInput.split("todo")[1].trim(); + Task t = new ToDo(toDoDescription, false); + addTask(t); + } + else if(choice.equals("deadline")) { + String[] input = userInput.split("/by"); + by = input[1].trim(); + String deadlineDescription = input[0].split("deadline")[1].trim(); + Task d = new Deadline(deadlineDescription, false, by); + addTask(d); + } + else if(choice.equals("event")) { + String[] input = userInput.split("/at"); + at = input[1].trim(); + String eventDescription = input[0].split("event")[1].trim(); + Task e = new Event(eventDescription, false, at); + addTask(e); + } + else if(choice.equals("delete")) { + int taskIndex = Integer.parseInt(userInput.split(" ")[1]); + deleteTask(taskIndex); + } + else{ + System.out.println("I don't understand D:"); + } + System.out.println("----------------------------------------------"); + } + } + + public void listTask() { + System.out.println("Here are the tasks in your list:"); + for(int i = 0; i Date: Thu, 3 Mar 2022 23:26:47 +0800 Subject: [PATCH 14/28] Give users a way to find a task by searching for a keyword. used Ui to get user input. --- src/main/java/duke/Ui.java | 9 +++++++++ src/main/java/duke/tasks/TaskList.java | 24 +++++++++++++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/main/java/duke/Ui.java b/src/main/java/duke/Ui.java index fb7160c52..9ec8c6279 100644 --- a/src/main/java/duke/Ui.java +++ b/src/main/java/duke/Ui.java @@ -1,6 +1,9 @@ package duke; +import java.util.Scanner; + public class Ui { + public static void greeting() { String greeting = "----------------------------------------------\n" + "Hello! I'm Duke.Duke\n" @@ -14,4 +17,10 @@ public static void farewell() { String bye = "Bye. Hope to see you again soon!\n"; System.out.println(bye); } + + public static String getInput() { + Scanner sc = new Scanner(System.in); + String userInput = sc.nextLine(); + return userInput; + } } diff --git a/src/main/java/duke/tasks/TaskList.java b/src/main/java/duke/tasks/TaskList.java index 7caed69a9..e976337aa 100644 --- a/src/main/java/duke/tasks/TaskList.java +++ b/src/main/java/duke/tasks/TaskList.java @@ -5,7 +5,6 @@ import java.io.IOException; import java.util.ArrayList; -import java.util.Scanner; public class TaskList { private static ArrayList tasks; @@ -26,12 +25,11 @@ public void loadTaskList() throws IOException { } public void processTasks() throws IOException { - Scanner sc = new Scanner(System.in); String by = new String(); String at = new String(); while(true){ - String userInput = sc.nextLine(); + String userInput = Ui.getInput(); String choice = userInput.split(" ")[0]; System.out.println("----------------------------------------------"); @@ -73,6 +71,10 @@ else if(choice.equals("delete")) { int taskIndex = Integer.parseInt(userInput.split(" ")[1]); deleteTask(taskIndex); } + else if(choice.equals("find")) { + String keyWord = userInput.split(" ")[1]; + findTask(keyWord); + } else{ System.out.println("I don't understand D:"); } @@ -111,4 +113,20 @@ private static void deleteTask(int taskIndex) { tasks.remove(taskIndex -1); System.out.println("Now you have " + tasks.size() + " tasks in the list."); } + + private static void findTask(String keyWord) { + System.out.println("Here are the matching tasks in your list:"); + int i = 1; + for(Task t: tasks) { + if(t.description.contains(keyWord)){ + System.out.println(i +"."+ t); + i++; + } + } + if(i == 1) { + System.out.println("The keyword doesn't exist in task descriptions, try other keyword please :)"); + } + + } + } From a583454e6a3df94dc77e17ceebfe889bceff3882 Mon Sep 17 00:00:00 2001 From: striris Date: Thu, 3 Mar 2022 23:51:56 +0800 Subject: [PATCH 15/28] Added Java doc. --- src/main/java/duke/Duke.java | 5 ++++- src/main/java/duke/Storage.java | 17 ++++++++++++++++- src/main/java/duke/Ui.java | 1 - src/main/java/duke/tasks/Deadline.java | 7 ++++++- src/main/java/duke/tasks/Task.java | 6 +++++- src/main/java/duke/tasks/TaskList.java | 4 ++++ 6 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 1ff3487e1..7f52af062 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -2,7 +2,10 @@ import duke.tasks.TaskList; import java.io.IOException; - +/** + * Entry point of the Duke application. + * Initializes the application and starts the interaction with the user. + */ public class Duke { private Storage storage; diff --git a/src/main/java/duke/Storage.java b/src/main/java/duke/Storage.java index 34bd6432f..af3f5d8ef 100644 --- a/src/main/java/duke/Storage.java +++ b/src/main/java/duke/Storage.java @@ -8,6 +8,12 @@ import java.util.ArrayList; import java.util.Scanner; +/** + * Represents a Storage object that contains support for + * saving tasks/loading tasks from storage (ensures persistent storage + * of tasks) + */ + public class Storage { protected static String filePath; protected static final char TODO = 'T'; @@ -18,6 +24,11 @@ public Storage(String filePath) { this.filePath = filePath; } + /** + * Helper for loadTaskList + * Loads tasks from duke.txt (file of saved tasks) + * Returns ArrayList of Task objects + */ public static ArrayList loadFile() throws IOException { try { File f = new File(filePath); @@ -58,7 +69,11 @@ public static ArrayList loadFile() throws IOException { } return null; } - + /** + * Helper for processTasks + * Saves the list of tasks to the filepath of the Storage object + * @param listArray an ArrayList of tasks to write to file + */ public static void saveFile(ArrayList listArray) throws IOException { try { FileWriter fw = new FileWriter("data/duke.txt"); diff --git a/src/main/java/duke/Ui.java b/src/main/java/duke/Ui.java index 9ec8c6279..8ffb2a11e 100644 --- a/src/main/java/duke/Ui.java +++ b/src/main/java/duke/Ui.java @@ -9,7 +9,6 @@ public static void greeting() { + "Hello! I'm Duke.Duke\n" + "What can I do for you?\n" + "----------------------------------------------\n"; - String bye = "Bye. Hope to see you again soon!\n"; System.out.println(greeting); } diff --git a/src/main/java/duke/tasks/Deadline.java b/src/main/java/duke/tasks/Deadline.java index b6bc617ac..1002f4966 100644 --- a/src/main/java/duke/tasks/Deadline.java +++ b/src/main/java/duke/tasks/Deadline.java @@ -1,5 +1,10 @@ package duke.tasks; - +/** + * Represents an Deadline object on a person's list. + * This class inherits from the Task class and supports a slightly different toString() method + * that contains a marker for the Deadline object (an "D" for "Deadline"). Also + * allows users to set the time/date the Deadline task should be completed by. + */ public class Deadline extends Task { protected String by; diff --git a/src/main/java/duke/tasks/Task.java b/src/main/java/duke/tasks/Task.java index 48a0646cf..2327abb4e 100644 --- a/src/main/java/duke/tasks/Task.java +++ b/src/main/java/duke/tasks/Task.java @@ -1,5 +1,9 @@ package duke.tasks; - +/** + * Represents a Task object on a person's list of tasks that they must complete. + * A Task corresponds to a Task represented by a description of the + * task as well as a flag for whether it has been completed. + */ public class Task { protected String description; protected boolean isDone; diff --git a/src/main/java/duke/tasks/TaskList.java b/src/main/java/duke/tasks/TaskList.java index e976337aa..619f90df6 100644 --- a/src/main/java/duke/tasks/TaskList.java +++ b/src/main/java/duke/tasks/TaskList.java @@ -6,6 +6,10 @@ import java.io.IOException; import java.util.ArrayList; +/** + * Represents a person's list of Tasks that they must complete. + * This class supports the modification of Tasks. + */ public class TaskList { private static ArrayList tasks; private Storage storage; From 0ada8a32275c871d4d2ef33e5ec5790f579f0872 Mon Sep 17 00:00:00 2001 From: striris Date: Fri, 4 Mar 2022 00:04:32 +0800 Subject: [PATCH 16/28] Added User Guide in README.md --- README.md | 160 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 136 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index a8111be76..f92dca5a7 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,136 @@ -# duke.duke project template - -This is a project template for a greenfield Java project. It's named after the Java mascot _Duke_. Given below are instructions on how to use it. - -## Setting up in Intellij - -Prerequisites: JDK 11, update Intellij to the most recent version. - -1. Open Intellij (if you are not in the welcome screen, click `File` > `Close Project` to close the existing project first) -1. Open the project into Intellij as follows: - 1. Click `Open`. - 1. Select the project directory, and click `OK`. - 1. If there are any further prompts, accept the defaults. -1. Configure the project to use **JDK 11** (not other versions) as explained in [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk).
- In the same dialog, set the **Project language level** field to the `SDK default` option. -3. After that, locate the `src/main/java/duke.duke.java` file, right-click it, and choose `Run duke.duke.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output: - ``` - Hello from - ____ _ - | _ \ _ _| | _____ - | | | | | | | |/ / _ \ - | |_| | |_| | < __/ - |____/ \__,_|_|\_\___| - ``` +# User Guide +Duke is a **desktop app for tracking tasks, +optimized for use via a Command Line Interface** (CLI). +As Duke is designed to be use in a CLI, this +application would benefit users who are able to type fast. + +## Quick Start +1. Ensure you have Java 11 or above installed on your Computer +2. Download the latest JAR file from GitHub. +3. Copy the file to the folder you want to use as the home folder for your Duke application. + Note that the data file would also be created in the same folder. +4. Open the CLI at where you have placed the jar file and run it using the command + `java -jar ip.jar` +5. Type the commands in the box and press enter to execute it. + Here are some commands you can try: + - `list` : List all current tasks. + - `todo Read Book` : Adds a todo task of reading book. + - `delete 1` : Deletes the first task from list. +### Feature list: +* Listing all tasks: `list` +* Adding a new task: + * Todo task: `todo` + * Deadline task: `deadline` + * Event task: `event` +* Marking a task as done: `mark` +* Marking a task as not done: `unmark` +* Deleting a task: `delete` +* Finding a task: `find` +* Exiting the program: `bye` + +## Feature +### Adding a Task +There are three kinds of Tasks: Todos, Deadlines, and Events. +### Adding a Todo +Adds a Todo to the list of tasks.
+Format: `todo DESCRIPTION`
+Words in `UPPER_CASE` are the parameters.
+Examples: +* todo buy sunscreen +* todo buy bubble tea + +### Adding a Deadline +Adds a Deadline to the list of tasks.
+Format: `deadline DESCRIPTION /by DEADLINE`
+Words in `UPPER_CASE` are the parameters.
+Examples:
+* deadline finish econometrics problem set /by Saturday +* deadine return book /by Sunday 12:30PM + +### Adding an Event +Adds an Event to the list of tasks.
+Format: `event DESCRIPTION /at TIME`
+Words in `UPPER_CASE` are the parameters.
+Examples:
+* event project meeting /at Saturday 8:00PM +* event attend CS2113 lecture /at Friday 4:00PM + +### Listing all Tasks +Displays all tasks that the user has added to their list.
+Format: `list`
+Output could look like the following:
+``` + 1: [T][ ] go shopping + 2: [D][ ] finish 2113 iP (by: Friday) + 3: [E][ ] 2113 project meeting (at: Monday 1:00PM) + ``` +`T` denotes a task of type Todo, `D` denotes a task of type Deadline, and `E` denotes a task of type Event. + +### Marking a Task as complete +You have the option of marking (i.e. checking off) a task that has been completed.
+Format: `mark TASK_NUMBER`
+`TASK_NUMBER` is the numerical label assigned to the task (that you can find from the output of the `list` command).
+Example:
+Assuming the following task list:
+``` + 1: [T][ ] go shopping + 2: [D][ ] finish 2113 iP (by: Friday) + 3: [E][ ] 2113 project meeting (at: Monday 1:00PM) +``` +`mark 2` would result in the following list:
+``` + 1: [T][ ] go shopping + 2: [D][X] finish 2113 iP (by: Friday) + 3: [E][ ] 2113 project meeting (at: Monday 1:00PM) +``` + +### Unmarking a Task +Alternatively, you may also unmark a task that has previously been marked.
+Format: `unmark TASK_NUMBER`
+Example:
+Assuming the following task list:
+``` + 1: [T][ ] go shopping + 2: [D][ ] finish 2113 iP (by: Friday) + 3: [E][X] 2113 project meeting (at: Monday 1:00PM) +``` +`unmark 3` would result in the following list:
+``` + 1: [T][ ] go shopping + 2: [D][ ] finish 2113 iP (by: Friday) + 3: [E][ ] 2113 project meeting (at: Monday 1:00PM) +``` + +### Deleting a Task +Users may also delete a task from the list of tasks.
+Format `delete TASK_NUMBER`
+Example:
+Assuming the following task list:
+``` + 1: [T][ ] go shopping + 2: [D][ ] finish 2113 iP (by: Friday) + 3: [E][ ] 2113 project meeting (at: Monday 1:00PM) +``` +`delete 2` would result in the following list:
+``` + 1: [T][ ] go shopping + 2: [E][ ] 2113 project meeting (at: Monday 1:00PM) +``` + + +### Finding a Task +Users can search for Tasks in their task list with a specific keywords.
+Format `find KEYWORD`
+Example:
+Assuming the following task list:
+``` + 1: [T][ ] go shopping + 2: [D][ ] finish 2113 iP (by: Friday) + 3: [E][X] 2113 project meeting (at: Monday 1:00PM) +``` +`find 2113` would result in the following list:
+``` + 1: [T][ ] go shopping + 2: [D][ ] finish 2113 iP (by: Friday) + 3: [E][ ] 2113 project meeting (at: Monday 1:00PM) + ``` \ No newline at end of file From d5cfae6f8af2e1097d931d847a83d498c7cdebf6 Mon Sep 17 00:00:00 2001 From: striris <72813713+striris@users.noreply.github.com> Date: Fri, 4 Mar 2022 00:08:58 +0800 Subject: [PATCH 17/28] Set theme jekyll-theme-dinky --- docs/_config.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/_config.yml diff --git a/docs/_config.yml b/docs/_config.yml new file mode 100644 index 000000000..9da9a0291 --- /dev/null +++ b/docs/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-dinky \ No newline at end of file From d37e92644eee1fdea0fbd0b9cc53d757ad09dd65 Mon Sep 17 00:00:00 2001 From: striris Date: Fri, 4 Mar 2022 00:16:23 +0800 Subject: [PATCH 18/28] code quality --- data/duke.txt | 7 +++---- src/main/java/duke/Ui.java | 2 +- src/main/java/duke/tasks/Deadline.java | 2 -- src/main/java/duke/tasks/Event.java | 2 +- src/main/java/duke/tasks/TaskList.java | 2 -- 5 files changed, 5 insertions(+), 10 deletions(-) diff --git a/data/duke.txt b/data/duke.txt index 2a95727b4..1413de65a 100644 --- a/data/duke.txt +++ b/data/duke.txt @@ -1,4 +1,3 @@ -T | 1 | what -D | 1 | ddl1 | June -E | 0 | EVENT1 | noon -D | 0 | ddl2 | 6.7 +T | 1 | go shopping +D | 1 | finish 2113 iP | Friday +E | 0 | 2113 project meeting | Monday 1:00PM diff --git a/src/main/java/duke/Ui.java b/src/main/java/duke/Ui.java index 8ffb2a11e..04ca6eb77 100644 --- a/src/main/java/duke/Ui.java +++ b/src/main/java/duke/Ui.java @@ -6,7 +6,7 @@ public class Ui { public static void greeting() { String greeting = "----------------------------------------------\n" - + "Hello! I'm Duke.Duke\n" + + "Hello! Duke here!!\n" + "What can I do for you?\n" + "----------------------------------------------\n"; System.out.println(greeting); diff --git a/src/main/java/duke/tasks/Deadline.java b/src/main/java/duke/tasks/Deadline.java index 1002f4966..a7692c2ae 100644 --- a/src/main/java/duke/tasks/Deadline.java +++ b/src/main/java/duke/tasks/Deadline.java @@ -24,5 +24,3 @@ public String saveTasks() { return "D " + super.saveTasks() + " | " + this.by + System.lineSeparator(); } } - -//this.description = description.substring(0, description.lastIndexOf("/") + 4); diff --git a/src/main/java/duke/tasks/Event.java b/src/main/java/duke/tasks/Event.java index 4fb214de9..ab3133dcc 100644 --- a/src/main/java/duke/tasks/Event.java +++ b/src/main/java/duke/tasks/Event.java @@ -18,4 +18,4 @@ public String toString() { public String saveTasks() { return "E " + super.saveTasks() + " | " + this.at + System.lineSeparator(); } -} \ No newline at end of file +} diff --git a/src/main/java/duke/tasks/TaskList.java b/src/main/java/duke/tasks/TaskList.java index 619f90df6..685bdb590 100644 --- a/src/main/java/duke/tasks/TaskList.java +++ b/src/main/java/duke/tasks/TaskList.java @@ -130,7 +130,5 @@ private static void findTask(String keyWord) { if(i == 1) { System.out.println("The keyword doesn't exist in task descriptions, try other keyword please :)"); } - } - } From b86f4abf543aaa3a55dc09dba8cbe071a8a7b854 Mon Sep 17 00:00:00 2001 From: striris Date: Fri, 4 Mar 2022 00:27:41 +0800 Subject: [PATCH 19/28] deleted Main class because it's reductant. --- src/main/java/duke/Duke.java | 4 ++++ src/main/java/duke/Main.java | 9 --------- 2 files changed, 4 insertions(+), 9 deletions(-) delete mode 100644 src/main/java/duke/Main.java diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 7f52af062..069b51b36 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -28,4 +28,8 @@ public void run() throws IOException { private static void startBot() throws IOException { taskList.processTasks(); } + + public static void main(String[] args) throws IOException { + new Duke("data/duke.txt").run(); + } } diff --git a/src/main/java/duke/Main.java b/src/main/java/duke/Main.java deleted file mode 100644 index 4251c0f70..000000000 --- a/src/main/java/duke/Main.java +++ /dev/null @@ -1,9 +0,0 @@ -package duke; - -import java.io.IOException; - -public class Main { - public static void main(String[] args) throws IOException { - new Duke("data/duke.txt").run(); - } -} From 2b642befe26a3f3d6db7269373a0a06de3057b97 Mon Sep 17 00:00:00 2001 From: striris Date: Fri, 4 Mar 2022 15:08:23 +0800 Subject: [PATCH 20/28] minor changes --- docs/README.md | 139 ++++++++++++++++++++++--- src/main/java/duke/tasks/TaskList.java | 2 +- 2 files changed, 124 insertions(+), 17 deletions(-) diff --git a/docs/README.md b/docs/README.md index 8077118eb..5624bc29f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,29 +1,136 @@ # User Guide +Duke is a **desktop app for tracking tasks, +optimized for use via a Command Line Interface** (CLI). +As Duke is designed to be use in a CLI, this +application would benefit users who are able to type fast. -## Features +## Quick Start +1. Ensure you have Java 11 or above installed on your Computer +2. Download the latest JAR file from GitHub. +3. Copy the file to the folder you want to use as the home folder for your Duke application. + Note that the data file would also be created in the same folder. +4. Open the CLI at where you have placed the jar file and run it using the command + `java -jar ip.jar` +5. Type the commands in the box and press enter to execute it. + Here are some commands you can try: + - `list` : List all current tasks. + - `todo Read Book` : Adds a todo task of reading book. + - `delete 1` : Deletes the first task from list. +### Feature list: +* Listing all tasks: `list` +* Adding a new task: + * Todo task: `todo` + * Deadline task: `deadline` + * Event task: `event` +* Marking a task as done: `mark` +* Marking a task as not done: `unmark` +* Deleting a task: `delete` +* Finding a task: `find` +* Exiting the program: `bye` -### Feature-ABC +## Feature +### Adding a Task +There are three kinds of Tasks: Todos, Deadlines, and Events. +### Adding a Todo +Adds a Todo to the list of tasks.
+Format: `todo DESCRIPTION`
+Words in `UPPER_CASE` are the parameters.
+Examples: +* todo buy sunscreen +* todo buy bubble tea -Description of the feature. +### Adding a Deadline +Adds a Deadline to the list of tasks.
+Format: `deadline DESCRIPTION /by DEADLINE`
+Words in `UPPER_CASE` are the parameters.
+Examples:
+* deadline finish econometrics problem set /by Saturday +* deadine return book /by Sunday 12:30PM -### Feature-XYZ +### Adding an Event +Adds an Event to the list of tasks.
+Format: `event DESCRIPTION /at TIME`
+Words in `UPPER_CASE` are the parameters.
+Examples:
+* event project meeting /at Saturday 8:00PM +* event attend CS2113 lecture /at Friday 4:00PM -Description of the feature. - -## Usage - -### `Keyword` - Describe action - -Describe the action and its outcome. +### Listing all Tasks +Displays all tasks that the user has added to their list.
+Format: `list`
+Output could look like the following:
+``` + 1: [T][ ] go shopping + 2: [D][ ] finish 2113 iP (by: Friday) + 3: [E][ ] 2113 project meeting (at: Monday 1:00PM) + ``` +`T` denotes a task of type Todo, `D` denotes a task of type Deadline, and `E` denotes a task of type Event. -Example of usage: +### Marking a Task as complete +You have the option of marking (i.e. checking off) a task that has been completed.
+Format: `mark TASK_NUMBER`
+`TASK_NUMBER` is the numerical label assigned to the task (that you can find from the output of the `list` command).
+Example:
+Assuming the following task list:
+``` + 1: [T][ ] go shopping + 2: [D][ ] finish 2113 iP (by: Friday) + 3: [E][ ] 2113 project meeting (at: Monday 1:00PM) +``` +`mark 2` would result in the following list:
+``` + 1: [T][ ] go shopping + 2: [D][X] finish 2113 iP (by: Friday) + 3: [E][ ] 2113 project meeting (at: Monday 1:00PM) +``` -`keyword (optional arguments)` +### Unmarking a Task +Alternatively, you may also unmark a task that has previously been marked.
+Format: `unmark TASK_NUMBER`
+Example:
+Assuming the following task list:
+``` + 1: [T][ ] go shopping + 2: [D][ ] finish 2113 iP (by: Friday) + 3: [E][X] 2113 project meeting (at: Monday 1:00PM) +``` +`unmark 3` would result in the following list:
+``` + 1: [T][ ] go shopping + 2: [D][ ] finish 2113 iP (by: Friday) + 3: [E][ ] 2113 project meeting (at: Monday 1:00PM) +``` -Expected outcome: +### Deleting a Task +Users may also delete a task from the list of tasks.
+Format `delete TASK_NUMBER`
+Example:
+Assuming the following task list:
+``` + 1: [T][ ] go shopping + 2: [D][ ] finish 2113 iP (by: Friday) + 3: [E][ ] 2113 project meeting (at: Monday 1:00PM) +``` +`delete 2` would result in the following list:
+``` + 1: [T][ ] go shopping + 2: [E][ ] 2113 project meeting (at: Monday 1:00PM) +``` -Description of the outcome. +### Finding a Task +Users can search for Tasks in their task list with a specific keywords.
+Format `find KEYWORD`
+Example:
+Assuming the following task list:
+``` + 1: [T][ ] go shopping + 2: [D][ ] finish 2113 iP (by: Friday) + 3: [E][X] 2113 project meeting (at: Monday 1:00PM) ``` -expected output +`find 2113` would result in the following list:
``` + 1: [T][ ] go shopping + 2: [D][ ] finish 2113 iP (by: Friday) + 3: [E][ ] 2113 project meeting (at: Monday 1:00PM) + ``` \ No newline at end of file diff --git a/src/main/java/duke/tasks/TaskList.java b/src/main/java/duke/tasks/TaskList.java index 685bdb590..417c1f099 100644 --- a/src/main/java/duke/tasks/TaskList.java +++ b/src/main/java/duke/tasks/TaskList.java @@ -80,7 +80,7 @@ else if(choice.equals("find")) { findTask(keyWord); } else{ - System.out.println("I don't understand D:"); + System.out.println("I don't understand D: Please key in again!"); } System.out.println("----------------------------------------------"); } From b10c45ca78ec432d860dc395999571bf257619bb Mon Sep 17 00:00:00 2001 From: striris Date: Fri, 4 Mar 2022 15:15:03 +0800 Subject: [PATCH 21/28] modified user guide --- docs/README.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/docs/README.md b/docs/README.md index 5624bc29f..326ae15e3 100644 --- a/docs/README.md +++ b/docs/README.md @@ -18,10 +18,9 @@ application would benefit users who are able to type fast. - `delete 1` : Deletes the first task from list. ### Feature list: * Listing all tasks: `list` -* Adding a new task: - * Todo task: `todo` - * Deadline task: `deadline` - * Event task: `event` +* Adding a new Todo task: `todo` +* Adding a new Deadline task: `deadline` +* Adding a new Event task: `event` * Marking a task as done: `mark` * Marking a task as not done: `unmark` * Deleting a task: `delete` @@ -36,16 +35,16 @@ Adds a Todo to the list of tasks.
Format: `todo DESCRIPTION`
Words in `UPPER_CASE` are the parameters.
Examples: -* todo buy sunscreen -* todo buy bubble tea +* todo go to class +* todo buy fruits ### Adding a Deadline Adds a Deadline to the list of tasks.
Format: `deadline DESCRIPTION /by DEADLINE`
Words in `UPPER_CASE` are the parameters.
Examples:
-* deadline finish econometrics problem set /by Saturday -* deadine return book /by Sunday 12:30PM +* deadline finish problem set /by Saturday +* deadine return book /by Sunday ### Adding an Event Adds an Event to the list of tasks.
From d4973266a177f7a725a55d8aeabb0718f9722b70 Mon Sep 17 00:00:00 2001 From: striris Date: Fri, 4 Mar 2022 15:44:02 +0800 Subject: [PATCH 22/28] added try and catch --- src/main/java/duke/Ui.java | 2 +- src/main/java/duke/tasks/TaskList.java | 39 ++++++++++++++++++-------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/main/java/duke/Ui.java b/src/main/java/duke/Ui.java index 04ca6eb77..a0bc34063 100644 --- a/src/main/java/duke/Ui.java +++ b/src/main/java/duke/Ui.java @@ -6,7 +6,7 @@ public class Ui { public static void greeting() { String greeting = "----------------------------------------------\n" - + "Hello! Duke here!!\n" + + "Hello! Duke here :)\n" + "What can I do for you?\n" + "----------------------------------------------\n"; System.out.println(greeting); diff --git a/src/main/java/duke/tasks/TaskList.java b/src/main/java/duke/tasks/TaskList.java index 417c1f099..04d04f3f3 100644 --- a/src/main/java/duke/tasks/TaskList.java +++ b/src/main/java/duke/tasks/TaskList.java @@ -80,7 +80,7 @@ else if(choice.equals("find")) { findTask(keyWord); } else{ - System.out.println("I don't understand D: Please key in again!"); + System.out.println("I don't understand D: Please key in your command again!"); } System.out.println("----------------------------------------------"); } @@ -93,15 +93,25 @@ public void listTask() { } private static void markTask(int taskIndex) { - System.out.println("Nice! I've marked this task as done:"); - tasks.get(taskIndex-1).markAsDone(); - System.out.println(tasks.get(taskIndex-1)); + try { + tasks.get(taskIndex-1).markAsDone(); + System.out.println("Nice! I've marked this task as done:"); + System.out.println(tasks.get(taskIndex-1)); + } + catch (IndexOutOfBoundsException e) { + System.out.println("This index is not within the range :( Try again!"); + } } private static void unmarkTask(int taskIndex) { - System.out.println("OK, I've marked this task as not done yet:"); - tasks.get(taskIndex-1).markAsNotDone(); - System.out.println(tasks.get(taskIndex-1)); + try { + tasks.get(taskIndex-1).markAsNotDone(); + System.out.println("OK, I've marked this task as not done yet:"); + System.out.println(tasks.get(taskIndex-1)); + } + catch (IndexOutOfBoundsException e) { + System.out.println("This index is not within the range :( Try again!"); + } } private static void addTask(Task t) { @@ -112,10 +122,17 @@ private static void addTask(Task t) { } private static void deleteTask(int taskIndex) { - System.out.println("Noted. I've removed this task:"); - System.out.println(tasks.get(taskIndex -1)); - tasks.remove(taskIndex -1); - System.out.println("Now you have " + tasks.size() + " tasks in the list."); + try{ + Task deletedTask = tasks.get(taskIndex -1); + tasks.remove(taskIndex -1); + System.out.println("Noted. I've removed this task:"); + System.out.println(deletedTask); + System.out.println("Now you have " + tasks.size() + " tasks in the list."); + } + catch (IndexOutOfBoundsException e) { + System.out.println("This index is not within the range :( Try again!"); + } + } private static void findTask(String keyWord) { From 0198f4c976dc611c08fb91aa19c956d440a5c719 Mon Sep 17 00:00:00 2001 From: striris Date: Tue, 22 Mar 2022 22:47:29 +0800 Subject: [PATCH 23/28] Used Ui to print error messages. --- src/main/java/duke/Ui.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/duke/Ui.java b/src/main/java/duke/Ui.java index a0bc34063..87edab0ed 100644 --- a/src/main/java/duke/Ui.java +++ b/src/main/java/duke/Ui.java @@ -22,4 +22,24 @@ public static String getInput() { String userInput = sc.nextLine(); return userInput; } + + public static void printDeadlineErrorMsg() { + System.out.println("Invalid input format. Please use /by for deadline."); + } + + public static void printEventErrorMsg() { + System.out.println("Invalid input format. Please use /at for event."); + } + + public static void printCommandErrorMsg() { + System.out.println("I don't understand D: Please key in your command again!"); + } + + public static void printIndexOutOfBoundMsg() { + System.out.println("This index is not within the range :( Try again!"); + } + + public static void printKeyWordMsg() { + System.out.println("The keyword doesn't exist in task descriptions, try other keyword please :)"); + } } From 62043477b20acdf40cff5cfbee4e5c493937f6e2 Mon Sep 17 00:00:00 2001 From: striris Date: Tue, 22 Mar 2022 22:48:31 +0800 Subject: [PATCH 24/28] change if statement to switch statement and fixed the event without statement error bug by try and catch block. --- src/main/java/duke/tasks/TaskList.java | 115 ++++++++++++++----------- 1 file changed, 65 insertions(+), 50 deletions(-) diff --git a/src/main/java/duke/tasks/TaskList.java b/src/main/java/duke/tasks/TaskList.java index 04d04f3f3..c2a236e5c 100644 --- a/src/main/java/duke/tasks/TaskList.java +++ b/src/main/java/duke/tasks/TaskList.java @@ -35,52 +35,64 @@ public void processTasks() throws IOException { while(true){ String userInput = Ui.getInput(); String choice = userInput.split(" ")[0]; - System.out.println("----------------------------------------------"); - if(userInput.equals("bye")) { - Storage.saveFile(tasks); - break; - } - else if(userInput.equals("list")) { - listTask(); - } - else if(choice.equals("mark")) { - int taskIndex = Integer.parseInt(userInput.split(" ")[1]); - markTask(taskIndex); - } - else if(choice.equals("unmark")) { - int taskIndex = Integer.parseInt(userInput.split(" ")[1]); - unmarkTask(taskIndex); - } - else if(choice.equals("todo")) { - String toDoDescription = userInput.split("todo")[1].trim(); - Task t = new ToDo(toDoDescription, false); - addTask(t); - } - else if(choice.equals("deadline")) { - String[] input = userInput.split("/by"); - by = input[1].trim(); - String deadlineDescription = input[0].split("deadline")[1].trim(); - Task d = new Deadline(deadlineDescription, false, by); - addTask(d); - } - else if(choice.equals("event")) { - String[] input = userInput.split("/at"); - at = input[1].trim(); - String eventDescription = input[0].split("event")[1].trim(); - Task e = new Event(eventDescription, false, at); - addTask(e); - } - else if(choice.equals("delete")) { - int taskIndex = Integer.parseInt(userInput.split(" ")[1]); - deleteTask(taskIndex); - } - else if(choice.equals("find")) { - String keyWord = userInput.split(" ")[1]; - findTask(keyWord); - } - else{ - System.out.println("I don't understand D: Please key in your command again!"); + switch (choice) { + case "bye": + Storage.saveFile(tasks); + break; + case "list": + listTask(); + break; + case "delete": + int taskIndexDelete = Integer.parseInt(userInput.replace("delete","").trim()); + deleteTask(taskIndexDelete); + break; + case "find": + String keyWord = userInput.replace("find","").trim(); + findTask(keyWord); + break; + case "mark": + int taskIndexMark = Integer.parseInt(userInput.replace("mark","").trim()); + markTask(taskIndexMark); + break; + case "unmark": + int taskIndexUnmark = Integer.parseInt(userInput.replace("unmark","").trim()); + unmarkTask(taskIndexUnmark); + break; + case "todo": + String toDoDescription = userInput.replace("todo","").trim(); + Task t = new ToDo(toDoDescription, false); + addTask(t); + break; + case "deadline": + String deadlineDescription = userInput.replace("deadline","").trim(); + String[] parsedDeadlineInput = deadlineDescription.split("/by"); + try { + by = parsedDeadlineInput[1].trim(); + deadlineDescription = parsedDeadlineInput[0].trim(); + Task d = new Deadline(deadlineDescription, false, by); + addTask(d); + } + catch (ArrayIndexOutOfBoundsException e) { + Ui.printDeadlineErrorMsg(); + } + break; + case "event": + String eventDescription = userInput.replace("event","").trim(); + String[] parsedEventInput = eventDescription.split("/at"); + try { + at = parsedEventInput[1].trim(); + eventDescription = parsedEventInput[0].trim(); + Task e = new Event(eventDescription, false, at); + addTask(e); + } + catch (ArrayIndexOutOfBoundsException e) { + Ui.printEventErrorMsg(); + } + break; + default: + Ui.printCommandErrorMsg(); + break; } System.out.println("----------------------------------------------"); } @@ -99,7 +111,7 @@ private static void markTask(int taskIndex) { System.out.println(tasks.get(taskIndex-1)); } catch (IndexOutOfBoundsException e) { - System.out.println("This index is not within the range :( Try again!"); + Ui.printIndexOutOfBoundMsg(); } } @@ -110,7 +122,7 @@ private static void unmarkTask(int taskIndex) { System.out.println(tasks.get(taskIndex-1)); } catch (IndexOutOfBoundsException e) { - System.out.println("This index is not within the range :( Try again!"); + Ui.printIndexOutOfBoundMsg(); } } @@ -130,22 +142,25 @@ private static void deleteTask(int taskIndex) { System.out.println("Now you have " + tasks.size() + " tasks in the list."); } catch (IndexOutOfBoundsException e) { - System.out.println("This index is not within the range :( Try again!"); + Ui.printIndexOutOfBoundMsg(); } } private static void findTask(String keyWord) { - System.out.println("Here are the matching tasks in your list:"); + int i = 1; for(Task t: tasks) { if(t.description.contains(keyWord)){ + if(i == 1) { + System.out.println("Here are the matching tasks in your list:"); + } System.out.println(i +"."+ t); i++; } } if(i == 1) { - System.out.println("The keyword doesn't exist in task descriptions, try other keyword please :)"); + Ui.printKeyWordMsg(); } } } From 64fc037b05324f15031149b898f2e987c45af331 Mon Sep 17 00:00:00 2001 From: striris Date: Tue, 22 Mar 2022 22:57:49 +0800 Subject: [PATCH 25/28] Modified the code such that the file will get updated after every Command. --- src/main/java/duke/tasks/TaskList.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/duke/tasks/TaskList.java b/src/main/java/duke/tasks/TaskList.java index c2a236e5c..39e96aae9 100644 --- a/src/main/java/duke/tasks/TaskList.java +++ b/src/main/java/duke/tasks/TaskList.java @@ -36,10 +36,11 @@ public void processTasks() throws IOException { String userInput = Ui.getInput(); String choice = userInput.split(" ")[0]; System.out.println("----------------------------------------------"); + if (choice.equals("bye")) { + Storage.saveFile(tasks); + break; + } switch (choice) { - case "bye": - Storage.saveFile(tasks); - break; case "list": listTask(); break; @@ -94,6 +95,7 @@ public void processTasks() throws IOException { Ui.printCommandErrorMsg(); break; } + Storage.saveFile(tasks); System.out.println("----------------------------------------------"); } } From 7da23ce49a4fc32d91ce76a1b22149a3fc2efb84 Mon Sep 17 00:00:00 2001 From: striris Date: Tue, 22 Mar 2022 23:05:13 +0800 Subject: [PATCH 26/28] Added more JavaDoc for functions and classes --- src/main/java/duke/Ui.java | 3 +++ src/main/java/duke/tasks/Event.java | 3 +++ src/main/java/duke/tasks/TaskList.java | 8 ++++++++ src/main/java/duke/tasks/ToDo.java | 3 +++ 4 files changed, 17 insertions(+) diff --git a/src/main/java/duke/Ui.java b/src/main/java/duke/Ui.java index 87edab0ed..32135aacd 100644 --- a/src/main/java/duke/Ui.java +++ b/src/main/java/duke/Ui.java @@ -2,6 +2,9 @@ import java.util.Scanner; +/** + * Create a UI for displaying message + */ public class Ui { public static void greeting() { diff --git a/src/main/java/duke/tasks/Event.java b/src/main/java/duke/tasks/Event.java index ab3133dcc..be80d2b1c 100644 --- a/src/main/java/duke/tasks/Event.java +++ b/src/main/java/duke/tasks/Event.java @@ -1,5 +1,8 @@ package duke.tasks; +/** + * Represents an Event Task + */ public class Event extends Task { protected String at; diff --git a/src/main/java/duke/tasks/TaskList.java b/src/main/java/duke/tasks/TaskList.java index 39e96aae9..4e85db14f 100644 --- a/src/main/java/duke/tasks/TaskList.java +++ b/src/main/java/duke/tasks/TaskList.java @@ -20,6 +20,10 @@ public TaskList(Storage storage) { this.storage = storage; } + /** + * Load the Task List from the file. + * @throws IOException + */ public void loadTaskList() throws IOException { try { tasks = storage.loadFile(); @@ -28,6 +32,10 @@ public void loadTaskList() throws IOException { } } + /** + * Process Tasks after parsing it and use the command accordingly. + * @throws IOException + */ public void processTasks() throws IOException { String by = new String(); String at = new String(); diff --git a/src/main/java/duke/tasks/ToDo.java b/src/main/java/duke/tasks/ToDo.java index c2b0fb4b2..0ad6f1ae7 100644 --- a/src/main/java/duke/tasks/ToDo.java +++ b/src/main/java/duke/tasks/ToDo.java @@ -1,5 +1,8 @@ package duke.tasks; +/** + * Represents a ToDo Task + */ public class ToDo extends Task { public ToDo(String description, boolean isDone) { From 18e39e7d852bb1447b36976182f5cff5a7110180 Mon Sep 17 00:00:00 2001 From: striris Date: Tue, 22 Mar 2022 23:17:24 +0800 Subject: [PATCH 27/28] Fixed number format bug for delete and mark function. --- src/main/java/duke/Ui.java | 4 ++++ src/main/java/duke/tasks/TaskList.java | 27 ++++++++++++++++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/main/java/duke/Ui.java b/src/main/java/duke/Ui.java index 32135aacd..4b508186f 100644 --- a/src/main/java/duke/Ui.java +++ b/src/main/java/duke/Ui.java @@ -45,4 +45,8 @@ public static void printIndexOutOfBoundMsg() { public static void printKeyWordMsg() { System.out.println("The keyword doesn't exist in task descriptions, try other keyword please :)"); } + + public static void printNumberFormatMsg() { + System.out.println("You didn't input a valid number, please try again!"); + } } diff --git a/src/main/java/duke/tasks/TaskList.java b/src/main/java/duke/tasks/TaskList.java index 4e85db14f..d36466ed0 100644 --- a/src/main/java/duke/tasks/TaskList.java +++ b/src/main/java/duke/tasks/TaskList.java @@ -53,20 +53,35 @@ public void processTasks() throws IOException { listTask(); break; case "delete": - int taskIndexDelete = Integer.parseInt(userInput.replace("delete","").trim()); - deleteTask(taskIndexDelete); + try{ + int taskIndexDelete = Integer.parseInt(userInput.replace("delete","").trim()); + deleteTask(taskIndexDelete); + } + catch (NumberFormatException e) { + Ui.printNumberFormatMsg(); + } break; case "find": String keyWord = userInput.replace("find","").trim(); findTask(keyWord); break; case "mark": - int taskIndexMark = Integer.parseInt(userInput.replace("mark","").trim()); - markTask(taskIndexMark); + try { + int taskIndexMark = Integer.parseInt(userInput.replace("mark","").trim()); + markTask(taskIndexMark); + } + catch (NumberFormatException e) { + Ui.printNumberFormatMsg(); + } break; case "unmark": - int taskIndexUnmark = Integer.parseInt(userInput.replace("unmark","").trim()); - unmarkTask(taskIndexUnmark); + try { + int taskIndexUnmark = Integer.parseInt(userInput.replace("unmark","").trim()); + unmarkTask(taskIndexUnmark); + } + catch (NumberFormatException e) { + Ui.printNumberFormatMsg(); + } break; case "todo": String toDoDescription = userInput.replace("todo","").trim(); From ae479ff771df7fe3ae67234d15d85c59c72d0590 Mon Sep 17 00:00:00 2001 From: striris Date: Tue, 22 Mar 2022 23:26:29 +0800 Subject: [PATCH 28/28] Made it compulsary to have description for each task. --- src/main/java/duke/Ui.java | 4 ++++ src/main/java/duke/tasks/TaskList.java | 27 ++++++++++++++++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/main/java/duke/Ui.java b/src/main/java/duke/Ui.java index 4b508186f..f0188c385 100644 --- a/src/main/java/duke/Ui.java +++ b/src/main/java/duke/Ui.java @@ -49,4 +49,8 @@ public static void printKeyWordMsg() { public static void printNumberFormatMsg() { System.out.println("You didn't input a valid number, please try again!"); } + + public static void printDescriptionMissingMsg() { + System.out.println("Please input some description for this Task!"); + } } diff --git a/src/main/java/duke/tasks/TaskList.java b/src/main/java/duke/tasks/TaskList.java index d36466ed0..0cc94c2cc 100644 --- a/src/main/java/duke/tasks/TaskList.java +++ b/src/main/java/duke/tasks/TaskList.java @@ -85,8 +85,13 @@ public void processTasks() throws IOException { break; case "todo": String toDoDescription = userInput.replace("todo","").trim(); - Task t = new ToDo(toDoDescription, false); - addTask(t); + if (toDoDescription.equals("")) { + Ui.printDescriptionMissingMsg(); + } + else { + Task t = new ToDo(toDoDescription, false); + addTask(t); + } break; case "deadline": String deadlineDescription = userInput.replace("deadline","").trim(); @@ -94,8 +99,13 @@ public void processTasks() throws IOException { try { by = parsedDeadlineInput[1].trim(); deadlineDescription = parsedDeadlineInput[0].trim(); - Task d = new Deadline(deadlineDescription, false, by); - addTask(d); + if (deadlineDescription.equals("")) { + Ui.printDescriptionMissingMsg(); + } + else { + Task d = new Deadline(deadlineDescription, false, by); + addTask(d); + } } catch (ArrayIndexOutOfBoundsException e) { Ui.printDeadlineErrorMsg(); @@ -107,8 +117,13 @@ public void processTasks() throws IOException { try { at = parsedEventInput[1].trim(); eventDescription = parsedEventInput[0].trim(); - Task e = new Event(eventDescription, false, at); - addTask(e); + if (eventDescription.equals("")) { + Ui.printDescriptionMissingMsg(); + } + else { + Task e = new Event(eventDescription, false, at); + addTask(e); + } } catch (ArrayIndexOutOfBoundsException e) { Ui.printEventErrorMsg();