From 3ab4eb789b84316155a46ecf8c33e4e1352c2d95 Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam Date: Mon, 30 Jan 2023 13:21:13 +0700 Subject: [PATCH 01/45] Level-0 Level-0 DONE - Add greet + rename project --- src/main/java/Arsdorint.java | 20 ++++++++++++++++++++ src/main/java/Duke.java | 10 ---------- 2 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 src/main/java/Arsdorint.java delete mode 100644 src/main/java/Duke.java diff --git a/src/main/java/Arsdorint.java b/src/main/java/Arsdorint.java new file mode 100644 index 000000000..fc8c68bd8 --- /dev/null +++ b/src/main/java/Arsdorint.java @@ -0,0 +1,20 @@ +public class Arsdorint { + public static void main(String[] args) { + String logo = " ___ _ _\n" + + " / _ \\ _____ _____ ___| | ___ _____ _ _____ _| |_\n" + + " / /_\\ \\ / ___| / __/ / _ | / _ \\ / ___| | | | _ \\ |_ _|\n" + + " / _____ \\ | / __\\ \\ | |_| | | |_| | | / | | | | | | | |\n" + + "/_/ \\_\\ |_| /____/ \\_____| \\___/ |_| |_| |_| |_| |_|\n"; + System.out.println("Hello from\n" + logo); + //System.out.println("____________________________________________________________\n" + + //" Hello! I'm Arsdorint\n" + + //" What can I do for you?"); + System.out.println("____________________________________________________________\n" + + " Hello! I'm Arsdorint\n" + + " What can I do for you?\n"); + + System.out.println("____________________________________________________________\n" + + " Bye. Hope to see you again soon!\n" + + "____________________________________________________________\n"); + } +} diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java deleted file mode 100644 index 5d313334c..000000000 --- a/src/main/java/Duke.java +++ /dev/null @@ -1,10 +0,0 @@ -public class Duke { - public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - } -} From 147f5435340431ae6aa9afa84d938c34e7d292b9 Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam <88639992+arsdorintbp2003@users.noreply.github.com> Date: Mon, 30 Jan 2023 13:40:51 +0700 Subject: [PATCH 02/45] Level-0 Done! Add Greet + Rename Project --- src/main/java/Arsdorint.java | 20 ++++++++++++++++++++ src/main/java/Duke.java | 10 ---------- 2 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 src/main/java/Arsdorint.java delete mode 100644 src/main/java/Duke.java diff --git a/src/main/java/Arsdorint.java b/src/main/java/Arsdorint.java new file mode 100644 index 000000000..fc8c68bd8 --- /dev/null +++ b/src/main/java/Arsdorint.java @@ -0,0 +1,20 @@ +public class Arsdorint { + public static void main(String[] args) { + String logo = " ___ _ _\n" + + " / _ \\ _____ _____ ___| | ___ _____ _ _____ _| |_\n" + + " / /_\\ \\ / ___| / __/ / _ | / _ \\ / ___| | | | _ \\ |_ _|\n" + + " / _____ \\ | / __\\ \\ | |_| | | |_| | | / | | | | | | | |\n" + + "/_/ \\_\\ |_| /____/ \\_____| \\___/ |_| |_| |_| |_| |_|\n"; + System.out.println("Hello from\n" + logo); + //System.out.println("____________________________________________________________\n" + + //" Hello! I'm Arsdorint\n" + + //" What can I do for you?"); + System.out.println("____________________________________________________________\n" + + " Hello! I'm Arsdorint\n" + + " What can I do for you?\n"); + + System.out.println("____________________________________________________________\n" + + " Bye. Hope to see you again soon!\n" + + "____________________________________________________________\n"); + } +} diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java deleted file mode 100644 index 5d313334c..000000000 --- a/src/main/java/Duke.java +++ /dev/null @@ -1,10 +0,0 @@ -public class Duke { - public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - } -} From 9e3786fed821bba5b4e29b86329d91a43709e6ca Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam <88639992+arsdorintbp2003@users.noreply.github.com> Date: Mon, 30 Jan 2023 13:46:16 +0700 Subject: [PATCH 03/45] Level 0 Done. Add greet + Rename Project --- src/main/java/Arsdorint.java | 20 ++++++++++++++++++++ src/main/java/Duke.java | 10 ---------- 2 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 src/main/java/Arsdorint.java delete mode 100644 src/main/java/Duke.java diff --git a/src/main/java/Arsdorint.java b/src/main/java/Arsdorint.java new file mode 100644 index 000000000..fc8c68bd8 --- /dev/null +++ b/src/main/java/Arsdorint.java @@ -0,0 +1,20 @@ +public class Arsdorint { + public static void main(String[] args) { + String logo = " ___ _ _\n" + + " / _ \\ _____ _____ ___| | ___ _____ _ _____ _| |_\n" + + " / /_\\ \\ / ___| / __/ / _ | / _ \\ / ___| | | | _ \\ |_ _|\n" + + " / _____ \\ | / __\\ \\ | |_| | | |_| | | / | | | | | | | |\n" + + "/_/ \\_\\ |_| /____/ \\_____| \\___/ |_| |_| |_| |_| |_|\n"; + System.out.println("Hello from\n" + logo); + //System.out.println("____________________________________________________________\n" + + //" Hello! I'm Arsdorint\n" + + //" What can I do for you?"); + System.out.println("____________________________________________________________\n" + + " Hello! I'm Arsdorint\n" + + " What can I do for you?\n"); + + System.out.println("____________________________________________________________\n" + + " Bye. Hope to see you again soon!\n" + + "____________________________________________________________\n"); + } +} diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java deleted file mode 100644 index 5d313334c..000000000 --- a/src/main/java/Duke.java +++ /dev/null @@ -1,10 +0,0 @@ -public class Duke { - public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - } -} From f035cec5bea26f6bfff6a6a24552423d1465c1e1 Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam Date: Mon, 30 Jan 2023 14:21:15 +0700 Subject: [PATCH 04/45] Finish Level-1 (Add Greet, Echo, Exit) --- src/main/java/Arsdorint.java | 39 +++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/src/main/java/Arsdorint.java b/src/main/java/Arsdorint.java index fc8c68bd8..15e6621e6 100644 --- a/src/main/java/Arsdorint.java +++ b/src/main/java/Arsdorint.java @@ -1,20 +1,39 @@ +import java.util.Locale; +import java.util.Scanner; public class Arsdorint { + static Scanner input = new Scanner(System.in); + static String logo = " ___ _ _\n" + + " / _ \\ _____ _____ ___| | ___ _____ _ _____ _| |_\n" + + " / /_\\ \\ / ___| / __/ / _ | / _ \\ / ___| | | | _ \\ |_ _|\n" + + " / _____ \\ | / __\\ \\ | |_| | | |_| | | / | | | | | | | |\n" + + "/_/ \\_\\ |_| /____/ \\_____| \\___/ |_| |_| |_| |_| |_|\n"; + + public static void echo(String command) { + System.out.println("Arsdorint says: " + command); + } + + public static String ask() { + String ask; + return ask = input.nextLine(); + } + public static void main(String[] args) { - String logo = " ___ _ _\n" - + " / _ \\ _____ _____ ___| | ___ _____ _ _____ _| |_\n" - + " / /_\\ \\ / ___| / __/ / _ | / _ \\ / ___| | | | _ \\ |_ _|\n" - + " / _____ \\ | / __\\ \\ | |_| | | |_| | | / | | | | | | | |\n" - + "/_/ \\_\\ |_| /____/ \\_____| \\___/ |_| |_| |_| |_| |_|\n"; - System.out.println("Hello from\n" + logo); //System.out.println("____________________________________________________________\n" + //" Hello! I'm Arsdorint\n" + //" What can I do for you?"); + String command = " "; + System.out.println("Hello from\n" + logo); System.out.println("____________________________________________________________\n" + - " Hello! I'm Arsdorint\n" + - " What can I do for you?\n"); + " Hello! I'm Arsdorint, a member of Arsdorint Team\n" + + " What can I do for you?\n" + + "____________________________________________________________\n"); + while (true) { + command = ask(); + if (command.toLowerCase().contains("bye")) break; + echo(command); + } - System.out.println("____________________________________________________________\n" + - " Bye. Hope to see you again soon!\n" + + System.out.println("Arsdorint says:" + " Bye. Hope to see you again soon!\n" + "____________________________________________________________\n"); } } From 2d5e5be7b0c48c5ed2c456e7b2a8ba4e3a905a7b Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam <88639992+arsdorintbp2003@users.noreply.github.com> Date: Mon, 30 Jan 2023 14:26:14 +0700 Subject: [PATCH 05/45] Level-1 (Add Greet, Echo, Exit) --- src/main/java/Arsdorint.java | 39 +++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/src/main/java/Arsdorint.java b/src/main/java/Arsdorint.java index fc8c68bd8..15e6621e6 100644 --- a/src/main/java/Arsdorint.java +++ b/src/main/java/Arsdorint.java @@ -1,20 +1,39 @@ +import java.util.Locale; +import java.util.Scanner; public class Arsdorint { + static Scanner input = new Scanner(System.in); + static String logo = " ___ _ _\n" + + " / _ \\ _____ _____ ___| | ___ _____ _ _____ _| |_\n" + + " / /_\\ \\ / ___| / __/ / _ | / _ \\ / ___| | | | _ \\ |_ _|\n" + + " / _____ \\ | / __\\ \\ | |_| | | |_| | | / | | | | | | | |\n" + + "/_/ \\_\\ |_| /____/ \\_____| \\___/ |_| |_| |_| |_| |_|\n"; + + public static void echo(String command) { + System.out.println("Arsdorint says: " + command); + } + + public static String ask() { + String ask; + return ask = input.nextLine(); + } + public static void main(String[] args) { - String logo = " ___ _ _\n" - + " / _ \\ _____ _____ ___| | ___ _____ _ _____ _| |_\n" - + " / /_\\ \\ / ___| / __/ / _ | / _ \\ / ___| | | | _ \\ |_ _|\n" - + " / _____ \\ | / __\\ \\ | |_| | | |_| | | / | | | | | | | |\n" - + "/_/ \\_\\ |_| /____/ \\_____| \\___/ |_| |_| |_| |_| |_|\n"; - System.out.println("Hello from\n" + logo); //System.out.println("____________________________________________________________\n" + //" Hello! I'm Arsdorint\n" + //" What can I do for you?"); + String command = " "; + System.out.println("Hello from\n" + logo); System.out.println("____________________________________________________________\n" + - " Hello! I'm Arsdorint\n" + - " What can I do for you?\n"); + " Hello! I'm Arsdorint, a member of Arsdorint Team\n" + + " What can I do for you?\n" + + "____________________________________________________________\n"); + while (true) { + command = ask(); + if (command.toLowerCase().contains("bye")) break; + echo(command); + } - System.out.println("____________________________________________________________\n" + - " Bye. Hope to see you again soon!\n" + + System.out.println("Arsdorint says:" + " Bye. Hope to see you again soon!\n" + "____________________________________________________________\n"); } } From 1eb047978091eca27b0c95ef92a235ab2ae26836 Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam Date: Mon, 30 Jan 2023 21:13:33 +0700 Subject: [PATCH 06/45] Level-2 finished (Add, list) Add, List --- src/main/java/Arsdorint.java | 36 +++++++++++++++++++++++++++++------- src/main/java/Task.java | 15 +++++++++++++++ 2 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 src/main/java/Task.java diff --git a/src/main/java/Arsdorint.java b/src/main/java/Arsdorint.java index 15e6621e6..6c7b602a5 100644 --- a/src/main/java/Arsdorint.java +++ b/src/main/java/Arsdorint.java @@ -8,8 +8,9 @@ public class Arsdorint { + " / _____ \\ | / __\\ \\ | |_| | | |_| | | / | | | | | | | |\n" + "/_/ \\_\\ |_| /____/ \\_____| \\___/ |_| |_| |_| |_| |_|\n"; + static Task[] toDoList = new Task[100]; public static void echo(String command) { - System.out.println("Arsdorint says: " + command); + System.out.println(command); } public static String ask() { @@ -17,6 +18,21 @@ public static String ask() { return ask = input.nextLine(); } + public static void list() { + for (int i = 0; i < Task.numOfTasks; i++) { + System.out.print(i + 1); + System.out.print(". " + toDoList[i].getStatus() + " "); + System.out.println(toDoList[i].description); + } + } + + public static void add(String command) { + toDoList[Task.numOfTasks] = new Task(command); + System.out.print("Added: "); + echo(command); + } + + public static void main(String[] args) { //System.out.println("____________________________________________________________\n" + //" Hello! I'm Arsdorint\n" + @@ -24,16 +40,22 @@ public static void main(String[] args) { String command = " "; System.out.println("Hello from\n" + logo); System.out.println("____________________________________________________________\n" + - " Hello! I'm Arsdorint, a member of Arsdorint Team\n" + - " What can I do for you?\n" + - "____________________________________________________________\n"); + " Hello! I'm Arsdorint, a member of Arsdorint Team.\n" + + " Please Type The Command As Follow:\n" + + "> Type anything to add to the to-do list. \n" + + "> Type \"list\" to list all the tasks. \n" + + "> Type \"bye\" to exit. \n" + + " What can I do for you? \n" + + "____________________________________________________________\n"); while (true) { command = ask(); - if (command.toLowerCase().contains("bye")) break; - echo(command); + if (command.toLowerCase().equals("bye")) break; //exit command + else if (command.equalsIgnoreCase("list")) list(); + //add command when user don't type list or bye + else add(command); } - System.out.println("Arsdorint says:" + " Bye. Hope to see you again soon!\n" + + System.out.println(" Bye. Hope to see you again soon!\n" + "____________________________________________________________\n"); } } diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 000000000..407b479b5 --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,15 @@ +public class Task { + public static int numOfTasks = 0; + public String description; + public boolean isDone; + + public Task(String description) { + this.description = description; + this.isDone = false; + numOfTasks++; + } + + public String getStatus() { + return (isDone) ? "[X}" : "[ ]"; + } +} From 568f230e3fa4175bf92fa67bd05ed052c295ddbf Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam <88639992+arsdorintbp2003@users.noreply.github.com> Date: Mon, 30 Jan 2023 21:17:58 +0700 Subject: [PATCH 07/45] Level-2 (Create Task class) --- src/main/java/Task.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/main/java/Task.java diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 000000000..407b479b5 --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,15 @@ +public class Task { + public static int numOfTasks = 0; + public String description; + public boolean isDone; + + public Task(String description) { + this.description = description; + this.isDone = false; + numOfTasks++; + } + + public String getStatus() { + return (isDone) ? "[X}" : "[ ]"; + } +} From 6e6cd122db2dc2b2c2f0be1f21f4730ce407e828 Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam <88639992+arsdorintbp2003@users.noreply.github.com> Date: Mon, 30 Jan 2023 21:18:39 +0700 Subject: [PATCH 08/45] Level-2 finished (Add, List) Add, List --- src/main/java/Arsdorint.java | 37 ++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/src/main/java/Arsdorint.java b/src/main/java/Arsdorint.java index 15e6621e6..f4ae4f9b0 100644 --- a/src/main/java/Arsdorint.java +++ b/src/main/java/Arsdorint.java @@ -1,4 +1,3 @@ -import java.util.Locale; import java.util.Scanner; public class Arsdorint { static Scanner input = new Scanner(System.in); @@ -8,8 +7,9 @@ public class Arsdorint { + " / _____ \\ | / __\\ \\ | |_| | | |_| | | / | | | | | | | |\n" + "/_/ \\_\\ |_| /____/ \\_____| \\___/ |_| |_| |_| |_| |_|\n"; + static Task[] toDoList = new Task[100]; public static void echo(String command) { - System.out.println("Arsdorint says: " + command); + System.out.println(command); } public static String ask() { @@ -17,6 +17,21 @@ public static String ask() { return ask = input.nextLine(); } + public static void list() { + for (int i = 0; i < Task.numOfTasks; i++) { + System.out.print(i + 1); + System.out.print(". " + toDoList[i].getStatus() + " "); + System.out.println(toDoList[i].description); + } + } + + public static void add(String command) { + toDoList[Task.numOfTasks] = new Task(command); + System.out.print("Added: "); + echo(command); + } + + public static void main(String[] args) { //System.out.println("____________________________________________________________\n" + //" Hello! I'm Arsdorint\n" + @@ -24,16 +39,22 @@ public static void main(String[] args) { String command = " "; System.out.println("Hello from\n" + logo); System.out.println("____________________________________________________________\n" + - " Hello! I'm Arsdorint, a member of Arsdorint Team\n" + - " What can I do for you?\n" + - "____________________________________________________________\n"); + " Hello! I'm Arsdorint, a member of Arsdorint Team.\n" + + " Please Type The Command As Follow:\n" + + "> Type anything to add to the to-do list. \n" + + "> Type \"list\" to list all the tasks. \n" + + "> Type \"bye\" to exit. \n" + + " What can I do for you? \n" + + "____________________________________________________________\n"); while (true) { command = ask(); - if (command.toLowerCase().contains("bye")) break; - echo(command); + if (command.toLowerCase().equals("bye")) break; //exit command + else if (command.equalsIgnoreCase("list")) list(); + //add command when user don't type list or bye + else add(command); } - System.out.println("Arsdorint says:" + " Bye. Hope to see you again soon!\n" + + System.out.println(" Bye. Hope to see you again soon!\n" + "____________________________________________________________\n"); } } From ece388788b02c978b9dbaa767d6230e881c9dc59 Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam <88639992+arsdorintbp2003@users.noreply.github.com> Date: Mon, 30 Jan 2023 22:20:18 +0700 Subject: [PATCH 09/45] Level-3 finished (Mark As Done) Added Mark & Unmark --- src/main/java/Arsdorint.java | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/main/java/Arsdorint.java b/src/main/java/Arsdorint.java index f4ae4f9b0..d36ae6428 100644 --- a/src/main/java/Arsdorint.java +++ b/src/main/java/Arsdorint.java @@ -31,6 +31,23 @@ public static void add(String command) { echo(command); } + public static void mark(String command) { + String[] num = command.split(" "); + int idx = Integer.parseInt(num[1]); + if (num[0].equalsIgnoreCase("mark")) + toDoList[idx - 1].isDone = true; + else toDoList[idx - 1].isDone = false; + list(); + } + + public static void unmark(String command) { + String[] num = command.split(" "); + int idx = Integer.parseInt(num[1]); + if (num[0].equalsIgnoreCase("mark")) + toDoList[idx - 1].isDone = false; + else toDoList[idx - 1].isDone = true; + list(); + } public static void main(String[] args) { //System.out.println("____________________________________________________________\n" + @@ -43,14 +60,27 @@ public static void main(String[] args) { " Please Type The Command As Follow:\n" + "> Type anything to add to the to-do list. \n" + "> Type \"list\" to list all the tasks. \n" + + "> Type \"mark\" follow by a number x to mark x tasks in the list" + + "> Type \"unmark\" follow by a number y to unmark y tasks in the list" + "> Type \"bye\" to exit. \n" + " What can I do for you? \n" + "____________________________________________________________\n"); while (true) { command = ask(); if (command.toLowerCase().equals("bye")) break; //exit command - else if (command.equalsIgnoreCase("list")) list(); - //add command when user don't type list or bye + else if (command.equalsIgnoreCase("list")) { + System.out.println("Here are the tasks in your list:"); + list(); + } + else if (command.toLowerCase().contains("mark")) { + System.out.println("Nice! I've marked this task as done: "); + mark(command); + } + else if (command.toLowerCase().contains("unmark")) { + System.out.println("OK, I've marked this task as not done yet:"); + unmark(command); + } + //add command when user don't type the instruction's command else add(command); } From 0fde3804d681bfb5a3ba793acf06deb8a9774497 Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam Date: Thu, 2 Feb 2023 08:48:20 +0700 Subject: [PATCH 10/45] Level-3 finished (Mark As Done) --- src/main/java/Arsdorint.java | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/main/java/Arsdorint.java b/src/main/java/Arsdorint.java index 6c7b602a5..d36ae6428 100644 --- a/src/main/java/Arsdorint.java +++ b/src/main/java/Arsdorint.java @@ -1,4 +1,3 @@ -import java.util.Locale; import java.util.Scanner; public class Arsdorint { static Scanner input = new Scanner(System.in); @@ -32,6 +31,23 @@ public static void add(String command) { echo(command); } + public static void mark(String command) { + String[] num = command.split(" "); + int idx = Integer.parseInt(num[1]); + if (num[0].equalsIgnoreCase("mark")) + toDoList[idx - 1].isDone = true; + else toDoList[idx - 1].isDone = false; + list(); + } + + public static void unmark(String command) { + String[] num = command.split(" "); + int idx = Integer.parseInt(num[1]); + if (num[0].equalsIgnoreCase("mark")) + toDoList[idx - 1].isDone = false; + else toDoList[idx - 1].isDone = true; + list(); + } public static void main(String[] args) { //System.out.println("____________________________________________________________\n" + @@ -44,14 +60,27 @@ public static void main(String[] args) { " Please Type The Command As Follow:\n" + "> Type anything to add to the to-do list. \n" + "> Type \"list\" to list all the tasks. \n" + + "> Type \"mark\" follow by a number x to mark x tasks in the list" + + "> Type \"unmark\" follow by a number y to unmark y tasks in the list" + "> Type \"bye\" to exit. \n" + " What can I do for you? \n" + "____________________________________________________________\n"); while (true) { command = ask(); if (command.toLowerCase().equals("bye")) break; //exit command - else if (command.equalsIgnoreCase("list")) list(); - //add command when user don't type list or bye + else if (command.equalsIgnoreCase("list")) { + System.out.println("Here are the tasks in your list:"); + list(); + } + else if (command.toLowerCase().contains("mark")) { + System.out.println("Nice! I've marked this task as done: "); + mark(command); + } + else if (command.toLowerCase().contains("unmark")) { + System.out.println("OK, I've marked this task as not done yet:"); + unmark(command); + } + //add command when user don't type the instruction's command else add(command); } From 1d1827569d11167b87aa8001d94ebedeeaae1c5b Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam Date: Thu, 2 Feb 2023 13:17:26 +0700 Subject: [PATCH 11/45] level4 --- src/main/java/Arsdorint.java | 41 +++++++++++++++++++++++++++++++----- src/main/java/Deadline.java | 13 ++++++++++++ src/main/java/Event.java | 13 ++++++++++++ src/main/java/Task.java | 5 +++++ src/main/java/Todo.java | 6 ++++++ 5 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 src/main/java/Deadline.java create mode 100644 src/main/java/Event.java create mode 100644 src/main/java/Todo.java diff --git a/src/main/java/Arsdorint.java b/src/main/java/Arsdorint.java index d36ae6428..514581e2a 100644 --- a/src/main/java/Arsdorint.java +++ b/src/main/java/Arsdorint.java @@ -18,17 +18,48 @@ public static String ask() { } public static void list() { + System.out.println("____________________________________________________________\n"); for (int i = 0; i < Task.numOfTasks; i++) { - System.out.print(i + 1); - System.out.print(". " + toDoList[i].getStatus() + " "); - System.out.println(toDoList[i].description); + System.out.print(Integer.toString(i + 1) + "."); + toDoList[i].printTask(); } + System.out.println("____________________________________________________________\n"); } public static void add(String command) { - toDoList[Task.numOfTasks] = new Task(command); + /*toDoList[Task.numOfTasks] = new Task(command); System.out.print("Added: "); - echo(command); + echo(command);*/ + String newTaskType = command.split(" ")[0]; + if (!(newTaskType.equalsIgnoreCase("todo") || + (newTaskType.equalsIgnoreCase("deadline")) || + (newTaskType.equalsIgnoreCase("event")))) + System.out.println("Please indicate task type: " + + "\"todo\" " + "or \"deadline\" or \"event\""); + else { + String[] taskDescription = + command.replace(newTaskType, "").trim().split("/"); + switch (newTaskType.toLowerCase()) { + case "todo": + toDoList[Task.numOfTasks] = new Todo(taskDescription[0]); + break; + case "deadline": + toDoList[Task.numOfTasks] = + new Deadline(taskDescription[0], taskDescription[1].trim()); + break; + case "event": + toDoList[Task.numOfTasks] = + new Event(taskDescription[0], taskDescription[1].trim()); + break; + default: + break; + } + System.out.println("____________________________________________________________\n"); + System.out.println("Got it. I've added this task:\n" + "\t"); + toDoList[Task.numOfTasks - 1].printTask(); + System.out.println("\t" + "Now you have " + Integer.toString(Task.numOfTasks) + " tasks in the list."); + System.out.println("____________________________________________________________\n"); + } } public static void mark(String command) { diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java new file mode 100644 index 000000000..d51602506 --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,13 @@ +public class Deadline extends Task { + public String date; + public Deadline(String description, String date) { + super(description); + this.date = date; + this.taskType = "[D]"; + } + public void printTask() { + System.out.println(this.taskType + this.getStatus() + + " " + this.description + "(" + this.date + ")"); + } + +} diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 000000000..a8052ecd0 --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,13 @@ +public class Event extends Task { + public String date; + public Event(String description, String Date) { + super(description); + this.date = date; + this.taskType = "[E]"; + } + + public void printTask() { + System.out.println(this.taskType + this.getStatus() + + " " + this.description + "(" + this.date + ")"); + } +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 407b479b5..d991e3146 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -2,6 +2,7 @@ public class Task { public static int numOfTasks = 0; public String description; public boolean isDone; + public String taskType; public Task(String description) { this.description = description; @@ -12,4 +13,8 @@ public Task(String description) { public String getStatus() { return (isDone) ? "[X}" : "[ ]"; } + public void printTask() { + System.out.println(this.taskType + + this.getStatus() + " " + this.description); + } } diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java new file mode 100644 index 000000000..080415f35 --- /dev/null +++ b/src/main/java/Todo.java @@ -0,0 +1,6 @@ +public class Todo extends Task { + public Todo(String description) { + super(description); + this.taskType = "[T]"; + } +} From a4ea47e111b88bfc639557387108100870bfcae3 Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam Date: Thu, 2 Feb 2023 23:06:27 +0700 Subject: [PATCH 12/45] Level-4 finished (ToDos, Events, Deadlines) --- src/main/java/Arsdorint.java | 4 ++-- src/main/java/Deadline.java | 2 +- src/main/java/Task.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/Arsdorint.java b/src/main/java/Arsdorint.java index 514581e2a..bc54fafbf 100644 --- a/src/main/java/Arsdorint.java +++ b/src/main/java/Arsdorint.java @@ -32,8 +32,8 @@ public static void add(String command) { echo(command);*/ String newTaskType = command.split(" ")[0]; if (!(newTaskType.equalsIgnoreCase("todo") || - (newTaskType.equalsIgnoreCase("deadline")) || - (newTaskType.equalsIgnoreCase("event")))) + newTaskType.equalsIgnoreCase("deadline") || + newTaskType.equalsIgnoreCase("event"))) System.out.println("Please indicate task type: " + "\"todo\" " + "or \"deadline\" or \"event\""); else { diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index d51602506..0d5c5a486 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -7,7 +7,7 @@ public Deadline(String description, String date) { } public void printTask() { System.out.println(this.taskType + this.getStatus() - + " " + this.description + "(" + this.date + ")"); + + " " + this.description + "\t(" + this.date + ")"); } } diff --git a/src/main/java/Task.java b/src/main/java/Task.java index d991e3146..0b0b33399 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -2,7 +2,7 @@ public class Task { public static int numOfTasks = 0; public String description; public boolean isDone; - public String taskType; + public String taskType = "[ ]"; public Task(String description) { this.description = description; From 182d6864f330ba5df64e24125a0c964b153cb773 Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam Date: Wed, 8 Feb 2023 23:10:36 +0700 Subject: [PATCH 13/45] A-TextUI-Testing finished --- src/main/java/Arsdorint.java | 5 +- text-ui-test/EXPECTED.TXT | 108 +++++++++++++++++++++++++++++++++-- text-ui-test/input.txt | 10 ++++ 3 files changed, 116 insertions(+), 7 deletions(-) diff --git a/src/main/java/Arsdorint.java b/src/main/java/Arsdorint.java index bc54fafbf..c69eb96f8 100644 --- a/src/main/java/Arsdorint.java +++ b/src/main/java/Arsdorint.java @@ -91,8 +91,9 @@ public static void main(String[] args) { " Please Type The Command As Follow:\n" + "> Type anything to add to the to-do list. \n" + "> Type \"list\" to list all the tasks. \n" + - "> Type \"mark\" follow by a number x to mark x tasks in the list" + - "> Type \"unmark\" follow by a number y to unmark y tasks in the list" + + "> Type \"mark\" follow by a number x to mark x tasks in the list. \n" + + "> Type \"unmark\" follow by a number y to unmark y tasks in the list. \n" + + "> Type \"todo\"/\"deadline\"/\"event\" to include the task type. \n" + "> Type \"bye\" to exit. \n" + " What can I do for you? \n" + "____________________________________________________________\n"); diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 657e74f6e..8e8aaa5fb 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,7 +1,105 @@ +"C:\Program Files\Java\jdk-18.0.1.1\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2022.1.1\lib\idea_rt.jar=52265:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2022.1.1\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\NamBP\Documents\GitHub\ip\out\production\ip Arsdorint Hello from - ____ _ -| _ \ _ _| | _____ -| | | | | | | |/ / _ \ -| |_| | |_| | < __/ -|____/ \__,_|_|\_\___| + ___ _ _ + / _ \ _____ _____ ___| | ___ _____ _ _____ _| |_ + / /_\ \ / ___| / __/ / _ | / _ \ / ___| | | | _ \ |_ _| + / _____ \ | / __\ \ | |_| | | |_| | | / | | | | | | | | +/_/ \_\ |_| /____/ \_____| \___/ |_| |_| |_| |_| |_| + +____________________________________________________________ + Hello! I'm Arsdorint, a member of Arsdorint Team. + Please Type The Command As Follow: +> Type anything to add to the to-do list. +> Type "list" to list all the tasks. +> Type "mark" follow by a number x to mark x tasks in the list. +> Type "unmark" follow by a number y to unmark y tasks in the list. +> Type "todo"/"deadline"/"event" to include the task type. +> Type "bye" to exit. + What can I do for you? +____________________________________________________________ +Please indicate task type: "todo" or "deadline" or "event" + +____________________________________________________________ + +Got it. I've added this task: + +[T][ ] CS2113 ip + Now you have 1 tasks in the list. +____________________________________________________________ + + +____________________________________________________________ + +Got it. I've added this task: + +[T][ ] CS2113 tp + Now you have 2 tasks in the list. +____________________________________________________________ + + +____________________________________________________________ + +Got it. I've added this task: + +[E][ ] Valentine (null) + Now you have 3 tasks in the list. +____________________________________________________________ + + +Here are the tasks in your list: +____________________________________________________________ + +1.[T][ ] CS2113 ip +2.[T][ ] CS2113 tp +3.[E][ ] Valentine (null) +____________________________________________________________ + + +____________________________________________________________ + +Got it. I've added this task: + +[D][ ] EE2026 (by next-week) + Now you have 4 tasks in the list. +____________________________________________________________ + + +Nice! I've marked this task as done: +____________________________________________________________ + +1.[T][ ] CS2113 ip +2.[T][ ] CS2113 tp +3.[E][X} Valentine (null) +4.[D][ ] EE2026 (by next-week) +____________________________________________________________ + + +Nice! I've marked this task as done: +____________________________________________________________ + +1.[T][ ] CS2113 ip +2.[T][X} CS2113 tp +3.[E][X} Valentine (null) +4.[D][ ] EE2026 (by next-week) +____________________________________________________________ + + +Nice! I've marked this task as done: +____________________________________________________________ + +1.[T][ ] CS2113 ip +2.[T][X} CS2113 tp +3.[E][ ] Valentine (null) +4.[D][ ] EE2026 (by next-week) +____________________________________________________________ + + +Here are the tasks in your list: +____________________________________________________________ + +1.[T][ ] CS2113 ip +2.[T][X} CS2113 tp +3.[E][ ] Valentine (null) +4.[D][ ] EE2026 (by next-week) +____________________________________________________________ diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index e69de29bb..a194a32ea 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -0,0 +1,10 @@ +boook +todo CS2113 ip +toDO CS2113 tp +EvenT Valentine /at 14th February +list +Deadline EE2026 /by next-week +Mark 3 +marK 2 +unmark 3 +list \ No newline at end of file From 23c669da233d9c9895d6592f09693893c16e5a71 Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam Date: Wed, 8 Feb 2023 23:33:23 +0700 Subject: [PATCH 14/45] A-CodingStandard --- src/main/java/Arsdorint.java | 11 +++-------- src/main/java/Task.java | 2 ++ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/java/Arsdorint.java b/src/main/java/Arsdorint.java index c69eb96f8..f43e52b52 100644 --- a/src/main/java/Arsdorint.java +++ b/src/main/java/Arsdorint.java @@ -27,10 +27,8 @@ public static void list() { } public static void add(String command) { - /*toDoList[Task.numOfTasks] = new Task(command); - System.out.print("Added: "); - echo(command);*/ String newTaskType = command.split(" ")[0]; + //if the commands are not todo/ deadline/ event, ask user to rewrite the commmand if (!(newTaskType.equalsIgnoreCase("todo") || newTaskType.equalsIgnoreCase("deadline") || newTaskType.equalsIgnoreCase("event"))) @@ -62,7 +60,7 @@ public static void add(String command) { } } - public static void mark(String command) { + public static void mark(String command) { // mark the completed task String[] num = command.split(" "); int idx = Integer.parseInt(num[1]); if (num[0].equalsIgnoreCase("mark")) @@ -71,7 +69,7 @@ public static void mark(String command) { list(); } - public static void unmark(String command) { + public static void unmark(String command) { // unmark task if needed String[] num = command.split(" "); int idx = Integer.parseInt(num[1]); if (num[0].equalsIgnoreCase("mark")) @@ -81,9 +79,6 @@ public static void unmark(String command) { } public static void main(String[] args) { - //System.out.println("____________________________________________________________\n" + - //" Hello! I'm Arsdorint\n" + - //" What can I do for you?"); String command = " "; System.out.println("Hello from\n" + logo); System.out.println("____________________________________________________________\n" + diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 0b0b33399..c9a905b3e 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -1,4 +1,5 @@ public class Task { + // initial number of task must be set to 0 public static int numOfTasks = 0; public String description; public boolean isDone; @@ -10,6 +11,7 @@ public Task(String description) { numOfTasks++; } + //status is marked or not public String getStatus() { return (isDone) ? "[X}" : "[ ]"; } From faad0ae58a39c8f366c45da4c53b69cfab5b8123 Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam Date: Wed, 15 Feb 2023 15:17:17 +0700 Subject: [PATCH 15/45] Level-5 Completed (Handle Errors) - A-Exceptions --- src/main/java/Arsdorint.java | 121 --------- src/main/java/Arsdorint/Arsdorint.java | 251 ++++++++++++++++++ .../Arsdorint/command/ArsdorintException.java | 7 + .../java/{ => Arsdorint/task}/Deadline.java | 2 + src/main/java/{ => Arsdorint/task}/Event.java | 4 + src/main/java/{ => Arsdorint/task}/Task.java | 2 + src/main/java/{ => Arsdorint/task}/Todo.java | 4 +- text-ui-test/EXPECTED.TXT | 111 +++++++- text-ui-test/input.txt | 10 + 9 files changed, 385 insertions(+), 127 deletions(-) delete mode 100644 src/main/java/Arsdorint.java create mode 100644 src/main/java/Arsdorint/Arsdorint.java create mode 100644 src/main/java/Arsdorint/command/ArsdorintException.java rename src/main/java/{ => Arsdorint/task}/Deadline.java (93%) rename src/main/java/{ => Arsdorint/task}/Event.java (73%) rename src/main/java/{ => Arsdorint/task}/Task.java (95%) rename src/main/java/{ => Arsdorint/task}/Todo.java (64%) diff --git a/src/main/java/Arsdorint.java b/src/main/java/Arsdorint.java deleted file mode 100644 index bc54fafbf..000000000 --- a/src/main/java/Arsdorint.java +++ /dev/null @@ -1,121 +0,0 @@ -import java.util.Scanner; -public class Arsdorint { - static Scanner input = new Scanner(System.in); - static String logo = " ___ _ _\n" - + " / _ \\ _____ _____ ___| | ___ _____ _ _____ _| |_\n" - + " / /_\\ \\ / ___| / __/ / _ | / _ \\ / ___| | | | _ \\ |_ _|\n" - + " / _____ \\ | / __\\ \\ | |_| | | |_| | | / | | | | | | | |\n" - + "/_/ \\_\\ |_| /____/ \\_____| \\___/ |_| |_| |_| |_| |_|\n"; - - static Task[] toDoList = new Task[100]; - public static void echo(String command) { - System.out.println(command); - } - - public static String ask() { - String ask; - return ask = input.nextLine(); - } - - public static void list() { - System.out.println("____________________________________________________________\n"); - for (int i = 0; i < Task.numOfTasks; i++) { - System.out.print(Integer.toString(i + 1) + "."); - toDoList[i].printTask(); - } - System.out.println("____________________________________________________________\n"); - } - - public static void add(String command) { - /*toDoList[Task.numOfTasks] = new Task(command); - System.out.print("Added: "); - echo(command);*/ - String newTaskType = command.split(" ")[0]; - if (!(newTaskType.equalsIgnoreCase("todo") || - newTaskType.equalsIgnoreCase("deadline") || - newTaskType.equalsIgnoreCase("event"))) - System.out.println("Please indicate task type: " + - "\"todo\" " + "or \"deadline\" or \"event\""); - else { - String[] taskDescription = - command.replace(newTaskType, "").trim().split("/"); - switch (newTaskType.toLowerCase()) { - case "todo": - toDoList[Task.numOfTasks] = new Todo(taskDescription[0]); - break; - case "deadline": - toDoList[Task.numOfTasks] = - new Deadline(taskDescription[0], taskDescription[1].trim()); - break; - case "event": - toDoList[Task.numOfTasks] = - new Event(taskDescription[0], taskDescription[1].trim()); - break; - default: - break; - } - System.out.println("____________________________________________________________\n"); - System.out.println("Got it. I've added this task:\n" + "\t"); - toDoList[Task.numOfTasks - 1].printTask(); - System.out.println("\t" + "Now you have " + Integer.toString(Task.numOfTasks) + " tasks in the list."); - System.out.println("____________________________________________________________\n"); - } - } - - public static void mark(String command) { - String[] num = command.split(" "); - int idx = Integer.parseInt(num[1]); - if (num[0].equalsIgnoreCase("mark")) - toDoList[idx - 1].isDone = true; - else toDoList[idx - 1].isDone = false; - list(); - } - - public static void unmark(String command) { - String[] num = command.split(" "); - int idx = Integer.parseInt(num[1]); - if (num[0].equalsIgnoreCase("mark")) - toDoList[idx - 1].isDone = false; - else toDoList[idx - 1].isDone = true; - list(); - } - - public static void main(String[] args) { - //System.out.println("____________________________________________________________\n" + - //" Hello! I'm Arsdorint\n" + - //" What can I do for you?"); - String command = " "; - System.out.println("Hello from\n" + logo); - System.out.println("____________________________________________________________\n" + - " Hello! I'm Arsdorint, a member of Arsdorint Team.\n" + - " Please Type The Command As Follow:\n" + - "> Type anything to add to the to-do list. \n" + - "> Type \"list\" to list all the tasks. \n" + - "> Type \"mark\" follow by a number x to mark x tasks in the list" + - "> Type \"unmark\" follow by a number y to unmark y tasks in the list" + - "> Type \"bye\" to exit. \n" + - " What can I do for you? \n" + - "____________________________________________________________\n"); - while (true) { - command = ask(); - if (command.toLowerCase().equals("bye")) break; //exit command - else if (command.equalsIgnoreCase("list")) { - System.out.println("Here are the tasks in your list:"); - list(); - } - else if (command.toLowerCase().contains("mark")) { - System.out.println("Nice! I've marked this task as done: "); - mark(command); - } - else if (command.toLowerCase().contains("unmark")) { - System.out.println("OK, I've marked this task as not done yet:"); - unmark(command); - } - //add command when user don't type the instruction's command - else add(command); - } - - System.out.println(" Bye. Hope to see you again soon!\n" + - "____________________________________________________________\n"); - } -} diff --git a/src/main/java/Arsdorint/Arsdorint.java b/src/main/java/Arsdorint/Arsdorint.java new file mode 100644 index 000000000..212c203ef --- /dev/null +++ b/src/main/java/Arsdorint/Arsdorint.java @@ -0,0 +1,251 @@ +package Arsdorint; + +import java.util.Scanner; + +import Arsdorint.command.ArsdorintException; +import Arsdorint.task.Deadline; +import Arsdorint.task.Event; +import Arsdorint.task.Task; +import Arsdorint.task.Todo; + +public class Arsdorint { + private static final int MAX_NUM_OF_TASKS = 100; + private static final String EXIT_MESSAGE = " Bye. Hope to see you again soon!\n"; + private static final String HELLO_MESSAGE = + " Hello! I'm Arsdorint, a member of Arsdorint Team.\n" + + " Please Type The Command As Follow:\n"; + private static final String COMMAND_LIST_MESSAGE = + "> Type \"list\" to list all the tasks. \n" + + "> Type \"mark\" follow by a number x to mark x tasks in the list. \n" + + "> Type \"unmark\" follow by a number y to unmark y tasks in the list. \n" + + "> Type \"todo\" follow by a string x to add a work that need to be done. \n" + + "> Type \"deadline /x y\" with x is the type of work, y is the time or date of the deadline. \n" + + "> Type \"event x /y\" with x is the event, y is the time or date of that event. \n" + + "> Type \"bye\" to exit. \n"; + private static final String QUESTION = " What can I do for you?"; + private static final String MESSAGE_DIVIDER = + "____________________________________________________________"; + private static final String MESSAGE_DIVIDER_LIST = + "____________________________LIST____________________________"; + + private static final String ERROR_MESSAGE_BYE = " "; + private static final String ERROR_MESSAGE_LIST = " "; + private static final String ERROR_MESSAGE_MARK = + "Syntax for mark\n\t>>> mark \nNote: item index must exist in the current list"; + private static final String ERROR_MESSAGE_UNMARK = + "Syntax for unmark\n\t" + + ">>> unmark \nNote: item index must exist in the current list"; + private static final String ERROR_MESSAGE_TODO = "Syntax for todo\n\t>>> todo "; + private static final String ERROR_MESSAGE_DEADLINE = + "Syntax for deadline\n\t>>> deadline />> event / Type anything to add to the to-do list. +> Type "list" to list all the tasks. +> Type "mark" follow by a number x to mark x tasks in the list. +> Type "unmark" follow by a number y to unmark y tasks in the list +> Type "todo" follow by a string x to add a work that need to be done +> Type "deadline /x y" with x is a preposition, y is the time or date to add a deadline +> Type "event /x y" with x is a preposition, y is the time or date to add an event +> Type "bye" to exit. + + What can I do for you? +____________________________________________________________ +Please indicate task type: "todo" or "deadline" or "event" + +____________________________________________________________ + +Got it. I've added this task: + +[T][ ] CS2113 ip + Now you have 1 tasks in the list. +____________________________________________________________ + + +____________________________________________________________ + +Got it. I've added this task: + +[T][ ] CS2113 tp + Now you have 2 tasks in the list. +____________________________________________________________ + + +____________________________________________________________ + +Got it. I've added this task: + +[E][ ] Valentine (null) + Now you have 3 tasks in the list. +____________________________________________________________ + + +Here are the tasks in your list: +____________________________________________________________ + +1.[T][ ] CS2113 ip +2.[T][ ] CS2113 tp +3.[E][ ] Valentine (null) +____________________________________________________________ + + +____________________________________________________________ + +Got it. I've added this task: + +[D][ ] EE2026 (by next-week) + Now you have 4 tasks in the list. +____________________________________________________________ + + +Nice! I've marked this task as done: +____________________________________________________________ + +1.[T][ ] CS2113 ip +2.[T][ ] CS2113 tp +3.[E][X} Valentine (null) +4.[D][ ] EE2026 (by next-week) +____________________________________________________________ + + +Nice! I've marked this task as done: +____________________________________________________________ + +1.[T][ ] CS2113 ip +2.[T][X} CS2113 tp +3.[E][X} Valentine (null) +4.[D][ ] EE2026 (by next-week) +____________________________________________________________ + + +Nice! I've marked this task as done: +____________________________________________________________ + +1.[T][ ] CS2113 ip +2.[T][X} CS2113 tp +3.[E][ ] Valentine (null) +4.[D][ ] EE2026 (by next-week) +____________________________________________________________ + + +Here are the tasks in your list: +____________________________________________________________ + +1.[T][ ] CS2113 ip +2.[T][X} CS2113 tp +3.[E][ ] Valentine (null) +4.[D][ ] EE2026 (by next-week) +____________________________________________________________ diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index e69de29bb..a194a32ea 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -0,0 +1,10 @@ +boook +todo CS2113 ip +toDO CS2113 tp +EvenT Valentine /at 14th February +list +Deadline EE2026 /by next-week +Mark 3 +marK 2 +unmark 3 +list \ No newline at end of file From 0f5ea94f84eb0712cc5307a169354e60d42a5906 Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam Date: Wed, 15 Feb 2023 17:05:05 +0700 Subject: [PATCH 16/45] A-Packages Completed --- src/main/java/Arsdorint.java | 20 ------ src/main/java/Arsdorint/Arsdorint.java | 29 +++++---- src/main/java/Arsdorint/task/Deadline.java | 2 +- src/main/java/Arsdorint/task/Event.java | 4 +- src/main/java/TaskList.java | 10 +++ text-ui-test/EXPECTED.TXT | 72 ++++++++++------------ 6 files changed, 58 insertions(+), 79 deletions(-) delete mode 100644 src/main/java/Arsdorint.java create mode 100644 src/main/java/TaskList.java diff --git a/src/main/java/Arsdorint.java b/src/main/java/Arsdorint.java deleted file mode 100644 index fc8c68bd8..000000000 --- a/src/main/java/Arsdorint.java +++ /dev/null @@ -1,20 +0,0 @@ -public class Arsdorint { - public static void main(String[] args) { - String logo = " ___ _ _\n" - + " / _ \\ _____ _____ ___| | ___ _____ _ _____ _| |_\n" - + " / /_\\ \\ / ___| / __/ / _ | / _ \\ / ___| | | | _ \\ |_ _|\n" - + " / _____ \\ | / __\\ \\ | |_| | | |_| | | / | | | | | | | |\n" - + "/_/ \\_\\ |_| /____/ \\_____| \\___/ |_| |_| |_| |_| |_|\n"; - System.out.println("Hello from\n" + logo); - //System.out.println("____________________________________________________________\n" + - //" Hello! I'm Arsdorint\n" + - //" What can I do for you?"); - System.out.println("____________________________________________________________\n" + - " Hello! I'm Arsdorint\n" + - " What can I do for you?\n"); - - System.out.println("____________________________________________________________\n" + - " Bye. Hope to see you again soon!\n" + - "____________________________________________________________\n"); - } -} diff --git a/src/main/java/Arsdorint/Arsdorint.java b/src/main/java/Arsdorint/Arsdorint.java index 212c203ef..910b058ac 100644 --- a/src/main/java/Arsdorint/Arsdorint.java +++ b/src/main/java/Arsdorint/Arsdorint.java @@ -12,7 +12,7 @@ public class Arsdorint { private static final int MAX_NUM_OF_TASKS = 100; private static final String EXIT_MESSAGE = " Bye. Hope to see you again soon!\n"; private static final String HELLO_MESSAGE = - " Hello! I'm Arsdorint, a member of Arsdorint Team.\n" + + " Hello! I'm TaskList, a member of TaskList Team.\n" + " Please Type The Command As Follow:\n"; private static final String COMMAND_LIST_MESSAGE = "> Type \"list\" to list all the tasks. \n" + @@ -31,14 +31,18 @@ public class Arsdorint { private static final String ERROR_MESSAGE_BYE = " "; private static final String ERROR_MESSAGE_LIST = " "; private static final String ERROR_MESSAGE_MARK = - "Syntax for mark\n\t>>> mark \nNote: item index must exist in the current list"; + "=( OOPS!!! The description of a mark cannot be empty.\n" + "Syntax for mark\n\t" + + ">>> mark \n" + "Note: item index must exist in the current list"; private static final String ERROR_MESSAGE_UNMARK = - "Syntax for unmark\n\t" + - ">>> unmark \nNote: item index must exist in the current list"; - private static final String ERROR_MESSAGE_TODO = "Syntax for todo\n\t>>> todo "; + "=( OOPS!!! The description of an unmark cannot be empty.\n" + "Syntax for unmark\n\t" + + ">>> unmark \n" + "Note: item index must exist in the current list"; + private static final String ERROR_MESSAGE_TODO = + "=( OOPS!!! The description of a todo cannot be empty.\n" + "Syntax for todo\n\t>>> todo "; private static final String ERROR_MESSAGE_DEADLINE = + "=( OOPS!!! The description of a deadline cannot be empty.\n" + "Syntax for deadline\n\t>>> deadline />> event / data = new ArrayList<>(MAX_NUM_OF_TASKS); + public TaskList() { + } +} diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 8265c99e5..ee91b5110 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -6,28 +6,23 @@ Hello from /_/ \_\ |_| /____/ \_____| \___/ |_| |_| |_| |_| |_| ____________________________________________________________ - Hello! I'm Arsdorint.Arsdorint, a member of Arsdorint.Arsdorint Team. + Hello! I'm TaskList, a member of TaskList Team. Please Type The Command As Follow: -> Type anything to add to the to-do list. > Type "list" to list all the tasks. > Type "mark" follow by a number x to mark x tasks in the list. -> Type "unmark" follow by a number y to unmark y tasks in the list -> Type "todo" follow by a string x to add a work that need to be done -> Type "deadline /x y" with x is a preposition, y is the time or date to add a deadline -> Type "event /x y" with x is a preposition, y is the time or date to add an event +> Type "unmark" follow by a number y to unmark y tasks in the list. +> Type "todo" follow by a string x to add a work that need to be done. +> Type "deadline /x y" with x is the type of work, y is the time or date of the deadline. +> Type "event x /y" with x is the event, y is the time or date of that event. > Type "bye" to exit. What can I do for you? ____________________________________________________________ -Please indicate task type: "todo" or "deadline" or "event" +=( OOPS!!! I'm sorry, but I don't know what that means :-( ____________________________________________________________ -Got it. I've added this task: - -[T][ ] CS2113 ip - Now you have 1 tasks in the list. ____________________________________________________________ @@ -35,74 +30,71 @@ ____________________________________________________________ Got it. I've added this task: -[T][ ] CS2113 tp - Now you have 2 tasks in the list. +[T][ ] CS2113 tp CS2113 tp + Now you have 3 tasks in the list. ____________________________________________________________ - ____________________________________________________________ Got it. I've added this task: -[E][ ] Valentine (null) - Now you have 3 tasks in the list. +[E][ ] Valentine (at 14th February) + Now you have 4 tasks in the list. ____________________________________________________________ - Here are the tasks in your list: -____________________________________________________________ +____________________________LIST____________________________ 1.[T][ ] CS2113 ip 2.[T][ ] CS2113 tp -3.[E][ ] Valentine (null) +3.[T][ ] CS2113 tp CS2113 tp +4.[E][ ] Valentine (at 14th February) ____________________________________________________________ - ____________________________________________________________ Got it. I've added this task: -[D][ ] EE2026 (by next-week) - Now you have 4 tasks in the list. +[D][ ] EE2026 (by next-week) + Now you have 5 tasks in the list. ____________________________________________________________ - Nice! I've marked this task as done: -____________________________________________________________ +____________________________LIST____________________________ 1.[T][ ] CS2113 ip 2.[T][ ] CS2113 tp -3.[E][X} Valentine (null) -4.[D][ ] EE2026 (by next-week) +3.[T][X} CS2113 tp CS2113 tp +4.[E][ ] Valentine (at 14th February) +5.[D][ ] EE2026 (by next-week) ____________________________________________________________ - Nice! I've marked this task as done: -____________________________________________________________ +____________________________LIST____________________________ 1.[T][ ] CS2113 ip 2.[T][X} CS2113 tp -3.[E][X} Valentine (null) -4.[D][ ] EE2026 (by next-week) +3.[T][X} CS2113 tp CS2113 tp +4.[E][ ] Valentine (at 14th February) +5.[D][ ] EE2026 (by next-week) ____________________________________________________________ +OK, I've marked this task as not done yet: -Nice! I've marked this task as done: -____________________________________________________________ - +____________________________LIST____________________________ 1.[T][ ] CS2113 ip 2.[T][X} CS2113 tp -3.[E][ ] Valentine (null) -4.[D][ ] EE2026 (by next-week) +3.[T][X} CS2113 tp CS2113 tp +4.[E][ ] Valentine (at 14th February) +5.[D][ ] EE2026 (by next-week) ____________________________________________________________ - Here are the tasks in your list: -____________________________________________________________ +____________________________LIST____________________________ 1.[T][ ] CS2113 ip 2.[T][X} CS2113 tp -3.[E][ ] Valentine (null) -4.[D][ ] EE2026 (by next-week) +3.[T][X} CS2113 tp CS2113 tp +4.[E][ ] Valentine (at 14th February) +5.[D][ ] EE2026 (by next-week) ____________________________________________________________ - From 917d80a08d33a44fb3c31fe56d6478ef3070074b Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam Date: Thu, 16 Feb 2023 08:32:28 +0700 Subject: [PATCH 17/45] Added ArrayList toDoList instead of Task[] --- src/main/java/Arsdorint/Arsdorint.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/Arsdorint/Arsdorint.java b/src/main/java/Arsdorint/Arsdorint.java index 910b058ac..f992aa3b4 100644 --- a/src/main/java/Arsdorint/Arsdorint.java +++ b/src/main/java/Arsdorint/Arsdorint.java @@ -1,5 +1,6 @@ package Arsdorint; +import java.util.ArrayList; import java.util.Scanner; import Arsdorint.command.ArsdorintException; @@ -44,6 +45,8 @@ public class Arsdorint { private static final String ERROR_MESSAGE_EVENT = "=( OOPS!!! The description of an event cannot be empty.\n" + "Syntax for event\n\t>>> event / toDoList = new ArrayList<>(MAX_NUM_OF_TASKS); static boolean isRunning = true; public static void exit() { isRunning = false; @@ -66,7 +69,7 @@ private static void list() { showToUser(MESSAGE_DIVIDER_LIST); for (int i = 0; i < Task.numOfTasks; i++) { System.out.print((i + 1) + "."); - toDoList[i].printTask(); + toDoList.get(i).printTask(); } showToUser(MESSAGE_DIVIDER); } @@ -112,6 +115,8 @@ private static void commandErrorHandler(String errorMessage) { case "event": showToUser(MESSAGE_DIVIDER, ERROR_MESSAGE_EVENT, MESSAGE_DIVIDER); break; + case "delete": + showToUser(MESSAGE_DIVIDER, ERROR_MESSAGE_DELETE, MESSAGE_DIVIDER); default: showToUser(MESSAGE_DIVIDER, errorMessage, MESSAGE_DIVIDER); break; @@ -169,7 +174,7 @@ public static void addToDo(String[] taskDescription) { if (taskDescription[0].trim().isEmpty()) { throw new ArsdorintException("Error: Empty Todo."); } - toDoList[Task.numOfTasks] = new Todo(taskDescription[0]); + toDoList.add(new Todo(taskDescription[0])); addTaskMessage(); } catch (ArrayIndexOutOfBoundsException err) { commandErrorHandler("todo"); @@ -239,6 +244,9 @@ else if (lowerCaseLine.equalsIgnoreCase("todo") || lowerCaseLine.equalsIgnoreCase("deadline") || lowerCaseLine.equalsIgnoreCase("event")) add(command); //add command when user don't type the instruction's TaskList.command + else if (lowerCaseLine.equalsIgnoreCase("delete")) { + delete(splitLine); + } else wrongCommandMessage(); } public static void main(String[] args) { From 55179447d111a9a537861e418a4b4870fbe9c970 Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam Date: Thu, 16 Feb 2023 09:23:59 +0700 Subject: [PATCH 18/45] Level-6 Completed (Added delete), fix minor bugs in Task.java ([} to []) --- src/main/java/Arsdorint/Arsdorint.java | 73 +++++++++++++++----------- src/main/java/Arsdorint/task/Task.java | 2 +- 2 files changed, 42 insertions(+), 33 deletions(-) diff --git a/src/main/java/Arsdorint/Arsdorint.java b/src/main/java/Arsdorint/Arsdorint.java index f992aa3b4..959f9cbab 100644 --- a/src/main/java/Arsdorint/Arsdorint.java +++ b/src/main/java/Arsdorint/Arsdorint.java @@ -28,6 +28,7 @@ public class Arsdorint { "____________________________________________________________"; private static final String MESSAGE_DIVIDER_LIST = "____________________________LIST____________________________"; + private static final String MESSAGE_DELETE = "Noted. I've removed this task:"; private static final String ERROR_MESSAGE_BYE = " "; private static final String ERROR_MESSAGE_LIST = " "; @@ -117,6 +118,7 @@ private static void commandErrorHandler(String errorMessage) { break; case "delete": showToUser(MESSAGE_DIVIDER, ERROR_MESSAGE_DELETE, MESSAGE_DIVIDER); + break; default: showToUser(MESSAGE_DIVIDER, errorMessage, MESSAGE_DIVIDER); break; @@ -126,60 +128,72 @@ private static void commandErrorHandler(String errorMessage) { private static void addTaskMessage() { showToUser(MESSAGE_DIVIDER); System.out.println("\nGot it. I've added this task:\n" + "\t"); - toDoList[Task.numOfTasks - 1].printTask(); + toDoList.get(toDoList.size() - 1).printTask(); System.out.println("\t" + "Now you have " + Integer.toString(Task.numOfTasks) + " tasks in the list."); showToUser(MESSAGE_DIVIDER); } public static void mark(String[] command) { try { - int idx = Integer.parseInt(command[1]); + int idx = Integer.parseInt(command[1]) - 1; if (command[0].equalsIgnoreCase("mark")) { - toDoList[idx - 1].isDone = true; + toDoList.get(idx).isDone = true; System.out.println("Nice! I've marked this task as done: \n"); - } - else toDoList[idx - 1].isDone = false; + } else toDoList.get(idx).isDone = false; list(); - } catch (NumberFormatException err) { - commandErrorHandler("mark"); - } catch (ArrayIndexOutOfBoundsException err) { - commandErrorHandler("mark"); - } catch (NullPointerException err) { + } catch (NumberFormatException | IndexOutOfBoundsException | NullPointerException err) { commandErrorHandler("mark"); } } public static void unmark(String[] command) { try { - int idx = Integer.parseInt(command[1]); + int idx = Integer.parseInt(command[1]) - 1; if (command[0].equalsIgnoreCase("unmark")) { System.out.println("OK, I've marked this task as not done yet: \n"); - toDoList[idx - 1].isDone = true; + toDoList.get(idx).isDone = true; } else { - toDoList[idx - 1].isDone = false; + toDoList.get(idx).isDone = false; } list(); - } catch (NumberFormatException err) { - commandErrorHandler("unmark"); - } catch (ArrayIndexOutOfBoundsException err) { - commandErrorHandler("unmark"); - } catch (NullPointerException err) { + } catch (NumberFormatException | IndexOutOfBoundsException | NullPointerException err) { commandErrorHandler("unmark"); } } + + public static void removeTaskMessage(int idx) { + //showToUser(MESSAGE_DIVIDER); + System.out.println("\t"); + toDoList.get(idx).printTask(); + System.out.println("\t" + "Now you have " + --Task.numOfTasks + " tasks in the list."); + showToUser(MESSAGE_DIVIDER); + } + + public static void delete(String[] command) { + try { + int idx = Integer.parseInt(command[1]) - 1; + if (command[0].equalsIgnoreCase("delete")) { + toDoList.get(idx).isDone = true; + System.out.println(MESSAGE_DELETE); + } else toDoList.get(idx).isDone = false; + removeTaskMessage(idx); + toDoList.remove(idx); + } + catch (NumberFormatException | IndexOutOfBoundsException | NullPointerException err) { + commandErrorHandler("delete"); + } + } + public static void addToDo(String[] taskDescription) { try { if (taskDescription[0].trim().isEmpty()) { - throw new ArsdorintException("Error: Empty Todo."); + throw new ArsdorintException("Error: Empty Todo Description."); } toDoList.add(new Todo(taskDescription[0])); addTaskMessage(); - } catch (ArrayIndexOutOfBoundsException err) { - commandErrorHandler("todo"); - - } catch (ArsdorintException err) { + } catch (ArrayIndexOutOfBoundsException | ArsdorintException err) { commandErrorHandler("todo"); } } @@ -189,11 +203,9 @@ public static void addDeadline(String[] taskDescription) { if (taskDescription[0].trim().isEmpty()) { throw new ArsdorintException("Error: Empty Deadline Description."); } - toDoList[Task.numOfTasks] = new Deadline(taskDescription[0], taskDescription[1].trim()); + toDoList.add(new Deadline(taskDescription[0], taskDescription[1].trim())); addTaskMessage(); - } catch (ArrayIndexOutOfBoundsException err) { - commandErrorHandler("deadline"); - } catch (ArsdorintException err) { + } catch (ArrayIndexOutOfBoundsException | ArsdorintException err) { commandErrorHandler("deadline"); } } @@ -203,16 +215,13 @@ public static void addEvent(String[] taskDescription) { if (taskDescription[0].trim().isEmpty()) { throw new ArsdorintException("Error: Empty Event Description."); } - toDoList[Task.numOfTasks] = new Event(taskDescription[0], taskDescription[1].trim()); + toDoList.add(new Event(taskDescription[0], taskDescription[1].trim())); addTaskMessage(); - } catch (ArrayIndexOutOfBoundsException err) { - commandErrorHandler("event"); - } catch (ArsdorintException err) { + } catch (ArrayIndexOutOfBoundsException | ArsdorintException err){ commandErrorHandler("event"); } } - private static void exitMessage() { showToUser(MESSAGE_DIVIDER, EXIT_MESSAGE, MESSAGE_DIVIDER); } diff --git a/src/main/java/Arsdorint/task/Task.java b/src/main/java/Arsdorint/task/Task.java index ecccd34ba..1c3fe75af 100644 --- a/src/main/java/Arsdorint/task/Task.java +++ b/src/main/java/Arsdorint/task/Task.java @@ -13,7 +13,7 @@ public Task(String description) { } public String getStatus() { - return (isDone) ? "[X}" : "[ ]"; + return (isDone) ? "[X]" : "[ ]"; } public void printTask() { System.out.println(this.taskType + From 54e2d798eb762ae8eb364ff73738677f5ddf1398 Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam Date: Thu, 16 Feb 2023 12:10:51 +0700 Subject: [PATCH 19/45] Level-7 Completed --- src/main/java/Arsdorint/Arsdorint.java | 75 +++++++++++++++++++++- src/main/java/Arsdorint/task/Deadline.java | 7 ++ src/main/java/Arsdorint/task/Event.java | 7 ++ src/main/java/Arsdorint/task/Task.java | 15 ++++- src/main/java/Arsdorint/task/Todo.java | 2 + storage/arsdorintTask.txt | 1 + 6 files changed, 102 insertions(+), 5 deletions(-) create mode 100644 storage/arsdorintTask.txt diff --git a/src/main/java/Arsdorint/Arsdorint.java b/src/main/java/Arsdorint/Arsdorint.java index 959f9cbab..4900ad82d 100644 --- a/src/main/java/Arsdorint/Arsdorint.java +++ b/src/main/java/Arsdorint/Arsdorint.java @@ -1,5 +1,9 @@ package Arsdorint; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; import java.util.ArrayList; import java.util.Scanner; @@ -13,7 +17,7 @@ public class Arsdorint { private static final int MAX_NUM_OF_TASKS = 100; private static final String EXIT_MESSAGE = " Bye. Hope to see you again soon!\n"; private static final String HELLO_MESSAGE = - " Hello! I'm TaskList, a member of TaskList Team.\n" + + " Hello! I'm Arsdorint, a member of Arsdorint Team.\n" + " Please Type The Command As Follow:\n"; private static final String COMMAND_LIST_MESSAGE = "> Type \"list\" to list all the tasks. \n" + @@ -24,6 +28,14 @@ public class Arsdorint { "> Type \"event x /y\" with x is the event, y is the time or date of that event. \n" + "> Type \"bye\" to exit. \n"; private static final String QUESTION = " What can I do for you?"; + + private static final String STORAGE_DIRECTORY = "./storage"; + private static final String STORAGE_FILE_NAME = "./storage/arsdorintTask.txt"; + private static final String MESSAGE_NEW_FILE = "File created"; + private static final String MESSAGE_OVERWRITE_FILE = "File overwritten"; + private static final String MESSAGE_LOAD_FILE = "File loaded"; + private static final String MESSAGE_NO_FILE = "There is no existing file"; + private static final String MESSAGE_WRONG_FILE = "The storage files entry is invalid. Please save to overwrite"; private static final String MESSAGE_DIVIDER = "____________________________________________________________"; private static final String MESSAGE_DIVIDER_LIST = @@ -48,6 +60,7 @@ public class Arsdorint { "Syntax for event\n\t>>> event / Date: Wed, 1 Mar 2023 15:27:58 +0700 Subject: [PATCH 20/45] Update & Refactor Code Before "More OOP" --- src/main/java/Arsdorint/Arsdorint.java | 70 +++++----------------- src/main/java/Arsdorint/MessageList.java | 51 ++++++++++++++++ src/main/java/Arsdorint/task/Deadline.java | 4 +- src/main/java/Arsdorint/task/Event.java | 4 +- src/main/java/Arsdorint/task/Task.java | 16 ++++- src/main/java/Arsdorint/task/Todo.java | 4 +- src/main/java/TaskList.java | 10 ---- 7 files changed, 86 insertions(+), 73 deletions(-) create mode 100644 src/main/java/Arsdorint/MessageList.java delete mode 100644 src/main/java/TaskList.java diff --git a/src/main/java/Arsdorint/Arsdorint.java b/src/main/java/Arsdorint/Arsdorint.java index 4900ad82d..d5d647294 100644 --- a/src/main/java/Arsdorint/Arsdorint.java +++ b/src/main/java/Arsdorint/Arsdorint.java @@ -13,54 +13,9 @@ import Arsdorint.task.Task; import Arsdorint.task.Todo; -public class Arsdorint { - private static final int MAX_NUM_OF_TASKS = 100; - private static final String EXIT_MESSAGE = " Bye. Hope to see you again soon!\n"; - private static final String HELLO_MESSAGE = - " Hello! I'm Arsdorint, a member of Arsdorint Team.\n" + - " Please Type The Command As Follow:\n"; - private static final String COMMAND_LIST_MESSAGE = - "> Type \"list\" to list all the tasks. \n" + - "> Type \"mark\" follow by a number x to mark x tasks in the list. \n" + - "> Type \"unmark\" follow by a number y to unmark y tasks in the list. \n" + - "> Type \"todo\" follow by a string x to add a work that need to be done. \n" + - "> Type \"deadline /x y\" with x is the type of work, y is the time or date of the deadline. \n" + - "> Type \"event x /y\" with x is the event, y is the time or date of that event. \n" + - "> Type \"bye\" to exit. \n"; - private static final String QUESTION = " What can I do for you?"; - - private static final String STORAGE_DIRECTORY = "./storage"; - private static final String STORAGE_FILE_NAME = "./storage/arsdorintTask.txt"; - private static final String MESSAGE_NEW_FILE = "File created"; - private static final String MESSAGE_OVERWRITE_FILE = "File overwritten"; - private static final String MESSAGE_LOAD_FILE = "File loaded"; - private static final String MESSAGE_NO_FILE = "There is no existing file"; - private static final String MESSAGE_WRONG_FILE = "The storage files entry is invalid. Please save to overwrite"; - private static final String MESSAGE_DIVIDER = - "____________________________________________________________"; - private static final String MESSAGE_DIVIDER_LIST = - "____________________________LIST____________________________"; - private static final String MESSAGE_DELETE = "Noted. I've removed this task:"; - - private static final String ERROR_MESSAGE_BYE = " "; - private static final String ERROR_MESSAGE_LIST = " "; - private static final String ERROR_MESSAGE_MARK = - "=( OOPS!!! The description of a mark cannot be empty.\n" + "Syntax for mark\n\t" + - ">>> mark \n" + "Note: item index must exist in the current list"; - private static final String ERROR_MESSAGE_UNMARK = - "=( OOPS!!! The description of an unmark cannot be empty.\n" + "Syntax for unmark\n\t" + - ">>> unmark \n" + "Note: item index must exist in the current list"; - private static final String ERROR_MESSAGE_TODO = - "=( OOPS!!! The description of a todo cannot be empty.\n" + "Syntax for todo\n\t>>> todo "; - private static final String ERROR_MESSAGE_DEADLINE = - "=( OOPS!!! The description of a deadline cannot be empty.\n" + - "Syntax for deadline\n\t>>> deadline />> event / Type \"list\" to list all the tasks. \n" + + "> Type \"mark\" follow by a number x to mark x tasks in the list. \n" + + "> Type \"unmark\" follow by a number y to unmark y tasks in the list. \n" + + "> Type \"todo\" follow by a string x to add a work that need to be done. \n" + + "> Type \"deadline /x y\" with x is the type of work, y is the time or date of the deadline. \n" + + "> Type \"event x /y\" with x is the event, y is the time or date of that event. \n" + + "> Type \"bye\" to exit. \n"; + public static final String QUESTION = " What can I do for you?"; + + public static final String STORAGE_DIRECTORY = "./storage"; + public static final String STORAGE_FILE_NAME = "./storage/arsdorintTask.txt"; + public static final String MESSAGE_NEW_FILE = "File created"; + public static final String MESSAGE_OVERWRITE_FILE = "File overwritten"; + public static final String MESSAGE_LOAD_FILE = "File loaded"; + public static final String MESSAGE_NO_FILE = "There is no existing file"; + public static final String MESSAGE_WRONG_FILE = "The storage files entry is invalid. Please save to overwrite"; + public static final String MESSAGE_DIVIDER = + "____________________________________________________________"; + public static final String MESSAGE_DIVIDER_LIST = + "____________________________LIST____________________________"; + public static final String MESSAGE_DELETE = "Noted. I've removed this task:"; + + public static final String ERROR_MESSAGE_BYE = " "; + public static final String ERROR_MESSAGE_LIST = " "; + public static final String ERROR_MESSAGE_MARK = + "=( OOPS!!! The description of a mark cannot be empty.\n" + "Syntax for mark\n\t" + + ">>> mark \n" + "Note: item index must exist in the current list"; + public static final String ERROR_MESSAGE_UNMARK = + "=( OOPS!!! The description of an unmark cannot be empty.\n" + "Syntax for unmark\n\t" + + ">>> unmark \n" + "Note: item index must exist in the current list"; + public static final String ERROR_MESSAGE_TODO = + "=( OOPS!!! The description of a todo cannot be empty.\n" + "Syntax for todo\n\t>>> todo "; + public static final String ERROR_MESSAGE_DEADLINE = + "=( OOPS!!! The description of a deadline cannot be empty.\n" + + "Syntax for deadline\n\t>>> deadline />> event / data = new ArrayList<>(MAX_NUM_OF_TASKS); - public TaskList() { - } -} From 0d19e7f9fbd77795caba9ccf9d058fdc76b35be5 Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam Date: Wed, 1 Mar 2023 22:46:32 +0700 Subject: [PATCH 21/45] Numerous Refactor To facilitate MoreOOP --- src/main/java/Arsdorint/Arsdorint.java | 237 ++++-------------- src/main/java/Arsdorint/MessageList.java | 2 + src/main/java/Arsdorint/UI/TextUI.java | 64 +++++ .../Arsdorint/command/ArsdorintException.java | 2 + .../command/ArsdorintFileException.java | 6 + src/main/java/Arsdorint/command/Command.java | 20 ++ .../java/Arsdorint/command/CommandDate.java | 32 +++ .../Arsdorint/command/CommandDeadline.java | 30 +++ .../java/Arsdorint/command/CommandDelete.java | 34 +++ .../java/Arsdorint/command/CommandEvent.java | 31 +++ .../java/Arsdorint/command/CommandExit.java | 19 ++ .../java/Arsdorint/command/CommandList.java | 18 ++ .../java/Arsdorint/command/CommandMark.java | 34 +++ .../java/Arsdorint/command/CommandRes.java | 39 +++ .../java/Arsdorint/command/CommandToDo.java | 31 +++ .../java/Arsdorint/command/CommandUnmark.java | 33 +++ .../java/Arsdorint/command/CommandWrong.java | 21 ++ src/main/java/Arsdorint/data/Message.java | 4 + src/main/java/Arsdorint/data/Storage.java | 62 +++++ src/main/java/Arsdorint/data/TaskList.java | 30 +++ .../java/Arsdorint/parser/TaskParser.java | 200 +++++++++++++++ src/main/java/Arsdorint/task/Deadline.java | 38 ++- src/main/java/Arsdorint/task/Event.java | 38 ++- src/main/java/Arsdorint/task/Task.java | 14 ++ src/main/java/Arsdorint/task/Todo.java | 5 + 25 files changed, 846 insertions(+), 198 deletions(-) create mode 100644 src/main/java/Arsdorint/UI/TextUI.java create mode 100644 src/main/java/Arsdorint/command/ArsdorintFileException.java create mode 100644 src/main/java/Arsdorint/command/Command.java create mode 100644 src/main/java/Arsdorint/command/CommandDate.java create mode 100644 src/main/java/Arsdorint/command/CommandDeadline.java create mode 100644 src/main/java/Arsdorint/command/CommandDelete.java create mode 100644 src/main/java/Arsdorint/command/CommandEvent.java create mode 100644 src/main/java/Arsdorint/command/CommandExit.java create mode 100644 src/main/java/Arsdorint/command/CommandList.java create mode 100644 src/main/java/Arsdorint/command/CommandMark.java create mode 100644 src/main/java/Arsdorint/command/CommandRes.java create mode 100644 src/main/java/Arsdorint/command/CommandToDo.java create mode 100644 src/main/java/Arsdorint/command/CommandUnmark.java create mode 100644 src/main/java/Arsdorint/command/CommandWrong.java create mode 100644 src/main/java/Arsdorint/data/Message.java create mode 100644 src/main/java/Arsdorint/data/Storage.java create mode 100644 src/main/java/Arsdorint/data/TaskList.java create mode 100644 src/main/java/Arsdorint/parser/TaskParser.java diff --git a/src/main/java/Arsdorint/Arsdorint.java b/src/main/java/Arsdorint/Arsdorint.java index d5d647294..41787a6f3 100644 --- a/src/main/java/Arsdorint/Arsdorint.java +++ b/src/main/java/Arsdorint/Arsdorint.java @@ -7,34 +7,43 @@ import java.util.ArrayList; import java.util.Scanner; -import Arsdorint.command.ArsdorintException; +import Arsdorint.UI.TextUI; +import Arsdorint.command.*; +import Arsdorint.data.Storage; +import Arsdorint.data.TaskList; +import Arsdorint.parser.TaskParser; import Arsdorint.task.Deadline; import Arsdorint.task.Event; import Arsdorint.task.Task; import Arsdorint.task.Todo; + import static Arsdorint.MessageList.*; +import static Arsdorint.parser.TaskParser.showToUser; public class Arsdorint { static Scanner input = new Scanner(System.in); - static String logo = " ___ _ _\n" + public static String logo = " ___ _ _\n" + " / _ \\ _____ _____ ___| | ___ _____ _ _____ _| |_\n" + " / /_\\ \\ / ___| / __/ / _ | / _ \\ / ___| | | | _ \\ |_ _|\n" + " / _____ \\ | / __\\ \\ | |_| | | |_| | | / | | | | | | | |\n" + "/_/ \\_\\ |_| /____/ \\_____| \\___/ |_| |_| |_| |_| |_|\n"; - static ArrayList toDoList = new ArrayList<>(MAX_NUM_OF_TASKS); + public static ArrayList toDoList = new ArrayList<>(MAX_NUM_OF_TASKS); static boolean isRunning = true; - public static void exit() { - isRunning = false; - exitMessage(); + private TextUI UI; + private TaskList taskList = new TaskList(); + public void exit() { + UI.showExitMessage(); + UI.input.close(); + System.exit(0); } private static void wrongCommandMessage() { System.out.println("=( OOPS!!! I'm sorry, but I don't know what that means :-(\n" + MESSAGE_DIVIDER); } - private static void list() { + public static void list() { showToUser(MESSAGE_DIVIDER_LIST); for (int i = 0; i < Task.numOfTasks; i++) { System.out.print((i + 1) + "."); @@ -43,7 +52,7 @@ private static void list() { showToUser(MESSAGE_DIVIDER); } - public static void add(String command) { + /*public static void add(String command) { String newTaskType = command.split(" ")[0]; String[] taskDescription = command.replace(newTaskType, "").trim().split("/"); @@ -92,9 +101,9 @@ private static void commandErrorHandler(String errorMessage) { showToUser(MESSAGE_DIVIDER, errorMessage, MESSAGE_DIVIDER); break; } - } + }*/ - private static void addTaskMessage() { + public static void addTaskMessage() { showToUser(MESSAGE_DIVIDER); System.out.println("\nGot it. I've added this task:\n" + "\t"); toDoList.get(toDoList.size() - 1).printTask(); @@ -102,195 +111,39 @@ private static void addTaskMessage() { showToUser(MESSAGE_DIVIDER); } - public static void mark(String[] command) { - try { - int idx = Integer.parseInt(command[1]) - 1; - if (command[0].equalsIgnoreCase("mark")) { - toDoList.get(idx).isDone = true; - System.out.println("Nice! I've marked this task as done: \n"); - } else toDoList.get(idx).isDone = false; - list(); - } catch (NumberFormatException | IndexOutOfBoundsException | NullPointerException err) { - commandErrorHandler("mark"); - } - } - - public static void unmark(String[] command) { - try { - int idx = Integer.parseInt(command[1]) - 1; - if (command[0].equalsIgnoreCase("unmark")) { - System.out.println("OK, I've marked this task as not done yet: \n"); - toDoList.get(idx).isDone = false; - } - else { - toDoList.get(idx).isDone = true; - } - list(); - } catch (NumberFormatException | IndexOutOfBoundsException | NullPointerException err) { - commandErrorHandler("unmark"); - } - } - - public static void removeTaskMessage(int idx) { - showToUser(MESSAGE_DIVIDER); - System.out.println("\t"); - toDoList.get(idx).printTask(); - System.out.println("\t" + "Now you have " + --Task.numOfTasks + " tasks in the list."); - showToUser(MESSAGE_DIVIDER); - } - - public static void delete(String[] command) { - try { - int idx = Integer.parseInt(command[1]) - 1; - if (command[0].equalsIgnoreCase("delete")) { - toDoList.get(idx).isDone = true; - System.out.println(MESSAGE_DELETE); - } else toDoList.get(idx).isDone = false; - removeTaskMessage(idx); - toDoList.remove(idx); - } - catch (NumberFormatException | IndexOutOfBoundsException | NullPointerException err) { - commandErrorHandler("delete"); - } - } - - public static void addToDo(String[] taskDescription) { - try { - if (taskDescription[0].trim().isEmpty()) { - throw new ArsdorintException("Error: Empty Todo Description."); - } - toDoList.add(new Todo(taskDescription[0])); - addTaskMessage(); - } catch (ArrayIndexOutOfBoundsException | ArsdorintException err) { - commandErrorHandler("todo"); - } - } - - public static void addDeadline(String[] taskDescription) { - try { - if (taskDescription[0].trim().isEmpty()) { - throw new ArsdorintException("Error: Empty Deadline Description."); - } - toDoList.add(new Deadline(taskDescription[0], taskDescription[1].trim())); - addTaskMessage(); - } catch (ArrayIndexOutOfBoundsException | ArsdorintException err) { - commandErrorHandler("deadline"); - } - } - - public static void addEvent(String[] taskDescription) { - try { - if (taskDescription[0].trim().isEmpty()) { - throw new ArsdorintException("Error: Empty Event Description."); - } - toDoList.add(new Event(taskDescription[0], taskDescription[1].trim())); - addTaskMessage(); - } catch (ArrayIndexOutOfBoundsException | ArsdorintException err){ - commandErrorHandler("event"); - } - } - - private static void save() { - try { - FileWriter fileWriter = new FileWriter(STORAGE_FILE_NAME); - for (int i = 0; i < Task.numOfTasks; i++) { - fileWriter.write(toDoList.get(i).toSave()); - } - fileWriter.close(); - } catch (IOException err) { - File newFile = new File(STORAGE_DIRECTORY); - newFile.mkdir(); - showToUser(MESSAGE_NEW_FILE); - save(); - } finally { - showToUser(MESSAGE_OVERWRITE_FILE); - } - } - private static void load() { - try { - File file = new File(STORAGE_FILE_NAME); - Scanner fileRead = new Scanner(file); - showToUser(MESSAGE_LOAD_FILE); - while (fileRead.hasNext()) { - fileParser(fileRead.nextLine()); - } - fileRead.close(); - } catch (FileNotFoundException err) { - showToUser(MESSAGE_NO_FILE); - } catch (ArrayIndexOutOfBoundsException err) { - showToUser(MESSAGE_WRONG_FILE); - } - } - private static void fileParser(String newLine) { - String[] parsedLine = newLine.split(""); - switch (parsedLine[0]) { - case Todo.TYPE_TODO: - toDoList.add(new Todo(parsedLine[2])); - toDoList.get(Task.numOfTasks - 1).isDone = Boolean.valueOf(parsedLine[1]); - addTaskMessage(); - break; - case Deadline.TYPE_DEADLINE: - toDoList.add(new Deadline(parsedLine[2], parsedLine[3])); - toDoList.get(Task.numOfTasks - 1).isDone = Boolean.valueOf(parsedLine[1]); - addTaskMessage(); - break; - case Event.TYPE_EVENT: - toDoList.add(new Event(parsedLine[2], parsedLine[3])); - toDoList.get(Task.numOfTasks - 1).isDone = Boolean.valueOf(parsedLine[1]); - addTaskMessage(); - break; - } + public static void main(String[] args) { + new Arsdorint().run(); + /*helloMessage(); + load(); + while (isRunning) { + command(); + }*/ } - private static void exitMessage() { - showToUser(MESSAGE_DIVIDER, EXIT_MESSAGE, MESSAGE_DIVIDER); + public void run() { + start(); + mainLoop(); + exit(); } - private static void showToUser(String... message) { - for (String i : message) System.out.println(i); + private void start() { + this.UI = new TextUI(); + UI.showHelloMessage(); + UI.showToUser(Storage.load()); } - private static void helloMessage() { - System.out.println("Hello from\n" + logo); - showToUser(MESSAGE_DIVIDER, HELLO_MESSAGE, COMMAND_LIST_MESSAGE, QUESTION, MESSAGE_DIVIDER); + private void mainLoop() { + Command command; + do { + String userCommandText = UI.getUserCommand(); + command = new TaskParser().parsedCommand(userCommandText); + CommandRes res = executeCommand(command); + UI.showResToUser(res); + UI.showToUser(Storage.save()); + } while (!CommandExit.isExit(command)); } - private static void command() { - String command = input.nextLine(); - String[] splitLine = command.split(" "); - String lowerCaseLine = splitLine[0].toLowerCase(); - if (lowerCaseLine.equals("bye")) exit(); - else if (lowerCaseLine.contains("list")) { - System.out.println("Here are the tasks in your list:\n"); - list(); - } - else if (lowerCaseLine.equalsIgnoreCase("mark")) { - mark(splitLine); - } - else if (lowerCaseLine.equalsIgnoreCase("unmark")) { - unmark(splitLine); - } - else if (lowerCaseLine.equalsIgnoreCase("todo") || - lowerCaseLine.equalsIgnoreCase("deadline") || - lowerCaseLine.equalsIgnoreCase("event")) { - add(command); - } - //add command when user don't type the instruction's Arsdorint.command - else if (lowerCaseLine.equalsIgnoreCase("delete")) { - delete(splitLine); - } - else if (lowerCaseLine.equalsIgnoreCase("save")) { - save(); - } - else { - wrongCommandMessage(); - } - } - public static void main(String[] args) { - helloMessage(); - load(); - while (isRunning) { - command(); - } + private CommandRes executeCommand(Command command) { + return command.execute(); } } diff --git a/src/main/java/Arsdorint/MessageList.java b/src/main/java/Arsdorint/MessageList.java index 67d79ea4d..ba577e1c3 100644 --- a/src/main/java/Arsdorint/MessageList.java +++ b/src/main/java/Arsdorint/MessageList.java @@ -28,6 +28,7 @@ public class MessageList { public static final String MESSAGE_DIVIDER_LIST = "____________________________LIST____________________________"; public static final String MESSAGE_DELETE = "Noted. I've removed this task:"; + public static final String MESSAGE_UNKNOWN = "unknown message"; public static final String ERROR_MESSAGE_BYE = " "; public static final String ERROR_MESSAGE_LIST = " "; @@ -48,4 +49,5 @@ public class MessageList { public static final String ERROR_MESSAGE_DELETE = "Syntax for delete item \n\t>>> delete \n" + "Note: item index must exist in the current list"; + public static final int OFFSET = 1; } diff --git a/src/main/java/Arsdorint/UI/TextUI.java b/src/main/java/Arsdorint/UI/TextUI.java new file mode 100644 index 000000000..1222e7673 --- /dev/null +++ b/src/main/java/Arsdorint/UI/TextUI.java @@ -0,0 +1,64 @@ +package Arsdorint.UI; + +import Arsdorint.MessageList; +import Arsdorint.command.CommandRes; +import Arsdorint.data.Message; + +import java.io.PrintStream; +import java.util.Scanner; + +import static Arsdorint.Arsdorint.logo; +import static Arsdorint.MessageList.*; + +public class TextUI { + public final Scanner input; + public final PrintStream output; + public static final String UI_PROMPT = ">>> "; + + public TextUI() { + this.input = new Scanner(System.in); + this.output = System.out; + } + + public String getUserCommand() { + output.print(UI_PROMPT); + String userInput = input.nextLine(); + while (shouldIgnore(userInput)) { + userInput = input.nextLine(); + } + return userInput; + } + + public boolean shouldIgnore(String input) { + return input.trim().isEmpty(); + } + + public void showToUser(String...messages) { + for (String m : messages) { + output.println(m); + } + } + + public void showResToUser(CommandRes res) { + output.println(MessageList.MESSAGE_DIVIDER); + showToUser(res.messageTop); + showToUser(res.printTask()); + showToUser(res.messageBottom); + output.println(MessageList.MESSAGE_DIVIDER); + } + + public void showExitMessage() { + this.showToUser(MessageList.EXIT_MESSAGE); + } + + public void showUnknownMessage() { + output.println(MessageList.MESSAGE_DIVIDER); + this.showToUser(MessageList.COMMAND_LIST_MESSAGE); + output.println(MessageList.MESSAGE_DIVIDER); + } + public void showHelloMessage() { + System.out.println("Hello from\n" + logo); + //showToUser(MESSAGE_DIVIDER, HELLO_MESSAGE, COMMAND_LIST_MESSAGE, QUESTION, MESSAGE_DIVIDER); + this.showToUser(HELLO_MESSAGE); + } +} diff --git a/src/main/java/Arsdorint/command/ArsdorintException.java b/src/main/java/Arsdorint/command/ArsdorintException.java index a9f84a468..68747d73d 100644 --- a/src/main/java/Arsdorint/command/ArsdorintException.java +++ b/src/main/java/Arsdorint/command/ArsdorintException.java @@ -4,4 +4,6 @@ public class ArsdorintException extends Exception { public ArsdorintException(String message) { super(message); } + public ArsdorintException() { + } } diff --git a/src/main/java/Arsdorint/command/ArsdorintFileException.java b/src/main/java/Arsdorint/command/ArsdorintFileException.java new file mode 100644 index 000000000..c9c61a4fa --- /dev/null +++ b/src/main/java/Arsdorint/command/ArsdorintFileException.java @@ -0,0 +1,6 @@ +package Arsdorint.command; + +public class ArsdorintFileException extends ArsdorintException { + public ArsdorintFileException() { + } +} diff --git a/src/main/java/Arsdorint/command/Command.java b/src/main/java/Arsdorint/command/Command.java new file mode 100644 index 000000000..00c5320ca --- /dev/null +++ b/src/main/java/Arsdorint/command/Command.java @@ -0,0 +1,20 @@ +package Arsdorint.command; + +public class Command { + public String commandType; + protected Command(String commandType) { + this.commandType = commandType; + } + public CommandRes execute() { + throw new UnsupportedOperationException("Child classes' method"); + } + + public boolean contains(final int[] arr, final int key) { + for (final int i : arr) { + if (i == key) { + return true; + } + } + return false; + } +} diff --git a/src/main/java/Arsdorint/command/CommandDate.java b/src/main/java/Arsdorint/command/CommandDate.java new file mode 100644 index 000000000..89d4487b2 --- /dev/null +++ b/src/main/java/Arsdorint/command/CommandDate.java @@ -0,0 +1,32 @@ +package Arsdorint.command; + +import Arsdorint.MessageList; +import Arsdorint.data.TaskList; +import Arsdorint.task.Task; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.stream.Collectors; + + +public class CommandDate extends Command { + public CommandDate(LocalDate date) { + super(COMMAND_NAME); + this.date = date; + } + public static final String COMMAND_NAME = "delete"; + public static final String SYNTAX = "TODO"; + public static final String MESSAGE_TOP = "TODO"; + public LocalDate date; + + @Override + public CommandRes execute() { + ArrayList task = new ArrayList(TaskList.list.stream().filter(i -> !i.isDateNull()).filter + (i -> i.getDate().equals(this.date)).collect(Collectors.toList())); + long count = task.stream().count(); + String messageTop = count + " tasks happen on this date"; + return new CommandRes(messageTop, task, ""); + } +} + + diff --git a/src/main/java/Arsdorint/command/CommandDeadline.java b/src/main/java/Arsdorint/command/CommandDeadline.java new file mode 100644 index 000000000..1d0554910 --- /dev/null +++ b/src/main/java/Arsdorint/command/CommandDeadline.java @@ -0,0 +1,30 @@ +package Arsdorint.command; + +import Arsdorint.data.TaskList; +import Arsdorint.task.Deadline; +import Arsdorint.task.Task; + +import java.util.ArrayList; + +public class CommandDeadline extends Command { + public CommandDeadline(String description, String date) { + super(COMMAND_NAME); + this.description = description; + this.date = date; + } + + public static final String COMMAND_NAME = "deadline"; + public static final String SYNTAX = "TODO"; + public static final String MESSAGE_TOP = "TODO"; + public String description; + public String date; + public ArrayList task = new ArrayList(); + + @Override + public CommandRes execute() { + Task added = new Deadline(description, date); + TaskList.list.add(added); + task.add(added); + return new CommandRes(MESSAGE_TOP, task, TaskList.getAllMessage()); + } +} diff --git a/src/main/java/Arsdorint/command/CommandDelete.java b/src/main/java/Arsdorint/command/CommandDelete.java new file mode 100644 index 000000000..31498c8c4 --- /dev/null +++ b/src/main/java/Arsdorint/command/CommandDelete.java @@ -0,0 +1,34 @@ +package Arsdorint.command; + +import Arsdorint.MessageList; +import Arsdorint.data.TaskList; +import Arsdorint.task.Task; + +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +public class CommandDelete extends Command { + + public CommandDelete(int...idx) { + super(COMMAND_NAME); + this.idx = idx; + } + public static final String COMMAND_NAME = "delete"; + public static final String SYNTAX = "TODO"; + public static final String MESSAGE_TOP = "TODO"; + public int[] idx; + + @Override + public CommandRes execute() { + ArrayList task = new ArrayList(IntStream.range(0, TaskList.list.size()).filter + (i -> contains(idx, i)).mapToObj(i -> TaskList.list.get(i)).collect(Collectors.toList())); + Arrays.sort(idx); + for (int i = idx.length - MessageList.OFFSET; i > -MessageList.OFFSET; i--) { + TaskList.list.remove(idx[1]); + } + return new CommandRes(MESSAGE_TOP, task, TaskList.getAllMessage()); + } +} diff --git a/src/main/java/Arsdorint/command/CommandEvent.java b/src/main/java/Arsdorint/command/CommandEvent.java new file mode 100644 index 000000000..3af4561ff --- /dev/null +++ b/src/main/java/Arsdorint/command/CommandEvent.java @@ -0,0 +1,31 @@ +package Arsdorint.command; + +import Arsdorint.data.TaskList; +import Arsdorint.task.Deadline; +import Arsdorint.task.Event; +import Arsdorint.task.Task; + +import java.util.ArrayList; + +public class CommandEvent extends Command { + public CommandEvent(String description, String date) { + super(COMMAND_NAME); + this.description = description; + this.date = date; + } + + public static final String COMMAND_NAME = "event"; + public static final String SYNTAX = "TODO"; + public static final String MESSAGE_TOP = "TODO"; + public String description; + public String date; + public ArrayList task = new ArrayList(); + + @Override + public CommandRes execute() { + Task added = new Event(description, date); + TaskList.list.add(added); + task.add(added); + return new CommandRes(MESSAGE_TOP, task, TaskList.getAllMessage()); + } +} diff --git a/src/main/java/Arsdorint/command/CommandExit.java b/src/main/java/Arsdorint/command/CommandExit.java new file mode 100644 index 000000000..5732de412 --- /dev/null +++ b/src/main/java/Arsdorint/command/CommandExit.java @@ -0,0 +1,19 @@ +package Arsdorint.command; + +public class CommandExit extends Command { + public CommandExit() { + super(COMMAND_NAME); + } + + public static final String COMMAND_NAME = "exit"; + public static final String MESSAGE_TOP = "Bye!"; + public static boolean isExit(Command command) { + return command.commandType.equalsIgnoreCase("COMMAND_NAME"); + } + + @Override + public CommandRes execute() { + return new CommandRes(MESSAGE_TOP); + } +} + diff --git a/src/main/java/Arsdorint/command/CommandList.java b/src/main/java/Arsdorint/command/CommandList.java new file mode 100644 index 000000000..2f75ea7c1 --- /dev/null +++ b/src/main/java/Arsdorint/command/CommandList.java @@ -0,0 +1,18 @@ +package Arsdorint.command; + +import Arsdorint.MessageList; +import Arsdorint.data.TaskList; + +public class CommandList extends Command { + public CommandList() { + super(COMMAND_NAME); + } + + public static final String COMMAND_NAME = "list"; + public static final String SYNTAX = "TODO"; + + @Override + public CommandRes execute() { + return new CommandRes(MessageList.MESSAGE_DIVIDER_LIST, TaskList.list, TaskList.getAllMessage()); + } +} diff --git a/src/main/java/Arsdorint/command/CommandMark.java b/src/main/java/Arsdorint/command/CommandMark.java new file mode 100644 index 000000000..9087687cb --- /dev/null +++ b/src/main/java/Arsdorint/command/CommandMark.java @@ -0,0 +1,34 @@ +package Arsdorint.command; + +import Arsdorint.MessageList; +import Arsdorint.data.TaskList; +import Arsdorint.task.Task; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +public class CommandMark extends Command { + public CommandMark(int...idx) { + super(COMMAND_NAME); + this.idx = idx; + } + + public static final String COMMAND_NAME = "mark"; + public static final String SYNTAX = "TODO"; + public static final String MESSAGE_TOP = "TODO"; + public int[] idx; + + @Override + public CommandRes execute() { + for (int i = 0; i < idx.length; i++) { + TaskList.list.get(idx[i]).setIsDone(true); + } + ArrayList task = new ArrayList(IntStream.range(0, TaskList.list.size()).filter + (i -> contains(idx, i)).mapToObj(i -> TaskList.list.get(i)).collect(Collectors.toList())); + + return new CommandRes(MESSAGE_TOP, task, TaskList.getAllMessage()); + } +} + diff --git a/src/main/java/Arsdorint/command/CommandRes.java b/src/main/java/Arsdorint/command/CommandRes.java new file mode 100644 index 000000000..37a2f5c55 --- /dev/null +++ b/src/main/java/Arsdorint/command/CommandRes.java @@ -0,0 +1,39 @@ +package Arsdorint.command; + +import Arsdorint.MessageList; +import Arsdorint.task.Task; + +import java.util.ArrayList; +import java.util.stream.IntStream; + +public class CommandRes { + public String messageTop = ""; + public String messageBottom = ""; + public ArrayList task = null; + + public CommandRes(String strTop) { + this.messageTop = strTop; + } + public CommandRes(String strTop, ArrayList task, String strBottom) { + this.messageTop = strTop; + this.messageBottom = strBottom; + this.task = task; + } + + public CommandRes() { + + } + + public String[] printTask() { + if (task == null) { + return new String[]{}; + } else if (messageTop.equals(MessageList.MESSAGE_DIVIDER_LIST)) { + return IntStream.range(0, task.size()).mapToObj(i -> + { + return (i + MessageList.OFFSET + "." + task.get(i)).toString(); + }).toArray(String[]::new); + } else { + return task.stream().map(Task::toString).toArray(String[]::new); + } + } +} diff --git a/src/main/java/Arsdorint/command/CommandToDo.java b/src/main/java/Arsdorint/command/CommandToDo.java new file mode 100644 index 000000000..269295509 --- /dev/null +++ b/src/main/java/Arsdorint/command/CommandToDo.java @@ -0,0 +1,31 @@ +package Arsdorint.command; + +import Arsdorint.data.TaskList; +import Arsdorint.task.Deadline; +import Arsdorint.task.Task; +import Arsdorint.task.Todo; + +import java.util.ArrayList; + +public class CommandToDo extends Command { + public CommandToDo(String description) { + super(COMMAND_NAME); + this.description = description; + } + + public static final String COMMAND_NAME = "todo"; + public static final String SYNTAX = "TODO"; + public static final String MESSAGE_TOP = "TODO"; + public String description; + + public ArrayList task = new ArrayList(); + + @Override + public CommandRes execute() { + Task added = new Todo(description); + TaskList.list.add(added); + task.add(added); + return new CommandRes(MESSAGE_TOP, task, TaskList.getAllMessage()); + } +} + diff --git a/src/main/java/Arsdorint/command/CommandUnmark.java b/src/main/java/Arsdorint/command/CommandUnmark.java new file mode 100644 index 000000000..e73d84cf0 --- /dev/null +++ b/src/main/java/Arsdorint/command/CommandUnmark.java @@ -0,0 +1,33 @@ +package Arsdorint.command; + +import Arsdorint.data.TaskList; +import Arsdorint.task.Task; + +import java.util.ArrayList; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +public class CommandUnmark extends Command { + public CommandUnmark(int...idx) { + super(COMMAND_NAME); + this.idx = idx; + } + + public static final String COMMAND_NAME = "unmark"; + public static final String SYNTAX = "TODO"; + public static final String MESSAGE_TOP = "TODO"; + public int[] idx; + + @Override + public CommandRes execute() { + for (int i = 0; i < idx.length; i++) { + TaskList.list.get(idx[i]).setIsDone(true); + } + ArrayList task = new ArrayList(IntStream.range(0, TaskList.list.size()).filter + (i -> contains(idx, i)).mapToObj(i -> TaskList.list.get(i)).collect(Collectors.toList())); + + return new CommandRes(MESSAGE_TOP, task, TaskList.getAllMessage()); + } +} + + diff --git a/src/main/java/Arsdorint/command/CommandWrong.java b/src/main/java/Arsdorint/command/CommandWrong.java new file mode 100644 index 000000000..c209f4be6 --- /dev/null +++ b/src/main/java/Arsdorint/command/CommandWrong.java @@ -0,0 +1,21 @@ +package Arsdorint.command; + +public class CommandWrong extends Command { + public CommandWrong(String message) { + super(COMMAND_NAME); + this.top = top; + } + + public CommandWrong(String top, String bottom) { + this(top); + this.bottom = bottom; + } + public static final String COMMAND_NAME = "wrong command"; + public String top; + public String bottom; + + @Override + public CommandRes execute() { + return new CommandRes(this.top, null, this.bottom); + } +} diff --git a/src/main/java/Arsdorint/data/Message.java b/src/main/java/Arsdorint/data/Message.java new file mode 100644 index 000000000..98ac74232 --- /dev/null +++ b/src/main/java/Arsdorint/data/Message.java @@ -0,0 +1,4 @@ +package Arsdorint.data; + +public class Message { +} diff --git a/src/main/java/Arsdorint/data/Storage.java b/src/main/java/Arsdorint/data/Storage.java new file mode 100644 index 000000000..c097cfa5d --- /dev/null +++ b/src/main/java/Arsdorint/data/Storage.java @@ -0,0 +1,62 @@ +package Arsdorint.data; + +import Arsdorint.command.ArsdorintFileException; +import Arsdorint.parser.TaskParser; +import Arsdorint.task.Task; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +import static Arsdorint.Arsdorint.*; +import static Arsdorint.MessageList.*; +import static Arsdorint.MessageList.MESSAGE_WRONG_FILE; +import static Arsdorint.parser.TaskParser.fileParser; +import static Arsdorint.parser.TaskParser.showToUser; + +public class Storage { + public Storage() { + + } + public static final String STORAGE_DIRECTORY = "./storage"; + public static final String STORAGE_FILE_NAME = "./storage/ArsdorintTask.txt"; + public static String[] save() { + try { + FileWriter fileWriter = new FileWriter(STORAGE_FILE_NAME); + for (int i = 0; i < Task.numOfTasks; i++) { + fileWriter.write(toDoList.get(i).toSave()); + } + fileWriter.close(); + return new String[]{MESSAGE_OVERWRITE_FILE}; + } catch (IOException err) { + File newFile = new File(STORAGE_DIRECTORY); + newFile.mkdir(); + //showToUser(MESSAGE_NEW_FILE); + save(); + /*} finally { + showToUser(MESSAGE_OVERWRITE_FILE);*/ + return new String[]{MESSAGE_NO_FILE, MESSAGE_NEW_FILE}; + } + } + public static String load() { + try { + File file = new File(STORAGE_FILE_NAME); + Scanner fileRead = new Scanner(file); + showToUser(MESSAGE_LOAD_FILE); + while (fileRead.hasNext()) { + new TaskParser().fileParser(fileRead.nextLine()); + } + fileRead.close(); + return MESSAGE_LOAD_FILE; + } catch (FileNotFoundException err) { + return MESSAGE_NO_FILE; + } catch (ArrayIndexOutOfBoundsException err) { + return MESSAGE_WRONG_FILE; + } catch (ArsdorintFileException err) { + return MESSAGE_WRONG_FILE; + } + } + +} diff --git a/src/main/java/Arsdorint/data/TaskList.java b/src/main/java/Arsdorint/data/TaskList.java new file mode 100644 index 000000000..faed9e978 --- /dev/null +++ b/src/main/java/Arsdorint/data/TaskList.java @@ -0,0 +1,30 @@ +package Arsdorint.data; + +import Arsdorint.task.Task; + +import java.util.ArrayList; + +public class TaskList { + public TaskList() { + } + public static final int MAX_NUM_OF_TASKS = 100; + public static ArrayList list = new ArrayList(MAX_NUM_OF_TASKS); + public static String getAllMessage() { + int count = TaskList.list.size(); + return "\t" + "Now you have " + count + printTasksOrTask(count) + " in the list."; + } + + public static String getMarkedMessage() { + int count = TaskList.list.size(); + return "\t" + "Now you have " + count + "marked" + printTasksOrTask(count) + " in the list."; + } + + public static String getUnmarkedMessage() { + int count = TaskList.list.size(); + return "\t" + "Now you have " + count + "unmarked" + printTasksOrTask(count) + " in the list."; + } + + private static String printTasksOrTask(int num) { + return ((num == 1) ? "task" : "tasks"); + } +} diff --git a/src/main/java/Arsdorint/parser/TaskParser.java b/src/main/java/Arsdorint/parser/TaskParser.java new file mode 100644 index 000000000..54d3066c7 --- /dev/null +++ b/src/main/java/Arsdorint/parser/TaskParser.java @@ -0,0 +1,200 @@ +package Arsdorint.parser; + +import Arsdorint.MessageList; +import Arsdorint.command.*; +import Arsdorint.data.TaskList; +import Arsdorint.task.Deadline; +import Arsdorint.task.Event; +import Arsdorint.task.Task; +import Arsdorint.task.Todo; + +import java.time.LocalDate; +import java.time.format.DateTimeParseException; + +import static Arsdorint.Arsdorint.*; +import static Arsdorint.MessageList.*; +import static Arsdorint.MessageList.MESSAGE_DIVIDER; +import static Arsdorint.data.Storage.save; + +public class TaskParser { + public TaskParser() { + } + public Command parsedCommand(String input) { + String[] command = input.split(" "); + if (command.length == 0) { + return new CommandWrong(MESSAGE_UNKNOWN, COMMAND_LIST_MESSAGE); + } + final String arguments = input.replaceFirst(command[0], "").trim(); + String lowerCaseLine = command[0].toLowerCase(); + if (lowerCaseLine.equals("bye")) { + return new CommandExit(); + } + else if (lowerCaseLine.contains("list")) { + System.out.println("Here are the tasks in your list:\n"); + return new CommandList(); + } + else if (lowerCaseLine.equalsIgnoreCase("mark")) { + return mark(arguments); + } + else if (lowerCaseLine.equalsIgnoreCase("unmark")) { + return unmark(arguments); + } + else if (lowerCaseLine.equalsIgnoreCase("todo")) { + return addToDo(arguments); + } + else if (lowerCaseLine.equalsIgnoreCase("deadline")) { + return addDeadline(arguments); + } + else if (lowerCaseLine.equalsIgnoreCase("event")) { + return addEvent(arguments); + } + //add command when user don't type the instruction's Arsdorint.command + else if (lowerCaseLine.equalsIgnoreCase("delete")) { + return delete(arguments); + } else if (lowerCaseLine.equalsIgnoreCase("date")) { + return addDate(arguments); + /*} else if (lowerCaseLine.equalsIgnoreCase("save")) { + //save(); + return new CommandExit();*/ + } else { + return new CommandWrong(MESSAGE_UNKNOWN, COMMAND_LIST_MESSAGE); + } + } + + public static void fileParser(String input) throws ArsdorintFileException { + String[] parsedLine = input.split(""); + String[] parsedTrim = new String[parsedLine.length]; + + for (int i = 0; i < parsedLine.length; i++) { + parsedTrim[i] = parsedLine[i].trim(); + } + switch (parsedLine[0]) { + case Todo.TYPE_TODO: + toDoList.add(new Todo(parsedLine[2])); + toDoList.get(Task.numOfTasks - 1).isDone = Boolean.valueOf(parsedLine[1]); + addTaskMessage(); + break; + case Deadline.TYPE_DEADLINE: + toDoList.add(new Deadline(parsedLine[2], parsedLine[3])); + toDoList.get(Task.numOfTasks - 1).isDone = Boolean.valueOf(parsedLine[1]); + addTaskMessage(); + break; + case Event.TYPE_EVENT: + toDoList.add(new Event(parsedLine[2], parsedLine[3])); + toDoList.get(Task.numOfTasks - 1).isDone = Boolean.valueOf(parsedLine[1]); + addTaskMessage(); + break; + default: + throw new ArsdorintFileException(); + } + } + + public Command mark(String command) { + try { + String[] parsed = command.split(" "); + if (parsed.length < 1) { + throw new ArsdorintException(); + //System.out.println("Nice! I've marked this task as done: \n"); + } return new CommandMark(strToIntArr(parsed)); + } catch (NumberFormatException | IndexOutOfBoundsException | ArsdorintException err) { + return new CommandWrong(CommandMark.SYNTAX); + } + } + + public Command unmark(String command) { + try { + String[] parsed = command.split(" "); + if (parsed.length < 1) { + throw new ArsdorintException(); + //System.out.println("OK, I've marked this task as not done yet: \n"); + } return new CommandMark(strToIntArr(parsed)); + } catch (NumberFormatException | IndexOutOfBoundsException | ArsdorintException err) { + return new CommandWrong(CommandUnmark.SYNTAX); + } +} + + public static void removeTaskMessage(int idx) { + showToUser(MESSAGE_DIVIDER); + System.out.println("\t"); + toDoList.get(idx).printTask(); + System.out.println("\t" + "Now you have " + --Task.numOfTasks + " tasks in the list."); + showToUser(MESSAGE_DIVIDER); + } + + public Command delete(String command) { + try { + String[] parsed = command.split(" "); + if (parsed.length < 1) { + throw new ArsdorintException(); + } return new CommandMark(strToIntArr(parsed)); + } catch (NumberFormatException | IndexOutOfBoundsException | ArsdorintException err) { + return new CommandWrong(CommandDelete.SYNTAX); + } + } + + public Command addToDo(String taskDescription) { + try { + String[] parsed = taskDescription.split("/"); + if (parsed[0].equals("")) { + throw new ArsdorintException("Error: Empty Todo Description."); + } + return new CommandToDo(taskDescription); + } catch (ArrayIndexOutOfBoundsException | ArsdorintException | NumberFormatException err) { + return new CommandWrong(CommandToDo.SYNTAX); + } + } + + public Command addDeadline(String taskDescription) { + try { + String[] parsed = taskDescription.split("/"); + if (!(parsed.length == 2)) { + throw new ArsdorintException("Error: Empty Deadline Description."); + } + return new CommandDeadline(parsed[0].trim(), parsed[1].trim()); + } catch (ArrayIndexOutOfBoundsException | ArsdorintException | NumberFormatException err) { + return new CommandWrong(CommandDeadline.SYNTAX); + } + } + + public Command addEvent(String taskDescription) { + try { + String[] parsed = taskDescription.split("/"); + if (!(parsed.length == 2)) { + throw new ArsdorintException("Error: Empty Event Description."); + } + return new CommandEvent(parsed[0].trim(), parsed[1].trim()); + } catch (ArrayIndexOutOfBoundsException | ArsdorintException | NumberFormatException err) { + return new CommandWrong(CommandEvent.SYNTAX); + } + } + + public Command addDate(String taskDescription) { + try { + return new CommandDate(LocalDate.parse(taskDescription)); + } catch (DateTimeParseException err) { + return new CommandWrong(CommandDate.SYNTAX); + } + } + + + private static void exitMessage() { + showToUser(MESSAGE_DIVIDER, EXIT_MESSAGE, MESSAGE_DIVIDER); + } + + public static void showToUser(String... message) { + for (String i : message) System.out.println(i); + } + + private int[] strToIntArr(String[] parsed) throws ArsdorintException { + int[] intArr = new int[parsed.length]; + for (int i = 0; i < parsed.length; i++) { + intArr[i] = Integer.parseInt(parsed[i]) - OFFSET; + if (intArr[i] < 0 | intArr[i] > TaskList.list.size()) { + throw new ArsdorintException(); + } + } + return intArr; + } + + +} diff --git a/src/main/java/Arsdorint/task/Deadline.java b/src/main/java/Arsdorint/task/Deadline.java index 36c9f1cec..233cafbba 100644 --- a/src/main/java/Arsdorint/task/Deadline.java +++ b/src/main/java/Arsdorint/task/Deadline.java @@ -1,13 +1,28 @@ package Arsdorint.task; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; + public class Deadline extends Task { public static final String TYPE_DEADLINE = "D"; - public String date; + public String dateString; + public LocalDate date; public Deadline(String description, String date) { super(description); - this.date = date; this.taskType = "[D]"; this.taskName = TYPE_DEADLINE; + try { + this.date = LocalDate.parse(date); + } catch (DateTimeParseException err) { + this.date = null; + this.dateString = date; + } + } + + public Deadline(boolean status, String description, String date) { + this(description, date); + this.isDone = status; } public void printTask() { System.out.println(this.taskType + this.getStatus() @@ -16,7 +31,24 @@ public void printTask() { @Override public String toSave() { return (this.taskName + VERTICAL_BAR + binaryRes() + VERTICAL_BAR + - this.description + VERTICAL_BAR + this.date + "\n"); + this.description + VERTICAL_BAR + printDate("yyyy-MM-dd") + "\n"); + } + + @Override + public String toString() { + return (this.taskType + this.getStatus() + " " + this.description + "\t(" + printDate("d MMM yyy") + ")"); + } + + @Override + public boolean isDateNull() { + return (this.date == null ? true : false); + } + + public String printDate(String date) { + return (this.date == null) ? this.dateString : this.date.format(DateTimeFormatter.ofPattern(date)); + } + public LocalDate getDate() { + return this.date; } } diff --git a/src/main/java/Arsdorint/task/Event.java b/src/main/java/Arsdorint/task/Event.java index ceda29013..6da519881 100644 --- a/src/main/java/Arsdorint/task/Event.java +++ b/src/main/java/Arsdorint/task/Event.java @@ -1,15 +1,30 @@ package Arsdorint.task; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; + public class Event extends Task { public static final String TYPE_EVENT = "E"; - public String date; + public String dateString; + public LocalDate date; public Event(String description, String date) { super(description); - this.date = date; + try { + this.date = LocalDate.parse(date); + } catch (DateTimeParseException err) { + this.date = null; + this.dateString = date; + } this.taskType = "[E]"; this.taskName = TYPE_EVENT; } + public Event(boolean status, String description, String date) { + this(description, date); + this.isDone = status; + } + public void printTask() { System.out.println(this.taskType + this.getStatus() + " " + this.description + "(" + this.date + ")"); @@ -17,6 +32,23 @@ public void printTask() { @Override public String toSave() { return (this.taskName + VERTICAL_BAR + binaryRes() + VERTICAL_BAR - + this.description + VERTICAL_BAR + this.date + "\n"); + + this.description + VERTICAL_BAR + printDate("yyyy-MM-dd") + "\n"); + } + + @Override + public String toString() { + return (this.taskType + this.getStatus() + " " + this.description + "\t(" + printDate("d MMM yyy") + ")"); + } + + @Override + public boolean isDateNull() { + return (this.date == null ? true : false); + } + + public String printDate(String date) { + return (this.date == null) ? this.dateString : this.date.format(DateTimeFormatter.ofPattern(date)); + } + public LocalDate getDate() { + return this.date; } } diff --git a/src/main/java/Arsdorint/task/Task.java b/src/main/java/Arsdorint/task/Task.java index 88b7aa78c..284d6ab13 100644 --- a/src/main/java/Arsdorint/task/Task.java +++ b/src/main/java/Arsdorint/task/Task.java @@ -1,13 +1,17 @@ package Arsdorint.task; +import java.time.LocalDate; + public class Task { // initial number of task must be set to 0 public static final String VERTICAL_BAR = " | "; + public static final String PARSE_LIMITER = "\\|"; public static int numOfTasks = 0; public String description; public boolean isDone; public String taskType = "[ ]"; public String taskName; + public LocalDate date; public Task(String description) { this.description = description; @@ -32,5 +36,15 @@ public int binaryRes() { public String toSave() { return (this.taskName + VERTICAL_BAR + binaryRes() + VERTICAL_BAR + this.description + "\n"); } + public boolean isDateNull() { + return true; + } + + public LocalDate getDate() { + return this.date; + } + public void setIsDone(boolean status) { + this.isDone = status; + } } diff --git a/src/main/java/Arsdorint/task/Todo.java b/src/main/java/Arsdorint/task/Todo.java index daed0706e..beb057691 100644 --- a/src/main/java/Arsdorint/task/Todo.java +++ b/src/main/java/Arsdorint/task/Todo.java @@ -7,4 +7,9 @@ public Todo(String description) { this.taskName = TYPE_TODO; this.taskType = "[T]"; } + + public Todo(boolean status, String description) { + this(description); + this.isDone = status; + } } From 5ae3f2e3090f3e27539704069027f6675ca303d6 Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam Date: Fri, 3 Mar 2023 17:43:05 +0700 Subject: [PATCH 22/45] More OOP finished --- src/main/java/Arsdorint/Arsdorint.java | 99 ------------------- src/main/java/Arsdorint/MessageList.java | 9 +- src/main/java/Arsdorint/UI/TextUI.java | 4 +- .../java/Arsdorint/command/CommandDate.java | 5 +- .../Arsdorint/command/CommandDeadline.java | 4 +- .../java/Arsdorint/command/CommandDelete.java | 6 +- .../java/Arsdorint/command/CommandEvent.java | 4 +- .../java/Arsdorint/command/CommandExit.java | 2 +- .../java/Arsdorint/command/CommandList.java | 6 +- .../java/Arsdorint/command/CommandMark.java | 7 +- .../java/Arsdorint/command/CommandRes.java | 8 +- .../java/Arsdorint/command/CommandToDo.java | 4 +- .../java/Arsdorint/command/CommandUnmark.java | 9 +- .../java/Arsdorint/command/CommandWrong.java | 6 +- src/main/java/Arsdorint/data/Message.java | 4 - src/main/java/Arsdorint/data/Storage.java | 13 +-- src/main/java/Arsdorint/data/TaskList.java | 10 +- .../java/Arsdorint/parser/TaskParser.java | 50 +++++----- storage/arsdorintTask.txt | 2 +- 19 files changed, 69 insertions(+), 183 deletions(-) delete mode 100644 src/main/java/Arsdorint/data/Message.java diff --git a/src/main/java/Arsdorint/Arsdorint.java b/src/main/java/Arsdorint/Arsdorint.java index 41787a6f3..d77c7b653 100644 --- a/src/main/java/Arsdorint/Arsdorint.java +++ b/src/main/java/Arsdorint/Arsdorint.java @@ -1,124 +1,25 @@ package Arsdorint; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileWriter; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Scanner; - import Arsdorint.UI.TextUI; import Arsdorint.command.*; import Arsdorint.data.Storage; -import Arsdorint.data.TaskList; import Arsdorint.parser.TaskParser; -import Arsdorint.task.Deadline; -import Arsdorint.task.Event; -import Arsdorint.task.Task; -import Arsdorint.task.Todo; - - -import static Arsdorint.MessageList.*; -import static Arsdorint.parser.TaskParser.showToUser; public class Arsdorint { - static Scanner input = new Scanner(System.in); public static String logo = " ___ _ _\n" + " / _ \\ _____ _____ ___| | ___ _____ _ _____ _| |_\n" + " / /_\\ \\ / ___| / __/ / _ | / _ \\ / ___| | | | _ \\ |_ _|\n" + " / _____ \\ | / __\\ \\ | |_| | | |_| | | / | | | | | | | |\n" + "/_/ \\_\\ |_| /____/ \\_____| \\___/ |_| |_| |_| |_| |_|\n"; - public static ArrayList toDoList = new ArrayList<>(MAX_NUM_OF_TASKS); - static boolean isRunning = true; private TextUI UI; - private TaskList taskList = new TaskList(); public void exit() { UI.showExitMessage(); UI.input.close(); System.exit(0); } - private static void wrongCommandMessage() { - System.out.println("=( OOPS!!! I'm sorry, but I don't know what that means :-(\n" + MESSAGE_DIVIDER); - } - - public static void list() { - showToUser(MESSAGE_DIVIDER_LIST); - for (int i = 0; i < Task.numOfTasks; i++) { - System.out.print((i + 1) + "."); - toDoList.get(i).printTask(); - } - showToUser(MESSAGE_DIVIDER); - } - - /*public static void add(String command) { - String newTaskType = command.split(" ")[0]; - String[] taskDescription = - command.replace(newTaskType, "").trim().split("/"); - switch (newTaskType.toLowerCase()) { - case "todo": - addToDo(taskDescription); - break; - case "deadline": - addDeadline(taskDescription); - break; - case "event": - addEvent(taskDescription); - break; - default: - break; - } - } - - private static void commandErrorHandler(String errorMessage) { - switch (errorMessage) { - case "bye": - showToUser(MESSAGE_DIVIDER, ERROR_MESSAGE_BYE, MESSAGE_DIVIDER); - break; - case "list": - showToUser(MESSAGE_DIVIDER, ERROR_MESSAGE_LIST, MESSAGE_DIVIDER); - break; - case "mark": - showToUser(MESSAGE_DIVIDER, ERROR_MESSAGE_MARK, MESSAGE_DIVIDER); - break; - case "unmark": - showToUser(MESSAGE_DIVIDER, ERROR_MESSAGE_UNMARK, MESSAGE_DIVIDER); - break; - case "todo": - showToUser(MESSAGE_DIVIDER, ERROR_MESSAGE_TODO, MESSAGE_DIVIDER); - break; - case "deadline": - showToUser(MESSAGE_DIVIDER, ERROR_MESSAGE_DEADLINE, MESSAGE_DIVIDER); - break; - case "event": - showToUser(MESSAGE_DIVIDER, ERROR_MESSAGE_EVENT, MESSAGE_DIVIDER); - break; - case "delete": - showToUser(MESSAGE_DIVIDER, ERROR_MESSAGE_DELETE, MESSAGE_DIVIDER); - break; - default: - showToUser(MESSAGE_DIVIDER, errorMessage, MESSAGE_DIVIDER); - break; - } - }*/ - - public static void addTaskMessage() { - showToUser(MESSAGE_DIVIDER); - System.out.println("\nGot it. I've added this task:\n" + "\t"); - toDoList.get(toDoList.size() - 1).printTask(); - System.out.println("\t" + "Now you have " + Integer.toString(Task.numOfTasks) + " tasks in the list."); - showToUser(MESSAGE_DIVIDER); - } - - public static void main(String[] args) { new Arsdorint().run(); - /*helloMessage(); - load(); - while (isRunning) { - command(); - }*/ } public void run() { diff --git a/src/main/java/Arsdorint/MessageList.java b/src/main/java/Arsdorint/MessageList.java index ba577e1c3..8041b92eb 100644 --- a/src/main/java/Arsdorint/MessageList.java +++ b/src/main/java/Arsdorint/MessageList.java @@ -1,23 +1,20 @@ package Arsdorint; public class MessageList { - public static final int MAX_NUM_OF_TASKS = 100; public static final String EXIT_MESSAGE = " Bye. Hope to see you again soon!\n"; public static final String HELLO_MESSAGE = " Hello! I'm Arsdorint, a member of Arsdorint Team.\n" + " Please Type The Command As Follow:\n"; public static final String COMMAND_LIST_MESSAGE = "> Type \"list\" to list all the tasks. \n" + - "> Type \"mark\" follow by a number x to mark x tasks in the list. \n" + - "> Type \"unmark\" follow by a number y to unmark y tasks in the list. \n" + + "> Type \"mark\" follow by a number x to mark tasks x in the list. \n" + + "> Type \"unmark\" follow by a number y to unmark tasks y in the list. \n" + "> Type \"todo\" follow by a string x to add a work that need to be done. \n" + "> Type \"deadline /x y\" with x is the type of work, y is the time or date of the deadline. \n" + "> Type \"event x /y\" with x is the event, y is the time or date of that event. \n" + + "> Type \"delete\" follow by a number z to delete task z in the the list. \n" + "> Type \"bye\" to exit. \n"; public static final String QUESTION = " What can I do for you?"; - - public static final String STORAGE_DIRECTORY = "./storage"; - public static final String STORAGE_FILE_NAME = "./storage/arsdorintTask.txt"; public static final String MESSAGE_NEW_FILE = "File created"; public static final String MESSAGE_OVERWRITE_FILE = "File overwritten"; public static final String MESSAGE_LOAD_FILE = "File loaded"; diff --git a/src/main/java/Arsdorint/UI/TextUI.java b/src/main/java/Arsdorint/UI/TextUI.java index 1222e7673..763c67713 100644 --- a/src/main/java/Arsdorint/UI/TextUI.java +++ b/src/main/java/Arsdorint/UI/TextUI.java @@ -2,7 +2,6 @@ import Arsdorint.MessageList; import Arsdorint.command.CommandRes; -import Arsdorint.data.Message; import java.io.PrintStream; import java.util.Scanner; @@ -58,7 +57,6 @@ public void showUnknownMessage() { } public void showHelloMessage() { System.out.println("Hello from\n" + logo); - //showToUser(MESSAGE_DIVIDER, HELLO_MESSAGE, COMMAND_LIST_MESSAGE, QUESTION, MESSAGE_DIVIDER); - this.showToUser(HELLO_MESSAGE); + showToUser(MESSAGE_DIVIDER, HELLO_MESSAGE, COMMAND_LIST_MESSAGE, QUESTION, MESSAGE_DIVIDER); } } diff --git a/src/main/java/Arsdorint/command/CommandDate.java b/src/main/java/Arsdorint/command/CommandDate.java index 89d4487b2..83b39c82c 100644 --- a/src/main/java/Arsdorint/command/CommandDate.java +++ b/src/main/java/Arsdorint/command/CommandDate.java @@ -1,6 +1,4 @@ package Arsdorint.command; - -import Arsdorint.MessageList; import Arsdorint.data.TaskList; import Arsdorint.task.Task; @@ -15,8 +13,7 @@ public CommandDate(LocalDate date) { this.date = date; } public static final String COMMAND_NAME = "delete"; - public static final String SYNTAX = "TODO"; - public static final String MESSAGE_TOP = "TODO"; + public static final String SYNTAX = "Syntax for date\n\t>>>date "; public LocalDate date; @Override diff --git a/src/main/java/Arsdorint/command/CommandDeadline.java b/src/main/java/Arsdorint/command/CommandDeadline.java index 1d0554910..2ddcfe686 100644 --- a/src/main/java/Arsdorint/command/CommandDeadline.java +++ b/src/main/java/Arsdorint/command/CommandDeadline.java @@ -14,8 +14,8 @@ public CommandDeadline(String description, String date) { } public static final String COMMAND_NAME = "deadline"; - public static final String SYNTAX = "TODO"; - public static final String MESSAGE_TOP = "TODO"; + public static final String SYNTAX = "Syntax for deadline\n\t>>> deadline / task = new ArrayList(); diff --git a/src/main/java/Arsdorint/command/CommandDelete.java b/src/main/java/Arsdorint/command/CommandDelete.java index 31498c8c4..ddbc9bccc 100644 --- a/src/main/java/Arsdorint/command/CommandDelete.java +++ b/src/main/java/Arsdorint/command/CommandDelete.java @@ -17,8 +17,8 @@ public CommandDelete(int...idx) { this.idx = idx; } public static final String COMMAND_NAME = "delete"; - public static final String SYNTAX = "TODO"; - public static final String MESSAGE_TOP = "TODO"; + public static final String SYNTAX = "Syntax for delete item \n\t>>> delete \n"; + public static final String MESSAGE_TOP = "\nGot it. I've deleted this task:\n" + "\t"; public int[] idx; @Override @@ -27,7 +27,7 @@ public CommandRes execute() { (i -> contains(idx, i)).mapToObj(i -> TaskList.list.get(i)).collect(Collectors.toList())); Arrays.sort(idx); for (int i = idx.length - MessageList.OFFSET; i > -MessageList.OFFSET; i--) { - TaskList.list.remove(idx[1]); + TaskList.list.remove(idx[i]); } return new CommandRes(MESSAGE_TOP, task, TaskList.getAllMessage()); } diff --git a/src/main/java/Arsdorint/command/CommandEvent.java b/src/main/java/Arsdorint/command/CommandEvent.java index 3af4561ff..cebbef32b 100644 --- a/src/main/java/Arsdorint/command/CommandEvent.java +++ b/src/main/java/Arsdorint/command/CommandEvent.java @@ -15,8 +15,8 @@ public CommandEvent(String description, String date) { } public static final String COMMAND_NAME = "event"; - public static final String SYNTAX = "TODO"; - public static final String MESSAGE_TOP = "TODO"; + public static final String SYNTAX = "Syntax for event\n\t>>> event / task = new ArrayList(); diff --git a/src/main/java/Arsdorint/command/CommandExit.java b/src/main/java/Arsdorint/command/CommandExit.java index 5732de412..85d631d5a 100644 --- a/src/main/java/Arsdorint/command/CommandExit.java +++ b/src/main/java/Arsdorint/command/CommandExit.java @@ -6,7 +6,7 @@ public CommandExit() { } public static final String COMMAND_NAME = "exit"; - public static final String MESSAGE_TOP = "Bye!"; + public static final String MESSAGE_TOP = " Bye. Hope to see you again soon!\n"; public static boolean isExit(Command command) { return command.commandType.equalsIgnoreCase("COMMAND_NAME"); } diff --git a/src/main/java/Arsdorint/command/CommandList.java b/src/main/java/Arsdorint/command/CommandList.java index 2f75ea7c1..2ccbefe62 100644 --- a/src/main/java/Arsdorint/command/CommandList.java +++ b/src/main/java/Arsdorint/command/CommandList.java @@ -3,16 +3,18 @@ import Arsdorint.MessageList; import Arsdorint.data.TaskList; +import static Arsdorint.MessageList.MESSAGE_DIVIDER_LIST; + public class CommandList extends Command { public CommandList() { super(COMMAND_NAME); } public static final String COMMAND_NAME = "list"; - public static final String SYNTAX = "TODO"; + public static final String SYNTAX = "Here's your task in the list: "; @Override public CommandRes execute() { - return new CommandRes(MessageList.MESSAGE_DIVIDER_LIST, TaskList.list, TaskList.getAllMessage()); + return new CommandRes(MESSAGE_DIVIDER_LIST, TaskList.list, TaskList.getAllMessage()); } } diff --git a/src/main/java/Arsdorint/command/CommandMark.java b/src/main/java/Arsdorint/command/CommandMark.java index 9087687cb..934cc830a 100644 --- a/src/main/java/Arsdorint/command/CommandMark.java +++ b/src/main/java/Arsdorint/command/CommandMark.java @@ -16,8 +16,9 @@ public CommandMark(int...idx) { } public static final String COMMAND_NAME = "mark"; - public static final String SYNTAX = "TODO"; - public static final String MESSAGE_TOP = "TODO"; + public static final String SYNTAX = "Syntax for mark\n\t" + + ">>> mark \n" + "Note: item index must exist in the current list"; + public static final String MESSAGE_TOP = "\nGot it. I've marked this task as done:\n" + "\t"; public int[] idx; @Override @@ -28,7 +29,7 @@ public CommandRes execute() { ArrayList task = new ArrayList(IntStream.range(0, TaskList.list.size()).filter (i -> contains(idx, i)).mapToObj(i -> TaskList.list.get(i)).collect(Collectors.toList())); - return new CommandRes(MESSAGE_TOP, task, TaskList.getAllMessage()); + return new CommandRes(MESSAGE_TOP, task, TaskList.getUnmarkedMessage()); } } diff --git a/src/main/java/Arsdorint/command/CommandRes.java b/src/main/java/Arsdorint/command/CommandRes.java index 37a2f5c55..9a59e35ce 100644 --- a/src/main/java/Arsdorint/command/CommandRes.java +++ b/src/main/java/Arsdorint/command/CommandRes.java @@ -20,18 +20,12 @@ public CommandRes(String strTop, ArrayList task, String strBottom) { this.task = task; } - public CommandRes() { - - } - public String[] printTask() { if (task == null) { return new String[]{}; } else if (messageTop.equals(MessageList.MESSAGE_DIVIDER_LIST)) { return IntStream.range(0, task.size()).mapToObj(i -> - { - return (i + MessageList.OFFSET + "." + task.get(i)).toString(); - }).toArray(String[]::new); + (i + MessageList.OFFSET + "." + task.get(i))).toArray(String[]::new); } else { return task.stream().map(Task::toString).toArray(String[]::new); } diff --git a/src/main/java/Arsdorint/command/CommandToDo.java b/src/main/java/Arsdorint/command/CommandToDo.java index 269295509..9870d58b6 100644 --- a/src/main/java/Arsdorint/command/CommandToDo.java +++ b/src/main/java/Arsdorint/command/CommandToDo.java @@ -14,8 +14,8 @@ public CommandToDo(String description) { } public static final String COMMAND_NAME = "todo"; - public static final String SYNTAX = "TODO"; - public static final String MESSAGE_TOP = "TODO"; + public static final String SYNTAX = "Syntax for todo\n\t>>> todo "; + public static final String MESSAGE_TOP = "\nGot it. I've added this task:\n" + "\t"; public String description; public ArrayList task = new ArrayList(); diff --git a/src/main/java/Arsdorint/command/CommandUnmark.java b/src/main/java/Arsdorint/command/CommandUnmark.java index e73d84cf0..ade865eb0 100644 --- a/src/main/java/Arsdorint/command/CommandUnmark.java +++ b/src/main/java/Arsdorint/command/CommandUnmark.java @@ -14,19 +14,20 @@ public CommandUnmark(int...idx) { } public static final String COMMAND_NAME = "unmark"; - public static final String SYNTAX = "TODO"; - public static final String MESSAGE_TOP = "TODO"; + public static final String SYNTAX = "Syntax for unmark\n\t" + + ">>> unmark \n" + "Note: item index must exist in the current list"; + public static final String MESSAGE_TOP = "\nGot it. I've marked this task as not done yet:\n" + "\t"; public int[] idx; @Override public CommandRes execute() { for (int i = 0; i < idx.length; i++) { - TaskList.list.get(idx[i]).setIsDone(true); + TaskList.list.get(idx[i]).setIsDone(false); } ArrayList task = new ArrayList(IntStream.range(0, TaskList.list.size()).filter (i -> contains(idx, i)).mapToObj(i -> TaskList.list.get(i)).collect(Collectors.toList())); - return new CommandRes(MESSAGE_TOP, task, TaskList.getAllMessage()); + return new CommandRes(MESSAGE_TOP, task, TaskList.getMarkedMessage()); } } diff --git a/src/main/java/Arsdorint/command/CommandWrong.java b/src/main/java/Arsdorint/command/CommandWrong.java index c209f4be6..6b9b7cfa8 100644 --- a/src/main/java/Arsdorint/command/CommandWrong.java +++ b/src/main/java/Arsdorint/command/CommandWrong.java @@ -1,5 +1,7 @@ package Arsdorint.command; +import static Arsdorint.MessageList.MESSAGE_DIVIDER; + public class CommandWrong extends Command { public CommandWrong(String message) { super(COMMAND_NAME); @@ -11,8 +13,8 @@ public CommandWrong(String top, String bottom) { this.bottom = bottom; } public static final String COMMAND_NAME = "wrong command"; - public String top; - public String bottom; + public String top = "=( OOPS!!! I'm sorry, but I don't know what that means :-(\n" + MESSAGE_DIVIDER; + public String bottom = "Error: Lack / Wrong description format of the command"; @Override public CommandRes execute() { diff --git a/src/main/java/Arsdorint/data/Message.java b/src/main/java/Arsdorint/data/Message.java deleted file mode 100644 index 98ac74232..000000000 --- a/src/main/java/Arsdorint/data/Message.java +++ /dev/null @@ -1,4 +0,0 @@ -package Arsdorint.data; - -public class Message { -} diff --git a/src/main/java/Arsdorint/data/Storage.java b/src/main/java/Arsdorint/data/Storage.java index c097cfa5d..79b49b850 100644 --- a/src/main/java/Arsdorint/data/Storage.java +++ b/src/main/java/Arsdorint/data/Storage.java @@ -2,7 +2,6 @@ import Arsdorint.command.ArsdorintFileException; import Arsdorint.parser.TaskParser; -import Arsdorint.task.Task; import java.io.File; import java.io.FileNotFoundException; @@ -10,33 +9,26 @@ import java.io.IOException; import java.util.Scanner; -import static Arsdorint.Arsdorint.*; import static Arsdorint.MessageList.*; import static Arsdorint.MessageList.MESSAGE_WRONG_FILE; -import static Arsdorint.parser.TaskParser.fileParser; -import static Arsdorint.parser.TaskParser.showToUser; public class Storage { public Storage() { - } public static final String STORAGE_DIRECTORY = "./storage"; public static final String STORAGE_FILE_NAME = "./storage/ArsdorintTask.txt"; public static String[] save() { try { FileWriter fileWriter = new FileWriter(STORAGE_FILE_NAME); - for (int i = 0; i < Task.numOfTasks; i++) { - fileWriter.write(toDoList.get(i).toSave()); + for (int i = 0; i < TaskList.list.size(); i++) { + fileWriter.write(TaskList.list.get(i).toSave()); } fileWriter.close(); return new String[]{MESSAGE_OVERWRITE_FILE}; } catch (IOException err) { File newFile = new File(STORAGE_DIRECTORY); newFile.mkdir(); - //showToUser(MESSAGE_NEW_FILE); save(); - /*} finally { - showToUser(MESSAGE_OVERWRITE_FILE);*/ return new String[]{MESSAGE_NO_FILE, MESSAGE_NEW_FILE}; } } @@ -44,7 +36,6 @@ public static String load() { try { File file = new File(STORAGE_FILE_NAME); Scanner fileRead = new Scanner(file); - showToUser(MESSAGE_LOAD_FILE); while (fileRead.hasNext()) { new TaskParser().fileParser(fileRead.nextLine()); } diff --git a/src/main/java/Arsdorint/data/TaskList.java b/src/main/java/Arsdorint/data/TaskList.java index faed9e978..6ff8abcb1 100644 --- a/src/main/java/Arsdorint/data/TaskList.java +++ b/src/main/java/Arsdorint/data/TaskList.java @@ -11,17 +11,17 @@ public TaskList() { public static ArrayList list = new ArrayList(MAX_NUM_OF_TASKS); public static String getAllMessage() { int count = TaskList.list.size(); - return "\t" + "Now you have " + count + printTasksOrTask(count) + " in the list."; + return "\t" + "Now you have " + count + " " + printTasksOrTask(count) + " in the list."; } public static String getMarkedMessage() { - int count = TaskList.list.size(); - return "\t" + "Now you have " + count + "marked" + printTasksOrTask(count) + " in the list."; + int count = (int) TaskList.list.stream().filter(i-> i.isDone).count(); + return "\t" + "Now you have " + count + " marked " + printTasksOrTask(count) + " in the list."; } public static String getUnmarkedMessage() { - int count = TaskList.list.size(); - return "\t" + "Now you have " + count + "unmarked" + printTasksOrTask(count) + " in the list."; + int count = (int) TaskList.list.stream().filter(i-> !i.isDone).count(); + return "\t" + "Now you have " + count + " unmarked " + printTasksOrTask(count) + " in the list."; } private static String printTasksOrTask(int num) { diff --git a/src/main/java/Arsdorint/parser/TaskParser.java b/src/main/java/Arsdorint/parser/TaskParser.java index 54d3066c7..1595104e2 100644 --- a/src/main/java/Arsdorint/parser/TaskParser.java +++ b/src/main/java/Arsdorint/parser/TaskParser.java @@ -53,9 +53,6 @@ else if (lowerCaseLine.equalsIgnoreCase("delete")) { return delete(arguments); } else if (lowerCaseLine.equalsIgnoreCase("date")) { return addDate(arguments); - /*} else if (lowerCaseLine.equalsIgnoreCase("save")) { - //save(); - return new CommandExit();*/ } else { return new CommandWrong(MESSAGE_UNKNOWN, COMMAND_LIST_MESSAGE); } @@ -70,19 +67,13 @@ public static void fileParser(String input) throws ArsdorintFileException { } switch (parsedLine[0]) { case Todo.TYPE_TODO: - toDoList.add(new Todo(parsedLine[2])); - toDoList.get(Task.numOfTasks - 1).isDone = Boolean.valueOf(parsedLine[1]); - addTaskMessage(); + todoParser(parsedTrim); break; case Deadline.TYPE_DEADLINE: - toDoList.add(new Deadline(parsedLine[2], parsedLine[3])); - toDoList.get(Task.numOfTasks - 1).isDone = Boolean.valueOf(parsedLine[1]); - addTaskMessage(); + deadlineParser(parsedTrim); break; case Event.TYPE_EVENT: - toDoList.add(new Event(parsedLine[2], parsedLine[3])); - toDoList.get(Task.numOfTasks - 1).isDone = Boolean.valueOf(parsedLine[1]); - addTaskMessage(); + eventParser(parsedTrim); break; default: throw new ArsdorintFileException(); @@ -107,26 +98,18 @@ public Command unmark(String command) { if (parsed.length < 1) { throw new ArsdorintException(); //System.out.println("OK, I've marked this task as not done yet: \n"); - } return new CommandMark(strToIntArr(parsed)); + } return new CommandUnmark(strToIntArr(parsed)); } catch (NumberFormatException | IndexOutOfBoundsException | ArsdorintException err) { return new CommandWrong(CommandUnmark.SYNTAX); } } - public static void removeTaskMessage(int idx) { - showToUser(MESSAGE_DIVIDER); - System.out.println("\t"); - toDoList.get(idx).printTask(); - System.out.println("\t" + "Now you have " + --Task.numOfTasks + " tasks in the list."); - showToUser(MESSAGE_DIVIDER); - } - public Command delete(String command) { try { String[] parsed = command.split(" "); if (parsed.length < 1) { throw new ArsdorintException(); - } return new CommandMark(strToIntArr(parsed)); + } return new CommandDelete(strToIntArr(parsed)); } catch (NumberFormatException | IndexOutOfBoundsException | ArsdorintException err) { return new CommandWrong(CommandDelete.SYNTAX); } @@ -185,6 +168,29 @@ public static void showToUser(String... message) { for (String i : message) System.out.println(i); } + private static void todoParser(String[] parsed) throws ArsdorintFileException { + + if (!(parsed.length == 3)) { + throw new ArsdorintFileException(); + } + TaskList.list.add(new Todo(Boolean.valueOf(parsed[1]), parsed[2])); + } + + private static void deadlineParser(String[] parsed) throws ArsdorintFileException { + if (!(parsed.length == 4)) { + throw new ArsdorintFileException(); + } + TaskList.list.add(new Deadline(Boolean.valueOf(parsed[1]), parsed[2], parsed[3])); + } + + private static void eventParser(String[] parsed) throws ArsdorintFileException { + if (!(parsed.length == 4)) { + throw new ArsdorintFileException(); + } + TaskList.list.add(new Event(Boolean.valueOf(parsed[1]), parsed[2], parsed[3])); + } + + private int[] strToIntArr(String[] parsed) throws ArsdorintException { int[] intArr = new int[parsed.length]; for (int i = 0; i < parsed.length; i++) { diff --git a/storage/arsdorintTask.txt b/storage/arsdorintTask.txt index 8b1378917..0de25e379 100644 --- a/storage/arsdorintTask.txt +++ b/storage/arsdorintTask.txt @@ -1 +1 @@ - +T | 0 | x From df7486e94517d974c51532e3a56dc91bec768703 Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam Date: Fri, 3 Mar 2023 17:45:01 +0700 Subject: [PATCH 23/45] Update arsdorintTask.txt --- storage/arsdorintTask.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/storage/arsdorintTask.txt b/storage/arsdorintTask.txt index 8b1378917..e69de29bb 100644 --- a/storage/arsdorintTask.txt +++ b/storage/arsdorintTask.txt @@ -1 +0,0 @@ - From 3f725330e64677e4b22cc1de492b77e1e7e162af Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam Date: Fri, 3 Mar 2023 17:45:38 +0700 Subject: [PATCH 24/45] Update arsdorintTask.txt --- storage/arsdorintTask.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/storage/arsdorintTask.txt b/storage/arsdorintTask.txt index e69de29bb..0de25e379 100644 --- a/storage/arsdorintTask.txt +++ b/storage/arsdorintTask.txt @@ -0,0 +1 @@ +T | 0 | x From 5659184a1225e11727729450ccee4872d14d69ba Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam Date: Fri, 3 Mar 2023 20:02:41 +0700 Subject: [PATCH 25/45] Level-8 finished --- src/main/java/Arsdorint/MessageList.java | 3 ++- src/main/java/Arsdorint/UI/TextUI.java | 6 +++--- src/main/java/Arsdorint/command/CommandDate.java | 2 +- src/main/java/Arsdorint/command/CommandEvent.java | 1 - src/main/java/Arsdorint/parser/TaskParser.java | 9 --------- src/main/java/Arsdorint/task/Deadline.java | 8 ++------ src/main/java/Arsdorint/task/Event.java | 4 ---- src/main/java/Arsdorint/task/Task.java | 7 ++++--- storage/arsdorintTask.txt | 3 ++- 9 files changed, 14 insertions(+), 29 deletions(-) diff --git a/src/main/java/Arsdorint/MessageList.java b/src/main/java/Arsdorint/MessageList.java index 8041b92eb..1d8129645 100644 --- a/src/main/java/Arsdorint/MessageList.java +++ b/src/main/java/Arsdorint/MessageList.java @@ -10,8 +10,9 @@ public class MessageList { "> Type \"mark\" follow by a number x to mark tasks x in the list. \n" + "> Type \"unmark\" follow by a number y to unmark tasks y in the list. \n" + "> Type \"todo\" follow by a string x to add a work that need to be done. \n" + - "> Type \"deadline /x y\" with x is the type of work, y is the time or date of the deadline. \n" + + "> Type \"deadline x /y\" with x is the type of work, y is the time or date of the deadline. \n" + "> Type \"event x /y\" with x is the event, y is the time or date of that event. \n" + + "> Type \"date YYYY-MM-DD\" to know how many tasks occurs in day DD, month MM, year YYYY. \n" + "> Type \"delete\" follow by a number z to delete task z in the the list. \n" + "> Type \"bye\" to exit. \n"; public static final String QUESTION = " What can I do for you?"; diff --git a/src/main/java/Arsdorint/UI/TextUI.java b/src/main/java/Arsdorint/UI/TextUI.java index 763c67713..6b18cce64 100644 --- a/src/main/java/Arsdorint/UI/TextUI.java +++ b/src/main/java/Arsdorint/UI/TextUI.java @@ -32,9 +32,9 @@ public boolean shouldIgnore(String input) { return input.trim().isEmpty(); } - public void showToUser(String...messages) { + public static void showToUser(String... messages) { for (String m : messages) { - output.println(m); + System.out.println(m); } } @@ -47,7 +47,7 @@ public void showResToUser(CommandRes res) { } public void showExitMessage() { - this.showToUser(MessageList.EXIT_MESSAGE); + showToUser(MESSAGE_DIVIDER, EXIT_MESSAGE, MESSAGE_DIVIDER); } public void showUnknownMessage() { diff --git a/src/main/java/Arsdorint/command/CommandDate.java b/src/main/java/Arsdorint/command/CommandDate.java index 83b39c82c..dc86faca3 100644 --- a/src/main/java/Arsdorint/command/CommandDate.java +++ b/src/main/java/Arsdorint/command/CommandDate.java @@ -18,7 +18,7 @@ public CommandDate(LocalDate date) { @Override public CommandRes execute() { - ArrayList task = new ArrayList(TaskList.list.stream().filter(i -> !i.isDateNull()).filter + ArrayList task = new ArrayList<>(TaskList.list.stream().filter(i -> !i.isDateNull()).filter (i -> i.getDate().equals(this.date)).collect(Collectors.toList())); long count = task.stream().count(); String messageTop = count + " tasks happen on this date"; diff --git a/src/main/java/Arsdorint/command/CommandEvent.java b/src/main/java/Arsdorint/command/CommandEvent.java index cebbef32b..be3fde2db 100644 --- a/src/main/java/Arsdorint/command/CommandEvent.java +++ b/src/main/java/Arsdorint/command/CommandEvent.java @@ -1,7 +1,6 @@ package Arsdorint.command; import Arsdorint.data.TaskList; -import Arsdorint.task.Deadline; import Arsdorint.task.Event; import Arsdorint.task.Task; diff --git a/src/main/java/Arsdorint/parser/TaskParser.java b/src/main/java/Arsdorint/parser/TaskParser.java index 1595104e2..080f9fae5 100644 --- a/src/main/java/Arsdorint/parser/TaskParser.java +++ b/src/main/java/Arsdorint/parser/TaskParser.java @@ -159,15 +159,6 @@ public Command addDate(String taskDescription) { } } - - private static void exitMessage() { - showToUser(MESSAGE_DIVIDER, EXIT_MESSAGE, MESSAGE_DIVIDER); - } - - public static void showToUser(String... message) { - for (String i : message) System.out.println(i); - } - private static void todoParser(String[] parsed) throws ArsdorintFileException { if (!(parsed.length == 3)) { diff --git a/src/main/java/Arsdorint/task/Deadline.java b/src/main/java/Arsdorint/task/Deadline.java index 233cafbba..28d3cb993 100644 --- a/src/main/java/Arsdorint/task/Deadline.java +++ b/src/main/java/Arsdorint/task/Deadline.java @@ -24,10 +24,6 @@ public Deadline(boolean status, String description, String date) { this(description, date); this.isDone = status; } - public void printTask() { - System.out.println(this.taskType + this.getStatus() - + " " + this.description + "(" + this.date + ")"); - } @Override public String toSave() { return (this.taskName + VERTICAL_BAR + binaryRes() + VERTICAL_BAR + @@ -44,8 +40,8 @@ public boolean isDateNull() { return (this.date == null ? true : false); } - public String printDate(String date) { - return (this.date == null) ? this.dateString : this.date.format(DateTimeFormatter.ofPattern(date)); + public String printDate(String pattern) { + return (this.date == null) ? this.dateString : this.date.format(DateTimeFormatter.ofPattern(pattern)); } public LocalDate getDate() { return this.date; diff --git a/src/main/java/Arsdorint/task/Event.java b/src/main/java/Arsdorint/task/Event.java index 6da519881..9da40ef56 100644 --- a/src/main/java/Arsdorint/task/Event.java +++ b/src/main/java/Arsdorint/task/Event.java @@ -25,10 +25,6 @@ public Event(boolean status, String description, String date) { this.isDone = status; } - public void printTask() { - System.out.println(this.taskType + this.getStatus() - + " " + this.description + "(" + this.date + ")"); - } @Override public String toSave() { return (this.taskName + VERTICAL_BAR + binaryRes() + VERTICAL_BAR diff --git a/src/main/java/Arsdorint/task/Task.java b/src/main/java/Arsdorint/task/Task.java index 284d6ab13..d41150c9b 100644 --- a/src/main/java/Arsdorint/task/Task.java +++ b/src/main/java/Arsdorint/task/Task.java @@ -27,15 +27,15 @@ public String toString() { public String getStatus() { return (isDone) ? "[X]" : "[ ]"; } - public void printTask() { - System.out.println(this.toString()); - } + public int binaryRes() { return (isDone) ? 1 : 0; } + public String toSave() { return (this.taskName + VERTICAL_BAR + binaryRes() + VERTICAL_BAR + this.description + "\n"); } + public boolean isDateNull() { return true; } @@ -43,6 +43,7 @@ public boolean isDateNull() { public LocalDate getDate() { return this.date; } + public void setIsDone(boolean status) { this.isDone = status; } diff --git a/storage/arsdorintTask.txt b/storage/arsdorintTask.txt index 0de25e379..add02bed5 100644 --- a/storage/arsdorintTask.txt +++ b/storage/arsdorintTask.txt @@ -1 +1,2 @@ -T | 0 | x +T | 0 | l +D | 1 | | x From bf5ae963733861299ab7c97cf8963b80623ff09b Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam Date: Fri, 3 Mar 2023 20:04:41 +0700 Subject: [PATCH 26/45] Update arsdorintTask.txt --- storage/arsdorintTask.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/storage/arsdorintTask.txt b/storage/arsdorintTask.txt index 0de25e379..add02bed5 100644 --- a/storage/arsdorintTask.txt +++ b/storage/arsdorintTask.txt @@ -1 +1,2 @@ -T | 0 | x +T | 0 | l +D | 1 | | x From 2f9a1f4eeb770d554a6ecb7cdbeac9ccd7f15907 Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam Date: Fri, 3 Mar 2023 21:04:43 +0700 Subject: [PATCH 27/45] Level-9 completed (Added find) --- src/main/java/Arsdorint/Arsdorint.java | 2 +- .../java/Arsdorint/command/CommandDate.java | 3 +- .../java/Arsdorint/command/CommandFind.java | 33 +++++++++++++++++++ src/main/java/Arsdorint/data/Storage.java | 2 +- src/main/java/Arsdorint/data/TaskList.java | 2 +- .../java/Arsdorint/parser/TaskParser.java | 14 ++++++++ storage/arsdorintTask.txt | 5 +-- 7 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 src/main/java/Arsdorint/command/CommandFind.java diff --git a/src/main/java/Arsdorint/Arsdorint.java b/src/main/java/Arsdorint/Arsdorint.java index d77c7b653..f3dddb41a 100644 --- a/src/main/java/Arsdorint/Arsdorint.java +++ b/src/main/java/Arsdorint/Arsdorint.java @@ -41,7 +41,7 @@ private void mainLoop() { command = new TaskParser().parsedCommand(userCommandText); CommandRes res = executeCommand(command); UI.showResToUser(res); - UI.showToUser(Storage.save()); + Storage.save(); } while (!CommandExit.isExit(command)); } private CommandRes executeCommand(Command command) { diff --git a/src/main/java/Arsdorint/command/CommandDate.java b/src/main/java/Arsdorint/command/CommandDate.java index dc86faca3..25a55b529 100644 --- a/src/main/java/Arsdorint/command/CommandDate.java +++ b/src/main/java/Arsdorint/command/CommandDate.java @@ -14,6 +14,7 @@ public CommandDate(LocalDate date) { } public static final String COMMAND_NAME = "delete"; public static final String SYNTAX = "Syntax for date\n\t>>>date "; + public static final String TOP_MESSAGE = "Tasks occurs on this date"; public LocalDate date; @Override @@ -22,7 +23,7 @@ public CommandRes execute() { (i -> i.getDate().equals(this.date)).collect(Collectors.toList())); long count = task.stream().count(); String messageTop = count + " tasks happen on this date"; - return new CommandRes(messageTop, task, ""); + return new CommandRes(TOP_MESSAGE, task, ""); } } diff --git a/src/main/java/Arsdorint/command/CommandFind.java b/src/main/java/Arsdorint/command/CommandFind.java new file mode 100644 index 000000000..85bcc750c --- /dev/null +++ b/src/main/java/Arsdorint/command/CommandFind.java @@ -0,0 +1,33 @@ +package Arsdorint.command; + +import Arsdorint.data.TaskList; +import Arsdorint.task.Task; + +import java.util.ArrayList; +import java.util.stream.Collectors; + +public class CommandFind extends Command { + + public CommandFind(String key) { + super(COMMAND_NAME); + this.key = key; + } + public static final String COMMAND_NAME = "find"; + public static final String SYNTAX = "Find syntax\n\t>>>find "; + public String key; + + @Override + public CommandRes execute() { + ArrayList task = new ArrayList<>(TaskList.list.stream().filter(i -> i.description + .equals(this.key)).collect(Collectors.toList())); + int count = (int) task.stream().count(); + String messageTop; + if (count != 0) { + messageTop = "Here are the matching tasks in your list, with " + + count + " " + TaskList.printTasksOrTask(count) + " as followed:"; + } else { + messageTop = "There are no tasks matching your search"; + } + return new CommandRes(messageTop, task, ""); + } +} diff --git a/src/main/java/Arsdorint/data/Storage.java b/src/main/java/Arsdorint/data/Storage.java index 79b49b850..ddcc29081 100644 --- a/src/main/java/Arsdorint/data/Storage.java +++ b/src/main/java/Arsdorint/data/Storage.java @@ -16,7 +16,7 @@ public class Storage { public Storage() { } public static final String STORAGE_DIRECTORY = "./storage"; - public static final String STORAGE_FILE_NAME = "./storage/ArsdorintTask.txt"; + public static final String STORAGE_FILE_NAME = "./storage/arsdorintTask.txt"; public static String[] save() { try { FileWriter fileWriter = new FileWriter(STORAGE_FILE_NAME); diff --git a/src/main/java/Arsdorint/data/TaskList.java b/src/main/java/Arsdorint/data/TaskList.java index 6ff8abcb1..00c40042c 100644 --- a/src/main/java/Arsdorint/data/TaskList.java +++ b/src/main/java/Arsdorint/data/TaskList.java @@ -24,7 +24,7 @@ public static String getUnmarkedMessage() { return "\t" + "Now you have " + count + " unmarked " + printTasksOrTask(count) + " in the list."; } - private static String printTasksOrTask(int num) { + public static String printTasksOrTask(int num) { return ((num == 1) ? "task" : "tasks"); } } diff --git a/src/main/java/Arsdorint/parser/TaskParser.java b/src/main/java/Arsdorint/parser/TaskParser.java index 080f9fae5..eea5e5d4e 100644 --- a/src/main/java/Arsdorint/parser/TaskParser.java +++ b/src/main/java/Arsdorint/parser/TaskParser.java @@ -48,6 +48,9 @@ else if (lowerCaseLine.equalsIgnoreCase("deadline")) { else if (lowerCaseLine.equalsIgnoreCase("event")) { return addEvent(arguments); } + else if (lowerCaseLine.equalsIgnoreCase("find")) { + return addFind(arguments); + } //add command when user don't type the instruction's Arsdorint.command else if (lowerCaseLine.equalsIgnoreCase("delete")) { return delete(arguments); @@ -159,6 +162,17 @@ public Command addDate(String taskDescription) { } } + public Command addFind(String taskDescription) { + try { + if (taskDescription.equals("")) { + throw new ArsdorintException(); + } + return new CommandFind(taskDescription); + } catch (ArsdorintException err) { + return new CommandWrong(CommandFind.SYNTAX); + } + } + private static void todoParser(String[] parsed) throws ArsdorintFileException { if (!(parsed.length == 3)) { diff --git a/storage/arsdorintTask.txt b/storage/arsdorintTask.txt index add02bed5..d6b31f64b 100644 --- a/storage/arsdorintTask.txt +++ b/storage/arsdorintTask.txt @@ -1,2 +1,3 @@ -T | 0 | l -D | 1 | | x +T | 0 | x +T | 0 | y +T | 0 | x From 763996e651328d503286a022acc00f56ba524c0a Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam Date: Fri, 3 Mar 2023 21:05:58 +0700 Subject: [PATCH 28/45] Update arsdorintTask.txt --- storage/arsdorintTask.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/storage/arsdorintTask.txt b/storage/arsdorintTask.txt index add02bed5..d6b31f64b 100644 --- a/storage/arsdorintTask.txt +++ b/storage/arsdorintTask.txt @@ -1,2 +1,3 @@ -T | 0 | l -D | 1 | | x +T | 0 | x +T | 0 | y +T | 0 | x From 44c9c3e7a222817323a336818ad91932c6a099ba Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam Date: Fri, 3 Mar 2023 21:40:43 +0700 Subject: [PATCH 29/45] Javadoc Added --- src/main/java/Arsdorint/Arsdorint.java | 28 ++++++++++++++++++- src/main/java/Arsdorint/UI/TextUI.java | 16 +++++++++++ .../Arsdorint/command/ArsdorintException.java | 3 ++ .../command/ArsdorintFileException.java | 3 ++ src/main/java/Arsdorint/command/Command.java | 9 ++++++ src/main/java/Arsdorint/data/Storage.java | 2 +- src/main/java/Arsdorint/data/TaskList.java | 1 + .../java/Arsdorint/parser/TaskParser.java | 19 ++++++++++++- 8 files changed, 78 insertions(+), 3 deletions(-) diff --git a/src/main/java/Arsdorint/Arsdorint.java b/src/main/java/Arsdorint/Arsdorint.java index f3dddb41a..2467e908f 100644 --- a/src/main/java/Arsdorint/Arsdorint.java +++ b/src/main/java/Arsdorint/Arsdorint.java @@ -2,8 +2,13 @@ import Arsdorint.UI.TextUI; import Arsdorint.command.*; import Arsdorint.data.Storage; +import Arsdorint.data.TaskList; import Arsdorint.parser.TaskParser; +/** + * Start of Arsdorint application + * Initializes the application and interact with the users + */ public class Arsdorint { public static String logo = " ___ _ _\n" + " / _ \\ _____ _____ ___| | ___ _____ _ _____ _| |_\n" @@ -12,6 +17,12 @@ public class Arsdorint { + "/_/ \\_\\ |_| /____/ \\_____| \\___/ |_| |_| |_| |_| |_|\n"; private TextUI UI; + private Storage storage; + private TaskList taskList; + + /** + * Print exit message and exits + */ public void exit() { UI.showExitMessage(); UI.input.close(); @@ -22,28 +33,43 @@ public static void main(String[] args) { new Arsdorint().run(); } + /** + * Run the program until termination / exit + */ public void run() { start(); mainLoop(); exit(); } + + /** + * Setup the required objects, print hello message + */ private void start() { this.UI = new TextUI(); UI.showHelloMessage(); UI.showToUser(Storage.load()); } + + /** + * Read user command and execute until exit command is detected + */ private void mainLoop() { Command command; do { String userCommandText = UI.getUserCommand(); - command = new TaskParser().parsedCommand(userCommandText); + command = new TaskParser(taskList).parsedCommand(userCommandText); CommandRes res = executeCommand(command); UI.showResToUser(res); Storage.save(); } while (!CommandExit.isExit(command)); } + + /** + * Execute the command + */ private CommandRes executeCommand(Command command) { return command.execute(); } diff --git a/src/main/java/Arsdorint/UI/TextUI.java b/src/main/java/Arsdorint/UI/TextUI.java index 6b18cce64..090b75a6b 100644 --- a/src/main/java/Arsdorint/UI/TextUI.java +++ b/src/main/java/Arsdorint/UI/TextUI.java @@ -19,6 +19,9 @@ public TextUI() { this.output = System.out; } + /** + * Get user command and filter blank lines + */ public String getUserCommand() { output.print(UI_PROMPT); String userInput = input.nextLine(); @@ -28,16 +31,29 @@ public String getUserCommand() { return userInput; } + /** + * Ignore if there is an empty line + */ public boolean shouldIgnore(String input) { return input.trim().isEmpty(); } + /** + * Display multiple messages, separated by newline + * + * @param messages String array of message need to be displayed. + */ public static void showToUser(String... messages) { for (String m : messages) { System.out.println(m); } } + /** + * Show the message and the tasks affected by the command + * + * @param res Result of a command + */ public void showResToUser(CommandRes res) { output.println(MessageList.MESSAGE_DIVIDER); showToUser(res.messageTop); diff --git a/src/main/java/Arsdorint/command/ArsdorintException.java b/src/main/java/Arsdorint/command/ArsdorintException.java index 68747d73d..c5f289217 100644 --- a/src/main/java/Arsdorint/command/ArsdorintException.java +++ b/src/main/java/Arsdorint/command/ArsdorintException.java @@ -1,5 +1,8 @@ package Arsdorint.command; +/** + * Represent Arsdorint Exception + */ public class ArsdorintException extends Exception { public ArsdorintException(String message) { super(message); diff --git a/src/main/java/Arsdorint/command/ArsdorintFileException.java b/src/main/java/Arsdorint/command/ArsdorintFileException.java index c9c61a4fa..997763c7f 100644 --- a/src/main/java/Arsdorint/command/ArsdorintFileException.java +++ b/src/main/java/Arsdorint/command/ArsdorintFileException.java @@ -1,5 +1,8 @@ package Arsdorint.command; +/** + * Represent Arsdorint Exception in files + */ public class ArsdorintFileException extends ArsdorintException { public ArsdorintFileException() { } diff --git a/src/main/java/Arsdorint/command/Command.java b/src/main/java/Arsdorint/command/Command.java index 00c5320ca..c55bd68f8 100644 --- a/src/main/java/Arsdorint/command/Command.java +++ b/src/main/java/Arsdorint/command/Command.java @@ -1,14 +1,23 @@ package Arsdorint.command; +/** + * The parent class Command + */ public class Command { public String commandType; protected Command(String commandType) { this.commandType = commandType; } + /** + * Execution of the command + */ public CommandRes execute() { throw new UnsupportedOperationException("Child classes' method"); } + /** + * Check if the key is contained in the index of the tasks + */ public boolean contains(final int[] arr, final int key) { for (final int i : arr) { if (i == key) { diff --git a/src/main/java/Arsdorint/data/Storage.java b/src/main/java/Arsdorint/data/Storage.java index ddcc29081..6dd8e8781 100644 --- a/src/main/java/Arsdorint/data/Storage.java +++ b/src/main/java/Arsdorint/data/Storage.java @@ -37,7 +37,7 @@ public static String load() { File file = new File(STORAGE_FILE_NAME); Scanner fileRead = new Scanner(file); while (fileRead.hasNext()) { - new TaskParser().fileParser(fileRead.nextLine()); + new TaskParser(new TaskList()).fileParser(fileRead.nextLine()); } fileRead.close(); return MESSAGE_LOAD_FILE; diff --git a/src/main/java/Arsdorint/data/TaskList.java b/src/main/java/Arsdorint/data/TaskList.java index 00c40042c..c4f9c2f0a 100644 --- a/src/main/java/Arsdorint/data/TaskList.java +++ b/src/main/java/Arsdorint/data/TaskList.java @@ -4,6 +4,7 @@ import java.util.ArrayList; +/* Represent the TaskList, and some functions to deal with messages */ public class TaskList { public TaskList() { } diff --git a/src/main/java/Arsdorint/parser/TaskParser.java b/src/main/java/Arsdorint/parser/TaskParser.java index eea5e5d4e..9ad2f8b8d 100644 --- a/src/main/java/Arsdorint/parser/TaskParser.java +++ b/src/main/java/Arsdorint/parser/TaskParser.java @@ -16,9 +16,26 @@ import static Arsdorint.MessageList.MESSAGE_DIVIDER; import static Arsdorint.data.Storage.save; +/** + * A class that handle the parsing of command + */ + public class TaskParser { - public TaskParser() { + private TaskList taskList; + + /** + * Parser instance take in the taskList to be manipulated + */ + public TaskParser(TaskList taskList) { + this.taskList = taskList; } + + /** + * Parse user input string + * + * @param input The user input string + * @return Command and its arguments + */ public Command parsedCommand(String input) { String[] command = input.split(" "); if (command.length == 0) { From 3693dbf543a88ddde6c1a1996db7b4b6541a0cd2 Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam Date: Fri, 3 Mar 2023 21:41:50 +0700 Subject: [PATCH 30/45] Update arsdorintTask.txt --- storage/arsdorintTask.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/storage/arsdorintTask.txt b/storage/arsdorintTask.txt index d6b31f64b..2d00ddd7a 100644 --- a/storage/arsdorintTask.txt +++ b/storage/arsdorintTask.txt @@ -1,3 +1,4 @@ -T | 0 | x -T | 0 | y -T | 0 | x +T | 1 | list +D | 1 | x | y +D | 0 | abc | z +T | 1 | x From 7ae60d96e51a46a57162a64d8006b4e92fabb9aa Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam Date: Fri, 3 Mar 2023 21:42:38 +0700 Subject: [PATCH 31/45] Create arsdorintTask.txt --- storage/arsdorintTask.txt | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 storage/arsdorintTask.txt diff --git a/storage/arsdorintTask.txt b/storage/arsdorintTask.txt new file mode 100644 index 000000000..2d00ddd7a --- /dev/null +++ b/storage/arsdorintTask.txt @@ -0,0 +1,4 @@ +T | 1 | list +D | 1 | x | y +D | 0 | abc | z +T | 1 | x From 8562de4bff274435a952b88cf31e51f0d6d98b55 Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam <88639992+arsdorintbp2003@users.noreply.github.com> Date: Fri, 3 Mar 2023 22:13:19 +0700 Subject: [PATCH 32/45] Update README.md A-Userguide --- README.md | 63 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 8715d4d91..43ad7aae3 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,58 @@ -# Duke project template +# Arsdorint chatbot -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 Arsdorint chatbot, a member of Arsdorint Team, and an adaptation application of CS2113 Project Duke) -## Setting up in Intellij +## User Guide -Prerequisites: JDK 11, update Intellij to the most recent version. +1. To download the application, click on this link. +2. The chatbot contains the following feature + + List + + Todo + + Deadline + + Event + + Mark + + Unmark + + Date + + Find + + Bye -1. Open Intellij (if you are not in the welcome screen, click `File` > `Close Project` to close the existing project first) -1. Open the project into Intellij as follows: - 1. Click `Open`. - 1. Select the project directory, and click `OK`. - 1. If there are any further prompts, accept the defaults. -1. Configure the project to use **JDK 11** (not other versions) as explained in [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk).
- In the same dialog, set the **Project language level** field to the `SDK default` option. -3. After that, locate the `src/main/java/Duke.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: +## Feature - List +- This function will list all the tasks inputed by the user. +- Example: + +## Feature - Todo +- This function will add a task that the user want to do, with a tickbox to mark if the task is done yet or not. +- Example: + +## Feature - Deadline +- This function will add a deadline that the user need to complete, with a tickbox to mark if the deadline is finished or not. +- Example: + +## Feature - Event +- This function will add an event that the user need to attend, with a tickbox to mark if the user have attended or not. +- Example: + +## Feature - Mark +- This function will mark a task as done by tick a "X" into the tickbox. +- Example: + +## Feature - Unmark +- This function will mark a task as not done yet by leaving the tickbox empty. +- Example: + +## Feature - Date +- This function will find if a date is in the task list yet. The date should be in the format of YYYY-MM-DD with YYYY is the year, MM is the month and DD is the day. +- Example + +## Feature - Find +- This function will find if the task the user want to search is in the list yet, and list all task with that name +- Example: + +## Feature - Bye + - This function will help the chatbot to say bye to the user, and end up the conversation. + - Example: + +### That's all about Arsdorint chatbot! Hope you enjoy our product, and leave some comments to help us improve the chatbot! Thank you so much! ``` Hello from ____ _ From f3914b71b6a40cc4f1c68459900924ce2d01c27e Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam <88639992+arsdorintbp2003@users.noreply.github.com> Date: Fri, 3 Mar 2023 22:48:19 +0700 Subject: [PATCH 33/45] Update README.md --- README.md | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 93 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 43ad7aae3..1a4b1ecb1 100644 --- a/README.md +++ b/README.md @@ -19,45 +19,132 @@ This is Arsdorint chatbot, a member of Arsdorint Team, and an adaptation applica ## Feature - List - This function will list all the tasks inputed by the user. - Example: +>>> list +Here are the tasks in your list: + +____________________________________________________________ +____________________________LIST____________________________ +1.[T][ ] midterm + Now you have 1 task in the list. +____________________________________________________________ + ## Feature - Todo - This function will add a task that the user want to do, with a tickbox to mark if the task is done yet or not. - Example: +>>> todo midterm +____________________________________________________________ + +Got it. I've added this task: + +[T][ ] midterm + Now you have 1 task in the list. +____________________________________________________________ + ## Feature - Deadline - This function will add a deadline that the user need to complete, with a tickbox to mark if the deadline is finished or not. - Example: +>>> deadline midterm /by tommorrow +____________________________________________________________ + +Got it. I've added this task: + +[D][ ] midterm (by tommorrow) + Now you have 2 tasks in the list. +____________________________________________________________ + +or +>>> deadline midterm /2023-03-04 +____________________________________________________________ + +Got it. I've added this task: + +[D][ ] midterm (4 Mar 2023) + Now you have 4 tasks in the list. +____________________________________________________________ ## Feature - Event - This function will add an event that the user need to attend, with a tickbox to mark if the user have attended or not. - Example: +>>> event Open House /on Sunday +____________________________________________________________ + +Got it. I've added this task: + +[E][ ] Open House (on Sunday) + Now you have 5 tasks in the list. +____________________________________________________________ + +or +>>> event NUS football match /2023-03-05 +____________________________________________________________ + +Got it. I've added this task: + +[E][ ] NUS football match (5 Mar 2023) + Now you have 6 tasks in the list. +____________________________________________________________ ## Feature - Mark - This function will mark a task as done by tick a "X" into the tickbox. - Example: +>>> mark 2 +____________________________________________________________ + +Got it. I've marked this task as done: + +[D][X] midterm (by tommorrow) + Now you have 5 unmarked tasks in the list. +____________________________________________________________ ## Feature - Unmark - This function will mark a task as not done yet by leaving the tickbox empty. - Example: +>>> unmark 2 +____________________________________________________________ + +Got it. I've marked this task as not done yet: + +[D][ ] midterm (by tommorrow) + Now you have 0 marked tasks in the list. +____________________________________________________________ ## Feature - Date - This function will find if a date is in the task list yet. The date should be in the format of YYYY-MM-DD with YYYY is the year, MM is the month and DD is the day. -- Example +- Example: +>>> date /2023-03-04 +____________________________________________________________ +1 task happen on this date +____________________________________________________________ ## Feature - Find - This function will find if the task the user want to search is in the list yet, and list all task with that name - Example: +>>> find Open House +____________________________________________________________ +Here are the matching tasks in your list, with 1 task as followed: +[E][ ] Open House (at Sunday) + +____________________________________________________________ ## Feature - Bye - This function will help the chatbot to say bye to the user, and end up the conversation. - Example: + >>> bye +____________________________________________________________ + Bye. Hope to see you again soon! + + +____________________________________________________________ ### That's all about Arsdorint chatbot! Hope you enjoy our product, and leave some comments to help us improve the chatbot! Thank you so much! ``` Hello from - ____ _ - | _ \ _ _| | _____ - | | | | | | | |/ / _ \ - | |_| | |_| | < __/ - |____/ \__,_|_|\_\___| + ___ _ _ + / _ \ _____ _____ ___| | ___ _____ _ _____ _| |_ + / /_\ \ / ___| / __/ / _ | / _ \ / ___| | | | _ \ |_ _| + / _____ \ | / __\ \ | |_| | | |_| | | / | | | | | | | | + /_/ \_\ |_| /____/ \_____| \___/ |_| |_| |_| |_| |_| + ``` From 1b2c2de69e539c77476dc159c520cd2d3154b912 Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam <88639992+arsdorintbp2003@users.noreply.github.com> Date: Fri, 3 Mar 2023 22:49:32 +0700 Subject: [PATCH 34/45] Finish User Guide --- docs/README.md | 153 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 137 insertions(+), 16 deletions(-) diff --git a/docs/README.md b/docs/README.md index 8077118eb..1a4b1ecb1 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,29 +1,150 @@ -# User Guide +# Arsdorint chatbot -## Features +This is Arsdorint chatbot, a member of Arsdorint Team, and an adaptation application of CS2113 Project Duke) -### Feature-ABC +## User Guide -Description of the feature. +1. To download the application, click on this link. +2. The chatbot contains the following feature + + List + + Todo + + Deadline + + Event + + Mark + + Unmark + + Date + + Find + + Bye -### Feature-XYZ +## Feature - List +- This function will list all the tasks inputed by the user. +- Example: +>>> list +Here are the tasks in your list: -Description of the feature. +____________________________________________________________ +____________________________LIST____________________________ +1.[T][ ] midterm + Now you have 1 task in the list. +____________________________________________________________ -## Usage -### `Keyword` - Describe action +## Feature - Todo +- This function will add a task that the user want to do, with a tickbox to mark if the task is done yet or not. +- Example: +>>> todo midterm +____________________________________________________________ -Describe the action and its outcome. +Got it. I've added this task: + +[T][ ] midterm + Now you have 1 task in the list. +____________________________________________________________ -Example of usage: -`keyword (optional arguments)` +## Feature - Deadline +- This function will add a deadline that the user need to complete, with a tickbox to mark if the deadline is finished or not. +- Example: +>>> deadline midterm /by tommorrow +____________________________________________________________ -Expected outcome: +Got it. I've added this task: + +[D][ ] midterm (by tommorrow) + Now you have 2 tasks in the list. +____________________________________________________________ -Description of the outcome. +or +>>> deadline midterm /2023-03-04 +____________________________________________________________ -``` -expected output -``` +Got it. I've added this task: + +[D][ ] midterm (4 Mar 2023) + Now you have 4 tasks in the list. +____________________________________________________________ + +## Feature - Event +- This function will add an event that the user need to attend, with a tickbox to mark if the user have attended or not. +- Example: +>>> event Open House /on Sunday +____________________________________________________________ + +Got it. I've added this task: + +[E][ ] Open House (on Sunday) + Now you have 5 tasks in the list. +____________________________________________________________ + +or +>>> event NUS football match /2023-03-05 +____________________________________________________________ + +Got it. I've added this task: + +[E][ ] NUS football match (5 Mar 2023) + Now you have 6 tasks in the list. +____________________________________________________________ + +## Feature - Mark +- This function will mark a task as done by tick a "X" into the tickbox. +- Example: +>>> mark 2 +____________________________________________________________ + +Got it. I've marked this task as done: + +[D][X] midterm (by tommorrow) + Now you have 5 unmarked tasks in the list. +____________________________________________________________ + +## Feature - Unmark +- This function will mark a task as not done yet by leaving the tickbox empty. +- Example: +>>> unmark 2 +____________________________________________________________ + +Got it. I've marked this task as not done yet: + +[D][ ] midterm (by tommorrow) + Now you have 0 marked tasks in the list. +____________________________________________________________ + +## Feature - Date +- This function will find if a date is in the task list yet. The date should be in the format of YYYY-MM-DD with YYYY is the year, MM is the month and DD is the day. +- Example: +>>> date /2023-03-04 +____________________________________________________________ +1 task happen on this date +____________________________________________________________ + +## Feature - Find +- This function will find if the task the user want to search is in the list yet, and list all task with that name +- Example: +>>> find Open House +____________________________________________________________ +Here are the matching tasks in your list, with 1 task as followed: +[E][ ] Open House (at Sunday) + +____________________________________________________________ + +## Feature - Bye + - This function will help the chatbot to say bye to the user, and end up the conversation. + - Example: + >>> bye +____________________________________________________________ + Bye. Hope to see you again soon! + + +____________________________________________________________ + +### That's all about Arsdorint chatbot! Hope you enjoy our product, and leave some comments to help us improve the chatbot! Thank you so much! + ``` + Hello from + ___ _ _ + / _ \ _____ _____ ___| | ___ _____ _ _____ _| |_ + / /_\ \ / ___| / __/ / _ | / _ \ / ___| | | | _ \ |_ _| + / _____ \ | / __\ \ | |_| | | |_| | | / | | | | | | | | + /_/ \_\ |_| /____/ \_____| \___/ |_| |_| |_| |_| |_| + + ``` From 3f0acf2398dfdb286794e2b34f12acb4c11d42f9 Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam <88639992+arsdorintbp2003@users.noreply.github.com> Date: Fri, 3 Mar 2023 23:06:53 +0700 Subject: [PATCH 35/45] Update README.md --- docs/README.md | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index 1a4b1ecb1..216dcc9cb 100644 --- a/docs/README.md +++ b/docs/README.md @@ -19,6 +19,8 @@ This is Arsdorint chatbot, a member of Arsdorint Team, and an adaptation applica ## Feature - List - This function will list all the tasks inputed by the user. - Example: + +``` >>> list Here are the tasks in your list: @@ -27,11 +29,13 @@ ____________________________LIST____________________________ 1.[T][ ] midterm Now you have 1 task in the list. ____________________________________________________________ - +``` ## Feature - Todo - This function will add a task that the user want to do, with a tickbox to mark if the task is done yet or not. - Example: + +``` >>> todo midterm ____________________________________________________________ @@ -40,11 +44,13 @@ Got it. I've added this task: [T][ ] midterm Now you have 1 task in the list. ____________________________________________________________ - +``` ## Feature - Deadline - This function will add a deadline that the user need to complete, with a tickbox to mark if the deadline is finished or not. - Example: + +``` >>> deadline midterm /by tommorrow ____________________________________________________________ @@ -53,8 +59,11 @@ Got it. I've added this task: [D][ ] midterm (by tommorrow) Now you have 2 tasks in the list. ____________________________________________________________ +``` or + +``` >>> deadline midterm /2023-03-04 ____________________________________________________________ @@ -63,10 +72,12 @@ Got it. I've added this task: [D][ ] midterm (4 Mar 2023) Now you have 4 tasks in the list. ____________________________________________________________ +``` ## Feature - Event - This function will add an event that the user need to attend, with a tickbox to mark if the user have attended or not. - Example: +``` >>> event Open House /on Sunday ____________________________________________________________ @@ -75,8 +86,11 @@ Got it. I've added this task: [E][ ] Open House (on Sunday) Now you have 5 tasks in the list. ____________________________________________________________ +``` or + +``` >>> event NUS football match /2023-03-05 ____________________________________________________________ @@ -85,10 +99,13 @@ Got it. I've added this task: [E][ ] NUS football match (5 Mar 2023) Now you have 6 tasks in the list. ____________________________________________________________ +``` ## Feature - Mark - This function will mark a task as done by tick a "X" into the tickbox. - Example: + +``` >>> mark 2 ____________________________________________________________ @@ -97,10 +114,13 @@ Got it. I've marked this task as done: [D][X] midterm (by tommorrow) Now you have 5 unmarked tasks in the list. ____________________________________________________________ +``` ## Feature - Unmark - This function will mark a task as not done yet by leaving the tickbox empty. - Example: + +``` >>> unmark 2 ____________________________________________________________ @@ -109,34 +129,44 @@ Got it. I've marked this task as not done yet: [D][ ] midterm (by tommorrow) Now you have 0 marked tasks in the list. ____________________________________________________________ +``` ## Feature - Date - This function will find if a date is in the task list yet. The date should be in the format of YYYY-MM-DD with YYYY is the year, MM is the month and DD is the day. - Example: + +``` >>> date /2023-03-04 ____________________________________________________________ 1 task happen on this date ____________________________________________________________ +``` ## Feature - Find - This function will find if the task the user want to search is in the list yet, and list all task with that name - Example: + +``` >>> find Open House ____________________________________________________________ Here are the matching tasks in your list, with 1 task as followed: [E][ ] Open House (at Sunday) ____________________________________________________________ +``` ## Feature - Bye - This function will help the chatbot to say bye to the user, and end up the conversation. - Example: + + ``` >>> bye ____________________________________________________________ Bye. Hope to see you again soon! ____________________________________________________________ +``` ### That's all about Arsdorint chatbot! Hope you enjoy our product, and leave some comments to help us improve the chatbot! Thank you so much! ``` From 9d8c00e30cbdd6600c9912fa68264d4da846ab03 Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam <88639992+arsdorintbp2003@users.noreply.github.com> Date: Fri, 3 Mar 2023 23:11:33 +0700 Subject: [PATCH 36/45] Update README.md --- docs/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/README.md b/docs/README.md index 216dcc9cb..e7af03d39 100644 --- a/docs/README.md +++ b/docs/README.md @@ -77,6 +77,7 @@ ____________________________________________________________ ## Feature - Event - This function will add an event that the user need to attend, with a tickbox to mark if the user have attended or not. - Example: + ``` >>> event Open House /on Sunday ____________________________________________________________ From 9830b67e817da7ac60446c9b34315bcf2353b0de Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam Date: Fri, 3 Mar 2023 23:19:26 +0700 Subject: [PATCH 37/45] Update arsdorintTask.txt --- storage/arsdorintTask.txt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/storage/arsdorintTask.txt b/storage/arsdorintTask.txt index 2d00ddd7a..66438487d 100644 --- a/storage/arsdorintTask.txt +++ b/storage/arsdorintTask.txt @@ -1,4 +1,6 @@ -T | 1 | list -D | 1 | x | y -D | 0 | abc | z -T | 1 | x +T | 0 | midterm +D | 0 | midterm | by tommorrow +D | 0 | midterm | 2023-3-4 +D | 0 | midterm | 2023-03-04 +E | 0 | Open House | at Sunday +E | 0 | NUS football match | 2023-03-05 From cba117a3816db18efd6a7be53383f72bd79605c5 Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam Date: Fri, 3 Mar 2023 23:20:01 +0700 Subject: [PATCH 38/45] Update arsdorintTask.txt --- storage/arsdorintTask.txt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/storage/arsdorintTask.txt b/storage/arsdorintTask.txt index 2d00ddd7a..66438487d 100644 --- a/storage/arsdorintTask.txt +++ b/storage/arsdorintTask.txt @@ -1,4 +1,6 @@ -T | 1 | list -D | 1 | x | y -D | 0 | abc | z -T | 1 | x +T | 0 | midterm +D | 0 | midterm | by tommorrow +D | 0 | midterm | 2023-3-4 +D | 0 | midterm | 2023-03-04 +E | 0 | Open House | at Sunday +E | 0 | NUS football match | 2023-03-05 From 7f55fed7b8d72da603a4d280f3919d56fd5693e1 Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam <88639992+arsdorintbp2003@users.noreply.github.com> Date: Mon, 6 Mar 2023 19:18:23 +0700 Subject: [PATCH 39/45] Update README.md --- docs/README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index e7af03d39..8dac31747 100644 --- a/docs/README.md +++ b/docs/README.md @@ -4,8 +4,11 @@ This is Arsdorint chatbot, a member of Arsdorint Team, and an adaptation applica ## User Guide -1. To download the application, click on this link. -2. The chatbot contains the following feature +1. To download the application, click [here](https://github.com/arsdorintbp2003/ip/releases/tag/Level-9). +2. Copy the file path after your download. (ie: C:\Users\YourPC\GitHub\ip_jar) +3. Open your terminal, if the current path is not where you keep the file (ie: C:\Users\YourPC), just type `cd` + the remaining path (ie: 'cd GitHub\ip_jar`) to access the file path. +4. Initializing the application by typing `java -jar ip.jar`, and enjoy using the chatbot. +5. The chatbot contains the following feature + List + Todo + Deadline From fc60d2167285fc772086e4d851de639e1c764adb Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam <88639992+arsdorintbp2003@users.noreply.github.com> Date: Mon, 6 Mar 2023 19:44:41 +0700 Subject: [PATCH 40/45] Update README.md --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 8dac31747..85e333d46 100644 --- a/docs/README.md +++ b/docs/README.md @@ -4,7 +4,7 @@ This is Arsdorint chatbot, a member of Arsdorint Team, and an adaptation applica ## User Guide -1. To download the application, click [here](https://github.com/arsdorintbp2003/ip/releases/tag/Level-9). +1. To download the application, click [here](https://github.com/arsdorintbp2003/ip/releases/tag/A-Released). 2. Copy the file path after your download. (ie: C:\Users\YourPC\GitHub\ip_jar) 3. Open your terminal, if the current path is not where you keep the file (ie: C:\Users\YourPC), just type `cd` + the remaining path (ie: 'cd GitHub\ip_jar`) to access the file path. 4. Initializing the application by typing `java -jar ip.jar`, and enjoy using the chatbot. From b847108b950b485d55f690603e1c3dd99acec97d Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam <88639992+arsdorintbp2003@users.noreply.github.com> Date: Tue, 7 Mar 2023 08:46:21 +0700 Subject: [PATCH 41/45] Update README.md --- docs/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/README.md b/docs/README.md index 85e333d46..7aa1e956b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -140,10 +140,10 @@ ____________________________________________________________ - Example: ``` ->>> date /2023-03-04 -____________________________________________________________ -1 task happen on this date +>>> date 2022-03-04 ____________________________________________________________ +Tasks occurs on this date +[D][ ] Open House (4 Mar 2022) ``` ## Feature - Find @@ -154,7 +154,7 @@ ____________________________________________________________ >>> find Open House ____________________________________________________________ Here are the matching tasks in your list, with 1 task as followed: -[E][ ] Open House (at Sunday) +[E][ ] Open House (on Sunday) ____________________________________________________________ ``` From b79e3ef089554207019bede0e89491c9e56191ee Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam Date: Mon, 20 Mar 2023 12:06:50 +0700 Subject: [PATCH 42/45] Fix Error (Need to do more) --- src/main/java/Arsdorint/Arsdorint.java | 34 ++++++++++-- src/main/java/Arsdorint/MessageList.java | 4 +- src/main/java/Arsdorint/command/Command.java | 5 ++ .../java/Arsdorint/command/CommandDate.java | 6 ++ .../Arsdorint/command/CommandDeadline.java | 6 ++ .../java/Arsdorint/command/CommandDelete.java | 6 ++ .../java/Arsdorint/command/CommandEvent.java | 6 ++ .../java/Arsdorint/command/CommandExit.java | 6 ++ .../java/Arsdorint/command/CommandFind.java | 7 +++ .../java/Arsdorint/command/CommandList.java | 6 ++ .../java/Arsdorint/command/CommandMark.java | 6 ++ .../java/Arsdorint/command/CommandRes.java | 19 +++++++ .../java/Arsdorint/command/CommandToDo.java | 6 ++ .../java/Arsdorint/command/CommandUnmark.java | 6 ++ .../java/Arsdorint/command/CommandWrong.java | 6 ++ .../Arsdorint/command/StorageException.java | 4 ++ .../java/Arsdorint/data/DecodeException.java | 4 ++ src/main/java/Arsdorint/data/Storage.java | 55 +++++++++++-------- src/main/java/Arsdorint/data/TaskList.java | 2 + .../java/Arsdorint/data/TaskListDecoder.java | 10 ++++ .../java/Arsdorint/data/TaskListEncoder.java | 8 +++ 21 files changed, 183 insertions(+), 29 deletions(-) create mode 100644 src/main/java/Arsdorint/command/StorageException.java create mode 100644 src/main/java/Arsdorint/data/DecodeException.java create mode 100644 src/main/java/Arsdorint/data/TaskListDecoder.java create mode 100644 src/main/java/Arsdorint/data/TaskListEncoder.java diff --git a/src/main/java/Arsdorint/Arsdorint.java b/src/main/java/Arsdorint/Arsdorint.java index 2467e908f..c66246ee8 100644 --- a/src/main/java/Arsdorint/Arsdorint.java +++ b/src/main/java/Arsdorint/Arsdorint.java @@ -5,6 +5,8 @@ import Arsdorint.data.TaskList; import Arsdorint.parser.TaskParser; +import static Arsdorint.MessageList.MESSAGE_NEW_FILE; + /** * Start of Arsdorint application * Initializes the application and interact with the users @@ -49,10 +51,16 @@ public void run() { private void start() { this.UI = new TextUI(); UI.showHelloMessage(); - UI.showToUser(Storage.load()); + this.storage = new Storage(); + try { + this.taskList = storage.load(); + UI.showToUser(MESSAGE_NEW_FILE); + } catch (StorageException err) { + UI.showToUser(err.getMessage()); + this.taskList = new TaskList(); + } } - /** * Read user command and execute until exit command is detected */ @@ -63,14 +71,32 @@ private void mainLoop() { command = new TaskParser(taskList).parsedCommand(userCommandText); CommandRes res = executeCommand(command); UI.showResToUser(res); - Storage.save(); + save(); } while (!CommandExit.isExit(command)); } + /** + * Save and catch error + */ + private void save() { + try { + storage.save(taskList); + } catch (StorageException e) { + UI.showToUser(e.getMessage()); + } + } + /** * Execute the command */ private CommandRes executeCommand(Command command) { - return command.execute(); + try { + command.setTaskList(taskList); + return command.execute(); + } catch (Exception err) { + UI.showToUser(err.getMessage()); + throw new RuntimeException(err); + } } } + diff --git a/src/main/java/Arsdorint/MessageList.java b/src/main/java/Arsdorint/MessageList.java index 1d8129645..e5394254f 100644 --- a/src/main/java/Arsdorint/MessageList.java +++ b/src/main/java/Arsdorint/MessageList.java @@ -22,9 +22,9 @@ public class MessageList { public static final String MESSAGE_NO_FILE = "There is no existing file"; public static final String MESSAGE_WRONG_FILE = "The storage files entry is invalid. Please save to overwrite"; public static final String MESSAGE_DIVIDER = - "____________________________________________________________"; + "________________________________________________________________________________"; public static final String MESSAGE_DIVIDER_LIST = - "____________________________LIST____________________________"; + "______________________________________LIST______________________________________"; public static final String MESSAGE_DELETE = "Noted. I've removed this task:"; public static final String MESSAGE_UNKNOWN = "unknown message"; diff --git a/src/main/java/Arsdorint/command/Command.java b/src/main/java/Arsdorint/command/Command.java index c55bd68f8..530388627 100644 --- a/src/main/java/Arsdorint/command/Command.java +++ b/src/main/java/Arsdorint/command/Command.java @@ -1,5 +1,7 @@ package Arsdorint.command; +import Arsdorint.data.TaskList; + /** * The parent class Command */ @@ -26,4 +28,7 @@ public boolean contains(final int[] arr, final int key) { } return false; } + + public void setTaskList(TaskList taskList) { + } } diff --git a/src/main/java/Arsdorint/command/CommandDate.java b/src/main/java/Arsdorint/command/CommandDate.java index 25a55b529..781882739 100644 --- a/src/main/java/Arsdorint/command/CommandDate.java +++ b/src/main/java/Arsdorint/command/CommandDate.java @@ -17,6 +17,12 @@ public CommandDate(LocalDate date) { public static final String TOP_MESSAGE = "Tasks occurs on this date"; public LocalDate date; + /** + * Execution of the "date" command + * + * @return printing the list of command happens on that date + * + */ @Override public CommandRes execute() { ArrayList task = new ArrayList<>(TaskList.list.stream().filter(i -> !i.isDateNull()).filter diff --git a/src/main/java/Arsdorint/command/CommandDeadline.java b/src/main/java/Arsdorint/command/CommandDeadline.java index 2ddcfe686..131cb7dfe 100644 --- a/src/main/java/Arsdorint/command/CommandDeadline.java +++ b/src/main/java/Arsdorint/command/CommandDeadline.java @@ -20,6 +20,12 @@ public CommandDeadline(String description, String date) { public String date; public ArrayList task = new ArrayList(); + /** + * Execution of the "deadline" command + * + * @return printing the deadline's added status to the user + * + */ @Override public CommandRes execute() { Task added = new Deadline(description, date); diff --git a/src/main/java/Arsdorint/command/CommandDelete.java b/src/main/java/Arsdorint/command/CommandDelete.java index ddbc9bccc..ce9ddf489 100644 --- a/src/main/java/Arsdorint/command/CommandDelete.java +++ b/src/main/java/Arsdorint/command/CommandDelete.java @@ -21,6 +21,12 @@ public CommandDelete(int...idx) { public static final String MESSAGE_TOP = "\nGot it. I've deleted this task:\n" + "\t"; public int[] idx; + /** + * Execution of the "delete" command + * + * @return @return printing the task's deleted status to the user + * + */ @Override public CommandRes execute() { ArrayList task = new ArrayList(IntStream.range(0, TaskList.list.size()).filter diff --git a/src/main/java/Arsdorint/command/CommandEvent.java b/src/main/java/Arsdorint/command/CommandEvent.java index be3fde2db..faf2dcd6b 100644 --- a/src/main/java/Arsdorint/command/CommandEvent.java +++ b/src/main/java/Arsdorint/command/CommandEvent.java @@ -20,6 +20,12 @@ public CommandEvent(String description, String date) { public String date; public ArrayList task = new ArrayList(); + /** + * Execution of the event command + * + * @return printing the event's added status to the user + * + */ @Override public CommandRes execute() { Task added = new Event(description, date); diff --git a/src/main/java/Arsdorint/command/CommandExit.java b/src/main/java/Arsdorint/command/CommandExit.java index 85d631d5a..f729dba03 100644 --- a/src/main/java/Arsdorint/command/CommandExit.java +++ b/src/main/java/Arsdorint/command/CommandExit.java @@ -11,6 +11,12 @@ public static boolean isExit(Command command) { return command.commandType.equalsIgnoreCase("COMMAND_NAME"); } + /** + * Execution of the exit command + * + * @return printing the exit of command + * + */ @Override public CommandRes execute() { return new CommandRes(MESSAGE_TOP); diff --git a/src/main/java/Arsdorint/command/CommandFind.java b/src/main/java/Arsdorint/command/CommandFind.java index 85bcc750c..ec34c098f 100644 --- a/src/main/java/Arsdorint/command/CommandFind.java +++ b/src/main/java/Arsdorint/command/CommandFind.java @@ -16,6 +16,13 @@ public CommandFind(String key) { public static final String SYNTAX = "Find syntax\n\t>>>find "; public String key; + /** + * Execution of the "find" command + * + * @return printing the task that match the user's search, or print "no tasks" command in case there are no tasks + * match what user search + * + */ @Override public CommandRes execute() { ArrayList task = new ArrayList<>(TaskList.list.stream().filter(i -> i.description diff --git a/src/main/java/Arsdorint/command/CommandList.java b/src/main/java/Arsdorint/command/CommandList.java index 2ccbefe62..14e9a0e9a 100644 --- a/src/main/java/Arsdorint/command/CommandList.java +++ b/src/main/java/Arsdorint/command/CommandList.java @@ -13,6 +13,12 @@ public CommandList() { public static final String COMMAND_NAME = "list"; public static final String SYNTAX = "Here's your task in the list: "; + /** + * Execution of the "list" command + * + * @return printing the list of command + * + */ @Override public CommandRes execute() { return new CommandRes(MESSAGE_DIVIDER_LIST, TaskList.list, TaskList.getAllMessage()); diff --git a/src/main/java/Arsdorint/command/CommandMark.java b/src/main/java/Arsdorint/command/CommandMark.java index 934cc830a..c8b9763f3 100644 --- a/src/main/java/Arsdorint/command/CommandMark.java +++ b/src/main/java/Arsdorint/command/CommandMark.java @@ -21,6 +21,12 @@ public CommandMark(int...idx) { public static final String MESSAGE_TOP = "\nGot it. I've marked this task as done:\n" + "\t"; public int[] idx; + /** + * Execution of the "mark" command + * + * @return printing the task to be marked with an "X" in its box + * + */ @Override public CommandRes execute() { for (int i = 0; i < idx.length; i++) { diff --git a/src/main/java/Arsdorint/command/CommandRes.java b/src/main/java/Arsdorint/command/CommandRes.java index 9a59e35ce..b1eb14223 100644 --- a/src/main/java/Arsdorint/command/CommandRes.java +++ b/src/main/java/Arsdorint/command/CommandRes.java @@ -6,20 +6,39 @@ import java.util.ArrayList; import java.util.stream.IntStream; +/** + * Represent the result of the command + */ public class CommandRes { public String messageTop = ""; public String messageBottom = ""; public ArrayList task = null; + /** + * Initialization without task + * + * @param strTop the first string to be shown + */ public CommandRes(String strTop) { this.messageTop = strTop; } + + /** + * Initialization with task + * + * @param strTop the first string to be shown + * @param task the list of all tasks + * @param strBottom the last string to be shown + */ public CommandRes(String strTop, ArrayList task, String strBottom) { this.messageTop = strTop; this.messageBottom = strBottom; this.task = task; } + /** + * Print the task + */ public String[] printTask() { if (task == null) { return new String[]{}; diff --git a/src/main/java/Arsdorint/command/CommandToDo.java b/src/main/java/Arsdorint/command/CommandToDo.java index 9870d58b6..6af0637b1 100644 --- a/src/main/java/Arsdorint/command/CommandToDo.java +++ b/src/main/java/Arsdorint/command/CommandToDo.java @@ -20,6 +20,12 @@ public CommandToDo(String description) { public ArrayList task = new ArrayList(); + /** + * Execution of the "todo" command + * + * @return printing the task to be including in the list + * + */ @Override public CommandRes execute() { Task added = new Todo(description); diff --git a/src/main/java/Arsdorint/command/CommandUnmark.java b/src/main/java/Arsdorint/command/CommandUnmark.java index ade865eb0..1f0070962 100644 --- a/src/main/java/Arsdorint/command/CommandUnmark.java +++ b/src/main/java/Arsdorint/command/CommandUnmark.java @@ -19,6 +19,12 @@ public CommandUnmark(int...idx) { public static final String MESSAGE_TOP = "\nGot it. I've marked this task as not done yet:\n" + "\t"; public int[] idx; + /** + * Execution of the "unmark" command + * + * @return printing the task to be unmarked with an empty of "X" in its box + * + */ @Override public CommandRes execute() { for (int i = 0; i < idx.length; i++) { diff --git a/src/main/java/Arsdorint/command/CommandWrong.java b/src/main/java/Arsdorint/command/CommandWrong.java index 6b9b7cfa8..ed0d952fa 100644 --- a/src/main/java/Arsdorint/command/CommandWrong.java +++ b/src/main/java/Arsdorint/command/CommandWrong.java @@ -16,6 +16,12 @@ public CommandWrong(String top, String bottom) { public String top = "=( OOPS!!! I'm sorry, but I don't know what that means :-(\n" + MESSAGE_DIVIDER; public String bottom = "Error: Lack / Wrong description format of the command"; + /** + * Execution in case the command is not in the command list + * + * @return printing the COMMAND_WRONG message + * + */ @Override public CommandRes execute() { return new CommandRes(this.top, null, this.bottom); diff --git a/src/main/java/Arsdorint/command/StorageException.java b/src/main/java/Arsdorint/command/StorageException.java new file mode 100644 index 000000000..99a00abc0 --- /dev/null +++ b/src/main/java/Arsdorint/command/StorageException.java @@ -0,0 +1,4 @@ +package Arsdorint.command; + +public class StorageException extends Exception { +} diff --git a/src/main/java/Arsdorint/data/DecodeException.java b/src/main/java/Arsdorint/data/DecodeException.java new file mode 100644 index 000000000..0241a2304 --- /dev/null +++ b/src/main/java/Arsdorint/data/DecodeException.java @@ -0,0 +1,4 @@ +package Arsdorint.data; + +public class DecodeException extends Throwable { +} diff --git a/src/main/java/Arsdorint/data/Storage.java b/src/main/java/Arsdorint/data/Storage.java index 6dd8e8781..11a55f433 100644 --- a/src/main/java/Arsdorint/data/Storage.java +++ b/src/main/java/Arsdorint/data/Storage.java @@ -1,12 +1,19 @@ package Arsdorint.data; import Arsdorint.command.ArsdorintFileException; +import Arsdorint.command.StorageException; import Arsdorint.parser.TaskParser; +import Arsdorint.task.Task; import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; import java.util.Scanner; import static Arsdorint.MessageList.*; @@ -14,39 +21,41 @@ public class Storage { public Storage() { + path = Paths.get(STORAGE_FILE_NAME); } public static final String STORAGE_DIRECTORY = "./storage"; public static final String STORAGE_FILE_NAME = "./storage/arsdorintTask.txt"; - public static String[] save() { + private static final Path path = null; + private static final String ERROR_SAVING_MESSAGE = "Error saving to "; + private static final String ERROR_LOADING_MESSAGE = "Error loading to "; + private static final String ERROR_PARSING_MESSAGE = "Error parsing "; + public static String[] save(TaskList taskList) throws StorageException { try { - FileWriter fileWriter = new FileWriter(STORAGE_FILE_NAME); - for (int i = 0; i < TaskList.list.size(); i++) { - fileWriter.write(TaskList.list.get(i).toSave()); - } - fileWriter.close(); - return new String[]{MESSAGE_OVERWRITE_FILE}; + List encodedTaskList = TaskListEncoder.encodeList(taskList); + Files.write(path, encodedTaskList); } catch (IOException err) { File newFile = new File(STORAGE_DIRECTORY); newFile.mkdir(); - save(); - return new String[]{MESSAGE_NO_FILE, MESSAGE_NEW_FILE}; + save(taskList); + throw new StorageException(ERROR_SAVING_MESSAGE + path + MESSAGE_NEW_FILE); } } - public static String load() { + public TaskList load() throws StorageException { + TaskList list = new TaskList(); try { - File file = new File(STORAGE_FILE_NAME); - Scanner fileRead = new Scanner(file); - while (fileRead.hasNext()) { - new TaskParser(new TaskList()).fileParser(fileRead.nextLine()); - } - fileRead.close(); - return MESSAGE_LOAD_FILE; - } catch (FileNotFoundException err) { - return MESSAGE_NO_FILE; - } catch (ArrayIndexOutOfBoundsException err) { - return MESSAGE_WRONG_FILE; - } catch (ArsdorintFileException err) { - return MESSAGE_WRONG_FILE; + ArrayList decodedList = TaskListDecoder.decodeFile(STORAGE_FILE_NAME); + list.data = decodedList; + return list; + } catch (IOException err) { + throw new StorageException(ERROR_LOADING_MESSAGE + path); + } catch (DecodeException err) { + throw new StorageException(ERROR_PARSING_MESSAGE + path); + } + } + + public static class StorageException extends Exception { + public StorageException(String message) { + super(message); } } diff --git a/src/main/java/Arsdorint/data/TaskList.java b/src/main/java/Arsdorint/data/TaskList.java index c4f9c2f0a..d3464898f 100644 --- a/src/main/java/Arsdorint/data/TaskList.java +++ b/src/main/java/Arsdorint/data/TaskList.java @@ -6,6 +6,8 @@ /* Represent the TaskList, and some functions to deal with messages */ public class TaskList { + public ArrayList data; + public TaskList() { } public static final int MAX_NUM_OF_TASKS = 100; diff --git a/src/main/java/Arsdorint/data/TaskListDecoder.java b/src/main/java/Arsdorint/data/TaskListDecoder.java new file mode 100644 index 000000000..e711d98f3 --- /dev/null +++ b/src/main/java/Arsdorint/data/TaskListDecoder.java @@ -0,0 +1,10 @@ +package Arsdorint.data; + +import Arsdorint.task.Task; + +import java.util.ArrayList; + +public class TaskListDecoder { + public static ArrayList decodeFile(String storageFileName) { + } +} diff --git a/src/main/java/Arsdorint/data/TaskListEncoder.java b/src/main/java/Arsdorint/data/TaskListEncoder.java new file mode 100644 index 000000000..3b68f6c37 --- /dev/null +++ b/src/main/java/Arsdorint/data/TaskListEncoder.java @@ -0,0 +1,8 @@ +package Arsdorint.data; + +import java.util.List; + +public class TaskListEncoder { + public static List encodeList(TaskList taskList) { + } +} From 76fccc724db054982950b5b2da5184a498b7bd52 Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam Date: Mon, 20 Mar 2023 22:13:24 +0700 Subject: [PATCH 43/45] Final Ver --- src/main/java/Arsdorint/Arsdorint.java | 16 +++--- src/main/java/Arsdorint/MessageList.java | 4 +- src/main/java/Arsdorint/UI/TextUI.java | 23 ++++++++ src/main/java/Arsdorint/command/Command.java | 23 ++++++-- .../java/Arsdorint/command/CommandDate.java | 9 ++- .../java/Arsdorint/command/CommandDelete.java | 4 +- .../java/Arsdorint/command/CommandRes.java | 9 ++- .../java/Arsdorint/data/DecodeException.java | 4 -- .../data/{Storage.java => StorageClass.java} | 24 ++++---- .../java/Arsdorint/data/TaskListDecoder.java | 57 ++++++++++++++++++- .../java/Arsdorint/data/TaskListEncoder.java | 32 ++++++++++- .../java/Arsdorint/parser/TaskParser.java | 7 --- src/main/java/Arsdorint/task/Deadline.java | 11 ++++ src/main/java/Arsdorint/task/Event.java | 9 +++ src/main/java/Arsdorint/task/Task.java | 33 +++++++++-- src/main/java/Arsdorint/task/Todo.java | 3 + storage/arsdorintTask.txt | 12 ++-- 17 files changed, 226 insertions(+), 54 deletions(-) delete mode 100644 src/main/java/Arsdorint/data/DecodeException.java rename src/main/java/Arsdorint/data/{Storage.java => StorageClass.java} (78%) diff --git a/src/main/java/Arsdorint/Arsdorint.java b/src/main/java/Arsdorint/Arsdorint.java index c66246ee8..b99ff8ba8 100644 --- a/src/main/java/Arsdorint/Arsdorint.java +++ b/src/main/java/Arsdorint/Arsdorint.java @@ -1,7 +1,7 @@ package Arsdorint; import Arsdorint.UI.TextUI; import Arsdorint.command.*; -import Arsdorint.data.Storage; +import Arsdorint.data.StorageClass; import Arsdorint.data.TaskList; import Arsdorint.parser.TaskParser; @@ -19,7 +19,7 @@ public class Arsdorint { + "/_/ \\_\\ |_| /____/ \\_____| \\___/ |_| |_| |_| |_| |_|\n"; private TextUI UI; - private Storage storage; + private StorageClass storage; private TaskList taskList; /** @@ -46,17 +46,17 @@ public void run() { /** - * Setup the required objects, print hello message + * Set up the required objects, print hello message */ private void start() { this.UI = new TextUI(); UI.showHelloMessage(); - this.storage = new Storage(); + this.storage = new StorageClass(); try { this.taskList = storage.load(); UI.showToUser(MESSAGE_NEW_FILE); - } catch (StorageException err) { - UI.showToUser(err.getMessage()); + } catch (StorageClass.StorageException e) { + UI.showToUser(e.getMessage()); this.taskList = new TaskList(); } } @@ -81,13 +81,15 @@ private void mainLoop() { private void save() { try { storage.save(taskList); - } catch (StorageException e) { + } catch (StorageClass.StorageException e) { UI.showToUser(e.getMessage()); } } /** * Execute the command + * + * @param command the input command that the user typed in */ private CommandRes executeCommand(Command command) { try { diff --git a/src/main/java/Arsdorint/MessageList.java b/src/main/java/Arsdorint/MessageList.java index e5394254f..c11254250 100644 --- a/src/main/java/Arsdorint/MessageList.java +++ b/src/main/java/Arsdorint/MessageList.java @@ -22,9 +22,9 @@ public class MessageList { public static final String MESSAGE_NO_FILE = "There is no existing file"; public static final String MESSAGE_WRONG_FILE = "The storage files entry is invalid. Please save to overwrite"; public static final String MESSAGE_DIVIDER = - "________________________________________________________________________________"; + "____________________________________________________________________________________________________"; public static final String MESSAGE_DIVIDER_LIST = - "______________________________________LIST______________________________________"; + "________________________________________________LIST________________________________________________"; public static final String MESSAGE_DELETE = "Noted. I've removed this task:"; public static final String MESSAGE_UNKNOWN = "unknown message"; diff --git a/src/main/java/Arsdorint/UI/TextUI.java b/src/main/java/Arsdorint/UI/TextUI.java index 090b75a6b..eaae42d33 100644 --- a/src/main/java/Arsdorint/UI/TextUI.java +++ b/src/main/java/Arsdorint/UI/TextUI.java @@ -9,9 +9,23 @@ import static Arsdorint.Arsdorint.logo; import static Arsdorint.MessageList.*; +/** + * Represent the class taking in user input and display command output + */ public class TextUI { public final Scanner input; public final PrintStream output; + /** + * Offset 0 index to 1 + */ + public static final int INDEX_OFFSET = 1; + /** + * Format of indexed list item + */ + private static final String INDEX_LIST_ITEM_FORMAT = "\t%1$d. %2$s"; + /** + * User Prompt + */ public static final String UI_PROMPT = ">>> "; public TextUI() { @@ -62,6 +76,10 @@ public void showResToUser(CommandRes res) { output.println(MessageList.MESSAGE_DIVIDER); } + /** + * Show the message when the user type "exit" command + * + */ public void showExitMessage() { showToUser(MESSAGE_DIVIDER, EXIT_MESSAGE, MESSAGE_DIVIDER); } @@ -71,6 +89,11 @@ public void showUnknownMessage() { this.showToUser(MessageList.COMMAND_LIST_MESSAGE); output.println(MessageList.MESSAGE_DIVIDER); } + + /** + * Show the welcome message from Arsdorint Team and the command list instruction to the user + * + */ public void showHelloMessage() { System.out.println("Hello from\n" + logo); showToUser(MESSAGE_DIVIDER, HELLO_MESSAGE, COMMAND_LIST_MESSAGE, QUESTION, MESSAGE_DIVIDER); diff --git a/src/main/java/Arsdorint/command/Command.java b/src/main/java/Arsdorint/command/Command.java index 530388627..7c67e7f66 100644 --- a/src/main/java/Arsdorint/command/Command.java +++ b/src/main/java/Arsdorint/command/Command.java @@ -1,21 +1,25 @@ package Arsdorint.command; import Arsdorint.data.TaskList; +import Arsdorint.task.Task; + +import java.util.ArrayList; /** * The parent class Command */ -public class Command { +public abstract class Command { public String commandType; + protected String message; + protected TaskList taskList = new TaskList(); + protected ArrayList taskListTarget = new ArrayList<>(); protected Command(String commandType) { this.commandType = commandType; } /** * Execution of the command */ - public CommandRes execute() { - throw new UnsupportedOperationException("Child classes' method"); - } + public abstract CommandRes execute(); /** * Check if the key is contained in the index of the tasks @@ -29,6 +33,17 @@ public boolean contains(final int[] arr, final int key) { return false; } + /** + * Set the tasklist that the command will act on + */ public void setTaskList(TaskList taskList) { + this.taskList = taskList; + } + + /** + * Count the target list that the command act on + */ + protected int targetCount() { + return (int) taskListTarget.stream().count(); } } diff --git a/src/main/java/Arsdorint/command/CommandDate.java b/src/main/java/Arsdorint/command/CommandDate.java index 781882739..03076768a 100644 --- a/src/main/java/Arsdorint/command/CommandDate.java +++ b/src/main/java/Arsdorint/command/CommandDate.java @@ -14,7 +14,6 @@ public CommandDate(LocalDate date) { } public static final String COMMAND_NAME = "delete"; public static final String SYNTAX = "Syntax for date\n\t>>>date "; - public static final String TOP_MESSAGE = "Tasks occurs on this date"; public LocalDate date; /** @@ -28,8 +27,12 @@ public CommandRes execute() { ArrayList task = new ArrayList<>(TaskList.list.stream().filter(i -> !i.isDateNull()).filter (i -> i.getDate().equals(this.date)).collect(Collectors.toList())); long count = task.stream().count(); - String messageTop = count + " tasks happen on this date"; - return new CommandRes(TOP_MESSAGE, task, ""); + String messageTop = count + " " + TaskList.printTasksOrTask((int) count) + + printOccursOrOccur((int) count) + " on this date"; + return new CommandRes(messageTop, task, ""); + } + private String printOccursOrOccur(int count) { + return (count == 1) ? "occurs" : "occur"; } } diff --git a/src/main/java/Arsdorint/command/CommandDelete.java b/src/main/java/Arsdorint/command/CommandDelete.java index ce9ddf489..aab9cb655 100644 --- a/src/main/java/Arsdorint/command/CommandDelete.java +++ b/src/main/java/Arsdorint/command/CommandDelete.java @@ -10,6 +10,8 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; +import static Arsdorint.MessageList.MESSAGE_DELETE; + public class CommandDelete extends Command { public CommandDelete(int...idx) { @@ -18,7 +20,7 @@ public CommandDelete(int...idx) { } public static final String COMMAND_NAME = "delete"; public static final String SYNTAX = "Syntax for delete item \n\t>>> delete \n"; - public static final String MESSAGE_TOP = "\nGot it. I've deleted this task:\n" + "\t"; + public static final String MESSAGE_TOP = MESSAGE_DELETE; public int[] idx; /** diff --git a/src/main/java/Arsdorint/command/CommandRes.java b/src/main/java/Arsdorint/command/CommandRes.java index b1eb14223..9e9a8927c 100644 --- a/src/main/java/Arsdorint/command/CommandRes.java +++ b/src/main/java/Arsdorint/command/CommandRes.java @@ -3,7 +3,10 @@ import Arsdorint.MessageList; import Arsdorint.task.Task; +import javax.crypto.spec.OAEPParameterSpec; import java.util.ArrayList; +import java.util.List; +import java.util.Optional; import java.util.stream.IntStream; /** @@ -12,7 +15,7 @@ public class CommandRes { public String messageTop = ""; public String messageBottom = ""; - public ArrayList task = null; + public List task; /** * Initialization without task @@ -49,4 +52,8 @@ public String[] printTask() { return task.stream().map(Task::toString).toArray(String[]::new); } } + + public Optional> getTask() { + return Optional.ofNullable(task); + } } diff --git a/src/main/java/Arsdorint/data/DecodeException.java b/src/main/java/Arsdorint/data/DecodeException.java deleted file mode 100644 index 0241a2304..000000000 --- a/src/main/java/Arsdorint/data/DecodeException.java +++ /dev/null @@ -1,4 +0,0 @@ -package Arsdorint.data; - -public class DecodeException extends Throwable { -} diff --git a/src/main/java/Arsdorint/data/Storage.java b/src/main/java/Arsdorint/data/StorageClass.java similarity index 78% rename from src/main/java/Arsdorint/data/Storage.java rename to src/main/java/Arsdorint/data/StorageClass.java index 11a55f433..095e06161 100644 --- a/src/main/java/Arsdorint/data/Storage.java +++ b/src/main/java/Arsdorint/data/StorageClass.java @@ -1,35 +1,35 @@ package Arsdorint.data; -import Arsdorint.command.ArsdorintFileException; -import Arsdorint.command.StorageException; -import Arsdorint.parser.TaskParser; import Arsdorint.task.Task; import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileWriter; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; -import java.util.Scanner; import static Arsdorint.MessageList.*; -import static Arsdorint.MessageList.MESSAGE_WRONG_FILE; -public class Storage { - public Storage() { +/** + * Represent the middleman class between the main and the encoding, decoding + */ +public class StorageClass { + public StorageClass() { path = Paths.get(STORAGE_FILE_NAME); } public static final String STORAGE_DIRECTORY = "./storage"; public static final String STORAGE_FILE_NAME = "./storage/arsdorintTask.txt"; - private static final Path path = null; + private final Path path; private static final String ERROR_SAVING_MESSAGE = "Error saving to "; private static final String ERROR_LOADING_MESSAGE = "Error loading to "; private static final String ERROR_PARSING_MESSAGE = "Error parsing "; - public static String[] save(TaskList taskList) throws StorageException { + + /** + * Method to save the file + */ + public void save(TaskList taskList) throws StorageException { try { List encodedTaskList = TaskListEncoder.encodeList(taskList); Files.write(path, encodedTaskList); @@ -48,7 +48,7 @@ public TaskList load() throws StorageException { return list; } catch (IOException err) { throw new StorageException(ERROR_LOADING_MESSAGE + path); - } catch (DecodeException err) { + } catch (TaskListDecoder.DecodeException err) { throw new StorageException(ERROR_PARSING_MESSAGE + path); } } diff --git a/src/main/java/Arsdorint/data/TaskListDecoder.java b/src/main/java/Arsdorint/data/TaskListDecoder.java index e711d98f3..8f806e395 100644 --- a/src/main/java/Arsdorint/data/TaskListDecoder.java +++ b/src/main/java/Arsdorint/data/TaskListDecoder.java @@ -1,10 +1,63 @@ package Arsdorint.data; +import Arsdorint.task.Deadline; +import Arsdorint.task.Event; import Arsdorint.task.Task; - +import Arsdorint.task.Todo; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; import java.util.ArrayList; +import java.util.Scanner; + +import static Arsdorint.task.Event.TYPE_EVENT; +import static Arsdorint.task.Todo.TYPE_TODO; public class TaskListDecoder { - public static ArrayList decodeFile(String storageFileName) { + private static final String PARSE_LIMITER = "\\|"; + + /** + * Read the class that handles decoding task from a line in the file and add Task to the TaskList + * + * @param path the path of the file + * @return TaskList + */ + public static ArrayList decodeFile(String path) throws DecodeException, IOException { + ArrayList taskListData = new ArrayList<>(); + File file = new File(path); + Scanner fileReader = new Scanner(file); + while (fileReader.hasNextLine()) { + taskListData.add(decodeLine(fileReader.nextLine())); + } + fileReader.close(); + return taskListData; } + + private static Task decodeLine(String nextLine) throws DecodeException { + try { + Task add; + String[] parsedString = nextLine.split(PARSE_LIMITER); + String command = parsedString[0].trim(); + boolean isDone = Boolean.valueOf(parsedString[1]); + String description = parsedString[2]; + switch (command) { + case Todo.TYPE_TODO: + add = new Todo(isDone,description); + return add; + case Event.TYPE_EVENT: + add = new Event(isDone, description, parsedString[3]); + return add; + case Deadline.TYPE_DEADLINE: + add = new Deadline(isDone, description, parsedString[3]); + return add; + default: + throw new DecodeException(); + } + } catch (Exception err) { + throw new DecodeException(); + } + } + public static class DecodeException extends Exception { + } + } diff --git a/src/main/java/Arsdorint/data/TaskListEncoder.java b/src/main/java/Arsdorint/data/TaskListEncoder.java index 3b68f6c37..def342923 100644 --- a/src/main/java/Arsdorint/data/TaskListEncoder.java +++ b/src/main/java/Arsdorint/data/TaskListEncoder.java @@ -1,8 +1,38 @@ package Arsdorint.data; +import Arsdorint.task.Task; +import java.util.ArrayList; import java.util.List; +/** + * Represent the class that handles encode task from TaskList to file + */ public class TaskListEncoder { - public static List encodeList(TaskList taskList) { + private static final String SEPARATOR = " | "; + + /** + * Encode the tasklist + * + * @param list tasklist to be represent in strings + * @return ArrayList of String (each string is a task to be saved) + */ + + public static List encodeList(TaskList list) { + final List encodedTasks = new ArrayList<>(); + list.data.stream().forEach(task -> encodedTasks.add(encodeTask(task))); + return encodedTasks; + } + + private static String encodeTask(Task task) { + final StringBuilder encodedTaskBuilder = new StringBuilder(); + + encodedTaskBuilder.append(task.getType()); + encodedTaskBuilder.append(SEPARATOR); + encodedTaskBuilder.append(task.isDone() ? "true" : "false"); + encodedTaskBuilder.append(SEPARATOR); + encodedTaskBuilder.append(task.description); + encodedTaskBuilder.append(SEPARATOR); + encodedTaskBuilder.append(task.isDateNull() ? task.getDate() : ""); + return encodedTaskBuilder.toString(); } } diff --git a/src/main/java/Arsdorint/parser/TaskParser.java b/src/main/java/Arsdorint/parser/TaskParser.java index 9ad2f8b8d..fdb7d50ac 100644 --- a/src/main/java/Arsdorint/parser/TaskParser.java +++ b/src/main/java/Arsdorint/parser/TaskParser.java @@ -1,20 +1,15 @@ package Arsdorint.parser; -import Arsdorint.MessageList; import Arsdorint.command.*; import Arsdorint.data.TaskList; import Arsdorint.task.Deadline; import Arsdorint.task.Event; -import Arsdorint.task.Task; import Arsdorint.task.Todo; import java.time.LocalDate; import java.time.format.DateTimeParseException; -import static Arsdorint.Arsdorint.*; import static Arsdorint.MessageList.*; -import static Arsdorint.MessageList.MESSAGE_DIVIDER; -import static Arsdorint.data.Storage.save; /** * A class that handle the parsing of command @@ -105,7 +100,6 @@ public Command mark(String command) { String[] parsed = command.split(" "); if (parsed.length < 1) { throw new ArsdorintException(); - //System.out.println("Nice! I've marked this task as done: \n"); } return new CommandMark(strToIntArr(parsed)); } catch (NumberFormatException | IndexOutOfBoundsException | ArsdorintException err) { return new CommandWrong(CommandMark.SYNTAX); @@ -117,7 +111,6 @@ public Command unmark(String command) { String[] parsed = command.split(" "); if (parsed.length < 1) { throw new ArsdorintException(); - //System.out.println("OK, I've marked this task as not done yet: \n"); } return new CommandUnmark(strToIntArr(parsed)); } catch (NumberFormatException | IndexOutOfBoundsException | ArsdorintException err) { return new CommandWrong(CommandUnmark.SYNTAX); diff --git a/src/main/java/Arsdorint/task/Deadline.java b/src/main/java/Arsdorint/task/Deadline.java index 28d3cb993..f523fe225 100644 --- a/src/main/java/Arsdorint/task/Deadline.java +++ b/src/main/java/Arsdorint/task/Deadline.java @@ -20,6 +20,9 @@ public Deadline(String description, String date) { } } + /** + * Initiate with status + */ public Deadline(boolean status, String description, String date) { this(description, date); this.isDone = status; @@ -35,11 +38,19 @@ public String toString() { return (this.taskType + this.getStatus() + " " + this.description + "\t(" + printDate("d MMM yyy") + ")"); } + /** + * A boolean function to check if the date input is null or not + * + * @return true if the date is null + */ @Override public boolean isDateNull() { return (this.date == null ? true : false); } + /** + * Print the date in right format (DDDD-MM-YY) + */ public String printDate(String pattern) { return (this.date == null) ? this.dateString : this.date.format(DateTimeFormatter.ofPattern(pattern)); } diff --git a/src/main/java/Arsdorint/task/Event.java b/src/main/java/Arsdorint/task/Event.java index 9da40ef56..8aa218864 100644 --- a/src/main/java/Arsdorint/task/Event.java +++ b/src/main/java/Arsdorint/task/Event.java @@ -20,6 +20,10 @@ public Event(String description, String date) { this.taskName = TYPE_EVENT; } + + /** + * Initiate with status + */ public Event(boolean status, String description, String date) { this(description, date); this.isDone = status; @@ -36,6 +40,11 @@ public String toString() { return (this.taskType + this.getStatus() + " " + this.description + "\t(" + printDate("d MMM yyy") + ")"); } + /** + * A boolean function to check if the date input is null or not + * + * @return true if the date is null + */ @Override public boolean isDateNull() { return (this.date == null ? true : false); diff --git a/src/main/java/Arsdorint/task/Task.java b/src/main/java/Arsdorint/task/Task.java index d41150c9b..1284263a1 100644 --- a/src/main/java/Arsdorint/task/Task.java +++ b/src/main/java/Arsdorint/task/Task.java @@ -2,7 +2,7 @@ import java.time.LocalDate; -public class Task { +public abstract class Task { // initial number of task must be set to 0 public static final String VERTICAL_BAR = " | "; public static final String PARSE_LIMITER = "\\|"; @@ -19,15 +19,27 @@ public Task(String description) { numOfTasks++; } + /** + * toString for viewing + */ public String toString() { return (this.taskType + this.getStatus() + " " + this.description); } - //status is marked or not + /** + * Get the status of the task ([X] as marked and [ ] as unmarked) + * + * @return [X] if the task is done, else [ ] + */ public String getStatus() { return (isDone) ? "[X]" : "[ ]"; } + /** + * Show the result in binary format (1 and 0) + * + * @return true 1 if the task is done, else 0 + */ public int binaryRes() { return (isDone) ? 1 : 0; } @@ -36,10 +48,15 @@ public String toSave() { return (this.taskName + VERTICAL_BAR + binaryRes() + VERTICAL_BAR + this.description + "\n"); } + /** + * A boolean function to check if the date input is null or not + * + * @return true if the date is null + */ public boolean isDateNull() { - return true; + return (this.date == null ? true : false); } - + public LocalDate getDate() { return this.date; } @@ -47,5 +64,13 @@ public LocalDate getDate() { public void setIsDone(boolean status) { this.isDone = status; } + + public String getType() { + return this.taskName; + } + + public boolean isDone() { + return this.isDone; + } } diff --git a/src/main/java/Arsdorint/task/Todo.java b/src/main/java/Arsdorint/task/Todo.java index beb057691..359eae0c5 100644 --- a/src/main/java/Arsdorint/task/Todo.java +++ b/src/main/java/Arsdorint/task/Todo.java @@ -8,6 +8,9 @@ public Todo(String description) { this.taskType = "[T]"; } + /** + * Initiate with status + */ public Todo(boolean status, String description) { this(description); this.isDone = status; diff --git a/storage/arsdorintTask.txt b/storage/arsdorintTask.txt index 66438487d..e4bae02f0 100644 --- a/storage/arsdorintTask.txt +++ b/storage/arsdorintTask.txt @@ -1,6 +1,6 @@ -T | 0 | midterm -D | 0 | midterm | by tommorrow -D | 0 | midterm | 2023-3-4 -D | 0 | midterm | 2023-03-04 -E | 0 | Open House | at Sunday -E | 0 | NUS football match | 2023-03-05 +T | false | midterm | null +D | false | midterm | null +D | false | midterm | null +D | false | midterm | null +E | false | Open House | null +E | false | NUS football match | null From 6c089cd7d4d5c19095301fbdccd8b61203219307 Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam <88639992+arsdorintbp2003@users.noreply.github.com> Date: Mon, 20 Mar 2023 22:15:26 +0700 Subject: [PATCH 44/45] Final Ver --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 7aa1e956b..f8a6e1fde 100644 --- a/docs/README.md +++ b/docs/README.md @@ -142,7 +142,7 @@ ____________________________________________________________ ``` >>> date 2022-03-04 ____________________________________________________________ -Tasks occurs on this date +1 task occurs on this date: [D][ ] Open House (4 Mar 2022) ``` From 26a4df1cadb5d91b7c62eb8eefbc36258b379e66 Mon Sep 17 00:00:00 2001 From: Bui Phuong Nam Date: Mon, 20 Mar 2023 22:21:45 +0700 Subject: [PATCH 45/45] Final Ver --- storage/arsdorintTask.txt | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/storage/arsdorintTask.txt b/storage/arsdorintTask.txt index 79b4eb286..4dbee1dfe 100644 --- a/storage/arsdorintTask.txt +++ b/storage/arsdorintTask.txt @@ -5,11 +5,4 @@ D | 0 | midterm | 2023-3-4 D | 0 | midterm | 2023-03-04 E | 0 | Open House | at Sunday E | 0 | NUS football match | 2023-03-05 -======= -T | false | midterm | null -D | false | midterm | null -D | false | midterm | null -D | false | midterm | null -E | false | Open House | null -E | false | NUS football match | null ->>>>>>> master +