From beabdec84efdcb4b894f8a58ab00e95ef2fe61e8 Mon Sep 17 00:00:00 2001 From: kestryix Date: Fri, 23 Aug 2024 15:15:06 +0800 Subject: [PATCH 01/17] Rename, greet, exit --- src/main/java/Duke.java | 10 ---------- src/main/java/TulipTask.java | 27 +++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 10 deletions(-) delete mode 100644 src/main/java/Duke.java create mode 100644 src/main/java/TulipTask.java diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java deleted file mode 100644 index 5d313334c..000000000 --- a/src/main/java/Duke.java +++ /dev/null @@ -1,10 +0,0 @@ -public class Duke { - public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - } -} diff --git a/src/main/java/TulipTask.java b/src/main/java/TulipTask.java new file mode 100644 index 000000000..9227179dc --- /dev/null +++ b/src/main/java/TulipTask.java @@ -0,0 +1,27 @@ +import java.util.ArrayList; +import java.util.Objects; +import java.util.Scanner; + +public class TulipTask { + public static void main(String[] args) { + String logo = " \n" + + "--.-- | o --.-- | \n" + + " | . .| .,---. | ,---.,---.|__/ \n" + + " | | || || | | ,---|`---.| \\ \n" + + " ` `---'`---'`|---' ` `---^`---'` `\n" + + " |"; + + ArrayList list = new ArrayList(); + + System.out.println(logo); + + System.out.println("--------------------------------------------"); + System.out.println("Hello, I'm TulipTask"); + System.out.println("What can I do for you today?"); + System.out.println("--------------------------------------------"); + + System.out.println("Bye! Hope to see you again soon :)"); + System.out.println("--------------------------------------------"); + + } +} From d4e2c74a42581f133982d7e427d3ff310840edd9 Mon Sep 17 00:00:00 2001 From: kestryix Date: Wed, 28 Aug 2024 15:07:49 +0800 Subject: [PATCH 02/17] echo --- src/main/java/TulipTask.java | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/TulipTask.java b/src/main/java/TulipTask.java index 9227179dc..8e0463b13 100644 --- a/src/main/java/TulipTask.java +++ b/src/main/java/TulipTask.java @@ -11,8 +11,6 @@ public static void main(String[] args) { " ` `---'`---'`|---' ` `---^`---'` `\n" + " |"; - ArrayList list = new ArrayList(); - System.out.println(logo); System.out.println("--------------------------------------------"); @@ -20,8 +18,26 @@ public static void main(String[] args) { System.out.println("What can I do for you today?"); System.out.println("--------------------------------------------"); + while (true) { + Scanner scanner = new Scanner(System.in); + String input = scanner.nextLine(); + + if (Objects.equals(input.toLowerCase(), "bye")) { + break; + } + + echo(input); + } + + System.out.println("--------------------------------------------"); System.out.println("Bye! Hope to see you again soon :)"); System.out.println("--------------------------------------------"); } + + public static void echo (String input) { + System.out.println("--------------------------------------------"); + System.out.println(input); + System.out.println("--------------------------------------------"); + } } From d9c8a222696f98795715cd160577b9d25c9e7673 Mon Sep 17 00:00:00 2001 From: kestryix Date: Wed, 28 Aug 2024 15:10:52 +0800 Subject: [PATCH 03/17] add, list --- src/main/java/TulipTask.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/TulipTask.java b/src/main/java/TulipTask.java index 8e0463b13..cd1285a2b 100644 --- a/src/main/java/TulipTask.java +++ b/src/main/java/TulipTask.java @@ -11,6 +11,8 @@ public static void main(String[] args) { " ` `---'`---'`|---' ` `---^`---'` `\n" + " |"; + ArrayList list = new ArrayList(); + System.out.println(logo); System.out.println("--------------------------------------------"); @@ -26,6 +28,12 @@ public static void main(String[] args) { break; } + if (Objects.equals(input.toLowerCase(), "list")) { + for (int i = 0; i < list.size(); i++) { + System.out.println((i + 1) + ". " + list.get(i)); + } + } + list.add(input); echo(input); } @@ -37,7 +45,7 @@ public static void main(String[] args) { public static void echo (String input) { System.out.println("--------------------------------------------"); - System.out.println(input); + System.out.println("added: " + input); System.out.println("--------------------------------------------"); } } From 9e3f1f9dcbb7e0f2cc7d79dd522040ce76bdb51c Mon Sep 17 00:00:00 2001 From: kestryix Date: Wed, 28 Aug 2024 16:01:23 +0800 Subject: [PATCH 04/17] mark as done --- src/main/java/Task.java | 21 +++++++++ src/main/java/TulipTask.java | 84 ++++++++++++++++++++++++++++++------ 2 files changed, 93 insertions(+), 12 deletions(-) create mode 100644 src/main/java/Task.java diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 000000000..d99873caf --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,21 @@ +public class Task { + protected String description; + protected boolean isDone; + + public Task(String description) { + this.description = description; + this.isDone = false; + } + + public String getStatusIcon() { + return (isDone ? "X" : " "); // mark done task with X + } + + public void markAsDone() { + this.isDone = true; + } + + public void markAsNotDone() { + this.isDone = false; + } +} diff --git a/src/main/java/TulipTask.java b/src/main/java/TulipTask.java index cd1285a2b..61315db89 100644 --- a/src/main/java/TulipTask.java +++ b/src/main/java/TulipTask.java @@ -11,7 +11,7 @@ public static void main(String[] args) { " ` `---'`---'`|---' ` `---^`---'` `\n" + " |"; - ArrayList list = new ArrayList(); + ArrayList list = new ArrayList<>(); System.out.println(logo); @@ -24,28 +24,88 @@ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String input = scanner.nextLine(); - if (Objects.equals(input.toLowerCase(), "bye")) { - break; +// if (Objects.equals(input.toLowerCase(), "bye")) { +// break; +// } +// +// if (Objects.equals(input.toLowerCase(), "list")) { +// listTasks(list); +// } +// +// if (input.toLowerCase().contains("mark")) { +// String[] splitStr = input.split(" "); +// System.out.println(splitStr[0]); +// System.out.println(splitStr[1]); +// } + + String command; + + if (input.toLowerCase().contains("mark")) { + String[] splitStr = input.split(" "); + command = splitStr[0]; + } else { + command = input.toLowerCase(); } - if (Objects.equals(input.toLowerCase(), "list")) { - for (int i = 0; i < list.size(); i++) { - System.out.println((i + 1) + ". " + list.get(i)); - } + switch(command) { + case "list": + listTasks(list); + break; + + case "mark": + String[] splitStr = input.split(" "); + int index = Integer.parseInt(splitStr[1]) - 1; + markAsDone(list.get(index)); + break; + + case "unmark": + String[] split = input.split(" "); + int idx = Integer.parseInt(split[1]) - 1; + markAsNotDone(list.get(idx)); + break; + + case "bye": + System.out.println("--------------------------------------------"); + System.out.println("Bye! Hope to see you again soon :)"); + System.out.println("--------------------------------------------"); + return; + + default: + Task task = new Task(command); + list.add(task); + echo(task); + break; } - list.add(input); - echo(input); } + } + public static void echo (Task task) { System.out.println("--------------------------------------------"); - System.out.println("Bye! Hope to see you again soon :)"); + System.out.println("added: " + task.description); System.out.println("--------------------------------------------"); + } + public static void listTasks (ArrayList list) { + System.out.println("--------------------------------------------"); + System.out.println("Here are your tasks: "); + for (int i = 0; i < list.size(); i++) { + Task task = list.get(i); + System.out.println((i + 1) + ". " + "[" + task.getStatusIcon() + "] " + task.description); + } + System.out.println("--------------------------------------------"); } - public static void echo (String input) { + public static void markAsDone(Task task) { + task.markAsDone(); System.out.println("--------------------------------------------"); - System.out.println("added: " + input); + System.out.println("Great job! I have marked this task as done: \n" + " [" + task.getStatusIcon() + "] " + task.description); + System.out.println("--------------------------------------------"); + } + public static void markAsNotDone(Task task) { + task.markAsNotDone(); + System.out.println("--------------------------------------------"); + System.out.println("Okay, I have marked this task as not done: \n" + " [" + task.getStatusIcon() + "] " + task.description); System.out.println("--------------------------------------------"); } } + From 582b04f6a91a176144614cf5c21a5c46af056bd9 Mon Sep 17 00:00:00 2001 From: kestryix Date: Sat, 7 Sep 2024 11:49:36 +0800 Subject: [PATCH 05/17] follow coding standard --- src/main/java/TulipTask.java | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/src/main/java/TulipTask.java b/src/main/java/TulipTask.java index 61315db89..b56bb1668 100644 --- a/src/main/java/TulipTask.java +++ b/src/main/java/TulipTask.java @@ -24,20 +24,6 @@ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String input = scanner.nextLine(); -// if (Objects.equals(input.toLowerCase(), "bye")) { -// break; -// } -// -// if (Objects.equals(input.toLowerCase(), "list")) { -// listTasks(list); -// } -// -// if (input.toLowerCase().contains("mark")) { -// String[] splitStr = input.split(" "); -// System.out.println(splitStr[0]); -// System.out.println(splitStr[1]); -// } - String command; if (input.toLowerCase().contains("mark")) { @@ -73,13 +59,13 @@ public static void main(String[] args) { default: Task task = new Task(command); list.add(task); - echo(task); + addTask(task); break; } } } - public static void echo (Task task) { + public static void addTask (Task task) { System.out.println("--------------------------------------------"); System.out.println("added: " + task.description); System.out.println("--------------------------------------------"); From 1b21a14a3ce12e4363d6e925e1c6d6d461935f21 Mon Sep 17 00:00:00 2001 From: kestryix Date: Sat, 7 Sep 2024 14:27:39 +0800 Subject: [PATCH 06/17] add todo, event and deadline --- src/main/java/Deadline.java | 12 +++++ src/main/java/Event.java | 14 ++++++ src/main/java/InputParser.java | 39 +++++++++++++++ src/main/java/Task.java | 8 +++ src/main/java/TaskList.java | 68 ++++++++++++++++++++++++++ src/main/java/ToDo.java | 9 ++++ src/main/java/TulipTask.java | 89 ++++++++++++---------------------- 7 files changed, 181 insertions(+), 58 deletions(-) create mode 100644 src/main/java/Deadline.java create mode 100644 src/main/java/Event.java create mode 100644 src/main/java/InputParser.java create mode 100644 src/main/java/TaskList.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..82a880f6d --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,12 @@ +public class Deadline extends Task { + protected String by; + + public Deadline(String description, String by) { + super(description); + this.by = by; + } + + public String toString() { + return String.format("[D]%s (by: %s)", super.toString(), this.by); + } +} diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 000000000..c8964f041 --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,14 @@ +public class Event extends Task { + protected String from; + protected String to; + + public Event(String description, String from, String to) { + super(description); + this.from = from; + this.to = to; + } + + public String toString() { + return String.format("[E]%s (from: %s to: %s)", super.toString(), this.from, this.to); + } +} diff --git a/src/main/java/InputParser.java b/src/main/java/InputParser.java new file mode 100644 index 000000000..f0d639a5a --- /dev/null +++ b/src/main/java/InputParser.java @@ -0,0 +1,39 @@ +import java.util.HashMap; + +public class InputParser { + public static final String COMMAND = "command"; + public static final String ARGUMENT = "argument"; + + public static HashMap parseCommands(String input) { + HashMap commandArguments = new HashMap<>(); + String[] splitInput = input.split(" "); + + if (splitInput.length == 0) { + commandArguments.put(InputParser.COMMAND, ""); + return commandArguments; + } + commandArguments.put(InputParser.COMMAND, splitInput[0]); + + String argumentDescription = InputParser.ARGUMENT; + StringBuilder argument = new StringBuilder(); + + for (int i = 1; i < splitInput.length; i++) { + if (splitInput[i].charAt(0) == '/') { + if (!argumentDescription.isEmpty()) { + commandArguments.put(argumentDescription, argument.toString().strip()); + } + + argumentDescription = splitInput[i]; + argument.setLength(0); + } else { + argument.append(" ").append(splitInput[i]); + } + } + + if (!argument.isEmpty()) { + commandArguments.put(argumentDescription, argument.toString().strip()); + } + + return commandArguments; + } +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java index d99873caf..04bddd725 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -18,4 +18,12 @@ public void markAsDone() { public void markAsNotDone() { this.isDone = false; } + + public String getDescription() { + return description; + } + + public String toString() { + return String.format("[%s] %s", this.getStatusIcon(), this.getDescription()); + } } diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java new file mode 100644 index 000000000..194299a28 --- /dev/null +++ b/src/main/java/TaskList.java @@ -0,0 +1,68 @@ +import java.util.ArrayList; +import java.util.HashMap; + +public class TaskList { + public ArrayList taskList; + + public TaskList() { + this.taskList = new ArrayList<>(); + } + + public void addTask(Task task) { + System.out.println("--------------------------------------------"); + this.taskList.add(task); + System.out.println("Okay! I have added this task: "); + System.out.println(task.toString()); + System.out.printf("You currently have %d tasks in your list \n", taskList.size()); + System.out.println("--------------------------------------------"); + } + + public void listTasks() { + System.out.println("--------------------------------------------"); + System.out.println("Here are your current tasks: "); + for (int i = 0; i < taskList.size(); i++) { + System.out.println(i + 1 + "." + this.taskList.get(i)); + } + System.out.println("--------------------------------------------"); + } + + public void addToDo(HashMap commandArguments) { + ToDo task = new ToDo(commandArguments.get("argument")); + addTask(task); + } + + public void addDeadline(HashMap commandArguments) { + String argument = commandArguments.get("argument"); + String by = commandArguments.get("/by"); + Deadline task = new Deadline(argument, by); + addTask(task); + } + + public void addEvent(HashMap commandArguments) { + String argument = commandArguments.get("argument"); + String from = commandArguments.get("/from"); + String to = commandArguments.get("/to"); + Event task = new Event(argument, from, to); + addTask(task); + } + + public void markTaskAsDone(HashMap commandArguments) { + int index = Integer.parseInt(commandArguments.get("argument")) - 1; + Task task = taskList.get(index); + task.markAsDone(); + System.out.println("--------------------------------------------"); + System.out.println("Great job! I have marked this task as done: "); + System.out.println(task); + System.out.println("--------------------------------------------"); + } + + public void markTaskAsNotDone(HashMap commandArguments) { + int index = Integer.parseInt(commandArguments.get("argument")) - 1; + Task task = taskList.get(index); + task.markAsNotDone(); + System.out.println("--------------------------------------------"); + System.out.println("Okay, I have marked this task as not done: "); + System.out.println(task); + System.out.println("--------------------------------------------"); + } +} diff --git a/src/main/java/ToDo.java b/src/main/java/ToDo.java new file mode 100644 index 000000000..c0e15ecae --- /dev/null +++ b/src/main/java/ToDo.java @@ -0,0 +1,9 @@ +public class ToDo extends Task { + public ToDo(String description) { + super(description); + } + + public String toString() { + return String.format("[T]%s", super.toString()); + } +} diff --git a/src/main/java/TulipTask.java b/src/main/java/TulipTask.java index b56bb1668..a3598bb27 100644 --- a/src/main/java/TulipTask.java +++ b/src/main/java/TulipTask.java @@ -1,5 +1,4 @@ -import java.util.ArrayList; -import java.util.Objects; +import java.util.HashMap; import java.util.Scanner; public class TulipTask { @@ -11,43 +10,48 @@ public static void main(String[] args) { " ` `---'`---'`|---' ` `---^`---'` `\n" + " |"; - ArrayList list = new ArrayList<>(); + String welcomeMessage = "--------------------------------------------\n" + + "Hello, I'm TulipTask\n" + + "What can I do for you today?\n" + + "--------------------------------------------"; + + HashMap commandArguments; System.out.println(logo); + System.out.println(welcomeMessage); - System.out.println("--------------------------------------------"); - System.out.println("Hello, I'm TulipTask"); - System.out.println("What can I do for you today?"); - System.out.println("--------------------------------------------"); + TaskList taskList = new TaskList(); + Scanner scanner = new Scanner(System.in); + String input; while (true) { - Scanner scanner = new Scanner(System.in); - String input = scanner.nextLine(); - - String command; + input = scanner.nextLine(); + commandArguments = InputParser.parseCommands(input); + String command = commandArguments.get(InputParser.COMMAND); - if (input.toLowerCase().contains("mark")) { - String[] splitStr = input.split(" "); - command = splitStr[0]; - } else { - command = input.toLowerCase(); - } - - switch(command) { + switch (command) { case "list": - listTasks(list); + taskList.listTasks(); break; case "mark": - String[] splitStr = input.split(" "); - int index = Integer.parseInt(splitStr[1]) - 1; - markAsDone(list.get(index)); + taskList.markTaskAsDone(commandArguments); break; case "unmark": - String[] split = input.split(" "); - int idx = Integer.parseInt(split[1]) - 1; - markAsNotDone(list.get(idx)); + taskList.markTaskAsNotDone(commandArguments); + break; + + case "todo": + taskList.addToDo(commandArguments); + break; + + case "deadline": + taskList.addDeadline(commandArguments); + break; + + case "event": + taskList.addEvent(commandArguments); break; case "bye": @@ -55,43 +59,12 @@ public static void main(String[] args) { System.out.println("Bye! Hope to see you again soon :)"); System.out.println("--------------------------------------------"); return; - default: - Task task = new Task(command); - list.add(task); - addTask(task); + System.out.println("Invalid command"); break; } - } - } - public static void addTask (Task task) { - System.out.println("--------------------------------------------"); - System.out.println("added: " + task.description); - System.out.println("--------------------------------------------"); - } - - public static void listTasks (ArrayList list) { - System.out.println("--------------------------------------------"); - System.out.println("Here are your tasks: "); - for (int i = 0; i < list.size(); i++) { - Task task = list.get(i); - System.out.println((i + 1) + ". " + "[" + task.getStatusIcon() + "] " + task.description); } - System.out.println("--------------------------------------------"); - } - - public static void markAsDone(Task task) { - task.markAsDone(); - System.out.println("--------------------------------------------"); - System.out.println("Great job! I have marked this task as done: \n" + " [" + task.getStatusIcon() + "] " + task.description); - System.out.println("--------------------------------------------"); - } - public static void markAsNotDone(Task task) { - task.markAsNotDone(); - System.out.println("--------------------------------------------"); - System.out.println("Okay, I have marked this task as not done: \n" + " [" + task.getStatusIcon() + "] " + task.description); - System.out.println("--------------------------------------------"); } } From 0b90f883c819faf92e17033437f3684f06538d2d Mon Sep 17 00:00:00 2001 From: kestryix Date: Sat, 7 Sep 2024 15:14:43 +0800 Subject: [PATCH 07/17] add text ui test --- text-ui-test/EXPECTED.TXT | 70 +++++++++++++++++++++++++++++++++++---- text-ui-test/input.txt | 12 +++++++ text-ui-test/runtest.bat | 2 +- text-ui-test/runtest.sh | 2 +- 4 files changed, 77 insertions(+), 9 deletions(-) diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 657e74f6e..9ae68aa1f 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,7 +1,63 @@ -Hello from - ____ _ -| _ \ _ _| | _____ -| | | | | | | |/ / _ \ -| |_| | |_| | < __/ -|____/ \__,_|_|\_\___| - + +--.-- | o --.-- | + | . .| .,---. | ,---.,---.|__/ + | | || || | | ,---|`---.| \ + ` `---'`---'`|---' ` `---^`---'` ` + | +-------------------------------------------- +Hello, I'm TulipTask +What can I do for you today? +-------------------------------------------- +-------------------------------------------- +Okay! I have added this task: +[T][ ] borrow book +You currently have 1 tasks in your list +-------------------------------------------- +-------------------------------------------- +Here are your current tasks: +1.[T][ ] borrow book +-------------------------------------------- +-------------------------------------------- +Okay! I have added this task: +[D][ ] return book (by: Friday) +You currently have 2 tasks in your list +-------------------------------------------- +-------------------------------------------- +Okay! I have added this task: +[E][ ] project meeting (from: Mon 2pm to: 4pm) +You currently have 3 tasks in your list +-------------------------------------------- +Invalid command +-------------------------------------------- +Here are your current tasks: +1.[T][ ] borrow book +2.[D][ ] return book (by: Friday) +3.[E][ ] project meeting (from: Mon 2pm to: 4pm) +-------------------------------------------- +-------------------------------------------- +Great job! I have marked this task as done: +[T][X] borrow book +-------------------------------------------- +-------------------------------------------- +Here are your current tasks: +1.[T][X] borrow book +2.[D][ ] return book (by: Friday) +3.[E][ ] project meeting (from: Mon 2pm to: 4pm) +-------------------------------------------- +-------------------------------------------- +Great job! I have marked this task as done: +[D][X] return book (by: Friday) +-------------------------------------------- +-------------------------------------------- +Okay, I have marked this task as not done: +[T][ ] borrow book +-------------------------------------------- +-------------------------------------------- +Here are your current tasks: +1.[T][ ] borrow book +2.[D][X] return book (by: Friday) +3.[E][ ] project meeting (from: Mon 2pm to: 4pm) +-------------------------------------------- +-------------------------------------------- +Bye! Hope to see you again soon :) +-------------------------------------------- diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index e69de29bb..62d76c6d1 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -0,0 +1,12 @@ +todo borrow book +list +deadline return book /by Friday +event project meeting /from Mon 2pm /to 4pm +test +list +mark 1 +list +mark 2 +unmark 1 +list +bye \ No newline at end of file diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 087374464..58d636d61 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 TulipTask < input.txt > ACTUAL.TXT REM compare the output to the expected output FC ACTUAL.TXT EXPECTED.TXT diff --git a/text-ui-test/runtest.sh b/text-ui-test/runtest.sh index c9ec87003..5739aa622 100644 --- a/text-ui-test/runtest.sh +++ b/text-ui-test/runtest.sh @@ -20,7 +20,7 @@ then fi # 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 TulipTask < input.txt > ACTUAL.TXT # convert to UNIX format cp EXPECTED.TXT EXPECTED-UNIX.TXT From b4c258ffccf3716a05c3bc13e959857fa96ad51d Mon Sep 17 00:00:00 2001 From: kestryix Date: Sat, 7 Sep 2024 15:29:24 +0800 Subject: [PATCH 08/17] improve code quality --- src/main/java/InputParser.java | 13 ++++++++++--- src/main/java/TulipTask.java | 8 +++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/java/InputParser.java b/src/main/java/InputParser.java index f0d639a5a..14cc8ce81 100644 --- a/src/main/java/InputParser.java +++ b/src/main/java/InputParser.java @@ -8,28 +8,35 @@ public static HashMap parseCommands(String input) { HashMap commandArguments = new HashMap<>(); String[] splitInput = input.split(" "); + // check if input is empty if (splitInput.length == 0) { commandArguments.put(InputParser.COMMAND, ""); return commandArguments; } + + // set first element as command commandArguments.put(InputParser.COMMAND, splitInput[0]); String argumentDescription = InputParser.ARGUMENT; StringBuilder argument = new StringBuilder(); + // parse remaining input for (int i = 1; i < splitInput.length; i++) { - if (splitInput[i].charAt(0) == '/') { + String arg = splitInput[i]; + + if (arg.startsWith("/")) { if (!argumentDescription.isEmpty()) { commandArguments.put(argumentDescription, argument.toString().strip()); } - argumentDescription = splitInput[i]; + argumentDescription = arg; argument.setLength(0); } else { - argument.append(" ").append(splitInput[i]); + argument.append(" ").append(arg); } } + // add last argument if (!argument.isEmpty()) { commandArguments.put(argumentDescription, argument.toString().strip()); } diff --git a/src/main/java/TulipTask.java b/src/main/java/TulipTask.java index a3598bb27..d9d0d805e 100644 --- a/src/main/java/TulipTask.java +++ b/src/main/java/TulipTask.java @@ -15,6 +15,10 @@ public static void main(String[] args) { "What can I do for you today?\n" + "--------------------------------------------"; + String goodByeMessage = "--------------------------------------------\n" + + "Bye! Hope to see you again soon :)\n" + + "--------------------------------------------"; + HashMap commandArguments; System.out.println(logo); @@ -55,9 +59,7 @@ public static void main(String[] args) { break; case "bye": - System.out.println("--------------------------------------------"); - System.out.println("Bye! Hope to see you again soon :)"); - System.out.println("--------------------------------------------"); + System.out.println(goodByeMessage); return; default: System.out.println("Invalid command"); From 345fde93479b4b6643a3b336fb82e83fb4e1d341 Mon Sep 17 00:00:00 2001 From: kestryix Date: Sat, 7 Sep 2024 16:04:56 +0800 Subject: [PATCH 09/17] error handling --- src/main/java/TaskList.java | 83 ++++++++++++++++++++++++++++++++++-- src/main/java/TulipTask.java | 11 +++-- 2 files changed, 87 insertions(+), 7 deletions(-) diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java index 194299a28..4b8e8c63b 100644 --- a/src/main/java/TaskList.java +++ b/src/main/java/TaskList.java @@ -3,6 +3,8 @@ public class TaskList { public ArrayList taskList; + protected int taskIndex; + public static final int INVALID_INDEX = -1; public TaskList() { this.taskList = new ArrayList<>(); @@ -27,6 +29,13 @@ public void listTasks() { } public void addToDo(HashMap commandArguments) { + String argument = commandArguments.get("argument"); + if (argument == null) { + System.out.println("--------------------------------------------"); + System.out.println("Task description was not given :("); + System.out.println("--------------------------------------------"); + } + ToDo task = new ToDo(commandArguments.get("argument")); addTask(task); } @@ -34,6 +43,21 @@ public void addToDo(HashMap commandArguments) { public void addDeadline(HashMap commandArguments) { String argument = commandArguments.get("argument"); String by = commandArguments.get("/by"); + + if (argument == null) { + System.out.println("--------------------------------------------"); + System.out.println("Task description was not given :("); + System.out.println("--------------------------------------------"); + return; + } + + if (by == null) { + System.out.println("--------------------------------------------"); + System.out.println("Task deadline was not given, add a deadline by using /by to indicate task end date!"); + System.out.println("--------------------------------------------"); + return; + } + Deadline task = new Deadline(argument, by); addTask(task); } @@ -42,13 +66,55 @@ public void addEvent(HashMap commandArguments) { String argument = commandArguments.get("argument"); String from = commandArguments.get("/from"); String to = commandArguments.get("/to"); + + if (argument == null) { + System.out.println("--------------------------------------------"); + System.out.println("Task description was not given :("); + System.out.println("--------------------------------------------"); + return; + } + + if (from == null) { + System.out.println("--------------------------------------------"); + System.out.println("Event start date was not given, add a start date by using /from to indicate task start date!"); + System.out.println("--------------------------------------------"); + return; + } + + if (to == null) { + System.out.println("--------------------------------------------"); + System.out.println("Event end date was not given, add a end date by using /to to indicate task end date!"); + System.out.println("--------------------------------------------"); + return; + } + Event task = new Event(argument, from, to); addTask(task); } + public void getTaskIndex(String indexString) { + int index = Integer.parseInt(indexString) - 1; + + if (index < 0 || index > taskList.size() - 1) { + this.taskIndex = INVALID_INDEX; + return; + } + + this.taskIndex = index; + } + public void markTaskAsDone(HashMap commandArguments) { - int index = Integer.parseInt(commandArguments.get("argument")) - 1; - Task task = taskList.get(index); + String argument = commandArguments.get("argument"); + getTaskIndex(argument); + + if (this.taskIndex == INVALID_INDEX) { + System.out.println("--------------------------------------------"); + System.out.printf("Invalid task index! Please input a number between 1 and %d \n", this.taskList.size()); + System.out.println("--------------------------------------------"); + return; + } + + Task task = taskList.get(this.taskIndex); task.markAsDone(); System.out.println("--------------------------------------------"); System.out.println("Great job! I have marked this task as done: "); @@ -57,8 +123,17 @@ public void markTaskAsDone(HashMap commandArguments) { } public void markTaskAsNotDone(HashMap commandArguments) { - int index = Integer.parseInt(commandArguments.get("argument")) - 1; - Task task = taskList.get(index); + String argument = commandArguments.get("argument"); + getTaskIndex(argument); + + if (this.taskIndex == INVALID_INDEX) { + System.out.println("--------------------------------------------"); + System.out.printf("Invalid task index! Please input a number between 1 and %d \n", this.taskList.size()); + System.out.println("--------------------------------------------"); + return; + } + + Task task = taskList.get(this.taskIndex); task.markAsNotDone(); System.out.println("--------------------------------------------"); System.out.println("Okay, I have marked this task as not done: "); diff --git a/src/main/java/TulipTask.java b/src/main/java/TulipTask.java index d9d0d805e..1973f8107 100644 --- a/src/main/java/TulipTask.java +++ b/src/main/java/TulipTask.java @@ -10,15 +10,19 @@ public static void main(String[] args) { " ` `---'`---'`|---' ` `---^`---'` `\n" + " |"; - String welcomeMessage = "--------------------------------------------\n" + + final String welcomeMessage = "--------------------------------------------\n" + "Hello, I'm TulipTask\n" + "What can I do for you today?\n" + "--------------------------------------------"; - String goodByeMessage = "--------------------------------------------\n" + + final String goodByeMessage = "--------------------------------------------\n" + "Bye! Hope to see you again soon :)\n" + "--------------------------------------------"; + final String unrecognizedCommand = "--------------------------------------------\n" + + "Unrecognized command!\n" + + "--------------------------------------------\n"; + HashMap commandArguments; System.out.println(logo); @@ -61,8 +65,9 @@ public static void main(String[] args) { case "bye": System.out.println(goodByeMessage); return; + default: - System.out.println("Invalid command"); + System.out.println(unrecognizedCommand); break; } From b74b7e6b15206599c98c56aba824d8220e375ae5 Mon Sep 17 00:00:00 2001 From: kestryix Date: Sun, 15 Sep 2024 15:36:13 +0800 Subject: [PATCH 10/17] delete --- src/main/java/TaskList.java | 12 ++++++++++++ src/main/java/TulipTask.java | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java index 4b8e8c63b..d6944f2e6 100644 --- a/src/main/java/TaskList.java +++ b/src/main/java/TaskList.java @@ -19,6 +19,18 @@ public void addTask(Task task) { System.out.println("--------------------------------------------"); } + public void deleteTask(HashMap commandArguments) { + String argument = commandArguments.get("argument"); + getTaskIndex(argument); + Task task = taskList.get(this.taskIndex); + System.out.println("--------------------------------------------"); + this.taskList.remove(task); + System.out.println("Okay! I have removed this task: "); + System.out.println(task.toString()); + System.out.printf("You currently have %d tasks in your list \n", taskList.size()); + System.out.println("--------------------------------------------"); + } + public void listTasks() { System.out.println("--------------------------------------------"); System.out.println("Here are your current tasks: "); diff --git a/src/main/java/TulipTask.java b/src/main/java/TulipTask.java index 1973f8107..a286df3bf 100644 --- a/src/main/java/TulipTask.java +++ b/src/main/java/TulipTask.java @@ -62,6 +62,10 @@ public static void main(String[] args) { taskList.addEvent(commandArguments); break; + case "delete": + taskList.deleteTask(commandArguments); + break; + case "bye": System.out.println(goodByeMessage); return; From 458c528d6f32887f93d73e713dce9d17ac7d44f8 Mon Sep 17 00:00:00 2001 From: kestryix Date: Sun, 15 Sep 2024 17:21:51 +0800 Subject: [PATCH 11/17] save tasks --- .gitignore | 2 ++ src/main/java/SaveTaskList.java | 58 +++++++++++++++++++++++++++++++ src/main/java/TaskList.java | 60 +++++++++++++++++++++++++++++++++ src/main/java/TulipTask.java | 8 +++++ 4 files changed, 128 insertions(+) create mode 100644 src/main/java/SaveTaskList.java diff --git a/.gitignore b/.gitignore index 2873e189e..cf1399567 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ bin/ /text-ui-test/ACTUAL.TXT text-ui-test/EXPECTED-UNIX.TXT + +data/ diff --git a/src/main/java/SaveTaskList.java b/src/main/java/SaveTaskList.java new file mode 100644 index 000000000..a5da2181c --- /dev/null +++ b/src/main/java/SaveTaskList.java @@ -0,0 +1,58 @@ +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; + +public class SaveTaskList { + static Path directoryPath = Path.of("./data"); + static Path filePath = directoryPath.resolve("data.txt"); + + public static void saveTasks(ArrayList taskList) { + try { + if (!Files.exists(directoryPath)) { + Files.createDirectories(directoryPath); + System.out.println("Directory created: " + directoryPath); + } + + if (!Files.exists(filePath)) { + Files.createFile(filePath); + System.out.println("File created: " + filePath); + } + + try (var writer = new FileWriter(filePath.toFile())) { + for (var item : taskList) { + writer.write(item + System.lineSeparator()); + } + System.out.println("Task list data saved to file: " + filePath); + } + + } catch (IOException e) { + System.out.println("An error occurred: " + e.getMessage()); + } + } + + public static List loadTasks() { + List taskList; + + if (!Files.exists(directoryPath)) { + System.out.println("Data directory does not exist"); + } + + try { + if (Files.exists(filePath)) { + taskList = Files.readAllLines(filePath); + return taskList; + } else { + System.out.println("Data file does not exist: " + filePath); + } + } catch (IOException e) { + System.out.println("An error occurred while reading the file: " + e.getMessage()); + } + return null; + } +} + + + diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java index 4b8e8c63b..6ab4677e1 100644 --- a/src/main/java/TaskList.java +++ b/src/main/java/TaskList.java @@ -1,5 +1,7 @@ import java.util.ArrayList; import java.util.HashMap; +import java.util.List; +import java.util.Objects; public class TaskList { public ArrayList taskList; @@ -140,4 +142,62 @@ public void markTaskAsNotDone(HashMap commandArguments) { System.out.println(task); System.out.println("--------------------------------------------"); } + + public void saveTaskToFile() { + System.out.println("--------------------------------------------"); + SaveTaskList.saveTasks(this.taskList); + System.out.println("--------------------------------------------"); + } + + public void loadTaskFromFile() { + List list = SaveTaskList.loadTasks(); + for (int i = 0; i < Objects.requireNonNull(list).size(); i++) { + parseTask(list.get(i)); + } + System.out.println("--------------------------------------------"); + System.out.println("Tasks have been successfully loaded!"); + System.out.println("--------------------------------------------"); + } + + public void parseTask(String line) { + String type = line.substring(1, 2); + boolean completed = line.charAt(4) == 'X'; + + switch (type) { + case "T" -> { + String description = line.substring(7); + ToDo task = new ToDo(description); + this.taskList.add(task); + if (completed) { + task.markAsDone(); + } + + } + case "D" -> { + int deadlineIndex = line.indexOf("(by:"); + String description = line.substring(7, deadlineIndex).trim(); + String deadline = line.substring(deadlineIndex + 5, line.length() - 1); + Deadline task = new Deadline(description, deadline); + this.taskList.add(task); + if (completed) { + task.markAsDone(); + } + + } + case "E" -> { + int eventIndex = line.indexOf("(from:"); + String description = line.substring(7, eventIndex).trim(); + String timeInfo = line.substring(eventIndex + 6, line.length() - 1); // Extract time info + + String[] timeParts = timeInfo.split(" to: "); + String eventStart = timeParts[0].trim(); + String eventEnd = timeParts[1].trim(); + Event task = new Event(description, eventStart, eventEnd); + this.taskList.add(task); + if (completed) { + task.markAsDone(); + } + } + } + } } diff --git a/src/main/java/TulipTask.java b/src/main/java/TulipTask.java index 1973f8107..4775c3ee2 100644 --- a/src/main/java/TulipTask.java +++ b/src/main/java/TulipTask.java @@ -62,6 +62,14 @@ public static void main(String[] args) { taskList.addEvent(commandArguments); break; + case "save": + taskList.saveTaskToFile(); + break; + + case "load": + taskList.loadTaskFromFile(); + break; + case "bye": System.out.println(goodByeMessage); return; From 6775b73b21d0feeb6448858202cb7e7724d00c5f Mon Sep 17 00:00:00 2001 From: kestryix Date: Sun, 15 Sep 2024 17:57:18 +0800 Subject: [PATCH 12/17] handle exceptions --- src/main/java/TaskList.java | 49 +++++++----------------- src/main/java/TulipTask.java | 54 ++++++++++++++++++++++++--- src/main/java/TulipTaskException.java | 11 ++++++ 3 files changed, 72 insertions(+), 42 deletions(-) create mode 100644 src/main/java/TulipTaskException.java diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java index 1a5f36870..ef926a0eb 100644 --- a/src/main/java/TaskList.java +++ b/src/main/java/TaskList.java @@ -42,64 +42,47 @@ public void listTasks() { System.out.println("--------------------------------------------"); } - public void addToDo(HashMap commandArguments) { + public void addToDo(HashMap commandArguments) throws TulipTaskException.InvalidTaskDescriptionException { String argument = commandArguments.get("argument"); if (argument == null) { - System.out.println("--------------------------------------------"); - System.out.println("Task description was not given :("); - System.out.println("--------------------------------------------"); + throw new TulipTaskException.InvalidTaskDescriptionException(); } ToDo task = new ToDo(commandArguments.get("argument")); addTask(task); } - public void addDeadline(HashMap commandArguments) { + public void addDeadline(HashMap commandArguments) throws TulipTaskException.InvalidDeadlineException, TulipTaskException.InvalidTaskDescriptionException { String argument = commandArguments.get("argument"); String by = commandArguments.get("/by"); if (argument == null) { - System.out.println("--------------------------------------------"); - System.out.println("Task description was not given :("); - System.out.println("--------------------------------------------"); - return; + throw new TulipTaskException.InvalidTaskDescriptionException(); } if (by == null) { - System.out.println("--------------------------------------------"); - System.out.println("Task deadline was not given, add a deadline by using /by to indicate task end date!"); - System.out.println("--------------------------------------------"); - return; + throw new TulipTaskException.InvalidDeadlineException(); } Deadline task = new Deadline(argument, by); addTask(task); } - public void addEvent(HashMap commandArguments) { + public void addEvent(HashMap commandArguments) throws TulipTaskException.InvalidTaskDescriptionException, TulipTaskException.InvalidStartDateException, TulipTaskException.InvalidEndDateException { String argument = commandArguments.get("argument"); String from = commandArguments.get("/from"); String to = commandArguments.get("/to"); if (argument == null) { - System.out.println("--------------------------------------------"); - System.out.println("Task description was not given :("); - System.out.println("--------------------------------------------"); - return; + throw new TulipTaskException.InvalidTaskDescriptionException(); } if (from == null) { - System.out.println("--------------------------------------------"); - System.out.println("Event start date was not given, add a start date by using /from to indicate task start date!"); - System.out.println("--------------------------------------------"); - return; + throw new TulipTaskException.InvalidStartDateException(); } if (to == null) { - System.out.println("--------------------------------------------"); - System.out.println("Event end date was not given, add a end date by using /to to indicate task end date!"); - System.out.println("--------------------------------------------"); - return; + throw new TulipTaskException.InvalidEndDateException(); } Event task = new Event(argument, from, to); @@ -117,15 +100,12 @@ public void getTaskIndex(String indexString) { this.taskIndex = index; } - public void markTaskAsDone(HashMap commandArguments) { + public void markTaskAsDone(HashMap commandArguments) throws TulipTaskException.InvalidTaskIndexException { String argument = commandArguments.get("argument"); getTaskIndex(argument); if (this.taskIndex == INVALID_INDEX) { - System.out.println("--------------------------------------------"); - System.out.printf("Invalid task index! Please input a number between 1 and %d \n", this.taskList.size()); - System.out.println("--------------------------------------------"); - return; + throw new TulipTaskException.InvalidTaskIndexException(); } Task task = taskList.get(this.taskIndex); @@ -136,15 +116,12 @@ public void markTaskAsDone(HashMap commandArguments) { System.out.println("--------------------------------------------"); } - public void markTaskAsNotDone(HashMap commandArguments) { + public void markTaskAsNotDone(HashMap commandArguments) throws TulipTaskException.InvalidTaskIndexException { String argument = commandArguments.get("argument"); getTaskIndex(argument); if (this.taskIndex == INVALID_INDEX) { - System.out.println("--------------------------------------------"); - System.out.printf("Invalid task index! Please input a number between 1 and %d \n", this.taskList.size()); - System.out.println("--------------------------------------------"); - return; + throw new TulipTaskException.InvalidTaskIndexException(); } Task task = taskList.get(this.taskIndex); diff --git a/src/main/java/TulipTask.java b/src/main/java/TulipTask.java index 0c89cbfbb..ae51d68d7 100644 --- a/src/main/java/TulipTask.java +++ b/src/main/java/TulipTask.java @@ -2,7 +2,7 @@ import java.util.Scanner; public class TulipTask { - public static void main(String[] args) { + public static void main(String[] args) throws TulipTaskException.InvalidTaskDescriptionException, TulipTaskException.InvalidEndDateException, TulipTaskException.InvalidStartDateException, TulipTaskException.InvalidDeadlineException, TulipTaskException.InvalidTaskIndexException { String logo = " \n" + "--.-- | o --.-- | \n" + " | . .| .,---. | ,---.,---.|__/ \n" + @@ -43,23 +43,65 @@ public static void main(String[] args) { break; case "mark": - taskList.markTaskAsDone(commandArguments); + try { + taskList.markTaskAsDone(commandArguments); + } catch (TulipTaskException.InvalidTaskIndexException e) { + System.out.println("--------------------------------------------"); + System.out.printf("Invalid task index! Please input a number between 1 and %d \n", taskList.taskList.size()); + System.out.println("--------------------------------------------"); + } break; case "unmark": - taskList.markTaskAsNotDone(commandArguments); + try { + taskList.markTaskAsNotDone(commandArguments); + } catch (TulipTaskException.InvalidTaskIndexException e) { + System.out.println("--------------------------------------------"); + System.out.printf("Invalid task index! Please input a number between 1 and %d \n", taskList.taskList.size()); + System.out.println("--------------------------------------------"); + } break; case "todo": - taskList.addToDo(commandArguments); + try { + taskList.addToDo(commandArguments); + } catch (TulipTaskException.InvalidTaskDescriptionException e) { + System.out.println("--------------------------------------------"); + System.out.println("Task description was not given :("); + System.out.println("--------------------------------------------"); + } break; case "deadline": - taskList.addDeadline(commandArguments); + try { + taskList.addDeadline(commandArguments); + } catch (TulipTaskException.InvalidTaskDescriptionException e) { + System.out.println("--------------------------------------------"); + System.out.println("Task description was not given :("); + System.out.println("--------------------------------------------"); + } catch (TulipTaskException.InvalidDeadlineException e) { + System.out.println("--------------------------------------------"); + System.out.println("Task deadline was not given, add a deadline by using /by to indicate task end date!"); + System.out.println("--------------------------------------------"); + } break; case "event": - taskList.addEvent(commandArguments); + try { + taskList.addEvent(commandArguments); + } catch (TulipTaskException.InvalidTaskDescriptionException e) { + System.out.println("--------------------------------------------"); + System.out.println("Task description was not given :("); + System.out.println("--------------------------------------------"); + } catch (TulipTaskException.InvalidStartDateException e) { + System.out.println("--------------------------------------------"); + System.out.println("Event start date was not given, add a start date by using /from to indicate task start date!"); + System.out.println("--------------------------------------------"); + } catch (TulipTaskException.InvalidEndDateException e) { + System.out.println("--------------------------------------------"); + System.out.println("Event end date was not given, add a end date by using /to to indicate task end date!"); + System.out.println("--------------------------------------------"); + } break; case "delete": diff --git a/src/main/java/TulipTaskException.java b/src/main/java/TulipTaskException.java new file mode 100644 index 000000000..ac124010f --- /dev/null +++ b/src/main/java/TulipTaskException.java @@ -0,0 +1,11 @@ +public class TulipTaskException { + public static class InvalidDeadlineException extends Exception {} + + public static class InvalidStartDateException extends Exception {} + + public static class InvalidEndDateException extends Exception {} + + public static class InvalidTaskDescriptionException extends Exception {} + + public static class InvalidTaskIndexException extends Exception {} +} From 254e14a1d57cef9575671d2488bee51d19c77b7d Mon Sep 17 00:00:00 2001 From: kestryix Date: Tue, 1 Oct 2024 16:57:41 +0800 Subject: [PATCH 13/17] find task --- src/main/java/TaskList.java | 16 ++++++++++++++++ src/main/java/TulipTask.java | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java index ef926a0eb..a1356d27b 100644 --- a/src/main/java/TaskList.java +++ b/src/main/java/TaskList.java @@ -189,4 +189,20 @@ public void parseTask(String line) { } } } + + public void findTask(HashMap commandArguments) { + String argument = commandArguments.get("argument"); + + System.out.println("--------------------------------------------"); + System.out.println("Here are the matching tasks in your list: "); + + for (Task task : taskList) { + if (task.description.contains(argument)) { + System.out.println(task); + } + } + + System.out.println("--------------------------------------------"); + + } } diff --git a/src/main/java/TulipTask.java b/src/main/java/TulipTask.java index ae51d68d7..8d3d181f5 100644 --- a/src/main/java/TulipTask.java +++ b/src/main/java/TulipTask.java @@ -116,6 +116,10 @@ public static void main(String[] args) throws TulipTaskException.InvalidTaskDesc taskList.loadTaskFromFile(); break; + case "find": + taskList.findTask(commandArguments); + break; + case "bye": System.out.println(goodByeMessage); return; From e637fcb042fa54843aafc7b1869392d5951959f0 Mon Sep 17 00:00:00 2001 From: kestryix Date: Tue, 1 Oct 2024 17:31:58 +0800 Subject: [PATCH 14/17] more oop --- .../java/{SaveTaskList.java => Storage.java} | 2 +- src/main/java/TaskList.java | 4 +- src/main/java/TulipTask.java | 128 +------------- src/main/java/Ui.java | 158 ++++++++++++++++++ 4 files changed, 163 insertions(+), 129 deletions(-) rename src/main/java/{SaveTaskList.java => Storage.java} (98%) create mode 100644 src/main/java/Ui.java diff --git a/src/main/java/SaveTaskList.java b/src/main/java/Storage.java similarity index 98% rename from src/main/java/SaveTaskList.java rename to src/main/java/Storage.java index a5da2181c..209420794 100644 --- a/src/main/java/SaveTaskList.java +++ b/src/main/java/Storage.java @@ -5,7 +5,7 @@ import java.util.ArrayList; import java.util.List; -public class SaveTaskList { +public class Storage { static Path directoryPath = Path.of("./data"); static Path filePath = directoryPath.resolve("data.txt"); diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java index ef926a0eb..e8729e28d 100644 --- a/src/main/java/TaskList.java +++ b/src/main/java/TaskList.java @@ -134,12 +134,12 @@ public void markTaskAsNotDone(HashMap commandArguments) throws T public void saveTaskToFile() { System.out.println("--------------------------------------------"); - SaveTaskList.saveTasks(this.taskList); + Storage.saveTasks(this.taskList); System.out.println("--------------------------------------------"); } public void loadTaskFromFile() { - List list = SaveTaskList.loadTasks(); + List list = Storage.loadTasks(); for (int i = 0; i < Objects.requireNonNull(list).size(); i++) { parseTask(list.get(i)); } diff --git a/src/main/java/TulipTask.java b/src/main/java/TulipTask.java index ae51d68d7..14c228dc7 100644 --- a/src/main/java/TulipTask.java +++ b/src/main/java/TulipTask.java @@ -1,131 +1,7 @@ -import java.util.HashMap; -import java.util.Scanner; - public class TulipTask { public static void main(String[] args) throws TulipTaskException.InvalidTaskDescriptionException, TulipTaskException.InvalidEndDateException, TulipTaskException.InvalidStartDateException, TulipTaskException.InvalidDeadlineException, TulipTaskException.InvalidTaskIndexException { - String logo = " \n" + - "--.-- | o --.-- | \n" + - " | . .| .,---. | ,---.,---.|__/ \n" + - " | | || || | | ,---|`---.| \\ \n" + - " ` `---'`---'`|---' ` `---^`---'` `\n" + - " |"; - - final String welcomeMessage = "--------------------------------------------\n" + - "Hello, I'm TulipTask\n" + - "What can I do for you today?\n" + - "--------------------------------------------"; - - final String goodByeMessage = "--------------------------------------------\n" + - "Bye! Hope to see you again soon :)\n" + - "--------------------------------------------"; - - final String unrecognizedCommand = "--------------------------------------------\n" + - "Unrecognized command!\n" + - "--------------------------------------------\n"; - - HashMap commandArguments; - - System.out.println(logo); - System.out.println(welcomeMessage); - - TaskList taskList = new TaskList(); - Scanner scanner = new Scanner(System.in); - String input; - - while (true) { - input = scanner.nextLine(); - commandArguments = InputParser.parseCommands(input); - String command = commandArguments.get(InputParser.COMMAND); - - switch (command) { - case "list": - taskList.listTasks(); - break; - - case "mark": - try { - taskList.markTaskAsDone(commandArguments); - } catch (TulipTaskException.InvalidTaskIndexException e) { - System.out.println("--------------------------------------------"); - System.out.printf("Invalid task index! Please input a number between 1 and %d \n", taskList.taskList.size()); - System.out.println("--------------------------------------------"); - } - break; - - case "unmark": - try { - taskList.markTaskAsNotDone(commandArguments); - } catch (TulipTaskException.InvalidTaskIndexException e) { - System.out.println("--------------------------------------------"); - System.out.printf("Invalid task index! Please input a number between 1 and %d \n", taskList.taskList.size()); - System.out.println("--------------------------------------------"); - } - break; - - case "todo": - try { - taskList.addToDo(commandArguments); - } catch (TulipTaskException.InvalidTaskDescriptionException e) { - System.out.println("--------------------------------------------"); - System.out.println("Task description was not given :("); - System.out.println("--------------------------------------------"); - } - break; - - case "deadline": - try { - taskList.addDeadline(commandArguments); - } catch (TulipTaskException.InvalidTaskDescriptionException e) { - System.out.println("--------------------------------------------"); - System.out.println("Task description was not given :("); - System.out.println("--------------------------------------------"); - } catch (TulipTaskException.InvalidDeadlineException e) { - System.out.println("--------------------------------------------"); - System.out.println("Task deadline was not given, add a deadline by using /by to indicate task end date!"); - System.out.println("--------------------------------------------"); - } - break; - - case "event": - try { - taskList.addEvent(commandArguments); - } catch (TulipTaskException.InvalidTaskDescriptionException e) { - System.out.println("--------------------------------------------"); - System.out.println("Task description was not given :("); - System.out.println("--------------------------------------------"); - } catch (TulipTaskException.InvalidStartDateException e) { - System.out.println("--------------------------------------------"); - System.out.println("Event start date was not given, add a start date by using /from to indicate task start date!"); - System.out.println("--------------------------------------------"); - } catch (TulipTaskException.InvalidEndDateException e) { - System.out.println("--------------------------------------------"); - System.out.println("Event end date was not given, add a end date by using /to to indicate task end date!"); - System.out.println("--------------------------------------------"); - } - break; - - case "delete": - taskList.deleteTask(commandArguments); - break; - - case "save": - taskList.saveTaskToFile(); - break; - - case "load": - taskList.loadTaskFromFile(); - break; - - case "bye": - System.out.println(goodByeMessage); - return; - - default: - System.out.println(unrecognizedCommand); - break; - } - - } + Ui ui = new Ui(); + ui.run(); } } diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java new file mode 100644 index 000000000..3bd7d706a --- /dev/null +++ b/src/main/java/Ui.java @@ -0,0 +1,158 @@ +import java.util.HashMap; +import java.util.Scanner; + +public class Ui { + public TaskList taskList; + + public Ui() { + taskList = new TaskList(); + + try { + taskList.loadTaskFromFile(); + } catch (Exception e) { + System.out.println(e.getMessage()); + } + } + + public boolean matchCommand(String command, HashMap commandArguments) { + final String goodByeMessage = "--------------------------------------------\n" + + "Bye! Hope to see you again soon :)\n" + + "--------------------------------------------"; + + final String unrecognizedCommand = "--------------------------------------------\n" + + "Unrecognized command!\n" + + "--------------------------------------------\n"; + + switch (command) { + case "list": + taskList.listTasks(); + break; + + case "mark": + try { + taskList.markTaskAsDone(commandArguments); + } catch (TulipTaskException.InvalidTaskIndexException e) { + System.out.println("--------------------------------------------"); + System.out.printf("Invalid task index! Please input a number between 1 and %d \n", taskList.taskList.size()); + System.out.println("--------------------------------------------"); + } + break; + + case "unmark": + try { + taskList.markTaskAsNotDone(commandArguments); + } catch (TulipTaskException.InvalidTaskIndexException e) { + System.out.println("--------------------------------------------"); + System.out.printf("Invalid task index! Please input a number between 1 and %d \n", taskList.taskList.size()); + System.out.println("--------------------------------------------"); + } + break; + + case "todo": + try { + taskList.addToDo(commandArguments); + } catch (TulipTaskException.InvalidTaskDescriptionException e) { + System.out.println("--------------------------------------------"); + System.out.println("Task description was not given :("); + System.out.println("--------------------------------------------"); + } + break; + + case "deadline": + try { + taskList.addDeadline(commandArguments); + } catch (TulipTaskException.InvalidTaskDescriptionException e) { + System.out.println("--------------------------------------------"); + System.out.println("Task description was not given :("); + System.out.println("--------------------------------------------"); + } catch (TulipTaskException.InvalidDeadlineException e) { + System.out.println("--------------------------------------------"); + System.out.println("Task deadline was not given, add a deadline by using /by to indicate task end date!"); + System.out.println("--------------------------------------------"); + } + break; + + case "event": + try { + taskList.addEvent(commandArguments); + } catch (TulipTaskException.InvalidTaskDescriptionException e) { + System.out.println("--------------------------------------------"); + System.out.println("Task description was not given :("); + System.out.println("--------------------------------------------"); + } catch (TulipTaskException.InvalidStartDateException e) { + System.out.println("--------------------------------------------"); + System.out.println("Event start date was not given, add a start date by using /from to indicate task start date!"); + System.out.println("--------------------------------------------"); + } catch (TulipTaskException.InvalidEndDateException e) { + System.out.println("--------------------------------------------"); + System.out.println("Event end date was not given, add a end date by using /to to indicate task end date!"); + System.out.println("--------------------------------------------"); + } + break; + + case "delete": + taskList.deleteTask(commandArguments); + break; + + case "save": + taskList.saveTaskToFile(); + break; + + case "load": + taskList.loadTaskFromFile(); + break; + + case "bye": + taskList.saveTaskToFile(); + System.out.println(goodByeMessage); + return false; + + default: + System.out.println(unrecognizedCommand); + break; + } + return true; + } + + public void commandEntry() { + HashMap commandArguments; + String input; + Scanner scanner = new Scanner(System.in); + + boolean isAcceptingInput = true; + + while (isAcceptingInput) { + input = scanner.nextLine(); + commandArguments = InputParser.parseCommands(input); + String command = commandArguments.get(InputParser.COMMAND); + + try { + isAcceptingInput = matchCommand(command, commandArguments); + } catch (Exception e) { + System.out.println(e.getMessage()); + } + } + } + + public void displayWelcome() { + String logo = " \n" + + "--.-- | o --.-- | \n" + + " | . .| .,---. | ,---.,---.|__/ \n" + + " | | || || | | ,---|`---.| \\ \n" + + " ` `---'`---'`|---' ` `---^`---'` `\n" + + " |"; + + final String welcomeMessage = "--------------------------------------------\n" + + "Hello, I'm TulipTask\n" + + "What can I do for you today?\n" + + "--------------------------------------------"; + + System.out.println(logo); + System.out.println(welcomeMessage); + } + + public void run() { + displayWelcome(); + commandEntry(); + } +} From 26619e279bdd64b808be960aefec3e2b6994af74 Mon Sep 17 00:00:00 2001 From: kestryix Date: Tue, 1 Oct 2024 18:04:41 +0800 Subject: [PATCH 15/17] javadoc comments --- src/main/java/Deadline.java | 16 ++++++++ src/main/java/Event.java | 17 ++++++++ src/main/java/InputParser.java | 12 ++++++ src/main/java/Storage.java | 15 +++++++ src/main/java/Task.java | 32 +++++++++++++++ src/main/java/TaskList.java | 71 ++++++++++++++++++++++++++++++++++ src/main/java/ToDo.java | 15 +++++++ src/main/java/TulipTask.java | 7 +++- src/main/java/Ui.java | 22 +++++++++++ 9 files changed, 206 insertions(+), 1 deletion(-) diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index 82a880f6d..fb71f9bd4 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -1,11 +1,27 @@ +/** + * The Deadline class represents a task that has a specific deadline. + * It extends the Task class by adding a due date (deadline) to the task. + */ public class Deadline extends Task { protected String by; + /** + * Constructs a Deadline task with a description and a deadline date. + * + * @param description The description of the task. + * @param by The deadline for the task. + */ public Deadline(String description, String by) { super(description); this.by = by; } + /** + * Returns a string representation of the deadline task. + * The format is [D] followed by the task description, status, and the deadline. + * + * @return A string in the format [D][status] description (by: deadline). + */ public String toString() { return String.format("[D]%s (by: %s)", super.toString(), this.by); } diff --git a/src/main/java/Event.java b/src/main/java/Event.java index c8964f041..15cf89dad 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -1,13 +1,30 @@ +/** + * The Event class represents a task that occurs over a specific time period. + * It extends the Task class by adding a start time and an end time. + */ public class Event extends Task { protected String from; protected String to; + /** + * Constructs an Event task with a description, start time, and end time. + * + * @param description The description of the event. + * @param from The start time of the event. + * @param to The end time of the event. + */ public Event(String description, String from, String to) { super(description); this.from = from; this.to = to; } + /** + * Returns a string representation of the event task. + * The format is [E] followed by the task description, status, and the event's time period. + * + * @return A string in the format [E][status] description (from: start time to: end time). + */ public String toString() { return String.format("[E]%s (from: %s to: %s)", super.toString(), this.from, this.to); } diff --git a/src/main/java/InputParser.java b/src/main/java/InputParser.java index 14cc8ce81..6528a13a4 100644 --- a/src/main/java/InputParser.java +++ b/src/main/java/InputParser.java @@ -1,9 +1,21 @@ import java.util.HashMap; +/** + * The InputParser class is responsible for parsing user input into commands and arguments. + * It takes a raw input string and splits it into meaningful components such as the command and its arguments. + */ public class InputParser { public static final String COMMAND = "command"; public static final String ARGUMENT = "argument"; + /** + * Parses the user's input into a command and associated arguments. + * The first word in the input is considered the command, and the rest is treated as arguments. + * Arguments that start with "/" are treated as named arguments. + * + * @param input The raw input string from the user. + * @return A HashMap containing the parsed command and its arguments. + */ public static HashMap parseCommands(String input) { HashMap commandArguments = new HashMap<>(); String[] splitInput = input.split(" "); diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index 209420794..492a9fdbc 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -5,10 +5,20 @@ import java.util.ArrayList; import java.util.List; +/** + * The Storage class handles saving and loading tasks from a file. + * It provides methods to save tasks to a text file and load tasks from it. + */ public class Storage { static Path directoryPath = Path.of("./data"); static Path filePath = directoryPath.resolve("data.txt"); + /** + * Saves the provided list of tasks to a file. + * If the directory or file does not exist, they are created. + * + * @param taskList The list of tasks to be saved. + */ public static void saveTasks(ArrayList taskList) { try { if (!Files.exists(directoryPath)) { @@ -33,6 +43,11 @@ public static void saveTasks(ArrayList taskList) { } } + /** + * Loads the tasks from the file into a list of strings. + * + * @return A list of strings representing the tasks. Returns null if an error occurs or the file does not exist. + */ public static List loadTasks() { List taskList; diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 04bddd725..6eed34ea3 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -1,28 +1,60 @@ +/** + * The Task class represents a general task with a description and a completion status. + * It serves as the base class for different types of tasks such as ToDo, Deadline, and Event. + */ public class Task { protected String description; protected boolean isDone; + /** + * Constructs a new Task with the specified description. + * The task is initially marked as not done. + * + * @param description The description of the task. + */ public Task(String description) { this.description = description; this.isDone = false; } + /** + * Returns the status icon of the task. "X" if the task is done, otherwise a space (" "). + * + * @return A string representing the status icon of the task. + */ public String getStatusIcon() { return (isDone ? "X" : " "); // mark done task with X } + /** + * Marks the task as done by setting its status to true. + */ public void markAsDone() { this.isDone = true; } + /** + * Marks the task as not done by setting its status to false. + */ public void markAsNotDone() { this.isDone = false; } + /** + * Returns the description of the task. + * + * @return The description of the task. + */ public String getDescription() { return description; } + /** + * Returns a string representation of the task. + * The format is [statusIcon] followed by the task description. + * + * @return A string representing the task, including its status and description. + */ public String toString() { return String.format("[%s] %s", this.getStatusIcon(), this.getDescription()); } diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java index 3d4af3d3f..72cddd4db 100644 --- a/src/main/java/TaskList.java +++ b/src/main/java/TaskList.java @@ -3,6 +3,10 @@ import java.util.List; import java.util.Objects; +/** + * The TaskList class manages a list of tasks. It allows tasks to be added, deleted, marked as done or not done, + * and supports operations like loading tasks from a file or saving them to a file. + */ public class TaskList { public ArrayList taskList; protected int taskIndex; @@ -12,6 +16,11 @@ public TaskList() { this.taskList = new ArrayList<>(); } + /** + * Adds a new task to the task list. + * + * @param task The task to be added. + */ public void addTask(Task task) { System.out.println("--------------------------------------------"); this.taskList.add(task); @@ -21,6 +30,11 @@ public void addTask(Task task) { System.out.println("--------------------------------------------"); } + /** + * Deletes a task from the task list. + * + * @param commandArguments A HashMap containing the command arguments, including the task index. + */ public void deleteTask(HashMap commandArguments) { String argument = commandArguments.get("argument"); getTaskIndex(argument); @@ -33,6 +47,9 @@ public void deleteTask(HashMap commandArguments) { System.out.println("--------------------------------------------"); } + /** + * Lists all tasks in the task list. + */ public void listTasks() { System.out.println("--------------------------------------------"); System.out.println("Here are your current tasks: "); @@ -42,6 +59,12 @@ public void listTasks() { System.out.println("--------------------------------------------"); } + /** + * Adds a new ToDo task to the task list. + * + * @param commandArguments A HashMap containing the command arguments, including the task description. + * @throws TulipTaskException.InvalidTaskDescriptionException if the task description is invalid. + */ public void addToDo(HashMap commandArguments) throws TulipTaskException.InvalidTaskDescriptionException { String argument = commandArguments.get("argument"); if (argument == null) { @@ -52,6 +75,13 @@ public void addToDo(HashMap commandArguments) throws TulipTaskEx addTask(task); } + /** + * Adds a new Deadline task to the task list. + * + * @param commandArguments A HashMap containing the command arguments, including the task description and deadline. + * @throws TulipTaskException.InvalidDeadlineException if the deadline is invalid. + * @throws TulipTaskException.InvalidTaskDescriptionException if the task description is invalid. + */ public void addDeadline(HashMap commandArguments) throws TulipTaskException.InvalidDeadlineException, TulipTaskException.InvalidTaskDescriptionException { String argument = commandArguments.get("argument"); String by = commandArguments.get("/by"); @@ -68,6 +98,14 @@ public void addDeadline(HashMap commandArguments) throws TulipTa addTask(task); } + /** + * Adds a new Event task to the task list. + * + * @param commandArguments A HashMap containing the command arguments, including the task description, start time, and end time. + * @throws TulipTaskException.InvalidTaskDescriptionException if the task description is invalid. + * @throws TulipTaskException.InvalidStartDateException if the start date is invalid. + * @throws TulipTaskException.InvalidEndDateException if the end date is invalid. + */ public void addEvent(HashMap commandArguments) throws TulipTaskException.InvalidTaskDescriptionException, TulipTaskException.InvalidStartDateException, TulipTaskException.InvalidEndDateException { String argument = commandArguments.get("argument"); String from = commandArguments.get("/from"); @@ -89,6 +127,11 @@ public void addEvent(HashMap commandArguments) throws TulipTaskE addTask(task); } + /** + * Gets the index of a task based on the provided index string. + * + * @param indexString The string representing the task index. + */ public void getTaskIndex(String indexString) { int index = Integer.parseInt(indexString) - 1; @@ -100,6 +143,12 @@ public void getTaskIndex(String indexString) { this.taskIndex = index; } + /** + * Marks a task as done. + * + * @param commandArguments A HashMap containing the command arguments, including the task index. + * @throws TulipTaskException.InvalidTaskIndexException if the task index is invalid. + */ public void markTaskAsDone(HashMap commandArguments) throws TulipTaskException.InvalidTaskIndexException { String argument = commandArguments.get("argument"); getTaskIndex(argument); @@ -116,6 +165,12 @@ public void markTaskAsDone(HashMap commandArguments) throws Tuli System.out.println("--------------------------------------------"); } + /** + * Marks a task as not done. + * + * @param commandArguments A HashMap containing the command arguments, including the task index. + * @throws TulipTaskException.InvalidTaskIndexException if the task index is invalid. + */ public void markTaskAsNotDone(HashMap commandArguments) throws TulipTaskException.InvalidTaskIndexException { String argument = commandArguments.get("argument"); getTaskIndex(argument); @@ -132,12 +187,18 @@ public void markTaskAsNotDone(HashMap commandArguments) throws T System.out.println("--------------------------------------------"); } + /** + * Saves the tasks to a file. + */ public void saveTaskToFile() { System.out.println("--------------------------------------------"); Storage.saveTasks(this.taskList); System.out.println("--------------------------------------------"); } + /** + * Loads tasks from a file. + */ public void loadTaskFromFile() { List list = Storage.loadTasks(); for (int i = 0; i < Objects.requireNonNull(list).size(); i++) { @@ -148,6 +209,11 @@ public void loadTaskFromFile() { System.out.println("--------------------------------------------"); } + /** + * Parses a task from a string. + * + * @param line The string containing the task information. + */ public void parseTask(String line) { String type = line.substring(1, 2); boolean completed = line.charAt(4) == 'X'; @@ -190,6 +256,11 @@ public void parseTask(String line) { } } + /** + * Finds tasks that match a given argument. + * + * @param commandArguments A HashMap containing the command arguments, including the search keyword. + */ public void findTask(HashMap commandArguments) { String argument = commandArguments.get("argument"); diff --git a/src/main/java/ToDo.java b/src/main/java/ToDo.java index c0e15ecae..2086df9a6 100644 --- a/src/main/java/ToDo.java +++ b/src/main/java/ToDo.java @@ -1,8 +1,23 @@ +/** + * The ToDo class represents a task without any specific time constraints. + * It extends the Task class and provides a simple to-do task. + */ public class ToDo extends Task { + /** + * Constructs a ToDo task with a given description. + * + * @param description The description of the to-do task. + */ public ToDo(String description) { super(description); } + /** + * Returns a string representation of the to-do task. + * The format is [T] followed by the task's status and description. + * + * @return A string in the format [T][status] description. + */ public String toString() { return String.format("[T]%s", super.toString()); } diff --git a/src/main/java/TulipTask.java b/src/main/java/TulipTask.java index 14c228dc7..b4a971347 100644 --- a/src/main/java/TulipTask.java +++ b/src/main/java/TulipTask.java @@ -1,5 +1,10 @@ public class TulipTask { - public static void main(String[] args) throws TulipTaskException.InvalidTaskDescriptionException, TulipTaskException.InvalidEndDateException, TulipTaskException.InvalidStartDateException, TulipTaskException.InvalidDeadlineException, TulipTaskException.InvalidTaskIndexException { + + /** + * Runs the TulipTask program + * @param args - Unused + */ + public static void main(String[] args) { Ui ui = new Ui(); ui.run(); } diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java index b49cc7681..2b20b2280 100644 --- a/src/main/java/Ui.java +++ b/src/main/java/Ui.java @@ -1,6 +1,11 @@ import java.util.HashMap; import java.util.Scanner; +/** + * The Ui class handles user interactions by accepting input commands and managing the task list. + * It provides methods for loading, saving, and modifying tasks, and facilitates communication between + * the user and the task list. + */ public class Ui { public TaskList taskList; @@ -14,6 +19,13 @@ public Ui() { } } + /** + * Matches the user's command with the corresponding task list operation. + * + * @param command The user's command as a string. + * @param commandArguments A HashMap containing command arguments for specific tasks. + * @return true if the program should continue accepting input, false if the user entered "bye". + */ public boolean matchCommand(String command, HashMap commandArguments) { final String goodByeMessage = "--------------------------------------------\n" + "Bye! Hope to see you again soon :)\n" + @@ -118,6 +130,10 @@ public boolean matchCommand(String command, HashMap commandArgum return true; } + /** + * Accepts and processes commands entered by the user in an interactive loop. + * The loop continues until the user enters the "bye" command. + */ public void commandEntry() { HashMap commandArguments; String input; @@ -138,6 +154,9 @@ public void commandEntry() { } } + /** + * Displays a welcome message to the user when the program starts. + */ public void displayWelcome() { String logo = " \n" + "--.-- | o --.-- | \n" + @@ -155,6 +174,9 @@ public void displayWelcome() { System.out.println(welcomeMessage); } + /** + * Starts the user interface by displaying the welcome message and then accepting commands from the user. + */ public void run() { displayWelcome(); commandEntry(); From 344e3f171fea42febea6dae5076e1f9f5c813292 Mon Sep 17 00:00:00 2001 From: kestryix Date: Tue, 1 Oct 2024 18:16:55 +0800 Subject: [PATCH 16/17] user guide --- README.md | 233 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 209 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 90aa7f092..4331a0743 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,209 @@ -# 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 17, 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 17** (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: - ``` - Hello from - ____ _ - | _ \ _ _| | _____ - | | | | | | | |/ / _ \ - | |_| | |_| | < __/ - |____/ \__,_|_|\_\___| - ``` +# TulipTask + +## Overview + +TulipTask allows users to manage tasks, including to-dos, events, and deadlines. It provides a command-line interface where users can add, delete, mark task as done, and list tasks. The tasks are saved to a file so they persist across sessions. + +--- + +## Features + +- **Add Tasks** + - **To-Do**: A basic task without any time constraints. + - **Deadline**: A task with a specific deadline. + - **Event**: A task that has a defined start and end time. + +- **Manage Tasks** + - Mark tasks as done or not done. + - Delete tasks from the task list. + +- **File Storage** + - Tasks are saved to and loaded from a file, making them persistent between sessions. + +- **Task Searching** + - You can search for tasks based on keywords in the task description. + +--- + +## Commands + +### 1. `todo ` +Adds a To-Do task to the task list. + +- **Example**: + ``` + todo Read a book + ``` + +### 2. `deadline /by ` +Adds a Deadline task to the task list. + +- **Example**: + ``` + deadline Submit assignment /by Sunday + ``` + +### 3. `event /from /to ` +Adds an Event task to the task list. + +- **Example**: + ``` + event Project meeting /from Monday 2pm /to Monday 4pm + ``` + +### 4. `list` +Displays all tasks in the list along with their statuses. + +- **Example**: + ``` + list + ``` + +### 5. `mark ` +Marks a specific task as done based on its task number. + +- **Example**: + ``` + mark 2 + ``` + +### 6. `unmark ` +Marks a specific task as not done based on its task number. + +- **Example**: + ``` + unmark 3 + ``` + +### 7. `delete ` +Deletes a specific task based on its task number. + +- **Example**: + ``` + delete 4 + ``` + +### 8. `find ` +Finds and lists tasks that contain the specified keyword in their description. + +- **Example**: + ``` + find book + ``` + +### 9. `save` +Manually saves the current task list to the file. + +- **Example**: + ``` + save + ``` + +### 10. `load` +Loads tasks from the file if they exist. + +- **Example**: + ``` + load + ``` + +### 11. `bye` +Exits the application, automatically saving all tasks to the file. + +- **Example**: + ``` + bye + ``` + +--- + +## Task Types + +### 1. **To-Do Task** +- A basic task with no specific time or deadline. +- **Format**: `[T][status] description` + +### 2. **Deadline Task** +- A task that must be completed by a specific deadline. +- **Format**: `[D][status] description (by: deadline)` + +### 3. **Event Task** +- A task that occurs within a specific time range. +- **Format**: `[E][status] description (from: start time to: end time)` + +### Status +- `X` means the task is done. +- ` ` means the task is not done. + +--- + +## File Storage + +- Tasks are saved in a file located at `./data/data.txt`. +- Tasks are loaded automatically when the application starts, if the file exists. +- If the data directory or file does not exist, they will be created automatically. + +--- + +## Running the Application + +1. **Compile and Run**: + - Ensure all the required classes (`Task`, `ToDo`, `Deadline`, `Event`, `TaskList`, `Ui`, `Storage`, `InputParser`) are compiled. + - Run the `Ui` class which provides the main interaction loop for the application. + +2. **Interacting with the App**: + - Upon starting, you will be greeted with a welcome message, and you can enter commands as described above. + +3. **Exiting**: + - Use the `bye` command to save all tasks and exit the application. + +--- + +## Example Usage + +``` +Hello, I'm TulipTask +What can I do for you today? + +> todo Read a book +Okay! I have added this task: +[T][ ] Read a book +You currently have 1 task in your list. + +> deadline Submit assignment /by Sunday +Okay! I have added this task: +[D][ ] Submit assignment (by: Sunday) +You currently have 2 tasks in your list. + +> event Project meeting /from Monday 2pm /to Monday 4pm +Okay! I have added this task: +[E][ ] Project meeting (from: Monday 2pm to: Monday 4pm) +You currently have 3 tasks in your list. + +> list +Here are your current tasks: +1. [T][ ] Read a book +2. [D][ ] Submit assignment (by: Sunday) +3. [E][ ] Project meeting (from: Monday 2pm to: Monday 4pm) + +> mark 1 +Great job! I have marked this task as done: +[T][X] Read a book + +> find assignment +Here are the matching tasks in your list: +[D][ ] Submit assignment (by: Sunday) + +> bye +Bye! Hope to see you again soon :) +``` + +--- + +## Future Enhancements + +- **Task Editing**: Add functionality to modify existing tasks. +- **Recurring Tasks**: Implement support for tasks that repeat on a regular schedule. +- **Priority Levels**: Allow users to assign priority levels to tasks. + +--- From 3c85d94223121f819a26f5f71454a0c6c2027f4f Mon Sep 17 00:00:00 2001 From: kestryix Date: Tue, 1 Oct 2024 18:34:14 +0800 Subject: [PATCH 17/17] user guide --- README.md | 233 +++++-------------------------------------------- docs/README.md | 209 ++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 218 insertions(+), 224 deletions(-) diff --git a/README.md b/README.md index 4331a0743..7ecd21748 100644 --- a/README.md +++ b/README.md @@ -1,209 +1,24 @@ -# TulipTask - -## Overview - -TulipTask allows users to manage tasks, including to-dos, events, and deadlines. It provides a command-line interface where users can add, delete, mark task as done, and list tasks. The tasks are saved to a file so they persist across sessions. - ---- - -## Features - -- **Add Tasks** - - **To-Do**: A basic task without any time constraints. - - **Deadline**: A task with a specific deadline. - - **Event**: A task that has a defined start and end time. - -- **Manage Tasks** - - Mark tasks as done or not done. - - Delete tasks from the task list. - -- **File Storage** - - Tasks are saved to and loaded from a file, making them persistent between sessions. - -- **Task Searching** - - You can search for tasks based on keywords in the task description. - ---- - -## Commands - -### 1. `todo ` -Adds a To-Do task to the task list. - -- **Example**: - ``` - todo Read a book - ``` - -### 2. `deadline /by ` -Adds a Deadline task to the task list. - -- **Example**: - ``` - deadline Submit assignment /by Sunday - ``` - -### 3. `event /from /to ` -Adds an Event task to the task list. - -- **Example**: - ``` - event Project meeting /from Monday 2pm /to Monday 4pm - ``` - -### 4. `list` -Displays all tasks in the list along with their statuses. - -- **Example**: - ``` - list - ``` - -### 5. `mark ` -Marks a specific task as done based on its task number. - -- **Example**: - ``` - mark 2 - ``` - -### 6. `unmark ` -Marks a specific task as not done based on its task number. - -- **Example**: - ``` - unmark 3 - ``` - -### 7. `delete ` -Deletes a specific task based on its task number. - -- **Example**: - ``` - delete 4 - ``` - -### 8. `find ` -Finds and lists tasks that contain the specified keyword in their description. - -- **Example**: - ``` - find book - ``` - -### 9. `save` -Manually saves the current task list to the file. - -- **Example**: - ``` - save - ``` - -### 10. `load` -Loads tasks from the file if they exist. - -- **Example**: - ``` - load - ``` - -### 11. `bye` -Exits the application, automatically saving all tasks to the file. - -- **Example**: - ``` - bye - ``` - ---- - -## Task Types - -### 1. **To-Do Task** -- A basic task with no specific time or deadline. -- **Format**: `[T][status] description` - -### 2. **Deadline Task** -- A task that must be completed by a specific deadline. -- **Format**: `[D][status] description (by: deadline)` - -### 3. **Event Task** -- A task that occurs within a specific time range. -- **Format**: `[E][status] description (from: start time to: end time)` - -### Status -- `X` means the task is done. -- ` ` means the task is not done. - ---- - -## File Storage - -- Tasks are saved in a file located at `./data/data.txt`. -- Tasks are loaded automatically when the application starts, if the file exists. -- If the data directory or file does not exist, they will be created automatically. - ---- - -## Running the Application - -1. **Compile and Run**: - - Ensure all the required classes (`Task`, `ToDo`, `Deadline`, `Event`, `TaskList`, `Ui`, `Storage`, `InputParser`) are compiled. - - Run the `Ui` class which provides the main interaction loop for the application. - -2. **Interacting with the App**: - - Upon starting, you will be greeted with a welcome message, and you can enter commands as described above. - -3. **Exiting**: - - Use the `bye` command to save all tasks and exit the application. - ---- - -## Example Usage - -``` -Hello, I'm TulipTask -What can I do for you today? - -> todo Read a book -Okay! I have added this task: -[T][ ] Read a book -You currently have 1 task in your list. - -> deadline Submit assignment /by Sunday -Okay! I have added this task: -[D][ ] Submit assignment (by: Sunday) -You currently have 2 tasks in your list. - -> event Project meeting /from Monday 2pm /to Monday 4pm -Okay! I have added this task: -[E][ ] Project meeting (from: Monday 2pm to: Monday 4pm) -You currently have 3 tasks in your list. - -> list -Here are your current tasks: -1. [T][ ] Read a book -2. [D][ ] Submit assignment (by: Sunday) -3. [E][ ] Project meeting (from: Monday 2pm to: Monday 4pm) - -> mark 1 -Great job! I have marked this task as done: -[T][X] Read a book - -> find assignment -Here are the matching tasks in your list: -[D][ ] Submit assignment (by: Sunday) - -> bye -Bye! Hope to see you again soon :) -``` - ---- - -## Future Enhancements - -- **Task Editing**: Add functionality to modify existing tasks. -- **Recurring Tasks**: Implement support for tasks that repeat on a regular schedule. -- **Priority Levels**: Allow users to assign priority levels to tasks. - ---- +# 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 17, 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 17** (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: + ``` + Hello from + ____ _ + | _ \ _ _| | _____ + | | | | | | | |/ / _ \ + | |_| | |_| | < __/ + |____/ \__,_|_|\_\___| + ``` \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index 47b9f984f..f4bdee04d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,30 +1,209 @@ -# Duke User Guide +# TulipTask -// Update the title above to match the actual product name +## Overview -// Product screenshot goes here +TulipTask allows users to manage tasks, including to-dos, events, and deadlines. It provides a command-line interface where users can add, delete, mark task as done, and list tasks. The tasks are saved to a file so they persist across sessions. -// Product intro goes here +--- -## Adding deadlines +## Features -// Describe the action and its outcome. +- **Add Tasks** + - **To-Do**: A basic task without any time constraints. + - **Deadline**: A task with a specific deadline. + - **Event**: A task that has a defined start and end time. -// Give examples of usage +- **Manage Tasks** + - Mark tasks as done or not done. + - Delete tasks from the task list. -Example: `keyword (optional arguments)` +- **File Storage** + - Tasks are saved to and loaded from a file, making them persistent between sessions. -// A description of the expected outcome goes here +- **Task Searching** + - You can search for tasks based on keywords in the task description. + +--- + +## Commands + +### 1. `todo ` +Adds a To-Do task to the task list. + +- **Example**: + ``` + todo Read a book + ``` + +### 2. `deadline /by ` +Adds a Deadline task to the task list. + +- **Example**: + ``` + deadline Submit assignment /by Sunday + ``` + +### 3. `event /from /to ` +Adds an Event task to the task list. + +- **Example**: + ``` + event Project meeting /from Monday 2pm /to Monday 4pm + ``` + +### 4. `list` +Displays all tasks in the list along with their statuses. + +- **Example**: + ``` + list + ``` + +### 5. `mark ` +Marks a specific task as done based on its task number. + +- **Example**: + ``` + mark 2 + ``` + +### 6. `unmark ` +Marks a specific task as not done based on its task number. + +- **Example**: + ``` + unmark 3 + ``` + +### 7. `delete ` +Deletes a specific task based on its task number. + +- **Example**: + ``` + delete 4 + ``` + +### 8. `find ` +Finds and lists tasks that contain the specified keyword in their description. + +- **Example**: + ``` + find book + ``` + +### 9. `save` +Manually saves the current task list to the file. + +- **Example**: + ``` + save + ``` + +### 10. `load` +Loads tasks from the file if they exist. + +- **Example**: + ``` + load + ``` + +### 11. `bye` +Exits the application, automatically saving all tasks to the file. + +- **Example**: + ``` + bye + ``` + +--- + +## Task Types + +### 1. **To-Do Task** +- A basic task with no specific time or deadline. +- **Format**: `[T][status] description` + +### 2. **Deadline Task** +- A task that must be completed by a specific deadline. +- **Format**: `[D][status] description (by: deadline)` + +### 3. **Event Task** +- A task that occurs within a specific time range. +- **Format**: `[E][status] description (from: start time to: end time)` + +### Status +- `X` means the task is done. +- ` ` means the task is not done. + +--- + +## File Storage + +- Tasks are saved in a file located at `./data/data.txt`. +- Tasks are loaded automatically when the application starts, if the file exists. +- If the data directory or file does not exist, they will be created automatically. + +--- + +## Running the Application + +1. **Compile and Run**: + - Ensure all the required classes (`Task`, `ToDo`, `Deadline`, `Event`, `TaskList`, `Ui`, `Storage`, `InputParser`) are compiled. + - Run the `Ui` class which provides the main interaction loop for the application. + +2. **Interacting with the App**: + - Upon starting, you will be greeted with a welcome message, and you can enter commands as described above. + +3. **Exiting**: + - Use the `bye` command to save all tasks and exit the application. + +--- + +## Example Usage ``` -expected output -``` +Hello, I'm TulipTask +What can I do for you today? + +> todo Read a book +Okay! I have added this task: +[T][ ] Read a book +You currently have 1 task in your list. -## Feature ABC +> deadline Submit assignment /by Sunday +Okay! I have added this task: +[D][ ] Submit assignment (by: Sunday) +You currently have 2 tasks in your list. + +> event Project meeting /from Monday 2pm /to Monday 4pm +Okay! I have added this task: +[E][ ] Project meeting (from: Monday 2pm to: Monday 4pm) +You currently have 3 tasks in your list. + +> list +Here are your current tasks: +1. [T][ ] Read a book +2. [D][ ] Submit assignment (by: Sunday) +3. [E][ ] Project meeting (from: Monday 2pm to: Monday 4pm) + +> mark 1 +Great job! I have marked this task as done: +[T][X] Read a book + +> find assignment +Here are the matching tasks in your list: +[D][ ] Submit assignment (by: Sunday) + +> bye +Bye! Hope to see you again soon :) +``` -// Feature details +--- +## Future Enhancements -## Feature XYZ +- **Task Editing**: Add functionality to modify existing tasks. +- **Recurring Tasks**: Implement support for tasks that repeat on a regular schedule. +- **Priority Levels**: Allow users to assign priority levels to tasks. -// Feature details \ No newline at end of file +---