From c456ebcaaa8c88e8e75728b5b163ba2e6ac907a5 Mon Sep 17 00:00:00 2001 From: LI-XINYI1 Date: Fri, 4 Feb 2022 04:21:17 +0800 Subject: [PATCH 01/28] Level 0. Greet --- src/main/java/Duke.java | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5d313334c..20d118dde 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,10 +1,21 @@ +import java.lang.*; + public class Duke { public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); + String greeting = " Hello! I'm Duke\n" + + " What can I do for you? \n"; + String ending = "Bye. Hope to see you again soon! 、\n"; + String horiLine = "____________________________________________________________\n"; + + System.out.println(horiLine + greeting + horiLine); + System.out.println(horiLine + ending + horiLine); + + +// String logo = " ____ _ \n" +// + "| _ \\ _ _| | _____ \n" +// + "| | | | | | | |/ / _ \\\n" +// + "| |_| | |_| | < __/\n" +// + "|____/ \\__,_|_|\\_\\___|\n"; +// System.out.println("Hello from\n" + logo); } } From 3cfc68a3dd067a364ce13682854e252a689ef787 Mon Sep 17 00:00:00 2001 From: LI-XINYI1 Date: Fri, 4 Feb 2022 09:48:53 +0800 Subject: [PATCH 02/28] Add Echo between greet and exit --- src/main/java/Duke.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 20d118dde..be0c58354 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,4 +1,5 @@ import java.lang.*; +import java.util.Scanner; public class Duke { public static void main(String[] args) { @@ -8,6 +9,14 @@ public static void main(String[] args) { String horiLine = "____________________________________________________________\n"; System.out.println(horiLine + greeting + horiLine); + + Scanner task = new Scanner(System.in); + String command = task.nextLine(); + while(!command.equals("bye")){ + System.out.println(horiLine + command+ System.lineSeparator() + horiLine); + command = task.nextLine(); + } + System.out.println(horiLine + ending + horiLine); From 25057ce810bd63dc117ece5a799872a6b19a1189 Mon Sep 17 00:00:00 2001 From: LI-XINYI1 Date: Thu, 10 Feb 2022 10:03:13 +0800 Subject: [PATCH 03/28] println text editing --- src/main/java/Duke.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index be0c58354..40375e6ea 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -3,17 +3,24 @@ public class Duke { public static void main(String[] args) { - String greeting = " Hello! I'm Duke\n" - + " What can I do for you? \n"; - String ending = "Bye. Hope to see you again soon! 、\n"; + String greeting = " Hello, I'm Baymax.\n"+ + " Your personal task managing companion. \n" + + " What can I do for you? \n"; + String ending = "Bye. Hope to see you again soon! \n"; String horiLine = "____________________________________________________________\n"; System.out.println(horiLine + greeting + horiLine); + //greetings + + String[] list = new String[100]; + int commCount = 0; Scanner task = new Scanner(System.in); String command = task.nextLine(); while(!command.equals("bye")){ - System.out.println(horiLine + command+ System.lineSeparator() + horiLine); + System.out.println(horiLine + "added: "+ command+ System.lineSeparator() + horiLine); + list[commCount] = command; + commCount++; command = task.nextLine(); } From 6fc67617619d9ae16fd9b788c464cf9ab9f8a692 Mon Sep 17 00:00:00 2001 From: LI-XINYI1 Date: Thu, 10 Feb 2022 10:13:36 +0800 Subject: [PATCH 04/28] Add,List --- src/main/java/Duke.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 40375e6ea..6e725d9fd 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -18,10 +18,21 @@ public static void main(String[] args) { Scanner task = new Scanner(System.in); String command = task.nextLine(); while(!command.equals("bye")){ - System.out.println(horiLine + "added: "+ command+ System.lineSeparator() + horiLine); - list[commCount] = command; - commCount++; - command = task.nextLine(); + + if(command.equals("list")){ + System.out.println(horiLine); + for(int i=0; i Date: Fri, 11 Feb 2022 01:22:25 +0800 Subject: [PATCH 05/28] Mark as Done: add Task class; add markdone and unmark commands --- src/main/java/Baymax.java | 72 +++++++++++++++++++++++++++++++++++++++ src/main/java/Duke.java | 48 -------------------------- src/main/java/Task.java | 25 ++++++++++++++ 3 files changed, 97 insertions(+), 48 deletions(-) create mode 100644 src/main/java/Baymax.java delete mode 100644 src/main/java/Duke.java create mode 100644 src/main/java/Task.java diff --git a/src/main/java/Baymax.java b/src/main/java/Baymax.java new file mode 100644 index 000000000..ae7d1145f --- /dev/null +++ b/src/main/java/Baymax.java @@ -0,0 +1,72 @@ +import java.lang.String; +import java.util.Scanner; + +public class Baymax { + + + public static void main(String[] args) { + String greeting = " Hello, I'm Baymax.\n"+ + " Your personal task managing companion. \n" + + " What can I do for you? \n"; + String ending = "Bye. Hope to see you again soon! \n"; + String horiLine = "____________________________________________________________\n"; + + System.out.println(horiLine + greeting + horiLine); + //greetings + + Task[] task = new Task[100]; + int taskCount = 0; + + + Scanner in = new Scanner(System.in); + String command = in.nextLine(); + + while(!command.equals("bye")){ + + if(command.equals("list")){ + System.out.println(horiLine); + for(int i=0; i Date: Fri, 11 Feb 2022 01:26:40 +0800 Subject: [PATCH 06/28] Following the Coding Standard --- src/main/java/Baymax.java | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/main/java/Baymax.java b/src/main/java/Baymax.java index ae7d1145f..a1bc611db 100644 --- a/src/main/java/Baymax.java +++ b/src/main/java/Baymax.java @@ -2,60 +2,51 @@ import java.util.Scanner; public class Baymax { - - public static void main(String[] args) { + String greeting = " Hello, I'm Baymax.\n"+ " Your personal task managing companion. \n" + " What can I do for you? \n"; String ending = "Bye. Hope to see you again soon! \n"; String horiLine = "____________________________________________________________\n"; - System.out.println(horiLine + greeting + horiLine); - //greetings - Task[] task = new Task[100]; int taskCount = 0; - - Scanner in = new Scanner(System.in); String command = in.nextLine(); + System.out.println(horiLine + greeting + horiLine);//greetings + while(!command.equals("bye")){ + System.out.println(horiLine); if(command.equals("list")){ - System.out.println(horiLine); for(int i=0; i Date: Fri, 11 Feb 2022 02:44:14 +0800 Subject: [PATCH 07/28] Level-4: ToDos. Events. Deadlins --- src/main/java/Baymax.java | 97 ++++++++++++++++------------------ src/main/java/Deadline.java | 19 +++++++ src/main/java/Event.java | 19 +++++++ src/main/java/TaskManager.java | 55 +++++++++++++++++++ src/main/java/Todo.java | 10 ++++ 5 files changed, 150 insertions(+), 50 deletions(-) create mode 100644 src/main/java/Deadline.java create mode 100644 src/main/java/Event.java create mode 100644 src/main/java/TaskManager.java create mode 100644 src/main/java/Todo.java diff --git a/src/main/java/Baymax.java b/src/main/java/Baymax.java index a1bc611db..638357044 100644 --- a/src/main/java/Baymax.java +++ b/src/main/java/Baymax.java @@ -4,60 +4,57 @@ public class Baymax { public static void main(String[] args) { - String greeting = " Hello, I'm Baymax.\n"+ - " Your personal task managing companion. \n" + - " What can I do for you? \n"; - String ending = "Bye. Hope to see you again soon! \n"; - String horiLine = "____________________________________________________________\n"; - - Task[] task = new Task[100]; - int taskCount = 0; Scanner in = new Scanner(System.in); - String command = in.nextLine(); - - System.out.println(horiLine + greeting + horiLine);//greetings - - while(!command.equals("bye")){ + String command; + String taskDescrip; + String[] taskWord; + TaskManager tManager = new TaskManager(); + String horiLine = "____________________________________________________________\n"; - System.out.println(horiLine); - if(command.equals("list")){ - for(int i=0; i Date: Fri, 11 Feb 2022 21:14:56 +0800 Subject: [PATCH 08/28] =?UTF-8?q?A-CodeQuality=20=EF=BC=9A=20improve=20cod?= =?UTF-8?q?e=20quality?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Baymax.java | 5 +++-- src/main/java/Task.java | 2 +- src/main/java/TaskManager.java | 14 ++++++++------ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/java/Baymax.java b/src/main/java/Baymax.java index 638357044..e52ee5f95 100644 --- a/src/main/java/Baymax.java +++ b/src/main/java/Baymax.java @@ -11,7 +11,7 @@ public static void main(String[] args) { TaskManager tManager = new TaskManager(); String horiLine = "____________________________________________________________\n"; - tManager.welcome(); + tManager.welcome(); //greating command = in.nextLine(); while (!command.equals("bye")) { @@ -20,6 +20,7 @@ public static void main(String[] args) { word_split = command.split(" ", 2); String taskName = word_split[0]; + //different functions based on command lines switch (taskName) { case "todo": tManager.addTask(new Todo(word_split[1])); @@ -55,6 +56,6 @@ public static void main(String[] args) { } command = in.nextLine(); } - tManager.bye(); + tManager.bye(); //bye } } diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 8773cff37..543090f28 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -22,4 +22,4 @@ public void markTaskDone() { public void unmarkTaskDone() { isDone = false; } -} \ No newline at end of file +} diff --git a/src/main/java/TaskManager.java b/src/main/java/TaskManager.java index 8b5c65f55..27ad457be 100644 --- a/src/main/java/TaskManager.java +++ b/src/main/java/TaskManager.java @@ -1,6 +1,5 @@ public class TaskManager { - String horiLine = "____________________________________________________________\n"; private final Task[] tManager = new Task[100]; private int taskCount = 0; @@ -12,7 +11,7 @@ public void welcome() { String greeting = " Hello, I'm Baymax.\n"+ " Your personal task managing companion. \n" + " What can I do for you? \n"; - System.out.println(horiLine + greeting + horiLine);//greetings + System.out.println(horiLine + greeting + horiLine); } public void bye() { @@ -25,7 +24,7 @@ public void addTask(Task description) { System.out.println(horiLine); System.out.println(" Got it. I've added this task: \n"+ this.tManager[this.taskCount].description+"\n" + - "Now you have " + (this.taskCount+1) + " taskS in the list."); + "Now you have " + (this.taskCount+1) + " tasks in the list."); System.out.println(horiLine); this.taskCount++; } @@ -34,7 +33,8 @@ public void printTaskList() { System.out.println(horiLine); System.out.println("Here are the tasks in your list:"); for (int i=0; i Date: Fri, 11 Feb 2022 21:52:01 +0800 Subject: [PATCH 09/28] Level 5. Handle Errors --- src/main/java/Baymax.java | 64 +++++++++++++++++++++--------- src/main/java/BaymaxException.java | 5 +++ src/main/java/TaskManager.java | 4 -- 3 files changed, 51 insertions(+), 22 deletions(-) create mode 100644 src/main/java/BaymaxException.java diff --git a/src/main/java/Baymax.java b/src/main/java/Baymax.java index e52ee5f95..cc791f206 100644 --- a/src/main/java/Baymax.java +++ b/src/main/java/Baymax.java @@ -1,8 +1,8 @@ import java.lang.String; import java.util.Scanner; -public class Baymax { - public static void main(String[] args) { +public class Baymax{ + public static void main(String[] args) throws BaymaxException { Scanner in = new Scanner(System.in); String command; @@ -20,40 +20,68 @@ public static void main(String[] args) { word_split = command.split(" ", 2); String taskName = word_split[0]; + System.out.println(horiLine); //different functions based on command lines switch (taskName) { case "todo": - tManager.addTask(new Todo(word_split[1])); + try { + tManager.addTask(new Todo(word_split[1])); + } catch (IndexOutOfBoundsException e) { + System.out.println(" ☹ OOPS!!! The description of a todo cannot be empty."); + } catch(BaymaxException b) { + System.out.println(b.getMessage() + "Let's try again."); + } break; case "deadline": - taskWord = word_split[1].split("/by ", 2); - taskDescrip = taskWord[0]; - String ddl = taskWord[1]; - tManager.addTask(new Deadline(taskDescrip, ddl)); + try { + taskWord = word_split[1].split("/by ", 2); + taskDescrip = taskWord[0]; + String ddl = taskWord[1]; + tManager.addTask(new Deadline(taskDescrip, ddl)); + } catch (IndexOutOfBoundsException e) { + System.out.println(" ☹ OOPS!!! The description of a deadline cannot be empty."); + } catch(BaymaxException b) { + System.out.println(b.getMessage() + "Let's try again."); + } break; case "event": - taskWord = word_split[1].split("/at ", 2); - taskDescrip = taskWord[0]; - String eventTime = taskWord[1]; - tManager.addTask(new Event(taskDescrip, eventTime)); + try { + taskWord = word_split[1].split("/at ", 2); + taskDescrip = taskWord[0]; + String eventTime = taskWord[1]; + tManager.addTask(new Event(taskDescrip, eventTime)); + } catch (IndexOutOfBoundsException e) { + System.out.println(" ☹ OOPS!!! The description of a event cannot be empty."); + } catch(BaymaxException b) { + System.out.println(b.getMessage() + "Let's try again."); + } break; case "list": tManager.printTaskList(); break; case "mark": - System.out.println(horiLine); - tManager.markTask(Integer.parseInt(word_split[1]) - 1); - System.out.println(horiLine); + try { + tManager.markTask(Integer.parseInt(word_split[1]) - 1); + } catch(NumberFormatException e) { + System.out.println("Please enter an integer for task index. Let's try again."); + } catch(BaymaxException b) { + System.out.println(b.getMessage() + "Let's try again."); + } break; case "unmark": - System.out.println(horiLine); - tManager.unmarkTask(Integer.parseInt(word_split[1]) - 1); - System.out.println(horiLine); + try { + tManager.unmarkTask(Integer.parseInt(word_split[1]) - 1); + } catch(NumberFormatException e) { + System.out.println("Please enter an integer for task index. Let's try again."); + } catch(BaymaxException b) { + System.out.println(b.getMessage() + "Let's try again."); + } break; default: - System.out.println("Error. Please retry"); + System.out.println(" ☹ OOPS!!! I'm sorry, but I don't know what that means :-( Please retry."); break; } + System.out.println(horiLine); command = in.nextLine(); } tManager.bye(); //bye diff --git a/src/main/java/BaymaxException.java b/src/main/java/BaymaxException.java new file mode 100644 index 000000000..eff94bad1 --- /dev/null +++ b/src/main/java/BaymaxException.java @@ -0,0 +1,5 @@ +public class BaymaxException extends RuntimeException{ + public BaymaxException(String warning){ + super(warning); + } +} \ No newline at end of file diff --git a/src/main/java/TaskManager.java b/src/main/java/TaskManager.java index 27ad457be..f431860de 100644 --- a/src/main/java/TaskManager.java +++ b/src/main/java/TaskManager.java @@ -21,22 +21,18 @@ public void bye() { public void addTask(Task description) { this.tManager[this.taskCount] = description; - System.out.println(horiLine); System.out.println(" Got it. I've added this task: \n"+ this.tManager[this.taskCount].description+"\n" + "Now you have " + (this.taskCount+1) + " tasks in the list."); - System.out.println(horiLine); this.taskCount++; } public void printTaskList() { - System.out.println(horiLine); System.out.println("Here are the tasks in your list:"); for (int i=0; i Date: Fri, 11 Feb 2022 22:08:25 +0800 Subject: [PATCH 10/28] Revert "Level 5. Handle Errors" This reverts commit 5cae0c1b629e00a4cc1c97d25e2c4a1c1a409d9f. --- src/main/java/Baymax.java | 64 +++++++++--------------------- src/main/java/BaymaxException.java | 5 --- src/main/java/TaskManager.java | 4 ++ 3 files changed, 22 insertions(+), 51 deletions(-) delete mode 100644 src/main/java/BaymaxException.java diff --git a/src/main/java/Baymax.java b/src/main/java/Baymax.java index cc791f206..e52ee5f95 100644 --- a/src/main/java/Baymax.java +++ b/src/main/java/Baymax.java @@ -1,8 +1,8 @@ import java.lang.String; import java.util.Scanner; -public class Baymax{ - public static void main(String[] args) throws BaymaxException { +public class Baymax { + public static void main(String[] args) { Scanner in = new Scanner(System.in); String command; @@ -20,68 +20,40 @@ public static void main(String[] args) throws BaymaxException { word_split = command.split(" ", 2); String taskName = word_split[0]; - System.out.println(horiLine); //different functions based on command lines switch (taskName) { case "todo": - try { - tManager.addTask(new Todo(word_split[1])); - } catch (IndexOutOfBoundsException e) { - System.out.println(" ☹ OOPS!!! The description of a todo cannot be empty."); - } catch(BaymaxException b) { - System.out.println(b.getMessage() + "Let's try again."); - } + tManager.addTask(new Todo(word_split[1])); break; case "deadline": - try { - taskWord = word_split[1].split("/by ", 2); - taskDescrip = taskWord[0]; - String ddl = taskWord[1]; - tManager.addTask(new Deadline(taskDescrip, ddl)); - } catch (IndexOutOfBoundsException e) { - System.out.println(" ☹ OOPS!!! The description of a deadline cannot be empty."); - } catch(BaymaxException b) { - System.out.println(b.getMessage() + "Let's try again."); - } + taskWord = word_split[1].split("/by ", 2); + taskDescrip = taskWord[0]; + String ddl = taskWord[1]; + tManager.addTask(new Deadline(taskDescrip, ddl)); break; case "event": - try { - taskWord = word_split[1].split("/at ", 2); - taskDescrip = taskWord[0]; - String eventTime = taskWord[1]; - tManager.addTask(new Event(taskDescrip, eventTime)); - } catch (IndexOutOfBoundsException e) { - System.out.println(" ☹ OOPS!!! The description of a event cannot be empty."); - } catch(BaymaxException b) { - System.out.println(b.getMessage() + "Let's try again."); - } + taskWord = word_split[1].split("/at ", 2); + taskDescrip = taskWord[0]; + String eventTime = taskWord[1]; + tManager.addTask(new Event(taskDescrip, eventTime)); break; case "list": tManager.printTaskList(); break; case "mark": - try { - tManager.markTask(Integer.parseInt(word_split[1]) - 1); - } catch(NumberFormatException e) { - System.out.println("Please enter an integer for task index. Let's try again."); - } catch(BaymaxException b) { - System.out.println(b.getMessage() + "Let's try again."); - } + System.out.println(horiLine); + tManager.markTask(Integer.parseInt(word_split[1]) - 1); + System.out.println(horiLine); break; case "unmark": - try { - tManager.unmarkTask(Integer.parseInt(word_split[1]) - 1); - } catch(NumberFormatException e) { - System.out.println("Please enter an integer for task index. Let's try again."); - } catch(BaymaxException b) { - System.out.println(b.getMessage() + "Let's try again."); - } + System.out.println(horiLine); + tManager.unmarkTask(Integer.parseInt(word_split[1]) - 1); + System.out.println(horiLine); break; default: - System.out.println(" ☹ OOPS!!! I'm sorry, but I don't know what that means :-( Please retry."); + System.out.println("Error. Please retry"); break; } - System.out.println(horiLine); command = in.nextLine(); } tManager.bye(); //bye diff --git a/src/main/java/BaymaxException.java b/src/main/java/BaymaxException.java deleted file mode 100644 index eff94bad1..000000000 --- a/src/main/java/BaymaxException.java +++ /dev/null @@ -1,5 +0,0 @@ -public class BaymaxException extends RuntimeException{ - public BaymaxException(String warning){ - super(warning); - } -} \ No newline at end of file diff --git a/src/main/java/TaskManager.java b/src/main/java/TaskManager.java index f431860de..27ad457be 100644 --- a/src/main/java/TaskManager.java +++ b/src/main/java/TaskManager.java @@ -21,18 +21,22 @@ public void bye() { public void addTask(Task description) { this.tManager[this.taskCount] = description; + System.out.println(horiLine); System.out.println(" Got it. I've added this task: \n"+ this.tManager[this.taskCount].description+"\n" + "Now you have " + (this.taskCount+1) + " tasks in the list."); + System.out.println(horiLine); this.taskCount++; } public void printTaskList() { + System.out.println(horiLine); System.out.println("Here are the tasks in your list:"); for (int i=0; i Date: Fri, 11 Feb 2022 22:21:05 +0800 Subject: [PATCH 11/28] restart over --- src/main/java/Baymax.java | 64 +++++++++--------------------- src/main/java/BaymaxException.java | 5 --- src/main/java/TaskManager.java | 4 ++ 3 files changed, 22 insertions(+), 51 deletions(-) delete mode 100644 src/main/java/BaymaxException.java diff --git a/src/main/java/Baymax.java b/src/main/java/Baymax.java index cc791f206..e52ee5f95 100644 --- a/src/main/java/Baymax.java +++ b/src/main/java/Baymax.java @@ -1,8 +1,8 @@ import java.lang.String; import java.util.Scanner; -public class Baymax{ - public static void main(String[] args) throws BaymaxException { +public class Baymax { + public static void main(String[] args) { Scanner in = new Scanner(System.in); String command; @@ -20,68 +20,40 @@ public static void main(String[] args) throws BaymaxException { word_split = command.split(" ", 2); String taskName = word_split[0]; - System.out.println(horiLine); //different functions based on command lines switch (taskName) { case "todo": - try { - tManager.addTask(new Todo(word_split[1])); - } catch (IndexOutOfBoundsException e) { - System.out.println(" ☹ OOPS!!! The description of a todo cannot be empty."); - } catch(BaymaxException b) { - System.out.println(b.getMessage() + "Let's try again."); - } + tManager.addTask(new Todo(word_split[1])); break; case "deadline": - try { - taskWord = word_split[1].split("/by ", 2); - taskDescrip = taskWord[0]; - String ddl = taskWord[1]; - tManager.addTask(new Deadline(taskDescrip, ddl)); - } catch (IndexOutOfBoundsException e) { - System.out.println(" ☹ OOPS!!! The description of a deadline cannot be empty."); - } catch(BaymaxException b) { - System.out.println(b.getMessage() + "Let's try again."); - } + taskWord = word_split[1].split("/by ", 2); + taskDescrip = taskWord[0]; + String ddl = taskWord[1]; + tManager.addTask(new Deadline(taskDescrip, ddl)); break; case "event": - try { - taskWord = word_split[1].split("/at ", 2); - taskDescrip = taskWord[0]; - String eventTime = taskWord[1]; - tManager.addTask(new Event(taskDescrip, eventTime)); - } catch (IndexOutOfBoundsException e) { - System.out.println(" ☹ OOPS!!! The description of a event cannot be empty."); - } catch(BaymaxException b) { - System.out.println(b.getMessage() + "Let's try again."); - } + taskWord = word_split[1].split("/at ", 2); + taskDescrip = taskWord[0]; + String eventTime = taskWord[1]; + tManager.addTask(new Event(taskDescrip, eventTime)); break; case "list": tManager.printTaskList(); break; case "mark": - try { - tManager.markTask(Integer.parseInt(word_split[1]) - 1); - } catch(NumberFormatException e) { - System.out.println("Please enter an integer for task index. Let's try again."); - } catch(BaymaxException b) { - System.out.println(b.getMessage() + "Let's try again."); - } + System.out.println(horiLine); + tManager.markTask(Integer.parseInt(word_split[1]) - 1); + System.out.println(horiLine); break; case "unmark": - try { - tManager.unmarkTask(Integer.parseInt(word_split[1]) - 1); - } catch(NumberFormatException e) { - System.out.println("Please enter an integer for task index. Let's try again."); - } catch(BaymaxException b) { - System.out.println(b.getMessage() + "Let's try again."); - } + System.out.println(horiLine); + tManager.unmarkTask(Integer.parseInt(word_split[1]) - 1); + System.out.println(horiLine); break; default: - System.out.println(" ☹ OOPS!!! I'm sorry, but I don't know what that means :-( Please retry."); + System.out.println("Error. Please retry"); break; } - System.out.println(horiLine); command = in.nextLine(); } tManager.bye(); //bye diff --git a/src/main/java/BaymaxException.java b/src/main/java/BaymaxException.java deleted file mode 100644 index eff94bad1..000000000 --- a/src/main/java/BaymaxException.java +++ /dev/null @@ -1,5 +0,0 @@ -public class BaymaxException extends RuntimeException{ - public BaymaxException(String warning){ - super(warning); - } -} \ No newline at end of file diff --git a/src/main/java/TaskManager.java b/src/main/java/TaskManager.java index f431860de..27ad457be 100644 --- a/src/main/java/TaskManager.java +++ b/src/main/java/TaskManager.java @@ -21,18 +21,22 @@ public void bye() { public void addTask(Task description) { this.tManager[this.taskCount] = description; + System.out.println(horiLine); System.out.println(" Got it. I've added this task: \n"+ this.tManager[this.taskCount].description+"\n" + "Now you have " + (this.taskCount+1) + " tasks in the list."); + System.out.println(horiLine); this.taskCount++; } public void printTaskList() { + System.out.println(horiLine); System.out.println("Here are the tasks in your list:"); for (int i=0; i Date: Fri, 11 Feb 2022 22:26:43 +0800 Subject: [PATCH 12/28] Level 5. Handle Errors --- src/main/java/Baymax.java | 59 ++++++++++++++++++++++-------- src/main/java/BaymaxException.java | 5 +++ src/main/java/TaskManager.java | 4 -- 3 files changed, 49 insertions(+), 19 deletions(-) create mode 100644 src/main/java/BaymaxException.java diff --git a/src/main/java/Baymax.java b/src/main/java/Baymax.java index e52ee5f95..f8a5e1054 100644 --- a/src/main/java/Baymax.java +++ b/src/main/java/Baymax.java @@ -20,41 +20,70 @@ public static void main(String[] args) { word_split = command.split(" ", 2); String taskName = word_split[0]; + System.out.println(horiLine); //different functions based on command lines switch (taskName) { case "todo": - tManager.addTask(new Todo(word_split[1])); + try { + tManager.addTask(new Todo(word_split[1])); + } catch (IndexOutOfBoundsException e) { + System.out.println(" ☹ OOPS!!! The description of a todo cannot be empty."); + } catch (BaymaxException b){ + System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); + } break; case "deadline": - taskWord = word_split[1].split("/by ", 2); - taskDescrip = taskWord[0]; - String ddl = taskWord[1]; - tManager.addTask(new Deadline(taskDescrip, ddl)); + try { + taskWord = word_split[1].split("/by ", 2); + taskDescrip = taskWord[0]; + String ddl = taskWord[1]; + tManager.addTask(new Deadline(taskDescrip, ddl)); + } catch (IndexOutOfBoundsException e) { + System.out.println(" ☹ OOPS!!! The description of a deadline cannot be empty."); + } catch (BaymaxException b){ + System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); + } break; case "event": - taskWord = word_split[1].split("/at ", 2); - taskDescrip = taskWord[0]; - String eventTime = taskWord[1]; - tManager.addTask(new Event(taskDescrip, eventTime)); + try { + taskWord = word_split[1].split("/at ", 2); + taskDescrip = taskWord[0]; + String eventTime = taskWord[1]; + tManager.addTask(new Event(taskDescrip, eventTime)); + } catch (IndexOutOfBoundsException e) { + System.out.println(" ☹ OOPS!!! The description of a event cannot be empty."); + } catch (BaymaxException b){ + System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); + } break; case "list": tManager.printTaskList(); break; case "mark": - System.out.println(horiLine); - tManager.markTask(Integer.parseInt(word_split[1]) - 1); - System.out.println(horiLine); + try { + tManager.markTask(Integer.parseInt(word_split[1]) - 1); + } catch (IndexOutOfBoundsException e) { + System.out.println("Please input an integer for task index."); + } catch (BaymaxException b){ + System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); + } break; case "unmark": - System.out.println(horiLine); - tManager.unmarkTask(Integer.parseInt(word_split[1]) - 1); - System.out.println(horiLine); + try { + tManager.unmarkTask(Integer.parseInt(word_split[1]) - 1); + } catch (IndexOutOfBoundsException e) { + System.out.println("Please input an integer for task index."); + } catch (BaymaxException b){ + System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); + } break; default: System.out.println("Error. Please retry"); break; } + System.out.println(horiLine); command = in.nextLine(); + } tManager.bye(); //bye } diff --git a/src/main/java/BaymaxException.java b/src/main/java/BaymaxException.java new file mode 100644 index 000000000..4f831e756 --- /dev/null +++ b/src/main/java/BaymaxException.java @@ -0,0 +1,5 @@ +public class BaymaxException extends RuntimeException{ + public BaymaxException(String errorMessage){ + super(errorMessage); + } +} diff --git a/src/main/java/TaskManager.java b/src/main/java/TaskManager.java index 27ad457be..f431860de 100644 --- a/src/main/java/TaskManager.java +++ b/src/main/java/TaskManager.java @@ -21,22 +21,18 @@ public void bye() { public void addTask(Task description) { this.tManager[this.taskCount] = description; - System.out.println(horiLine); System.out.println(" Got it. I've added this task: \n"+ this.tManager[this.taskCount].description+"\n" + "Now you have " + (this.taskCount+1) + " tasks in the list."); - System.out.println(horiLine); this.taskCount++; } public void printTaskList() { - System.out.println(horiLine); System.out.println("Here are the tasks in your list:"); for (int i=0; i Date: Fri, 18 Feb 2022 11:13:02 +0800 Subject: [PATCH 13/28] Improve code quality and fix previous bugs --- src/main/java/Baymax.java | 46 +++++++--------------------------- src/main/java/Deadline.java | 2 +- src/main/java/TaskManager.java | 22 ++++++++++++---- 3 files changed, 27 insertions(+), 43 deletions(-) diff --git a/src/main/java/Baymax.java b/src/main/java/Baymax.java index ee86dd86b..7bb1d8c71 100644 --- a/src/main/java/Baymax.java +++ b/src/main/java/Baymax.java @@ -23,36 +23,15 @@ public static void main(String[] args) { //different functions based on command lines switch (taskName) { case "todo": -<<<<<<< HEAD tManager.addTask(new Todo(word_split[1])); break; - case "deadline": - taskWord = word_split[1].split("/by ", 2); - taskDescrip = taskWord[0]; - String ddl = taskWord[1]; - tManager.addTask(new Deadline(taskDescrip, ddl)); - break; - case "event": - taskWord = word_split[1].split("/at ", 2); - taskDescrip = taskWord[0]; - String eventTime = taskWord[1]; - tManager.addTask(new Event(taskDescrip, eventTime)); -======= - try { - tManager.addTask(new Todo(word_split[1])); - } catch (IndexOutOfBoundsException e) { - System.out.println(" ☹ OOPS!!! The description of a todo cannot be empty."); - } catch (BaymaxException b){ - System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); - } - break; case "deadline": try { taskWord = word_split[1].split("/by ", 2); taskDescrip = taskWord[0]; String ddl = taskWord[1]; tManager.addTask(new Deadline(taskDescrip, ddl)); - } catch (IndexOutOfBoundsException e) { + } catch (ArrayIndexOutOfBoundsException e) { System.out.println(" ☹ OOPS!!! The description of a deadline cannot be empty."); } catch (BaymaxException b){ System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); @@ -64,18 +43,16 @@ public static void main(String[] args) { taskDescrip = taskWord[0]; String eventTime = taskWord[1]; tManager.addTask(new Event(taskDescrip, eventTime)); - } catch (IndexOutOfBoundsException e) { - System.out.println(" ☹ OOPS!!! The description of a event cannot be empty."); + } catch (ArrayIndexOutOfBoundsException e) { + System.out.println(" ☹ OOPS!!! The description of an event cannot be empty."); } catch (BaymaxException b){ System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); } ->>>>>>> branch-Level-5 break; case "list": tManager.printTaskList(); break; case "mark": -<<<<<<< HEAD System.out.println(horiLine); tManager.markTask(Integer.parseInt(word_split[1]) - 1); System.out.println(horiLine); @@ -84,7 +61,6 @@ public static void main(String[] args) { System.out.println(horiLine); tManager.unmarkTask(Integer.parseInt(word_split[1]) - 1); System.out.println(horiLine); -======= try { tManager.markTask(Integer.parseInt(word_split[1]) - 1); } catch (IndexOutOfBoundsException e) { @@ -93,18 +69,14 @@ public static void main(String[] args) { System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); } break; - case "unmark": - try { - tManager.unmarkTask(Integer.parseInt(word_split[1]) - 1); - } catch (IndexOutOfBoundsException e) { - System.out.println("Please input an integer for task index."); - } catch (BaymaxException b){ - System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); - } ->>>>>>> branch-Level-5 - break; +// case "delete": +// System.out.println(horiLine); +// tManager.deleteTask(Integer.parseInt(word_split[1]) - 1); +// System.out.println(horiLine); default: + System.out.println(horiLine); System.out.println("Error. Please retry"); + System.out.println(horiLine); break; } command = in.nextLine(); diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index ec28f0e8a..c40d855e0 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -9,7 +9,7 @@ public Deadline(String description, String ddl) { @Override public String getStatusIcon() { - return "[D]" + super.getStatusIcon() +"( by: "+ ddl + ")"; + return "[D]" + super.getStatusIcon() ; } @Override diff --git a/src/main/java/TaskManager.java b/src/main/java/TaskManager.java index 27ad457be..0e16316a9 100644 --- a/src/main/java/TaskManager.java +++ b/src/main/java/TaskManager.java @@ -19,12 +19,12 @@ public void bye() { System.out.println(horiLine + goodbye + horiLine);//bye } - public void addTask(Task description) { - this.tManager[this.taskCount] = description; + public void addTask(Task newT) { + this.tManager[this.taskCount] = newT; System.out.println(horiLine); - System.out.println(" Got it. I've added this task: \n"+ - this.tManager[this.taskCount].description+"\n" + - "Now you have " + (this.taskCount+1) + " tasks in the list."); + System.out.println(" Got it. I've added this task: \n"+ this.tManager[this.taskCount].getStatusIcon()+ + this.tManager[this.taskCount]. getDescription()+"\n" + + "Now you have " + + (this.taskCount+1) + " tasks in the list."); System.out.println(horiLine); this.taskCount++; } @@ -53,5 +53,17 @@ public void unmarkTask (int taskIndex) { this.tManager[taskIndex].getDescription()); } +// public void deleteTask (int taskIndex) { +// +// Task deleted = tManager.get(taskIndex - 1); +// tManager.remove(taskIndex - 1); +// +// System.out.println(horiLine); +// System.out.println("\t Noted. I've removed this task:"); +// System.out.println("\t\t " + deleted.toString()); +// System.out.println("\t Now you have " + tasks.size() + " tasks in the list."); +// System.out.println(horiLine); +// } + } From b820e7b98a2c138da4a54b48eeb7bf88b1ce7bf6 Mon Sep 17 00:00:00 2001 From: LI-XINYI1 Date: Fri, 18 Feb 2022 11:24:37 +0800 Subject: [PATCH 14/28] change TaskManager from arrary to ArrayList --- src/main/java/Baymax.java | 5 ++--- src/main/java/TaskManager.java | 34 ++++++++++++++++++---------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/main/java/Baymax.java b/src/main/java/Baymax.java index 7bb1d8c71..615a2cc5e 100644 --- a/src/main/java/Baymax.java +++ b/src/main/java/Baymax.java @@ -58,16 +58,15 @@ public static void main(String[] args) { System.out.println(horiLine); break; case "unmark": - System.out.println(horiLine); - tManager.unmarkTask(Integer.parseInt(word_split[1]) - 1); System.out.println(horiLine); try { - tManager.markTask(Integer.parseInt(word_split[1]) - 1); + tManager.unmarkTask(Integer.parseInt(word_split[1]) - 1); } catch (IndexOutOfBoundsException e) { System.out.println("Please input an integer for task index."); } catch (BaymaxException b){ System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); } + System.out.println(horiLine); break; // case "delete": // System.out.println(horiLine); diff --git a/src/main/java/TaskManager.java b/src/main/java/TaskManager.java index 0e16316a9..899e066a0 100644 --- a/src/main/java/TaskManager.java +++ b/src/main/java/TaskManager.java @@ -1,8 +1,10 @@ +import java.util.ArrayList; + public class TaskManager { String horiLine = "____________________________________________________________\n"; - private final Task[] tManager = new Task[100]; - private int taskCount = 0; + + private final ArrayList tasks = new ArrayList<>(); public TaskManager() { } @@ -20,37 +22,37 @@ public void bye() { } public void addTask(Task newT) { - this.tManager[this.taskCount] = newT; + tasks.add(newT); System.out.println(horiLine); - System.out.println(" Got it. I've added this task: \n"+ this.tManager[this.taskCount].getStatusIcon()+ - this.tManager[this.taskCount]. getDescription()+"\n" + - "Now you have " + + (this.taskCount+1) + " tasks in the list."); + System.out.println(" Got it. I've added this task: \n"+ newT.getStatusIcon()+ + newT.getDescription()+"\n" + + "Now you have " + + tasks.size() + " tasks in the list."); System.out.println(horiLine); - this.taskCount++; } public void printTaskList() { System.out.println(horiLine); System.out.println("Here are the tasks in your list:"); - for (int i=0; i Date: Fri, 18 Feb 2022 21:15:25 +0800 Subject: [PATCH 15/28] Level 6. Delete : Add support for deleting tasks from the list. --- src/main/java/Baymax.java | 9 +++++---- src/main/java/TaskManager.java | 19 ++++++++----------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/main/java/Baymax.java b/src/main/java/Baymax.java index 615a2cc5e..ba9485171 100644 --- a/src/main/java/Baymax.java +++ b/src/main/java/Baymax.java @@ -68,10 +68,11 @@ public static void main(String[] args) { } System.out.println(horiLine); break; -// case "delete": -// System.out.println(horiLine); -// tManager.deleteTask(Integer.parseInt(word_split[1]) - 1); -// System.out.println(horiLine); + case "delete": + System.out.println(horiLine); + tManager.deleteTask(Integer.parseInt(word_split[1]) - 1); + System.out.println(horiLine); + break; default: System.out.println(horiLine); System.out.println("Error. Please retry"); diff --git a/src/main/java/TaskManager.java b/src/main/java/TaskManager.java index 899e066a0..16bcad5fb 100644 --- a/src/main/java/TaskManager.java +++ b/src/main/java/TaskManager.java @@ -55,17 +55,14 @@ public void unmarkTask (int taskIndex) { temp.getDescription()); } -// public void deleteTask (int taskIndex) { -// -// Task deleted = tManager.get(taskIndex - 1); -// tManager.remove(taskIndex - 1); -// -// System.out.println(horiLine); -// System.out.println("\t Noted. I've removed this task:"); -// System.out.println("\t\t " + deleted.toString()); -// System.out.println("\t Now you have " + tasks.size() + " tasks in the list."); -// System.out.println(horiLine); -// } + public void deleteTask (int taskIndex) { + Task deleted = tasks.get(taskIndex); + System.out.println("Noted. I've removed this task:"); + System.out.println(String.format("%s %s", deleted.getStatusIcon(), deleted.getDescription())); + tasks.remove(taskIndex); + System.out.println("Now you have " + tasks.size() + " tasks in the list."); + + } } From 89b12544bf9b7c7da6e07621415bfaedae30ed26 Mon Sep 17 00:00:00 2001 From: LI-XINYI1 Date: Fri, 18 Feb 2022 21:18:29 +0800 Subject: [PATCH 16/28] add exception handler (try catch) --- src/main/java/Baymax.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/Baymax.java b/src/main/java/Baymax.java index ba9485171..173b43305 100644 --- a/src/main/java/Baymax.java +++ b/src/main/java/Baymax.java @@ -54,14 +54,20 @@ public static void main(String[] args) { break; case "mark": System.out.println(horiLine); - tManager.markTask(Integer.parseInt(word_split[1]) - 1); + try { + tManager.markTask(Integer.parseInt(word_split[1]) - 1); + } catch (ArrayIndexOutOfBoundsException e) { + System.out.println("Please input an integer for task index."); + } catch (BaymaxException b){ + System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); + } System.out.println(horiLine); break; case "unmark": System.out.println(horiLine); try { tManager.unmarkTask(Integer.parseInt(word_split[1]) - 1); - } catch (IndexOutOfBoundsException e) { + } catch (ArrayIndexOutOfBoundsException e) { System.out.println("Please input an integer for task index."); } catch (BaymaxException b){ System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); @@ -70,7 +76,13 @@ public static void main(String[] args) { break; case "delete": System.out.println(horiLine); - tManager.deleteTask(Integer.parseInt(word_split[1]) - 1); + try { + tManager.deleteTask(Integer.parseInt(word_split[1]) - 1); + } catch (ArrayIndexOutOfBoundsException e) { + System.out.println("Please input an integer for task index."); + } catch (BaymaxException b){ + System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); + } System.out.println(horiLine); break; default: From c0a0f969648e767cf5b01350003edd9f558f30ca Mon Sep 17 00:00:00 2001 From: LI-XINYI1 Date: Fri, 18 Feb 2022 21:51:34 +0800 Subject: [PATCH 17/28] improve code quality and clarity --- src/main/java/TaskManager.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/TaskManager.java b/src/main/java/TaskManager.java index 16bcad5fb..5be158dfb 100644 --- a/src/main/java/TaskManager.java +++ b/src/main/java/TaskManager.java @@ -34,7 +34,8 @@ public void printTaskList() { System.out.println(horiLine); System.out.println("Here are the tasks in your list:"); for (Task task: tasks) { - System.out.println(String.format("%d. %s %s", tasks.indexOf(task)+1, task.getStatusIcon(), task.getDescription())); + String text = String.format("%d. %s %s", tasks.indexOf(task)+1, task.getStatusIcon(), task.getDescription()); + System.out.println(text); } System.out.println(horiLine); } @@ -59,7 +60,8 @@ public void deleteTask (int taskIndex) { Task deleted = tasks.get(taskIndex); System.out.println("Noted. I've removed this task:"); - System.out.println(String.format("%s %s", deleted.getStatusIcon(), deleted.getDescription())); + String text = String.format("%s %s", deleted.getStatusIcon(), deleted.getDescription()); + System.out.println(text); tasks.remove(taskIndex); System.out.println("Now you have " + tasks.size() + " tasks in the list."); From 64b13703fa8fe89aa088c7ab4123046d719ced83 Mon Sep 17 00:00:00 2001 From: LI-XINYI1 Date: Fri, 18 Feb 2022 23:16:40 +0800 Subject: [PATCH 18/28] Level 7.save. Add record txt file. --- data/Baymax.txt | 4 ++ src/main/java/Baymax.java | 16 +++++++- src/main/java/Deadline.java | 6 +++ src/main/java/Event.java | 6 +++ src/main/java/Task.java | 6 +++ src/main/java/TaskManager.java | 68 +++++++++++++++++++++++++++++++++- src/main/java/Todo.java | 6 +++ 7 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 data/Baymax.txt diff --git a/data/Baymax.txt b/data/Baymax.txt new file mode 100644 index 000000000..6d26c7ff7 --- /dev/null +++ b/data/Baymax.txt @@ -0,0 +1,4 @@ +T / 1 / read book +D / 0 / return book / June 6th +E / 0 / project meeting / Aug 6th 2-4pm +T / 1 / join sports club \ No newline at end of file diff --git a/src/main/java/Baymax.java b/src/main/java/Baymax.java index 173b43305..91b3a596b 100644 --- a/src/main/java/Baymax.java +++ b/src/main/java/Baymax.java @@ -1,8 +1,11 @@ import java.lang.String; import java.util.Scanner; +import java.io.FileNotFoundException; +import java.io.IOException; + public class Baymax { - public static void main(String[] args) { + public static void main(String[] args) throws IOException { Scanner in = new Scanner(System.in); String command; @@ -11,6 +14,15 @@ public static void main(String[] args) { TaskManager tManager = new TaskManager(); String horiLine = "____________________________________________________________\n"; + //load record + try { + tManager.initialiseNewFile(); + } catch (FileNotFoundException e) { + System.out.println("File not found."); + } catch (IOException e) { + e.printStackTrace(); + } + tManager.welcome(); //greating command = in.nextLine(); @@ -94,6 +106,8 @@ public static void main(String[] args) { command = in.nextLine(); } + tManager.saveTask(); tManager.bye(); //bye } + } diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index c40d855e0..d16e10db8 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -16,4 +16,10 @@ public String getStatusIcon() { public String getDescription() { return super.getDescription()+ "( by: "+ ddl + ")"; } + + @Override + public String saveInfo(){ + String sep = " / "; + return "D" + sep + super.saveInfo() + this.ddl; + } } \ No newline at end of file diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 90df3887b..405ea2028 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -16,4 +16,10 @@ public String getStatusIcon() { public String getDescription() { return super.getDescription()+ "( at: "+ time + ")"; } + + @Override + public String saveInfo(){ + String sep =" / "; + return "E" + sep + super.saveInfo() + this.time; + } } \ No newline at end of file diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 543090f28..0d1dcebf1 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -22,4 +22,10 @@ public void markTaskDone() { public void unmarkTaskDone() { isDone = false; } + + public String saveInfo(){ + String sep = " / "; + String printT = sep + (isDone ? "1" : "0") + sep + this.description; + return printT; + } } diff --git a/src/main/java/TaskManager.java b/src/main/java/TaskManager.java index 16bcad5fb..5861fa966 100644 --- a/src/main/java/TaskManager.java +++ b/src/main/java/TaskManager.java @@ -1,9 +1,13 @@ +import java.io.File; +import java.io.IOException; +import java.io.FileWriter; + import java.util.ArrayList; +import java.util.Scanner; public class TaskManager { String horiLine = "____________________________________________________________\n"; - private final ArrayList tasks = new ArrayList<>(); public TaskManager() { @@ -64,5 +68,67 @@ public void deleteTask (int taskIndex) { System.out.println("Now you have " + tasks.size() + " tasks in the list."); } + + public void initialiseNewFile() throws IOException { + System.out.println(horiLine); + System.out.println("Record accessing......"); + File dir = new File("data"); + if(!dir.exists()){ + dir.mkdir(); + System.out.println("create a new directory \"data\"...... "); + } + File file = new File("data/Baymax.txt"); + if(!file.exists()) { + file.createNewFile(); + System.out.println("create a new file \"Baymax.txt\"...... "); + System.out.println(horiLine); + return; + } + Scanner initTask = new Scanner(file); + int taskIndex = -1; + while(initTask.hasNext()){ + taskIndex++; + Task temp; + String[] word_split = initTask.nextLine().split(" / "); + switch(word_split[0]){ + case "T": + tasks.add(new Todo(word_split[2])); + if (word_split[1].equals("1")) { + temp = tasks.get(taskIndex); + temp.markTaskDone(); + } + break; + case "D": + tasks.add(new Deadline(word_split[2],word_split[3])); + if (word_split[1].equals("1")) { + temp = tasks.get(taskIndex); + temp.markTaskDone(); + } + break; + case "E": + tasks.add(new Event(word_split[2],word_split[3])); + if (word_split[1].equals("1")) { + temp = tasks.get(taskIndex); + temp.markTaskDone(); + } + break; + default: + System.out.println(horiLine); + System.out.println("Error accur, please check."); + System.out.println(horiLine); + break; + } + } + System.out.println(horiLine); + } + + public void saveTask() throws IOException { + + FileWriter fw = new FileWriter("data/Baymax.txt"); + for(int i = 0; i < tasks.size(); i++){ + fw.write(tasks.get(i).saveInfo() + "\n"); + } + fw.close(); + } } diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java index fc3262b12..8f36af1cd 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/Todo.java @@ -7,4 +7,10 @@ public Todo(String description) { public String getStatusIcon() { return "[T]" + super.getStatusIcon(); } + + @Override + public String saveInfo(){ + String sep =" / "; + return "T" + sep + super.saveInfo() ; + } } From 041d1b7a60ecfd74b4ef3fe0d10200a900bc2917 Mon Sep 17 00:00:00 2001 From: LI-XINYI1 Date: Fri, 18 Feb 2022 23:53:10 +0800 Subject: [PATCH 19/28] merge branch-level-6 and master --- src/main/java/Baymax.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/Baymax.java b/src/main/java/Baymax.java index 173b43305..afbdce020 100644 --- a/src/main/java/Baymax.java +++ b/src/main/java/Baymax.java @@ -83,6 +83,7 @@ public static void main(String[] args) { } catch (BaymaxException b){ System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); } + //check branch merge System.out.println(horiLine); break; default: From 090c9061e2909836e17b214234829ef3e012e1ef Mon Sep 17 00:00:00 2001 From: LI-XINYI1 Date: Sat, 19 Feb 2022 00:00:34 +0800 Subject: [PATCH 20/28] A-Jar : create a jar file --- src/main/java/META-INF/MANIFEST.MF | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/main/java/META-INF/MANIFEST.MF diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 000000000..1da7a8fc7 --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: Baymax + From 68faea8eef27d9bcf66b32807a2c60aa1ffb8538 Mon Sep 17 00:00:00 2001 From: LI-XINYI1 Date: Sat, 19 Feb 2022 00:32:50 +0800 Subject: [PATCH 21/28] Debug and improve code quality. --- src/main/java/Deadline.java | 2 +- src/main/java/Event.java | 2 +- src/main/java/TaskManager.java | 1 + src/main/java/Todo.java | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index d16e10db8..5801ff737 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -20,6 +20,6 @@ public String getDescription() { @Override public String saveInfo(){ String sep = " / "; - return "D" + sep + super.saveInfo() + this.ddl; + return "D" + super.saveInfo() + sep + this.ddl; } } \ No newline at end of file diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 405ea2028..47abb5b9a 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -20,6 +20,6 @@ public String getDescription() { @Override public String saveInfo(){ String sep =" / "; - return "E" + sep + super.saveInfo() + this.time; + return "E" + super.saveInfo() + sep + this.time; } } \ No newline at end of file diff --git a/src/main/java/TaskManager.java b/src/main/java/TaskManager.java index c40f4eec5..9962f3143 100644 --- a/src/main/java/TaskManager.java +++ b/src/main/java/TaskManager.java @@ -92,6 +92,7 @@ public void initialiseNewFile() throws IOException { taskIndex++; Task temp; String[] word_split = initTask.nextLine().split(" / "); + //System.out.println(word_split[0]+" sdf " + word_split[1] + " df "+ word_split[2]+ " df "+ word_split[3]); switch(word_split[0]){ case "T": tasks.add(new Todo(word_split[2])); diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java index 8f36af1cd..d2f3b24ec 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/Todo.java @@ -11,6 +11,6 @@ public String getStatusIcon() { @Override public String saveInfo(){ String sep =" / "; - return "T" + sep + super.saveInfo() ; + return "T" + super.saveInfo() + sep; } } From 03e38ad8db10612164c7052cad729a6b4df8ad97 Mon Sep 17 00:00:00 2001 From: LI-XINYI1 Date: Fri, 4 Mar 2022 07:34:58 +0800 Subject: [PATCH 22/28] =?UTF-8?q?A-MoreOOP=EF=BC=9AMake=20the=20code=20mor?= =?UTF-8?q?e=20OOP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Baymax.java | 218 ++++++++++-------- src/main/java/TaskManager.java | 137 ----------- src/main/java/{ => baymax/data}/Deadline.java | 7 + src/main/java/{ => baymax/data}/Event.java | 7 + src/main/java/{ => baymax/data}/Task.java | 7 + src/main/java/baymax/data/TaskManager.java | 130 +++++++++++ src/main/java/{ => baymax/data}/Todo.java | 11 +- .../baymax/exception/BaymaxException.java | 7 + src/main/java/baymax/parse/Parser.java | 111 +++++++++ src/main/java/baymax/storage/Storage.java | 86 +++++++ src/main/java/baymax/ui/Ui.java | 56 +++++ 11 files changed, 543 insertions(+), 234 deletions(-) delete mode 100644 src/main/java/TaskManager.java rename src/main/java/{ => baymax/data}/Deadline.java (82%) rename src/main/java/{ => baymax/data}/Event.java (82%) rename src/main/java/{ => baymax/data}/Task.java (85%) create mode 100644 src/main/java/baymax/data/TaskManager.java rename src/main/java/{ => baymax/data}/Todo.java (63%) create mode 100644 src/main/java/baymax/exception/BaymaxException.java create mode 100644 src/main/java/baymax/parse/Parser.java create mode 100644 src/main/java/baymax/storage/Storage.java create mode 100644 src/main/java/baymax/ui/Ui.java diff --git a/src/main/java/Baymax.java b/src/main/java/Baymax.java index d8c2bea0a..c7b91317e 100644 --- a/src/main/java/Baymax.java +++ b/src/main/java/Baymax.java @@ -1,114 +1,140 @@ +import baymax.data.TaskManager; +import baymax.data.Deadline; +import baymax.data.Event; +import baymax.data.Todo; + import java.lang.String; import java.util.Scanner; import java.io.FileNotFoundException; import java.io.IOException; +import baymax.data.TaskManager; +import baymax.ui.Ui; +import baymax.parse.Parser; +import baymax.storage.Storage; + public class Baymax { - public static void main(String[] args) throws IOException { - Scanner in = new Scanner(System.in); - String command; - String taskDescrip; - String[] taskWord; - TaskManager tManager = new TaskManager(); - String horiLine = "____________________________________________________________\n"; + private final Ui ui; + private TaskManager tManager; - //load record + public Baymax(String filePath) { + ui = new Ui(); + Storage storage = new Storage(filePath); try { - tManager.initialiseNewFile(); - } catch (FileNotFoundException e) { - System.out.println("File not found."); + tManager = new TaskManager(storage.load()); } catch (IOException e) { - e.printStackTrace(); + ui.showLoadingError(e.getMessage()); + tManager = new TaskManager(); } + } - tManager.welcome(); //greating + public void run() throws IOException { + ui.displayWelcomeMessage(); + boolean isBye; + isBye = false; + while (!isBye) { + String fullCommand = ui.getUserCommand(); + Parser parse = new Parser(ui); + parse.parse(fullCommand, tManager); + isBye = parse.getExit(); + } + ui.showByeMessage(); + } - command = in.nextLine(); - while (!command.equals("bye")) { + public static void main(String[] args) throws IOException { + new Baymax("data/Baymax.txt").run(); + } +} - String[] word_split; - word_split = command.split(" ", 2); - String taskName = word_split[0]; - //different functions based on command lines - switch (taskName) { - case "todo": - tManager.addTask(new Todo(word_split[1])); - break; - case "deadline": - try { - taskWord = word_split[1].split("/by ", 2); - taskDescrip = taskWord[0]; - String ddl = taskWord[1]; - tManager.addTask(new Deadline(taskDescrip, ddl)); - } catch (ArrayIndexOutOfBoundsException e) { - System.out.println(" ☹ OOPS!!! The description of a deadline cannot be empty."); - } catch (BaymaxException b){ - System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); - } - break; - case "event": - try { - taskWord = word_split[1].split("/at ", 2); - taskDescrip = taskWord[0]; - String eventTime = taskWord[1]; - tManager.addTask(new Event(taskDescrip, eventTime)); - } catch (ArrayIndexOutOfBoundsException e) { - System.out.println(" ☹ OOPS!!! The description of an event cannot be empty."); - } catch (BaymaxException b){ - System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); - } - break; - case "list": - tManager.printTaskList(); - break; - case "mark": - System.out.println(horiLine); - try { - tManager.markTask(Integer.parseInt(word_split[1]) - 1); - } catch (ArrayIndexOutOfBoundsException e) { - System.out.println("Please input an integer for task index."); - } catch (BaymaxException b){ - System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); - } - System.out.println(horiLine); - break; - case "unmark": - System.out.println(horiLine); - try { - tManager.unmarkTask(Integer.parseInt(word_split[1]) - 1); - } catch (ArrayIndexOutOfBoundsException e) { - System.out.println("Please input an integer for task index."); - } catch (BaymaxException b){ - System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); - } - System.out.println(horiLine); - break; - case "delete": - System.out.println(horiLine); - try { - tManager.deleteTask(Integer.parseInt(word_split[1]) - 1); - } catch (ArrayIndexOutOfBoundsException e) { - System.out.println("Please input an integer for task index."); - } catch (BaymaxException b){ - System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); - } - //check branch merge - System.out.println(horiLine); - break; - default: - System.out.println(horiLine); - System.out.println("Error. Please retry"); - System.out.println(horiLine); - break; - } - command = in.nextLine(); +// tManager.welcome(); //greating + +// command = in.nextLine(); +// while (!command.equals("bye")) { +// +// String[] word_split; +// word_split = command.split(" ", 2); +// String taskName = word_split[0]; +// +// //different functions based on command lines +// switch (taskName) { +// case "todo": +// tManager.addTask(new Todo(word_split[1])); +// break; +// case "deadline": +// try { +// taskWord = word_split[1].split("/by ", 2); +// taskDescrip = taskWord[0]; +// String ddl = taskWord[1]; +// tManager.addTask(new Deadline(taskDescrip, ddl)); +// } catch (ArrayIndexOutOfBoundsException e) { +// System.out.println(" ☹ OOPS!!! The description of a deadline cannot be empty."); +// } catch (BaymaxException b){ +// System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); +// } +// break; +// case "event": +// try { +// taskWord = word_split[1].split("/at ", 2); +// taskDescrip = taskWord[0]; +// String eventTime = taskWord[1]; +// tManager.addTask(new Event(taskDescrip, eventTime)); +// } catch (ArrayIndexOutOfBoundsException e) { +// System.out.println(" ☹ OOPS!!! The description of an event cannot be empty."); +// } catch (BaymaxException b){ +// System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); +// } +// break; +// case "list": +// tManager.printTaskList(); +// break; +// case "mark": +// System.out.println(horiLine); +// try { +// tManager.markTask(Integer.parseInt(word_split[1]) - 1); +// } catch (ArrayIndexOutOfBoundsException e) { +// System.out.println("Please input an integer for task index."); +// } catch (BaymaxException b){ +// System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); +// } +// System.out.println(horiLine); +// break; +// case "unmark": +// System.out.println(horiLine); +// try { +// tManager.unmarkTask(Integer.parseInt(word_split[1]) - 1); +// } catch (ArrayIndexOutOfBoundsException e) { +// System.out.println("Please input an integer for task index."); +// } catch (BaymaxException b){ +// System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); +// } +// System.out.println(horiLine); +// break; +// case "delete": +// System.out.println(horiLine); +// try { +// tManager.deleteTask(Integer.parseInt(word_split[1]) - 1); +// } catch (ArrayIndexOutOfBoundsException e) { +// System.out.println("Please input an integer for task index."); +// } catch (BaymaxException b){ +// System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); +// } +// //check branch merge +// System.out.println(horiLine); +// break; +// default: +// System.out.println(horiLine); +// System.out.println("Error. Please retry"); +// System.out.println(horiLine); +// break; +// } +// command = in.nextLine(); +// +// } +// tManager.saveTask(); +// tManager.bye(); //bye +// } - } - tManager.saveTask(); - tManager.bye(); //bye - } -} diff --git a/src/main/java/TaskManager.java b/src/main/java/TaskManager.java deleted file mode 100644 index 9962f3143..000000000 --- a/src/main/java/TaskManager.java +++ /dev/null @@ -1,137 +0,0 @@ -import java.io.File; -import java.io.IOException; -import java.io.FileWriter; - -import java.util.ArrayList; -import java.util.Scanner; - -public class TaskManager { - - String horiLine = "____________________________________________________________\n"; - private final ArrayList tasks = new ArrayList<>(); - - public TaskManager() { - } - - public void welcome() { - String greeting = " Hello, I'm Baymax.\n"+ - " Your personal task managing companion. \n" + - " What can I do for you? \n"; - System.out.println(horiLine + greeting + horiLine); - } - - public void bye() { - String goodbye = " Bye. Hope to see you again soon! \n"; - System.out.println(horiLine + goodbye + horiLine);//bye - } - - public void addTask(Task newT) { - tasks.add(newT); - System.out.println(horiLine); - System.out.println(" Got it. I've added this task: \n"+ newT.getStatusIcon()+ - newT.getDescription()+"\n" + - "Now you have " + + tasks.size() + " tasks in the list."); - System.out.println(horiLine); - } - - public void printTaskList() { - System.out.println(horiLine); - System.out.println("Here are the tasks in your list:"); - for (Task task: tasks) { - String text = String.format("%d. %s %s", tasks.indexOf(task)+1, task.getStatusIcon(), task.getDescription()); - System.out.println(text); - } - System.out.println(horiLine); - } - - public void markTask (int taskIndex) { - Task temp = tasks.get(taskIndex); - temp.markTaskDone(); - System.out.println("Nice! I've marked this task as done:"); - System.out.println(temp.getStatusIcon() + " " + - temp.getDescription()); - } - - public void unmarkTask (int taskIndex) { - Task temp = tasks.get(taskIndex); - temp.unmarkTaskDone(); - System.out.println("OK, I've marked this task as not done yet:"); - System.out.println(temp.getStatusIcon() + " " + - temp.getDescription()); - } - - public void deleteTask (int taskIndex) { - - Task deleted = tasks.get(taskIndex); - System.out.println("Noted. I've removed this task:"); - String text = String.format("%s %s", deleted.getStatusIcon(), deleted.getDescription()); - System.out.println(text); - tasks.remove(taskIndex); - System.out.println("Now you have " + tasks.size() + " tasks in the list."); - - } - - public void initialiseNewFile() throws IOException { - System.out.println(horiLine); - System.out.println("Record accessing......"); - File dir = new File("data"); - if(!dir.exists()){ - dir.mkdir(); - System.out.println("create a new directory \"data\"...... "); - } - File file = new File("data/Baymax.txt"); - if(!file.exists()) { - file.createNewFile(); - System.out.println("create a new file \"Baymax.txt\"...... "); - System.out.println(horiLine); - return; - } - Scanner initTask = new Scanner(file); - int taskIndex = -1; - while(initTask.hasNext()){ - taskIndex++; - Task temp; - String[] word_split = initTask.nextLine().split(" / "); - //System.out.println(word_split[0]+" sdf " + word_split[1] + " df "+ word_split[2]+ " df "+ word_split[3]); - switch(word_split[0]){ - case "T": - tasks.add(new Todo(word_split[2])); - if (word_split[1].equals("1")) { - temp = tasks.get(taskIndex); - temp.markTaskDone(); - } - break; - case "D": - tasks.add(new Deadline(word_split[2],word_split[3])); - if (word_split[1].equals("1")) { - temp = tasks.get(taskIndex); - temp.markTaskDone(); - } - break; - case "E": - tasks.add(new Event(word_split[2],word_split[3])); - if (word_split[1].equals("1")) { - temp = tasks.get(taskIndex); - temp.markTaskDone(); - } - break; - default: - System.out.println(horiLine); - System.out.println("Error accur, please check."); - System.out.println(horiLine); - break; - } - } - System.out.println(horiLine); - } - - public void saveTask() throws IOException { - - FileWriter fw = new FileWriter("data/Baymax.txt"); - for(int i = 0; i < tasks.size(); i++){ - fw.write(tasks.get(i).saveInfo() + "\n"); - } - fw.close(); - } -} - diff --git a/src/main/java/Deadline.java b/src/main/java/baymax/data/Deadline.java similarity index 82% rename from src/main/java/Deadline.java rename to src/main/java/baymax/data/Deadline.java index 5801ff737..37f0da8e8 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/baymax/data/Deadline.java @@ -1,3 +1,5 @@ +package baymax.data; + public class Deadline extends Task { private String ddl; @@ -22,4 +24,9 @@ public String saveInfo(){ String sep = " / "; return "D" + super.saveInfo() + sep + this.ddl; } + + @Override + public String toString(){ + return "[D]" + super.toString(); + } } \ No newline at end of file diff --git a/src/main/java/Event.java b/src/main/java/baymax/data/Event.java similarity index 82% rename from src/main/java/Event.java rename to src/main/java/baymax/data/Event.java index 47abb5b9a..707a01ff7 100644 --- a/src/main/java/Event.java +++ b/src/main/java/baymax/data/Event.java @@ -1,3 +1,5 @@ +package baymax.data; + public class Event extends Task { private String time; @@ -22,4 +24,9 @@ public String saveInfo(){ String sep =" / "; return "E" + super.saveInfo() + sep + this.time; } + + @Override + public String toString(){ + return "[E]" + super.toString(); + } } \ No newline at end of file diff --git a/src/main/java/Task.java b/src/main/java/baymax/data/Task.java similarity index 85% rename from src/main/java/Task.java rename to src/main/java/baymax/data/Task.java index 0d1dcebf1..c7e291329 100644 --- a/src/main/java/Task.java +++ b/src/main/java/baymax/data/Task.java @@ -1,3 +1,5 @@ +package baymax.data; + public class Task { protected String description; @@ -28,4 +30,9 @@ public String saveInfo(){ String printT = sep + (isDone ? "1" : "0") + sep + this.description; return printT; } + + public String toString(){ + return getStatusIcon() + " " + getDescription(); + + } } diff --git a/src/main/java/baymax/data/TaskManager.java b/src/main/java/baymax/data/TaskManager.java new file mode 100644 index 000000000..0dcc40c4f --- /dev/null +++ b/src/main/java/baymax/data/TaskManager.java @@ -0,0 +1,130 @@ +package baymax.data; + +import java.util.ArrayList; + +import baymax.storage.Storage; +import baymax.ui.Ui; + +public class TaskManager { + + String horiLine = "____________________________________________________________\n"; + private final ArrayList tasks; + private Ui ui; + + public TaskManager() { + tasks = new ArrayList<>(); + } + + public TaskManager(ArrayList tasks) { + this.tasks = tasks; + } + + public ArrayList getTasks() { + return tasks; + } + + public void addTask(Task newT) { + tasks.add(newT); + System.out.println(horiLine); + System.out.println(" Got it. I've added this task: \n"+ newT.getStatusIcon()+ + newT.getDescription()+"\n" + + "Now you have " + + tasks.size() + " tasks in the list."); + System.out.println(horiLine); + } + + + public void markTask (int taskIndex) { + System.out.println(horiLine); + Task temp = tasks.get(taskIndex); + temp.markTaskDone(); + System.out.println("Nice! I've marked this task as done:"); + System.out.println(temp.getStatusIcon() + " " + + temp.getDescription()); + System.out.println(horiLine); + } + + public void unmarkTask (int taskIndex) { + System.out.println(horiLine); + Task temp = tasks.get(taskIndex); + temp.unmarkTaskDone(); + System.out.println("OK, I've marked this task as not done yet:"); + System.out.println(temp.getStatusIcon() + " " + + temp.getDescription()); + System.out.println(horiLine); + } + + public void deleteTask (int taskIndex) { + System.out.println(horiLine); + Task deleted = tasks.get(taskIndex); + System.out.println("Noted. I've removed this task:"); + String text = String.format("%s %s", deleted.getStatusIcon(), deleted.getDescription()); + System.out.println(text); + tasks.remove(taskIndex); + System.out.println("Now you have " + tasks.size() + " tasks in the list."); + System.out.println(horiLine); + } + +// public void initialiseNewFile() throws IOException { +// System.out.println(horiLine); +// System.out.println("Record accessing......"); +// File dir = new File("data"); +// if(!dir.exists()){ +// dir.mkdir(); +// System.out.println("create a new directory \"data\"...... "); +// } +// File file = new File("data/Baymax.txt"); +// if(!file.exists()) { +// file.createNewFile(); +// System.out.println("create a new file \"Baymax.txt\"...... "); +// System.out.println(horiLine); +// return; +// } +// Scanner initTask = new Scanner(file); +// int taskIndex = -1; +// while(initTask.hasNext()){ +// taskIndex++; +// Task temp; +// String[] word_split = initTask.nextLine().split(" / "); +// //System.out.println(word_split[0]+" sdf " + word_split[1] + " df "+ word_split[2]+ " df "+ word_split[3]); +// switch(word_split[0]){ +// case "T": +// tasks.add(new Todo(word_split[2])); +// if (word_split[1].equals("1")) { +// temp = tasks.get(taskIndex); +// temp.markTaskDone(); +// } +// break; +// case "D": +// tasks.add(new Deadline(word_split[2],word_split[3])); +// if (word_split[1].equals("1")) { +// temp = tasks.get(taskIndex); +// temp.markTaskDone(); +// } +// break; +// case "E": +// tasks.add(new Event(word_split[2],word_split[3])); +// if (word_split[1].equals("1")) { +// temp = tasks.get(taskIndex); +// temp.markTaskDone(); +// } +// break; +// default: +// System.out.println(horiLine); +// System.out.println("Error accur, please check."); +// System.out.println(horiLine); +// break; +// } +// } +// System.out.println(horiLine); +// } +// +// public void saveTask() throws IOException { +// +// FileWriter fw = new FileWriter("data/Baymax.txt"); +// for(int i = 0; i < tasks.size(); i++){ +// fw.write(tasks.get(i).saveInfo() + "\n"); +// } +// fw.close(); +// } +} + diff --git a/src/main/java/Todo.java b/src/main/java/baymax/data/Todo.java similarity index 63% rename from src/main/java/Todo.java rename to src/main/java/baymax/data/Todo.java index d2f3b24ec..8590efba7 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/baymax/data/Todo.java @@ -1,4 +1,8 @@ -public class Todo extends Task{ +package baymax.data; + +import baymax.data.Task; + +public class Todo extends Task { public Todo(String description) { super(description); } @@ -13,4 +17,9 @@ public String saveInfo(){ String sep =" / "; return "T" + super.saveInfo() + sep; } + + @Override + public String toString(){ + return "[T]" + super.toString(); + } } diff --git a/src/main/java/baymax/exception/BaymaxException.java b/src/main/java/baymax/exception/BaymaxException.java new file mode 100644 index 000000000..317ff8be7 --- /dev/null +++ b/src/main/java/baymax/exception/BaymaxException.java @@ -0,0 +1,7 @@ +package baymax.exception; + +public class BaymaxException extends RuntimeException{ + public BaymaxException(String errorMessage){ + super(errorMessage); + } +} diff --git a/src/main/java/baymax/parse/Parser.java b/src/main/java/baymax/parse/Parser.java new file mode 100644 index 000000000..710e96a70 --- /dev/null +++ b/src/main/java/baymax/parse/Parser.java @@ -0,0 +1,111 @@ +package baymax.parse; + +import baymax.data.Deadline; +import baymax.data.Event; +import baymax.data.TaskManager; +import baymax.data.Todo; +import baymax.storage.Storage; +import baymax.ui.Ui; +import baymax.exception.BaymaxException; + +import java.io.IOException; + +public class Parser { + private static boolean isBye; + + private static final String horiLine = "____________________________________________________________\n"; + + private Ui ui; + + public Parser(Ui ui) { + this.ui = ui; + } + public void setExit(boolean bye) { + isBye = bye; + } + + public boolean getExit() { + return isBye; + } + + public void parse(String fullCommand, TaskManager tManager) throws IOException { + String[] word_split; + word_split = fullCommand.split(" ", 2); + String command = word_split[0]; + + if (command.equals("bye")) { + Storage.encode(tManager.getTasks(), "data/Baymax.txt"); + setExit(true); + return; + } + + String taskDescrip; + switch (command) { + case "todo": + tManager.addTask(new Todo(word_split[1])); + break; + case "deadline": + try { + String[] taskWord = word_split[1].split("/by ", 2); + taskDescrip = taskWord[0]; + String ddl = taskWord[1]; + tManager.addTask(new Deadline(taskDescrip, ddl)); + } catch (ArrayIndexOutOfBoundsException e) { + System.out.println(" ☹ OOPS!!! The description of a deadline cannot be empty."); + } catch (BaymaxException b){ + System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); + } + break; + case "event": + try { + String[] taskWord = word_split[1].split("/at ", 2); + taskDescrip = taskWord[0]; + String eventTime = taskWord[1]; + tManager.addTask(new Event(taskDescrip, eventTime)); + } catch (ArrayIndexOutOfBoundsException e) { + System.out.println(" ☹ OOPS!!! The description of an event cannot be empty."); + } catch (BaymaxException b){ + System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); + } + break; + case "list": + ui.printTaskList(tManager.getTasks()); + break; + case "mark": + try { + tManager.markTask(Integer.parseInt(word_split[1]) - 1); + } catch (ArrayIndexOutOfBoundsException e) { + System.out.println("Please input an integer for task index."); + } catch (NumberFormatException e) { + System.out.println("Please put in integer value"); + } catch (BaymaxException b){ + System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); + } + break; + case "unmark": + try { + tManager.unmarkTask(Integer.parseInt(word_split[1]) - 1); + } catch (ArrayIndexOutOfBoundsException e) { + System.out.println("Please input an integer for task index."); + } catch (NumberFormatException e) { + System.out.println("Please put in integer value"); + }catch (BaymaxException b){ + System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); + } + break; + case "delete": + try { + tManager.deleteTask(Integer.parseInt(word_split[1]) - 1); + } catch (ArrayIndexOutOfBoundsException e) { + System.out.println("Please input an integer for task index."); + } catch (BaymaxException b){ + System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); + } + //check branch merge + break; + default: + System.out.println("Error. Please retry"); + break; + } + } +} diff --git a/src/main/java/baymax/storage/Storage.java b/src/main/java/baymax/storage/Storage.java new file mode 100644 index 000000000..170625268 --- /dev/null +++ b/src/main/java/baymax/storage/Storage.java @@ -0,0 +1,86 @@ +package baymax.storage; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Scanner; + +import baymax.data.Deadline; +import baymax.data.Event; +import baymax.data.Task; +import baymax.data.Todo; + + + +public class Storage { + + private final String filePath; + + public Storage(String filePath) { + this.filePath = filePath; + } + + public ArrayList load() throws IOException { + + File file = new File(filePath); + if(!file.exists()) { + file.createNewFile(); + } + Scanner s = new Scanner(file); + ArrayList tasks = new ArrayList<>(); + decode(s, tasks); + return tasks; + } + + public static void decode(Scanner s, ArrayList tasks) { + int taskIndex = -1; + while(s.hasNext()){ + taskIndex++; + Task temp; + String[] word_split = s.nextLine().split(" / "); + //System.out.println(word_split[0]+" sdf " + word_split[1] + " df "+ word_split[2]+ " df "+ word_split[3]); + switch(word_split[0]){ + case "T": + tasks.add(new Todo(word_split[2])); + if (word_split[1].equals("1")) { + temp = tasks.get(taskIndex); + temp.markTaskDone(); + } + break; + case "D": + tasks.add(new Deadline(word_split[2],word_split[3])); + if (word_split[1].equals("1")) { + temp = tasks.get(taskIndex); + temp.markTaskDone(); + } + break; + case "E": + tasks.add(new Event(word_split[2],word_split[3])); + if (word_split[1].equals("1")) { + temp = tasks.get(taskIndex); + temp.markTaskDone(); + } + break; + default: + System.out.println("Error accur, please check."); + break; + } + } + + } + + public void save(ArrayList tasks) throws IOException { + encode(tasks, filePath); + } + + public static void encode(ArrayList tasks, String filePath) throws IOException { + FileWriter fw = new FileWriter("data/Baymax.txt"); + for(int i = 0; i < tasks.size(); i++){ + fw.write(tasks.get(i).saveInfo() + "\n"); + } + fw.close(); + } +} + + diff --git a/src/main/java/baymax/ui/Ui.java b/src/main/java/baymax/ui/Ui.java new file mode 100644 index 000000000..46e673060 --- /dev/null +++ b/src/main/java/baymax/ui/Ui.java @@ -0,0 +1,56 @@ +package baymax.ui; + +import baymax.data.Task; +import java.util.ArrayList; +import java.util.Scanner; + +public class Ui { + String input; + private final Scanner in; + public static final String horiLine = "_____________________________________________"; + boolean isBye; + + public Ui() { + in = new Scanner(System.in); + isBye = false; + } + + public String getUserCommand() { + input = in.nextLine(); + return input; + } + + public void showLoadingError(String message) { + System.out.println(" You have error in loading data. Error message:"); + System.out.println("" + message); + } + + public void displayWelcomeMessage() { + System.out.println(horiLine); + String greeting = " Hello, I'm Baymax.\n"+ + " Your personal task managing companion. \n" + + " What can I do for you? \n"; + System.out.println(greeting); + System.out.println(horiLine); + } + + public void showByeMessage() { + System.out.println(horiLine); + System.out.println("Bye, Hope to see you again soon!"); + System.out.println(horiLine); + } + + public void printTaskList(ArrayList tasks) { + System.out.println(horiLine); + if (tasks.size() == 0) { + System.out.println("There's no tasks found! Let's add more tasks"); + return; + } + System.out.println("Here are the tasks in your list:"); + for (Task task : tasks) { + System.out.println(String.format("%d ", tasks.indexOf((task)) + 1) + task); + } + System.out.println(horiLine); + } + +} From 9a188e8546bffc85b6daa47542031cb1f9ed5033 Mon Sep 17 00:00:00 2001 From: LI-XINYI1 Date: Fri, 4 Mar 2022 07:50:48 +0800 Subject: [PATCH 23/28] Level 9: find: find a task by searching for a keyword --- data/Baymax.txt | 6 ++---- src/main/java/baymax/parse/Parser.java | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/data/Baymax.txt b/data/Baymax.txt index 6d26c7ff7..7e0bff506 100644 --- a/data/Baymax.txt +++ b/data/Baymax.txt @@ -1,4 +1,2 @@ -T / 1 / read book -D / 0 / return book / June 6th -E / 0 / project meeting / Aug 6th 2-4pm -T / 1 / join sports club \ No newline at end of file +E / 1 / Xinyi attend CS2113 lecture / Friday 18 Feb 2022 from 4 to 6pm +E / 1 / 1234 / jkd diff --git a/src/main/java/baymax/parse/Parser.java b/src/main/java/baymax/parse/Parser.java index 710e96a70..cc6bda5bd 100644 --- a/src/main/java/baymax/parse/Parser.java +++ b/src/main/java/baymax/parse/Parser.java @@ -7,8 +7,11 @@ import baymax.storage.Storage; import baymax.ui.Ui; import baymax.exception.BaymaxException; +import baymax.data.Task; import java.io.IOException; +import java.util.ArrayList; +import static java.util.stream.Collectors.toList; public class Parser { private static boolean isBye; @@ -103,6 +106,17 @@ public void parse(String fullCommand, TaskManager tManager) throws IOException { } //check branch merge break; + case "find": + try { + String search = word_split[1]; + ArrayList filteredTask = (ArrayList) tManager.getTasks().stream(). + filter(task -> task.getDescription().toLowerCase().contains(search.toLowerCase())).collect(toList()); + ui.printTaskList(filteredTask); + } catch (IndexOutOfBoundsException e) { + System.out.println("Please enter something for Baymax to search for!!"); + } + break; + default: System.out.println("Error. Please retry"); break; From cfeeb90363d2c86fce815c748e23e0b140fcae5c Mon Sep 17 00:00:00 2001 From: LI-XINYI1 Date: Fri, 4 Mar 2022 08:16:56 +0800 Subject: [PATCH 24/28] Level-8: dates and times --- data/Baymax.txt | 4 ++-- src/main/java/baymax/data/Deadline.java | 18 +++++++++++++----- src/main/java/baymax/data/Event.java | 18 +++++++++++++----- src/main/java/baymax/data/Todo.java | 2 +- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/data/Baymax.txt b/data/Baymax.txt index 7e0bff506..950413050 100644 --- a/data/Baymax.txt +++ b/data/Baymax.txt @@ -1,2 +1,2 @@ -E / 1 / Xinyi attend CS2113 lecture / Friday 18 Feb 2022 from 4 to 6pm -E / 1 / 1234 / jkd +E / 1 / Xinyi attend CS2113 lecture / 03 04 2022 +E / 1 / 1234 / 03 04 2022 diff --git a/src/main/java/baymax/data/Deadline.java b/src/main/java/baymax/data/Deadline.java index 37f0da8e8..2abf96498 100644 --- a/src/main/java/baymax/data/Deadline.java +++ b/src/main/java/baymax/data/Deadline.java @@ -1,12 +1,19 @@ package baymax.data; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + public class Deadline extends Task { - private String ddl; + private LocalDate ddl; public Deadline(String description, String ddl) { super(description); - this.ddl = ddl; + try{ + this.ddl = LocalDate.parse(ddl); + } catch(Exception e){ + this.ddl = LocalDate.parse(ddl,DateTimeFormatter.ofPattern("MM dd yyyy")); + } } @Override @@ -16,17 +23,18 @@ public String getStatusIcon() { @Override public String getDescription() { - return super.getDescription()+ "( by: "+ ddl + ")"; + return super.getDescription()+ + "( by: "+ ddl.format(DateTimeFormatter.ofPattern("MM dd yyyy")) + ")"; } @Override public String saveInfo(){ String sep = " / "; - return "D" + super.saveInfo() + sep + this.ddl; + return "D" + super.saveInfo() + sep + this.ddl.format(DateTimeFormatter.ofPattern("MM dd yyyy")) ; } @Override public String toString(){ - return "[D]" + super.toString(); + return super.toString(); } } \ No newline at end of file diff --git a/src/main/java/baymax/data/Event.java b/src/main/java/baymax/data/Event.java index 707a01ff7..e9270f6a8 100644 --- a/src/main/java/baymax/data/Event.java +++ b/src/main/java/baymax/data/Event.java @@ -1,12 +1,19 @@ package baymax.data; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + public class Event extends Task { - private String time; + private LocalDate time; public Event(String description, String time) { super(description); - this.time = time; + try{ + this.time = LocalDate.parse(time); + } catch(Exception e){ + this.time= LocalDate.parse(time,DateTimeFormatter.ofPattern("MM dd yyyy")); + } } @Override @@ -16,17 +23,18 @@ public String getStatusIcon() { @Override public String getDescription() { - return super.getDescription()+ "( at: "+ time + ")"; + return super.getDescription()+ + "( at: "+ time.format(DateTimeFormatter.ofPattern("MM dd yyyy")) + ")"; } @Override public String saveInfo(){ String sep =" / "; - return "E" + super.saveInfo() + sep + this.time; + return "E" + super.saveInfo() + sep + this.time.format(DateTimeFormatter.ofPattern("MM dd yyyy")) ; } @Override public String toString(){ - return "[E]" + super.toString(); + return super.toString(); } } \ No newline at end of file diff --git a/src/main/java/baymax/data/Todo.java b/src/main/java/baymax/data/Todo.java index 8590efba7..d9d80e22a 100644 --- a/src/main/java/baymax/data/Todo.java +++ b/src/main/java/baymax/data/Todo.java @@ -20,6 +20,6 @@ public String saveInfo(){ @Override public String toString(){ - return "[T]" + super.toString(); + return super.toString(); } } From a0dc9d0c771b6605ec8aa1fe60698a87aabd110f Mon Sep 17 00:00:00 2001 From: LI-XINYI1 Date: Fri, 4 Mar 2022 09:52:07 +0800 Subject: [PATCH 25/28] A-JavaDoc: Add JavaDoc comments to the code. --- data/Baymax.txt | 1 + src/main/java/Baymax.java | 110 +++------------------ src/main/java/baymax/data/Deadline.java | 9 ++ src/main/java/baymax/data/Event.java | 9 ++ src/main/java/baymax/data/Task.java | 4 + src/main/java/baymax/data/TaskManager.java | 91 ++++++----------- src/main/java/baymax/data/Todo.java | 3 + src/main/java/baymax/parse/Parser.java | 22 ++++- src/main/java/baymax/storage/Storage.java | 14 +-- src/main/java/baymax/ui/Ui.java | 11 +++ 10 files changed, 105 insertions(+), 169 deletions(-) diff --git a/data/Baymax.txt b/data/Baymax.txt index 950413050..2d449e293 100644 --- a/data/Baymax.txt +++ b/data/Baymax.txt @@ -1,2 +1,3 @@ E / 1 / Xinyi attend CS2113 lecture / 03 04 2022 E / 1 / 1234 / 03 04 2022 +D / 0 / sdf / 02 11 2021 diff --git a/src/main/java/Baymax.java b/src/main/java/Baymax.java index c7b91317e..1b99eada0 100644 --- a/src/main/java/Baymax.java +++ b/src/main/java/Baymax.java @@ -1,12 +1,5 @@ -import baymax.data.TaskManager; -import baymax.data.Deadline; -import baymax.data.Event; -import baymax.data.Todo; - import java.lang.String; -import java.util.Scanner; -import java.io.FileNotFoundException; import java.io.IOException; import baymax.data.TaskManager; @@ -14,8 +7,17 @@ import baymax.parse.Parser; import baymax.storage.Storage; +/** + * Enter point for Baymax task management bot + * Initialize the task manager + */ public class Baymax { + /** + * initialize UI, taskmanager, and storage. + * @param filePath the txt file location where + * the application read from and store in + */ private final Ui ui; private TaskManager tManager; @@ -30,6 +32,11 @@ public Baymax(String filePath) { } } + /** + * Read user input + * keep iteration until exit signal is sent + * @throws IOException + */ public void run() throws IOException { ui.displayWelcomeMessage(); boolean isBye; @@ -49,92 +56,3 @@ public static void main(String[] args) throws IOException { } -// tManager.welcome(); //greating - -// command = in.nextLine(); -// while (!command.equals("bye")) { -// -// String[] word_split; -// word_split = command.split(" ", 2); -// String taskName = word_split[0]; -// -// //different functions based on command lines -// switch (taskName) { -// case "todo": -// tManager.addTask(new Todo(word_split[1])); -// break; -// case "deadline": -// try { -// taskWord = word_split[1].split("/by ", 2); -// taskDescrip = taskWord[0]; -// String ddl = taskWord[1]; -// tManager.addTask(new Deadline(taskDescrip, ddl)); -// } catch (ArrayIndexOutOfBoundsException e) { -// System.out.println(" ☹ OOPS!!! The description of a deadline cannot be empty."); -// } catch (BaymaxException b){ -// System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); -// } -// break; -// case "event": -// try { -// taskWord = word_split[1].split("/at ", 2); -// taskDescrip = taskWord[0]; -// String eventTime = taskWord[1]; -// tManager.addTask(new Event(taskDescrip, eventTime)); -// } catch (ArrayIndexOutOfBoundsException e) { -// System.out.println(" ☹ OOPS!!! The description of an event cannot be empty."); -// } catch (BaymaxException b){ -// System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); -// } -// break; -// case "list": -// tManager.printTaskList(); -// break; -// case "mark": -// System.out.println(horiLine); -// try { -// tManager.markTask(Integer.parseInt(word_split[1]) - 1); -// } catch (ArrayIndexOutOfBoundsException e) { -// System.out.println("Please input an integer for task index."); -// } catch (BaymaxException b){ -// System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); -// } -// System.out.println(horiLine); -// break; -// case "unmark": -// System.out.println(horiLine); -// try { -// tManager.unmarkTask(Integer.parseInt(word_split[1]) - 1); -// } catch (ArrayIndexOutOfBoundsException e) { -// System.out.println("Please input an integer for task index."); -// } catch (BaymaxException b){ -// System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); -// } -// System.out.println(horiLine); -// break; -// case "delete": -// System.out.println(horiLine); -// try { -// tManager.deleteTask(Integer.parseInt(word_split[1]) - 1); -// } catch (ArrayIndexOutOfBoundsException e) { -// System.out.println("Please input an integer for task index."); -// } catch (BaymaxException b){ -// System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); -// } -// //check branch merge -// System.out.println(horiLine); -// break; -// default: -// System.out.println(horiLine); -// System.out.println("Error. Please retry"); -// System.out.println(horiLine); -// break; -// } -// command = in.nextLine(); -// -// } -// tManager.saveTask(); -// tManager.bye(); //bye -// } - - diff --git a/src/main/java/baymax/data/Deadline.java b/src/main/java/baymax/data/Deadline.java index 2abf96498..56a16169e 100644 --- a/src/main/java/baymax/data/Deadline.java +++ b/src/main/java/baymax/data/Deadline.java @@ -3,10 +3,19 @@ import java.time.LocalDate; import java.time.format.DateTimeFormatter; +/** + * Inherit from Task class, + * with additioanl attribute: ddl storing the date of deadline + */ public class Deadline extends Task { private LocalDate ddl; + /** + * class constructor + * @param description description of the deadline task + * @param ddl deadline of the task in format: MM dd yyyy + */ public Deadline(String description, String ddl) { super(description); try{ diff --git a/src/main/java/baymax/data/Event.java b/src/main/java/baymax/data/Event.java index e9270f6a8..d9f38f149 100644 --- a/src/main/java/baymax/data/Event.java +++ b/src/main/java/baymax/data/Event.java @@ -3,10 +3,19 @@ import java.time.LocalDate; import java.time.format.DateTimeFormatter; +/** + * Inherit from Task class, + * with additioanl attribute: time storing the date of event + */ public class Event extends Task { private LocalDate time; + /** + * class constructor + * @param description description of the deadline task + * @param time time of the task in format: MM dd yyyy + */ public Event(String description, String time) { super(description); try{ diff --git a/src/main/java/baymax/data/Task.java b/src/main/java/baymax/data/Task.java index c7e291329..66f3b3f65 100644 --- a/src/main/java/baymax/data/Task.java +++ b/src/main/java/baymax/data/Task.java @@ -1,5 +1,9 @@ package baymax.data; +/** + * abstract class Task + * the parent of Todo, Deadline, and Event + */ public class Task { protected String description; diff --git a/src/main/java/baymax/data/TaskManager.java b/src/main/java/baymax/data/TaskManager.java index 0dcc40c4f..fe0ab7fe1 100644 --- a/src/main/java/baymax/data/TaskManager.java +++ b/src/main/java/baymax/data/TaskManager.java @@ -5,16 +5,28 @@ import baymax.storage.Storage; import baymax.ui.Ui; +/** + * taskmanager class is used for manage the arrarylist of tasks + */ public class TaskManager { String horiLine = "____________________________________________________________\n"; private final ArrayList tasks; private Ui ui; + /** + * class constructor, + * no parameter passed,create a new arrarylist + */ public TaskManager() { tasks = new ArrayList<>(); } + /** + * class constructor + * initialise with user input of tasks + * @param tasks + */ public TaskManager(ArrayList tasks) { this.tasks = tasks; } @@ -23,6 +35,10 @@ public ArrayList getTasks() { return tasks; } + /** + * add new task into arrylist of tasks + * @param newT the new task + */ public void addTask(Task newT) { tasks.add(newT); System.out.println(horiLine); @@ -32,7 +48,10 @@ public void addTask(Task newT) { System.out.println(horiLine); } - + /** + * mark the certain task as done + * @param taskIndex + */ public void markTask (int taskIndex) { System.out.println(horiLine); Task temp = tasks.get(taskIndex); @@ -43,6 +62,10 @@ public void markTask (int taskIndex) { System.out.println(horiLine); } + /** + * unmark the certain task as not done yet + * @param taskIndex + */ public void unmarkTask (int taskIndex) { System.out.println(horiLine); Task temp = tasks.get(taskIndex); @@ -53,6 +76,10 @@ public void unmarkTask (int taskIndex) { System.out.println(horiLine); } + /** + * delete the task + * @param taskIndex index of the task to be deleted + */ public void deleteTask (int taskIndex) { System.out.println(horiLine); Task deleted = tasks.get(taskIndex); @@ -64,67 +91,5 @@ public void deleteTask (int taskIndex) { System.out.println(horiLine); } -// public void initialiseNewFile() throws IOException { -// System.out.println(horiLine); -// System.out.println("Record accessing......"); -// File dir = new File("data"); -// if(!dir.exists()){ -// dir.mkdir(); -// System.out.println("create a new directory \"data\"...... "); -// } -// File file = new File("data/Baymax.txt"); -// if(!file.exists()) { -// file.createNewFile(); -// System.out.println("create a new file \"Baymax.txt\"...... "); -// System.out.println(horiLine); -// return; -// } -// Scanner initTask = new Scanner(file); -// int taskIndex = -1; -// while(initTask.hasNext()){ -// taskIndex++; -// Task temp; -// String[] word_split = initTask.nextLine().split(" / "); -// //System.out.println(word_split[0]+" sdf " + word_split[1] + " df "+ word_split[2]+ " df "+ word_split[3]); -// switch(word_split[0]){ -// case "T": -// tasks.add(new Todo(word_split[2])); -// if (word_split[1].equals("1")) { -// temp = tasks.get(taskIndex); -// temp.markTaskDone(); -// } -// break; -// case "D": -// tasks.add(new Deadline(word_split[2],word_split[3])); -// if (word_split[1].equals("1")) { -// temp = tasks.get(taskIndex); -// temp.markTaskDone(); -// } -// break; -// case "E": -// tasks.add(new Event(word_split[2],word_split[3])); -// if (word_split[1].equals("1")) { -// temp = tasks.get(taskIndex); -// temp.markTaskDone(); -// } -// break; -// default: -// System.out.println(horiLine); -// System.out.println("Error accur, please check."); -// System.out.println(horiLine); -// break; -// } -// } -// System.out.println(horiLine); -// } -// -// public void saveTask() throws IOException { -// -// FileWriter fw = new FileWriter("data/Baymax.txt"); -// for(int i = 0; i < tasks.size(); i++){ -// fw.write(tasks.get(i).saveInfo() + "\n"); -// } -// fw.close(); -// } } diff --git a/src/main/java/baymax/data/Todo.java b/src/main/java/baymax/data/Todo.java index d9d80e22a..6a2f0d667 100644 --- a/src/main/java/baymax/data/Todo.java +++ b/src/main/java/baymax/data/Todo.java @@ -2,6 +2,9 @@ import baymax.data.Task; +/** + * Inherit from Task class + */ public class Todo extends Task { public Todo(String description) { super(description); diff --git a/src/main/java/baymax/parse/Parser.java b/src/main/java/baymax/parse/Parser.java index cc6bda5bd..e3b2b0618 100644 --- a/src/main/java/baymax/parse/Parser.java +++ b/src/main/java/baymax/parse/Parser.java @@ -10,14 +10,17 @@ import baymax.data.Task; import java.io.IOException; +import java.time.format.DateTimeParseException; import java.util.ArrayList; import static java.util.stream.Collectors.toList; +/** + * Parse user input and execute + */ public class Parser { - private static boolean isBye; + private static boolean isBye; private static final String horiLine = "____________________________________________________________\n"; - private Ui ui; public Parser(Ui ui) { @@ -31,13 +34,20 @@ public boolean getExit() { return isBye; } + /** + * Parse user input + * interpret user input with initial command word and execute + * @param fullCommand the whole content of user input + * @param tManager task manager object storing all the tasks + * @throws IOException + */ public void parse(String fullCommand, TaskManager tManager) throws IOException { String[] word_split; word_split = fullCommand.split(" ", 2); String command = word_split[0]; if (command.equals("bye")) { - Storage.encode(tManager.getTasks(), "data/Baymax.txt"); + Storage.save(tManager.getTasks()); setExit(true); return; } @@ -57,6 +67,8 @@ public void parse(String fullCommand, TaskManager tManager) throws IOException { System.out.println(" ☹ OOPS!!! The description of a deadline cannot be empty."); } catch (BaymaxException b){ System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); + } catch (DateTimeParseException d){ + System.out.println( " ☹ OOPS!!! Please re-enter the date in format: MM dd yyyy"); } break; case "event": @@ -69,6 +81,8 @@ public void parse(String fullCommand, TaskManager tManager) throws IOException { System.out.println(" ☹ OOPS!!! The description of an event cannot be empty."); } catch (BaymaxException b){ System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); + }catch (DateTimeParseException d){ + System.out.println( " ☹ OOPS!!! Please re-enter the date in format: MM dd yyyy"); } break; case "list": @@ -118,7 +132,7 @@ public void parse(String fullCommand, TaskManager tManager) throws IOException { break; default: - System.out.println("Error. Please retry"); + ui.displayErrorMessage(); break; } } diff --git a/src/main/java/baymax/storage/Storage.java b/src/main/java/baymax/storage/Storage.java index 170625268..daf6d62b4 100644 --- a/src/main/java/baymax/storage/Storage.java +++ b/src/main/java/baymax/storage/Storage.java @@ -12,10 +12,12 @@ import baymax.data.Todo; - +/** + * class for file management + * loading data into baymax, saving data after execution + */ public class Storage { - - private final String filePath; + private String filePath; public Storage(String filePath) { this.filePath = filePath; @@ -70,11 +72,11 @@ public static void decode(Scanner s, ArrayList tasks) { } - public void save(ArrayList tasks) throws IOException { - encode(tasks, filePath); + public static void save(ArrayList tasks) throws IOException { + encode(tasks); } - public static void encode(ArrayList tasks, String filePath) throws IOException { + public static void encode(ArrayList tasks) throws IOException { FileWriter fw = new FileWriter("data/Baymax.txt"); for(int i = 0; i < tasks.size(); i++){ fw.write(tasks.get(i).saveInfo() + "\n"); diff --git a/src/main/java/baymax/ui/Ui.java b/src/main/java/baymax/ui/Ui.java index 46e673060..b0a020baf 100644 --- a/src/main/java/baymax/ui/Ui.java +++ b/src/main/java/baymax/ui/Ui.java @@ -4,6 +4,10 @@ import java.util.ArrayList; import java.util.Scanner; +/** + * class for mange UI (output of baymax) + * give response and guide to the user + */ public class Ui { String input; private final Scanner in; @@ -40,6 +44,13 @@ public void showByeMessage() { System.out.println(horiLine); } + public void displayErrorMessage() { + System.out.println(horiLine); + System.out.println("Error occur: cannot find this command.\n"+ + "Please re-enter your command."); + System.out.println(horiLine); + } + public void printTaskList(ArrayList tasks) { System.out.println(horiLine); if (tasks.size() == 0) { From 764dd9dc04921392b699f6c105afd9e40a9f29f9 Mon Sep 17 00:00:00 2001 From: LI-XINYI1 Date: Fri, 4 Mar 2022 22:02:01 +0800 Subject: [PATCH 26/28] A-UserGuide: Add a User Guide --- README.md | 132 +++++++++++++++++++++++++++++++++++++++++++------ docs/README.md | 125 ++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 228 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 8715d4d91..ef54e7635 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,126 @@ -# Duke project template +# Duke project: the task management chatbot +## project user guide -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. +* This is a CLI(command line interface) task management application named Baymax. +* ## Setting up in Intellij Prerequisites: JDK 11, update Intellij to the most recent version. 1. Open Intellij (if you are not in the welcome screen, click `File` > `Close Project` to close the existing project first) -1. Open the project into Intellij as follows: +2. Open the project into Intellij as follows: 1. Click `Open`. - 1. Select the project directory, and click `OK`. - 1. If there are any further prompts, accept the defaults. -1. Configure the project to use **JDK 11** (not other versions) as explained in [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk).
+ 2. Select the project directory, and click `OK`. + 3. If there are any further prompts, accept the defaults. +3. Configure the project to use **JDK 11** (not other versions) as explained in [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk).
In the same dialog, set the **Project language level** field to the `SDK default` option. -3. After that, locate the `src/main/java/Duke.java` file, right-click it, and choose `Run Duke.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output: - ``` - Hello from - ____ _ - | _ \ _ _| | _____ - | | | | | | | |/ / _ \ - | |_| | |_| | < __/ - |____/ \__,_|_|\_\___| - ``` +4. After that, locate the `src/main/java/Baymax.java` file, right-click it, and choose `Run Baymax.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, I'm Baymax. +Your personal task managing companion. +What can I do for you? +``` + +5. The application now should run in the console. +6. Now you can interact with the program in the console. + + +*Using Command Line* + +1. 'Build' the project using IntelliJ. +2. Open the `Terminal`/`Command Prompt`. +3. `cd` into the project's `out\production\ip` directory +4. Type `java Baymax`, then press enter to execute. +5. Now you can interact with the program through the CLI.. + + +## Features +### three types of tasks +### 1. Feature-event: +- event is a subclass of task, with description and date. +### 2. Feature-deadline: +- deadline is a subclass of task, with description and due date. +### 3. Feature-todo: +- todo is a subclass of task, with description of the task. + +## Usage +1. Adding a todo task + * Add a todo task to the list of tasks. + * Format: `todo ` + * Words inside `< >` are parameters. There is no need to type the `<` and `>`. + * Example of usage:`todo Read textbook` + * Expected oucome: +``` +Got it. I've added this task: +[T][ ] Read textbook +Now you have 1 tasks tasks in the list. +``` + +2. Adding a deadline task + * Add a deadline task to the list of tasks. + * Format: `deadline /by ` + * Example: + * `deadline Submit lab report /by 03 04 2022` + * Expected oucome: +``` +Got it. I've added this task: +[D][ ] Submit lab report /by 03 04 2022` +Now you have 2 tasks tasks in the list. +``` +3. Adding a event task + * Add an event task to the list of tasks. + * Format: `event /at ` + * Example: + * `event Attend meeting /at 03 04 2022` + * Expected oucome: +``` +Got it. I've added this task: +[E][ ] Submit lab report /by 03 04 2022` +Now you have 3 tasks tasks in the list. +``` + +4. Listing all tasks: `list` + * Display the entire list of tasks. + * Format: `list` + * Expected oucome: + +``` +Here are the tasks in your list: +1.[T][ ] Read textbook +2.[D][ ] Submit lab report /by 03 04 2022 +3.[E][ ] Submit lab report /by 03 04 2022` +``` +5. Finding all tasks containing a keyword in their description: `find` + * Find all the tasks whose description contains the specified keyword. + * Format: `find ` + * Example: + * `find meeting` + + Returns all tasks containing `meeting` in description. + +6. Deleting a task: `delete` + * Delete a task by specifying the index of it. + * Format: `delete ` + * Example: + * `delete 2` + + Deletes the second task in the task list. + +7. Marking a task: `mark` + * Mark a task as done by specifying the index of it. + * Format: `mark ` + * Example: + * `mark 3` + + Marks the third task in the task list as done. + +8. Marking a task: `unmark` + * Unmark a task as not done yet by specifying the index of it. + * Format: `unmark ` + * Example: + * `mark 1` + + Unmark the first task in the task list. + +9. Exiting the program: `bye` + * Exit the program. + * Format: `bye` + * Expected output:`Bye, Hope to see you again soon!` diff --git a/docs/README.md b/docs/README.md index 8077118eb..d840671e6 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,29 +1,126 @@ -# User Guide +# Duke project: the task management chatbot +## project user guide -## Features +* This is a CLI(command line interface) task management application named Baymax. +* -### Feature-ABC +## Setting up in Intellij -Description of the feature. +Prerequisites: JDK 11, update Intellij to the most recent version. -### Feature-XYZ +1. Open Intellij (if you are not in the welcome screen, click `File` > `Close Project` to close the existing project first) +2. Open the project into Intellij as follows: + 1. Click `Open`. + 2. Select the project directory, and click `OK`. + 3. If there are any further prompts, accept the defaults. +3. Configure the project to use **JDK 11** (not other versions) as explained in [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk).
+ In the same dialog, set the **Project language level** field to the `SDK default` option. +4. After that, locate the `src/main/java/Baymax.java` file, right-click it, and choose `Run Baymax.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: -Description of the feature. +``` +Hello, I'm Baymax. +Your personal task managing companion. +What can I do for you? +``` + +5. The application now should run in the console. +6. Now you can interact with the program in the console. -## Usage -### `Keyword` - Describe action +*Using Command Line* -Describe the action and its outcome. +1. 'Build' the project using IntelliJ. +2. Open the `Terminal`/`Command Prompt`. +3. `cd` into the project's `out\production\ip` directory +4. Type `java Baymax`, then press enter to execute. +5. Now you can interact with the program through the CLI.. -Example of usage: -`keyword (optional arguments)` +## Features +### three types of tasks +### 1. Feature-event: +- event is a subclass of task, with description and date. +### 2. Feature-deadline: +- deadline is a subclass of task, with description and due date. +### 3. Feature-todo: +- todo is a subclass of task, with description of the task. + +## Usage +1. Adding a todo task + * Add a todo task to the list of tasks. + * Format: `todo ` + * Words inside `< >` are parameters. There is no need to type the `<` and `>`. + * Example of usage:`todo Read textbook` + * Expected oucome: +``` +Got it. I've added this task: +[T][ ] Read textbook +Now you have 1 tasks tasks in the list. +``` -Expected outcome: +2. Adding a deadline task + * Add a deadline task to the list of tasks. + * Format: `deadline /by ` + * Example: + * `deadline Submit lab report /by 03 04 2022` + * Expected oucome: +``` +Got it. I've added this task: +[D][ ] Submit lab report /by 03 04 2022` +Now you have 2 tasks tasks in the list. +``` +3. Adding a event task + * Add an event task to the list of tasks. + * Format: `event /at ` + * Example: + * `event Attend meeting /at 03 04 2022` + * Expected oucome: +``` +Got it. I've added this task: +[E][ ] Submit lab report /by 03 04 2022` +Now you have 3 tasks tasks in the list. +``` -Description of the outcome. +4. Listing all tasks: `list` + * Display the entire list of tasks. + * Format: `list` + * Expected oucome: ``` -expected output +Here are the tasks in your list: +1.[T][ ] Read textbook +2.[D][ ] Submit lab report /by 03 04 2022 +3.[E][ ] Submit lab report /by 03 04 2022` ``` +5. Finding all tasks containing a keyword in their description: `find` + * Find all the tasks whose description contains the specified keyword. + * Format: `find ` + * Example: + * `find meeting` + + Returns all tasks containing `meeting` in description. + +6. Deleting a task: `delete` + * Delete a task by specifying the index of it. + * Format: `delete ` + * Example: + * `delete 2` + + Deletes the second task in the task list. + +7. Marking a task: `mark` + * Mark a task as done by specifying the index of it. + * Format: `mark ` + * Example: + * `mark 3` + + Marks the third task in the task list as done. + +8. Marking a task: `unmark` + * Unmark a task as not done yet by specifying the index of it. + * Format: `unmark ` + * Example: + * `mark 1` + + Unmark the first task in the task list. + +9. Exiting the program: `bye` + * Exit the program. + * Format: `bye` + * Expected output:`Bye, Hope to see you again soon!` From 6374f84e8679216849d0b2dd5f3cbd09473d61f8 Mon Sep 17 00:00:00 2001 From: LI-XINYI1 Date: Fri, 4 Mar 2022 23:36:33 +0800 Subject: [PATCH 27/28] improve code quality --- data/Baymax.txt | 6 ++-- docs/README.md | 10 +++---- src/main/java/baymax/data/TaskManager.java | 3 +- src/main/java/baymax/parse/Parser.java | 32 +++++++++++++--------- src/main/java/baymax/storage/Storage.java | 9 +++++- src/main/java/baymax/ui/Ui.java | 32 +++++++++++++++++++++- 6 files changed, 67 insertions(+), 25 deletions(-) diff --git a/data/Baymax.txt b/data/Baymax.txt index 2d449e293..b8623f7ff 100644 --- a/data/Baymax.txt +++ b/data/Baymax.txt @@ -1,3 +1,3 @@ -E / 1 / Xinyi attend CS2113 lecture / 03 04 2022 -E / 1 / 1234 / 03 04 2022 -D / 0 / sdf / 02 11 2021 +D / 0 / xinyi submit cs2113 ip / 03 02 2022 +E / 1 / xinyi learns lecture / 03 29 2022 +T / 0 / xinyi practice coding / diff --git a/docs/README.md b/docs/README.md index d840671e6..9b51f0565 100644 --- a/docs/README.md +++ b/docs/README.md @@ -66,7 +66,7 @@ Now you have 1 tasks tasks in the list. * Expected oucome: ``` Got it. I've added this task: -[D][ ] Submit lab report /by 03 04 2022` +[D][ ] Submit lab report (by: 03 04 2022) Now you have 2 tasks tasks in the list. ``` 3. Adding a event task @@ -77,7 +77,7 @@ Now you have 2 tasks tasks in the list. * Expected oucome: ``` Got it. I've added this task: -[E][ ] Submit lab report /by 03 04 2022` +[E][ ] Submit lab report (by: 03 04 2022) Now you have 3 tasks tasks in the list. ``` @@ -88,9 +88,9 @@ Now you have 3 tasks tasks in the list. ``` Here are the tasks in your list: -1.[T][ ] Read textbook -2.[D][ ] Submit lab report /by 03 04 2022 -3.[E][ ] Submit lab report /by 03 04 2022` +1 [T][ ] Read textbook +2 [D][ ] Submit lab report (by: 03 04 2022) +3 [E][ ] Submit lab report (at: 03 04 2022) ``` 5. Finding all tasks containing a keyword in their description: `find` * Find all the tasks whose description contains the specified keyword. diff --git a/src/main/java/baymax/data/TaskManager.java b/src/main/java/baymax/data/TaskManager.java index fe0ab7fe1..6d5001a51 100644 --- a/src/main/java/baymax/data/TaskManager.java +++ b/src/main/java/baymax/data/TaskManager.java @@ -42,8 +42,7 @@ public ArrayList getTasks() { public void addTask(Task newT) { tasks.add(newT); System.out.println(horiLine); - System.out.println(" Got it. I've added this task: \n"+ newT.getStatusIcon()+ - newT.getDescription()+"\n" + + System.out.println(" Got it. I've added this task: \n"+ newT.toString()+"\n"+ "Now you have " + + tasks.size() + " tasks in the list."); System.out.println(horiLine); } diff --git a/src/main/java/baymax/parse/Parser.java b/src/main/java/baymax/parse/Parser.java index e3b2b0618..972e95fc3 100644 --- a/src/main/java/baymax/parse/Parser.java +++ b/src/main/java/baymax/parse/Parser.java @@ -20,7 +20,7 @@ public class Parser { private static boolean isBye; - private static final String horiLine = "____________________________________________________________\n"; + private static final String horiLine = "____________________________________________________________"; private Ui ui; public Parser(Ui ui) { @@ -64,11 +64,11 @@ public void parse(String fullCommand, TaskManager tManager) throws IOException { String ddl = taskWord[1]; tManager.addTask(new Deadline(taskDescrip, ddl)); } catch (ArrayIndexOutOfBoundsException e) { - System.out.println(" ☹ OOPS!!! The description of a deadline cannot be empty."); + ui.DescripEmptyExceptionMessage(); } catch (BaymaxException b){ System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); } catch (DateTimeParseException d){ - System.out.println( " ☹ OOPS!!! Please re-enter the date in format: MM dd yyyy"); + ui.DateExceptionMessage(); } break; case "event": @@ -78,11 +78,11 @@ public void parse(String fullCommand, TaskManager tManager) throws IOException { String eventTime = taskWord[1]; tManager.addTask(new Event(taskDescrip, eventTime)); } catch (ArrayIndexOutOfBoundsException e) { - System.out.println(" ☹ OOPS!!! The description of an event cannot be empty."); + ui.DescripEmptyExceptionMessage(); } catch (BaymaxException b){ System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); }catch (DateTimeParseException d){ - System.out.println( " ☹ OOPS!!! Please re-enter the date in format: MM dd yyyy"); + ui.DateExceptionMessage(); } break; case "list": @@ -92,42 +92,48 @@ public void parse(String fullCommand, TaskManager tManager) throws IOException { try { tManager.markTask(Integer.parseInt(word_split[1]) - 1); } catch (ArrayIndexOutOfBoundsException e) { - System.out.println("Please input an integer for task index."); + ui.ArrayIndexOutOfBoundsExceptionMessage(); } catch (NumberFormatException e) { - System.out.println("Please put in integer value"); + ui.NumberFormatExceptionMessage(); } catch (BaymaxException b){ System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); + } catch (IndexOutOfBoundsException e) { + ui.IndexOutOfBoundsExceptionMessage(); } break; case "unmark": try { tManager.unmarkTask(Integer.parseInt(word_split[1]) - 1); } catch (ArrayIndexOutOfBoundsException e) { - System.out.println("Please input an integer for task index."); + ui.ArrayIndexOutOfBoundsExceptionMessage(); } catch (NumberFormatException e) { - System.out.println("Please put in integer value"); + ui.NumberFormatExceptionMessage(); }catch (BaymaxException b){ System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); + }catch (IndexOutOfBoundsException e) { + ui.IndexOutOfBoundsExceptionMessage(); } break; case "delete": try { tManager.deleteTask(Integer.parseInt(word_split[1]) - 1); } catch (ArrayIndexOutOfBoundsException e) { - System.out.println("Please input an integer for task index."); + ui.ArrayIndexOutOfBoundsExceptionMessage(); } catch (BaymaxException b){ System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again."); + }catch (IndexOutOfBoundsException e) { + ui.IndexOutOfBoundsExceptionMessage(); } - //check branch merge break; case "find": try { String search = word_split[1]; ArrayList filteredTask = (ArrayList) tManager.getTasks().stream(). - filter(task -> task.getDescription().toLowerCase().contains(search.toLowerCase())).collect(toList()); + filter(task -> task.getDescription().toLowerCase().contains(search.toLowerCase())). + collect(toList()); ui.printTaskList(filteredTask); } catch (IndexOutOfBoundsException e) { - System.out.println("Please enter something for Baymax to search for!!"); + ui.IndexOutOfBoundsExceptionMessage(); } break; diff --git a/src/main/java/baymax/storage/Storage.java b/src/main/java/baymax/storage/Storage.java index daf6d62b4..b1f598fcd 100644 --- a/src/main/java/baymax/storage/Storage.java +++ b/src/main/java/baymax/storage/Storage.java @@ -25,9 +25,16 @@ public Storage(String filePath) { public ArrayList load() throws IOException { - File file = new File(filePath); + System.out.println("Record accessing......"); + File dir = new File("data"); + if(!dir.exists()){ + dir.mkdir(); + System.out.println("create a new directory \"data\"...... "); + } + File file = new File("data/Baymax.txt"); if(!file.exists()) { file.createNewFile(); + System.out.println("create a new file \"Baymax.txt\"...... "); } Scanner s = new Scanner(file); ArrayList tasks = new ArrayList<>(); diff --git a/src/main/java/baymax/ui/Ui.java b/src/main/java/baymax/ui/Ui.java index b0a020baf..ec3bdf509 100644 --- a/src/main/java/baymax/ui/Ui.java +++ b/src/main/java/baymax/ui/Ui.java @@ -33,7 +33,7 @@ public void displayWelcomeMessage() { System.out.println(horiLine); String greeting = " Hello, I'm Baymax.\n"+ " Your personal task managing companion. \n" + - " What can I do for you? \n"; + " What can I do for you? "; System.out.println(greeting); System.out.println(horiLine); } @@ -55,6 +55,7 @@ public void printTaskList(ArrayList tasks) { System.out.println(horiLine); if (tasks.size() == 0) { System.out.println("There's no tasks found! Let's add more tasks"); + System.out.println(horiLine); return; } System.out.println("Here are the tasks in your list:"); @@ -64,4 +65,33 @@ public void printTaskList(ArrayList tasks) { System.out.println(horiLine); } + public void DateExceptionMessage() { + System.out.println(horiLine); + System.out.println(" ☹ OOPS!!! Please re-enter the date in format: MM dd yyyy"); + System.out.println(horiLine); + } + + public void DescripEmptyExceptionMessage() { + System.out.println(horiLine); + System.out.println(" ☹ OOPS!!! The description or timestamp of the task cannot be empty."); + System.out.println(horiLine); + } + + public void ArrayIndexOutOfBoundsExceptionMessage() { + System.out.println(horiLine); + System.out.println("☹ OOPS!!!Please input an integer for task index."); + System.out.println(horiLine); + } + + public void NumberFormatExceptionMessage() { + System.out.println(horiLine); + System.out.println("☹ OOPS!!!Please put in an integer value"); + System.out.println(horiLine); + } + + public void IndexOutOfBoundsExceptionMessage() { + System.out.println("☹ OOPS!!!Entered index is out of bounds. Please redo it."); + System.out.println(horiLine); + } + } From 4c5e030e496021444b8a57d135707e561a0fe7b7 Mon Sep 17 00:00:00 2001 From: LI-XINYI1 Date: Sat, 5 Mar 2022 00:01:16 +0800 Subject: [PATCH 28/28] add help message and method --- data/Baymax.txt | 1 + src/main/java/baymax/parse/Parser.java | 4 +++- src/main/java/baymax/ui/Ui.java | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/data/Baymax.txt b/data/Baymax.txt index b8623f7ff..c29faa58b 100644 --- a/data/Baymax.txt +++ b/data/Baymax.txt @@ -1,3 +1,4 @@ D / 0 / xinyi submit cs2113 ip / 03 02 2022 E / 1 / xinyi learns lecture / 03 29 2022 T / 0 / xinyi practice coding / +T / 0 / Mark release a jar file / diff --git a/src/main/java/baymax/parse/Parser.java b/src/main/java/baymax/parse/Parser.java index 972e95fc3..be89caf9e 100644 --- a/src/main/java/baymax/parse/Parser.java +++ b/src/main/java/baymax/parse/Parser.java @@ -136,7 +136,9 @@ public void parse(String fullCommand, TaskManager tManager) throws IOException { ui.IndexOutOfBoundsExceptionMessage(); } break; - + case "help": + ui.helpMessage(); + break; default: ui.displayErrorMessage(); break; diff --git a/src/main/java/baymax/ui/Ui.java b/src/main/java/baymax/ui/Ui.java index ec3bdf509..2dd9d593f 100644 --- a/src/main/java/baymax/ui/Ui.java +++ b/src/main/java/baymax/ui/Ui.java @@ -35,6 +35,21 @@ public void displayWelcomeMessage() { " Your personal task managing companion. \n" + " What can I do for you? "; System.out.println(greeting); + this.helpMessage(); + } + + public void helpMessage(){ + System.out.println(horiLine); + String help = " Add three types of tasks: event, deadline, task \n"+ + " \tin the form of \n" + + " \tto add deadline time: append \"'/by MM dd yyyy\" \n" + + " \tto add event time: append \"'/at MM dd yyyy\" \n" + + " Use list method to see all the tasks \n" + + " Use mark and unmark methods with task index to set or unset the tasks as done \n" + + " Use find method with description to search specific tasks \n" + + " Use delete method with task index to delete certain task \n" + + " Let's start!!! "; + System.out.println(help); System.out.println(horiLine); }