From fcd317b2310e23a1f87468c44050c2d72dd439dd Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Tue, 28 Jan 2020 16:23:36 +0800 Subject: [PATCH 01/45] Completed Level 0 (Greet) --- src/main/java/Duke.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5d313334cc..7e3775ebff 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,10 +1,10 @@ public class Duke { public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); + System.out.println("____________________________________________________________"); + System.out.println("Hello! I'm Duke"); + System.out.println("What can I do for you?"); + System.out.println("____________________________________________________________"); + System.out.println("Bye. Hope to see you again soon!"); + System.out.println("____________________________________________________________"); } } From 59307c5191adb4f30c29883922289c68c4c3db56 Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Fri, 31 Jan 2020 17:43:59 +0800 Subject: [PATCH 02/45] Completed Level 1. Greet, Echo, Exit --- src/main/java/Duke.java | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 7e3775ebff..b8c26d31e2 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,10 +1,21 @@ +import java.util.Scanner; + public class Duke { public static void main(String[] args) { - System.out.println("____________________________________________________________"); - System.out.println("Hello! I'm Duke"); - System.out.println("What can I do for you?"); - System.out.println("____________________________________________________________"); - System.out.println("Bye. Hope to see you again soon!"); - System.out.println("____________________________________________________________"); + System.out.println(" ____________________________________________________________"); + System.out.println(" Hello! I'm Duke"); + System.out.println(" What can I do for you?"); + System.out.println(" ____________________________________________________________"); + Scanner sc = new Scanner(System.in); + String string = sc.next(); + while (!string.equals("bye")) { + System.out.println(" ____________________________________________________________"); + System.out.println(" " + string); + System.out.println(" ____________________________________________________________"); + string = sc.next(); + } + System.out.println(" ____________________________________________________________"); + System.out.println(" Bye. Hope to see you again soon!"); + System.out.println(" ____________________________________________________________"); } } From 58959609ad1d96539e81f59395098e57b5ea62f3 Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Fri, 31 Jan 2020 18:15:13 +0800 Subject: [PATCH 03/45] Completed Level 2. Add, List --- src/main/java/Duke.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index b8c26d31e2..559c94852c 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -2,17 +2,27 @@ public class Duke { public static void main(String[] args) { + String[] lines = new String[100]; + int count = 0; System.out.println(" ____________________________________________________________"); System.out.println(" Hello! I'm Duke"); System.out.println(" What can I do for you?"); System.out.println(" ____________________________________________________________"); Scanner sc = new Scanner(System.in); - String string = sc.next(); + String string = sc.nextLine(); while (!string.equals("bye")) { System.out.println(" ____________________________________________________________"); - System.out.println(" " + string); + if (!string.equals("list")) { + lines[count] = string; + count++; + System.out.println(" added: " + string); + } else { + for (int i = 0; i < count; i++) { + System.out.println(" " + (i + 1) + ". " + lines[i]); + } + } System.out.println(" ____________________________________________________________"); - string = sc.next(); + string = sc.nextLine(); } System.out.println(" ____________________________________________________________"); System.out.println(" Bye. Hope to see you again soon!"); From ce2126ede96a351c5d02b00b2f11da180f36085b Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Fri, 31 Jan 2020 20:49:13 +0800 Subject: [PATCH 04/45] Completed Level 3. Mark as Done --- src/main/java/Duke.java | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 559c94852c..3668b3463f 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -3,7 +3,8 @@ public class Duke { public static void main(String[] args) { String[] lines = new String[100]; - int count = 0; + boolean[] isDone = new boolean[100]; + int count = 1; System.out.println(" ____________________________________________________________"); System.out.println(" Hello! I'm Duke"); System.out.println(" What can I do for you?"); @@ -12,14 +13,23 @@ public static void main(String[] args) { String string = sc.nextLine(); while (!string.equals("bye")) { System.out.println(" ____________________________________________________________"); - if (!string.equals("list")) { + String[] stringSplit = string.split(" "); + if (string.equals("list")) { + System.out.println(" Here are the tasks in your list:"); + for (int i = 1; i < count; i++) { + System.out.print(" " + (i) + ".["); + System.out.print(isDone[i] ? "✓" : "✗"); + System.out.println("] " + lines[i]); + } + } else if (stringSplit[0].equals("done")) { + int done = Integer.parseInt(stringSplit[1]); + isDone[done] = true; + System.out.println(" Nice! I've marked this task as done: "); + System.out.println(" [✓] " + lines[done]); + } else { lines[count] = string; count++; System.out.println(" added: " + string); - } else { - for (int i = 0; i < count; i++) { - System.out.println(" " + (i + 1) + ". " + lines[i]); - } } System.out.println(" ____________________________________________________________"); string = sc.nextLine(); From dd30a60720da045b7b622017af82874f4d38efd2 Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Fri, 31 Jan 2020 21:29:04 +0800 Subject: [PATCH 05/45] Completed Extension of Level 3: A-Classes --- src/main/java/Duke.java | 16 +++++++--------- src/main/java/Task.java | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 src/main/java/Task.java diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 3668b3463f..5630a869f6 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -2,8 +2,7 @@ public class Duke { public static void main(String[] args) { - String[] lines = new String[100]; - boolean[] isDone = new boolean[100]; + Task[] tasks = new Task[100]; int count = 1; System.out.println(" ____________________________________________________________"); System.out.println(" Hello! I'm Duke"); @@ -17,19 +16,18 @@ public static void main(String[] args) { if (string.equals("list")) { System.out.println(" Here are the tasks in your list:"); for (int i = 1; i < count; i++) { - System.out.print(" " + (i) + ".["); - System.out.print(isDone[i] ? "✓" : "✗"); - System.out.println("] " + lines[i]); + System.out.print(" " + (i) + ".[" + tasks[i].getStatusIcon() + "] "); + System.out.println(tasks[i].getDescription()); } } else if (stringSplit[0].equals("done")) { int done = Integer.parseInt(stringSplit[1]); - isDone[done] = true; + tasks[done].markAsDone(); System.out.println(" Nice! I've marked this task as done: "); - System.out.println(" [✓] " + lines[done]); + System.out.println(" [\u2713] " + tasks[done].getDescription()); } else { - lines[count] = string; + tasks[count] = new Task(string); + System.out.println(" added: " + tasks[count].getDescription()); count++; - System.out.println(" added: " + string); } System.out.println(" ____________________________________________________________"); string = sc.nextLine(); diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 0000000000..14d5fd9750 --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,25 @@ +public class Task { + protected String description; + protected boolean isDone; + + public Task(String description) { + this.description = description; + this.isDone = false; + } + + public String getStatusIcon() { + return (isDone ? "\u2713" : "\u2718"); //return tick or X symbols + } + + public void markAsDone() { + this.isDone = true; + } + + public String getDescription() { + return this.description; + } + + public boolean getIsDone() { + return this.isDone; + } +} From 19ae450d7a33f665328ae435d600b8cb44b58a79 Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Fri, 31 Jan 2020 21:45:57 +0800 Subject: [PATCH 06/45] Completed tweaking the code to comply with a coding standard (A-CodingStandard) --- src/main/java/Duke.java | 2 +- src/main/java/Task.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5630a869f6..f8a9873898 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -23,7 +23,7 @@ public static void main(String[] args) { int done = Integer.parseInt(stringSplit[1]); tasks[done].markAsDone(); System.out.println(" Nice! I've marked this task as done: "); - System.out.println(" [\u2713] " + tasks[done].getDescription()); + System.out.println(" [\u2713] " + tasks[done].getDescription()); //return tick symbol } else { tasks[count] = new Task(string); System.out.println(" added: " + tasks[count].getDescription()); diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 14d5fd9750..ade15f1a85 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -11,6 +11,7 @@ public String getStatusIcon() { return (isDone ? "\u2713" : "\u2718"); //return tick or X symbols } + // Not immutable version public void markAsDone() { this.isDone = true; } From 87cd5ff8056e25f7c3607e55d738380eec3a7b6e Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Sun, 2 Feb 2020 18:39:36 +0800 Subject: [PATCH 07/45] Completed Level-4: ToDo, Event, Deadline --- src/main/java/Deadline.java | 11 +++++++ src/main/java/Duke.java | 64 ++++++++++++++++++++++++++++--------- src/main/java/Event.java | 12 +++++++ src/main/java/Task.java | 4 +++ src/main/java/Todo.java | 9 ++++++ 5 files changed, 85 insertions(+), 15 deletions(-) create mode 100644 src/main/java/Deadline.java create mode 100644 src/main/java/Event.java create mode 100644 src/main/java/Todo.java diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java new file mode 100644 index 0000000000..8bb3a376dd --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,11 @@ +public class Deadline extends Task { + String date; + public Deadline(String description, String date) { + super(description); + this.date = date; + } + + public String toString() { + return "[D]" + super.toString() + " (by: " + this.date + ")"; + } +} diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index f8a9873898..717a0f5471 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,39 +1,73 @@ import java.util.Scanner; +import java.util.Arrays; public class Duke { public static void main(String[] args) { Task[] tasks = new Task[100]; - int count = 1; + int count = 0; + boolean isBye = false; System.out.println(" ____________________________________________________________"); System.out.println(" Hello! I'm Duke"); System.out.println(" What can I do for you?"); System.out.println(" ____________________________________________________________"); Scanner sc = new Scanner(System.in); - String string = sc.nextLine(); - while (!string.equals("bye")) { + while (!isBye) { + String description; + String date; + System.out.println(); + String string = sc.nextLine(); System.out.println(" ____________________________________________________________"); String[] stringSplit = string.split(" "); - if (string.equals("list")) { + switch (stringSplit[0]) { + case "list": System.out.println(" Here are the tasks in your list:"); - for (int i = 1; i < count; i++) { - System.out.print(" " + (i) + ".[" + tasks[i].getStatusIcon() + "] "); - System.out.println(tasks[i].getDescription()); + for (int i = 0; i < count; i++) { + System.out.println(" " + (i + 1) + "." + tasks[i].toString()); } - } else if (stringSplit[0].equals("done")) { - int done = Integer.parseInt(stringSplit[1]); + break; + case "done": + int done = Integer.parseInt(stringSplit[1]) - 1; tasks[done].markAsDone(); System.out.println(" Nice! I've marked this task as done: "); - System.out.println(" [\u2713] " + tasks[done].getDescription()); //return tick symbol - } else { + System.out.println(" " + tasks[done].toString()); + break; + case "bye": + System.out.println(" Bye. Hope to see you again soon!"); + isBye = true; + break; + case "todo": + description = String.join(" ", Arrays.copyOfRange(stringSplit, 1, stringSplit.length)); + tasks[count] = new Todo(description); + System.out.println(" Got it. I've added this task: "); + System.out.println(" " + tasks[count].toString()); + count++; + System.out.println(" Now you have " + count + " tasks in the list."); + break; + case "deadline": + description = string.substring(0, string.indexOf(" /by")).replace("deadline ", ""); + date = string.substring(string.indexOf("/by ")).replace("/by ", ""); + tasks[count] = new Deadline(description, date); + System.out.println(" Got it. I've added this task: "); + System.out.println(" " + tasks[count].toString()); + count++; + System.out.println(" Now you have " + count + " tasks in the list."); + break; + case "event": + description = string.substring(0, string.indexOf(" /at")).replace("event ", ""); + date = string.substring(string.indexOf("/at ")).replace("/at ", ""); + tasks[count] = new Event(description, date); + System.out.println(" Got it. I've added this task: "); + System.out.println(" " + tasks[count].toString()); + count++; + System.out.println(" Now you have " + count + " tasks in the list."); + break; + default: //add Task into List tasks[count] = new Task(string); System.out.println(" added: " + tasks[count].getDescription()); count++; + break; } System.out.println(" ____________________________________________________________"); - string = sc.nextLine(); } - System.out.println(" ____________________________________________________________"); - System.out.println(" Bye. Hope to see you again soon!"); - System.out.println(" ____________________________________________________________"); } } diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 0000000000..36d53b9496 --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,12 @@ +public class Event extends Task { + String date; + + public Event(String description, String date) { + super(description); + this.date = date; + } + + public String toString() { + return "[E]" + super.toString() + " (at: " + this.date + ")"; + } +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java index ade15f1a85..76926e9d05 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -23,4 +23,8 @@ public String getDescription() { public boolean getIsDone() { return this.isDone; } + + public String toString() { + return "[" + getStatusIcon() + "] " + getDescription(); + } } diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java new file mode 100644 index 0000000000..421c97a517 --- /dev/null +++ b/src/main/java/Todo.java @@ -0,0 +1,9 @@ +public class Todo extends Task { + public Todo(String description) { + super(description); + } + + public String toString() { + return "[T]" + super.toString(); + } +} From cc313b9f45bb53419978a0f38b327666b761b7c5 Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Tue, 11 Feb 2020 02:13:06 +0800 Subject: [PATCH 08/45] Completed A-TextUiTesting: Automated Text UI Testing --- src/main/java/Duke.java | 34 ++++---- text-ui-test/ACTUAL.TXT | 161 ++++++++++++++++++++++++++++++++++++++ text-ui-test/EXPECTED.txt | 161 ++++++++++++++++++++++++++++++++++++++ text-ui-test/input.txt | 22 ++++++ text-ui-test/runtest.bat | 22 ++++++ 5 files changed, 383 insertions(+), 17 deletions(-) create mode 100644 text-ui-test/ACTUAL.TXT create mode 100644 text-ui-test/EXPECTED.txt create mode 100644 text-ui-test/input.txt create mode 100644 text-ui-test/runtest.bat diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 717a0f5471..31c3046e62 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -4,7 +4,7 @@ public class Duke { public static void main(String[] args) { Task[] tasks = new Task[100]; - int count = 0; + int taskCount = 0; boolean isBye = false; System.out.println(" ____________________________________________________________"); System.out.println(" Hello! I'm Duke"); @@ -21,7 +21,7 @@ public static void main(String[] args) { switch (stringSplit[0]) { case "list": System.out.println(" Here are the tasks in your list:"); - for (int i = 0; i < count; i++) { + for (int i = 0; i < taskCount; i++) { System.out.println(" " + (i + 1) + "." + tasks[i].toString()); } break; @@ -37,34 +37,34 @@ public static void main(String[] args) { break; case "todo": description = String.join(" ", Arrays.copyOfRange(stringSplit, 1, stringSplit.length)); - tasks[count] = new Todo(description); + tasks[taskCount] = new Todo(description); System.out.println(" Got it. I've added this task: "); - System.out.println(" " + tasks[count].toString()); - count++; - System.out.println(" Now you have " + count + " tasks in the list."); + System.out.println(" " + tasks[taskCount].toString()); + taskCount++; + System.out.println(" Now you have " + taskCount + " tasks in the list."); break; case "deadline": description = string.substring(0, string.indexOf(" /by")).replace("deadline ", ""); date = string.substring(string.indexOf("/by ")).replace("/by ", ""); - tasks[count] = new Deadline(description, date); + tasks[taskCount] = new Deadline(description, date); System.out.println(" Got it. I've added this task: "); - System.out.println(" " + tasks[count].toString()); - count++; - System.out.println(" Now you have " + count + " tasks in the list."); + System.out.println(" " + tasks[taskCount].toString()); + taskCount++; + System.out.println(" Now you have " + taskCount + " tasks in the list."); break; case "event": description = string.substring(0, string.indexOf(" /at")).replace("event ", ""); date = string.substring(string.indexOf("/at ")).replace("/at ", ""); - tasks[count] = new Event(description, date); + tasks[taskCount] = new Event(description, date); System.out.println(" Got it. I've added this task: "); - System.out.println(" " + tasks[count].toString()); - count++; - System.out.println(" Now you have " + count + " tasks in the list."); + System.out.println(" " + tasks[taskCount].toString()); + taskCount++; + System.out.println(" Now you have " + taskCount + " tasks in the list."); break; default: //add Task into List - tasks[count] = new Task(string); - System.out.println(" added: " + tasks[count].getDescription()); - count++; + tasks[taskCount] = new Task(string); + System.out.println(" added: " + tasks[taskCount].getDescription()); + taskCount++; break; } System.out.println(" ____________________________________________________________"); diff --git a/text-ui-test/ACTUAL.TXT b/text-ui-test/ACTUAL.TXT new file mode 100644 index 0000000000..fbd1405615 --- /dev/null +++ b/text-ui-test/ACTUAL.TXT @@ -0,0 +1,161 @@ + ____________________________________________________________ + Hello! I'm Duke + What can I do for you? + ____________________________________________________________ + + ____________________________________________________________ + Got it. I've added this task: + [T][✘] read book + Now you have 1 tasks in the list. + ____________________________________________________________ + + ____________________________________________________________ + Got it. I've added this task: + [D][✘] return book (by: June 6th) + Now you have 2 tasks in the list. + ____________________________________________________________ + + ____________________________________________________________ + Got it. I've added this task: + [E][✘] project meeting (at: Aug 6th 2-4pm) + Now you have 3 tasks in the list. + ____________________________________________________________ + + ____________________________________________________________ + Here are the tasks in your list: + 1.[T][✘] read book + 2.[D][✘] return book (by: June 6th) + 3.[E][✘] project meeting (at: Aug 6th 2-4pm) + ____________________________________________________________ + + ____________________________________________________________ + Nice! I've marked this task as done: + [T][✓] read book + ____________________________________________________________ + + ____________________________________________________________ + Got it. I've added this task: + [T][✘] join sports club + Now you have 4 tasks in the list. + ____________________________________________________________ + + ____________________________________________________________ + Here are the tasks in your list: + 1.[T][✓] read book + 2.[D][✘] return book (by: June 6th) + 3.[E][✘] project meeting (at: Aug 6th 2-4pm) + 4.[T][✘] join sports club + ____________________________________________________________ + + ____________________________________________________________ + Nice! I've marked this task as done: + [T][✓] join sports club + ____________________________________________________________ + + ____________________________________________________________ + Got it. I've added this task: + [T][✘] borrow book + Now you have 5 tasks in the list. + ____________________________________________________________ + + ____________________________________________________________ + Here are the tasks in your list: + 1.[T][✓] read book + 2.[D][✘] return book (by: June 6th) + 3.[E][✘] project meeting (at: Aug 6th 2-4pm) + 4.[T][✓] join sports club + 5.[T][✘] borrow book + ____________________________________________________________ + + ____________________________________________________________ + Got it. I've added this task: + [D][✘] return book (by: Sunday) + Now you have 6 tasks in the list. + ____________________________________________________________ + + ____________________________________________________________ + Got it. I've added this task: + [E][✘] project meeting (at: Mon 2-4pm) + Now you have 7 tasks in the list. + ____________________________________________________________ + + ____________________________________________________________ + Here are the tasks in your list: + 1.[T][✓] read book + 2.[D][✘] return book (by: June 6th) + 3.[E][✘] project meeting (at: Aug 6th 2-4pm) + 4.[T][✓] join sports club + 5.[T][✘] borrow book + 6.[D][✘] return book (by: Sunday) + 7.[E][✘] project meeting (at: Mon 2-4pm) + ____________________________________________________________ + + ____________________________________________________________ + Nice! I've marked this task as done: + [T][✓] borrow book + ____________________________________________________________ + + ____________________________________________________________ + Here are the tasks in your list: + 1.[T][✓] read book + 2.[D][✘] return book (by: June 6th) + 3.[E][✘] project meeting (at: Aug 6th 2-4pm) + 4.[T][✓] join sports club + 5.[T][✓] borrow book + 6.[D][✘] return book (by: Sunday) + 7.[E][✘] project meeting (at: Mon 2-4pm) + ____________________________________________________________ + + ____________________________________________________________ + Nice! I've marked this task as done: + [D][✓] return book (by: Sunday) + ____________________________________________________________ + + ____________________________________________________________ + Here are the tasks in your list: + 1.[T][✓] read book + 2.[D][✘] return book (by: June 6th) + 3.[E][✘] project meeting (at: Aug 6th 2-4pm) + 4.[T][✓] join sports club + 5.[T][✓] borrow book + 6.[D][✓] return book (by: Sunday) + 7.[E][✘] project meeting (at: Mon 2-4pm) + ____________________________________________________________ + + ____________________________________________________________ + Nice! I've marked this task as done: + [E][✓] project meeting (at: Mon 2-4pm) + ____________________________________________________________ + + ____________________________________________________________ + Here are the tasks in your list: + 1.[T][✓] read book + 2.[D][✘] return book (by: June 6th) + 3.[E][✘] project meeting (at: Aug 6th 2-4pm) + 4.[T][✓] join sports club + 5.[T][✓] borrow book + 6.[D][✓] return book (by: Sunday) + 7.[E][✓] project meeting (at: Mon 2-4pm) + ____________________________________________________________ + + ____________________________________________________________ + Got it. I've added this task: + [D][✘] do homework (by: no idea :-p) + Now you have 8 tasks in the list. + ____________________________________________________________ + + ____________________________________________________________ + Here are the tasks in your list: + 1.[T][✓] read book + 2.[D][✘] return book (by: June 6th) + 3.[E][✘] project meeting (at: Aug 6th 2-4pm) + 4.[T][✓] join sports club + 5.[T][✓] borrow book + 6.[D][✓] return book (by: Sunday) + 7.[E][✓] project meeting (at: Mon 2-4pm) + 8.[D][✘] do homework (by: no idea :-p) + ____________________________________________________________ + + ____________________________________________________________ + Bye. Hope to see you again soon! + ____________________________________________________________ diff --git a/text-ui-test/EXPECTED.txt b/text-ui-test/EXPECTED.txt new file mode 100644 index 0000000000..fbd1405615 --- /dev/null +++ b/text-ui-test/EXPECTED.txt @@ -0,0 +1,161 @@ + ____________________________________________________________ + Hello! I'm Duke + What can I do for you? + ____________________________________________________________ + + ____________________________________________________________ + Got it. I've added this task: + [T][✘] read book + Now you have 1 tasks in the list. + ____________________________________________________________ + + ____________________________________________________________ + Got it. I've added this task: + [D][✘] return book (by: June 6th) + Now you have 2 tasks in the list. + ____________________________________________________________ + + ____________________________________________________________ + Got it. I've added this task: + [E][✘] project meeting (at: Aug 6th 2-4pm) + Now you have 3 tasks in the list. + ____________________________________________________________ + + ____________________________________________________________ + Here are the tasks in your list: + 1.[T][✘] read book + 2.[D][✘] return book (by: June 6th) + 3.[E][✘] project meeting (at: Aug 6th 2-4pm) + ____________________________________________________________ + + ____________________________________________________________ + Nice! I've marked this task as done: + [T][✓] read book + ____________________________________________________________ + + ____________________________________________________________ + Got it. I've added this task: + [T][✘] join sports club + Now you have 4 tasks in the list. + ____________________________________________________________ + + ____________________________________________________________ + Here are the tasks in your list: + 1.[T][✓] read book + 2.[D][✘] return book (by: June 6th) + 3.[E][✘] project meeting (at: Aug 6th 2-4pm) + 4.[T][✘] join sports club + ____________________________________________________________ + + ____________________________________________________________ + Nice! I've marked this task as done: + [T][✓] join sports club + ____________________________________________________________ + + ____________________________________________________________ + Got it. I've added this task: + [T][✘] borrow book + Now you have 5 tasks in the list. + ____________________________________________________________ + + ____________________________________________________________ + Here are the tasks in your list: + 1.[T][✓] read book + 2.[D][✘] return book (by: June 6th) + 3.[E][✘] project meeting (at: Aug 6th 2-4pm) + 4.[T][✓] join sports club + 5.[T][✘] borrow book + ____________________________________________________________ + + ____________________________________________________________ + Got it. I've added this task: + [D][✘] return book (by: Sunday) + Now you have 6 tasks in the list. + ____________________________________________________________ + + ____________________________________________________________ + Got it. I've added this task: + [E][✘] project meeting (at: Mon 2-4pm) + Now you have 7 tasks in the list. + ____________________________________________________________ + + ____________________________________________________________ + Here are the tasks in your list: + 1.[T][✓] read book + 2.[D][✘] return book (by: June 6th) + 3.[E][✘] project meeting (at: Aug 6th 2-4pm) + 4.[T][✓] join sports club + 5.[T][✘] borrow book + 6.[D][✘] return book (by: Sunday) + 7.[E][✘] project meeting (at: Mon 2-4pm) + ____________________________________________________________ + + ____________________________________________________________ + Nice! I've marked this task as done: + [T][✓] borrow book + ____________________________________________________________ + + ____________________________________________________________ + Here are the tasks in your list: + 1.[T][✓] read book + 2.[D][✘] return book (by: June 6th) + 3.[E][✘] project meeting (at: Aug 6th 2-4pm) + 4.[T][✓] join sports club + 5.[T][✓] borrow book + 6.[D][✘] return book (by: Sunday) + 7.[E][✘] project meeting (at: Mon 2-4pm) + ____________________________________________________________ + + ____________________________________________________________ + Nice! I've marked this task as done: + [D][✓] return book (by: Sunday) + ____________________________________________________________ + + ____________________________________________________________ + Here are the tasks in your list: + 1.[T][✓] read book + 2.[D][✘] return book (by: June 6th) + 3.[E][✘] project meeting (at: Aug 6th 2-4pm) + 4.[T][✓] join sports club + 5.[T][✓] borrow book + 6.[D][✓] return book (by: Sunday) + 7.[E][✘] project meeting (at: Mon 2-4pm) + ____________________________________________________________ + + ____________________________________________________________ + Nice! I've marked this task as done: + [E][✓] project meeting (at: Mon 2-4pm) + ____________________________________________________________ + + ____________________________________________________________ + Here are the tasks in your list: + 1.[T][✓] read book + 2.[D][✘] return book (by: June 6th) + 3.[E][✘] project meeting (at: Aug 6th 2-4pm) + 4.[T][✓] join sports club + 5.[T][✓] borrow book + 6.[D][✓] return book (by: Sunday) + 7.[E][✓] project meeting (at: Mon 2-4pm) + ____________________________________________________________ + + ____________________________________________________________ + Got it. I've added this task: + [D][✘] do homework (by: no idea :-p) + Now you have 8 tasks in the list. + ____________________________________________________________ + + ____________________________________________________________ + Here are the tasks in your list: + 1.[T][✓] read book + 2.[D][✘] return book (by: June 6th) + 3.[E][✘] project meeting (at: Aug 6th 2-4pm) + 4.[T][✓] join sports club + 5.[T][✓] borrow book + 6.[D][✓] return book (by: Sunday) + 7.[E][✓] project meeting (at: Mon 2-4pm) + 8.[D][✘] do homework (by: no idea :-p) + ____________________________________________________________ + + ____________________________________________________________ + Bye. Hope to see you again soon! + ____________________________________________________________ diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt new file mode 100644 index 0000000000..fcaa1ebbcf --- /dev/null +++ b/text-ui-test/input.txt @@ -0,0 +1,22 @@ +todo read book +deadline return book /by June 6th +event project meeting /at Aug 6th 2-4pm +list +done 1 +todo join sports club +list +done 4 +todo borrow book +list +deadline return book /by Sunday +event project meeting /at Mon 2-4pm +list +done 5 +list +done 6 +list +done 7 +list +deadline do homework /by no idea :-p +list +bye diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat new file mode 100644 index 0000000000..7b5c846ca8 --- /dev/null +++ b/text-ui-test/runtest.bat @@ -0,0 +1,22 @@ +@ECHO OFF + +REM create bin directory if it doesn't exist +if not exist ..\bin mkdir ..\bin + +REM delete output from previous run +del ACTUAL.TXT + +REM compile the code into the bin folder +javac -cp ..\src -Xlint:none -d ..\bin ..\src\main\java\*.java +IF ERRORLEVEL 1 ( + echo ********** BUILD FAILURE ********** + exit /b 1 +) +REM no error here, errorlevel == 0 + +REM run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT +REM java -classpath ..\bin Duke < input.txt > ACTUAL.TXT +java -Dfile.encoding=UTF-8 -classpath ..\bin Duke < input.txt > ACTUAL.TXT + +REM compare the output to the expected output +FC ACTUAL.TXT EXPECTED.TXT From 5baf6ea775f262864aa04d584244643b3285b4cf Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Tue, 11 Feb 2020 10:00:15 +0800 Subject: [PATCH 09/45] A-CodeQuality: Improve Code Quality through refracting codes as well as made changes according to the feedbacks given --- src/main/java/Duke.java | 34 ++++++++++++++++++++++++++++++---- text-ui-test/ACTUAL.TXT | 18 ++++++++++++++++++ text-ui-test/EXPECTED.txt | 18 ++++++++++++++++++ 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 31c3046e62..3c08384694 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -6,10 +6,7 @@ public static void main(String[] args) { Task[] tasks = new Task[100]; int taskCount = 0; boolean isBye = false; - System.out.println(" ____________________________________________________________"); - System.out.println(" Hello! I'm Duke"); - System.out.println(" What can I do for you?"); - System.out.println(" ____________________________________________________________"); + greetUser(); Scanner sc = new Scanner(System.in); while (!isBye) { String description; @@ -70,4 +67,33 @@ public static void main(String[] args) { System.out.println(" ____________________________________________________________"); } } + + public static void greetUser() { + System.out.println(" ____________________________________________________________"); + System.out.println(" Hello! I'm Duke"); + commandList(); + System.out.println(" What can I do for you?"); + System.out.println(" ____________________________________________________________"); + } + + public static void commandList() { + System.out.println(" Here is the list of commands that are available:"); + System.out.println("+---------------------------------------------------------------+"); + System.out.println("| Index | Input | Command |"); + System.out.println("|-------+------------------+------------------------------------|"); + System.out.println("| 01 | list | List out all the stored task |"); + System.out.println("|-------+------------------+------------------------------------|"); + System.out.println("| 02 | done i | Mark task i as done |"); + System.out.println("|-------+------------------+------------------------------------|"); + System.out.println("| 03 | bye | Terminate the program |"); + System.out.println("|-------+------------------+------------------------------------|"); + System.out.println("| 04 | todo j | Add a task(j) without dateline |"); + System.out.println("|-------+------------------+------------------------------------|"); + System.out.println("| 05 | dateline j /by d | Add a task(j) with due date d |"); + System.out.println("|-------+------------------+------------------------------------|"); + System.out.println("| 06 | event j /at d | Add a task(j) that start at date d |"); + System.out.println("|-------+------------------+------------------------------------|"); + System.out.println("| 07 | j | Add a task(j) |"); + System.out.println("|---------------------------------------------------------------|"); + } } diff --git a/text-ui-test/ACTUAL.TXT b/text-ui-test/ACTUAL.TXT index fbd1405615..0cabdf3de3 100644 --- a/text-ui-test/ACTUAL.TXT +++ b/text-ui-test/ACTUAL.TXT @@ -1,5 +1,23 @@ ____________________________________________________________ Hello! I'm Duke + Here is the list of commands that are available: ++---------------------------------------------------------------+ +| Index | Input | Command | +|-------+------------------+------------------------------------| +| 01 | list | List out all the stored task | +|-------+------------------+------------------------------------| +| 02 | done i | Mark task i as done | +|-------+------------------+------------------------------------| +| 03 | bye | Terminate the program | +|-------+------------------+------------------------------------| +| 04 | todo j | Add a task(j) without dateline | +|-------+------------------+------------------------------------| +| 05 | dateline j /by d | Add a task(j) with due date d | +|-------+------------------+------------------------------------| +| 06 | event j /at d | Add a task(j) that start at date d | +|-------+------------------+------------------------------------| +| 07 | j | Add a task(j) | +|---------------------------------------------------------------| What can I do for you? ____________________________________________________________ diff --git a/text-ui-test/EXPECTED.txt b/text-ui-test/EXPECTED.txt index fbd1405615..0cabdf3de3 100644 --- a/text-ui-test/EXPECTED.txt +++ b/text-ui-test/EXPECTED.txt @@ -1,5 +1,23 @@ ____________________________________________________________ Hello! I'm Duke + Here is the list of commands that are available: ++---------------------------------------------------------------+ +| Index | Input | Command | +|-------+------------------+------------------------------------| +| 01 | list | List out all the stored task | +|-------+------------------+------------------------------------| +| 02 | done i | Mark task i as done | +|-------+------------------+------------------------------------| +| 03 | bye | Terminate the program | +|-------+------------------+------------------------------------| +| 04 | todo j | Add a task(j) without dateline | +|-------+------------------+------------------------------------| +| 05 | dateline j /by d | Add a task(j) with due date d | +|-------+------------------+------------------------------------| +| 06 | event j /at d | Add a task(j) that start at date d | +|-------+------------------+------------------------------------| +| 07 | j | Add a task(j) | +|---------------------------------------------------------------| What can I do for you? ____________________________________________________________ From a9bead2aab02be0f3313493d42703973ea81ad32 Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Tue, 11 Feb 2020 22:04:42 +0800 Subject: [PATCH 10/45] Refracted case list, done & bye into methods. Added Exceptions for list, done & bye --- src/main/java/Duke.java | 139 +++++++++++++++-------- src/main/java/DukeArgumentException.java | 5 + src/main/java/DukeIndexException.java | 5 + 3 files changed, 102 insertions(+), 47 deletions(-) create mode 100644 src/main/java/DukeArgumentException.java create mode 100644 src/main/java/DukeIndexException.java diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 3c08384694..1dc150da26 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -15,59 +15,104 @@ public static void main(String[] args) { String string = sc.nextLine(); System.out.println(" ____________________________________________________________"); String[] stringSplit = string.split(" "); - switch (stringSplit[0]) { - case "list": - System.out.println(" Here are the tasks in your list:"); - for (int i = 0; i < taskCount; i++) { - System.out.println(" " + (i + 1) + "." + tasks[i].toString()); + try { + switch (stringSplit[0]) { + case "list": + listCommand(tasks, stringSplit, taskCount); + break; + case "done": + doneCommand(tasks, stringSplit, taskCount); + break; + case "bye": + isBye = byeCommand(stringSplit); + break; + case "todo": + description = String.join(" ", Arrays.copyOfRange(stringSplit, 1, stringSplit.length)); + tasks[taskCount] = new Todo(description); + System.out.println(" Got it. I've added this task: "); + System.out.println(" " + tasks[taskCount].toString()); + taskCount++; + System.out.println(" Now you have " + taskCount + " tasks in the list."); + break; + case "deadline": + description = string.substring(0, string.indexOf(" /by")).replace("deadline ", ""); + date = string.substring(string.indexOf("/by ")).replace("/by ", ""); + tasks[taskCount] = new Deadline(description, date); + System.out.println(" Got it. I've added this task: "); + System.out.println(" " + tasks[taskCount].toString()); + taskCount++; + System.out.println(" Now you have " + taskCount + " tasks in the list."); + break; + case "event": + description = string.substring(0, string.indexOf(" /at")).replace("event ", ""); + date = string.substring(string.indexOf("/at ")).replace("/at ", ""); + tasks[taskCount] = new Event(description, date); + System.out.println(" Got it. I've added this task: "); + System.out.println(" " + tasks[taskCount].toString()); + taskCount++; + System.out.println(" Now you have " + taskCount + " tasks in the list."); + break; + default: //add Task into List + tasks[taskCount] = new Task(string); + System.out.println(" added: " + tasks[taskCount].getDescription()); + taskCount++; + break; } - break; - case "done": - int done = Integer.parseInt(stringSplit[1]) - 1; - tasks[done].markAsDone(); - System.out.println(" Nice! I've marked this task as done: "); - System.out.println(" " + tasks[done].toString()); - break; - case "bye": - System.out.println(" Bye. Hope to see you again soon!"); - isBye = true; - break; - case "todo": - description = String.join(" ", Arrays.copyOfRange(stringSplit, 1, stringSplit.length)); - tasks[taskCount] = new Todo(description); - System.out.println(" Got it. I've added this task: "); - System.out.println(" " + tasks[taskCount].toString()); - taskCount++; - System.out.println(" Now you have " + taskCount + " tasks in the list."); - break; - case "deadline": - description = string.substring(0, string.indexOf(" /by")).replace("deadline ", ""); - date = string.substring(string.indexOf("/by ")).replace("/by ", ""); - tasks[taskCount] = new Deadline(description, date); - System.out.println(" Got it. I've added this task: "); - System.out.println(" " + tasks[taskCount].toString()); - taskCount++; - System.out.println(" Now you have " + taskCount + " tasks in the list."); - break; - case "event": - description = string.substring(0, string.indexOf(" /at")).replace("event ", ""); - date = string.substring(string.indexOf("/at ")).replace("/at ", ""); - tasks[taskCount] = new Event(description, date); - System.out.println(" Got it. I've added this task: "); - System.out.println(" " + tasks[taskCount].toString()); - taskCount++; - System.out.println(" Now you have " + taskCount + " tasks in the list."); - break; - default: //add Task into List - tasks[taskCount] = new Task(string); - System.out.println(" added: " + tasks[taskCount].getDescription()); - taskCount++; - break; + } catch (DukeArgumentException e) { + System.out.println(e.getMessage()); + } catch (DukeIndexException e) { + System.out.println(e.getMessage()); } System.out.println(" ____________________________________________________________"); } } + public static boolean byeCommand(String[] stringSplit) throws DukeArgumentException { + if (stringSplit.length > 1) { + throw new DukeArgumentException(" ☹ OOPS!!! Description not required after bye."); + } + + System.out.println(" Bye. Hope to see you again soon!"); + return true; + } + + public static void doneCommand(Task[] tasks, String[] stringSplit, int taskCount) throws + DukeArgumentException, DukeIndexException { + int completedTask; + if (stringSplit.length == 1) { + throw new DukeArgumentException(" ☹ OOPS!!! Missing index after done."); + } else { + completedTask = Integer.parseInt(stringSplit[1]) - 1; + } + + if (completedTask >= taskCount) { + throw new DukeIndexException(" ☹ OOPS!!! Invalid index after done."); + } else { + System.out.println("done is: " + completedTask); + System.out.println("taskCount is: " + taskCount); + tasks[completedTask].markAsDone(); + System.out.println(" Nice! I've marked this task as done: "); + System.out.println(" " + tasks[completedTask].toString()); + } + } + + public static void listCommand(Task[] tasks, String[] stringSplit, int taskCount) throws DukeArgumentException { + if (stringSplit.length > 1) { + throw new DukeArgumentException(" ☹ OOPS!!! Description not required after list."); + } + + switch (taskCount) { + case 0: + System.out.println(" There are currently no tasks in your list"); + break; + default: + System.out.println(" Here are the tasks in your list:"); + for (int i = 0; i < taskCount; i++) { + System.out.println(" " + (i + 1) + "." + tasks[i].toString()); + } + } + } + public static void greetUser() { System.out.println(" ____________________________________________________________"); System.out.println(" Hello! I'm Duke"); diff --git a/src/main/java/DukeArgumentException.java b/src/main/java/DukeArgumentException.java new file mode 100644 index 0000000000..4b1d5fd4f0 --- /dev/null +++ b/src/main/java/DukeArgumentException.java @@ -0,0 +1,5 @@ +public class DukeArgumentException extends IllegalArgumentException { + public DukeArgumentException(String message) { + super(message); + } +} diff --git a/src/main/java/DukeIndexException.java b/src/main/java/DukeIndexException.java new file mode 100644 index 0000000000..68d0ba54cb --- /dev/null +++ b/src/main/java/DukeIndexException.java @@ -0,0 +1,5 @@ +public class DukeIndexException extends IndexOutOfBoundsException { + public DukeIndexException(String message) { + super(message); + } +} From 8e9ad008d8cc36b9de161d2950050df0da9aaa74 Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Thu, 13 Feb 2020 11:48:24 +0800 Subject: [PATCH 11/45] Completed A-Exceptions. Refracted and added exception for todo, deadline, event, default. Updated input and expected file --- src/main/java/Duke.java | 141 +++++++++++++++++---------- src/main/java/DukeNullException.java | 5 + text-ui-test/ACTUAL.TXT | 58 +++++++++++ text-ui-test/EXPECTED.txt | 58 +++++++++++ text-ui-test/input.txt | 10 ++ 5 files changed, 218 insertions(+), 54 deletions(-) create mode 100644 src/main/java/DukeNullException.java diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 1dc150da26..ab62f853aa 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -6,70 +6,107 @@ public static void main(String[] args) { Task[] tasks = new Task[100]; int taskCount = 0; boolean isBye = false; - greetUser(); Scanner sc = new Scanner(System.in); + greetUser(); while (!isBye) { - String description; - String date; System.out.println(); String string = sc.nextLine(); System.out.println(" ____________________________________________________________"); String[] stringSplit = string.split(" "); try { switch (stringSplit[0]) { - case "list": - listCommand(tasks, stringSplit, taskCount); - break; - case "done": - doneCommand(tasks, stringSplit, taskCount); - break; - case "bye": - isBye = byeCommand(stringSplit); - break; - case "todo": - description = String.join(" ", Arrays.copyOfRange(stringSplit, 1, stringSplit.length)); - tasks[taskCount] = new Todo(description); - System.out.println(" Got it. I've added this task: "); - System.out.println(" " + tasks[taskCount].toString()); - taskCount++; - System.out.println(" Now you have " + taskCount + " tasks in the list."); - break; - case "deadline": - description = string.substring(0, string.indexOf(" /by")).replace("deadline ", ""); - date = string.substring(string.indexOf("/by ")).replace("/by ", ""); - tasks[taskCount] = new Deadline(description, date); - System.out.println(" Got it. I've added this task: "); - System.out.println(" " + tasks[taskCount].toString()); - taskCount++; - System.out.println(" Now you have " + taskCount + " tasks in the list."); - break; - case "event": - description = string.substring(0, string.indexOf(" /at")).replace("event ", ""); - date = string.substring(string.indexOf("/at ")).replace("/at ", ""); - tasks[taskCount] = new Event(description, date); - System.out.println(" Got it. I've added this task: "); - System.out.println(" " + tasks[taskCount].toString()); - taskCount++; - System.out.println(" Now you have " + taskCount + " tasks in the list."); - break; - default: //add Task into List - tasks[taskCount] = new Task(string); - System.out.println(" added: " + tasks[taskCount].getDescription()); - taskCount++; - break; + case "list": + listCommand(tasks, stringSplit, taskCount); + break; + case "done": + doneCommand(tasks, stringSplit, taskCount); + break; + case "bye": + isBye = byeCommand(stringSplit); + break; + case "todo": + taskCount = todoCommand(tasks, stringSplit, taskCount); + break; + case "deadline": + taskCount = deadlineCommand(tasks, taskCount, string); + break; + case "event": + taskCount = eventCommand(tasks, taskCount, string); + break; + default: //add Task into List + throw new DukeNullException(" \u2639 OOPS!!! Command does not exist."); } } catch (DukeArgumentException e) { System.out.println(e.getMessage()); } catch (DukeIndexException e) { System.out.println(e.getMessage()); + } catch (DukeNullException e) { + System.out.println(e.getMessage()); + commandList(); + } finally { + System.out.println(" ____________________________________________________________"); } - System.out.println(" ____________________________________________________________"); } } + public static int eventCommand(Task[] tasks, int taskCount, String string) { + if (string.length() == 5) { + throw new DukeArgumentException(" \u2639 OOPS!!! Missing description for event."); + } + if (!string.contains("/at")) { + throw new DukeArgumentException(" \u2639 OOPS!!! Missing date for event."); + } + + String description; + String date; + description = string.substring(0, string.indexOf(" /at")).replace("event ", ""); + date = string.substring(string.indexOf("/at ")).replace("/at ", ""); + tasks[taskCount] = new Event(description, date); + System.out.println(" Got it. I've added this task: "); + System.out.println(" " + tasks[taskCount].toString()); + taskCount++; + System.out.println(" Now you have " + taskCount + " tasks in the list."); + return taskCount; + } + + public static int deadlineCommand(Task[] tasks, int taskCount, String string) { + if (string.length() == 8) { + throw new DukeArgumentException(" \u2639 OOPS!!! Missing description for deadline."); + } + if (!string.contains("/by")) { + throw new DukeArgumentException(" \u2639 OOPS!!! Missing date for deadline."); + } + + String description; + String date; + description = string.substring(0, string.indexOf(" /by")).replace("deadline ", ""); + date = string.substring(string.indexOf("/by ")).replace("/by ", ""); + tasks[taskCount] = new Deadline(description, date); + System.out.println(" Got it. I've added this task: "); + System.out.println(" " + tasks[taskCount].toString()); + taskCount++; + System.out.println(" Now you have " + taskCount + " tasks in the list."); + return taskCount; + } + + public static int todoCommand(Task[] tasks, String[] stringSplit, int taskCount) throws DukeArgumentException { + if (stringSplit.length == 1) { + throw new DukeArgumentException(" \u2639 OOPS!!! Missing description for todo."); + } + + String description; + description = String.join(" ", Arrays.copyOfRange(stringSplit, 1, stringSplit.length)); + tasks[taskCount] = new Todo(description); + System.out.println(" Got it. I've added this task: "); + System.out.println(" " + tasks[taskCount].toString()); + taskCount++; + System.out.println(" Now you have " + taskCount + " tasks in the list."); + return taskCount; + } + public static boolean byeCommand(String[] stringSplit) throws DukeArgumentException { if (stringSplit.length > 1) { - throw new DukeArgumentException(" ☹ OOPS!!! Description not required after bye."); + throw new DukeArgumentException(" \u2639 OOPS!!! Description not required for bye."); } System.out.println(" Bye. Hope to see you again soon!"); @@ -80,16 +117,14 @@ public static void doneCommand(Task[] tasks, String[] stringSplit, int taskCount DukeArgumentException, DukeIndexException { int completedTask; if (stringSplit.length == 1) { - throw new DukeArgumentException(" ☹ OOPS!!! Missing index after done."); + throw new DukeArgumentException(" \u2639 OOPS!!! Missing index for done."); } else { completedTask = Integer.parseInt(stringSplit[1]) - 1; } if (completedTask >= taskCount) { - throw new DukeIndexException(" ☹ OOPS!!! Invalid index after done."); + throw new DukeIndexException(" \u2639 OOPS!!! Invalid index for done."); } else { - System.out.println("done is: " + completedTask); - System.out.println("taskCount is: " + taskCount); tasks[completedTask].markAsDone(); System.out.println(" Nice! I've marked this task as done: "); System.out.println(" " + tasks[completedTask].toString()); @@ -98,14 +133,12 @@ public static void doneCommand(Task[] tasks, String[] stringSplit, int taskCount public static void listCommand(Task[] tasks, String[] stringSplit, int taskCount) throws DukeArgumentException { if (stringSplit.length > 1) { - throw new DukeArgumentException(" ☹ OOPS!!! Description not required after list."); + throw new DukeArgumentException(" \u2639 OOPS!!! Description not required for list."); } - switch (taskCount) { - case 0: + if (taskCount == 0) { System.out.println(" There are currently no tasks in your list"); - break; - default: + } else { System.out.println(" Here are the tasks in your list:"); for (int i = 0; i < taskCount; i++) { System.out.println(" " + (i + 1) + "." + tasks[i].toString()); diff --git a/src/main/java/DukeNullException.java b/src/main/java/DukeNullException.java new file mode 100644 index 0000000000..30ed98c849 --- /dev/null +++ b/src/main/java/DukeNullException.java @@ -0,0 +1,5 @@ +public class DukeNullException extends NullPointerException { + public DukeNullException(String message) { + super(message); + } +} diff --git a/text-ui-test/ACTUAL.TXT b/text-ui-test/ACTUAL.TXT index 0cabdf3de3..d3c87ce322 100644 --- a/text-ui-test/ACTUAL.TXT +++ b/text-ui-test/ACTUAL.TXT @@ -174,6 +174,64 @@ 8.[D][✘] do homework (by: no idea :-p) ____________________________________________________________ + ____________________________________________________________ + ☹ OOPS!!! Description not required for list. + ____________________________________________________________ + + ____________________________________________________________ + ☹ OOPS!!! Missing index for done. + ____________________________________________________________ + + ____________________________________________________________ + ☹ OOPS!!! Invalid index for done. + ____________________________________________________________ + + ____________________________________________________________ + ☹ OOPS!!! Description not required for bye. + ____________________________________________________________ + + ____________________________________________________________ + ☹ OOPS!!! Missing description for todo. + ____________________________________________________________ + + ____________________________________________________________ + ☹ OOPS!!! Missing description for deadline. + ____________________________________________________________ + + ____________________________________________________________ + ☹ OOPS!!! Missing date for deadline. + ____________________________________________________________ + + ____________________________________________________________ + ☹ OOPS!!! Missing description for event. + ____________________________________________________________ + + ____________________________________________________________ + ☹ OOPS!!! Missing date for event. + ____________________________________________________________ + + ____________________________________________________________ + ☹ OOPS!!! Command does not exist. + Here is the list of commands that are available: ++---------------------------------------------------------------+ +| Index | Input | Command | +|-------+------------------+------------------------------------| +| 01 | list | List out all the stored task | +|-------+------------------+------------------------------------| +| 02 | done i | Mark task i as done | +|-------+------------------+------------------------------------| +| 03 | bye | Terminate the program | +|-------+------------------+------------------------------------| +| 04 | todo j | Add a task(j) without dateline | +|-------+------------------+------------------------------------| +| 05 | dateline j /by d | Add a task(j) with due date d | +|-------+------------------+------------------------------------| +| 06 | event j /at d | Add a task(j) that start at date d | +|-------+------------------+------------------------------------| +| 07 | j | Add a task(j) | +|---------------------------------------------------------------| + ____________________________________________________________ + ____________________________________________________________ Bye. Hope to see you again soon! ____________________________________________________________ diff --git a/text-ui-test/EXPECTED.txt b/text-ui-test/EXPECTED.txt index 0cabdf3de3..d3c87ce322 100644 --- a/text-ui-test/EXPECTED.txt +++ b/text-ui-test/EXPECTED.txt @@ -174,6 +174,64 @@ 8.[D][✘] do homework (by: no idea :-p) ____________________________________________________________ + ____________________________________________________________ + ☹ OOPS!!! Description not required for list. + ____________________________________________________________ + + ____________________________________________________________ + ☹ OOPS!!! Missing index for done. + ____________________________________________________________ + + ____________________________________________________________ + ☹ OOPS!!! Invalid index for done. + ____________________________________________________________ + + ____________________________________________________________ + ☹ OOPS!!! Description not required for bye. + ____________________________________________________________ + + ____________________________________________________________ + ☹ OOPS!!! Missing description for todo. + ____________________________________________________________ + + ____________________________________________________________ + ☹ OOPS!!! Missing description for deadline. + ____________________________________________________________ + + ____________________________________________________________ + ☹ OOPS!!! Missing date for deadline. + ____________________________________________________________ + + ____________________________________________________________ + ☹ OOPS!!! Missing description for event. + ____________________________________________________________ + + ____________________________________________________________ + ☹ OOPS!!! Missing date for event. + ____________________________________________________________ + + ____________________________________________________________ + ☹ OOPS!!! Command does not exist. + Here is the list of commands that are available: ++---------------------------------------------------------------+ +| Index | Input | Command | +|-------+------------------+------------------------------------| +| 01 | list | List out all the stored task | +|-------+------------------+------------------------------------| +| 02 | done i | Mark task i as done | +|-------+------------------+------------------------------------| +| 03 | bye | Terminate the program | +|-------+------------------+------------------------------------| +| 04 | todo j | Add a task(j) without dateline | +|-------+------------------+------------------------------------| +| 05 | dateline j /by d | Add a task(j) with due date d | +|-------+------------------+------------------------------------| +| 06 | event j /at d | Add a task(j) that start at date d | +|-------+------------------+------------------------------------| +| 07 | j | Add a task(j) | +|---------------------------------------------------------------| + ____________________________________________________________ + ____________________________________________________________ Bye. Hope to see you again soon! ____________________________________________________________ diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index fcaa1ebbcf..674b000d00 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -19,4 +19,14 @@ done 7 list deadline do homework /by no idea :-p list +list all +done +done 10 +bye there +todo +deadline +deadline complete ip coding +event +event complete ip coding +complete everything bye From 45fee0f6f5f5a429f176d5919835b1bdf3900d26 Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Thu, 13 Feb 2020 14:42:08 +0800 Subject: [PATCH 12/45] Minimum editing to Task's getStatusIcon to make use of getter rather than accessing the Task's isDone property --- src/main/java/Task.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 76926e9d05..f11fd2bc3d 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -8,7 +8,7 @@ public Task(String description) { } public String getStatusIcon() { - return (isDone ? "\u2713" : "\u2718"); //return tick or X symbols + return (getIsDone() ? "\u2713" : "\u2718"); //return tick or X symbols } // Not immutable version From d4b3fdc40244bf2a552584d977ed773d11622639 Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Thu, 13 Feb 2020 15:30:28 +0800 Subject: [PATCH 13/45] Completed A-Packages: Organize into Packages --- README.md | 4 ++-- src/main/java/{ => duke}/Duke.java | 14 ++++++++++++-- .../exception}/DukeArgumentException.java | 2 ++ .../{ => duke/exception}/DukeIndexException.java | 2 ++ .../{ => duke/exception}/DukeNullException.java | 2 ++ src/main/java/{ => duke/task}/Deadline.java | 2 ++ src/main/java/{ => duke/task}/Event.java | 2 ++ src/main/java/{ => duke/task}/Task.java | 2 ++ src/main/java/{ => duke/task}/Todo.java | 2 ++ text-ui-test/ACTUAL.TXT | 2 +- text-ui-test/EXPECTED.txt | 2 +- text-ui-test/runtest.bat | 4 ++-- tutorials/gradleTutorial.md | 6 +++--- tutorials/javaFxTutorialPart1.md | 6 +++--- tutorials/javaFxTutorialPart2.md | 16 ++++++++-------- tutorials/javaFxTutorialPart3.md | 14 +++++++------- tutorials/javaFxTutorialPart4.md | 12 ++++++------ tutorials/textUiTestingTutorial.md | 8 ++++---- 18 files changed, 63 insertions(+), 39 deletions(-) rename src/main/java/{ => duke}/Duke.java (95%) rename src/main/java/{ => duke/exception}/DukeArgumentException.java (85%) rename src/main/java/{ => duke/exception}/DukeIndexException.java (85%) rename src/main/java/{ => duke/exception}/DukeNullException.java (84%) rename src/main/java/{ => duke/task}/Deadline.java (93%) rename src/main/java/{ => duke/task}/Event.java (93%) rename src/main/java/{ => duke/task}/Task.java (97%) rename src/main/java/{ => duke/task}/Todo.java (90%) diff --git a/README.md b/README.md index 84755485a7..5dc79b47cb 100644 --- a/README.md +++ b/README.md @@ -22,11 +22,11 @@ # Tutorials -Duke Increment | Tutorial +duke.Duke Increment | Tutorial ---------------|--------------- `A-Gradle` | [Gradle Tutorial](tutorials/gradleTutorial.md) `A-TextUiTesting` | [Text UI Testing Tutorial](tutorials/textUiTestingTutorial.md) -`Level-10` | JavaFX tutorials:
→ [Part 1: Introduction to JavaFX][fx1]
→ [Part 2: Creating a GUI for Duke][fx2]
→ [Part 3: Interacting with the user][fx3]
→ [Part 4: Introduction to FXML][fx4] +`Level-10` | JavaFX tutorials:
→ [Part 1: Introduction to JavaFX][fx1]
→ [Part 2: Creating a GUI for duke.Duke][fx2]
→ [Part 3: Interacting with the user][fx3]
→ [Part 4: Introduction to FXML][fx4] [fx1]: [fx2]: diff --git a/src/main/java/Duke.java b/src/main/java/duke/Duke.java similarity index 95% rename from src/main/java/Duke.java rename to src/main/java/duke/Duke.java index ab62f853aa..5f149994d6 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,3 +1,13 @@ +package duke; + +import duke.exception.DukeArgumentException; +import duke.exception.DukeIndexException; +import duke.exception.DukeNullException; +import duke.task.Deadline; +import duke.task.Event; +import duke.task.Task; +import duke.task.Todo; + import java.util.Scanner; import java.util.Arrays; @@ -33,7 +43,7 @@ public static void main(String[] args) { case "event": taskCount = eventCommand(tasks, taskCount, string); break; - default: //add Task into List + default: //add duke.task.Task into List throw new DukeNullException(" \u2639 OOPS!!! Command does not exist."); } } catch (DukeArgumentException e) { @@ -148,7 +158,7 @@ public static void listCommand(Task[] tasks, String[] stringSplit, int taskCount public static void greetUser() { System.out.println(" ____________________________________________________________"); - System.out.println(" Hello! I'm Duke"); + System.out.println(" Hello! I'm duke.Duke"); commandList(); System.out.println(" What can I do for you?"); System.out.println(" ____________________________________________________________"); diff --git a/src/main/java/DukeArgumentException.java b/src/main/java/duke/exception/DukeArgumentException.java similarity index 85% rename from src/main/java/DukeArgumentException.java rename to src/main/java/duke/exception/DukeArgumentException.java index 4b1d5fd4f0..04d20a837f 100644 --- a/src/main/java/DukeArgumentException.java +++ b/src/main/java/duke/exception/DukeArgumentException.java @@ -1,3 +1,5 @@ +package duke.exception; + public class DukeArgumentException extends IllegalArgumentException { public DukeArgumentException(String message) { super(message); diff --git a/src/main/java/DukeIndexException.java b/src/main/java/duke/exception/DukeIndexException.java similarity index 85% rename from src/main/java/DukeIndexException.java rename to src/main/java/duke/exception/DukeIndexException.java index 68d0ba54cb..14c26e3d00 100644 --- a/src/main/java/DukeIndexException.java +++ b/src/main/java/duke/exception/DukeIndexException.java @@ -1,3 +1,5 @@ +package duke.exception; + public class DukeIndexException extends IndexOutOfBoundsException { public DukeIndexException(String message) { super(message); diff --git a/src/main/java/DukeNullException.java b/src/main/java/duke/exception/DukeNullException.java similarity index 84% rename from src/main/java/DukeNullException.java rename to src/main/java/duke/exception/DukeNullException.java index 30ed98c849..332e6975ae 100644 --- a/src/main/java/DukeNullException.java +++ b/src/main/java/duke/exception/DukeNullException.java @@ -1,3 +1,5 @@ +package duke.exception; + public class DukeNullException extends NullPointerException { public DukeNullException(String message) { super(message); diff --git a/src/main/java/Deadline.java b/src/main/java/duke/task/Deadline.java similarity index 93% rename from src/main/java/Deadline.java rename to src/main/java/duke/task/Deadline.java index 8bb3a376dd..ed47c4a0fa 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/duke/task/Deadline.java @@ -1,3 +1,5 @@ +package duke.task; + public class Deadline extends Task { String date; public Deadline(String description, String date) { diff --git a/src/main/java/Event.java b/src/main/java/duke/task/Event.java similarity index 93% rename from src/main/java/Event.java rename to src/main/java/duke/task/Event.java index 36d53b9496..e55740e734 100644 --- a/src/main/java/Event.java +++ b/src/main/java/duke/task/Event.java @@ -1,3 +1,5 @@ +package duke.task; + public class Event extends Task { String date; diff --git a/src/main/java/Task.java b/src/main/java/duke/task/Task.java similarity index 97% rename from src/main/java/Task.java rename to src/main/java/duke/task/Task.java index f11fd2bc3d..17815dc5c4 100644 --- a/src/main/java/Task.java +++ b/src/main/java/duke/task/Task.java @@ -1,3 +1,5 @@ +package duke.task; + public class Task { protected String description; protected boolean isDone; diff --git a/src/main/java/Todo.java b/src/main/java/duke/task/Todo.java similarity index 90% rename from src/main/java/Todo.java rename to src/main/java/duke/task/Todo.java index 421c97a517..142da72107 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/duke/task/Todo.java @@ -1,3 +1,5 @@ +package duke.task; + public class Todo extends Task { public Todo(String description) { super(description); diff --git a/text-ui-test/ACTUAL.TXT b/text-ui-test/ACTUAL.TXT index d3c87ce322..0763c508c5 100644 --- a/text-ui-test/ACTUAL.TXT +++ b/text-ui-test/ACTUAL.TXT @@ -1,5 +1,5 @@ ____________________________________________________________ - Hello! I'm Duke + Hello! I'm duke.Duke Here is the list of commands that are available: +---------------------------------------------------------------+ | Index | Input | Command | diff --git a/text-ui-test/EXPECTED.txt b/text-ui-test/EXPECTED.txt index d3c87ce322..0763c508c5 100644 --- a/text-ui-test/EXPECTED.txt +++ b/text-ui-test/EXPECTED.txt @@ -1,5 +1,5 @@ ____________________________________________________________ - Hello! I'm Duke + Hello! I'm duke.Duke Here is the list of commands that are available: +---------------------------------------------------------------+ | Index | Input | Command | diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 7b5c846ca8..38c8ff673c 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -15,8 +15,8 @@ IF ERRORLEVEL 1 ( REM no error here, errorlevel == 0 REM run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT -REM java -classpath ..\bin Duke < input.txt > ACTUAL.TXT -java -Dfile.encoding=UTF-8 -classpath ..\bin Duke < input.txt > ACTUAL.TXT +REM java -classpath ..\bin duke.Duke < input.txt > ACTUAL.TXT +java -Dfile.encoding=UTF-8 -classpath ..\bin duke.Duke < input.txt > ACTUAL.TXT REM compare the output to the expected output FC ACTUAL.TXT EXPECTED.TXT diff --git a/tutorials/gradleTutorial.md b/tutorials/gradleTutorial.md index 08292b118d..2d60727f2b 100644 --- a/tutorials/gradleTutorial.md +++ b/tutorials/gradleTutorial.md @@ -30,10 +30,10 @@ As a developer, you write a _build file_ that describes the project. A build fil git checkout master git merge gradle ``` -1. Open the `build.gradle` file in an editor. Update the following code block to point to the main class (i.e., the one containing the `main` method) of your application. The code below assumes your main class is `seedu.duke.Duke` +1. Open the `build.gradle` file in an editor. Update the following code block to point to the main class (i.e., the one containing the `main` method) of your application. The code below assumes your main class is `seedu.duke.duke.Duke` ```groovy application { - mainClassName = "seedu.duke.Duke" + mainClassName = "seedu.duke.duke.Duke" } ``` 1. To check if Gradle has been added to the project correctly, open a terminal window, navigate to the root directory of your project and run the command `gradlew run`. This should result in Gradle running the main method of your project. @@ -146,7 +146,7 @@ By convention, java tests belong in `src/test/java` folder. Create a new `test/j src ├─main │ └─java -│ └─seedu/duke/Duke.java +│ └─seedu/duke/duke.Duke.java └─test └─java └─seedu/duke/DukeTest.java diff --git a/tutorials/javaFxTutorialPart1.md b/tutorials/javaFxTutorialPart1.md index 561daeca43..ee9db15e82 100644 --- a/tutorials/javaFxTutorialPart1.md +++ b/tutorials/javaFxTutorialPart1.md @@ -44,7 +44,7 @@ javafx { ## Writing your first program -As customary, let’s start off with a simple “Hello World” program. Modify your `Duke` class to extend `javafx.application.Application`. This requires you to override the `Application#start()` method and provide a concrete implementation. Notice that the method signature for `Application#start()` has a parameter `Stage`. This is the _primary stage_ that JavaFX provides. +As customary, let’s start off with a simple “Hello World” program. Modify your `duke.Duke` class to extend `javafx.application.Application`. This requires you to override the `Application#start()` method and provide a concrete implementation. Notice that the method signature for `Application#start()` has a parameter `Stage`. This is the _primary stage_ that JavaFX provides. ```java import javafx.application.Application; @@ -52,7 +52,7 @@ import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.stage.Stage; -public class Duke extends Application { +public class duke.Duke extends Application { // ... @@ -73,7 +73,7 @@ Next, we create another Java class, `Launcher`, as an entry point to our applica The `Launcher` class is reproduced below in its entirety. ```java -import javafx.application.Application; +import duke.Duke;import javafx.application.Application; /** * A launcher class to workaround classpath issues. diff --git a/tutorials/javaFxTutorialPart2.md b/tutorials/javaFxTutorialPart2.md index f24a0cd6ad..ade0b458cd 100644 --- a/tutorials/javaFxTutorialPart2.md +++ b/tutorials/javaFxTutorialPart2.md @@ -1,8 +1,8 @@ -# JavaFX Tutorial Part 2 - Creating a GUI for Duke +# JavaFX Tutorial Part 2 - Creating a GUI for duke.Duke -In this tutorial, we will be creating a GUI for Duke from scratch based on the following mockup. +In this tutorial, we will be creating a GUI for duke.Duke from scratch based on the following mockup. -![Mockup for Duke](assets/DukeMockup.png) +![Mockup for duke.Duke](assets/DukeMockup.png) ## JavaFX controls @@ -34,7 +34,7 @@ But how do we get the exact layout we want in the UI? JavaFX provides that funct One way to obtain the layout in the mockup is as follows. -![Duke's layout](assets/DukeSceneGraph.png) +![duke.Duke's layout](assets/DukeSceneGraph.png) To get that layout, we create a new `AnchorPane` and add our controls to it. Similarly, we create a new `VBox` to hold the contents of the `ScrollPane`. The code should look something like this: @@ -49,7 +49,7 @@ import javafx.scene.layout.VBox; import javafx.stage.Stage; -public class Duke extends Application { +public class duke.Duke extends Application { private ScrollPane scrollPane; private VBox dialogContainer; @@ -88,7 +88,7 @@ public class Duke extends Application { Run the application and you should see something like this: -![Duke's raw layout](assets/RawLayout.png) +![duke.Duke's raw layout](assets/RawLayout.png) That is not what we were expecting, what did we forget to do? @@ -106,7 +106,7 @@ Add the following code to the bottom of the `start` method. You'll have to add ` //... //Step 2. Formatting the window to look as expected - stage.setTitle("Duke"); + stage.setTitle("duke.Duke"); stage.setResizable(false); stage.setMinHeight(600.0); stage.setMinWidth(400.0); @@ -141,7 +141,7 @@ Add the following code to the bottom of the `start` method. You'll have to add ` Run the application again. It should now look like this: -![Duke's Final layout](assets/FinalLayout.png) +![duke.Duke's Final layout](assets/FinalLayout.png) ## Exercises diff --git a/tutorials/javaFxTutorialPart3.md b/tutorials/javaFxTutorialPart3.md index a9e1bdddd3..813079f3fa 100644 --- a/tutorials/javaFxTutorialPart3.md +++ b/tutorials/javaFxTutorialPart3.md @@ -8,7 +8,7 @@ Rather than to do everything in one try, let’s iterate and build up towards ou JavaFX has an _event-driven architecture style_. As such, we programmatically define _handler_ methods to execute as a response to certain _events_. When an event is detected, JavaFX will call the respective handlers. -For Duke, there are two events that we want to respond to, namely the user pressing `Enter` in the `TextField` and left-clicking the `Button`. These are the `onAction` event for the `TextField` and the `onMouseClicked` event for the `Button`. +For duke.Duke, there are two events that we want to respond to, namely the user pressing `Enter` in the `TextField` and left-clicking the `Button`. These are the `onAction` event for the `TextField` and the `onMouseClicked` event for the `Button`. For now, let’s have the application add a new `Label` with the text from the `TextField`. Update the `Main` class as follows. You'll need to add an `import javafx.scene.control.Label;` too. ```java @@ -103,7 +103,7 @@ import javafx.scene.image.ImageView; ``` Next, add two images to the `main/resources/images` folder. -For this tutorial, we have two images `DaUser.png` and `DaDuke.png` to represent the user avatar and Duke's avatar respectively but you can use any image you want. +For this tutorial, we have two images `DaUser.png` and `DaDuke.png` to represent the user avatar and duke.Duke's avatar respectively but you can use any image you want. Image|Filename ---|--- @@ -112,7 +112,7 @@ Image|Filename ```java -public class Duke extends Application { +public class duke.Duke extends Application { // ... private Image user = new Image(this.getClass().getResourceAsStream("/images/DaUser.png")); private Image duke = new Image(this.getClass().getResourceAsStream("/images/DaDuke.png")); @@ -124,7 +124,7 @@ Add a new method to handle user input: ```java /** * Iteration 2: - * Creates two dialog boxes, one echoing user input and the other containing Duke's reply and then appends them to + * Creates two dialog boxes, one echoing user input and the other containing duke.Duke's reply and then appends them to * the dialog container. Clears the user input after processing. */ private void handleUserInput() { @@ -142,7 +142,7 @@ private void handleUserInput() { * Replace this stub with your completed method. */ private String getResponse(String input) { - return "Duke heard: " + input; + return "duke.Duke heard: " + input; } ``` @@ -170,7 +170,7 @@ Run the program and see how it works. ## Iteration 3 – Adding custom behavior to DialogBox -One additional benefit of defining a custom control is that we can add behavior specific to our `DialogBox`. Let’s add a method to flip a dialog box such that the image on the left to differentiate between user input and Duke’s output. +One additional benefit of defining a custom control is that we can add behavior specific to our `DialogBox`. Let’s add a method to flip a dialog box such that the image on the left to differentiate between user input and duke.Duke’s output. ```java /** @@ -224,7 +224,7 @@ Run the application and play around with it. ![DialogBoxes Iteration 3](assets/DialogBoxesIteration3.png) Congratulations! -You have successfully implemented a fully functional GUI for Duke! +You have successfully implemented a fully functional GUI for duke.Duke! ## Exercises diff --git a/tutorials/javaFxTutorialPart4.md b/tutorials/javaFxTutorialPart4.md index 0e0ab280c4..638505a99b 100644 --- a/tutorials/javaFxTutorialPart4.md +++ b/tutorials/javaFxTutorialPart4.md @@ -29,7 +29,7 @@ FXML is a XML-based language that allows us to define our user interface. Proper The FXML snippet define a TextField similar to the one that we programmatically defined previous in Tutorial 2. Notice how concise FXML is compared to the plain Java version. -Let's return to Duke and convert it to use FXML instead. +Let's return to duke.Duke and convert it to use FXML instead. # Rebuilding the Scene using FXML @@ -101,14 +101,14 @@ We will get to that later. ## Using Controllers -As part of the effort to separate the code handling Duke's logic and UI, let's _refactor_ the UI-related code to its own class. +As part of the effort to separate the code handling duke.Duke's logic and UI, let's _refactor_ the UI-related code to its own class. We call these UI classes _controllers_. Let's implement the `MainWindow` controller class that we specified in `MainWindow.fxml`. **MainWindow.java** ```java -import javafx.fxml.FXML; +import duke.Duke;import javafx.fxml.FXML; import javafx.scene.control.Button; import javafx.scene.control.ScrollPane; import javafx.scene.control.TextField; @@ -143,7 +143,7 @@ public class MainWindow extends AnchorPane { } /** - * Creates two dialog boxes, one echoing user input and the other containing Duke's reply and then appends them to + * Creates two dialog boxes, one echoing user input and the other containing duke.Duke's reply and then appends them to * the dialog container. Clears the user input after processing. */ @FXML @@ -168,7 +168,7 @@ Similarly, methods like private methods like `handleUserInput` can be used in FX ## Using FXML in our application -Let's create a new `Main` class as the bridge between the existing logic in `Duke` and the UI in `MainWindow`. +Let's create a new `Main` class as the bridge between the existing logic in `duke.Duke` and the UI in `MainWindow`. **Main.java** ```java @@ -182,7 +182,7 @@ import javafx.scene.layout.AnchorPane; import javafx.stage.Stage; /** - * A GUI for Duke using FXML. + * A GUI for duke.Duke using FXML. */ public class Main extends Application { diff --git a/tutorials/textUiTestingTutorial.md b/tutorials/textUiTestingTutorial.md index f397d76aef..b421fa37da 100644 --- a/tutorials/textUiTestingTutorial.md +++ b/tutorials/textUiTestingTutorial.md @@ -13,7 +13,7 @@ del ACTUAL.TXT REM compile the code into the bin folder - javac -cp ..\src -Xlint:none -d ..\bin ..\src\main\java\Duke.java + javac -cp ..\src -Xlint:none -d ..\bin ..\src\main\java\duke.Duke.java IF ERRORLEVEL 1 ( echo ********** BUILD FAILURE ********** exit /b 1 @@ -21,7 +21,7 @@ REM no error here, errorlevel == 0 REM run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT - java -classpath ..\bin Duke < input.txt > ACTUAL.TXT + java -classpath ..\bin duke.Duke < input.txt > ACTUAL.TXT REM compare the output to the expected output FC ACTUAL.TXT EXPECTED.TXT @@ -44,14 +44,14 @@ fi # compile the code into the bin folder, terminates if error occurred - if ! javac -cp ../src -Xlint:none -d ../bin ../src/main/java/Duke.java + if ! javac -cp ../src -Xlint:none -d ../bin ../src/main/java/duke.Duke.java then echo "********** BUILD FAILURE **********" exit 1 fi # run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT - java -classpath ../bin Duke < input.txt > ACTUAL.TXT + java -classpath ../bin duke.Duke < input.txt > ACTUAL.TXT # compare the output to the expected output diff ACTUAL.TXT EXPECTED.TXT From c38ed0163a8aef58d31d2b61addc9958f8a97064 Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Thu, 13 Feb 2020 16:04:57 +0800 Subject: [PATCH 14/45] Updated input, actual and expected files to make testing more vigorous and structured by including corner cases --- text-ui-test/ACTUAL.TXT | 108 +++++++++++++++----------------------- text-ui-test/EXPECTED.txt | 108 +++++++++++++++----------------------- text-ui-test/input.txt | 15 +++--- 3 files changed, 93 insertions(+), 138 deletions(-) diff --git a/text-ui-test/ACTUAL.TXT b/text-ui-test/ACTUAL.TXT index d3c87ce322..2e23dc562f 100644 --- a/text-ui-test/ACTUAL.TXT +++ b/text-ui-test/ACTUAL.TXT @@ -21,18 +21,33 @@ What can I do for you? ____________________________________________________________ + ____________________________________________________________ + There are currently no tasks in your list + ____________________________________________________________ + ____________________________________________________________ Got it. I've added this task: [T][✘] read book Now you have 1 tasks in the list. ____________________________________________________________ + ____________________________________________________________ + Here are the tasks in your list: + 1.[T][✘] read book + ____________________________________________________________ + ____________________________________________________________ Got it. I've added this task: [D][✘] return book (by: June 6th) Now you have 2 tasks in the list. ____________________________________________________________ + ____________________________________________________________ + Here are the tasks in your list: + 1.[T][✘] read book + 2.[D][✘] return book (by: June 6th) + ____________________________________________________________ + ____________________________________________________________ Got it. I've added this task: [E][✘] project meeting (at: Aug 6th 2-4pm) @@ -51,127 +66,90 @@ [T][✓] read book ____________________________________________________________ - ____________________________________________________________ - Got it. I've added this task: - [T][✘] join sports club - Now you have 4 tasks in the list. - ____________________________________________________________ - ____________________________________________________________ Here are the tasks in your list: 1.[T][✓] read book 2.[D][✘] return book (by: June 6th) 3.[E][✘] project meeting (at: Aug 6th 2-4pm) - 4.[T][✘] join sports club ____________________________________________________________ ____________________________________________________________ Nice! I've marked this task as done: - [T][✓] join sports club - ____________________________________________________________ - - ____________________________________________________________ - Got it. I've added this task: - [T][✘] borrow book - Now you have 5 tasks in the list. + [E][✓] project meeting (at: Aug 6th 2-4pm) ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: 1.[T][✓] read book 2.[D][✘] return book (by: June 6th) - 3.[E][✘] project meeting (at: Aug 6th 2-4pm) - 4.[T][✓] join sports club - 5.[T][✘] borrow book + 3.[E][✓] project meeting (at: Aug 6th 2-4pm) ____________________________________________________________ ____________________________________________________________ Got it. I've added this task: - [D][✘] return book (by: Sunday) - Now you have 6 tasks in the list. + [T][✘] join sports club + Now you have 4 tasks in the list. ____________________________________________________________ ____________________________________________________________ Got it. I've added this task: - [E][✘] project meeting (at: Mon 2-4pm) - Now you have 7 tasks in the list. + [D][✘] return book (by: Sunday) + Now you have 5 tasks in the list. ____________________________________________________________ ____________________________________________________________ - Here are the tasks in your list: - 1.[T][✓] read book - 2.[D][✘] return book (by: June 6th) - 3.[E][✘] project meeting (at: Aug 6th 2-4pm) - 4.[T][✓] join sports club - 5.[T][✘] borrow book - 6.[D][✘] return book (by: Sunday) - 7.[E][✘] project meeting (at: Mon 2-4pm) + Got it. I've added this task: + [E][✘] project meeting (at: Mon 2-4pm) + Now you have 6 tasks in the list. ____________________________________________________________ ____________________________________________________________ - Nice! I've marked this task as done: - [T][✓] borrow book + Got it. I've added this task: + [D][✘] do homework (by: no idea :-p) + Now you have 7 tasks in the list. ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: 1.[T][✓] read book 2.[D][✘] return book (by: June 6th) - 3.[E][✘] project meeting (at: Aug 6th 2-4pm) - 4.[T][✓] join sports club - 5.[T][✓] borrow book - 6.[D][✘] return book (by: Sunday) - 7.[E][✘] project meeting (at: Mon 2-4pm) + 3.[E][✓] project meeting (at: Aug 6th 2-4pm) + 4.[T][✘] join sports club + 5.[D][✘] return book (by: Sunday) + 6.[E][✘] project meeting (at: Mon 2-4pm) + 7.[D][✘] do homework (by: no idea :-p) ____________________________________________________________ ____________________________________________________________ Nice! I've marked this task as done: - [D][✓] return book (by: Sunday) + [D][✓] do homework (by: no idea :-p) ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: 1.[T][✓] read book 2.[D][✘] return book (by: June 6th) - 3.[E][✘] project meeting (at: Aug 6th 2-4pm) - 4.[T][✓] join sports club - 5.[T][✓] borrow book - 6.[D][✓] return book (by: Sunday) - 7.[E][✘] project meeting (at: Mon 2-4pm) + 3.[E][✓] project meeting (at: Aug 6th 2-4pm) + 4.[T][✘] join sports club + 5.[D][✘] return book (by: Sunday) + 6.[E][✘] project meeting (at: Mon 2-4pm) + 7.[D][✓] do homework (by: no idea :-p) ____________________________________________________________ ____________________________________________________________ Nice! I've marked this task as done: - [E][✓] project meeting (at: Mon 2-4pm) - ____________________________________________________________ - - ____________________________________________________________ - Here are the tasks in your list: - 1.[T][✓] read book - 2.[D][✘] return book (by: June 6th) - 3.[E][✘] project meeting (at: Aug 6th 2-4pm) - 4.[T][✓] join sports club - 5.[T][✓] borrow book - 6.[D][✓] return book (by: Sunday) - 7.[E][✓] project meeting (at: Mon 2-4pm) - ____________________________________________________________ - - ____________________________________________________________ - Got it. I've added this task: - [D][✘] do homework (by: no idea :-p) - Now you have 8 tasks in the list. + [T][✓] join sports club ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: 1.[T][✓] read book 2.[D][✘] return book (by: June 6th) - 3.[E][✘] project meeting (at: Aug 6th 2-4pm) + 3.[E][✓] project meeting (at: Aug 6th 2-4pm) 4.[T][✓] join sports club - 5.[T][✓] borrow book - 6.[D][✓] return book (by: Sunday) - 7.[E][✓] project meeting (at: Mon 2-4pm) - 8.[D][✘] do homework (by: no idea :-p) + 5.[D][✘] return book (by: Sunday) + 6.[E][✘] project meeting (at: Mon 2-4pm) + 7.[D][✓] do homework (by: no idea :-p) ____________________________________________________________ ____________________________________________________________ diff --git a/text-ui-test/EXPECTED.txt b/text-ui-test/EXPECTED.txt index d3c87ce322..2e23dc562f 100644 --- a/text-ui-test/EXPECTED.txt +++ b/text-ui-test/EXPECTED.txt @@ -21,18 +21,33 @@ What can I do for you? ____________________________________________________________ + ____________________________________________________________ + There are currently no tasks in your list + ____________________________________________________________ + ____________________________________________________________ Got it. I've added this task: [T][✘] read book Now you have 1 tasks in the list. ____________________________________________________________ + ____________________________________________________________ + Here are the tasks in your list: + 1.[T][✘] read book + ____________________________________________________________ + ____________________________________________________________ Got it. I've added this task: [D][✘] return book (by: June 6th) Now you have 2 tasks in the list. ____________________________________________________________ + ____________________________________________________________ + Here are the tasks in your list: + 1.[T][✘] read book + 2.[D][✘] return book (by: June 6th) + ____________________________________________________________ + ____________________________________________________________ Got it. I've added this task: [E][✘] project meeting (at: Aug 6th 2-4pm) @@ -51,127 +66,90 @@ [T][✓] read book ____________________________________________________________ - ____________________________________________________________ - Got it. I've added this task: - [T][✘] join sports club - Now you have 4 tasks in the list. - ____________________________________________________________ - ____________________________________________________________ Here are the tasks in your list: 1.[T][✓] read book 2.[D][✘] return book (by: June 6th) 3.[E][✘] project meeting (at: Aug 6th 2-4pm) - 4.[T][✘] join sports club ____________________________________________________________ ____________________________________________________________ Nice! I've marked this task as done: - [T][✓] join sports club - ____________________________________________________________ - - ____________________________________________________________ - Got it. I've added this task: - [T][✘] borrow book - Now you have 5 tasks in the list. + [E][✓] project meeting (at: Aug 6th 2-4pm) ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: 1.[T][✓] read book 2.[D][✘] return book (by: June 6th) - 3.[E][✘] project meeting (at: Aug 6th 2-4pm) - 4.[T][✓] join sports club - 5.[T][✘] borrow book + 3.[E][✓] project meeting (at: Aug 6th 2-4pm) ____________________________________________________________ ____________________________________________________________ Got it. I've added this task: - [D][✘] return book (by: Sunday) - Now you have 6 tasks in the list. + [T][✘] join sports club + Now you have 4 tasks in the list. ____________________________________________________________ ____________________________________________________________ Got it. I've added this task: - [E][✘] project meeting (at: Mon 2-4pm) - Now you have 7 tasks in the list. + [D][✘] return book (by: Sunday) + Now you have 5 tasks in the list. ____________________________________________________________ ____________________________________________________________ - Here are the tasks in your list: - 1.[T][✓] read book - 2.[D][✘] return book (by: June 6th) - 3.[E][✘] project meeting (at: Aug 6th 2-4pm) - 4.[T][✓] join sports club - 5.[T][✘] borrow book - 6.[D][✘] return book (by: Sunday) - 7.[E][✘] project meeting (at: Mon 2-4pm) + Got it. I've added this task: + [E][✘] project meeting (at: Mon 2-4pm) + Now you have 6 tasks in the list. ____________________________________________________________ ____________________________________________________________ - Nice! I've marked this task as done: - [T][✓] borrow book + Got it. I've added this task: + [D][✘] do homework (by: no idea :-p) + Now you have 7 tasks in the list. ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: 1.[T][✓] read book 2.[D][✘] return book (by: June 6th) - 3.[E][✘] project meeting (at: Aug 6th 2-4pm) - 4.[T][✓] join sports club - 5.[T][✓] borrow book - 6.[D][✘] return book (by: Sunday) - 7.[E][✘] project meeting (at: Mon 2-4pm) + 3.[E][✓] project meeting (at: Aug 6th 2-4pm) + 4.[T][✘] join sports club + 5.[D][✘] return book (by: Sunday) + 6.[E][✘] project meeting (at: Mon 2-4pm) + 7.[D][✘] do homework (by: no idea :-p) ____________________________________________________________ ____________________________________________________________ Nice! I've marked this task as done: - [D][✓] return book (by: Sunday) + [D][✓] do homework (by: no idea :-p) ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: 1.[T][✓] read book 2.[D][✘] return book (by: June 6th) - 3.[E][✘] project meeting (at: Aug 6th 2-4pm) - 4.[T][✓] join sports club - 5.[T][✓] borrow book - 6.[D][✓] return book (by: Sunday) - 7.[E][✘] project meeting (at: Mon 2-4pm) + 3.[E][✓] project meeting (at: Aug 6th 2-4pm) + 4.[T][✘] join sports club + 5.[D][✘] return book (by: Sunday) + 6.[E][✘] project meeting (at: Mon 2-4pm) + 7.[D][✓] do homework (by: no idea :-p) ____________________________________________________________ ____________________________________________________________ Nice! I've marked this task as done: - [E][✓] project meeting (at: Mon 2-4pm) - ____________________________________________________________ - - ____________________________________________________________ - Here are the tasks in your list: - 1.[T][✓] read book - 2.[D][✘] return book (by: June 6th) - 3.[E][✘] project meeting (at: Aug 6th 2-4pm) - 4.[T][✓] join sports club - 5.[T][✓] borrow book - 6.[D][✓] return book (by: Sunday) - 7.[E][✓] project meeting (at: Mon 2-4pm) - ____________________________________________________________ - - ____________________________________________________________ - Got it. I've added this task: - [D][✘] do homework (by: no idea :-p) - Now you have 8 tasks in the list. + [T][✓] join sports club ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: 1.[T][✓] read book 2.[D][✘] return book (by: June 6th) - 3.[E][✘] project meeting (at: Aug 6th 2-4pm) + 3.[E][✓] project meeting (at: Aug 6th 2-4pm) 4.[T][✓] join sports club - 5.[T][✓] borrow book - 6.[D][✓] return book (by: Sunday) - 7.[E][✓] project meeting (at: Mon 2-4pm) - 8.[D][✘] do homework (by: no idea :-p) + 5.[D][✘] return book (by: Sunday) + 6.[E][✘] project meeting (at: Mon 2-4pm) + 7.[D][✓] do homework (by: no idea :-p) ____________________________________________________________ ____________________________________________________________ diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index 674b000d00..b5e362b781 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -1,23 +1,22 @@ +list todo read book +list deadline return book /by June 6th +list event project meeting /at Aug 6th 2-4pm list done 1 -todo join sports club list -done 4 -todo borrow book +done 3 list +todo join sports club deadline return book /by Sunday event project meeting /at Mon 2-4pm -list -done 5 -list -done 6 +deadline do homework /by no idea :-p list done 7 list -deadline do homework /by no idea :-p +done 4 list list all done From d972c315728a5a0258b80f92b6f2863bada6cdf8 Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Sat, 29 Feb 2020 01:40:33 +0800 Subject: [PATCH 15/45] Commit manifest file for A-Jar --- src/main/java/META-INF/MANIFEST.MF | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/main/java/META-INF/MANIFEST.MF diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..2c9a9745c5 --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: duke.Duke + From 47b8924c7d31dae750aae6d86562bb92bb5d0bd8 Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Mon, 2 Mar 2020 02:06:30 +0800 Subject: [PATCH 16/45] Add delete method for level 6 and update test cases --- src/main/java/duke/Duke.java | 80 +++++++++++++++++++++++------------- text-ui-test/ACTUAL.TXT | 48 ++++++++++++++++------ text-ui-test/EXPECTED.txt | 48 ++++++++++++++++------ text-ui-test/input.txt | 5 +++ text-ui-test/runtest.bat | 2 +- 5 files changed, 128 insertions(+), 55 deletions(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 5f149994d6..ba656033b9 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -10,10 +10,12 @@ import java.util.Scanner; import java.util.Arrays; +import java.util.ArrayList; public class Duke { public static void main(String[] args) { - Task[] tasks = new Task[100]; + ArrayList tasks = new ArrayList<>(); + //Task[] tasks = new Task[100]; int taskCount = 0; boolean isBye = false; Scanner sc = new Scanner(System.in); @@ -43,23 +45,45 @@ public static void main(String[] args) { case "event": taskCount = eventCommand(tasks, taskCount, string); break; - default: //add duke.task.Task into List + case "delete": + taskCount = deleteCommand(tasks, stringSplit, taskCount); + break; + default: throw new DukeNullException(" \u2639 OOPS!!! Command does not exist."); } - } catch (DukeArgumentException e) { - System.out.println(e.getMessage()); - } catch (DukeIndexException e) { + } catch (DukeArgumentException | DukeIndexException e) { System.out.println(e.getMessage()); } catch (DukeNullException e) { System.out.println(e.getMessage()); commandList(); + } catch (NumberFormatException e) { + System.out.println(" \u2639 OOPS!!! " + e.getMessage().substring(18) + " is not number!"); } finally { System.out.println(" ____________________________________________________________"); } } } - public static int eventCommand(Task[] tasks, int taskCount, String string) { + public static int deleteCommand(ArrayList tasks, String[] stringSplit, int taskCount) throws + DukeArgumentException { + int deletedTask; + if (stringSplit.length == 1) { + throw new DukeArgumentException(" \u2639 OOPS!!! Missing index for delete."); + } + deletedTask = Integer.parseInt(stringSplit[1]) - 1; // Might throw NumberFormatException + if (deletedTask >= taskCount | deletedTask < 0) { + throw new DukeIndexException(" \u2639 OOPS!!! Invalid index for delete."); + } + System.out.println(" Noted. I've removed this task:"); + System.out.println(" " + tasks.get(deletedTask)); + tasks.remove(deletedTask); + taskCount--; + System.out.println(" Now you have " + taskCount + " tasks in the list."); + return taskCount; + } + + public static int eventCommand(ArrayList tasks, int taskCount, String string) throws + DukeArgumentException { if (string.length() == 5) { throw new DukeArgumentException(" \u2639 OOPS!!! Missing description for event."); } @@ -71,15 +95,16 @@ public static int eventCommand(Task[] tasks, int taskCount, String string) { String date; description = string.substring(0, string.indexOf(" /at")).replace("event ", ""); date = string.substring(string.indexOf("/at ")).replace("/at ", ""); - tasks[taskCount] = new Event(description, date); - System.out.println(" Got it. I've added this task: "); - System.out.println(" " + tasks[taskCount].toString()); + tasks.add(new Event(description, date)); + System.out.println(" Got it. I've added this task:"); + System.out.println(" " + tasks.get(taskCount).toString()); taskCount++; System.out.println(" Now you have " + taskCount + " tasks in the list."); return taskCount; } - public static int deadlineCommand(Task[] tasks, int taskCount, String string) { + public static int deadlineCommand(ArrayList tasks, int taskCount, String string) throws + DukeArgumentException { if (string.length() == 8) { throw new DukeArgumentException(" \u2639 OOPS!!! Missing description for deadline."); } @@ -91,24 +116,25 @@ public static int deadlineCommand(Task[] tasks, int taskCount, String string) { String date; description = string.substring(0, string.indexOf(" /by")).replace("deadline ", ""); date = string.substring(string.indexOf("/by ")).replace("/by ", ""); - tasks[taskCount] = new Deadline(description, date); - System.out.println(" Got it. I've added this task: "); - System.out.println(" " + tasks[taskCount].toString()); + tasks.add(new Deadline(description, date)); + System.out.println(" Got it. I've added this task:"); + System.out.println(" " + tasks.get(taskCount).toString()); taskCount++; System.out.println(" Now you have " + taskCount + " tasks in the list."); return taskCount; } - public static int todoCommand(Task[] tasks, String[] stringSplit, int taskCount) throws DukeArgumentException { + public static int todoCommand(ArrayList tasks, String[] stringSplit, int taskCount) throws + DukeArgumentException { if (stringSplit.length == 1) { throw new DukeArgumentException(" \u2639 OOPS!!! Missing description for todo."); } String description; description = String.join(" ", Arrays.copyOfRange(stringSplit, 1, stringSplit.length)); - tasks[taskCount] = new Todo(description); - System.out.println(" Got it. I've added this task: "); - System.out.println(" " + tasks[taskCount].toString()); + tasks.add(new Todo(description)); + System.out.println(" Got it. I've added this task:"); + System.out.println(" " + tasks.get(taskCount).toString()); taskCount++; System.out.println(" Now you have " + taskCount + " tasks in the list."); return taskCount; @@ -123,25 +149,23 @@ public static boolean byeCommand(String[] stringSplit) throws DukeArgumentExcept return true; } - public static void doneCommand(Task[] tasks, String[] stringSplit, int taskCount) throws + public static void doneCommand(ArrayList tasks, String[] stringSplit, int taskCount) throws DukeArgumentException, DukeIndexException { int completedTask; if (stringSplit.length == 1) { throw new DukeArgumentException(" \u2639 OOPS!!! Missing index for done."); - } else { - completedTask = Integer.parseInt(stringSplit[1]) - 1; } - if (completedTask >= taskCount) { + completedTask = Integer.parseInt(stringSplit[1]) - 1; // Might throw NumberFormatException + if (completedTask >= taskCount || completedTask < 0) { throw new DukeIndexException(" \u2639 OOPS!!! Invalid index for done."); - } else { - tasks[completedTask].markAsDone(); - System.out.println(" Nice! I've marked this task as done: "); - System.out.println(" " + tasks[completedTask].toString()); } + tasks.get(completedTask).markAsDone(); + System.out.println(" Nice! I've marked this task as done:"); + System.out.println(" " + tasks.get(completedTask).toString()); } - public static void listCommand(Task[] tasks, String[] stringSplit, int taskCount) throws DukeArgumentException { + public static void listCommand(ArrayList tasks, String[] stringSplit, int taskCount) throws DukeArgumentException { if (stringSplit.length > 1) { throw new DukeArgumentException(" \u2639 OOPS!!! Description not required for list."); } @@ -151,7 +175,7 @@ public static void listCommand(Task[] tasks, String[] stringSplit, int taskCount } else { System.out.println(" Here are the tasks in your list:"); for (int i = 0; i < taskCount; i++) { - System.out.println(" " + (i + 1) + "." + tasks[i].toString()); + System.out.println(" " + (i + 1) + "." + tasks.get(i).toString()); } } } @@ -181,7 +205,7 @@ public static void commandList() { System.out.println("|-------+------------------+------------------------------------|"); System.out.println("| 06 | event j /at d | Add a task(j) that start at date d |"); System.out.println("|-------+------------------+------------------------------------|"); - System.out.println("| 07 | j | Add a task(j) |"); + System.out.println("| 07 | delete j | Delete task(j) |"); System.out.println("|---------------------------------------------------------------|"); } } diff --git a/text-ui-test/ACTUAL.TXT b/text-ui-test/ACTUAL.TXT index 29b1c04599..18d29653b8 100644 --- a/text-ui-test/ACTUAL.TXT +++ b/text-ui-test/ACTUAL.TXT @@ -16,7 +16,7 @@ |-------+------------------+------------------------------------| | 06 | event j /at d | Add a task(j) that start at date d | |-------+------------------+------------------------------------| -| 07 | j | Add a task(j) | +| 07 | delete j | Delete task(j) | |---------------------------------------------------------------| What can I do for you? ____________________________________________________________ @@ -26,7 +26,7 @@ ____________________________________________________________ ____________________________________________________________ - Got it. I've added this task: + Got it. I've added this task: [T][✘] read book Now you have 1 tasks in the list. ____________________________________________________________ @@ -37,7 +37,7 @@ ____________________________________________________________ ____________________________________________________________ - Got it. I've added this task: + Got it. I've added this task: [D][✘] return book (by: June 6th) Now you have 2 tasks in the list. ____________________________________________________________ @@ -49,7 +49,7 @@ ____________________________________________________________ ____________________________________________________________ - Got it. I've added this task: + Got it. I've added this task: [E][✘] project meeting (at: Aug 6th 2-4pm) Now you have 3 tasks in the list. ____________________________________________________________ @@ -62,7 +62,7 @@ ____________________________________________________________ ____________________________________________________________ - Nice! I've marked this task as done: + Nice! I've marked this task as done: [T][✓] read book ____________________________________________________________ @@ -74,7 +74,7 @@ ____________________________________________________________ ____________________________________________________________ - Nice! I've marked this task as done: + Nice! I've marked this task as done: [E][✓] project meeting (at: Aug 6th 2-4pm) ____________________________________________________________ @@ -86,25 +86,25 @@ ____________________________________________________________ ____________________________________________________________ - Got it. I've added this task: + Got it. I've added this task: [T][✘] join sports club Now you have 4 tasks in the list. ____________________________________________________________ ____________________________________________________________ - Got it. I've added this task: + Got it. I've added this task: [D][✘] return book (by: Sunday) Now you have 5 tasks in the list. ____________________________________________________________ ____________________________________________________________ - Got it. I've added this task: + Got it. I've added this task: [E][✘] project meeting (at: Mon 2-4pm) Now you have 6 tasks in the list. ____________________________________________________________ ____________________________________________________________ - Got it. I've added this task: + Got it. I've added this task: [D][✘] do homework (by: no idea :-p) Now you have 7 tasks in the list. ____________________________________________________________ @@ -121,7 +121,7 @@ ____________________________________________________________ ____________________________________________________________ - Nice! I've marked this task as done: + Nice! I've marked this task as done: [D][✓] do homework (by: no idea :-p) ____________________________________________________________ @@ -137,7 +137,7 @@ ____________________________________________________________ ____________________________________________________________ - Nice! I've marked this task as done: + Nice! I've marked this task as done: [T][✓] join sports club ____________________________________________________________ @@ -152,6 +152,28 @@ 7.[D][✓] do homework (by: no idea :-p) ____________________________________________________________ + ____________________________________________________________ + Noted. I've removed this task: + [D][✓] do homework (by: no idea :-p) + Now you have 6 tasks in the list. + ____________________________________________________________ + + ____________________________________________________________ + ☹ OOPS!!! Missing index for delete. + ____________________________________________________________ + + ____________________________________________________________ + ☹ OOPS!!! "a" is not number! + ____________________________________________________________ + + ____________________________________________________________ + ☹ OOPS!!! Invalid index for delete. + ____________________________________________________________ + + ____________________________________________________________ + ☹ OOPS!!! Invalid index for delete. + ____________________________________________________________ + ____________________________________________________________ ☹ OOPS!!! Description not required for list. ____________________________________________________________ @@ -206,7 +228,7 @@ |-------+------------------+------------------------------------| | 06 | event j /at d | Add a task(j) that start at date d | |-------+------------------+------------------------------------| -| 07 | j | Add a task(j) | +| 07 | delete j | Delete task(j) | |---------------------------------------------------------------| ____________________________________________________________ diff --git a/text-ui-test/EXPECTED.txt b/text-ui-test/EXPECTED.txt index 29b1c04599..18d29653b8 100644 --- a/text-ui-test/EXPECTED.txt +++ b/text-ui-test/EXPECTED.txt @@ -16,7 +16,7 @@ |-------+------------------+------------------------------------| | 06 | event j /at d | Add a task(j) that start at date d | |-------+------------------+------------------------------------| -| 07 | j | Add a task(j) | +| 07 | delete j | Delete task(j) | |---------------------------------------------------------------| What can I do for you? ____________________________________________________________ @@ -26,7 +26,7 @@ ____________________________________________________________ ____________________________________________________________ - Got it. I've added this task: + Got it. I've added this task: [T][✘] read book Now you have 1 tasks in the list. ____________________________________________________________ @@ -37,7 +37,7 @@ ____________________________________________________________ ____________________________________________________________ - Got it. I've added this task: + Got it. I've added this task: [D][✘] return book (by: June 6th) Now you have 2 tasks in the list. ____________________________________________________________ @@ -49,7 +49,7 @@ ____________________________________________________________ ____________________________________________________________ - Got it. I've added this task: + Got it. I've added this task: [E][✘] project meeting (at: Aug 6th 2-4pm) Now you have 3 tasks in the list. ____________________________________________________________ @@ -62,7 +62,7 @@ ____________________________________________________________ ____________________________________________________________ - Nice! I've marked this task as done: + Nice! I've marked this task as done: [T][✓] read book ____________________________________________________________ @@ -74,7 +74,7 @@ ____________________________________________________________ ____________________________________________________________ - Nice! I've marked this task as done: + Nice! I've marked this task as done: [E][✓] project meeting (at: Aug 6th 2-4pm) ____________________________________________________________ @@ -86,25 +86,25 @@ ____________________________________________________________ ____________________________________________________________ - Got it. I've added this task: + Got it. I've added this task: [T][✘] join sports club Now you have 4 tasks in the list. ____________________________________________________________ ____________________________________________________________ - Got it. I've added this task: + Got it. I've added this task: [D][✘] return book (by: Sunday) Now you have 5 tasks in the list. ____________________________________________________________ ____________________________________________________________ - Got it. I've added this task: + Got it. I've added this task: [E][✘] project meeting (at: Mon 2-4pm) Now you have 6 tasks in the list. ____________________________________________________________ ____________________________________________________________ - Got it. I've added this task: + Got it. I've added this task: [D][✘] do homework (by: no idea :-p) Now you have 7 tasks in the list. ____________________________________________________________ @@ -121,7 +121,7 @@ ____________________________________________________________ ____________________________________________________________ - Nice! I've marked this task as done: + Nice! I've marked this task as done: [D][✓] do homework (by: no idea :-p) ____________________________________________________________ @@ -137,7 +137,7 @@ ____________________________________________________________ ____________________________________________________________ - Nice! I've marked this task as done: + Nice! I've marked this task as done: [T][✓] join sports club ____________________________________________________________ @@ -152,6 +152,28 @@ 7.[D][✓] do homework (by: no idea :-p) ____________________________________________________________ + ____________________________________________________________ + Noted. I've removed this task: + [D][✓] do homework (by: no idea :-p) + Now you have 6 tasks in the list. + ____________________________________________________________ + + ____________________________________________________________ + ☹ OOPS!!! Missing index for delete. + ____________________________________________________________ + + ____________________________________________________________ + ☹ OOPS!!! "a" is not number! + ____________________________________________________________ + + ____________________________________________________________ + ☹ OOPS!!! Invalid index for delete. + ____________________________________________________________ + + ____________________________________________________________ + ☹ OOPS!!! Invalid index for delete. + ____________________________________________________________ + ____________________________________________________________ ☹ OOPS!!! Description not required for list. ____________________________________________________________ @@ -206,7 +228,7 @@ |-------+------------------+------------------------------------| | 06 | event j /at d | Add a task(j) that start at date d | |-------+------------------+------------------------------------| -| 07 | j | Add a task(j) | +| 07 | delete j | Delete task(j) | |---------------------------------------------------------------| ____________________________________________________________ diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index b5e362b781..c3a50f3ece 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -18,6 +18,11 @@ done 7 list done 4 list +delete 7 +delete +delete a +delete -3 +delete 10 list all done done 10 diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 38c8ff673c..4ddb462e70 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -7,7 +7,7 @@ REM delete output from previous run del ACTUAL.TXT REM compile the code into the bin folder -javac -cp ..\src -Xlint:none -d ..\bin ..\src\main\java\*.java +javac -cp ..\src -Xlint:none -d ..\bin ..\src\main\java\duke\*.java ..\src\main\java\duke\task\*.java ..\src\main\java\duke\exception\*.java IF ERRORLEVEL 1 ( echo ********** BUILD FAILURE ********** exit /b 1 From 9ed45704765aef1ad048b96eaa7289333cf5ead0 Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Mon, 2 Mar 2020 11:09:22 +0800 Subject: [PATCH 17/45] Complete Level 7 Save Method --- data/duke.txt | 7 ++ src/main/java/duke/Duke.java | 95 +++++++++++++++++++++++++-- src/main/java/duke/task/Deadline.java | 4 ++ src/main/java/duke/task/Event.java | 4 ++ 4 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 data/duke.txt diff --git a/data/duke.txt b/data/duke.txt new file mode 100644 index 0000000000..e4f34bee11 --- /dev/null +++ b/data/duke.txt @@ -0,0 +1,7 @@ +T | 0 | read book +D | 0 | return book | June 6th +E | 1 | project meeting | Aug 6th 2-4pm +T | 0 | join sports club +D | 0 | return book | Sunday +E | 0 | project meeting | Mon 2-4pm +D | 1 | do homework | no idea :-p diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 5f149994d6..75a950361b 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -10,11 +10,23 @@ import java.util.Scanner; import java.util.Arrays; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.Path; public class Duke { + + public static final String FILE_PATH = "data/duke.txt"; + public static void main(String[] args) { Task[] tasks = new Task[100]; - int taskCount = 0; + tasks = getFileTask(FILE_PATH, tasks, 0); + int taskCount = getFileTaskQuantity(FILE_PATH); boolean isBye = false; Scanner sc = new Scanner(System.in); greetUser(); @@ -32,7 +44,7 @@ public static void main(String[] args) { doneCommand(tasks, stringSplit, taskCount); break; case "bye": - isBye = byeCommand(stringSplit); + isBye = byeCommand(stringSplit, taskCount, tasks); break; case "todo": taskCount = todoCommand(tasks, stringSplit, taskCount); @@ -53,12 +65,63 @@ public static void main(String[] args) { } catch (DukeNullException e) { System.out.println(e.getMessage()); commandList(); + } catch (FileNotFoundException e) { + System.out.println("Folder does not exist yet" + e.getMessage()); + } catch (IOException e) { + System.out.println("Something went wrong: " + e.getMessage()); } finally { System.out.println(" ____________________________________________________________"); } } } + private static int getFileTaskQuantity(String filePath) { + int taskCount = 0; + try { + File file = new File(filePath); // create a File for the given file path + Scanner fileScanner = new Scanner(file); // create a Scanner using the File as the source + while (fileScanner.hasNext()) { + fileScanner.nextLine(); + taskCount++; + } + return taskCount; + } catch (FileNotFoundException e) { + return taskCount; + } + } + + public static void writeFileTask(String filePath, String taskToAdd) throws IOException { + FileWriter fileWriter = new FileWriter(filePath); + fileWriter.write(taskToAdd); + fileWriter.close(); + } + + public static Task[] getFileTask(String filePath, Task[] tasks, int taskCount) { + try { + File file = new File(filePath); // create a File for the given file path + Scanner fileScanner = new Scanner(file); // create a Scanner using the File as the source + while (fileScanner.hasNext()) { + String[] existingTask = fileScanner.nextLine().split(" \\| "); + if (existingTask[0].equals("T")) { + tasks[taskCount] = new Todo(existingTask[2]); + } + if (existingTask[0].equals("D")) { + tasks[taskCount] = new Deadline(existingTask[2], existingTask[3]); + } + if (existingTask[0].equals("E")) { + tasks[taskCount] = new Event(existingTask[2], existingTask[3]); + } + if (existingTask[1].equals("1")) { + tasks[taskCount].markAsDone(); + } + taskCount++; + } + return tasks; + } catch (FileNotFoundException e) { + return tasks; + } + } + public static int eventCommand(Task[] tasks, int taskCount, String string) { if (string.length() == 5) { throw new DukeArgumentException(" \u2639 OOPS!!! Missing description for event."); @@ -114,11 +177,35 @@ public static int todoCommand(Task[] tasks, String[] stringSplit, int taskCount) return taskCount; } - public static boolean byeCommand(String[] stringSplit) throws DukeArgumentException { + public static boolean byeCommand(String[] stringSplit, int taskCount, Task[] tasks) throws + DukeArgumentException, IOException { if (stringSplit.length > 1) { throw new DukeArgumentException(" \u2639 OOPS!!! Description not required for bye."); } - + Path path = Paths.get("data"); + if(!Files.exists(path)) { + Files.createDirectory(path); + } + String taskToAdd = ""; + for (int i = 0; i < taskCount; i++) { + if ( tasks[i] instanceof Todo) { + Todo todo = (Todo) tasks[i]; + taskToAdd = taskToAdd + "T | " + (todo.getIsDone() ? 1 : 0) + " | "; + taskToAdd = taskToAdd + todo.getDescription(); + } + if ( tasks[i] instanceof Deadline) { + Deadline deadline = (Deadline) tasks[i]; + taskToAdd = taskToAdd + "D | " + (deadline.getIsDone() ? 1 : 0) + " | "; + taskToAdd = taskToAdd + deadline.getDescription() + " | " + deadline.getDate(); + } + if ( tasks[i] instanceof Event) { + Event event = (Event) tasks[i]; + taskToAdd = taskToAdd + "E | " + (event.getIsDone() ? 1 : 0) + " | "; + taskToAdd = taskToAdd + event.getDescription() + " | " + event.getDate(); + } + taskToAdd += "\n"; + } + writeFileTask(FILE_PATH, taskToAdd); System.out.println(" Bye. Hope to see you again soon!"); return true; } diff --git a/src/main/java/duke/task/Deadline.java b/src/main/java/duke/task/Deadline.java index ed47c4a0fa..f028500e84 100644 --- a/src/main/java/duke/task/Deadline.java +++ b/src/main/java/duke/task/Deadline.java @@ -7,6 +7,10 @@ public Deadline(String description, String date) { this.date = date; } + public String getDate() { + return this.date; + } + public String toString() { return "[D]" + super.toString() + " (by: " + this.date + ")"; } diff --git a/src/main/java/duke/task/Event.java b/src/main/java/duke/task/Event.java index e55740e734..c8911219ce 100644 --- a/src/main/java/duke/task/Event.java +++ b/src/main/java/duke/task/Event.java @@ -8,6 +8,10 @@ public Event(String description, String date) { this.date = date; } + public String getDate() { + return this.date; + } + public String toString() { return "[E]" + super.toString() + " (at: " + this.date + ")"; } From d3821335f88a5b68dcda9809395dfaa33e3ea768 Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Mon, 2 Mar 2020 12:01:06 +0800 Subject: [PATCH 18/45] Replace Symbols(Tick, Cross, Smiley Face) with Words --- src/main/java/duke/Duke.java | 26 +++---- src/main/java/duke/task/Task.java | 2 +- text-ui-test/ACTUAL.TXT | 118 +++++++++++++++--------------- text-ui-test/EXPECTED.txt | 118 +++++++++++++++--------------- text-ui-test/data/duke.txt | 6 ++ 5 files changed, 138 insertions(+), 132 deletions(-) create mode 100644 text-ui-test/data/duke.txt diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 6f7dbe26e6..6516b8e5c8 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -58,7 +58,7 @@ public static void main(String[] args) { taskCount = deleteCommand(tasks, stringSplit, taskCount); break; default: - throw new DukeNullException(" \u2639 OOPS!!! Command does not exist."); + throw new DukeNullException(" :( OOPS!!! Command does not exist."); } } catch (DukeArgumentException | DukeIndexException e) { System.out.println(e.getMessage()); @@ -66,7 +66,7 @@ public static void main(String[] args) { System.out.println(e.getMessage()); commandList(); } catch (NumberFormatException e) { - System.out.println(" \u2639 OOPS!!! " + e.getMessage().substring(18) + " is not number!"); + System.out.println(" :( OOPS!!! " + e.getMessage().substring(18) + " is not number!"); } catch (FileNotFoundException e) { System.out.println("Folder does not exist yet" + e.getMessage()); } catch (IOException e) { @@ -113,11 +113,11 @@ public static int deleteCommand(ArrayList tasks, String[] stringSplit, int DukeArgumentException { int deletedTask; if (stringSplit.length == 1) { - throw new DukeArgumentException(" \u2639 OOPS!!! Missing index for delete."); + throw new DukeArgumentException(" :( OOPS!!! Missing index for delete."); } deletedTask = Integer.parseInt(stringSplit[1]) - 1; // Might throw NumberFormatException if (deletedTask >= taskCount | deletedTask < 0) { - throw new DukeIndexException(" \u2639 OOPS!!! Invalid index for delete."); + throw new DukeIndexException(" :( OOPS!!! Invalid index for delete."); } System.out.println(" Noted. I've removed this task:"); System.out.println(" " + tasks.get(deletedTask)); @@ -130,10 +130,10 @@ public static int deleteCommand(ArrayList tasks, String[] stringSplit, int public static int eventCommand(ArrayList tasks, int taskCount, String string) throws DukeArgumentException { if (string.length() == 5) { - throw new DukeArgumentException(" \u2639 OOPS!!! Missing description for event."); + throw new DukeArgumentException(" :( OOPS!!! Missing description for event."); } if (!string.contains("/at")) { - throw new DukeArgumentException(" \u2639 OOPS!!! Missing date for event."); + throw new DukeArgumentException(" :( OOPS!!! Missing date for event."); } String description; @@ -151,10 +151,10 @@ public static int eventCommand(ArrayList tasks, int taskCount, String stri public static int deadlineCommand(ArrayList tasks, int taskCount, String string) throws DukeArgumentException { if (string.length() == 8) { - throw new DukeArgumentException(" \u2639 OOPS!!! Missing description for deadline."); + throw new DukeArgumentException(" :( OOPS!!! Missing description for deadline."); } if (!string.contains("/by")) { - throw new DukeArgumentException(" \u2639 OOPS!!! Missing date for deadline."); + throw new DukeArgumentException(" :( OOPS!!! Missing date for deadline."); } String description; @@ -172,7 +172,7 @@ public static int deadlineCommand(ArrayList tasks, int taskCount, String s public static int todoCommand(ArrayList tasks, String[] stringSplit, int taskCount) throws DukeArgumentException { if (stringSplit.length == 1) { - throw new DukeArgumentException(" \u2639 OOPS!!! Missing description for todo."); + throw new DukeArgumentException(" :( OOPS!!! Missing description for todo."); } String description; @@ -188,7 +188,7 @@ public static int todoCommand(ArrayList tasks, String[] stringSplit, int t public static boolean byeCommand(String[] stringSplit, int taskCount, ArrayList tasks) throws DukeArgumentException, IOException { if (stringSplit.length > 1) { - throw new DukeArgumentException(" \u2639 OOPS!!! Description not required for bye."); + throw new DukeArgumentException(" :( OOPS!!! Description not required for bye."); } Path path = Paths.get("data"); if(!Files.exists(path)) { @@ -222,12 +222,12 @@ public static void doneCommand(ArrayList tasks, String[] stringSplit, int DukeArgumentException, DukeIndexException { int completedTask; if (stringSplit.length == 1) { - throw new DukeArgumentException(" \u2639 OOPS!!! Missing index for done."); + throw new DukeArgumentException(" :( OOPS!!! Missing index for done."); } completedTask = Integer.parseInt(stringSplit[1]) - 1; // Might throw NumberFormatException if (completedTask >= taskCount || completedTask < 0) { - throw new DukeIndexException(" \u2639 OOPS!!! Invalid index for done."); + throw new DukeIndexException(" :( OOPS!!! Invalid index for done."); } tasks.get(completedTask).markAsDone(); System.out.println(" Nice! I've marked this task as done:"); @@ -236,7 +236,7 @@ public static void doneCommand(ArrayList tasks, String[] stringSplit, int public static void listCommand(ArrayList tasks, String[] stringSplit, int taskCount) throws DukeArgumentException { if (stringSplit.length > 1) { - throw new DukeArgumentException(" \u2639 OOPS!!! Description not required for list."); + throw new DukeArgumentException(" :( OOPS!!! Description not required for list."); } if (taskCount == 0) { diff --git a/src/main/java/duke/task/Task.java b/src/main/java/duke/task/Task.java index 17815dc5c4..a06b3de3df 100644 --- a/src/main/java/duke/task/Task.java +++ b/src/main/java/duke/task/Task.java @@ -10,7 +10,7 @@ public Task(String description) { } public String getStatusIcon() { - return (getIsDone() ? "\u2713" : "\u2718"); //return tick or X symbols + return (getIsDone() ? "Y" : "N"); } // Not immutable version diff --git a/text-ui-test/ACTUAL.TXT b/text-ui-test/ACTUAL.TXT index 18d29653b8..81538659d9 100644 --- a/text-ui-test/ACTUAL.TXT +++ b/text-ui-test/ACTUAL.TXT @@ -27,191 +27,191 @@ ____________________________________________________________ Got it. I've added this task: - [T][✘] read book + [T][N] read book Now you have 1 tasks in the list. ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: - 1.[T][✘] read book + 1.[T][N] read book ____________________________________________________________ ____________________________________________________________ Got it. I've added this task: - [D][✘] return book (by: June 6th) + [D][N] return book (by: June 6th) Now you have 2 tasks in the list. ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: - 1.[T][✘] read book - 2.[D][✘] return book (by: June 6th) + 1.[T][N] read book + 2.[D][N] return book (by: June 6th) ____________________________________________________________ ____________________________________________________________ Got it. I've added this task: - [E][✘] project meeting (at: Aug 6th 2-4pm) + [E][N] project meeting (at: Aug 6th 2-4pm) Now you have 3 tasks in the list. ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: - 1.[T][✘] read book - 2.[D][✘] return book (by: June 6th) - 3.[E][✘] project meeting (at: Aug 6th 2-4pm) + 1.[T][N] read book + 2.[D][N] return book (by: June 6th) + 3.[E][N] project meeting (at: Aug 6th 2-4pm) ____________________________________________________________ ____________________________________________________________ Nice! I've marked this task as done: - [T][✓] read book + [T][Y] read book ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: - 1.[T][✓] read book - 2.[D][✘] return book (by: June 6th) - 3.[E][✘] project meeting (at: Aug 6th 2-4pm) + 1.[T][Y] read book + 2.[D][N] return book (by: June 6th) + 3.[E][N] project meeting (at: Aug 6th 2-4pm) ____________________________________________________________ ____________________________________________________________ Nice! I've marked this task as done: - [E][✓] project meeting (at: Aug 6th 2-4pm) + [E][Y] project meeting (at: Aug 6th 2-4pm) ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: - 1.[T][✓] read book - 2.[D][✘] return book (by: June 6th) - 3.[E][✓] project meeting (at: Aug 6th 2-4pm) + 1.[T][Y] read book + 2.[D][N] return book (by: June 6th) + 3.[E][Y] project meeting (at: Aug 6th 2-4pm) ____________________________________________________________ ____________________________________________________________ Got it. I've added this task: - [T][✘] join sports club + [T][N] join sports club Now you have 4 tasks in the list. ____________________________________________________________ ____________________________________________________________ Got it. I've added this task: - [D][✘] return book (by: Sunday) + [D][N] return book (by: Sunday) Now you have 5 tasks in the list. ____________________________________________________________ ____________________________________________________________ Got it. I've added this task: - [E][✘] project meeting (at: Mon 2-4pm) + [E][N] project meeting (at: Mon 2-4pm) Now you have 6 tasks in the list. ____________________________________________________________ ____________________________________________________________ Got it. I've added this task: - [D][✘] do homework (by: no idea :-p) + [D][N] do homework (by: no idea :-p) Now you have 7 tasks in the list. ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: - 1.[T][✓] read book - 2.[D][✘] return book (by: June 6th) - 3.[E][✓] project meeting (at: Aug 6th 2-4pm) - 4.[T][✘] join sports club - 5.[D][✘] return book (by: Sunday) - 6.[E][✘] project meeting (at: Mon 2-4pm) - 7.[D][✘] do homework (by: no idea :-p) + 1.[T][Y] read book + 2.[D][N] return book (by: June 6th) + 3.[E][Y] project meeting (at: Aug 6th 2-4pm) + 4.[T][N] join sports club + 5.[D][N] return book (by: Sunday) + 6.[E][N] project meeting (at: Mon 2-4pm) + 7.[D][N] do homework (by: no idea :-p) ____________________________________________________________ ____________________________________________________________ Nice! I've marked this task as done: - [D][✓] do homework (by: no idea :-p) + [D][Y] do homework (by: no idea :-p) ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: - 1.[T][✓] read book - 2.[D][✘] return book (by: June 6th) - 3.[E][✓] project meeting (at: Aug 6th 2-4pm) - 4.[T][✘] join sports club - 5.[D][✘] return book (by: Sunday) - 6.[E][✘] project meeting (at: Mon 2-4pm) - 7.[D][✓] do homework (by: no idea :-p) + 1.[T][Y] read book + 2.[D][N] return book (by: June 6th) + 3.[E][Y] project meeting (at: Aug 6th 2-4pm) + 4.[T][N] join sports club + 5.[D][N] return book (by: Sunday) + 6.[E][N] project meeting (at: Mon 2-4pm) + 7.[D][Y] do homework (by: no idea :-p) ____________________________________________________________ ____________________________________________________________ Nice! I've marked this task as done: - [T][✓] join sports club + [T][Y] join sports club ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: - 1.[T][✓] read book - 2.[D][✘] return book (by: June 6th) - 3.[E][✓] project meeting (at: Aug 6th 2-4pm) - 4.[T][✓] join sports club - 5.[D][✘] return book (by: Sunday) - 6.[E][✘] project meeting (at: Mon 2-4pm) - 7.[D][✓] do homework (by: no idea :-p) + 1.[T][Y] read book + 2.[D][N] return book (by: June 6th) + 3.[E][Y] project meeting (at: Aug 6th 2-4pm) + 4.[T][Y] join sports club + 5.[D][N] return book (by: Sunday) + 6.[E][N] project meeting (at: Mon 2-4pm) + 7.[D][Y] do homework (by: no idea :-p) ____________________________________________________________ ____________________________________________________________ Noted. I've removed this task: - [D][✓] do homework (by: no idea :-p) + [D][Y] do homework (by: no idea :-p) Now you have 6 tasks in the list. ____________________________________________________________ ____________________________________________________________ - ☹ OOPS!!! Missing index for delete. + :( OOPS!!! Missing index for delete. ____________________________________________________________ ____________________________________________________________ - ☹ OOPS!!! "a" is not number! + :( OOPS!!! "a" is not number! ____________________________________________________________ ____________________________________________________________ - ☹ OOPS!!! Invalid index for delete. + :( OOPS!!! Invalid index for delete. ____________________________________________________________ ____________________________________________________________ - ☹ OOPS!!! Invalid index for delete. + :( OOPS!!! Invalid index for delete. ____________________________________________________________ ____________________________________________________________ - ☹ OOPS!!! Description not required for list. + :( OOPS!!! Description not required for list. ____________________________________________________________ ____________________________________________________________ - ☹ OOPS!!! Missing index for done. + :( OOPS!!! Missing index for done. ____________________________________________________________ ____________________________________________________________ - ☹ OOPS!!! Invalid index for done. + :( OOPS!!! Invalid index for done. ____________________________________________________________ ____________________________________________________________ - ☹ OOPS!!! Description not required for bye. + :( OOPS!!! Description not required for bye. ____________________________________________________________ ____________________________________________________________ - ☹ OOPS!!! Missing description for todo. + :( OOPS!!! Missing description for todo. ____________________________________________________________ ____________________________________________________________ - ☹ OOPS!!! Missing description for deadline. + :( OOPS!!! Missing description for deadline. ____________________________________________________________ ____________________________________________________________ - ☹ OOPS!!! Missing date for deadline. + :( OOPS!!! Missing date for deadline. ____________________________________________________________ ____________________________________________________________ - ☹ OOPS!!! Missing description for event. + :( OOPS!!! Missing description for event. ____________________________________________________________ ____________________________________________________________ - ☹ OOPS!!! Missing date for event. + :( OOPS!!! Missing date for event. ____________________________________________________________ ____________________________________________________________ - ☹ OOPS!!! Command does not exist. + :( OOPS!!! Command does not exist. Here is the list of commands that are available: +---------------------------------------------------------------+ | Index | Input | Command | diff --git a/text-ui-test/EXPECTED.txt b/text-ui-test/EXPECTED.txt index 18d29653b8..81538659d9 100644 --- a/text-ui-test/EXPECTED.txt +++ b/text-ui-test/EXPECTED.txt @@ -27,191 +27,191 @@ ____________________________________________________________ Got it. I've added this task: - [T][✘] read book + [T][N] read book Now you have 1 tasks in the list. ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: - 1.[T][✘] read book + 1.[T][N] read book ____________________________________________________________ ____________________________________________________________ Got it. I've added this task: - [D][✘] return book (by: June 6th) + [D][N] return book (by: June 6th) Now you have 2 tasks in the list. ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: - 1.[T][✘] read book - 2.[D][✘] return book (by: June 6th) + 1.[T][N] read book + 2.[D][N] return book (by: June 6th) ____________________________________________________________ ____________________________________________________________ Got it. I've added this task: - [E][✘] project meeting (at: Aug 6th 2-4pm) + [E][N] project meeting (at: Aug 6th 2-4pm) Now you have 3 tasks in the list. ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: - 1.[T][✘] read book - 2.[D][✘] return book (by: June 6th) - 3.[E][✘] project meeting (at: Aug 6th 2-4pm) + 1.[T][N] read book + 2.[D][N] return book (by: June 6th) + 3.[E][N] project meeting (at: Aug 6th 2-4pm) ____________________________________________________________ ____________________________________________________________ Nice! I've marked this task as done: - [T][✓] read book + [T][Y] read book ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: - 1.[T][✓] read book - 2.[D][✘] return book (by: June 6th) - 3.[E][✘] project meeting (at: Aug 6th 2-4pm) + 1.[T][Y] read book + 2.[D][N] return book (by: June 6th) + 3.[E][N] project meeting (at: Aug 6th 2-4pm) ____________________________________________________________ ____________________________________________________________ Nice! I've marked this task as done: - [E][✓] project meeting (at: Aug 6th 2-4pm) + [E][Y] project meeting (at: Aug 6th 2-4pm) ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: - 1.[T][✓] read book - 2.[D][✘] return book (by: June 6th) - 3.[E][✓] project meeting (at: Aug 6th 2-4pm) + 1.[T][Y] read book + 2.[D][N] return book (by: June 6th) + 3.[E][Y] project meeting (at: Aug 6th 2-4pm) ____________________________________________________________ ____________________________________________________________ Got it. I've added this task: - [T][✘] join sports club + [T][N] join sports club Now you have 4 tasks in the list. ____________________________________________________________ ____________________________________________________________ Got it. I've added this task: - [D][✘] return book (by: Sunday) + [D][N] return book (by: Sunday) Now you have 5 tasks in the list. ____________________________________________________________ ____________________________________________________________ Got it. I've added this task: - [E][✘] project meeting (at: Mon 2-4pm) + [E][N] project meeting (at: Mon 2-4pm) Now you have 6 tasks in the list. ____________________________________________________________ ____________________________________________________________ Got it. I've added this task: - [D][✘] do homework (by: no idea :-p) + [D][N] do homework (by: no idea :-p) Now you have 7 tasks in the list. ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: - 1.[T][✓] read book - 2.[D][✘] return book (by: June 6th) - 3.[E][✓] project meeting (at: Aug 6th 2-4pm) - 4.[T][✘] join sports club - 5.[D][✘] return book (by: Sunday) - 6.[E][✘] project meeting (at: Mon 2-4pm) - 7.[D][✘] do homework (by: no idea :-p) + 1.[T][Y] read book + 2.[D][N] return book (by: June 6th) + 3.[E][Y] project meeting (at: Aug 6th 2-4pm) + 4.[T][N] join sports club + 5.[D][N] return book (by: Sunday) + 6.[E][N] project meeting (at: Mon 2-4pm) + 7.[D][N] do homework (by: no idea :-p) ____________________________________________________________ ____________________________________________________________ Nice! I've marked this task as done: - [D][✓] do homework (by: no idea :-p) + [D][Y] do homework (by: no idea :-p) ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: - 1.[T][✓] read book - 2.[D][✘] return book (by: June 6th) - 3.[E][✓] project meeting (at: Aug 6th 2-4pm) - 4.[T][✘] join sports club - 5.[D][✘] return book (by: Sunday) - 6.[E][✘] project meeting (at: Mon 2-4pm) - 7.[D][✓] do homework (by: no idea :-p) + 1.[T][Y] read book + 2.[D][N] return book (by: June 6th) + 3.[E][Y] project meeting (at: Aug 6th 2-4pm) + 4.[T][N] join sports club + 5.[D][N] return book (by: Sunday) + 6.[E][N] project meeting (at: Mon 2-4pm) + 7.[D][Y] do homework (by: no idea :-p) ____________________________________________________________ ____________________________________________________________ Nice! I've marked this task as done: - [T][✓] join sports club + [T][Y] join sports club ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: - 1.[T][✓] read book - 2.[D][✘] return book (by: June 6th) - 3.[E][✓] project meeting (at: Aug 6th 2-4pm) - 4.[T][✓] join sports club - 5.[D][✘] return book (by: Sunday) - 6.[E][✘] project meeting (at: Mon 2-4pm) - 7.[D][✓] do homework (by: no idea :-p) + 1.[T][Y] read book + 2.[D][N] return book (by: June 6th) + 3.[E][Y] project meeting (at: Aug 6th 2-4pm) + 4.[T][Y] join sports club + 5.[D][N] return book (by: Sunday) + 6.[E][N] project meeting (at: Mon 2-4pm) + 7.[D][Y] do homework (by: no idea :-p) ____________________________________________________________ ____________________________________________________________ Noted. I've removed this task: - [D][✓] do homework (by: no idea :-p) + [D][Y] do homework (by: no idea :-p) Now you have 6 tasks in the list. ____________________________________________________________ ____________________________________________________________ - ☹ OOPS!!! Missing index for delete. + :( OOPS!!! Missing index for delete. ____________________________________________________________ ____________________________________________________________ - ☹ OOPS!!! "a" is not number! + :( OOPS!!! "a" is not number! ____________________________________________________________ ____________________________________________________________ - ☹ OOPS!!! Invalid index for delete. + :( OOPS!!! Invalid index for delete. ____________________________________________________________ ____________________________________________________________ - ☹ OOPS!!! Invalid index for delete. + :( OOPS!!! Invalid index for delete. ____________________________________________________________ ____________________________________________________________ - ☹ OOPS!!! Description not required for list. + :( OOPS!!! Description not required for list. ____________________________________________________________ ____________________________________________________________ - ☹ OOPS!!! Missing index for done. + :( OOPS!!! Missing index for done. ____________________________________________________________ ____________________________________________________________ - ☹ OOPS!!! Invalid index for done. + :( OOPS!!! Invalid index for done. ____________________________________________________________ ____________________________________________________________ - ☹ OOPS!!! Description not required for bye. + :( OOPS!!! Description not required for bye. ____________________________________________________________ ____________________________________________________________ - ☹ OOPS!!! Missing description for todo. + :( OOPS!!! Missing description for todo. ____________________________________________________________ ____________________________________________________________ - ☹ OOPS!!! Missing description for deadline. + :( OOPS!!! Missing description for deadline. ____________________________________________________________ ____________________________________________________________ - ☹ OOPS!!! Missing date for deadline. + :( OOPS!!! Missing date for deadline. ____________________________________________________________ ____________________________________________________________ - ☹ OOPS!!! Missing description for event. + :( OOPS!!! Missing description for event. ____________________________________________________________ ____________________________________________________________ - ☹ OOPS!!! Missing date for event. + :( OOPS!!! Missing date for event. ____________________________________________________________ ____________________________________________________________ - ☹ OOPS!!! Command does not exist. + :( OOPS!!! Command does not exist. Here is the list of commands that are available: +---------------------------------------------------------------+ | Index | Input | Command | diff --git a/text-ui-test/data/duke.txt b/text-ui-test/data/duke.txt new file mode 100644 index 0000000000..ccbf113b5b --- /dev/null +++ b/text-ui-test/data/duke.txt @@ -0,0 +1,6 @@ +T | 1 | read book +D | 0 | return book | June 6th +E | 1 | project meeting | Aug 6th 2-4pm +T | 1 | join sports club +D | 0 | return book | Sunday +E | 0 | project meeting | Mon 2-4pm From 26b1ef077efbc949c9a560fd032132dc89597b1b Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Mon, 2 Mar 2020 13:12:23 +0800 Subject: [PATCH 19/45] Complete Level 9 Find, Modify runtest.bat to delete duke.txt in text-ui-test --- src/main/java/duke/Duke.java | 27 +++++++++++++++++++++++++++ text-ui-test/ACTUAL.TXT | 15 +++++++++++++++ text-ui-test/EXPECTED.txt | 15 +++++++++++++++ text-ui-test/data/duke.txt | 6 ------ text-ui-test/input.txt | 3 +++ text-ui-test/runtest.bat | 3 +++ 6 files changed, 63 insertions(+), 6 deletions(-) delete mode 100644 text-ui-test/data/duke.txt diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 6516b8e5c8..9a5641b398 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -57,6 +57,9 @@ public static void main(String[] args) { case "delete": taskCount = deleteCommand(tasks, stringSplit, taskCount); break; + case "find": + findCommand(tasks, taskCount, string); + break; default: throw new DukeNullException(" :( OOPS!!! Command does not exist."); } @@ -77,6 +80,30 @@ public static void main(String[] args) { } } + public static void findCommand(ArrayList tasks, int taskCount, String string) throws + DukeArgumentException { + int deletedTask; + if (string.length() == 4) { + throw new DukeArgumentException(" :( OOPS!!! Missing description for find."); + } + String description = string.substring(5); + boolean containDescription = false; + int matchNumber = 1; + for (int i = 0; i < taskCount; i++) { + if (tasks.get(i).getDescription().contains(description)) { + if (!containDescription) { + System.out.println(" Here are the matching tasks in your list:"); + containDescription = true; + } + System.out.println(" " + matchNumber + "." + tasks.get(i).toString()); + matchNumber++; + } + } + if (!containDescription) { + System.out.println(" There is no matching tasks"); + } + } + public static void writeFileTask(String filePath, String taskToAdd) throws IOException { FileWriter fileWriter = new FileWriter(filePath); fileWriter.write(taskToAdd); diff --git a/text-ui-test/ACTUAL.TXT b/text-ui-test/ACTUAL.TXT index 81538659d9..402269f7f6 100644 --- a/text-ui-test/ACTUAL.TXT +++ b/text-ui-test/ACTUAL.TXT @@ -158,6 +158,21 @@ Now you have 6 tasks in the list. ____________________________________________________________ + ____________________________________________________________ + Here are the matching tasks in your list: + 1.[T][Y] read book + 2.[D][N] return book (by: June 6th) + 3.[D][N] return book (by: Sunday) + ____________________________________________________________ + + ____________________________________________________________ + There is no matching tasks + ____________________________________________________________ + + ____________________________________________________________ + :( OOPS!!! Missing description for find. + ____________________________________________________________ + ____________________________________________________________ :( OOPS!!! Missing index for delete. ____________________________________________________________ diff --git a/text-ui-test/EXPECTED.txt b/text-ui-test/EXPECTED.txt index 81538659d9..402269f7f6 100644 --- a/text-ui-test/EXPECTED.txt +++ b/text-ui-test/EXPECTED.txt @@ -158,6 +158,21 @@ Now you have 6 tasks in the list. ____________________________________________________________ + ____________________________________________________________ + Here are the matching tasks in your list: + 1.[T][Y] read book + 2.[D][N] return book (by: June 6th) + 3.[D][N] return book (by: Sunday) + ____________________________________________________________ + + ____________________________________________________________ + There is no matching tasks + ____________________________________________________________ + + ____________________________________________________________ + :( OOPS!!! Missing description for find. + ____________________________________________________________ + ____________________________________________________________ :( OOPS!!! Missing index for delete. ____________________________________________________________ diff --git a/text-ui-test/data/duke.txt b/text-ui-test/data/duke.txt deleted file mode 100644 index ccbf113b5b..0000000000 --- a/text-ui-test/data/duke.txt +++ /dev/null @@ -1,6 +0,0 @@ -T | 1 | read book -D | 0 | return book | June 6th -E | 1 | project meeting | Aug 6th 2-4pm -T | 1 | join sports club -D | 0 | return book | Sunday -E | 0 | project meeting | Mon 2-4pm diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index c3a50f3ece..06c7d789a6 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -19,6 +19,9 @@ list done 4 list delete 7 +find book +find everything +find delete delete a delete -3 diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 4ddb462e70..da4d968b60 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -20,3 +20,6 @@ java -Dfile.encoding=UTF-8 -classpath ..\bin duke.Duke < input.txt > ACTUAL.TXT REM compare the output to the expected output FC ACTUAL.TXT EXPECTED.TXT + +REM Delete duke.txt from previous run +del ..\text-ui-test\data\duke.txt From dfd006473e1eccc273a7afacc06e6883e93305a6 Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Mon, 2 Mar 2020 15:43:46 +0800 Subject: [PATCH 20/45] Complete A-JavaDoc and Add JavaDoc comments --- src/main/java/duke/Duke.java | 92 ++++++++++++++++++- .../duke/exception/DukeArgumentException.java | 11 +++ .../duke/exception/DukeIndexException.java | 12 +++ .../duke/exception/DukeNullException.java | 11 +++ src/main/java/duke/task/Deadline.java | 20 ++++ src/main/java/duke/task/Event.java | 19 ++++ src/main/java/duke/task/Task.java | 29 ++++++ src/main/java/duke/task/Todo.java | 14 +++ 8 files changed, 206 insertions(+), 2 deletions(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 6516b8e5c8..07d7f816a1 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -19,10 +19,19 @@ import java.nio.file.Paths; import java.nio.file.Path; +/** + * Duke is a chatbot that manages Task for user. + * @author Lam Yue Wei + * @version CS2113 AY19/20 Sem 2 Duke + */ public class Duke { public static final String FILE_PATH = "data/duke.txt"; + /** + * Main method for Duke. + * @param args String[] args in main. + */ public static void main(String[] args) { ArrayList tasks = new ArrayList<>(); int taskCount = getFileTask(FILE_PATH, tasks, 0); @@ -77,12 +86,26 @@ public static void main(String[] args) { } } + /** + * Open the file directory based on the filePath, add Task for storage into hard disk and close file. + * @param filePath File directory path. + * @param taskToAdd Sting containing Task information to store into file. + * @throws IOException If input or output operation failed. + */ public static void writeFileTask(String filePath, String taskToAdd) throws IOException { FileWriter fileWriter = new FileWriter(filePath); fileWriter.write(taskToAdd); fileWriter.close(); } + /** + * Open file from file directory if any and convert the string into the respective Task at the + * start of the programs launch. + * @param filePath File directory path. + * @param tasks ArrayList containing all the Task. + * @param taskCount Total number of Task stored. + * @return Total number of Task stored or 0 if the file does not exists. + */ public static int getFileTask(String filePath, ArrayList tasks, int taskCount) { try { File file = new File(filePath); // create a File for the given file path @@ -109,8 +132,17 @@ public static int getFileTask(String filePath, ArrayList tasks, int taskCo } } + /** + * Delete a Task given an index. + * @param tasks ArrayList containing all the Task. + * @param stringSplit User input that is split by spacing. + * @param taskCount Total number of Task stored. + * @return Total number of Task stored. + * @throws DukeArgumentException If missing parameter for index. + * @throws DukeIndexException If index provided is out of range. + */ public static int deleteCommand(ArrayList tasks, String[] stringSplit, int taskCount) throws - DukeArgumentException { + DukeArgumentException, DukeIndexException { int deletedTask; if (stringSplit.length == 1) { throw new DukeArgumentException(" :( OOPS!!! Missing index for delete."); @@ -127,6 +159,14 @@ public static int deleteCommand(ArrayList tasks, String[] stringSplit, int return taskCount; } + /** + * Add event Task given a description and a time of occurrence. + * @param tasks ArrayList containing all the Task. + * @param taskCount Total number of Task stored. + * @param string User input. + * @return Total number of Task stored. + * @throws DukeArgumentException If missing parameter for description or date. + */ public static int eventCommand(ArrayList tasks, int taskCount, String string) throws DukeArgumentException { if (string.length() == 5) { @@ -148,6 +188,14 @@ public static int eventCommand(ArrayList tasks, int taskCount, String stri return taskCount; } + /** + * Add deadline Task given a description and a due date. + * @param tasks ArrayList containing all the Task. + * @param taskCount Total number of Task stored. + * @param string User input. + * @return Total number of Task stored. + * @throws DukeArgumentException If missing parameter for description or date. + */ public static int deadlineCommand(ArrayList tasks, int taskCount, String string) throws DukeArgumentException { if (string.length() == 8) { @@ -169,6 +217,14 @@ public static int deadlineCommand(ArrayList tasks, int taskCount, String s return taskCount; } + /** + * Add todo Task given a description. + * @param tasks ArrayList containing all the Task. + * @param stringSplit User input that is split by spacing. + * @param taskCount Total number of Task stored. + * @return Total number of Task stored. + * @throws DukeArgumentException If missing parameter for index. + */ public static int todoCommand(ArrayList tasks, String[] stringSplit, int taskCount) throws DukeArgumentException { if (stringSplit.length == 1) { @@ -185,6 +241,15 @@ public static int todoCommand(ArrayList tasks, String[] stringSplit, int t return taskCount; } + /** + * Store all the Task into the hard disk and exit the program. + * @param stringSplit User input that is split by spacing. + * @param taskCount Total number of Task stored. + * @param tasks ArrayList containing all the Task. + * @return true to indicate to the program to end. + * @throws DukeArgumentException If additional parameter is provided. + * @throws IOException If input or output operation failed. + */ public static boolean byeCommand(String[] stringSplit, int taskCount, ArrayList tasks) throws DukeArgumentException, IOException { if (stringSplit.length > 1) { @@ -218,6 +283,14 @@ public static boolean byeCommand(String[] stringSplit, int taskCount, ArrayList< return true; } + /** + * Mark a Task as done. + * @param tasks ArrayList containing all the Task. + * @param stringSplit User input that is split by spacing. + * @param taskCount Total number of Task stored. + * @throws DukeArgumentException If missing parameter for index. + * @throws DukeIndexException If index provided is out of range. + */ public static void doneCommand(ArrayList tasks, String[] stringSplit, int taskCount) throws DukeArgumentException, DukeIndexException { int completedTask; @@ -234,7 +307,15 @@ public static void doneCommand(ArrayList tasks, String[] stringSplit, int System.out.println(" " + tasks.get(completedTask).toString()); } - public static void listCommand(ArrayList tasks, String[] stringSplit, int taskCount) throws DukeArgumentException { + /** + * List all the Task stored. + * @param tasks ArrayList containing all the Task. + * @param stringSplit User input that is split by spacing. + * @param taskCount Total number of Task stored. + * @throws DukeArgumentException If additional parameter is provided. + */ + public static void listCommand(ArrayList tasks, String[] stringSplit, int taskCount) throws + DukeArgumentException { if (stringSplit.length > 1) { throw new DukeArgumentException(" :( OOPS!!! Description not required for list."); } @@ -249,6 +330,10 @@ public static void listCommand(ArrayList tasks, String[] stringSplit, int } } + /** + * Print the Welcome message and call commandList method to List out all the possible command + * the user can execute. + */ public static void greetUser() { System.out.println(" ____________________________________________________________"); System.out.println(" Hello! I'm duke.Duke"); @@ -257,6 +342,9 @@ public static void greetUser() { System.out.println(" ____________________________________________________________"); } + /** + * Print out all the possible command the user can execute. + */ public static void commandList() { System.out.println(" Here is the list of commands that are available:"); System.out.println("+---------------------------------------------------------------+"); diff --git a/src/main/java/duke/exception/DukeArgumentException.java b/src/main/java/duke/exception/DukeArgumentException.java index 04d20a837f..e77e599ae8 100644 --- a/src/main/java/duke/exception/DukeArgumentException.java +++ b/src/main/java/duke/exception/DukeArgumentException.java @@ -1,6 +1,17 @@ package duke.exception; +/** + * The DukeArgumentException class is an Exception that is thrown when there are either + * missing parameter or too many parameter provided by the user. + * DukeArgumentException class extends from IllegalArgumentException class. + * @author Lam Yue Wei + * @version CS2113 AY19/20 Sem 2 Duke + */ public class DukeArgumentException extends IllegalArgumentException { + /** + * Public constructor for DukeArgumentException. + * @param message Error message shown to the user. + */ public DukeArgumentException(String message) { super(message); } diff --git a/src/main/java/duke/exception/DukeIndexException.java b/src/main/java/duke/exception/DukeIndexException.java index 14c26e3d00..cc172465dc 100644 --- a/src/main/java/duke/exception/DukeIndexException.java +++ b/src/main/java/duke/exception/DukeIndexException.java @@ -1,6 +1,18 @@ package duke.exception; +/** + * The DukeIndexException class is an Exception that is thrown when the index provided by + * the user is out of bound. In such cases, the index provided is either negative or greater + * than total number of Task stored. + * DukeIndexException class extends from IndexOutOfBoundsException class. + * @author Lam Yue Wei + * @version CS2113 AY19/20 Sem 2 Duke + */ public class DukeIndexException extends IndexOutOfBoundsException { + /** + * Public constructor for DukeIndexException. + * @param message Error message shown to the user. + */ public DukeIndexException(String message) { super(message); } diff --git a/src/main/java/duke/exception/DukeNullException.java b/src/main/java/duke/exception/DukeNullException.java index 332e6975ae..f95df4b622 100644 --- a/src/main/java/duke/exception/DukeNullException.java +++ b/src/main/java/duke/exception/DukeNullException.java @@ -1,6 +1,17 @@ package duke.exception; +/** + * The DukeNullException class is an Exception that is thrown when there is an invalid + * command provided by the user. + * DukeNullException class extends from NullPointerException class. + * @author Lam Yue Wei + * @version CS2113 AY19/20 Sem 2 Duke + */ public class DukeNullException extends NullPointerException { + /** + * Public constructor for DukeNullException. + * @param message Error message shown to the user. + */ public DukeNullException(String message) { super(message); } diff --git a/src/main/java/duke/task/Deadline.java b/src/main/java/duke/task/Deadline.java index f028500e84..5b15af44c1 100644 --- a/src/main/java/duke/task/Deadline.java +++ b/src/main/java/duke/task/Deadline.java @@ -1,16 +1,36 @@ package duke.task; +/** + * The Deadline class is a Task with specified description and due date. + * Deadline class extends from Task class. + * @author Lam Yue Wei + * @version CS2113 AY19/20 Sem 2 Duke + */ public class Deadline extends Task { String date; + + /** + * Public constructor for Deadline. + * @param description Description of the Deadline Task. + * @param date Due date of the Deadline Task. + */ public Deadline(String description, String date) { super(description); this.date = date; } + /** + * Getter method for the due date. + * @return Due date. + */ public String getDate() { return this.date; } + /** + * Return a String representation of this Deadline. + * @return The Deadline's icon, followed by the Task's toString, followed by the due date. + */ public String toString() { return "[D]" + super.toString() + " (by: " + this.date + ")"; } diff --git a/src/main/java/duke/task/Event.java b/src/main/java/duke/task/Event.java index c8911219ce..0ad4edb7eb 100644 --- a/src/main/java/duke/task/Event.java +++ b/src/main/java/duke/task/Event.java @@ -1,17 +1,36 @@ package duke.task; +/** + * The Event class is a Task with specified description and date of occurrence. + * Event class extends from Task class. + * @author Lam Yue Wei + * @version CS2113 AY19/20 Sem 2 Duke + */ public class Event extends Task { String date; + /** + * Public constructor for Event. + * @param description Description of the Event Task. + * @param date Date of occurrence of the Event Task. + */ public Event(String description, String date) { super(description); this.date = date; } + /** + * Getter method for the date of occurrence. + * @return Date of occurrence. + */ public String getDate() { return this.date; } + /** + * Return a String representation of this Event. + * @return The Event's icon, followed by the Task's toString, followed by the date of occurrence. + */ public String toString() { return "[E]" + super.toString() + " (at: " + this.date + ")"; } diff --git a/src/main/java/duke/task/Task.java b/src/main/java/duke/task/Task.java index a06b3de3df..5d4d7c16cb 100644 --- a/src/main/java/duke/task/Task.java +++ b/src/main/java/duke/task/Task.java @@ -1,31 +1,60 @@ package duke.task; +/** + * The Task class keeps a record of the description of any Task and whether is is done. + * @author Lam Yue Wei + * @version CS2113 AY19/20 Sem 2 Duke + */ public class Task { protected String description; protected boolean isDone; + /** + * Public constructor for Task and set isDone to false by default. + * @param description Description of the Task. + */ public Task(String description) { this.description = description; this.isDone = false; } + /** + * Getter method for the status of Task's completion. + * @return Y if Task is done and N if Task is not done. + */ public String getStatusIcon() { return (getIsDone() ? "Y" : "N"); } // Not immutable version + + /** + * Mark the task as done by setting isDone to true. + */ public void markAsDone() { this.isDone = true; } + /** + * Getter method for description of the Task. + * @return Description of the Task. + */ public String getDescription() { return this.description; } + /** + * Getter method for isDone. + * @return isDone which is true if Task if done and false if Task is not done. + */ public boolean getIsDone() { return this.isDone; } + /** + * Return a String representation of this Task. + * @return The Task's done status, followed by the description. + */ public String toString() { return "[" + getStatusIcon() + "] " + getDescription(); } diff --git a/src/main/java/duke/task/Todo.java b/src/main/java/duke/task/Todo.java index 142da72107..97f8019685 100644 --- a/src/main/java/duke/task/Todo.java +++ b/src/main/java/duke/task/Todo.java @@ -1,10 +1,24 @@ package duke.task; +/** + * The Todo class is a Task with specified description. + * Todo class extends from Task class. + * @author Lam Yue Wei + * @version CS2113 AY19/20 Sem 2 Duke + */ public class Todo extends Task { + /** + * Public constructor for Task. + * @param description Description of the Task. + */ public Todo(String description) { super(description); } + /** + * Return a String representation of this Todo. + * @return The Todo's icon, followed by the Task's toString. + */ public String toString() { return "[T]" + super.toString(); } From c11bc5ee61be1c132a57af2c0aa2e7ed87e114c7 Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Mon, 2 Mar 2020 17:52:40 +0800 Subject: [PATCH 21/45] Complete Level 8. Dates and Times for deadline and event --- data/duke.txt | 9 ++++----- src/main/java/duke/Duke.java | 13 +++++++------ src/main/java/duke/task/Deadline.java | 23 ++++++++++++++++++----- src/main/java/duke/task/Event.java | 22 +++++++++++++++++----- text-ui-test/input.txt | 13 ++++++------- 5 files changed, 52 insertions(+), 28 deletions(-) diff --git a/data/duke.txt b/data/duke.txt index e4f34bee11..f873bacba5 100644 --- a/data/duke.txt +++ b/data/duke.txt @@ -1,7 +1,6 @@ T | 0 | read book -D | 0 | return book | June 6th -E | 1 | project meeting | Aug 6th 2-4pm +D | 0 | return book | 2020-10-06 19:30 +E | 1 | project meeting | 2021-05-29 03:20 T | 0 | join sports club -D | 0 | return book | Sunday -E | 0 | project meeting | Mon 2-4pm -D | 1 | do homework | no idea :-p +E | 0 | exams | 2020-05-03 16:00 +D | 1 | do homework | 2020-04-25 11:45 diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 6516b8e5c8..d9cdecb29d 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -137,10 +137,10 @@ public static int eventCommand(ArrayList tasks, int taskCount, String stri } String description; - String date; + String dateTime; description = string.substring(0, string.indexOf(" /at")).replace("event ", ""); - date = string.substring(string.indexOf("/at ")).replace("/at ", ""); - tasks.add(new Event(description, date)); + dateTime = string.substring(string.indexOf("/at ")).replace("/at ", ""); + tasks.add(new Event(description, dateTime)); System.out.println(" Got it. I've added this task:"); System.out.println(" " + tasks.get(taskCount).toString()); taskCount++; @@ -158,10 +158,11 @@ public static int deadlineCommand(ArrayList tasks, int taskCount, String s } String description; - String date; + String dateTime; description = string.substring(0, string.indexOf(" /by")).replace("deadline ", ""); - date = string.substring(string.indexOf("/by ")).replace("/by ", ""); - tasks.add(new Deadline(description, date)); + dateTime = string.substring(string.indexOf("/by ")).replace("/by ", ""); + + tasks.add(new Deadline(description, dateTime)); System.out.println(" Got it. I've added this task:"); System.out.println(" " + tasks.get(taskCount).toString()); taskCount++; diff --git a/src/main/java/duke/task/Deadline.java b/src/main/java/duke/task/Deadline.java index f028500e84..45cf345741 100644 --- a/src/main/java/duke/task/Deadline.java +++ b/src/main/java/duke/task/Deadline.java @@ -1,17 +1,30 @@ package duke.task; +import java.time.LocalDate; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; + public class Deadline extends Task { - String date; - public Deadline(String description, String date) { + String dateTime; + LocalDate date; + LocalTime time; + + public Deadline(String description, String dateTime) { super(description); - this.date = date; + this.dateTime = dateTime; + date = LocalDate.parse(dateTime.split(" ")[0]); + time = LocalTime.parse(dateTime.split(" ")[1]); } public String getDate() { - return this.date; + return this.date.format(DateTimeFormatter.ofPattern("MMM d yyyy")); + } + + public String getTime() { + return this.time.toString(); } public String toString() { - return "[D]" + super.toString() + " (by: " + this.date + ")"; + return "[D]" + super.toString() + " (by: " + getDate() + ", " + getTime() + ")"; } } diff --git a/src/main/java/duke/task/Event.java b/src/main/java/duke/task/Event.java index c8911219ce..eac7cb9310 100644 --- a/src/main/java/duke/task/Event.java +++ b/src/main/java/duke/task/Event.java @@ -1,18 +1,30 @@ package duke.task; +import java.time.LocalDate; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; + public class Event extends Task { - String date; + String dateTime; + LocalDate date; + LocalTime time; - public Event(String description, String date) { + public Event(String description, String dateTime) { super(description); - this.date = date; + this.dateTime = dateTime; + date = LocalDate.parse(dateTime.split(" ")[0]); + time = LocalTime.parse(dateTime.split(" ")[1]); } public String getDate() { - return this.date; + return this.date.format(DateTimeFormatter.ofPattern("MMM d yyyy")); + } + + public String getTime() { + return this.time.toString(); } public String toString() { - return "[E]" + super.toString() + " (at: " + this.date + ")"; + return "[E]" + super.toString() + " (at: " + getDate() + ", " + getTime() + ")"; } } diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index c3a50f3ece..9e0f8e1cac 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -1,24 +1,23 @@ list todo read book list -deadline return book /by June 6th +deadline return book /by 2020-10-06 19:30 list -event project meeting /at Aug 6th 2-4pm +event project meeting /at 2021-05-29 03:20 list done 1 list done 3 list todo join sports club -deadline return book /by Sunday -event project meeting /at Mon 2-4pm -deadline do homework /by no idea :-p +event exams /at 2020-05-03 16:00 +deadline do homework /by 2020-04-25 11:45 list -done 7 +done 6 list done 4 list -delete 7 +delete 6 delete delete a delete -3 From c150c231c2205743a545aca8f84d01d8f6de8fa4 Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Mon, 2 Mar 2020 18:25:36 +0800 Subject: [PATCH 22/45] Commit changes post Level 8 --- src/main/java/duke/Duke.java | 13 ++--- src/main/java/duke/task/Deadline.java | 36 ++++++++++---- src/main/java/duke/task/Event.java | 31 +++++++++--- text-ui-test/ACTUAL.TXT | 70 ++++++++++++--------------- text-ui-test/EXPECTED.txt | 70 ++++++++++++--------------- text-ui-test/input.txt | 13 +++-- 6 files changed, 128 insertions(+), 105 deletions(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 78c7ae551e..1f7e568650 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -211,10 +211,10 @@ public static int eventCommand(ArrayList tasks, int taskCount, String stri } String description; - String date; + String dateTime; description = string.substring(0, string.indexOf(" /at")).replace("event ", ""); - date = string.substring(string.indexOf("/at ")).replace("/at ", ""); - tasks.add(new Event(description, date)); + dateTime = string.substring(string.indexOf("/at ")).replace("/at ", ""); + tasks.add(new Event(description, dateTime)); System.out.println(" Got it. I've added this task:"); System.out.println(" " + tasks.get(taskCount).toString()); taskCount++; @@ -240,10 +240,11 @@ public static int deadlineCommand(ArrayList tasks, int taskCount, String s } String description; - String date; + String dateTime; description = string.substring(0, string.indexOf(" /by")).replace("deadline ", ""); - date = string.substring(string.indexOf("/by ")).replace("/by ", ""); - tasks.add(new Deadline(description, date)); + dateTime = string.substring(string.indexOf("/by ")).replace("/by ", ""); + + tasks.add(new Deadline(description, dateTime)); System.out.println(" Got it. I've added this task:"); System.out.println(" " + tasks.get(taskCount).toString()); taskCount++; diff --git a/src/main/java/duke/task/Deadline.java b/src/main/java/duke/task/Deadline.java index 5b15af44c1..67472c3ec4 100644 --- a/src/main/java/duke/task/Deadline.java +++ b/src/main/java/duke/task/Deadline.java @@ -1,37 +1,55 @@ package duke.task; +import java.time.LocalDate; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; + /** - * The Deadline class is a Task with specified description and due date. + * The Deadline class is a Task with specified String description and String dateTime. + * The class stores the date as a LocalDate Object, time as a LocalTime Object and their combined + * String representation as a String dateTime. * Deadline class extends from Task class. * @author Lam Yue Wei * @version CS2113 AY19/20 Sem 2 Duke */ public class Deadline extends Task { - String date; + String dateTime; + LocalDate date; + LocalTime time; /** * Public constructor for Deadline. * @param description Description of the Deadline Task. - * @param date Due date of the Deadline Task. + * @param dateTime Due date and time of the Deadline Task. */ - public Deadline(String description, String date) { + public Deadline(String description, String dateTime) { super(description); - this.date = date; + this.dateTime = dateTime; + date = LocalDate.parse(dateTime.split(" ")[0]); + time = LocalTime.parse(dateTime.split(" ")[1]); } /** - * Getter method for the due date. + * Getter method for the date. * @return Due date. */ public String getDate() { - return this.date; + return this.date.format(DateTimeFormatter.ofPattern("MMM d yyyy")); + } + + /** + * Getter method for the time. + * @return Due time. + */ + public String getTime() { + return this.time.toString(); } /** * Return a String representation of this Deadline. - * @return The Deadline's icon, followed by the Task's toString, followed by the due date. + * @return The Deadline's icon, followed by the Task's toString, followed by the due date and time. */ public String toString() { - return "[D]" + super.toString() + " (by: " + this.date + ")"; + return "[D]" + super.toString() + " (by: " + getDate() + ", " + getTime() + ")"; } } diff --git a/src/main/java/duke/task/Event.java b/src/main/java/duke/task/Event.java index 0ad4edb7eb..5647b1b9bc 100644 --- a/src/main/java/duke/task/Event.java +++ b/src/main/java/duke/task/Event.java @@ -1,5 +1,9 @@ package duke.task; +import java.time.LocalDate; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; + /** * The Event class is a Task with specified description and date of occurrence. * Event class extends from Task class. @@ -7,16 +11,21 @@ * @version CS2113 AY19/20 Sem 2 Duke */ public class Event extends Task { - String date; + String dateTime; + LocalDate date; + LocalTime time; + /** * Public constructor for Event. * @param description Description of the Event Task. - * @param date Date of occurrence of the Event Task. + * @param dateTime Date of occurrence and time of the Event Task. */ - public Event(String description, String date) { + public Event(String description, String dateTime) { super(description); - this.date = date; + this.dateTime = dateTime; + date = LocalDate.parse(dateTime.split(" ")[0]); + time = LocalTime.parse(dateTime.split(" ")[1]); } /** @@ -24,14 +33,22 @@ public Event(String description, String date) { * @return Date of occurrence. */ public String getDate() { - return this.date; + return this.date.format(DateTimeFormatter.ofPattern("MMM d yyyy")); + } + + /** + * Getter method for the time of occurrence. + * @return Time of occurrence. + */ + public String getTime() { + return this.time.toString(); } /** * Return a String representation of this Event. - * @return The Event's icon, followed by the Task's toString, followed by the date of occurrence. + * @return The Event's icon, followed by the Task's toString, followed by the date and time of occurrence. */ public String toString() { - return "[E]" + super.toString() + " (at: " + this.date + ")"; + return "[E]" + super.toString() + " (at: " + getDate() + ", " + getTime() + ")"; } } diff --git a/text-ui-test/ACTUAL.TXT b/text-ui-test/ACTUAL.TXT index 402269f7f6..f85bd5c41b 100644 --- a/text-ui-test/ACTUAL.TXT +++ b/text-ui-test/ACTUAL.TXT @@ -17,6 +17,8 @@ | 06 | event j /at d | Add a task(j) that start at date d | |-------+------------------+------------------------------------| | 07 | delete j | Delete task(j) | +|-------+------------------+------------------------------------| +| 08 | find j | Find all task with description j | |---------------------------------------------------------------| What can I do for you? ____________________________________________________________ @@ -38,27 +40,27 @@ ____________________________________________________________ Got it. I've added this task: - [D][N] return book (by: June 6th) + [D][N] return book (by: Oct 6 2020, 19:30) Now you have 2 tasks in the list. ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: 1.[T][N] read book - 2.[D][N] return book (by: June 6th) + 2.[D][N] return book (by: Oct 6 2020, 19:30) ____________________________________________________________ ____________________________________________________________ Got it. I've added this task: - [E][N] project meeting (at: Aug 6th 2-4pm) + [E][N] project meeting (at: May 29 2021, 03:20) Now you have 3 tasks in the list. ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: 1.[T][N] read book - 2.[D][N] return book (by: June 6th) - 3.[E][N] project meeting (at: Aug 6th 2-4pm) + 2.[D][N] return book (by: Oct 6 2020, 19:30) + 3.[E][N] project meeting (at: May 29 2021, 03:20) ____________________________________________________________ ____________________________________________________________ @@ -69,20 +71,20 @@ ____________________________________________________________ Here are the tasks in your list: 1.[T][Y] read book - 2.[D][N] return book (by: June 6th) - 3.[E][N] project meeting (at: Aug 6th 2-4pm) + 2.[D][N] return book (by: Oct 6 2020, 19:30) + 3.[E][N] project meeting (at: May 29 2021, 03:20) ____________________________________________________________ ____________________________________________________________ Nice! I've marked this task as done: - [E][Y] project meeting (at: Aug 6th 2-4pm) + [E][Y] project meeting (at: May 29 2021, 03:20) ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: 1.[T][Y] read book - 2.[D][N] return book (by: June 6th) - 3.[E][Y] project meeting (at: Aug 6th 2-4pm) + 2.[D][N] return book (by: Oct 6 2020, 19:30) + 3.[E][Y] project meeting (at: May 29 2021, 03:20) ____________________________________________________________ ____________________________________________________________ @@ -93,47 +95,39 @@ ____________________________________________________________ Got it. I've added this task: - [D][N] return book (by: Sunday) + [E][N] exams (at: May 3 2020, 16:00) Now you have 5 tasks in the list. ____________________________________________________________ ____________________________________________________________ Got it. I've added this task: - [E][N] project meeting (at: Mon 2-4pm) + [D][N] do homework (by: Apr 25 2020, 11:45) Now you have 6 tasks in the list. ____________________________________________________________ - ____________________________________________________________ - Got it. I've added this task: - [D][N] do homework (by: no idea :-p) - Now you have 7 tasks in the list. - ____________________________________________________________ - ____________________________________________________________ Here are the tasks in your list: 1.[T][Y] read book - 2.[D][N] return book (by: June 6th) - 3.[E][Y] project meeting (at: Aug 6th 2-4pm) + 2.[D][N] return book (by: Oct 6 2020, 19:30) + 3.[E][Y] project meeting (at: May 29 2021, 03:20) 4.[T][N] join sports club - 5.[D][N] return book (by: Sunday) - 6.[E][N] project meeting (at: Mon 2-4pm) - 7.[D][N] do homework (by: no idea :-p) + 5.[E][N] exams (at: May 3 2020, 16:00) + 6.[D][N] do homework (by: Apr 25 2020, 11:45) ____________________________________________________________ ____________________________________________________________ Nice! I've marked this task as done: - [D][Y] do homework (by: no idea :-p) + [D][Y] do homework (by: Apr 25 2020, 11:45) ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: 1.[T][Y] read book - 2.[D][N] return book (by: June 6th) - 3.[E][Y] project meeting (at: Aug 6th 2-4pm) + 2.[D][N] return book (by: Oct 6 2020, 19:30) + 3.[E][Y] project meeting (at: May 29 2021, 03:20) 4.[T][N] join sports club - 5.[D][N] return book (by: Sunday) - 6.[E][N] project meeting (at: Mon 2-4pm) - 7.[D][Y] do homework (by: no idea :-p) + 5.[E][N] exams (at: May 3 2020, 16:00) + 6.[D][Y] do homework (by: Apr 25 2020, 11:45) ____________________________________________________________ ____________________________________________________________ @@ -144,25 +138,23 @@ ____________________________________________________________ Here are the tasks in your list: 1.[T][Y] read book - 2.[D][N] return book (by: June 6th) - 3.[E][Y] project meeting (at: Aug 6th 2-4pm) + 2.[D][N] return book (by: Oct 6 2020, 19:30) + 3.[E][Y] project meeting (at: May 29 2021, 03:20) 4.[T][Y] join sports club - 5.[D][N] return book (by: Sunday) - 6.[E][N] project meeting (at: Mon 2-4pm) - 7.[D][Y] do homework (by: no idea :-p) + 5.[E][N] exams (at: May 3 2020, 16:00) + 6.[D][Y] do homework (by: Apr 25 2020, 11:45) ____________________________________________________________ ____________________________________________________________ Noted. I've removed this task: - [D][Y] do homework (by: no idea :-p) - Now you have 6 tasks in the list. + [D][Y] do homework (by: Apr 25 2020, 11:45) + Now you have 5 tasks in the list. ____________________________________________________________ ____________________________________________________________ Here are the matching tasks in your list: 1.[T][Y] read book - 2.[D][N] return book (by: June 6th) - 3.[D][N] return book (by: Sunday) + 2.[D][N] return book (by: Oct 6 2020, 19:30) ____________________________________________________________ ____________________________________________________________ @@ -244,6 +236,8 @@ | 06 | event j /at d | Add a task(j) that start at date d | |-------+------------------+------------------------------------| | 07 | delete j | Delete task(j) | +|-------+------------------+------------------------------------| +| 08 | find j | Find all task with description j | |---------------------------------------------------------------| ____________________________________________________________ diff --git a/text-ui-test/EXPECTED.txt b/text-ui-test/EXPECTED.txt index 402269f7f6..f85bd5c41b 100644 --- a/text-ui-test/EXPECTED.txt +++ b/text-ui-test/EXPECTED.txt @@ -17,6 +17,8 @@ | 06 | event j /at d | Add a task(j) that start at date d | |-------+------------------+------------------------------------| | 07 | delete j | Delete task(j) | +|-------+------------------+------------------------------------| +| 08 | find j | Find all task with description j | |---------------------------------------------------------------| What can I do for you? ____________________________________________________________ @@ -38,27 +40,27 @@ ____________________________________________________________ Got it. I've added this task: - [D][N] return book (by: June 6th) + [D][N] return book (by: Oct 6 2020, 19:30) Now you have 2 tasks in the list. ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: 1.[T][N] read book - 2.[D][N] return book (by: June 6th) + 2.[D][N] return book (by: Oct 6 2020, 19:30) ____________________________________________________________ ____________________________________________________________ Got it. I've added this task: - [E][N] project meeting (at: Aug 6th 2-4pm) + [E][N] project meeting (at: May 29 2021, 03:20) Now you have 3 tasks in the list. ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: 1.[T][N] read book - 2.[D][N] return book (by: June 6th) - 3.[E][N] project meeting (at: Aug 6th 2-4pm) + 2.[D][N] return book (by: Oct 6 2020, 19:30) + 3.[E][N] project meeting (at: May 29 2021, 03:20) ____________________________________________________________ ____________________________________________________________ @@ -69,20 +71,20 @@ ____________________________________________________________ Here are the tasks in your list: 1.[T][Y] read book - 2.[D][N] return book (by: June 6th) - 3.[E][N] project meeting (at: Aug 6th 2-4pm) + 2.[D][N] return book (by: Oct 6 2020, 19:30) + 3.[E][N] project meeting (at: May 29 2021, 03:20) ____________________________________________________________ ____________________________________________________________ Nice! I've marked this task as done: - [E][Y] project meeting (at: Aug 6th 2-4pm) + [E][Y] project meeting (at: May 29 2021, 03:20) ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: 1.[T][Y] read book - 2.[D][N] return book (by: June 6th) - 3.[E][Y] project meeting (at: Aug 6th 2-4pm) + 2.[D][N] return book (by: Oct 6 2020, 19:30) + 3.[E][Y] project meeting (at: May 29 2021, 03:20) ____________________________________________________________ ____________________________________________________________ @@ -93,47 +95,39 @@ ____________________________________________________________ Got it. I've added this task: - [D][N] return book (by: Sunday) + [E][N] exams (at: May 3 2020, 16:00) Now you have 5 tasks in the list. ____________________________________________________________ ____________________________________________________________ Got it. I've added this task: - [E][N] project meeting (at: Mon 2-4pm) + [D][N] do homework (by: Apr 25 2020, 11:45) Now you have 6 tasks in the list. ____________________________________________________________ - ____________________________________________________________ - Got it. I've added this task: - [D][N] do homework (by: no idea :-p) - Now you have 7 tasks in the list. - ____________________________________________________________ - ____________________________________________________________ Here are the tasks in your list: 1.[T][Y] read book - 2.[D][N] return book (by: June 6th) - 3.[E][Y] project meeting (at: Aug 6th 2-4pm) + 2.[D][N] return book (by: Oct 6 2020, 19:30) + 3.[E][Y] project meeting (at: May 29 2021, 03:20) 4.[T][N] join sports club - 5.[D][N] return book (by: Sunday) - 6.[E][N] project meeting (at: Mon 2-4pm) - 7.[D][N] do homework (by: no idea :-p) + 5.[E][N] exams (at: May 3 2020, 16:00) + 6.[D][N] do homework (by: Apr 25 2020, 11:45) ____________________________________________________________ ____________________________________________________________ Nice! I've marked this task as done: - [D][Y] do homework (by: no idea :-p) + [D][Y] do homework (by: Apr 25 2020, 11:45) ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: 1.[T][Y] read book - 2.[D][N] return book (by: June 6th) - 3.[E][Y] project meeting (at: Aug 6th 2-4pm) + 2.[D][N] return book (by: Oct 6 2020, 19:30) + 3.[E][Y] project meeting (at: May 29 2021, 03:20) 4.[T][N] join sports club - 5.[D][N] return book (by: Sunday) - 6.[E][N] project meeting (at: Mon 2-4pm) - 7.[D][Y] do homework (by: no idea :-p) + 5.[E][N] exams (at: May 3 2020, 16:00) + 6.[D][Y] do homework (by: Apr 25 2020, 11:45) ____________________________________________________________ ____________________________________________________________ @@ -144,25 +138,23 @@ ____________________________________________________________ Here are the tasks in your list: 1.[T][Y] read book - 2.[D][N] return book (by: June 6th) - 3.[E][Y] project meeting (at: Aug 6th 2-4pm) + 2.[D][N] return book (by: Oct 6 2020, 19:30) + 3.[E][Y] project meeting (at: May 29 2021, 03:20) 4.[T][Y] join sports club - 5.[D][N] return book (by: Sunday) - 6.[E][N] project meeting (at: Mon 2-4pm) - 7.[D][Y] do homework (by: no idea :-p) + 5.[E][N] exams (at: May 3 2020, 16:00) + 6.[D][Y] do homework (by: Apr 25 2020, 11:45) ____________________________________________________________ ____________________________________________________________ Noted. I've removed this task: - [D][Y] do homework (by: no idea :-p) - Now you have 6 tasks in the list. + [D][Y] do homework (by: Apr 25 2020, 11:45) + Now you have 5 tasks in the list. ____________________________________________________________ ____________________________________________________________ Here are the matching tasks in your list: 1.[T][Y] read book - 2.[D][N] return book (by: June 6th) - 3.[D][N] return book (by: Sunday) + 2.[D][N] return book (by: Oct 6 2020, 19:30) ____________________________________________________________ ____________________________________________________________ @@ -244,6 +236,8 @@ | 06 | event j /at d | Add a task(j) that start at date d | |-------+------------------+------------------------------------| | 07 | delete j | Delete task(j) | +|-------+------------------+------------------------------------| +| 08 | find j | Find all task with description j | |---------------------------------------------------------------| ____________________________________________________________ diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index 06c7d789a6..bb12e6abf3 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -1,24 +1,23 @@ list todo read book list -deadline return book /by June 6th +deadline return book /by 2020-10-06 19:30 list -event project meeting /at Aug 6th 2-4pm +event project meeting /at 2021-05-29 03:20 list done 1 list done 3 list todo join sports club -deadline return book /by Sunday -event project meeting /at Mon 2-4pm -deadline do homework /by no idea :-p +event exams /at 2020-05-03 16:00 +deadline do homework /by 2020-04-25 11:45 list -done 7 +done 6 list done 4 list -delete 7 +delete 6 find book find everything find From 8d1b6bba26108070c4035245de57fb346ad34052 Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Mon, 2 Mar 2020 18:37:03 +0800 Subject: [PATCH 23/45] Edit Duke File --- data/duke.txt | 9 ++-- src/main/java/duke/Duke.java | 13 +++-- src/main/java/duke/task/Deadline.java | 36 ++++---------- src/main/java/duke/task/Event.java | 31 +++--------- text-ui-test/ACTUAL.TXT | 70 +++++++++++++++------------ text-ui-test/EXPECTED.txt | 70 +++++++++++++++------------ text-ui-test/input.txt | 13 ++--- 7 files changed, 109 insertions(+), 133 deletions(-) diff --git a/data/duke.txt b/data/duke.txt index e4f34bee11..f873bacba5 100644 --- a/data/duke.txt +++ b/data/duke.txt @@ -1,7 +1,6 @@ T | 0 | read book -D | 0 | return book | June 6th -E | 1 | project meeting | Aug 6th 2-4pm +D | 0 | return book | 2020-10-06 19:30 +E | 1 | project meeting | 2021-05-29 03:20 T | 0 | join sports club -D | 0 | return book | Sunday -E | 0 | project meeting | Mon 2-4pm -D | 1 | do homework | no idea :-p +E | 0 | exams | 2020-05-03 16:00 +D | 1 | do homework | 2020-04-25 11:45 diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 1f7e568650..78c7ae551e 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -211,10 +211,10 @@ public static int eventCommand(ArrayList tasks, int taskCount, String stri } String description; - String dateTime; + String date; description = string.substring(0, string.indexOf(" /at")).replace("event ", ""); - dateTime = string.substring(string.indexOf("/at ")).replace("/at ", ""); - tasks.add(new Event(description, dateTime)); + date = string.substring(string.indexOf("/at ")).replace("/at ", ""); + tasks.add(new Event(description, date)); System.out.println(" Got it. I've added this task:"); System.out.println(" " + tasks.get(taskCount).toString()); taskCount++; @@ -240,11 +240,10 @@ public static int deadlineCommand(ArrayList tasks, int taskCount, String s } String description; - String dateTime; + String date; description = string.substring(0, string.indexOf(" /by")).replace("deadline ", ""); - dateTime = string.substring(string.indexOf("/by ")).replace("/by ", ""); - - tasks.add(new Deadline(description, dateTime)); + date = string.substring(string.indexOf("/by ")).replace("/by ", ""); + tasks.add(new Deadline(description, date)); System.out.println(" Got it. I've added this task:"); System.out.println(" " + tasks.get(taskCount).toString()); taskCount++; diff --git a/src/main/java/duke/task/Deadline.java b/src/main/java/duke/task/Deadline.java index 67472c3ec4..5b15af44c1 100644 --- a/src/main/java/duke/task/Deadline.java +++ b/src/main/java/duke/task/Deadline.java @@ -1,55 +1,37 @@ package duke.task; -import java.time.LocalDate; -import java.time.LocalTime; -import java.time.format.DateTimeFormatter; - /** - * The Deadline class is a Task with specified String description and String dateTime. - * The class stores the date as a LocalDate Object, time as a LocalTime Object and their combined - * String representation as a String dateTime. + * The Deadline class is a Task with specified description and due date. * Deadline class extends from Task class. * @author Lam Yue Wei * @version CS2113 AY19/20 Sem 2 Duke */ public class Deadline extends Task { - String dateTime; - LocalDate date; - LocalTime time; + String date; /** * Public constructor for Deadline. * @param description Description of the Deadline Task. - * @param dateTime Due date and time of the Deadline Task. + * @param date Due date of the Deadline Task. */ - public Deadline(String description, String dateTime) { + public Deadline(String description, String date) { super(description); - this.dateTime = dateTime; - date = LocalDate.parse(dateTime.split(" ")[0]); - time = LocalTime.parse(dateTime.split(" ")[1]); + this.date = date; } /** - * Getter method for the date. + * Getter method for the due date. * @return Due date. */ public String getDate() { - return this.date.format(DateTimeFormatter.ofPattern("MMM d yyyy")); - } - - /** - * Getter method for the time. - * @return Due time. - */ - public String getTime() { - return this.time.toString(); + return this.date; } /** * Return a String representation of this Deadline. - * @return The Deadline's icon, followed by the Task's toString, followed by the due date and time. + * @return The Deadline's icon, followed by the Task's toString, followed by the due date. */ public String toString() { - return "[D]" + super.toString() + " (by: " + getDate() + ", " + getTime() + ")"; + return "[D]" + super.toString() + " (by: " + this.date + ")"; } } diff --git a/src/main/java/duke/task/Event.java b/src/main/java/duke/task/Event.java index 5647b1b9bc..0ad4edb7eb 100644 --- a/src/main/java/duke/task/Event.java +++ b/src/main/java/duke/task/Event.java @@ -1,9 +1,5 @@ package duke.task; -import java.time.LocalDate; -import java.time.LocalTime; -import java.time.format.DateTimeFormatter; - /** * The Event class is a Task with specified description and date of occurrence. * Event class extends from Task class. @@ -11,21 +7,16 @@ * @version CS2113 AY19/20 Sem 2 Duke */ public class Event extends Task { - String dateTime; - LocalDate date; - LocalTime time; - + String date; /** * Public constructor for Event. * @param description Description of the Event Task. - * @param dateTime Date of occurrence and time of the Event Task. + * @param date Date of occurrence of the Event Task. */ - public Event(String description, String dateTime) { + public Event(String description, String date) { super(description); - this.dateTime = dateTime; - date = LocalDate.parse(dateTime.split(" ")[0]); - time = LocalTime.parse(dateTime.split(" ")[1]); + this.date = date; } /** @@ -33,22 +24,14 @@ public Event(String description, String dateTime) { * @return Date of occurrence. */ public String getDate() { - return this.date.format(DateTimeFormatter.ofPattern("MMM d yyyy")); - } - - /** - * Getter method for the time of occurrence. - * @return Time of occurrence. - */ - public String getTime() { - return this.time.toString(); + return this.date; } /** * Return a String representation of this Event. - * @return The Event's icon, followed by the Task's toString, followed by the date and time of occurrence. + * @return The Event's icon, followed by the Task's toString, followed by the date of occurrence. */ public String toString() { - return "[E]" + super.toString() + " (at: " + getDate() + ", " + getTime() + ")"; + return "[E]" + super.toString() + " (at: " + this.date + ")"; } } diff --git a/text-ui-test/ACTUAL.TXT b/text-ui-test/ACTUAL.TXT index f85bd5c41b..402269f7f6 100644 --- a/text-ui-test/ACTUAL.TXT +++ b/text-ui-test/ACTUAL.TXT @@ -17,8 +17,6 @@ | 06 | event j /at d | Add a task(j) that start at date d | |-------+------------------+------------------------------------| | 07 | delete j | Delete task(j) | -|-------+------------------+------------------------------------| -| 08 | find j | Find all task with description j | |---------------------------------------------------------------| What can I do for you? ____________________________________________________________ @@ -40,27 +38,27 @@ ____________________________________________________________ Got it. I've added this task: - [D][N] return book (by: Oct 6 2020, 19:30) + [D][N] return book (by: June 6th) Now you have 2 tasks in the list. ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: 1.[T][N] read book - 2.[D][N] return book (by: Oct 6 2020, 19:30) + 2.[D][N] return book (by: June 6th) ____________________________________________________________ ____________________________________________________________ Got it. I've added this task: - [E][N] project meeting (at: May 29 2021, 03:20) + [E][N] project meeting (at: Aug 6th 2-4pm) Now you have 3 tasks in the list. ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: 1.[T][N] read book - 2.[D][N] return book (by: Oct 6 2020, 19:30) - 3.[E][N] project meeting (at: May 29 2021, 03:20) + 2.[D][N] return book (by: June 6th) + 3.[E][N] project meeting (at: Aug 6th 2-4pm) ____________________________________________________________ ____________________________________________________________ @@ -71,20 +69,20 @@ ____________________________________________________________ Here are the tasks in your list: 1.[T][Y] read book - 2.[D][N] return book (by: Oct 6 2020, 19:30) - 3.[E][N] project meeting (at: May 29 2021, 03:20) + 2.[D][N] return book (by: June 6th) + 3.[E][N] project meeting (at: Aug 6th 2-4pm) ____________________________________________________________ ____________________________________________________________ Nice! I've marked this task as done: - [E][Y] project meeting (at: May 29 2021, 03:20) + [E][Y] project meeting (at: Aug 6th 2-4pm) ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: 1.[T][Y] read book - 2.[D][N] return book (by: Oct 6 2020, 19:30) - 3.[E][Y] project meeting (at: May 29 2021, 03:20) + 2.[D][N] return book (by: June 6th) + 3.[E][Y] project meeting (at: Aug 6th 2-4pm) ____________________________________________________________ ____________________________________________________________ @@ -95,39 +93,47 @@ ____________________________________________________________ Got it. I've added this task: - [E][N] exams (at: May 3 2020, 16:00) + [D][N] return book (by: Sunday) Now you have 5 tasks in the list. ____________________________________________________________ ____________________________________________________________ Got it. I've added this task: - [D][N] do homework (by: Apr 25 2020, 11:45) + [E][N] project meeting (at: Mon 2-4pm) Now you have 6 tasks in the list. ____________________________________________________________ + ____________________________________________________________ + Got it. I've added this task: + [D][N] do homework (by: no idea :-p) + Now you have 7 tasks in the list. + ____________________________________________________________ + ____________________________________________________________ Here are the tasks in your list: 1.[T][Y] read book - 2.[D][N] return book (by: Oct 6 2020, 19:30) - 3.[E][Y] project meeting (at: May 29 2021, 03:20) + 2.[D][N] return book (by: June 6th) + 3.[E][Y] project meeting (at: Aug 6th 2-4pm) 4.[T][N] join sports club - 5.[E][N] exams (at: May 3 2020, 16:00) - 6.[D][N] do homework (by: Apr 25 2020, 11:45) + 5.[D][N] return book (by: Sunday) + 6.[E][N] project meeting (at: Mon 2-4pm) + 7.[D][N] do homework (by: no idea :-p) ____________________________________________________________ ____________________________________________________________ Nice! I've marked this task as done: - [D][Y] do homework (by: Apr 25 2020, 11:45) + [D][Y] do homework (by: no idea :-p) ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: 1.[T][Y] read book - 2.[D][N] return book (by: Oct 6 2020, 19:30) - 3.[E][Y] project meeting (at: May 29 2021, 03:20) + 2.[D][N] return book (by: June 6th) + 3.[E][Y] project meeting (at: Aug 6th 2-4pm) 4.[T][N] join sports club - 5.[E][N] exams (at: May 3 2020, 16:00) - 6.[D][Y] do homework (by: Apr 25 2020, 11:45) + 5.[D][N] return book (by: Sunday) + 6.[E][N] project meeting (at: Mon 2-4pm) + 7.[D][Y] do homework (by: no idea :-p) ____________________________________________________________ ____________________________________________________________ @@ -138,23 +144,25 @@ ____________________________________________________________ Here are the tasks in your list: 1.[T][Y] read book - 2.[D][N] return book (by: Oct 6 2020, 19:30) - 3.[E][Y] project meeting (at: May 29 2021, 03:20) + 2.[D][N] return book (by: June 6th) + 3.[E][Y] project meeting (at: Aug 6th 2-4pm) 4.[T][Y] join sports club - 5.[E][N] exams (at: May 3 2020, 16:00) - 6.[D][Y] do homework (by: Apr 25 2020, 11:45) + 5.[D][N] return book (by: Sunday) + 6.[E][N] project meeting (at: Mon 2-4pm) + 7.[D][Y] do homework (by: no idea :-p) ____________________________________________________________ ____________________________________________________________ Noted. I've removed this task: - [D][Y] do homework (by: Apr 25 2020, 11:45) - Now you have 5 tasks in the list. + [D][Y] do homework (by: no idea :-p) + Now you have 6 tasks in the list. ____________________________________________________________ ____________________________________________________________ Here are the matching tasks in your list: 1.[T][Y] read book - 2.[D][N] return book (by: Oct 6 2020, 19:30) + 2.[D][N] return book (by: June 6th) + 3.[D][N] return book (by: Sunday) ____________________________________________________________ ____________________________________________________________ @@ -236,8 +244,6 @@ | 06 | event j /at d | Add a task(j) that start at date d | |-------+------------------+------------------------------------| | 07 | delete j | Delete task(j) | -|-------+------------------+------------------------------------| -| 08 | find j | Find all task with description j | |---------------------------------------------------------------| ____________________________________________________________ diff --git a/text-ui-test/EXPECTED.txt b/text-ui-test/EXPECTED.txt index f85bd5c41b..402269f7f6 100644 --- a/text-ui-test/EXPECTED.txt +++ b/text-ui-test/EXPECTED.txt @@ -17,8 +17,6 @@ | 06 | event j /at d | Add a task(j) that start at date d | |-------+------------------+------------------------------------| | 07 | delete j | Delete task(j) | -|-------+------------------+------------------------------------| -| 08 | find j | Find all task with description j | |---------------------------------------------------------------| What can I do for you? ____________________________________________________________ @@ -40,27 +38,27 @@ ____________________________________________________________ Got it. I've added this task: - [D][N] return book (by: Oct 6 2020, 19:30) + [D][N] return book (by: June 6th) Now you have 2 tasks in the list. ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: 1.[T][N] read book - 2.[D][N] return book (by: Oct 6 2020, 19:30) + 2.[D][N] return book (by: June 6th) ____________________________________________________________ ____________________________________________________________ Got it. I've added this task: - [E][N] project meeting (at: May 29 2021, 03:20) + [E][N] project meeting (at: Aug 6th 2-4pm) Now you have 3 tasks in the list. ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: 1.[T][N] read book - 2.[D][N] return book (by: Oct 6 2020, 19:30) - 3.[E][N] project meeting (at: May 29 2021, 03:20) + 2.[D][N] return book (by: June 6th) + 3.[E][N] project meeting (at: Aug 6th 2-4pm) ____________________________________________________________ ____________________________________________________________ @@ -71,20 +69,20 @@ ____________________________________________________________ Here are the tasks in your list: 1.[T][Y] read book - 2.[D][N] return book (by: Oct 6 2020, 19:30) - 3.[E][N] project meeting (at: May 29 2021, 03:20) + 2.[D][N] return book (by: June 6th) + 3.[E][N] project meeting (at: Aug 6th 2-4pm) ____________________________________________________________ ____________________________________________________________ Nice! I've marked this task as done: - [E][Y] project meeting (at: May 29 2021, 03:20) + [E][Y] project meeting (at: Aug 6th 2-4pm) ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: 1.[T][Y] read book - 2.[D][N] return book (by: Oct 6 2020, 19:30) - 3.[E][Y] project meeting (at: May 29 2021, 03:20) + 2.[D][N] return book (by: June 6th) + 3.[E][Y] project meeting (at: Aug 6th 2-4pm) ____________________________________________________________ ____________________________________________________________ @@ -95,39 +93,47 @@ ____________________________________________________________ Got it. I've added this task: - [E][N] exams (at: May 3 2020, 16:00) + [D][N] return book (by: Sunday) Now you have 5 tasks in the list. ____________________________________________________________ ____________________________________________________________ Got it. I've added this task: - [D][N] do homework (by: Apr 25 2020, 11:45) + [E][N] project meeting (at: Mon 2-4pm) Now you have 6 tasks in the list. ____________________________________________________________ + ____________________________________________________________ + Got it. I've added this task: + [D][N] do homework (by: no idea :-p) + Now you have 7 tasks in the list. + ____________________________________________________________ + ____________________________________________________________ Here are the tasks in your list: 1.[T][Y] read book - 2.[D][N] return book (by: Oct 6 2020, 19:30) - 3.[E][Y] project meeting (at: May 29 2021, 03:20) + 2.[D][N] return book (by: June 6th) + 3.[E][Y] project meeting (at: Aug 6th 2-4pm) 4.[T][N] join sports club - 5.[E][N] exams (at: May 3 2020, 16:00) - 6.[D][N] do homework (by: Apr 25 2020, 11:45) + 5.[D][N] return book (by: Sunday) + 6.[E][N] project meeting (at: Mon 2-4pm) + 7.[D][N] do homework (by: no idea :-p) ____________________________________________________________ ____________________________________________________________ Nice! I've marked this task as done: - [D][Y] do homework (by: Apr 25 2020, 11:45) + [D][Y] do homework (by: no idea :-p) ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: 1.[T][Y] read book - 2.[D][N] return book (by: Oct 6 2020, 19:30) - 3.[E][Y] project meeting (at: May 29 2021, 03:20) + 2.[D][N] return book (by: June 6th) + 3.[E][Y] project meeting (at: Aug 6th 2-4pm) 4.[T][N] join sports club - 5.[E][N] exams (at: May 3 2020, 16:00) - 6.[D][Y] do homework (by: Apr 25 2020, 11:45) + 5.[D][N] return book (by: Sunday) + 6.[E][N] project meeting (at: Mon 2-4pm) + 7.[D][Y] do homework (by: no idea :-p) ____________________________________________________________ ____________________________________________________________ @@ -138,23 +144,25 @@ ____________________________________________________________ Here are the tasks in your list: 1.[T][Y] read book - 2.[D][N] return book (by: Oct 6 2020, 19:30) - 3.[E][Y] project meeting (at: May 29 2021, 03:20) + 2.[D][N] return book (by: June 6th) + 3.[E][Y] project meeting (at: Aug 6th 2-4pm) 4.[T][Y] join sports club - 5.[E][N] exams (at: May 3 2020, 16:00) - 6.[D][Y] do homework (by: Apr 25 2020, 11:45) + 5.[D][N] return book (by: Sunday) + 6.[E][N] project meeting (at: Mon 2-4pm) + 7.[D][Y] do homework (by: no idea :-p) ____________________________________________________________ ____________________________________________________________ Noted. I've removed this task: - [D][Y] do homework (by: Apr 25 2020, 11:45) - Now you have 5 tasks in the list. + [D][Y] do homework (by: no idea :-p) + Now you have 6 tasks in the list. ____________________________________________________________ ____________________________________________________________ Here are the matching tasks in your list: 1.[T][Y] read book - 2.[D][N] return book (by: Oct 6 2020, 19:30) + 2.[D][N] return book (by: June 6th) + 3.[D][N] return book (by: Sunday) ____________________________________________________________ ____________________________________________________________ @@ -236,8 +244,6 @@ | 06 | event j /at d | Add a task(j) that start at date d | |-------+------------------+------------------------------------| | 07 | delete j | Delete task(j) | -|-------+------------------+------------------------------------| -| 08 | find j | Find all task with description j | |---------------------------------------------------------------| ____________________________________________________________ diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index bb12e6abf3..06c7d789a6 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -1,23 +1,24 @@ list todo read book list -deadline return book /by 2020-10-06 19:30 +deadline return book /by June 6th list -event project meeting /at 2021-05-29 03:20 +event project meeting /at Aug 6th 2-4pm list done 1 list done 3 list todo join sports club -event exams /at 2020-05-03 16:00 -deadline do homework /by 2020-04-25 11:45 +deadline return book /by Sunday +event project meeting /at Mon 2-4pm +deadline do homework /by no idea :-p list -done 6 +done 7 list done 4 list -delete 6 +delete 7 find book find everything find From 9db50adb9130a6be44c8447d5a18b4d68d5cea09 Mon Sep 17 00:00:00 2001 From: Lam Yue Wei <60146045+lamyuewei@users.noreply.github.com> Date: Mon, 2 Mar 2020 19:08:04 +0800 Subject: [PATCH 24/45] Set theme jekyll-theme-cayman --- docs/_config.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/_config.yml diff --git a/docs/_config.yml b/docs/_config.yml new file mode 100644 index 0000000000..c4192631f2 --- /dev/null +++ b/docs/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-cayman \ No newline at end of file From 40c9d1c39219bde90635a95d265ce3b3411a1e8a Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Mon, 2 Mar 2020 20:35:22 +0800 Subject: [PATCH 25/45] Complete A-UserGuide: User Guide --- README.md | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 68 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5dc79b47cb..49b18d5235 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,69 @@ -# Setting up +#User Guide for Duke +##Introduction +Duke is your personal chatbot who is capable of managing your task. + +Some of the task that Duke can manage are *Todo*, *Deadline* and *Event*. + +* **Todo:** A Task with description of what needs to be done. +* **Deadline:** A Task with description of what needs to be done along with the due date and time. +* **Event:** A Task with description of what needs to be done along with the date and time that the task will occur. + +##Features +Below are the list of command that you can key in to interact with Duke. +1. Add Task + 1. Input: todo j\ + Example: todo CS2113 Homework\ + Command: Add a *Todo* Task with String description j. + + 1. Input: deadline j /by d\ + Example: deadline CS2113 Homework /by 2020-04-15 16:00\ + Command: Add a *Deadline* Task with String description j, followed by "/by", then the corresponding due date in YYYY-MM-DD format and the time in HH:MM format.\ + + 1. Input: event j /at d\ + Example: deadline CS2113 Homework /at 2020-04-15 16:00\ + Command: Add a *Event* Task with String description j, followed by "/at", then the corresponding date in YYYY-MM-DD format and the time in HH:MM format. + +1. List Task\ +Input: list\ +Example: list\ +Command: List out all the stored task. + +1. Complete Task\ +Input: done i\ +Example: done 3\ +Command: Mark Task i as done, where i is the corresponding Task number. + +1. Delete Task\ +Input: delete i\ +Example: delete 3\ +Command: Delete Task i, where i is the corresponding Task number. + +1. Find Task\ +Input: find j\ +Example: find Homework\ +Command: Find all the task with description that contains the word/phrase j. + +1. Exit\ +Input: bye\ +Command: Terminate the program and automatically help you store the Task into your hard disk with directory ../data/Duke.txt\ +**Note:** Duke will help you take care of creating a folder and txt file if one does not already exist. + +##Summary of Commands +Index | Input | Command +---|-------------------------------------------|----------------------------------------------- +01 | list | List out all the stored task +02 | done index | Mark task index as done +03 | bye | Terminate the program +04 | todo description | Add a todo task with description +05 | dateline description /by YYYY-MM-DD HH:MM | Add a deadline task description and due date +06 | event description /by YYYY-MM-DD HH:MM | Add a event task description and due date +07 | delete index | Delete task index +08 | find description | Find all task containing the description + + +**Additional information can be found below** + +## Setting up **Prerequisites** @@ -20,7 +85,7 @@ 1. Ensure that your src folder is checked. Keep clicking `Next`. 1. Click `Finish`. -# Tutorials +## Tutorials duke.Duke Increment | Tutorial ---------------|--------------- @@ -33,7 +98,7 @@ duke.Duke Increment | Tutorial [fx3]: [fx4]: -# Feedback, Bug Reports +## Feedback, Bug Reports * If you have feedback or bug reports, please post in [se-edu/duke issue tracker](https://github.com/se-edu/duke/issues). * We welcome pull requests too. \ No newline at end of file From 64039713c77563358a00fe42235af7f9cd25b304 Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Mon, 2 Mar 2020 21:05:51 +0800 Subject: [PATCH 26/45] Rectify issue of editing on the Wrong README earlier --- README.md | 71 ++----------------------------------------- docs/README.md | 81 +++++++++++++++++++++++++++++++++++++------------- 2 files changed, 64 insertions(+), 88 deletions(-) diff --git a/README.md b/README.md index 49b18d5235..5dc79b47cb 100644 --- a/README.md +++ b/README.md @@ -1,69 +1,4 @@ -#User Guide for Duke -##Introduction -Duke is your personal chatbot who is capable of managing your task. - -Some of the task that Duke can manage are *Todo*, *Deadline* and *Event*. - -* **Todo:** A Task with description of what needs to be done. -* **Deadline:** A Task with description of what needs to be done along with the due date and time. -* **Event:** A Task with description of what needs to be done along with the date and time that the task will occur. - -##Features -Below are the list of command that you can key in to interact with Duke. -1. Add Task - 1. Input: todo j\ - Example: todo CS2113 Homework\ - Command: Add a *Todo* Task with String description j. - - 1. Input: deadline j /by d\ - Example: deadline CS2113 Homework /by 2020-04-15 16:00\ - Command: Add a *Deadline* Task with String description j, followed by "/by", then the corresponding due date in YYYY-MM-DD format and the time in HH:MM format.\ - - 1. Input: event j /at d\ - Example: deadline CS2113 Homework /at 2020-04-15 16:00\ - Command: Add a *Event* Task with String description j, followed by "/at", then the corresponding date in YYYY-MM-DD format and the time in HH:MM format. - -1. List Task\ -Input: list\ -Example: list\ -Command: List out all the stored task. - -1. Complete Task\ -Input: done i\ -Example: done 3\ -Command: Mark Task i as done, where i is the corresponding Task number. - -1. Delete Task\ -Input: delete i\ -Example: delete 3\ -Command: Delete Task i, where i is the corresponding Task number. - -1. Find Task\ -Input: find j\ -Example: find Homework\ -Command: Find all the task with description that contains the word/phrase j. - -1. Exit\ -Input: bye\ -Command: Terminate the program and automatically help you store the Task into your hard disk with directory ../data/Duke.txt\ -**Note:** Duke will help you take care of creating a folder and txt file if one does not already exist. - -##Summary of Commands -Index | Input | Command ----|-------------------------------------------|----------------------------------------------- -01 | list | List out all the stored task -02 | done index | Mark task index as done -03 | bye | Terminate the program -04 | todo description | Add a todo task with description -05 | dateline description /by YYYY-MM-DD HH:MM | Add a deadline task description and due date -06 | event description /by YYYY-MM-DD HH:MM | Add a event task description and due date -07 | delete index | Delete task index -08 | find description | Find all task containing the description - - -**Additional information can be found below** - -## Setting up +# Setting up **Prerequisites** @@ -85,7 +20,7 @@ Index | Input | Command 1. Ensure that your src folder is checked. Keep clicking `Next`. 1. Click `Finish`. -## Tutorials +# Tutorials duke.Duke Increment | Tutorial ---------------|--------------- @@ -98,7 +33,7 @@ duke.Duke Increment | Tutorial [fx3]: [fx4]: -## Feedback, Bug Reports +# Feedback, Bug Reports * If you have feedback or bug reports, please post in [se-edu/duke issue tracker](https://github.com/se-edu/duke/issues). * We welcome pull requests too. \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index fd44069597..f3e0ce9d30 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,20 +1,61 @@ -# User Guide - -## Features - -### Feature 1 -Description of feature. - -## Usage - -### `Keyword` - Describe action - -Describe action and its outcome. - -Example of usage: - -`keyword (optional arguments)` - -Expected outcome: - -`outcome` +#User Guide for Duke +##Introduction +Duke is your personal chatbot who is capable of managing your task. + +Some of the task that Duke can manage are *Todo*, *Deadline* and *Event*. + +* **Todo:** A Task with description of what needs to be done. +* **Deadline:** A Task with description of what needs to be done along with the due date and time. +* **Event:** A Task with description of what needs to be done along with the date and time that the task will occur. + +##Features +Below are the list of command that you can key in to interact with Duke. +1. Add Task + 1. Input: todo j\ + Example: todo CS2113 Homework\ + Command: Add a *Todo* Task with String description j. + + 1. Input: deadline j /by d\ + Example: deadline CS2113 Homework /by 2020-04-15 16:00\ + Command: Add a *Deadline* Task with String description j, followed by "/by", then the corresponding due date in YYYY-MM-DD format and the time in HH:MM format.\ + + 1. Input: event j /at d\ + Example: deadline CS2113 Homework /at 2020-04-15 16:00\ + Command: Add a *Event* Task with String description j, followed by "/at", then the corresponding date in YYYY-MM-DD format and the time in HH:MM format. + +1. List Task\ +Input: list\ +Example: list\ +Command: List out all the stored task. + +1. Complete Task\ +Input: done i\ +Example: done 3\ +Command: Mark Task i as done, where i is the corresponding Task number. + +1. Delete Task\ +Input: delete i\ +Example: delete 3\ +Command: Delete Task i, where i is the corresponding Task number. + +1. Find Task\ +Input: find j\ +Example: find Homework\ +Command: Find all the task with description that contains the word/phrase j. + +1. Exit\ +Input: bye\ +Command: Terminate the program and automatically help you store the Task into your hard disk with directory ../data/Duke.txt\ +**Note:** Duke will help you take care of creating a folder and txt file if one does not already exist. + +##Summary of Commands +Index | Input | Command +---|-------------------------------------------|----------------------------------------------- +01 | list | List out all the stored task +02 | done index | Mark task index as done +03 | bye | Terminate the program +04 | todo description | Add a todo task with description +05 | dateline description /by YYYY-MM-DD HH:MM | Add a deadline task description and due date +06 | event description /by YYYY-MM-DD HH:MM | Add a event task description and due date +07 | delete index | Delete task index +08 | find description | Find all task containing the description From 8b2079c6ee6586916b6d2b497209747b6c5d2d4d Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Mon, 2 Mar 2020 21:17:20 +0800 Subject: [PATCH 27/45] Bug fixed to rmake word bold instead of showing # --- docs/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/README.md b/docs/README.md index f3e0ce9d30..ef844c938a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,5 +1,5 @@ -#User Guide for Duke -##Introduction +# User Guide for Duke +## Introduction Duke is your personal chatbot who is capable of managing your task. Some of the task that Duke can manage are *Todo*, *Deadline* and *Event*. @@ -8,7 +8,7 @@ Some of the task that Duke can manage are *Todo*, *Deadline* and *Event*. * **Deadline:** A Task with description of what needs to be done along with the due date and time. * **Event:** A Task with description of what needs to be done along with the date and time that the task will occur. -##Features +## Features Below are the list of command that you can key in to interact with Duke. 1. Add Task 1. Input: todo j\ @@ -48,7 +48,7 @@ Input: bye\ Command: Terminate the program and automatically help you store the Task into your hard disk with directory ../data/Duke.txt\ **Note:** Duke will help you take care of creating a folder and txt file if one does not already exist. -##Summary of Commands +## Summary of Commands Index | Input | Command ---|-------------------------------------------|----------------------------------------------- 01 | list | List out all the stored task From 0d43e60003349afec2172aed0a00d6188ce12275 Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Mon, 2 Mar 2020 21:28:30 +0800 Subject: [PATCH 28/45] Bug Fixed for README next line --- docs/README.md | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/docs/README.md b/docs/README.md index ef844c938a..3633331bfd 100644 --- a/docs/README.md +++ b/docs/README.md @@ -11,41 +11,41 @@ Some of the task that Duke can manage are *Todo*, *Deadline* and *Event*. ## Features Below are the list of command that you can key in to interact with Duke. 1. Add Task - 1. Input: todo j\ - Example: todo CS2113 Homework\ + 1. Input: todo j + Example: todo CS2113 Homework Command: Add a *Todo* Task with String description j. - 1. Input: deadline j /by d\ - Example: deadline CS2113 Homework /by 2020-04-15 16:00\ + 1. Input: deadline j /by d + Example: deadline CS2113 Homework /by 2020-04-15 16:00 Command: Add a *Deadline* Task with String description j, followed by "/by", then the corresponding due date in YYYY-MM-DD format and the time in HH:MM format.\ - 1. Input: event j /at d\ - Example: deadline CS2113 Homework /at 2020-04-15 16:00\ + 1. Input: event j /at d + Example: deadline CS2113 Homework /at 2020-04-15 16:00 Command: Add a *Event* Task with String description j, followed by "/at", then the corresponding date in YYYY-MM-DD format and the time in HH:MM format. -1. List Task\ -Input: list\ -Example: list\ +1. List Task +Input: list +Example: list Command: List out all the stored task. -1. Complete Task\ -Input: done i\ -Example: done 3\ +1. Complete Task +Input: done i +Example: done 3 Command: Mark Task i as done, where i is the corresponding Task number. -1. Delete Task\ -Input: delete i\ -Example: delete 3\ +1. Delete Task +Input: delete i +Example: delete 3 Command: Delete Task i, where i is the corresponding Task number. -1. Find Task\ -Input: find j\ -Example: find Homework\ +1. Find Task +Input: find j +Example: find Homework Command: Find all the task with description that contains the word/phrase j. -1. Exit\ -Input: bye\ -Command: Terminate the program and automatically help you store the Task into your hard disk with directory ../data/Duke.txt\ +1. Exit +Input: bye +Command: Terminate the program and automatically help you store the Task into your hard disk with directory ../data/Duke.txt **Note:** Duke will help you take care of creating a folder and txt file if one does not already exist. ## Summary of Commands From 17943793657816ac002f8d3dc8f5be40949af2ad Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Mon, 2 Mar 2020 21:36:48 +0800 Subject: [PATCH 29/45] Bug Fix for Summary of Content in README --- docs/README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/README.md b/docs/README.md index 3633331bfd..1544bced0f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -49,13 +49,13 @@ Command: Terminate the program and automatically help you store the Task into yo **Note:** Duke will help you take care of creating a folder and txt file if one does not already exist. ## Summary of Commands -Index | Input | Command ----|-------------------------------------------|----------------------------------------------- -01 | list | List out all the stored task -02 | done index | Mark task index as done -03 | bye | Terminate the program -04 | todo description | Add a todo task with description -05 | dateline description /by YYYY-MM-DD HH:MM | Add a deadline task description and due date -06 | event description /by YYYY-MM-DD HH:MM | Add a event task description and due date -07 | delete index | Delete task index -08 | find description | Find all task containing the description +| Index | Input | Command | +| ----- | ----- | --------------- | +| 01 | list | List out all the stored task | +| 02 | done index | Mark task index as done | +| 03 | bye | Terminate the program and store all Task into hard disk | +| 04 | todo description | Add a todo task with description | +| 05 | dateline description /by YYYY-MM-DD HH:MM | Add a deadline task description and due date | +| 06 | event description /by YYYY-MM-DD HH:MM | Add a event task description and due date | +| 07 | delete index | Delete task index | +| 08 | find description | Find all task containing the description | From a50358ead6fdf6dcc9aedeeb52c8df477bbfdd55 Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Mon, 2 Mar 2020 21:40:25 +0800 Subject: [PATCH 30/45] Bug fix v2 for Summary of Command in README --- docs/README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/README.md b/docs/README.md index 1544bced0f..2205fc6baf 100644 --- a/docs/README.md +++ b/docs/README.md @@ -49,13 +49,13 @@ Command: Terminate the program and automatically help you store the Task into yo **Note:** Duke will help you take care of creating a folder and txt file if one does not already exist. ## Summary of Commands -| Index | Input | Command | -| ----- | ----- | --------------- | -| 01 | list | List out all the stored task | -| 02 | done index | Mark task index as done | -| 03 | bye | Terminate the program and store all Task into hard disk | -| 04 | todo description | Add a todo task with description | -| 05 | dateline description /by YYYY-MM-DD HH:MM | Add a deadline task description and due date | -| 06 | event description /by YYYY-MM-DD HH:MM | Add a event task description and due date | -| 07 | delete index | Delete task index | -| 08 | find description | Find all task containing the description | +| Index | Input | Command | +| ----- | ----- | --------------- | +| 01 | list | List out all the stored task | +| 02 | done index | Mark task index as done | +| 03 | bye | Terminate the program and store all Task into hard disk | +| 04 | todo description | Add a todo task with description | +| 05 | dateline description /by YYYY-MM-DD HH:MM | Add a deadline task description and due date | +| 06 | event description /by YYYY-MM-DD HH:MM | Add a event task description and due date | +| 07 | delete index | Delete task index | +| 08 | find description | Find all task containing the description | From d4344790f2464460aedf0dbf16cfe4a27b1c39c6 Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Mon, 2 Mar 2020 21:45:26 +0800 Subject: [PATCH 31/45] Bug fix v3 for Summary of Comand in README --- docs/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/README.md b/docs/README.md index 2205fc6baf..0ef69402cc 100644 --- a/docs/README.md +++ b/docs/README.md @@ -49,6 +49,7 @@ Command: Terminate the program and automatically help you store the Task into yo **Note:** Duke will help you take care of creating a folder and txt file if one does not already exist. ## Summary of Commands + | Index | Input | Command | | ----- | ----- | --------------- | | 01 | list | List out all the stored task | From 3d47646949a49350bf7926194f59257b5b1d2bb9 Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Mon, 2 Mar 2020 21:48:45 +0800 Subject: [PATCH 32/45] Bug Fixed Typo in README --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 0ef69402cc..475afa191e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -57,6 +57,6 @@ Command: Terminate the program and automatically help you store the Task into yo | 03 | bye | Terminate the program and store all Task into hard disk | | 04 | todo description | Add a todo task with description | | 05 | dateline description /by YYYY-MM-DD HH:MM | Add a deadline task description and due date | -| 06 | event description /by YYYY-MM-DD HH:MM | Add a event task description and due date | +| 06 | event description /at YYYY-MM-DD HH:MM | Add a event task description and due date | | 07 | delete index | Delete task index | | 08 | find description | Find all task containing the description | From 8946f002faf758f6b776109b4a0c78afa7321345 Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Mon, 2 Mar 2020 22:23:44 +0800 Subject: [PATCH 33/45] Add help command --- docs/README.md | 21 +++++++----- src/main/java/duke/Duke.java | 26 ++++++++------ text-ui-test/ACTUAL.TXT | 66 +++++++++++++++++++++--------------- text-ui-test/EXPECTED.txt | 66 +++++++++++++++++++++--------------- text-ui-test/input.txt | 1 + 5 files changed, 105 insertions(+), 75 deletions(-) diff --git a/docs/README.md b/docs/README.md index 475afa191e..764bfd48a5 100644 --- a/docs/README.md +++ b/docs/README.md @@ -43,6 +43,10 @@ Input: find j Example: find Homework Command: Find all the task with description that contains the word/phrase j. +1. Help +Input: help +Command: List out all the commands + 1. Exit Input: bye Command: Terminate the program and automatically help you store the Task into your hard disk with directory ../data/Duke.txt @@ -52,11 +56,12 @@ Command: Terminate the program and automatically help you store the Task into yo | Index | Input | Command | | ----- | ----- | --------------- | -| 01 | list | List out all the stored task | -| 02 | done index | Mark task index as done | -| 03 | bye | Terminate the program and store all Task into hard disk | -| 04 | todo description | Add a todo task with description | -| 05 | dateline description /by YYYY-MM-DD HH:MM | Add a deadline task description and due date | -| 06 | event description /at YYYY-MM-DD HH:MM | Add a event task description and due date | -| 07 | delete index | Delete task index | -| 08 | find description | Find all task containing the description | +| 01 | todo description | Add a todo task with description | +| 02 | dateline description /by YYYY-MM-DD HH:MM | Add a deadline task description and due date | +| 03 | event description /at YYYY-MM-DD HH:MM | Add a event task description and due date | +| 04 | list | List out all the stored task | +| 05 | done index | Mark task index as done | +| 06 | delete index | Delete task index | +| 07 | find description | Find all task containing the description | +| 08 | help | List out all the commands | +| 09 | bye | Terminate the program and store all Task into hard disk | diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 1f7e568650..c0fe658720 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -69,6 +69,8 @@ public static void main(String[] args) { case "find": findCommand(tasks, taskCount, string); break; + case "help": + helpCommand(); default: throw new DukeNullException(" :( OOPS!!! Command does not exist."); } @@ -76,7 +78,7 @@ public static void main(String[] args) { System.out.println(e.getMessage()); } catch (DukeNullException e) { System.out.println(e.getMessage()); - commandList(); + System.out.println(" To view the list of commands available use the command: help"); } catch (NumberFormatException e) { System.out.println(" :( OOPS!!! " + e.getMessage().substring(18) + " is not number!"); } catch (FileNotFoundException e) { @@ -372,7 +374,7 @@ public static void listCommand(ArrayList tasks, String[] stringSplit, int public static void greetUser() { System.out.println(" ____________________________________________________________"); System.out.println(" Hello! I'm duke.Duke"); - commandList(); + helpCommand(); System.out.println(" What can I do for you?"); System.out.println(" ____________________________________________________________"); } @@ -380,26 +382,28 @@ public static void greetUser() { /** * Print out all the possible command the user can execute. */ - public static void commandList() { + public static void helpCommand() { System.out.println(" Here is the list of commands that are available:"); System.out.println("+---------------------------------------------------------------+"); System.out.println("| Index | Input | Command |"); System.out.println("|-------+------------------+------------------------------------|"); - System.out.println("| 01 | list | List out all the stored task |"); + System.out.println("| 01 | todo j | Add a task(j) without dateline |"); System.out.println("|-------+------------------+------------------------------------|"); - System.out.println("| 02 | done i | Mark task i as done |"); + System.out.println("| 02 | dateline j /by d | Add a task(j) with due date d |"); System.out.println("|-------+------------------+------------------------------------|"); - System.out.println("| 03 | bye | Terminate the program |"); + System.out.println("| 03 | event j /at d | Add a task(j) that start at date d |"); System.out.println("|-------+------------------+------------------------------------|"); - System.out.println("| 04 | todo j | Add a task(j) without dateline |"); + System.out.println("| 04 | list | List out all the stored task |"); System.out.println("|-------+------------------+------------------------------------|"); - System.out.println("| 05 | dateline j /by d | Add a task(j) with due date d |"); + System.out.println("| 05 | done i | Mark task i as done |"); System.out.println("|-------+------------------+------------------------------------|"); - System.out.println("| 06 | event j /at d | Add a task(j) that start at date d |"); + System.out.println("| 06 | delete i | Delete task(i) |"); System.out.println("|-------+------------------+------------------------------------|"); - System.out.println("| 07 | delete j | Delete task(j) |"); + System.out.println("| 07 | find j | Find all task with description j |"); System.out.println("|-------+------------------+------------------------------------|"); - System.out.println("| 08 | find j | Find all task with description j |"); + System.out.println("| 08 | help | List out all the commands |"); + System.out.println("|-------+------------------+------------------------------------|"); + System.out.println("| 09 | bye | Terminate the program |"); System.out.println("|---------------------------------------------------------------|"); } } diff --git a/text-ui-test/ACTUAL.TXT b/text-ui-test/ACTUAL.TXT index f85bd5c41b..0bfe06ba38 100644 --- a/text-ui-test/ACTUAL.TXT +++ b/text-ui-test/ACTUAL.TXT @@ -4,21 +4,23 @@ +---------------------------------------------------------------+ | Index | Input | Command | |-------+------------------+------------------------------------| -| 01 | list | List out all the stored task | +| 01 | todo j | Add a task(j) without dateline | |-------+------------------+------------------------------------| -| 02 | done i | Mark task i as done | +| 02 | dateline j /by d | Add a task(j) with due date d | |-------+------------------+------------------------------------| -| 03 | bye | Terminate the program | +| 03 | event j /at d | Add a task(j) that start at date d | |-------+------------------+------------------------------------| -| 04 | todo j | Add a task(j) without dateline | +| 04 | list | List out all the stored task | |-------+------------------+------------------------------------| -| 05 | dateline j /by d | Add a task(j) with due date d | +| 05 | done i | Mark task i as done | |-------+------------------+------------------------------------| -| 06 | event j /at d | Add a task(j) that start at date d | +| 06 | delete i | Delete task(i) | |-------+------------------+------------------------------------| -| 07 | delete j | Delete task(j) | +| 07 | find j | Find all task with description j | |-------+------------------+------------------------------------| -| 08 | find j | Find all task with description j | +| 08 | help | List out all the commands | +|-------+------------------+------------------------------------| +| 09 | bye | Terminate the program | |---------------------------------------------------------------| What can I do for you? ____________________________________________________________ @@ -157,6 +159,33 @@ 2.[D][N] return book (by: Oct 6 2020, 19:30) ____________________________________________________________ + ____________________________________________________________ + Here is the list of commands that are available: ++---------------------------------------------------------------+ +| Index | Input | Command | +|-------+------------------+------------------------------------| +| 01 | todo j | Add a task(j) without dateline | +|-------+------------------+------------------------------------| +| 02 | dateline j /by d | Add a task(j) with due date d | +|-------+------------------+------------------------------------| +| 03 | event j /at d | Add a task(j) that start at date d | +|-------+------------------+------------------------------------| +| 04 | list | List out all the stored task | +|-------+------------------+------------------------------------| +| 05 | done i | Mark task i as done | +|-------+------------------+------------------------------------| +| 06 | delete i | Delete task(i) | +|-------+------------------+------------------------------------| +| 07 | find j | Find all task with description j | +|-------+------------------+------------------------------------| +| 08 | help | List out all the commands | +|-------+------------------+------------------------------------| +| 09 | bye | Terminate the program | +|---------------------------------------------------------------| + :( OOPS!!! Command does not exist. + To view the list of commands available use the command: help + ____________________________________________________________ + ____________________________________________________________ There is no matching tasks ____________________________________________________________ @@ -219,26 +248,7 @@ ____________________________________________________________ :( OOPS!!! Command does not exist. - Here is the list of commands that are available: -+---------------------------------------------------------------+ -| Index | Input | Command | -|-------+------------------+------------------------------------| -| 01 | list | List out all the stored task | -|-------+------------------+------------------------------------| -| 02 | done i | Mark task i as done | -|-------+------------------+------------------------------------| -| 03 | bye | Terminate the program | -|-------+------------------+------------------------------------| -| 04 | todo j | Add a task(j) without dateline | -|-------+------------------+------------------------------------| -| 05 | dateline j /by d | Add a task(j) with due date d | -|-------+------------------+------------------------------------| -| 06 | event j /at d | Add a task(j) that start at date d | -|-------+------------------+------------------------------------| -| 07 | delete j | Delete task(j) | -|-------+------------------+------------------------------------| -| 08 | find j | Find all task with description j | -|---------------------------------------------------------------| + To view the list of commands available use the command: help ____________________________________________________________ ____________________________________________________________ diff --git a/text-ui-test/EXPECTED.txt b/text-ui-test/EXPECTED.txt index f85bd5c41b..0bfe06ba38 100644 --- a/text-ui-test/EXPECTED.txt +++ b/text-ui-test/EXPECTED.txt @@ -4,21 +4,23 @@ +---------------------------------------------------------------+ | Index | Input | Command | |-------+------------------+------------------------------------| -| 01 | list | List out all the stored task | +| 01 | todo j | Add a task(j) without dateline | |-------+------------------+------------------------------------| -| 02 | done i | Mark task i as done | +| 02 | dateline j /by d | Add a task(j) with due date d | |-------+------------------+------------------------------------| -| 03 | bye | Terminate the program | +| 03 | event j /at d | Add a task(j) that start at date d | |-------+------------------+------------------------------------| -| 04 | todo j | Add a task(j) without dateline | +| 04 | list | List out all the stored task | |-------+------------------+------------------------------------| -| 05 | dateline j /by d | Add a task(j) with due date d | +| 05 | done i | Mark task i as done | |-------+------------------+------------------------------------| -| 06 | event j /at d | Add a task(j) that start at date d | +| 06 | delete i | Delete task(i) | |-------+------------------+------------------------------------| -| 07 | delete j | Delete task(j) | +| 07 | find j | Find all task with description j | |-------+------------------+------------------------------------| -| 08 | find j | Find all task with description j | +| 08 | help | List out all the commands | +|-------+------------------+------------------------------------| +| 09 | bye | Terminate the program | |---------------------------------------------------------------| What can I do for you? ____________________________________________________________ @@ -157,6 +159,33 @@ 2.[D][N] return book (by: Oct 6 2020, 19:30) ____________________________________________________________ + ____________________________________________________________ + Here is the list of commands that are available: ++---------------------------------------------------------------+ +| Index | Input | Command | +|-------+------------------+------------------------------------| +| 01 | todo j | Add a task(j) without dateline | +|-------+------------------+------------------------------------| +| 02 | dateline j /by d | Add a task(j) with due date d | +|-------+------------------+------------------------------------| +| 03 | event j /at d | Add a task(j) that start at date d | +|-------+------------------+------------------------------------| +| 04 | list | List out all the stored task | +|-------+------------------+------------------------------------| +| 05 | done i | Mark task i as done | +|-------+------------------+------------------------------------| +| 06 | delete i | Delete task(i) | +|-------+------------------+------------------------------------| +| 07 | find j | Find all task with description j | +|-------+------------------+------------------------------------| +| 08 | help | List out all the commands | +|-------+------------------+------------------------------------| +| 09 | bye | Terminate the program | +|---------------------------------------------------------------| + :( OOPS!!! Command does not exist. + To view the list of commands available use the command: help + ____________________________________________________________ + ____________________________________________________________ There is no matching tasks ____________________________________________________________ @@ -219,26 +248,7 @@ ____________________________________________________________ :( OOPS!!! Command does not exist. - Here is the list of commands that are available: -+---------------------------------------------------------------+ -| Index | Input | Command | -|-------+------------------+------------------------------------| -| 01 | list | List out all the stored task | -|-------+------------------+------------------------------------| -| 02 | done i | Mark task i as done | -|-------+------------------+------------------------------------| -| 03 | bye | Terminate the program | -|-------+------------------+------------------------------------| -| 04 | todo j | Add a task(j) without dateline | -|-------+------------------+------------------------------------| -| 05 | dateline j /by d | Add a task(j) with due date d | -|-------+------------------+------------------------------------| -| 06 | event j /at d | Add a task(j) that start at date d | -|-------+------------------+------------------------------------| -| 07 | delete j | Delete task(j) | -|-------+------------------+------------------------------------| -| 08 | find j | Find all task with description j | -|---------------------------------------------------------------| + To view the list of commands available use the command: help ____________________________________________________________ ____________________________________________________________ diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index bb12e6abf3..cc42d4d21c 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -19,6 +19,7 @@ done 4 list delete 6 find book +help find everything find delete From 2e376854ac901ac33d01dac081c714e2adbfe4c5 Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Mon, 2 Mar 2020 23:55:51 +0800 Subject: [PATCH 34/45] Add Storage and Ui class --- src/main/java/duke/Duke.java | 84 +++------------------------------ src/main/java/duke/Storage.java | 52 ++++++++++++++++++++ src/main/java/duke/Ui.java | 46 ++++++++++++++++++ 3 files changed, 104 insertions(+), 78 deletions(-) create mode 100644 src/main/java/duke/Storage.java create mode 100644 src/main/java/duke/Ui.java diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index c0fe658720..a71ca9d38d 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -33,11 +33,13 @@ public class Duke { * @param args String[] args in main. */ public static void main(String[] args) { - ArrayList tasks = new ArrayList<>(); - int taskCount = getFileTask(FILE_PATH, tasks, 0); + Ui ui = new Ui(); + Storage storage = new Storage(FILE_PATH); + ArrayList tasks = storage.load(); + int taskCount = tasks.size(); boolean isBye = false; Scanner sc = new Scanner(System.in); - greetUser(); + ui.greetUser(); while (!isBye) { System.out.println(); String string = sc.nextLine(); @@ -70,7 +72,7 @@ public static void main(String[] args) { findCommand(tasks, taskCount, string); break; case "help": - helpCommand(); + ui.helpCommand(); default: throw new DukeNullException(" :( OOPS!!! Command does not exist."); } @@ -134,40 +136,6 @@ public static void writeFileTask(String filePath, String taskToAdd) throws IOExc fileWriter.close(); } - /** - * Open file from file directory if any and convert the string into the respective Task at the - * start of the programs launch. - * @param filePath File directory path. - * @param tasks ArrayList containing all the Task. - * @param taskCount Total number of Task stored. - * @return Total number of Task stored or 0 if the file does not exists. - */ - public static int getFileTask(String filePath, ArrayList tasks, int taskCount) { - try { - File file = new File(filePath); // create a File for the given file path - Scanner fileScanner = new Scanner(file); // create a Scanner using the File as the source - while (fileScanner.hasNext()) { - String[] existingTask = fileScanner.nextLine().split(" \\| "); - if (existingTask[0].equals("T")) { - tasks.add(new Todo(existingTask[2])); - } - if (existingTask[0].equals("D")) { - tasks.add(new Deadline(existingTask[2], existingTask[3])); - } - if (existingTask[0].equals("E")) { - tasks.add(new Event(existingTask[2], existingTask[3])); - } - if (existingTask[1].equals("1")) { - tasks.get(taskCount).markAsDone(); - } - taskCount++; - } - return taskCount; - } catch (FileNotFoundException e) { - return taskCount; - } - } - /** * Delete a Task given an index. * @param tasks ArrayList containing all the Task. @@ -366,44 +334,4 @@ public static void listCommand(ArrayList tasks, String[] stringSplit, int } } } - - /** - * Print the Welcome message and call commandList method to List out all the possible command - * the user can execute. - */ - public static void greetUser() { - System.out.println(" ____________________________________________________________"); - System.out.println(" Hello! I'm duke.Duke"); - helpCommand(); - System.out.println(" What can I do for you?"); - System.out.println(" ____________________________________________________________"); - } - - /** - * Print out all the possible command the user can execute. - */ - public static void helpCommand() { - System.out.println(" Here is the list of commands that are available:"); - System.out.println("+---------------------------------------------------------------+"); - System.out.println("| Index | Input | Command |"); - System.out.println("|-------+------------------+------------------------------------|"); - System.out.println("| 01 | todo j | Add a task(j) without dateline |"); - System.out.println("|-------+------------------+------------------------------------|"); - System.out.println("| 02 | dateline j /by d | Add a task(j) with due date d |"); - System.out.println("|-------+------------------+------------------------------------|"); - System.out.println("| 03 | event j /at d | Add a task(j) that start at date d |"); - System.out.println("|-------+------------------+------------------------------------|"); - System.out.println("| 04 | list | List out all the stored task |"); - System.out.println("|-------+------------------+------------------------------------|"); - System.out.println("| 05 | done i | Mark task i as done |"); - System.out.println("|-------+------------------+------------------------------------|"); - System.out.println("| 06 | delete i | Delete task(i) |"); - System.out.println("|-------+------------------+------------------------------------|"); - System.out.println("| 07 | find j | Find all task with description j |"); - System.out.println("|-------+------------------+------------------------------------|"); - System.out.println("| 08 | help | List out all the commands |"); - System.out.println("|-------+------------------+------------------------------------|"); - System.out.println("| 09 | bye | Terminate the program |"); - System.out.println("|---------------------------------------------------------------|"); - } } diff --git a/src/main/java/duke/Storage.java b/src/main/java/duke/Storage.java new file mode 100644 index 0000000000..ebecba5d7e --- /dev/null +++ b/src/main/java/duke/Storage.java @@ -0,0 +1,52 @@ +package duke; + +import duke.task.Deadline; +import duke.task.Event; +import duke.task.Task; +import duke.task.Todo; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.Scanner; + +public class Storage { + private String filePath; + + public Storage(String filePath) { + this.filePath = filePath; + } + + /** + * Open file from file directory if any and convert the string into the respective Task at the + * start of the programs launch. + * @return ArrayList of Task stored in the file if it exist. + */ + public ArrayList load() { + ArrayList taskArray = new ArrayList<>(); + int taskCount = 0; + try { + File file = new File(filePath); // create a File for the given file path + Scanner fileScanner = new Scanner(file); // create a Scanner using the File as the source + while (fileScanner.hasNext()) { + String[] existingTask = fileScanner.nextLine().split(" \\| "); + if (existingTask[0].equals("T")) { + taskArray.add(new Todo(existingTask[2])); + } + if (existingTask[0].equals("D")) { + taskArray.add(new Deadline(existingTask[2], existingTask[3])); + } + if (existingTask[0].equals("E")) { + taskArray.add(new Event(existingTask[2], existingTask[3])); + } + if (existingTask[1].equals("1")) { + taskArray.get(taskCount).markAsDone(); + } + taskCount++; + } + return taskArray; + } catch (FileNotFoundException e) { + return taskArray; + } + } +} diff --git a/src/main/java/duke/Ui.java b/src/main/java/duke/Ui.java new file mode 100644 index 0000000000..4bc2b049bc --- /dev/null +++ b/src/main/java/duke/Ui.java @@ -0,0 +1,46 @@ +package duke; + +public class Ui { + public Ui() { + } + + /** + * Print the Welcome message and call commandList method to List out all the possible command + * the user can execute. + */ + public void greetUser() { + System.out.println(" ____________________________________________________________"); + System.out.println(" Hello! I'm duke.Duke"); + helpCommand(); + System.out.println(" What can I do for you?"); + System.out.println(" ____________________________________________________________"); + } + + /** + * Print out all the possible command the user can execute. + */ + public void helpCommand() { + System.out.println(" Here is the list of commands that are available:"); + System.out.println("+---------------------------------------------------------------+"); + System.out.println("| Index | Input | Command |"); + System.out.println("|-------+------------------+------------------------------------|"); + System.out.println("| 01 | todo j | Add a task(j) without dateline |"); + System.out.println("|-------+------------------+------------------------------------|"); + System.out.println("| 02 | dateline j /by d | Add a task(j) with due date d |"); + System.out.println("|-------+------------------+------------------------------------|"); + System.out.println("| 03 | event j /at d | Add a task(j) that start at date d |"); + System.out.println("|-------+------------------+------------------------------------|"); + System.out.println("| 04 | list | List out all the stored task |"); + System.out.println("|-------+------------------+------------------------------------|"); + System.out.println("| 05 | done i | Mark task i as done |"); + System.out.println("|-------+------------------+------------------------------------|"); + System.out.println("| 06 | delete i | Delete task(i) |"); + System.out.println("|-------+------------------+------------------------------------|"); + System.out.println("| 07 | find j | Find all task with description j |"); + System.out.println("|-------+------------------+------------------------------------|"); + System.out.println("| 08 | help | List out all the commands |"); + System.out.println("|-------+------------------+------------------------------------|"); + System.out.println("| 09 | bye | Terminate the program |"); + System.out.println("|---------------------------------------------------------------|"); + } +} From 03d714ab8907b03cdd1d9fd27b1bff43897d616d Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Tue, 3 Mar 2020 14:55:14 +0800 Subject: [PATCH 35/45] Add emphasize on keywords in README --- docs/README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/README.md b/docs/README.md index 764bfd48a5..dee3a9b13a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -11,44 +11,44 @@ Some of the task that Duke can manage are *Todo*, *Deadline* and *Event*. ## Features Below are the list of command that you can key in to interact with Duke. 1. Add Task - 1. Input: todo j + 1. Input: `todo` j Example: todo CS2113 Homework Command: Add a *Todo* Task with String description j. - 1. Input: deadline j /by d + 1. Input: `deadline` j /by d Example: deadline CS2113 Homework /by 2020-04-15 16:00 - Command: Add a *Deadline* Task with String description j, followed by "/by", then the corresponding due date in YYYY-MM-DD format and the time in HH:MM format.\ + Command: Add a *Deadline* Task with String description j, followed by "/by", then the corresponding due date in YYYY-MM-DD format and the time in HH:MM format. - 1. Input: event j /at d + 1. Input: `event` j /at d Example: deadline CS2113 Homework /at 2020-04-15 16:00 Command: Add a *Event* Task with String description j, followed by "/at", then the corresponding date in YYYY-MM-DD format and the time in HH:MM format. 1. List Task -Input: list +Input: `list` Example: list Command: List out all the stored task. 1. Complete Task -Input: done i +Input: `done` i Example: done 3 Command: Mark Task i as done, where i is the corresponding Task number. 1. Delete Task -Input: delete i +Input: `delete` i Example: delete 3 Command: Delete Task i, where i is the corresponding Task number. 1. Find Task -Input: find j +Input: `find` j Example: find Homework Command: Find all the task with description that contains the word/phrase j. 1. Help -Input: help +Input: `help` Command: List out all the commands 1. Exit -Input: bye +Input: `bye` Command: Terminate the program and automatically help you store the Task into your hard disk with directory ../data/Duke.txt **Note:** Duke will help you take care of creating a folder and txt file if one does not already exist. From fc66763ee076cf378555c54ad34098dc1495497f Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Sat, 14 Mar 2020 02:14:49 +0800 Subject: [PATCH 36/45] Add Parser and TaskList --- src/main/java/duke/Duke.java | 19 ++++++++----------- src/main/java/duke/Parser.java | 11 +++++++++++ src/main/java/duke/Storage.java | 14 +++++++------- src/main/java/duke/TaskList.java | 14 ++++++++++++++ src/main/java/duke/Ui.java | 26 +++++++++++++++++++++++++- 5 files changed, 65 insertions(+), 19 deletions(-) create mode 100644 src/main/java/duke/Parser.java create mode 100644 src/main/java/duke/TaskList.java diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index a71ca9d38d..b60a860843 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -8,10 +8,9 @@ import duke.task.Task; import duke.task.Todo; -import java.util.Scanner; +import java.time.format.DateTimeParseException; import java.util.Arrays; import java.util.ArrayList; -import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; @@ -34,16 +33,14 @@ public class Duke { */ public static void main(String[] args) { Ui ui = new Ui(); + TaskList taskList; Storage storage = new Storage(FILE_PATH); ArrayList tasks = storage.load(); int taskCount = tasks.size(); boolean isBye = false; - Scanner sc = new Scanner(System.in); ui.greetUser(); while (!isBye) { - System.out.println(); - String string = sc.nextLine(); - System.out.println(" ____________________________________________________________"); + String string = ui.getUserCommand(); String[] stringSplit = string.split(" "); try { switch (stringSplit[0]) { @@ -69,7 +66,7 @@ public static void main(String[] args) { taskCount = deleteCommand(tasks, stringSplit, taskCount); break; case "find": - findCommand(tasks, taskCount, string); + findCommand(tasks, string); break; case "help": ui.helpCommand(); @@ -87,6 +84,8 @@ public static void main(String[] args) { System.out.println("Folder does not exist yet" + e.getMessage()); } catch (IOException e) { System.out.println("Something went wrong: " + e.getMessage()); + } catch (DateTimeParseException e) { + System.out.println(" :( OOPS!!! Please enter a valid date and time"); } finally { System.out.println(" ____________________________________________________________"); } @@ -96,20 +95,18 @@ public static void main(String[] args) { /** * Find all Task with description that matches a key word or phrase. * @param tasks ArrayList containing all the Task. - * @param taskCount Total number of Task stored. * @param string User input. * @throws DukeArgumentException If missing parameter for description. */ - public static void findCommand(ArrayList tasks, int taskCount, String string) throws + public static void findCommand(ArrayList tasks, String string) throws DukeArgumentException { - int deletedTask; if (string.length() == 4) { throw new DukeArgumentException(" :( OOPS!!! Missing description for find."); } String description = string.substring(5); boolean containDescription = false; int matchNumber = 1; - for (int i = 0; i < taskCount; i++) { + for (int i = 0; i < tasks.size(); i++) { if (tasks.get(i).getDescription().contains(description)) { if (!containDescription) { System.out.println(" Here are the matching tasks in your list:"); diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java new file mode 100644 index 0000000000..4f4a05fe59 --- /dev/null +++ b/src/main/java/duke/Parser.java @@ -0,0 +1,11 @@ +package duke; + +public class Parser { + public Parser() { + } + + // To be edited to return Command object instead subsequently + public String parseCommand(String string) { + return "command"; + } +} diff --git a/src/main/java/duke/Storage.java b/src/main/java/duke/Storage.java index ebecba5d7e..e97ac9b095 100644 --- a/src/main/java/duke/Storage.java +++ b/src/main/java/duke/Storage.java @@ -23,7 +23,7 @@ public Storage(String filePath) { * @return ArrayList of Task stored in the file if it exist. */ public ArrayList load() { - ArrayList taskArray = new ArrayList<>(); + ArrayList tasksStored = new ArrayList<>(); int taskCount = 0; try { File file = new File(filePath); // create a File for the given file path @@ -31,22 +31,22 @@ public ArrayList load() { while (fileScanner.hasNext()) { String[] existingTask = fileScanner.nextLine().split(" \\| "); if (existingTask[0].equals("T")) { - taskArray.add(new Todo(existingTask[2])); + tasksStored.add(new Todo(existingTask[2])); } if (existingTask[0].equals("D")) { - taskArray.add(new Deadline(existingTask[2], existingTask[3])); + tasksStored.add(new Deadline(existingTask[2], existingTask[3])); } if (existingTask[0].equals("E")) { - taskArray.add(new Event(existingTask[2], existingTask[3])); + tasksStored.add(new Event(existingTask[2], existingTask[3])); } if (existingTask[1].equals("1")) { - taskArray.get(taskCount).markAsDone(); + tasksStored.get(taskCount).markAsDone(); } taskCount++; } - return taskArray; + return tasksStored; } catch (FileNotFoundException e) { - return taskArray; + return tasksStored; } } } diff --git a/src/main/java/duke/TaskList.java b/src/main/java/duke/TaskList.java new file mode 100644 index 0000000000..de391e95c5 --- /dev/null +++ b/src/main/java/duke/TaskList.java @@ -0,0 +1,14 @@ +package duke; + +import duke.task.Task; + +import java.util.ArrayList; + +public class TaskList { + private ArrayList tasksStored; + + public TaskList(ArrayList tasksStored) { + this.tasksStored = tasksStored; + } + +} diff --git a/src/main/java/duke/Ui.java b/src/main/java/duke/Ui.java index 4bc2b049bc..2d8b331963 100644 --- a/src/main/java/duke/Ui.java +++ b/src/main/java/duke/Ui.java @@ -1,9 +1,33 @@ package duke; +import java.util.Scanner; + +/** + * The Deadline class is an Object that deals with interaction with the user. + * @author Lam Yue Wei + * @version CS2113 AY19/20 Sem 2 Duke + */ public class Ui { + private Scanner sc = new Scanner(System.in); + + /** + * Empty constructor for Ui object. + */ public Ui() { } + /** + * Scan the user input into a String and return it. + * @return User input. + */ + public String getUserCommand() { + String userCommand; + System.out.println(); + userCommand = sc.nextLine(); + System.out.println(" ____________________________________________________________"); + return userCommand; + } + /** * Print the Welcome message and call commandList method to List out all the possible command * the user can execute. @@ -26,7 +50,7 @@ public void helpCommand() { System.out.println("|-------+------------------+------------------------------------|"); System.out.println("| 01 | todo j | Add a task(j) without dateline |"); System.out.println("|-------+------------------+------------------------------------|"); - System.out.println("| 02 | dateline j /by d | Add a task(j) with due date d |"); + System.out.println("| 02 | deadline j /by d | Add a task(j) with due date d |"); System.out.println("|-------+------------------+------------------------------------|"); System.out.println("| 03 | event j /at d | Add a task(j) that start at date d |"); System.out.println("|-------+------------------+------------------------------------|"); From f2cfdda06c370d151b5bd2a5c892cbdd1a0e1ae5 Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Sun, 15 Mar 2020 03:26:16 +0800 Subject: [PATCH 37/45] Add Command, HelpCommand, ListCommand --- data/duke.txt | 8 +-- src/main/java/duke/Command.java | 16 +++++ src/main/java/duke/Duke.java | 77 +++++++++++------------- src/main/java/duke/HelpCommand.java | 27 +++++++++ src/main/java/duke/Storage.java | 24 +++++--- src/main/java/duke/TaskList.java | 59 +++++++++++++++++- src/main/java/duke/Ui.java | 8 +-- src/main/java/duke/task/ListCommand.java | 39 ++++++++++++ text-ui-test/ACTUAL.TXT | 6 +- text-ui-test/EXPECTED.txt | 6 +- 10 files changed, 203 insertions(+), 67 deletions(-) create mode 100644 src/main/java/duke/Command.java create mode 100644 src/main/java/duke/HelpCommand.java create mode 100644 src/main/java/duke/task/ListCommand.java diff --git a/data/duke.txt b/data/duke.txt index f873bacba5..e088f286cc 100644 --- a/data/duke.txt +++ b/data/duke.txt @@ -1,6 +1,6 @@ T | 0 | read book -D | 0 | return book | 2020-10-06 19:30 -E | 1 | project meeting | 2021-05-29 03:20 +D | 0 | return book | Oct 6 2020 +E | 1 | project meeting | May 29 2021 T | 0 | join sports club -E | 0 | exams | 2020-05-03 16:00 -D | 1 | do homework | 2020-04-25 11:45 +E | 0 | exams | May 3 2020 +D | 1 | do homework | Apr 25 2020 diff --git a/src/main/java/duke/Command.java b/src/main/java/duke/Command.java new file mode 100644 index 0000000000..f6101fb0be --- /dev/null +++ b/src/main/java/duke/Command.java @@ -0,0 +1,16 @@ +package duke; + +/** + * The Command Interface is an Interface that provides the platform for various Command to be executed. + * @author Lam Yue Wei + * @version CS2113 AY19/20 Sem 2 Duke + */ +public interface Command { + /** + * Abstract method that other Command Object has to override to executes their respective command function. + * @param taskList Task Manager in charge of storing the Task required to be done. + * @param ui Ui Object that deals with interaction with the user. + * @param storage Storage Object that deals with the loading and Storing of Tasks. + */ + public abstract void execute(TaskList taskList, Ui ui, Storage storage); +} diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index b60a860843..a6de7a9009 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -3,10 +3,7 @@ import duke.exception.DukeArgumentException; import duke.exception.DukeIndexException; import duke.exception.DukeNullException; -import duke.task.Deadline; -import duke.task.Event; -import duke.task.Task; -import duke.task.Todo; +import duke.task.*; import java.time.format.DateTimeParseException; import java.util.Arrays; @@ -33,10 +30,10 @@ public class Duke { */ public static void main(String[] args) { Ui ui = new Ui(); - TaskList taskList; + Command command; Storage storage = new Storage(FILE_PATH); ArrayList tasks = storage.load(); - int taskCount = tasks.size(); + TaskList taskList = new TaskList(tasks); //Use this to replace tasks boolean isBye = false; ui.greetUser(); while (!isBye) { @@ -45,31 +42,40 @@ public static void main(String[] args) { try { switch (stringSplit[0]) { case "list": - listCommand(tasks, stringSplit, taskCount); + listCommand(tasks, stringSplit); + command = new ListCommand(); + command.execute(taskList, ui,storage); break; case "done": - doneCommand(tasks, stringSplit, taskCount); + doneCommand(tasks, stringSplit); + taskList.doneTask(Integer.parseInt(stringSplit[1]) - 1); break; case "bye": - isBye = byeCommand(stringSplit, taskCount, tasks); + isBye = byeCommand(stringSplit, tasks); break; case "todo": - taskCount = todoCommand(tasks, stringSplit, taskCount); + todoCommand(tasks, stringSplit); + taskList.addTask(new Todo(String.join(" ", Arrays.copyOfRange(stringSplit, 1, stringSplit.length)))); break; case "deadline": - taskCount = deadlineCommand(tasks, taskCount, string); + deadlineCommand(tasks, string); + taskList.addTask(new Deadline(string.substring(0, string.indexOf(" /by")).replace("deadline ", ""), string.substring(string.indexOf("/by ")).replace("/by ", ""))); break; case "event": - taskCount = eventCommand(tasks, taskCount, string); + eventCommand(tasks, string); + taskList.addTask(new Event(string.substring(0, string.indexOf(" /at")).replace("event ", ""), string.substring(string.indexOf("/at ")).replace("/at ", ""))); break; case "delete": - taskCount = deleteCommand(tasks, stringSplit, taskCount); + deleteCommand(tasks, stringSplit); + taskList.deleteTask(Integer.parseInt(stringSplit[1]) - 1); break; case "find": findCommand(tasks, string); break; case "help": - ui.helpCommand(); + command = new HelpCommand(); + command.execute(taskList, ui, storage); + break; default: throw new DukeNullException(" :( OOPS!!! Command does not exist."); } @@ -137,14 +143,13 @@ public static void writeFileTask(String filePath, String taskToAdd) throws IOExc * Delete a Task given an index. * @param tasks ArrayList containing all the Task. * @param stringSplit User input that is split by spacing. - * @param taskCount Total number of Task stored. - * @return Total number of Task stored. * @throws DukeArgumentException If missing parameter for index. * @throws DukeIndexException If index provided is out of range. */ - public static int deleteCommand(ArrayList tasks, String[] stringSplit, int taskCount) throws + public static void deleteCommand(ArrayList tasks, String[] stringSplit) throws DukeArgumentException, DukeIndexException { int deletedTask; + int taskCount = tasks.size(); if (stringSplit.length == 1) { throw new DukeArgumentException(" :( OOPS!!! Missing index for delete."); } @@ -157,18 +162,15 @@ public static int deleteCommand(ArrayList tasks, String[] stringSplit, int tasks.remove(deletedTask); taskCount--; System.out.println(" Now you have " + taskCount + " tasks in the list."); - return taskCount; } /** * Add event Task given a description and a time of occurrence. * @param tasks ArrayList containing all the Task. - * @param taskCount Total number of Task stored. * @param string User input. - * @return Total number of Task stored. * @throws DukeArgumentException If missing parameter for description or date. */ - public static int eventCommand(ArrayList tasks, int taskCount, String string) throws + public static void eventCommand(ArrayList tasks, String string) throws DukeArgumentException { if (string.length() == 5) { throw new DukeArgumentException(" :( OOPS!!! Missing description for event."); @@ -179,6 +181,7 @@ public static int eventCommand(ArrayList tasks, int taskCount, String stri String description; String dateTime; + int taskCount = tasks.size(); description = string.substring(0, string.indexOf(" /at")).replace("event ", ""); dateTime = string.substring(string.indexOf("/at ")).replace("/at ", ""); tasks.add(new Event(description, dateTime)); @@ -186,18 +189,15 @@ public static int eventCommand(ArrayList tasks, int taskCount, String stri System.out.println(" " + tasks.get(taskCount).toString()); taskCount++; System.out.println(" Now you have " + taskCount + " tasks in the list."); - return taskCount; } /** * Add deadline Task given a description and a due date. * @param tasks ArrayList containing all the Task. - * @param taskCount Total number of Task stored. * @param string User input. - * @return Total number of Task stored. * @throws DukeArgumentException If missing parameter for description or date. */ - public static int deadlineCommand(ArrayList tasks, int taskCount, String string) throws + public static void deadlineCommand(ArrayList tasks, String string) throws DukeArgumentException { if (string.length() == 8) { throw new DukeArgumentException(" :( OOPS!!! Missing description for deadline."); @@ -208,6 +208,7 @@ public static int deadlineCommand(ArrayList tasks, int taskCount, String s String description; String dateTime; + int taskCount = tasks.size(); description = string.substring(0, string.indexOf(" /by")).replace("deadline ", ""); dateTime = string.substring(string.indexOf("/by ")).replace("/by ", ""); @@ -216,43 +217,39 @@ public static int deadlineCommand(ArrayList tasks, int taskCount, String s System.out.println(" " + tasks.get(taskCount).toString()); taskCount++; System.out.println(" Now you have " + taskCount + " tasks in the list."); - return taskCount; } /** * Add todo Task given a description. * @param tasks ArrayList containing all the Task. * @param stringSplit User input that is split by spacing. - * @param taskCount Total number of Task stored. - * @return Total number of Task stored. * @throws DukeArgumentException If missing parameter for index. */ - public static int todoCommand(ArrayList tasks, String[] stringSplit, int taskCount) throws + public static void todoCommand(ArrayList tasks, String[] stringSplit) throws DukeArgumentException { if (stringSplit.length == 1) { throw new DukeArgumentException(" :( OOPS!!! Missing description for todo."); } String description; + int taskCount = tasks.size(); description = String.join(" ", Arrays.copyOfRange(stringSplit, 1, stringSplit.length)); tasks.add(new Todo(description)); System.out.println(" Got it. I've added this task:"); System.out.println(" " + tasks.get(taskCount).toString()); taskCount++; System.out.println(" Now you have " + taskCount + " tasks in the list."); - return taskCount; } /** * Store all the Task into the hard disk and exit the program. * @param stringSplit User input that is split by spacing. - * @param taskCount Total number of Task stored. * @param tasks ArrayList containing all the Task. * @return true to indicate to the program to end. * @throws DukeArgumentException If additional parameter is provided. * @throws IOException If input or output operation failed. */ - public static boolean byeCommand(String[] stringSplit, int taskCount, ArrayList tasks) throws + public static boolean byeCommand(String[] stringSplit, ArrayList tasks) throws DukeArgumentException, IOException { if (stringSplit.length > 1) { throw new DukeArgumentException(" :( OOPS!!! Description not required for bye."); @@ -262,7 +259,7 @@ public static boolean byeCommand(String[] stringSplit, int taskCount, ArrayList< Files.createDirectory(path); } String taskToAdd = ""; - for (int i = 0; i < taskCount; i++) { + for (int i = 0; i < tasks.size(); i++) { if ( tasks.get(i) instanceof Todo) { Todo todo = (Todo) tasks.get(i); taskToAdd = taskToAdd + "T | " + (todo.getIsDone() ? 1 : 0) + " | "; @@ -289,11 +286,10 @@ public static boolean byeCommand(String[] stringSplit, int taskCount, ArrayList< * Mark a Task as done. * @param tasks ArrayList containing all the Task. * @param stringSplit User input that is split by spacing. - * @param taskCount Total number of Task stored. * @throws DukeArgumentException If missing parameter for index. * @throws DukeIndexException If index provided is out of range. */ - public static void doneCommand(ArrayList tasks, String[] stringSplit, int taskCount) throws + public static void doneCommand(ArrayList tasks, String[] stringSplit) throws DukeArgumentException, DukeIndexException { int completedTask; if (stringSplit.length == 1) { @@ -301,7 +297,7 @@ public static void doneCommand(ArrayList tasks, String[] stringSplit, int } completedTask = Integer.parseInt(stringSplit[1]) - 1; // Might throw NumberFormatException - if (completedTask >= taskCount || completedTask < 0) { + if (completedTask >= tasks.size() || completedTask < 0) { throw new DukeIndexException(" :( OOPS!!! Invalid index for done."); } tasks.get(completedTask).markAsDone(); @@ -313,22 +309,21 @@ public static void doneCommand(ArrayList tasks, String[] stringSplit, int * List all the Task stored. * @param tasks ArrayList containing all the Task. * @param stringSplit User input that is split by spacing. - * @param taskCount Total number of Task stored. * @throws DukeArgumentException If additional parameter is provided. */ - public static void listCommand(ArrayList tasks, String[] stringSplit, int taskCount) throws + public static void listCommand(ArrayList tasks, String[] stringSplit) throws DukeArgumentException { if (stringSplit.length > 1) { throw new DukeArgumentException(" :( OOPS!!! Description not required for list."); } - if (taskCount == 0) { + /*if (tasks.size() == 0) { System.out.println(" There are currently no tasks in your list"); } else { System.out.println(" Here are the tasks in your list:"); - for (int i = 0; i < taskCount; i++) { + for (int i = 0; i < tasks.size(); i++) { System.out.println(" " + (i + 1) + "." + tasks.get(i).toString()); } - } + }*/ } } diff --git a/src/main/java/duke/HelpCommand.java b/src/main/java/duke/HelpCommand.java new file mode 100644 index 0000000000..46cebbe26e --- /dev/null +++ b/src/main/java/duke/HelpCommand.java @@ -0,0 +1,27 @@ +package duke; + +/** + * The HelpCommand class is the Object that provides the user with help by showing the list of available commands. + * HelpCommand implement Command interface. + * @author Lam Yue Wei + * @version CS2113 AY19/20 Sem 2 Duke + */ +public class HelpCommand implements Command { + + /** + * Empty constructor for the HelpCommand. + */ + public HelpCommand() { + } + + /** + * Executes the help function and shows the user the available commands. + * @param taskList Task Manager in charge of storing the Task required to be done. + * @param ui Ui Object that deals with interaction with the user. + * @param storage Storage Object that deals with the loading and Storing of Tasks. + */ + @Override + public void execute(TaskList taskList, Ui ui, Storage storage) { + ui.printAvailableCommand(); + } +} diff --git a/src/main/java/duke/Storage.java b/src/main/java/duke/Storage.java index e97ac9b095..ee5933f0e3 100644 --- a/src/main/java/duke/Storage.java +++ b/src/main/java/duke/Storage.java @@ -10,9 +10,19 @@ import java.util.ArrayList; import java.util.Scanner; +/** + * The Storage class is the class handles the loading of Task from a specified filePath and + * storing of Task into the filePath. + * @author Lam Yue Wei + * @version CS2113 AY19/20 Sem 2 Duke + */ public class Storage { private String filePath; + /** + * Public constructor for Storage. + * @param filePath File path where the Tasks will be loaded from or stored into. + */ public Storage(String filePath) { this.filePath = filePath; } @@ -23,7 +33,7 @@ public Storage(String filePath) { * @return ArrayList of Task stored in the file if it exist. */ public ArrayList load() { - ArrayList tasksStored = new ArrayList<>(); + ArrayList tasks = new ArrayList<>(); int taskCount = 0; try { File file = new File(filePath); // create a File for the given file path @@ -31,22 +41,22 @@ public ArrayList load() { while (fileScanner.hasNext()) { String[] existingTask = fileScanner.nextLine().split(" \\| "); if (existingTask[0].equals("T")) { - tasksStored.add(new Todo(existingTask[2])); + tasks.add(new Todo(existingTask[2])); } if (existingTask[0].equals("D")) { - tasksStored.add(new Deadline(existingTask[2], existingTask[3])); + tasks.add(new Deadline(existingTask[2], existingTask[3])); } if (existingTask[0].equals("E")) { - tasksStored.add(new Event(existingTask[2], existingTask[3])); + tasks.add(new Event(existingTask[2], existingTask[3])); } if (existingTask[1].equals("1")) { - tasksStored.get(taskCount).markAsDone(); + tasks.get(taskCount).markAsDone(); } taskCount++; } - return tasksStored; + return tasks; } catch (FileNotFoundException e) { - return tasksStored; + return tasks; } } } diff --git a/src/main/java/duke/TaskList.java b/src/main/java/duke/TaskList.java index de391e95c5..c3227bb4bd 100644 --- a/src/main/java/duke/TaskList.java +++ b/src/main/java/duke/TaskList.java @@ -4,11 +4,64 @@ import java.util.ArrayList; +/** + * The TaskList class is the class involved in getting and setting Task Object into an ArrayList. + * @author Lam Yue Wei + * @version CS2113 AY19/20 Sem 2 Duke + */ public class TaskList { - private ArrayList tasksStored; + private ArrayList tasks; - public TaskList(ArrayList tasksStored) { - this.tasksStored = tasksStored; + /** + * Public constructor for TaskList. + * @param tasks ArrayList of Tasks to be stored. + */ + public TaskList(ArrayList tasks) { + this.tasks = new ArrayList<>(); + for (int i = 0; i < tasks.size(); i++) { + this.tasks.add(tasks.get(i)); + } + //this.tasks = tasks; } + /** + * Takes in a Task Object and add it into the stored task list. + * @param task The Task Object to be stored. + */ + public void addTask(Task task) { + tasks.add(task); + } + + /** + * Return the Task Object stored at a specific task index. + * @param taskIndex The index of the Task Object in the ArrayList. + * @return Task Object stored at the index provided. + */ + public Task getTask(int taskIndex) { + return tasks.get(taskIndex); + } + + /** + * Provides the count of task stored. + * @return Total number of task stored. + */ + public int getTaskCount() { + return tasks.size(); + } + + /** + * Delete the Task stored at a specific index. + * @param deleteIndex The index of the task to be deleted. + */ + public void deleteTask(int deleteIndex) { + tasks.remove(deleteIndex); + } + + /** + * Mark a Task as completed. + * @param doneIndex The index of the task that is done. + */ + public void doneTask(int doneIndex) { + tasks.get(doneIndex).markAsDone(); + } } diff --git a/src/main/java/duke/Ui.java b/src/main/java/duke/Ui.java index 2d8b331963..2cbb44cbd6 100644 --- a/src/main/java/duke/Ui.java +++ b/src/main/java/duke/Ui.java @@ -3,7 +3,7 @@ import java.util.Scanner; /** - * The Deadline class is an Object that deals with interaction with the user. + * The Ui class is an Object that deals with interaction with the user. * @author Lam Yue Wei * @version CS2113 AY19/20 Sem 2 Duke */ @@ -11,7 +11,7 @@ public class Ui { private Scanner sc = new Scanner(System.in); /** - * Empty constructor for Ui object. + * Empty constructor for Ui. */ public Ui() { } @@ -35,7 +35,7 @@ public String getUserCommand() { public void greetUser() { System.out.println(" ____________________________________________________________"); System.out.println(" Hello! I'm duke.Duke"); - helpCommand(); + printAvailableCommand(); System.out.println(" What can I do for you?"); System.out.println(" ____________________________________________________________"); } @@ -43,7 +43,7 @@ public void greetUser() { /** * Print out all the possible command the user can execute. */ - public void helpCommand() { + public void printAvailableCommand() { System.out.println(" Here is the list of commands that are available:"); System.out.println("+---------------------------------------------------------------+"); System.out.println("| Index | Input | Command |"); diff --git a/src/main/java/duke/task/ListCommand.java b/src/main/java/duke/task/ListCommand.java new file mode 100644 index 0000000000..72aa61546b --- /dev/null +++ b/src/main/java/duke/task/ListCommand.java @@ -0,0 +1,39 @@ +package duke.task; + +import duke.Command; +import duke.Storage; +import duke.TaskList; +import duke.Ui; + +/** + * The ListCommand class is the Object that provides the user with the list of Tasks stored. + * ListCommand implement Command interface. + * @author Lam Yue Wei + * @version CS2113 AY19/20 Sem 2 Duke + */ +public class ListCommand implements Command { + + /** + * Empty constructor for ListCommand. + */ + public ListCommand() { + } + + /** + * Executes the list function and shows the user the list of Tasks stored. + * @param taskList Task Manager in charge of storing the Task required to be done. + * @param ui Ui Object that deals with interaction with the user. + * @param storage Storage Object that deals with the loading and Storing of Tasks. + */ + @Override + public void execute(TaskList taskList, Ui ui, Storage storage) { + if (taskList.getTaskCount() == 0) { + System.out.println(" There are currently no tasks in your list"); + } else { + System.out.println(" Here are the tasks in your list:"); + for (int i = 0; i < taskList.getTaskCount(); i++) { + System.out.println(" " + (i + 1) + "." + taskList.getTask(i).toString()); + } + } + } +} diff --git a/text-ui-test/ACTUAL.TXT b/text-ui-test/ACTUAL.TXT index 0bfe06ba38..8aab82c1bc 100644 --- a/text-ui-test/ACTUAL.TXT +++ b/text-ui-test/ACTUAL.TXT @@ -6,7 +6,7 @@ |-------+------------------+------------------------------------| | 01 | todo j | Add a task(j) without dateline | |-------+------------------+------------------------------------| -| 02 | dateline j /by d | Add a task(j) with due date d | +| 02 | deadline j /by d | Add a task(j) with due date d | |-------+------------------+------------------------------------| | 03 | event j /at d | Add a task(j) that start at date d | |-------+------------------+------------------------------------| @@ -166,7 +166,7 @@ |-------+------------------+------------------------------------| | 01 | todo j | Add a task(j) without dateline | |-------+------------------+------------------------------------| -| 02 | dateline j /by d | Add a task(j) with due date d | +| 02 | deadline j /by d | Add a task(j) with due date d | |-------+------------------+------------------------------------| | 03 | event j /at d | Add a task(j) that start at date d | |-------+------------------+------------------------------------| @@ -182,8 +182,6 @@ |-------+------------------+------------------------------------| | 09 | bye | Terminate the program | |---------------------------------------------------------------| - :( OOPS!!! Command does not exist. - To view the list of commands available use the command: help ____________________________________________________________ ____________________________________________________________ diff --git a/text-ui-test/EXPECTED.txt b/text-ui-test/EXPECTED.txt index 0bfe06ba38..8aab82c1bc 100644 --- a/text-ui-test/EXPECTED.txt +++ b/text-ui-test/EXPECTED.txt @@ -6,7 +6,7 @@ |-------+------------------+------------------------------------| | 01 | todo j | Add a task(j) without dateline | |-------+------------------+------------------------------------| -| 02 | dateline j /by d | Add a task(j) with due date d | +| 02 | deadline j /by d | Add a task(j) with due date d | |-------+------------------+------------------------------------| | 03 | event j /at d | Add a task(j) that start at date d | |-------+------------------+------------------------------------| @@ -166,7 +166,7 @@ |-------+------------------+------------------------------------| | 01 | todo j | Add a task(j) without dateline | |-------+------------------+------------------------------------| -| 02 | dateline j /by d | Add a task(j) with due date d | +| 02 | deadline j /by d | Add a task(j) with due date d | |-------+------------------+------------------------------------| | 03 | event j /at d | Add a task(j) that start at date d | |-------+------------------+------------------------------------| @@ -182,8 +182,6 @@ |-------+------------------+------------------------------------| | 09 | bye | Terminate the program | |---------------------------------------------------------------| - :( OOPS!!! Command does not exist. - To view the list of commands available use the command: help ____________________________________________________________ ____________________________________________________________ From 9fee2e4178a0a86a1eaa72a3d5241a6853c29052 Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Sun, 15 Mar 2020 18:51:45 +0800 Subject: [PATCH 38/45] Extract list and help into parser --- src/main/java/duke/Duke.java | 62 +++++----- src/main/java/duke/Parser.java | 113 +++++++++++++++++- src/main/java/duke/{ => command}/Command.java | 6 +- .../java/duke/command/DeadlineCommand.java | 28 +++++ .../java/duke/{ => command}/HelpCommand.java | 6 +- .../duke/{task => command}/ListCommand.java | 3 +- src/main/java/duke/command/TodoCommand.java | 40 +++++++ text-ui-test/runtest.bat | 2 +- 8 files changed, 221 insertions(+), 39 deletions(-) rename src/main/java/duke/{ => command}/Command.java (88%) create mode 100644 src/main/java/duke/command/DeadlineCommand.java rename src/main/java/duke/{ => command}/HelpCommand.java (91%) rename src/main/java/duke/{task => command}/ListCommand.java (96%) create mode 100644 src/main/java/duke/command/TodoCommand.java diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index a6de7a9009..2bef8c236b 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,5 +1,9 @@ package duke; +import duke.command.Command; +import duke.command.HelpCommand; +import duke.command.ListCommand; +import duke.command.TodoCommand; import duke.exception.DukeArgumentException; import duke.exception.DukeIndexException; import duke.exception.DukeNullException; @@ -31,19 +35,26 @@ public class Duke { public static void main(String[] args) { Ui ui = new Ui(); Command command; + Parser parser = new Parser(); Storage storage = new Storage(FILE_PATH); - ArrayList tasks = storage.load(); + ArrayList tasks; + try { + tasks = storage.load(); + } catch (DateTimeParseException e) { + System.out.println(" :( OOPS!!! Please enter a valid date and time"); + tasks = new ArrayList<>(); + } TaskList taskList = new TaskList(tasks); //Use this to replace tasks boolean isBye = false; ui.greetUser(); while (!isBye) { - String string = ui.getUserCommand(); - String[] stringSplit = string.split(" "); + String userCommand = ui.getUserCommand(); + String[] stringSplit = userCommand.split(" "); try { switch (stringSplit[0]) { case "list": - listCommand(tasks, stringSplit); - command = new ListCommand(); + case "help": + command = parser.parseCommand(userCommand); command.execute(taskList, ui,storage); break; case "done": @@ -54,27 +65,23 @@ public static void main(String[] args) { isBye = byeCommand(stringSplit, tasks); break; case "todo": - todoCommand(tasks, stringSplit); - taskList.addTask(new Todo(String.join(" ", Arrays.copyOfRange(stringSplit, 1, stringSplit.length)))); + command = todoCommand(tasks, stringSplit); + command.execute(taskList, ui, storage); break; case "deadline": - deadlineCommand(tasks, string); - taskList.addTask(new Deadline(string.substring(0, string.indexOf(" /by")).replace("deadline ", ""), string.substring(string.indexOf("/by ")).replace("/by ", ""))); + deadlineCommand(tasks, userCommand); + taskList.addTask(new Deadline(userCommand.substring(0, userCommand.indexOf(" /by")).replace("deadline ", ""), userCommand.substring(userCommand.indexOf("/by ")).replace("/by ", ""))); break; case "event": - eventCommand(tasks, string); - taskList.addTask(new Event(string.substring(0, string.indexOf(" /at")).replace("event ", ""), string.substring(string.indexOf("/at ")).replace("/at ", ""))); + eventCommand(tasks, userCommand); + taskList.addTask(new Event(userCommand.substring(0, userCommand.indexOf(" /at")).replace("event ", ""), userCommand.substring(userCommand.indexOf("/at ")).replace("/at ", ""))); break; case "delete": deleteCommand(tasks, stringSplit); taskList.deleteTask(Integer.parseInt(stringSplit[1]) - 1); break; case "find": - findCommand(tasks, string); - break; - case "help": - command = new HelpCommand(); - command.execute(taskList, ui, storage); + findCommand(tasks, userCommand); break; default: throw new DukeNullException(" :( OOPS!!! Command does not exist."); @@ -224,21 +231,23 @@ public static void deadlineCommand(ArrayList tasks, String string) throws * @param tasks ArrayList containing all the Task. * @param stringSplit User input that is split by spacing. * @throws DukeArgumentException If missing parameter for index. + * @return TodoCommand which adds Todo Task into the TaskList. */ - public static void todoCommand(ArrayList tasks, String[] stringSplit) throws + public static TodoCommand todoCommand(ArrayList tasks, String[] stringSplit) throws DukeArgumentException { if (stringSplit.length == 1) { throw new DukeArgumentException(" :( OOPS!!! Missing description for todo."); } String description; - int taskCount = tasks.size(); description = String.join(" ", Arrays.copyOfRange(stringSplit, 1, stringSplit.length)); tasks.add(new Todo(description)); + /*int taskCount = tasks.size(); System.out.println(" Got it. I've added this task:"); System.out.println(" " + tasks.get(taskCount).toString()); taskCount++; - System.out.println(" Now you have " + taskCount + " tasks in the list."); + System.out.println(" Now you have " + taskCount + " tasks in the list.");*/ + return new TodoCommand(description); } /** @@ -310,20 +319,13 @@ public static void doneCommand(ArrayList tasks, String[] stringSplit) thro * @param tasks ArrayList containing all the Task. * @param stringSplit User input that is split by spacing. * @throws DukeArgumentException If additional parameter is provided. + * @return ListCommand Object that provides the stored tasks. */ - public static void listCommand(ArrayList tasks, String[] stringSplit) throws + /*public static ListCommand listCommand(ArrayList tasks, String[] stringSplit) throws DukeArgumentException { if (stringSplit.length > 1) { throw new DukeArgumentException(" :( OOPS!!! Description not required for list."); } - - /*if (tasks.size() == 0) { - System.out.println(" There are currently no tasks in your list"); - } else { - System.out.println(" Here are the tasks in your list:"); - for (int i = 0; i < tasks.size(); i++) { - System.out.println(" " + (i + 1) + "." + tasks.get(i).toString()); - } - }*/ - } + return new ListCommand(); + }*/ } diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java index 4f4a05fe59..cda43ff5ae 100644 --- a/src/main/java/duke/Parser.java +++ b/src/main/java/duke/Parser.java @@ -1,11 +1,116 @@ package duke; +import duke.command.Command; +import duke.command.HelpCommand; +import duke.command.ListCommand; +import duke.exception.DukeArgumentException; +import duke.exception.DukeNullException; + +/** + * The Parser class is in charged of parsing user input into a Command Object. + * @author Lam Yue Wei + * @version CS2113 AY19/20 Sem 2 Duke + */ public class Parser { + + /** + * Empty constructor for Parser. + */ public Parser() { } - // To be edited to return Command object instead subsequently - public String parseCommand(String string) { - return "command"; + /** + * Parse the user input into a Command Object based on the command keywords. + * @param userCommand User input. + * @return Command Object if command keyword, description and date is valid or DukeNullException otherwise. + */ + public Command parseCommand(String userCommand) { + String commandKeyWord = getCommandKeyWord(userCommand); + Command command; + switch (commandKeyWord) { + case "list": + return parseListCommand(userCommand); + /*case "done": + //doneCommand(tasks, stringSplit); + //taskList.doneTask(Integer.parseInt(stringSplit[1]) - 1); + break; + case "bye": + //isBye = byeCommand(stringSplit, tasks); + break; + case "todo": + //command = todoCommand(tasks, stringSplit); + //command.execute(taskList, ui, storage); + break; + case "deadline": + //deadlineCommand(tasks, userCommand); + //taskList.addTask(new Deadline(userCommand.substring(0, userCommand.indexOf(" /by")).replace("deadline ", ""), userCommand.substring(userCommand.indexOf("/by ")).replace("/by ", ""))); + break; + case "event": + //eventCommand(tasks, userCommand); + //taskList.addTask(new Event(userCommand.substring(0, userCommand.indexOf(" /at")).replace("event ", ""), userCommand.substring(userCommand.indexOf("/at ")).replace("/at ", ""))); + break; + case "delete": + //deleteCommand(tasks, stringSplit); + //taskList.deleteTask(Integer.parseInt(stringSplit[1]) - 1); + break; + case "find": + //findCommand(tasks, userCommand); + break;*/ + case "help": + return parseHelpCommand(userCommand); + default: + throw new DukeNullException(" :( OOPS!!! Command does not exist."); + } + } + + /** + * Extract and return the command keyword from the user input. + * @param userCommand User input. + * @return Command keyword. + */ + public String getCommandKeyWord(String userCommand) { + String[] userCommandSplit = userCommand.split(" "); + return userCommandSplit[0]; + } + + /** + * Extract and return the description from the user input. + * @param userCommand User input. + * @return Description for the command to process. + */ + public String getDescription(String userCommand) { + String userCommandKeyWord = getCommandKeyWord(userCommand); + if (userCommand.equals("deadline")) { + return "To be edited in parser class"; + } else if (userCommand.equals("event")) { + return "Edit Parser class"; + } + return userCommand.substring(userCommandKeyWord.length()); + } + + /** + * Parse userCommand as ListCommand that list all the Task stored. + * @param userCommand User input. + * @throws DukeArgumentException If additional parameter is provided. + * @return ListCommand Object that provides the stored tasks. + */ + public ListCommand parseListCommand(String userCommand) throws DukeArgumentException { + if (getDescription(userCommand).length() > 1) { + throw new DukeArgumentException(" :( OOPS!!! Description not required for list."); + } + return new ListCommand(); + } + + /** + * Parse userCommand as HelpCommand that show the list of available command. + * @param userCommand User input. + * @throws DukeArgumentException If additional parameter is provided. + * @return HelpCommand Object that show the list of available command. + */ + public HelpCommand parseHelpCommand(String userCommand) throws DukeArgumentException { + if (getDescription(userCommand).length() > 1) { + throw new DukeArgumentException(" :( OOPS!!! Description not required for help."); + } + return new HelpCommand(); } -} +} \ No newline at end of file diff --git a/src/main/java/duke/Command.java b/src/main/java/duke/command/Command.java similarity index 88% rename from src/main/java/duke/Command.java rename to src/main/java/duke/command/Command.java index f6101fb0be..670237130d 100644 --- a/src/main/java/duke/Command.java +++ b/src/main/java/duke/command/Command.java @@ -1,4 +1,8 @@ -package duke; +package duke.command; + +import duke.Storage; +import duke.TaskList; +import duke.Ui; /** * The Command Interface is an Interface that provides the platform for various Command to be executed. diff --git a/src/main/java/duke/command/DeadlineCommand.java b/src/main/java/duke/command/DeadlineCommand.java new file mode 100644 index 0000000000..eed9f11752 --- /dev/null +++ b/src/main/java/duke/command/DeadlineCommand.java @@ -0,0 +1,28 @@ +package duke.command; + +import duke.Storage; +import duke.TaskList; +import duke.Ui; + +/** + * The DeadlineCommand class is the Object that adds Deadline Object into the TaskList. + * DeadlineCommand implement Command interface. + * @author Lam Yue Wei + * @version CS2113 AY19/20 Sem 2 Duke + */ +public class DeadlineCommand implements Command { + private String description; + + /** + * Public constructor for DeadlineCommand. + * @param description Description of the Task. + */ + public DeadlineCommand(String description) { + this.description = description; + } + + @Override + public void execute(TaskList taskList, Ui ui, Storage storage) { + System.out.println("to be completed" + description); + } +} diff --git a/src/main/java/duke/HelpCommand.java b/src/main/java/duke/command/HelpCommand.java similarity index 91% rename from src/main/java/duke/HelpCommand.java rename to src/main/java/duke/command/HelpCommand.java index 46cebbe26e..2b191141ab 100644 --- a/src/main/java/duke/HelpCommand.java +++ b/src/main/java/duke/command/HelpCommand.java @@ -1,4 +1,8 @@ -package duke; +package duke.command; + +import duke.Storage; +import duke.TaskList; +import duke.Ui; /** * The HelpCommand class is the Object that provides the user with help by showing the list of available commands. diff --git a/src/main/java/duke/task/ListCommand.java b/src/main/java/duke/command/ListCommand.java similarity index 96% rename from src/main/java/duke/task/ListCommand.java rename to src/main/java/duke/command/ListCommand.java index 72aa61546b..a9f82fe1e2 100644 --- a/src/main/java/duke/task/ListCommand.java +++ b/src/main/java/duke/command/ListCommand.java @@ -1,6 +1,5 @@ -package duke.task; +package duke.command; -import duke.Command; import duke.Storage; import duke.TaskList; import duke.Ui; diff --git a/src/main/java/duke/command/TodoCommand.java b/src/main/java/duke/command/TodoCommand.java new file mode 100644 index 0000000000..dfe7763528 --- /dev/null +++ b/src/main/java/duke/command/TodoCommand.java @@ -0,0 +1,40 @@ +package duke.command; + +import duke.Storage; +import duke.TaskList; +import duke.Ui; +import duke.task.Todo; + +/** + * The TodoCommand class is the Object that adds Todo Object into the TaskList. + * TodoCommand implement Command interface. + * @author Lam Yue Wei + * @version CS2113 AY19/20 Sem 2 Duke + */ +public class TodoCommand implements Command { + private String description; + + /** + * Public constructor for TodoCommand. + * @param description Description of the Task. + */ + public TodoCommand(String description) { + this.description = description; + } + + /** + * Executes the todo function and add the Todo Task into the TaskList. + * @param taskList Task Manager in charge of storing the Task required to be done. + * @param ui Ui Object that deals with interaction with the user. + * @param storage Storage Object that deals with the loading and Storing of Tasks. + */ + @Override + public void execute(TaskList taskList, Ui ui, Storage storage) { + int taskCount = taskList.getTaskCount(); + taskList.addTask(new Todo(description)); + System.out.println(" Got it. I've added this task:"); + System.out.println(" " + taskList.getTask(taskCount).toString()); + taskCount++; + System.out.println(" Now you have " + taskCount + " tasks in the list."); + } +} diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index da4d968b60..55719d2dc6 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -7,7 +7,7 @@ REM delete output from previous run del ACTUAL.TXT REM compile the code into the bin folder -javac -cp ..\src -Xlint:none -d ..\bin ..\src\main\java\duke\*.java ..\src\main\java\duke\task\*.java ..\src\main\java\duke\exception\*.java +javac -cp ..\src -Xlint:none -d ..\bin ..\src\main\java\duke\*.java ..\src\main\java\duke\task\*.java ..\src\main\java\duke\exception\*.java ..\src\main\java\duke\command\*.java IF ERRORLEVEL 1 ( echo ********** BUILD FAILURE ********** exit /b 1 From 0153e1f709a6931a3a33cdda0033ed52f81bbee8 Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Sun, 15 Mar 2020 20:38:05 +0800 Subject: [PATCH 39/45] Add DukeException and DukeDateTimeException --- data/duke.txt | 6 ---- src/main/java/duke/Duke.java | 33 ++++++++++++++--- src/main/java/duke/Parser.java | 36 +++++++++++++------ .../duke/exception/DukeArgumentException.java | 6 ++-- .../duke/exception/DukeDateTimeException.java | 17 +++++++++ .../java/duke/exception/DukeException.java | 17 +++++++++ .../duke/exception/DukeIndexException.java | 6 ++-- .../duke/exception/DukeNullException.java | 4 +-- 8 files changed, 96 insertions(+), 29 deletions(-) create mode 100644 src/main/java/duke/exception/DukeDateTimeException.java create mode 100644 src/main/java/duke/exception/DukeException.java diff --git a/data/duke.txt b/data/duke.txt index e088f286cc..e69de29bb2 100644 --- a/data/duke.txt +++ b/data/duke.txt @@ -1,6 +0,0 @@ -T | 0 | read book -D | 0 | return book | Oct 6 2020 -E | 1 | project meeting | May 29 2021 -T | 0 | join sports club -E | 0 | exams | May 3 2020 -D | 1 | do homework | Apr 25 2020 diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 2bef8c236b..95906c21b8 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -5,10 +5,13 @@ import duke.command.ListCommand; import duke.command.TodoCommand; import duke.exception.DukeArgumentException; +import duke.exception.DukeDateTimeException; import duke.exception.DukeIndexException; import duke.exception.DukeNullException; import duke.task.*; +import java.time.LocalDate; +import java.time.LocalTime; import java.time.format.DateTimeParseException; import java.util.Arrays; import java.util.ArrayList; @@ -65,8 +68,9 @@ public static void main(String[] args) { isBye = byeCommand(stringSplit, tasks); break; case "todo": - command = todoCommand(tasks, stringSplit); - command.execute(taskList, ui, storage); + todoCommand(tasks, stringSplit); + command = parser.parseCommand(userCommand); + command.execute(taskList, ui,storage); break; case "deadline": deadlineCommand(tasks, userCommand); @@ -86,7 +90,7 @@ public static void main(String[] args) { default: throw new DukeNullException(" :( OOPS!!! Command does not exist."); } - } catch (DukeArgumentException | DukeIndexException e) { + } catch (DukeArgumentException | DukeIndexException | DukeDateTimeException e) { System.out.println(e.getMessage()); } catch (DukeNullException e) { System.out.println(e.getMessage()); @@ -178,7 +182,7 @@ public static void deleteCommand(ArrayList tasks, String[] stringSplit) th * @throws DukeArgumentException If missing parameter for description or date. */ public static void eventCommand(ArrayList tasks, String string) throws - DukeArgumentException { + DukeArgumentException, DukeDateTimeException { if (string.length() == 5) { throw new DukeArgumentException(" :( OOPS!!! Missing description for event."); } @@ -191,6 +195,16 @@ public static void eventCommand(ArrayList tasks, String string) throws int taskCount = tasks.size(); description = string.substring(0, string.indexOf(" /at")).replace("event ", ""); dateTime = string.substring(string.indexOf("/at ")).replace("/at ", ""); + + LocalDate date; + LocalTime time; + try { + date = LocalDate.parse(dateTime.split(" ")[0]); + time = LocalTime.parse(dateTime.split(" ")[1]); + } catch(DateTimeParseException e) { + throw new DukeDateTimeException(" :( OOPS!!! Please enter a valid date and time"); + } + tasks.add(new Event(description, dateTime)); System.out.println(" Got it. I've added this task:"); System.out.println(" " + tasks.get(taskCount).toString()); @@ -205,7 +219,7 @@ public static void eventCommand(ArrayList tasks, String string) throws * @throws DukeArgumentException If missing parameter for description or date. */ public static void deadlineCommand(ArrayList tasks, String string) throws - DukeArgumentException { + DukeArgumentException, DukeDateTimeException { if (string.length() == 8) { throw new DukeArgumentException(" :( OOPS!!! Missing description for deadline."); } @@ -219,6 +233,15 @@ public static void deadlineCommand(ArrayList tasks, String string) throws description = string.substring(0, string.indexOf(" /by")).replace("deadline ", ""); dateTime = string.substring(string.indexOf("/by ")).replace("/by ", ""); + LocalDate date; + LocalTime time; + try { + date = LocalDate.parse(dateTime.split(" ")[0]); + time = LocalTime.parse(dateTime.split(" ")[1]); + } catch(DateTimeParseException e) { + throw new DukeDateTimeException(" :( OOPS!!! Please enter a valid date and time"); + } + tasks.add(new Deadline(description, dateTime)); System.out.println(" Got it. I've added this task:"); System.out.println(" " + tasks.get(taskCount).toString()); diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java index cda43ff5ae..1da83bd2be 100644 --- a/src/main/java/duke/Parser.java +++ b/src/main/java/duke/Parser.java @@ -3,9 +3,12 @@ import duke.command.Command; import duke.command.HelpCommand; import duke.command.ListCommand; +import duke.command.TodoCommand; import duke.exception.DukeArgumentException; import duke.exception.DukeNullException; +import java.util.Arrays; + /** * The Parser class is in charged of parsing user input into a Command Object. * @author Lam Yue Wei @@ -24,24 +27,22 @@ public Parser() { * @param userCommand User input. * @return Command Object if command keyword, description and date is valid or DukeNullException otherwise. */ - public Command parseCommand(String userCommand) { + public Command parseCommand(String userCommand) throws DukeArgumentException, DukeNullException { String commandKeyWord = getCommandKeyWord(userCommand); Command command; switch (commandKeyWord) { case "list": return parseListCommand(userCommand); - /*case "done": + /*case "done": //doneCommand(tasks, stringSplit); //taskList.doneTask(Integer.parseInt(stringSplit[1]) - 1); break; case "bye": //isBye = byeCommand(stringSplit, tasks); - break; + break;*/ case "todo": - //command = todoCommand(tasks, stringSplit); - //command.execute(taskList, ui, storage); - break; - case "deadline": + return parseTodoCommand(userCommand); + /*case "deadline": //deadlineCommand(tasks, userCommand); //taskList.addTask(new Deadline(userCommand.substring(0, userCommand.indexOf(" /by")).replace("deadline ", ""), userCommand.substring(userCommand.indexOf("/by ")).replace("/by ", ""))); break; @@ -85,7 +86,22 @@ public String getDescription(String userCommand) { } else if (userCommand.equals("event")) { return "Edit Parser class"; } - return userCommand.substring(userCommandKeyWord.length()); + //String description = description = String.join(" ", Arrays.copyOfRange(stringSplit, 1, stringSplit.length)); + return userCommand.substring(userCommandKeyWord.length()).strip(); + } + + /** + * Parse userCommand as TodoCommand that add todo Task given with a description. + * @param userCommand User input. + * @throws DukeArgumentException If missing parameter for index. + * @return TodoCommand which adds Todo Task into the TaskList. + */ + public TodoCommand parseTodoCommand(String userCommand) throws DukeArgumentException { + String description = getDescription(userCommand); + if (description.length() == 0) { + throw new DukeArgumentException(" :( OOPS!!! Missing description for todo."); + } + return new TodoCommand(description); } /** @@ -95,7 +111,7 @@ public String getDescription(String userCommand) { * @return ListCommand Object that provides the stored tasks. */ public ListCommand parseListCommand(String userCommand) throws DukeArgumentException { - if (getDescription(userCommand).length() > 1) { + if (getDescription(userCommand).length() > 0) { throw new DukeArgumentException(" :( OOPS!!! Description not required for list."); } return new ListCommand(); @@ -108,7 +124,7 @@ public ListCommand parseListCommand(String userCommand) throws DukeArgumentExcep * @return HelpCommand Object that show the list of available command. */ public HelpCommand parseHelpCommand(String userCommand) throws DukeArgumentException { - if (getDescription(userCommand).length() > 1) { + if (getDescription(userCommand).length() > 0) { throw new DukeArgumentException(" :( OOPS!!! Description not required for help."); } return new HelpCommand(); diff --git a/src/main/java/duke/exception/DukeArgumentException.java b/src/main/java/duke/exception/DukeArgumentException.java index e77e599ae8..77183f2dad 100644 --- a/src/main/java/duke/exception/DukeArgumentException.java +++ b/src/main/java/duke/exception/DukeArgumentException.java @@ -2,12 +2,12 @@ /** * The DukeArgumentException class is an Exception that is thrown when there are either - * missing parameter or too many parameter provided by the user. - * DukeArgumentException class extends from IllegalArgumentException class. + * missing argument or too many arguments provided by the user. + * DukeArgumentException class extends from DukeException class. * @author Lam Yue Wei * @version CS2113 AY19/20 Sem 2 Duke */ -public class DukeArgumentException extends IllegalArgumentException { +public class DukeArgumentException extends DukeException { /** * Public constructor for DukeArgumentException. * @param message Error message shown to the user. diff --git a/src/main/java/duke/exception/DukeDateTimeException.java b/src/main/java/duke/exception/DukeDateTimeException.java new file mode 100644 index 0000000000..e04c0d7f46 --- /dev/null +++ b/src/main/java/duke/exception/DukeDateTimeException.java @@ -0,0 +1,17 @@ +package duke.exception; + +/** + * The DukeDateTimeException class is an Exception that is thrown when the user input wrong Date or Time format. + * DukeDateTimeException class extends from DukeException class. + * @author Lam Yue Wei + * @version CS2113 AY19/20 Sem 2 Duke + */ +public class DukeDateTimeException extends DukeException { + /** + * Public constructor for DukeDateTimeException. + * @param message Error message shown to the user. + */ + public DukeDateTimeException(String message) { + super(message); + } +} diff --git a/src/main/java/duke/exception/DukeException.java b/src/main/java/duke/exception/DukeException.java new file mode 100644 index 0000000000..03edb940ec --- /dev/null +++ b/src/main/java/duke/exception/DukeException.java @@ -0,0 +1,17 @@ +package duke.exception; + +/** + * The DukeException class is all the Exception that might be thrown by Duke program. + * DukeException class extends from Exception class. + * @author Lam Yue Wei + * @version CS2113 AY19/20 Sem 2 Duke + */ +public class DukeException extends Exception { + /** + * Public constructor for DukeException. + * @param message Error message shown to the user. + */ + public DukeException(String message) { + super(message); + } +} diff --git a/src/main/java/duke/exception/DukeIndexException.java b/src/main/java/duke/exception/DukeIndexException.java index cc172465dc..3bc590b178 100644 --- a/src/main/java/duke/exception/DukeIndexException.java +++ b/src/main/java/duke/exception/DukeIndexException.java @@ -2,13 +2,13 @@ /** * The DukeIndexException class is an Exception that is thrown when the index provided by - * the user is out of bound. In such cases, the index provided is either negative or greater + * the user is out of bound. Such cases occur when the index provided is either negative or greater * than total number of Task stored. - * DukeIndexException class extends from IndexOutOfBoundsException class. + * DukeIndexException class extends from DukeException class. * @author Lam Yue Wei * @version CS2113 AY19/20 Sem 2 Duke */ -public class DukeIndexException extends IndexOutOfBoundsException { +public class DukeIndexException extends DukeException { /** * Public constructor for DukeIndexException. * @param message Error message shown to the user. diff --git a/src/main/java/duke/exception/DukeNullException.java b/src/main/java/duke/exception/DukeNullException.java index f95df4b622..911c2ca90b 100644 --- a/src/main/java/duke/exception/DukeNullException.java +++ b/src/main/java/duke/exception/DukeNullException.java @@ -3,11 +3,11 @@ /** * The DukeNullException class is an Exception that is thrown when there is an invalid * command provided by the user. - * DukeNullException class extends from NullPointerException class. + * DukeNullException class extends from DukeException class. * @author Lam Yue Wei * @version CS2113 AY19/20 Sem 2 Duke */ -public class DukeNullException extends NullPointerException { +public class DukeNullException extends DukeException { /** * Public constructor for DukeNullException. * @param message Error message shown to the user. From df595691602d5361bdf23cce6f7b13bcf106110c Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Sun, 15 Mar 2020 22:09:42 +0800 Subject: [PATCH 40/45] Add DoneCommand and FindCommand --- src/main/java/duke/Duke.java | 185 ++++++++++-------- src/main/java/duke/Parser.java | 77 +++++--- src/main/java/duke/command/DoneCommand.java | 40 ++++ src/main/java/duke/command/FindCommand.java | 48 +++++ .../duke/exception/DukeIndexException.java | 4 +- 5 files changed, 238 insertions(+), 116 deletions(-) create mode 100644 src/main/java/duke/command/DoneCommand.java create mode 100644 src/main/java/duke/command/FindCommand.java diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 95906c21b8..195f43e4f6 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -24,6 +24,7 @@ /** * Duke is a chatbot that manages Task for user. + * * @author Lam Yue Wei * @version CS2113 AY19/20 Sem 2 Duke */ @@ -33,6 +34,7 @@ public class Duke { /** * Main method for Duke. + * * @param args String[] args in main. */ public static void main(String[] args) { @@ -57,20 +59,25 @@ public static void main(String[] args) { switch (stringSplit[0]) { case "list": case "help": + case "find": command = parser.parseCommand(userCommand); - command.execute(taskList, ui,storage); + command.execute(taskList, ui, storage); break; case "done": - doneCommand(tasks, stringSplit); - taskList.doneTask(Integer.parseInt(stringSplit[1]) - 1); + command = parser.parseCommand(userCommand); + command.execute(taskList, ui, storage); + int doneIndex = Integer.parseInt(stringSplit[1]) - 1; + if (!(doneIndex >= tasks.size() || doneIndex < 0)) { + tasks.get(doneIndex).markAsDone(); + } break; case "bye": isBye = byeCommand(stringSplit, tasks); break; case "todo": - todoCommand(tasks, stringSplit); command = parser.parseCommand(userCommand); - command.execute(taskList, ui,storage); + command.execute(taskList, ui, storage); + tasks.add(new Todo(String.join(" ", Arrays.copyOfRange(stringSplit, 1, stringSplit.length)))); break; case "deadline": deadlineCommand(tasks, userCommand); @@ -84,9 +91,9 @@ public static void main(String[] args) { deleteCommand(tasks, stringSplit); taskList.deleteTask(Integer.parseInt(stringSplit[1]) - 1); break; - case "find": + /*case "find": findCommand(tasks, userCommand); - break; + break;*/ default: throw new DukeNullException(" :( OOPS!!! Command does not exist."); } @@ -109,38 +116,10 @@ public static void main(String[] args) { } } - /** - * Find all Task with description that matches a key word or phrase. - * @param tasks ArrayList containing all the Task. - * @param string User input. - * @throws DukeArgumentException If missing parameter for description. - */ - public static void findCommand(ArrayList tasks, String string) throws - DukeArgumentException { - if (string.length() == 4) { - throw new DukeArgumentException(" :( OOPS!!! Missing description for find."); - } - String description = string.substring(5); - boolean containDescription = false; - int matchNumber = 1; - for (int i = 0; i < tasks.size(); i++) { - if (tasks.get(i).getDescription().contains(description)) { - if (!containDescription) { - System.out.println(" Here are the matching tasks in your list:"); - containDescription = true; - } - System.out.println(" " + matchNumber + "." + tasks.get(i).toString()); - matchNumber++; - } - } - if (!containDescription) { - System.out.println(" There is no matching tasks"); - } - } - /** * Open the file directory based on the filePath, add Task for storage into hard disk and close file. - * @param filePath File directory path. + * + * @param filePath File directory path. * @param taskToAdd Sting containing Task information to store into file. * @throws IOException If input or output operation failed. */ @@ -152,10 +131,11 @@ public static void writeFileTask(String filePath, String taskToAdd) throws IOExc /** * Delete a Task given an index. - * @param tasks ArrayList containing all the Task. + * + * @param tasks ArrayList containing all the Task. * @param stringSplit User input that is split by spacing. * @throws DukeArgumentException If missing parameter for index. - * @throws DukeIndexException If index provided is out of range. + * @throws DukeIndexException If index provided is out of range. */ public static void deleteCommand(ArrayList tasks, String[] stringSplit) throws DukeArgumentException, DukeIndexException { @@ -177,7 +157,8 @@ public static void deleteCommand(ArrayList tasks, String[] stringSplit) th /** * Add event Task given a description and a time of occurrence. - * @param tasks ArrayList containing all the Task. + * + * @param tasks ArrayList containing all the Task. * @param string User input. * @throws DukeArgumentException If missing parameter for description or date. */ @@ -201,7 +182,7 @@ public static void eventCommand(ArrayList tasks, String string) throws try { date = LocalDate.parse(dateTime.split(" ")[0]); time = LocalTime.parse(dateTime.split(" ")[1]); - } catch(DateTimeParseException e) { + } catch (DateTimeParseException e) { throw new DukeDateTimeException(" :( OOPS!!! Please enter a valid date and time"); } @@ -214,7 +195,8 @@ public static void eventCommand(ArrayList tasks, String string) throws /** * Add deadline Task given a description and a due date. - * @param tasks ArrayList containing all the Task. + * + * @param tasks ArrayList containing all the Task. * @param string User input. * @throws DukeArgumentException If missing parameter for description or date. */ @@ -238,7 +220,7 @@ public static void deadlineCommand(ArrayList tasks, String string) throws try { date = LocalDate.parse(dateTime.split(" ")[0]); time = LocalTime.parse(dateTime.split(" ")[1]); - } catch(DateTimeParseException e) { + } catch (DateTimeParseException e) { throw new DukeDateTimeException(" :( OOPS!!! Please enter a valid date and time"); } @@ -249,37 +231,14 @@ public static void deadlineCommand(ArrayList tasks, String string) throws System.out.println(" Now you have " + taskCount + " tasks in the list."); } - /** - * Add todo Task given a description. - * @param tasks ArrayList containing all the Task. - * @param stringSplit User input that is split by spacing. - * @throws DukeArgumentException If missing parameter for index. - * @return TodoCommand which adds Todo Task into the TaskList. - */ - public static TodoCommand todoCommand(ArrayList tasks, String[] stringSplit) throws - DukeArgumentException { - if (stringSplit.length == 1) { - throw new DukeArgumentException(" :( OOPS!!! Missing description for todo."); - } - - String description; - description = String.join(" ", Arrays.copyOfRange(stringSplit, 1, stringSplit.length)); - tasks.add(new Todo(description)); - /*int taskCount = tasks.size(); - System.out.println(" Got it. I've added this task:"); - System.out.println(" " + tasks.get(taskCount).toString()); - taskCount++; - System.out.println(" Now you have " + taskCount + " tasks in the list.");*/ - return new TodoCommand(description); - } - /** * Store all the Task into the hard disk and exit the program. + * * @param stringSplit User input that is split by spacing. - * @param tasks ArrayList containing all the Task. + * @param tasks ArrayList containing all the Task. * @return true to indicate to the program to end. * @throws DukeArgumentException If additional parameter is provided. - * @throws IOException If input or output operation failed. + * @throws IOException If input or output operation failed. */ public static boolean byeCommand(String[] stringSplit, ArrayList tasks) throws DukeArgumentException, IOException { @@ -287,22 +246,22 @@ public static boolean byeCommand(String[] stringSplit, ArrayList tasks) th throw new DukeArgumentException(" :( OOPS!!! Description not required for bye."); } Path path = Paths.get("data"); - if(!Files.exists(path)) { + if (!Files.exists(path)) { Files.createDirectory(path); } String taskToAdd = ""; for (int i = 0; i < tasks.size(); i++) { - if ( tasks.get(i) instanceof Todo) { + if (tasks.get(i) instanceof Todo) { Todo todo = (Todo) tasks.get(i); taskToAdd = taskToAdd + "T | " + (todo.getIsDone() ? 1 : 0) + " | "; taskToAdd = taskToAdd + todo.getDescription(); } - if ( tasks.get(i) instanceof Deadline) { + if (tasks.get(i) instanceof Deadline) { Deadline deadline = (Deadline) tasks.get(i); taskToAdd = taskToAdd + "D | " + (deadline.getIsDone() ? 1 : 0) + " | "; taskToAdd = taskToAdd + deadline.getDescription() + " | " + deadline.getDate(); } - if ( tasks.get(i) instanceof Event) { + if (tasks.get(i) instanceof Event) { Event event = (Event) tasks.get(i); taskToAdd = taskToAdd + "E | " + (event.getIsDone() ? 1 : 0) + " | "; taskToAdd = taskToAdd + event.getDescription() + " | " + event.getDate(); @@ -316,26 +275,31 @@ public static boolean byeCommand(String[] stringSplit, ArrayList tasks) th /** * Mark a Task as done. - * @param tasks ArrayList containing all the Task. + * + * @param tasks ArrayList containing all the Task. * @param stringSplit User input that is split by spacing. * @throws DukeArgumentException If missing parameter for index. - * @throws DukeIndexException If index provided is out of range. + * @throws DukeIndexException If index provided is out of range. */ - public static void doneCommand(ArrayList tasks, String[] stringSplit) throws + /*public static void doneCommand(ArrayList tasks, String[] stringSplit) throws DukeArgumentException, DukeIndexException { int completedTask; if (stringSplit.length == 1) { throw new DukeArgumentException(" :( OOPS!!! Missing index for done."); } - completedTask = Integer.parseInt(stringSplit[1]) - 1; // Might throw NumberFormatException - if (completedTask >= tasks.size() || completedTask < 0) { - throw new DukeIndexException(" :( OOPS!!! Invalid index for done."); + try { + completedTask = Integer.parseInt(stringSplit[1]) - 1; // Might throw NumberFormatException + if (completedTask >= tasks.size() || completedTask < 0) { + throw new DukeIndexException(" :( OOPS!!! Invalid index for done."); + } + tasks.get(completedTask).markAsDone(); + //System.out.println(" Nice! I've marked this task as done:"); + //System.out.println(" " + tasks.get(completedTask).toString()); + } catch (NumberFormatException e) { + throw new DukeIndexException(" :( OOPS!!! " + e.getMessage().substring(18) + " is not number!"); } - tasks.get(completedTask).markAsDone(); - System.out.println(" Nice! I've marked this task as done:"); - System.out.println(" " + tasks.get(completedTask).toString()); - } + }*/ /** * List all the Task stored. @@ -351,4 +315,59 @@ public static void doneCommand(ArrayList tasks, String[] stringSplit) thro } return new ListCommand(); }*/ + + /** + * Add todo Task given a description. + * + * @param tasks ArrayList containing all the Task. + * @param stringSplit User input that is split by spacing. + * @return TodoCommand which adds Todo Task into the TaskList. + * @throws DukeArgumentException If missing parameter for index. + */ + /*public static TodoCommand todoCommand(ArrayList tasks, String[] stringSplit) throws + DukeArgumentException { + if (stringSplit.length == 1) { + throw new DukeArgumentException(" :( OOPS!!! Missing description for todo."); + } + + String description; + description = String.join(" ", Arrays.copyOfRange(stringSplit, 1, stringSplit.length)); + tasks.add(new Todo(description)); + int taskCount = tasks.size(); + System.out.println(" Got it. I've added this task:"); + System.out.println(" " + tasks.get(taskCount).toString()); + taskCount++; + System.out.println(" Now you have " + taskCount + " tasks in the list."); + return new TodoCommand(description); + }*/ + + /** + * Find all Task with description that matches a key word or phrase. + * + * @param tasks ArrayList containing all the Task. + * @param string User input. + * @throws DukeArgumentException If missing parameter for description. + */ + /*public static void findCommand(ArrayList tasks, String string) throws + DukeArgumentException { + if (string.length() == 4) { + throw new DukeArgumentException(" :( OOPS!!! Missing description for find."); + } + String description = string.substring(5); + boolean containDescription = false; + int matchNumber = 1; + for (int i = 0; i < tasks.size(); i++) { + if (tasks.get(i).getDescription().contains(description)) { + if (!containDescription) { + System.out.println(" Here are the matching tasks in your list:"); + containDescription = true; + } + System.out.println(" " + matchNumber + "." + tasks.get(i).toString()); + matchNumber++; + } + } + if (!containDescription) { + System.out.println(" There is no matching tasks"); + } + }*/ } diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java index 1da83bd2be..c6fd18255b 100644 --- a/src/main/java/duke/Parser.java +++ b/src/main/java/duke/Parser.java @@ -1,14 +1,10 @@ package duke; -import duke.command.Command; -import duke.command.HelpCommand; -import duke.command.ListCommand; -import duke.command.TodoCommand; +import duke.command.*; import duke.exception.DukeArgumentException; +import duke.exception.DukeIndexException; import duke.exception.DukeNullException; -import java.util.Arrays; - /** * The Parser class is in charged of parsing user input into a Command Object. * @author Lam Yue Wei @@ -27,38 +23,25 @@ public Parser() { * @param userCommand User input. * @return Command Object if command keyword, description and date is valid or DukeNullException otherwise. */ - public Command parseCommand(String userCommand) throws DukeArgumentException, DukeNullException { + public Command parseCommand(String userCommand) throws DukeArgumentException, DukeNullException, DukeIndexException { String commandKeyWord = getCommandKeyWord(userCommand); - Command command; switch (commandKeyWord) { - case "list": - return parseListCommand(userCommand); - /*case "done": - //doneCommand(tasks, stringSplit); - //taskList.doneTask(Integer.parseInt(stringSplit[1]) - 1); - break; - case "bye": - //isBye = byeCommand(stringSplit, tasks); - break;*/ case "todo": return parseTodoCommand(userCommand); + case "list": + return parseListCommand(userCommand); + case "done": + return parseDoneCommand(userCommand); + case "find": + return parseFindCommand(userCommand); + case "help": + return parseHelpCommand(userCommand); + /*case "deadline": - //deadlineCommand(tasks, userCommand); - //taskList.addTask(new Deadline(userCommand.substring(0, userCommand.indexOf(" /by")).replace("deadline ", ""), userCommand.substring(userCommand.indexOf("/by ")).replace("/by ", ""))); - break; case "event": - //eventCommand(tasks, userCommand); - //taskList.addTask(new Event(userCommand.substring(0, userCommand.indexOf(" /at")).replace("event ", ""), userCommand.substring(userCommand.indexOf("/at ")).replace("/at ", ""))); - break; case "delete": - //deleteCommand(tasks, stringSplit); - //taskList.deleteTask(Integer.parseInt(stringSplit[1]) - 1); - break; - case "find": - //findCommand(tasks, userCommand); + case "bye": break;*/ - case "help": - return parseHelpCommand(userCommand); default: throw new DukeNullException(" :( OOPS!!! Command does not exist."); } @@ -117,6 +100,40 @@ public ListCommand parseListCommand(String userCommand) throws DukeArgumentExcep return new ListCommand(); } + /** + * Parse userCommand as DoneCommand that marks a Task as done. + * @param userCommand User input. + * @return DoneCommand Object that marks a Task as done. + * @throws DukeArgumentException If missing parameter for index. + * @throws DukeIndexException If index provided has incorrect format. + * @return DoneCommand Object that marks a Task as done. + */ + public DoneCommand parseDoneCommand(String userCommand) throws DukeArgumentException, DukeIndexException { + if (getDescription(userCommand).length() == 0) { + throw new DukeArgumentException(" :( OOPS!!! Missing index for done."); + } + + try { + int doneTask = Integer.parseInt(getDescription(userCommand)) - 1; // Might throw NumberFormatException + return new DoneCommand(doneTask); + } catch (NumberFormatException e) { + throw new DukeIndexException(" :( OOPS!!! " + e.getMessage().substring(18) + " is not number!"); + } + } + + /** + * Parse userCommand as FindCommand that find all Task with description that matches a key word or phrase. + * @param userCommand User input. + * @throws DukeArgumentException If missing parameter for description. + * @return FindCommand Object that find all Task with description that matches a key word or phrase. + */ + public Command parseFindCommand(String userCommand) throws DukeArgumentException { + if (userCommand.length() == 4) { + throw new DukeArgumentException(" :( OOPS!!! Missing description for find."); + } + return new FindCommand(getDescription(userCommand)); + } + /** * Parse userCommand as HelpCommand that show the list of available command. * @param userCommand User input. diff --git a/src/main/java/duke/command/DoneCommand.java b/src/main/java/duke/command/DoneCommand.java new file mode 100644 index 0000000000..6e3ef08207 --- /dev/null +++ b/src/main/java/duke/command/DoneCommand.java @@ -0,0 +1,40 @@ +package duke.command; + +import duke.Storage; +import duke.TaskList; +import duke.Ui; + +/** + * The DoneCommand class is the Object that mark a Task in the TaskList as completed. + * DoneCommand implement Command interface. + * @author Lam Yue Wei + * @version CS2113 AY19/20 Sem 2 Duke + */ +public class DoneCommand implements Command { + private int doneIndex; + + /** + * Public constructor for TodoCommand. + * @param doneIndex Index of Task that is completed. + */ + public DoneCommand(int doneIndex) { + this.doneIndex = doneIndex; + } + + /** + * Executes the done function and mark a Task in the TaskList as completed. + * @param taskList Task Manager in charge of storing the Task required to be done. + * @param ui Ui Object that deals with interaction with the user. + * @param storage Storage Object that deals with the loading and Storing of Tasks. + */ + @Override + public void execute(TaskList taskList, Ui ui, Storage storage) { + if (doneIndex >= taskList.getTaskCount() || doneIndex < 0) { + System.out.println(" :( OOPS!!! Invalid index for done."); + } else { + taskList.getTask(doneIndex).markAsDone(); + System.out.println(" Nice! I've marked this task as done:"); + System.out.println(" " + taskList.getTask(doneIndex).toString()); + } + } +} diff --git a/src/main/java/duke/command/FindCommand.java b/src/main/java/duke/command/FindCommand.java new file mode 100644 index 0000000000..53cf52c460 --- /dev/null +++ b/src/main/java/duke/command/FindCommand.java @@ -0,0 +1,48 @@ +package duke.command; + +import duke.Storage; +import duke.TaskList; +import duke.Ui; + +/** + * The FindCommand class is the Object that find all Task with description that matches a keyword or phrase. + * FindCommand implement Command interface. + * @author Lam Yue Wei + * @version CS2113 AY19/20 Sem 2 Duke + */ +public class FindCommand implements Command { + private String description; + + /** + * Public constructor for FindCommand. + * @param description Keyword or phrase of the Task that user wants to find. + */ + public FindCommand(String description) { + this.description = description; + } + + /** + * Executes the find function and find all Task with description that matches the keyword or phrase. + * @param taskList Task Manager in charge of storing the Task required to be done. + * @param ui Ui Object that deals with interaction with the user. + * @param storage Storage Object that deals with the loading and Storing of Tasks. + */ + @Override + public void execute(TaskList taskList, Ui ui, Storage storage) { + boolean containDescription = false; + int matchNumber = 1; + for (int i = 0; i < taskList.getTaskCount(); i++) { + if (taskList.getTask(i).getDescription().contains(description)) { + if (!containDescription) { + System.out.println(" Here are the matching tasks in your list:"); + containDescription = true; + } + System.out.println(" " + matchNumber + "." + taskList.getTask(i).toString()); + matchNumber++; + } + } + if (!containDescription) { + System.out.println(" There is no matching tasks"); + } + } +} diff --git a/src/main/java/duke/exception/DukeIndexException.java b/src/main/java/duke/exception/DukeIndexException.java index 3bc590b178..c6bf567576 100644 --- a/src/main/java/duke/exception/DukeIndexException.java +++ b/src/main/java/duke/exception/DukeIndexException.java @@ -1,9 +1,7 @@ package duke.exception; /** - * The DukeIndexException class is an Exception that is thrown when the index provided by - * the user is out of bound. Such cases occur when the index provided is either negative or greater - * than total number of Task stored. + * The DukeIndexException class is an Exception that is thrown when the user input wrong index format. * DukeIndexException class extends from DukeException class. * @author Lam Yue Wei * @version CS2113 AY19/20 Sem 2 Duke From b2c91138928326798d987e15d4bda05cdc78e02f Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Sun, 15 Mar 2020 22:53:05 +0800 Subject: [PATCH 41/45] Add DeleteCommand --- src/main/java/duke/Duke.java | 144 ++---------------- src/main/java/duke/Parser.java | 42 +++-- src/main/java/duke/command/DeleteCommand.java | 42 +++++ src/main/java/duke/command/DoneCommand.java | 2 +- 4 files changed, 85 insertions(+), 145 deletions(-) create mode 100644 src/main/java/duke/command/DeleteCommand.java diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 195f43e4f6..e45c5c0a73 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -88,20 +88,20 @@ public static void main(String[] args) { taskList.addTask(new Event(userCommand.substring(0, userCommand.indexOf(" /at")).replace("event ", ""), userCommand.substring(userCommand.indexOf("/at ")).replace("/at ", ""))); break; case "delete": - deleteCommand(tasks, stringSplit); - taskList.deleteTask(Integer.parseInt(stringSplit[1]) - 1); + command = parser.parseCommand(userCommand); + command.execute(taskList, ui, storage); + int deleteIndex = Integer.parseInt(stringSplit[1]) - 1; + if (!(deleteIndex >= tasks.size() || deleteIndex < 0)) { + tasks.remove(Integer.parseInt(stringSplit[1]) - 1); + } break; - /*case "find": - findCommand(tasks, userCommand); - break;*/ default: - throw new DukeNullException(" :( OOPS!!! Command does not exist."); + String message = " :( OOPS!!! Command does not exist.\n"; + message += " To view the list of commands available use the command: help"; + throw new DukeNullException(message); } - } catch (DukeArgumentException | DukeIndexException | DukeDateTimeException e) { - System.out.println(e.getMessage()); - } catch (DukeNullException e) { + } catch (DukeArgumentException | DukeIndexException | DukeDateTimeException | DukeNullException e) { System.out.println(e.getMessage()); - System.out.println(" To view the list of commands available use the command: help"); } catch (NumberFormatException e) { System.out.println(" :( OOPS!!! " + e.getMessage().substring(18) + " is not number!"); } catch (FileNotFoundException e) { @@ -129,32 +129,6 @@ public static void writeFileTask(String filePath, String taskToAdd) throws IOExc fileWriter.close(); } - /** - * Delete a Task given an index. - * - * @param tasks ArrayList containing all the Task. - * @param stringSplit User input that is split by spacing. - * @throws DukeArgumentException If missing parameter for index. - * @throws DukeIndexException If index provided is out of range. - */ - public static void deleteCommand(ArrayList tasks, String[] stringSplit) throws - DukeArgumentException, DukeIndexException { - int deletedTask; - int taskCount = tasks.size(); - if (stringSplit.length == 1) { - throw new DukeArgumentException(" :( OOPS!!! Missing index for delete."); - } - deletedTask = Integer.parseInt(stringSplit[1]) - 1; // Might throw NumberFormatException - if (deletedTask >= taskCount | deletedTask < 0) { - throw new DukeIndexException(" :( OOPS!!! Invalid index for delete."); - } - System.out.println(" Noted. I've removed this task:"); - System.out.println(" " + tasks.get(deletedTask)); - tasks.remove(deletedTask); - taskCount--; - System.out.println(" Now you have " + taskCount + " tasks in the list."); - } - /** * Add event Task given a description and a time of occurrence. * @@ -272,102 +246,4 @@ public static boolean byeCommand(String[] stringSplit, ArrayList tasks) th System.out.println(" Bye. Hope to see you again soon!"); return true; } - - /** - * Mark a Task as done. - * - * @param tasks ArrayList containing all the Task. - * @param stringSplit User input that is split by spacing. - * @throws DukeArgumentException If missing parameter for index. - * @throws DukeIndexException If index provided is out of range. - */ - /*public static void doneCommand(ArrayList tasks, String[] stringSplit) throws - DukeArgumentException, DukeIndexException { - int completedTask; - if (stringSplit.length == 1) { - throw new DukeArgumentException(" :( OOPS!!! Missing index for done."); - } - - try { - completedTask = Integer.parseInt(stringSplit[1]) - 1; // Might throw NumberFormatException - if (completedTask >= tasks.size() || completedTask < 0) { - throw new DukeIndexException(" :( OOPS!!! Invalid index for done."); - } - tasks.get(completedTask).markAsDone(); - //System.out.println(" Nice! I've marked this task as done:"); - //System.out.println(" " + tasks.get(completedTask).toString()); - } catch (NumberFormatException e) { - throw new DukeIndexException(" :( OOPS!!! " + e.getMessage().substring(18) + " is not number!"); - } - }*/ - - /** - * List all the Task stored. - * @param tasks ArrayList containing all the Task. - * @param stringSplit User input that is split by spacing. - * @throws DukeArgumentException If additional parameter is provided. - * @return ListCommand Object that provides the stored tasks. - */ - /*public static ListCommand listCommand(ArrayList tasks, String[] stringSplit) throws - DukeArgumentException { - if (stringSplit.length > 1) { - throw new DukeArgumentException(" :( OOPS!!! Description not required for list."); - } - return new ListCommand(); - }*/ - - /** - * Add todo Task given a description. - * - * @param tasks ArrayList containing all the Task. - * @param stringSplit User input that is split by spacing. - * @return TodoCommand which adds Todo Task into the TaskList. - * @throws DukeArgumentException If missing parameter for index. - */ - /*public static TodoCommand todoCommand(ArrayList tasks, String[] stringSplit) throws - DukeArgumentException { - if (stringSplit.length == 1) { - throw new DukeArgumentException(" :( OOPS!!! Missing description for todo."); - } - - String description; - description = String.join(" ", Arrays.copyOfRange(stringSplit, 1, stringSplit.length)); - tasks.add(new Todo(description)); - int taskCount = tasks.size(); - System.out.println(" Got it. I've added this task:"); - System.out.println(" " + tasks.get(taskCount).toString()); - taskCount++; - System.out.println(" Now you have " + taskCount + " tasks in the list."); - return new TodoCommand(description); - }*/ - - /** - * Find all Task with description that matches a key word or phrase. - * - * @param tasks ArrayList containing all the Task. - * @param string User input. - * @throws DukeArgumentException If missing parameter for description. - */ - /*public static void findCommand(ArrayList tasks, String string) throws - DukeArgumentException { - if (string.length() == 4) { - throw new DukeArgumentException(" :( OOPS!!! Missing description for find."); - } - String description = string.substring(5); - boolean containDescription = false; - int matchNumber = 1; - for (int i = 0; i < tasks.size(); i++) { - if (tasks.get(i).getDescription().contains(description)) { - if (!containDescription) { - System.out.println(" Here are the matching tasks in your list:"); - containDescription = true; - } - System.out.println(" " + matchNumber + "." + tasks.get(i).toString()); - matchNumber++; - } - } - if (!containDescription) { - System.out.println(" There is no matching tasks"); - } - }*/ } diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java index c6fd18255b..bf544f3544 100644 --- a/src/main/java/duke/Parser.java +++ b/src/main/java/duke/Parser.java @@ -4,6 +4,9 @@ import duke.exception.DukeArgumentException; import duke.exception.DukeIndexException; import duke.exception.DukeNullException; +import duke.task.Task; + +import java.util.ArrayList; /** * The Parser class is in charged of parsing user input into a Command Object. @@ -32,6 +35,8 @@ public Command parseCommand(String userCommand) throws DukeArgumentException, Du return parseListCommand(userCommand); case "done": return parseDoneCommand(userCommand); + case "delete": + return parseDeleteCommand(userCommand); case "find": return parseFindCommand(userCommand); case "help": @@ -39,7 +44,7 @@ public Command parseCommand(String userCommand) throws DukeArgumentException, Du /*case "deadline": case "event": - case "delete": + case "bye": break;*/ default: @@ -50,7 +55,7 @@ public Command parseCommand(String userCommand) throws DukeArgumentException, Du /** * Extract and return the command keyword from the user input. * @param userCommand User input. - * @return Command keyword. + * @return String representation of Command keyword. */ public String getCommandKeyWord(String userCommand) { String[] userCommandSplit = userCommand.split(" "); @@ -60,7 +65,7 @@ public String getCommandKeyWord(String userCommand) { /** * Extract and return the description from the user input. * @param userCommand User input. - * @return Description for the command to process. + * @return String representation of the description for the command to process. */ public String getDescription(String userCommand) { String userCommandKeyWord = getCommandKeyWord(userCommand); @@ -69,15 +74,14 @@ public String getDescription(String userCommand) { } else if (userCommand.equals("event")) { return "Edit Parser class"; } - //String description = description = String.join(" ", Arrays.copyOfRange(stringSplit, 1, stringSplit.length)); return userCommand.substring(userCommandKeyWord.length()).strip(); } /** * Parse userCommand as TodoCommand that add todo Task given with a description. * @param userCommand User input. - * @throws DukeArgumentException If missing parameter for index. * @return TodoCommand which adds Todo Task into the TaskList. + * @throws DukeArgumentException If missing parameter for index. */ public TodoCommand parseTodoCommand(String userCommand) throws DukeArgumentException { String description = getDescription(userCommand); @@ -90,8 +94,8 @@ public TodoCommand parseTodoCommand(String userCommand) throws DukeArgumentExcep /** * Parse userCommand as ListCommand that list all the Task stored. * @param userCommand User input. - * @throws DukeArgumentException If additional parameter is provided. * @return ListCommand Object that provides the stored tasks. + * @throws DukeArgumentException If additional parameter is provided. */ public ListCommand parseListCommand(String userCommand) throws DukeArgumentException { if (getDescription(userCommand).length() > 0) { @@ -106,7 +110,6 @@ public ListCommand parseListCommand(String userCommand) throws DukeArgumentExcep * @return DoneCommand Object that marks a Task as done. * @throws DukeArgumentException If missing parameter for index. * @throws DukeIndexException If index provided has incorrect format. - * @return DoneCommand Object that marks a Task as done. */ public DoneCommand parseDoneCommand(String userCommand) throws DukeArgumentException, DukeIndexException { if (getDescription(userCommand).length() == 0) { @@ -121,13 +124,32 @@ public DoneCommand parseDoneCommand(String userCommand) throws DukeArgumentExcep } } + /** + * Parse userCommand as DeleteCommand that delete a Task. + * @param userCommand User input. + * @return DeleteCommand Object that delete a Task from the TaskList. + * @throws DukeArgumentException If missing parameter for index. + * @throws DukeIndexException If index provided has incorrect format. + */ + public DeleteCommand parseDeleteCommand(String userCommand) throws DukeArgumentException, DukeIndexException { + if (getDescription(userCommand).length() == 0) { + throw new DukeArgumentException(" :( OOPS!!! Missing index for delete."); + } + try { + int deleteTask = Integer.parseInt(getDescription(userCommand)) - 1; // Might throw NumberFormatException + return new DeleteCommand(deleteTask); + } catch (NumberFormatException e) { + throw new DukeIndexException(" :( OOPS!!! " + e.getMessage().substring(18) + " is not number!"); + } + } + /** * Parse userCommand as FindCommand that find all Task with description that matches a key word or phrase. * @param userCommand User input. - * @throws DukeArgumentException If missing parameter for description. * @return FindCommand Object that find all Task with description that matches a key word or phrase. + * @throws DukeArgumentException If missing parameter for description. */ - public Command parseFindCommand(String userCommand) throws DukeArgumentException { + public FindCommand parseFindCommand(String userCommand) throws DukeArgumentException { if (userCommand.length() == 4) { throw new DukeArgumentException(" :( OOPS!!! Missing description for find."); } @@ -137,8 +159,8 @@ public Command parseFindCommand(String userCommand) throws DukeArgumentException /** * Parse userCommand as HelpCommand that show the list of available command. * @param userCommand User input. - * @throws DukeArgumentException If additional parameter is provided. * @return HelpCommand Object that show the list of available command. + * @throws DukeArgumentException If additional parameter is provided. */ public HelpCommand parseHelpCommand(String userCommand) throws DukeArgumentException { if (getDescription(userCommand).length() > 0) { diff --git a/src/main/java/duke/command/DeleteCommand.java b/src/main/java/duke/command/DeleteCommand.java new file mode 100644 index 0000000000..6845e7bb2f --- /dev/null +++ b/src/main/java/duke/command/DeleteCommand.java @@ -0,0 +1,42 @@ +package duke.command; + +import duke.Storage; +import duke.TaskList; +import duke.Ui; +import duke.exception.DukeIndexException; + +/** + * The DeleteCommand class is the Object that delete a Task from the TaskList. + * DeleteCommand implement Command interface. + * @author Lam Yue Wei + * @version CS2113 AY19/20 Sem 2 Duke + */ +public class DeleteCommand implements Command { + private int deleteIndex; + + /** + * Public constructor for DeleteCommand. + * @param deleteIndex Index of Task that is completed. + */ + public DeleteCommand(int deleteIndex) { + this.deleteIndex = deleteIndex; + } + + /** + * Executes the delete function and delete a Task from the TaskList. + * @param taskList Task Manager in charge of storing the Task required to be done. + * @param ui Ui Object that deals with interaction with the user. + * @param storage Storage Object that deals with the loading and Storing of Tasks. + */ + @Override + public void execute(TaskList taskList, Ui ui, Storage storage) { + if (deleteIndex >= taskList.getTaskCount() | deleteIndex < 0) { + System.out.println(" :( OOPS!!! Invalid index for delete."); + } else{ + System.out.println(" Noted. I've removed this task:"); + System.out.println(" " + taskList.getTask(deleteIndex)); + taskList.deleteTask(deleteIndex); + System.out.println(" Now you have " + taskList.getTaskCount() + " tasks in the list."); + } + } +} diff --git a/src/main/java/duke/command/DoneCommand.java b/src/main/java/duke/command/DoneCommand.java index 6e3ef08207..022ae63e1a 100644 --- a/src/main/java/duke/command/DoneCommand.java +++ b/src/main/java/duke/command/DoneCommand.java @@ -14,7 +14,7 @@ public class DoneCommand implements Command { private int doneIndex; /** - * Public constructor for TodoCommand. + * Public constructor for DoneCommand. * @param doneIndex Index of Task that is completed. */ public DoneCommand(int doneIndex) { From 245182d6a94d87da3a087b3cc110fba96bdcc33b Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Mon, 16 Mar 2020 20:10:41 +0800 Subject: [PATCH 42/45] Complete all extraction into Command and Parser --- src/main/java/duke/Constant.java | 27 ++ src/main/java/duke/Duke.java | 250 +++--------------- src/main/java/duke/Parser.java | 174 ++++++++++-- src/main/java/duke/Storage.java | 58 +++- src/main/java/duke/TaskList.java | 7 + src/main/java/duke/Ui.java | 33 ++- src/main/java/duke/command/ByeCommand.java | 48 ++++ src/main/java/duke/command/Command.java | 9 +- .../java/duke/command/DeadlineCommand.java | 32 ++- src/main/java/duke/command/DeleteCommand.java | 10 +- src/main/java/duke/command/DoneCommand.java | 9 + src/main/java/duke/command/EventCommand.java | 57 ++++ src/main/java/duke/command/FindCommand.java | 9 + src/main/java/duke/command/HelpCommand.java | 9 + src/main/java/duke/command/ListCommand.java | 9 + src/main/java/duke/command/TodoCommand.java | 9 + .../duke/exception/DukeFileException.java | 18 ++ src/main/java/duke/task/Deadline.java | 13 + src/main/java/duke/task/Event.java | 15 +- src/main/java/duke/task/Task.java | 1 - text-ui-test/ACTUAL.TXT | 73 +++-- text-ui-test/EXPECTED.txt | 73 +++-- text-ui-test/input.txt | 8 + 23 files changed, 651 insertions(+), 300 deletions(-) create mode 100644 src/main/java/duke/Constant.java create mode 100644 src/main/java/duke/command/ByeCommand.java create mode 100644 src/main/java/duke/command/EventCommand.java create mode 100644 src/main/java/duke/exception/DukeFileException.java diff --git a/src/main/java/duke/Constant.java b/src/main/java/duke/Constant.java new file mode 100644 index 0000000000..f3f573691a --- /dev/null +++ b/src/main/java/duke/Constant.java @@ -0,0 +1,27 @@ +package duke; + +/** + * The Constant class is the class that keeps a record of all the constants used across all Duke package. + * @author Lam Yue Wei + * @version CS2113 AY19/20 Sem 2 Duke + */ +public class Constant { + // Command Keywords for all the command + public static final String TODO_COMMAND_KEYWORD = "todo"; + public static final String DEADLINE_COMMAND_KEYWORD = "deadline"; + public static final String EVENT_COMMAND_KEYWORD = "event"; + public static final String LIST_COMMAND_KEYWORD = "list"; + public static final String DONE_COMMAND_KEYWORD = "done"; + public static final String DELETE_COMMAND_KEYWORD = "delete"; + public static final String FIND_COMMAND_KEYWORD = "find"; + public static final String HELP_COMMAND_KEYWORD = "help"; + public static final String BYE_COMMAND_KEYWORD = "bye"; + + // Command delimiter for deadline and event + public static final String DEADLINE_COMMAND_DELIMITER = " /by "; + public static final String EVENT_COMMAND_DELIMITER = " /at "; + + // File path and name for storing and loading of data + public static final String FILE_PATH = "data/duke.txt"; + public static final String FILE_NAME = "data"; +} diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index e45c5c0a73..c9dfe801bd 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,249 +1,69 @@ package duke; import duke.command.Command; -import duke.command.HelpCommand; -import duke.command.ListCommand; -import duke.command.TodoCommand; -import duke.exception.DukeArgumentException; -import duke.exception.DukeDateTimeException; -import duke.exception.DukeIndexException; -import duke.exception.DukeNullException; +import duke.exception.*; import duke.task.*; -import java.time.LocalDate; -import java.time.LocalTime; import java.time.format.DateTimeParseException; -import java.util.Arrays; import java.util.ArrayList; import java.io.FileNotFoundException; -import java.io.FileWriter; import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.nio.file.Path; + +import static duke.Constant.FILE_PATH; /** * Duke is a chatbot that manages Task for user. - * * @author Lam Yue Wei * @version CS2113 AY19/20 Sem 2 Duke */ public class Duke { - - public static final String FILE_PATH = "data/duke.txt"; + private Storage storage; + private TaskList taskList; + private Ui ui; + private Parser parser; /** - * Main method for Duke. - * - * @param args String[] args in main. + * Public constructor for Duke. + * @param filePath File path of the external hard disk that the Task data will be stored into. */ - public static void main(String[] args) { - Ui ui = new Ui(); - Command command; - Parser parser = new Parser(); - Storage storage = new Storage(FILE_PATH); - ArrayList tasks; + public Duke(String filePath) { + this.ui = new Ui(); + this.storage = new Storage(filePath); + this.parser = new Parser(); try { - tasks = storage.load(); - } catch (DateTimeParseException e) { - System.out.println(" :( OOPS!!! Please enter a valid date and time"); - tasks = new ArrayList<>(); + taskList = new TaskList(storage.load()); + } catch (DukeException e) { + ui.showError(e.getMessage()); + taskList = new TaskList(); } - TaskList taskList = new TaskList(tasks); //Use this to replace tasks + } + + /** + * Run the Duke program to add / view / find / delete / done Task. Terminate program when user + * input "bye" and store all the Task data into an external hard disk. + */ + public void run() { boolean isBye = false; ui.greetUser(); while (!isBye) { - String userCommand = ui.getUserCommand(); - String[] stringSplit = userCommand.split(" "); try { - switch (stringSplit[0]) { - case "list": - case "help": - case "find": - command = parser.parseCommand(userCommand); - command.execute(taskList, ui, storage); - break; - case "done": - command = parser.parseCommand(userCommand); - command.execute(taskList, ui, storage); - int doneIndex = Integer.parseInt(stringSplit[1]) - 1; - if (!(doneIndex >= tasks.size() || doneIndex < 0)) { - tasks.get(doneIndex).markAsDone(); - } - break; - case "bye": - isBye = byeCommand(stringSplit, tasks); - break; - case "todo": - command = parser.parseCommand(userCommand); - command.execute(taskList, ui, storage); - tasks.add(new Todo(String.join(" ", Arrays.copyOfRange(stringSplit, 1, stringSplit.length)))); - break; - case "deadline": - deadlineCommand(tasks, userCommand); - taskList.addTask(new Deadline(userCommand.substring(0, userCommand.indexOf(" /by")).replace("deadline ", ""), userCommand.substring(userCommand.indexOf("/by ")).replace("/by ", ""))); - break; - case "event": - eventCommand(tasks, userCommand); - taskList.addTask(new Event(userCommand.substring(0, userCommand.indexOf(" /at")).replace("event ", ""), userCommand.substring(userCommand.indexOf("/at ")).replace("/at ", ""))); - break; - case "delete": - command = parser.parseCommand(userCommand); - command.execute(taskList, ui, storage); - int deleteIndex = Integer.parseInt(stringSplit[1]) - 1; - if (!(deleteIndex >= tasks.size() || deleteIndex < 0)) { - tasks.remove(Integer.parseInt(stringSplit[1]) - 1); - } - break; - default: - String message = " :( OOPS!!! Command does not exist.\n"; - message += " To view the list of commands available use the command: help"; - throw new DukeNullException(message); - } - } catch (DukeArgumentException | DukeIndexException | DukeDateTimeException | DukeNullException e) { - System.out.println(e.getMessage()); - } catch (NumberFormatException e) { - System.out.println(" :( OOPS!!! " + e.getMessage().substring(18) + " is not number!"); - } catch (FileNotFoundException e) { - System.out.println("Folder does not exist yet" + e.getMessage()); - } catch (IOException e) { - System.out.println("Something went wrong: " + e.getMessage()); - } catch (DateTimeParseException e) { - System.out.println(" :( OOPS!!! Please enter a valid date and time"); + String userCommand = ui.getUserCommand(); + Command command = parser.parseCommand(userCommand); + command.execute(taskList, ui, storage); + isBye = command.isExit(); + } catch (DukeException e) { + ui.showError(e.getMessage()); } finally { - System.out.println(" ____________________________________________________________"); + ui.showLine(); } } } /** - * Open the file directory based on the filePath, add Task for storage into hard disk and close file. - * - * @param filePath File directory path. - * @param taskToAdd Sting containing Task information to store into file. - * @throws IOException If input or output operation failed. - */ - public static void writeFileTask(String filePath, String taskToAdd) throws IOException { - FileWriter fileWriter = new FileWriter(filePath); - fileWriter.write(taskToAdd); - fileWriter.close(); - } - - /** - * Add event Task given a description and a time of occurrence. - * - * @param tasks ArrayList containing all the Task. - * @param string User input. - * @throws DukeArgumentException If missing parameter for description or date. - */ - public static void eventCommand(ArrayList tasks, String string) throws - DukeArgumentException, DukeDateTimeException { - if (string.length() == 5) { - throw new DukeArgumentException(" :( OOPS!!! Missing description for event."); - } - if (!string.contains("/at")) { - throw new DukeArgumentException(" :( OOPS!!! Missing date for event."); - } - - String description; - String dateTime; - int taskCount = tasks.size(); - description = string.substring(0, string.indexOf(" /at")).replace("event ", ""); - dateTime = string.substring(string.indexOf("/at ")).replace("/at ", ""); - - LocalDate date; - LocalTime time; - try { - date = LocalDate.parse(dateTime.split(" ")[0]); - time = LocalTime.parse(dateTime.split(" ")[1]); - } catch (DateTimeParseException e) { - throw new DukeDateTimeException(" :( OOPS!!! Please enter a valid date and time"); - } - - tasks.add(new Event(description, dateTime)); - System.out.println(" Got it. I've added this task:"); - System.out.println(" " + tasks.get(taskCount).toString()); - taskCount++; - System.out.println(" Now you have " + taskCount + " tasks in the list."); - } - - /** - * Add deadline Task given a description and a due date. - * - * @param tasks ArrayList containing all the Task. - * @param string User input. - * @throws DukeArgumentException If missing parameter for description or date. - */ - public static void deadlineCommand(ArrayList tasks, String string) throws - DukeArgumentException, DukeDateTimeException { - if (string.length() == 8) { - throw new DukeArgumentException(" :( OOPS!!! Missing description for deadline."); - } - if (!string.contains("/by")) { - throw new DukeArgumentException(" :( OOPS!!! Missing date for deadline."); - } - - String description; - String dateTime; - int taskCount = tasks.size(); - description = string.substring(0, string.indexOf(" /by")).replace("deadline ", ""); - dateTime = string.substring(string.indexOf("/by ")).replace("/by ", ""); - - LocalDate date; - LocalTime time; - try { - date = LocalDate.parse(dateTime.split(" ")[0]); - time = LocalTime.parse(dateTime.split(" ")[1]); - } catch (DateTimeParseException e) { - throw new DukeDateTimeException(" :( OOPS!!! Please enter a valid date and time"); - } - - tasks.add(new Deadline(description, dateTime)); - System.out.println(" Got it. I've added this task:"); - System.out.println(" " + tasks.get(taskCount).toString()); - taskCount++; - System.out.println(" Now you have " + taskCount + " tasks in the list."); - } - - /** - * Store all the Task into the hard disk and exit the program. - * - * @param stringSplit User input that is split by spacing. - * @param tasks ArrayList containing all the Task. - * @return true to indicate to the program to end. - * @throws DukeArgumentException If additional parameter is provided. - * @throws IOException If input or output operation failed. + * Main method for Duke. + * @param args String[] args in main. */ - public static boolean byeCommand(String[] stringSplit, ArrayList tasks) throws - DukeArgumentException, IOException { - if (stringSplit.length > 1) { - throw new DukeArgumentException(" :( OOPS!!! Description not required for bye."); - } - Path path = Paths.get("data"); - if (!Files.exists(path)) { - Files.createDirectory(path); - } - String taskToAdd = ""; - for (int i = 0; i < tasks.size(); i++) { - if (tasks.get(i) instanceof Todo) { - Todo todo = (Todo) tasks.get(i); - taskToAdd = taskToAdd + "T | " + (todo.getIsDone() ? 1 : 0) + " | "; - taskToAdd = taskToAdd + todo.getDescription(); - } - if (tasks.get(i) instanceof Deadline) { - Deadline deadline = (Deadline) tasks.get(i); - taskToAdd = taskToAdd + "D | " + (deadline.getIsDone() ? 1 : 0) + " | "; - taskToAdd = taskToAdd + deadline.getDescription() + " | " + deadline.getDate(); - } - if (tasks.get(i) instanceof Event) { - Event event = (Event) tasks.get(i); - taskToAdd = taskToAdd + "E | " + (event.getIsDone() ? 1 : 0) + " | "; - taskToAdd = taskToAdd + event.getDescription() + " | " + event.getDate(); - } - taskToAdd += "\n"; - } - writeFileTask(FILE_PATH, taskToAdd); - System.out.println(" Bye. Hope to see you again soon!"); - return true; + public static void main(String[] args) { + new Duke(FILE_PATH).run(); } } diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java index bf544f3544..512a250212 100644 --- a/src/main/java/duke/Parser.java +++ b/src/main/java/duke/Parser.java @@ -2,11 +2,15 @@ import duke.command.*; import duke.exception.DukeArgumentException; +import duke.exception.DukeDateTimeException; import duke.exception.DukeIndexException; import duke.exception.DukeNullException; -import duke.task.Task; -import java.util.ArrayList; +import java.time.LocalDate; +import java.time.LocalTime; +import java.time.format.DateTimeParseException; + +import static duke.Constant.*; /** * The Parser class is in charged of parsing user input into a Command Object. @@ -26,29 +30,32 @@ public Parser() { * @param userCommand User input. * @return Command Object if command keyword, description and date is valid or DukeNullException otherwise. */ - public Command parseCommand(String userCommand) throws DukeArgumentException, DukeNullException, DukeIndexException { + public Command parseCommand(String userCommand) throws DukeArgumentException, DukeNullException, + DukeIndexException, DukeDateTimeException { String commandKeyWord = getCommandKeyWord(userCommand); switch (commandKeyWord) { - case "todo": + case TODO_COMMAND_KEYWORD: return parseTodoCommand(userCommand); - case "list": + case DEADLINE_COMMAND_KEYWORD: + return parseDeadlineCommand(userCommand); + case EVENT_COMMAND_KEYWORD: + return parseEventCommand(userCommand); + case LIST_COMMAND_KEYWORD: return parseListCommand(userCommand); - case "done": + case DONE_COMMAND_KEYWORD: return parseDoneCommand(userCommand); - case "delete": + case DELETE_COMMAND_KEYWORD: return parseDeleteCommand(userCommand); - case "find": + case FIND_COMMAND_KEYWORD: return parseFindCommand(userCommand); - case "help": + case HELP_COMMAND_KEYWORD: return parseHelpCommand(userCommand); - - /*case "deadline": - case "event": - - case "bye": - break;*/ + case BYE_COMMAND_KEYWORD: + return parseByeCommand(userCommand); default: - throw new DukeNullException(" :( OOPS!!! Command does not exist."); + String message = " :( OOPS!!! Command does not exist.\n"; + message += " To view the list of commands available use the command: help"; + throw new DukeNullException(message); } } @@ -69,14 +76,80 @@ public String getCommandKeyWord(String userCommand) { */ public String getDescription(String userCommand) { String userCommandKeyWord = getCommandKeyWord(userCommand); - if (userCommand.equals("deadline")) { - return "To be edited in parser class"; - } else if (userCommand.equals("event")) { - return "Edit Parser class"; - } return userCommand.substring(userCommandKeyWord.length()).strip(); } + /** + * Extract and return the description from the user input using the delimiter. + * @param userCommand User input. + * @param delimiter Delimiter used to split the user input. + * @return String representation of the description for the command to process. + */ + public String getDescription(String userCommand, String delimiter) { + String userCommandKeyWord = getCommandKeyWord(userCommand); + return userCommand.substring(userCommandKeyWord.length(), userCommand.indexOf(delimiter)).strip(); + } + + /** + * Extract and return the Date and Time as a String Array from the user input. String representation of date + * and time is found in index 0 and 1 respectively. + * @param userCommand User input. + * @param delimiter Delimiter used to split the user input. + * @return String Array representation of the Date and Time from the user input. + * @throws DukeArgumentException If missing date and/or time is found or if additional parameter is found. + */ + public String[] getDateTime(String userCommand, String delimiter) throws DukeArgumentException { + String[] dateTime; + String userCommandKeyword = getCommandKeyWord(userCommand); + dateTime = userCommand.substring(userCommand.indexOf(delimiter)).replace(delimiter, "") + .strip().split( " "); + if (dateTime.length == 0 || dateTime.length == 1) { + throw new DukeArgumentException(" :( OOPS!!! Missing Date or Time for " + userCommandKeyword + "."); + } + if (dateTime.length > 2) { + throw new DukeArgumentException(" :( OOPS!!! Extra arguments found for " + userCommandKeyword + "."); + } + return dateTime; + } + + /** + * Handles the parsing of user command into a LocalDate Object. + * @param userCommand User input. + * @param delimiter Delimiter used to split the user input. + * @return LocalDate Object of the date of the Task. + * @throws DukeArgumentException If missing date and/or time is found or if additional parameter is found. + * @throws DukeDateTimeException If date provided has incorrect format. + */ + public LocalDate getDate(String userCommand, String delimiter) throws DukeArgumentException, DukeDateTimeException { + String[] dateTime = getDateTime(userCommand, delimiter); + try { + return LocalDate.parse(dateTime[0]); + } catch (DateTimeParseException e) { + String message = " :( OOPS!!! Please enter a valid date and time\n" + + " Date and time format: YYYY-MM-DD HH:MM"; + throw new DukeDateTimeException(message); + } + } + + /** + * Handles the parsing of user command into a LocalTime Object. + * @param userCommand User input. + * @param delimiter Delimiter used to split the user input. + * @return LocalTime Object of the time of the Task. + * @throws DukeArgumentException If missing date and/or time is found or if additional parameter is found. + * @throws DukeDateTimeException If time provided has incorrect format. + */ + public LocalTime getTime(String userCommand, String delimiter) throws DukeArgumentException, DukeDateTimeException { + String[] dateTime = getDateTime(userCommand, delimiter); + try { + return LocalTime.parse(dateTime[1]); + } catch (DateTimeParseException e) { + String message = " :( OOPS!!! Please enter a valid date and time\n" + + " Date and time format: YYYY-MM-DD HH:MM"; + throw new DukeDateTimeException(message); + } + } + /** * Parse userCommand as TodoCommand that add todo Task given with a description. * @param userCommand User input. @@ -91,6 +164,50 @@ public TodoCommand parseTodoCommand(String userCommand) throws DukeArgumentExcep return new TodoCommand(description); } + /** + * Parse userCommand as DeadlineCommand that add deadline Task given a description and a due date and time. + * @param userCommand User input. + * @return DeadlineCommand which add deadline Task given a description and a due date. + * @throws DukeArgumentException If there are missing description, if missing date and/or time is found or + * if additional parameter is found. + * @throws DukeDateTimeException If date or time provided has incorrect format. + */ + public DeadlineCommand parseDeadlineCommand(String userCommand) throws DukeArgumentException, DukeDateTimeException { + if (getDescription(userCommand).length() == 0) { + throw new DukeArgumentException(" :( OOPS!!! Missing description for deadline."); + } + if (!userCommand.contains(DEADLINE_COMMAND_DELIMITER)) { + throw new DukeArgumentException(" :( OOPS!!! Missing date and time for deadline."); + } + + String description = getDescription(userCommand, DEADLINE_COMMAND_DELIMITER); + LocalDate date = getDate(userCommand, DEADLINE_COMMAND_DELIMITER); + LocalTime time = getTime(userCommand, DEADLINE_COMMAND_DELIMITER); + return new DeadlineCommand(description, date, time); + } + + /** + * Parse userCommand as EventCommand that add event Task given a description and a date and time of occurrence. + * @param userCommand User input. + * @return EventCommand which add event Task given a description and a date and time of occurrence. + * @throws DukeArgumentException If there are missing description, if missing date and/or time is found or + * if additional parameter is found. + * @throws DukeDateTimeException If date or time provided has incorrect format. + */ + public EventCommand parseEventCommand(String userCommand) throws DukeArgumentException, DukeDateTimeException { + if (getDescription(userCommand).length() == 0) { + throw new DukeArgumentException(" :( OOPS!!! Missing description for event."); + } + if (!userCommand.contains(EVENT_COMMAND_DELIMITER)) { + throw new DukeArgumentException(" :( OOPS!!! Missing date and time for event."); + } + + String description = getDescription(userCommand, EVENT_COMMAND_DELIMITER); + LocalDate date = getDate(userCommand, EVENT_COMMAND_DELIMITER); + LocalTime time = getTime(userCommand, EVENT_COMMAND_DELIMITER); + return new EventCommand(description, date, time); + } + /** * Parse userCommand as ListCommand that list all the Task stored. * @param userCommand User input. @@ -150,7 +267,7 @@ public DeleteCommand parseDeleteCommand(String userCommand) throws DukeArgumentE * @throws DukeArgumentException If missing parameter for description. */ public FindCommand parseFindCommand(String userCommand) throws DukeArgumentException { - if (userCommand.length() == 4) { + if (getDescription(userCommand).length() == 0) { throw new DukeArgumentException(" :( OOPS!!! Missing description for find."); } return new FindCommand(getDescription(userCommand)); @@ -168,4 +285,17 @@ public HelpCommand parseHelpCommand(String userCommand) throws DukeArgumentExcep } return new HelpCommand(); } + + /** + * Parse userCommand as ByeCommand that store all the Task into the hard disk and exit the program. + * @param userCommand User input. + * @return ByeCommand Object that store all the Task into the hard disk and exit the program. + * @throws DukeArgumentException If additional parameter is provided. + */ + public ByeCommand parseByeCommand(String userCommand) throws DukeArgumentException { + if (getDescription(userCommand).length() > 0) { + throw new DukeArgumentException(" :( OOPS!!! Description not required for bye."); + } + return new ByeCommand(); + } } \ No newline at end of file diff --git a/src/main/java/duke/Storage.java b/src/main/java/duke/Storage.java index ee5933f0e3..d79fb0f45a 100644 --- a/src/main/java/duke/Storage.java +++ b/src/main/java/duke/Storage.java @@ -1,5 +1,6 @@ package duke; +import duke.exception.DukeFileException; import duke.task.Deadline; import duke.task.Event; import duke.task.Task; @@ -7,9 +8,16 @@ 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.Scanner; +import static duke.Constant.FILE_NAME; + /** * The Storage class is the class handles the loading of Task from a specified filePath and * storing of Task into the filePath. @@ -32,7 +40,7 @@ public Storage(String filePath) { * start of the programs launch. * @return ArrayList of Task stored in the file if it exist. */ - public ArrayList load() { + public ArrayList load() throws DukeFileException { ArrayList tasks = new ArrayList<>(); int taskCount = 0; try { @@ -54,9 +62,55 @@ public ArrayList load() { } taskCount++; } + System.out.println(" File successfully loaded into TaskList."); return tasks; } catch (FileNotFoundException e) { - return tasks; + throw new DukeFileException(" File does not exist. Launching new TaskList."); + } + } + + /** + * Open the file directory based on the filePath, add Task for storage into hard disk and close file. + * @param filePath File directory path. + * @param taskToAdd Sting containing Task information to store into file. + * @throws IOException If input or output operation failed. + */ + public void writeFileTask(String filePath, String taskToAdd) throws IOException { + FileWriter fileWriter = new FileWriter(filePath); + fileWriter.write(taskToAdd); + fileWriter.close(); + } + + /** + * Convert the tasks in TaskList into a suitable String for saving and pass this String to writeFileTask method + * to write it into an external file for storage. + * @param taskList Task manager that deals with getting and setting Task Object. + * @throws IOException + */ + public void saveTask(TaskList taskList) throws IOException { + Path path = Paths.get(FILE_NAME); + if (!Files.exists(path)) { + Files.createDirectory(path); + } + String taskToAdd = ""; + for (int i = 0; i < taskList.getTaskCount(); i++) { + if (taskList.getTask(i) instanceof Todo) { + Todo todo = (Todo) taskList.getTask(i); + taskToAdd = taskToAdd + "T | " + (todo.getIsDone() ? 1 : 0) + " | "; + taskToAdd = taskToAdd + todo.getDescription(); + } + if (taskList.getTask(i) instanceof Deadline) { + Deadline deadline = (Deadline) taskList.getTask(i); + taskToAdd = taskToAdd + "D | " + (deadline.getIsDone() ? 1 : 0) + " | "; + taskToAdd = taskToAdd + deadline.getDescription() + " | " + deadline.getDate(); + } + if (taskList.getTask(i) instanceof Event) { + Event event = (Event) taskList.getTask(i); + taskToAdd = taskToAdd + "E | " + (event.getIsDone() ? 1 : 0) + " | "; + taskToAdd = taskToAdd + event.getDescription() + " | " + event.getDate(); + } + taskToAdd += "\n"; } + writeFileTask(filePath, taskToAdd); } } diff --git a/src/main/java/duke/TaskList.java b/src/main/java/duke/TaskList.java index c3227bb4bd..8b0a1d6fe3 100644 --- a/src/main/java/duke/TaskList.java +++ b/src/main/java/duke/TaskList.java @@ -12,6 +12,13 @@ public class TaskList { private ArrayList tasks; + /** + * Empty constructor for TaskList. Used when there are no existing Tasks stored yet. + */ + public TaskList() { + this.tasks = new ArrayList<>(); + } + /** * Public constructor for TaskList. * @param tasks ArrayList of Tasks to be stored. diff --git a/src/main/java/duke/Ui.java b/src/main/java/duke/Ui.java index 2cbb44cbd6..c05e1f12fb 100644 --- a/src/main/java/duke/Ui.java +++ b/src/main/java/duke/Ui.java @@ -33,10 +33,17 @@ public String getUserCommand() { * the user can execute. */ public void greetUser() { - System.out.println(" ____________________________________________________________"); + showLine(); System.out.println(" Hello! I'm duke.Duke"); printAvailableCommand(); System.out.println(" What can I do for you?"); + showLine(); + } + + /** + * Print a line to separate the input and output. + */ + public void showLine() { System.out.println(" ____________________________________________________________"); } @@ -49,22 +56,26 @@ public void printAvailableCommand() { System.out.println("| Index | Input | Command |"); System.out.println("|-------+------------------+------------------------------------|"); System.out.println("| 01 | todo j | Add a task(j) without dateline |"); - System.out.println("|-------+------------------+------------------------------------|"); System.out.println("| 02 | deadline j /by d | Add a task(j) with due date d |"); - System.out.println("|-------+------------------+------------------------------------|"); System.out.println("| 03 | event j /at d | Add a task(j) that start at date d |"); - System.out.println("|-------+------------------+------------------------------------|"); System.out.println("| 04 | list | List out all the stored task |"); - System.out.println("|-------+------------------+------------------------------------|"); System.out.println("| 05 | done i | Mark task i as done |"); - System.out.println("|-------+------------------+------------------------------------|"); - System.out.println("| 06 | delete i | Delete task(i) |"); - System.out.println("|-------+------------------+------------------------------------|"); + System.out.println("| 06 | delete i | Delete task i |"); System.out.println("| 07 | find j | Find all task with description j |"); - System.out.println("|-------+------------------+------------------------------------|"); System.out.println("| 08 | help | List out all the commands |"); - System.out.println("|-------+------------------+------------------------------------|"); System.out.println("| 09 | bye | Terminate the program |"); - System.out.println("|---------------------------------------------------------------|"); + System.out.println("|-------+------------------+------------------------------------|"); + System.out.println("| j - refers to String description of Task |"); + System.out.println("| d - refers to date & time of Task in format: YYYY-MM-DD HH:MM |"); + System.out.println("| i - refers to int index of Task |"); + System.out.println("+---------------------------------------------------------------+"); + } + + /** + * Print Error message provided. + * @param errorMessage Error Message. + */ + public void showError(String errorMessage) { + System.out.println(errorMessage); } } diff --git a/src/main/java/duke/command/ByeCommand.java b/src/main/java/duke/command/ByeCommand.java new file mode 100644 index 0000000000..e54a2f3e04 --- /dev/null +++ b/src/main/java/duke/command/ByeCommand.java @@ -0,0 +1,48 @@ +package duke.command; + +import duke.Storage; +import duke.TaskList; +import duke.Ui; +import duke.exception.DukeFileException; + +import java.io.IOException; + +/** + * The ByeCommand class is the Object that store all the Task into the hard disk and exit the program.. + * ByeCommand implement Command interface. + * @author Lam Yue Wei + * @version CS2113 AY19/20 Sem 2 Duke + */ +public class ByeCommand implements Command { + + /** + * Empty constructor for ByeCommand. + */ + public ByeCommand() { + } + + /** + * Executes the bye function to store all the Task into the hard disk and exit the program. + * @param taskList Task Manager in charge of storing the Task required to be done. + * @param ui Ui Object that deals with interaction with the user. + * @param storage Storage Object that deals with the loading and Storing of Tasks. + */ + @Override + public void execute(TaskList taskList, Ui ui, Storage storage) throws DukeFileException { + try { + storage.saveTask(taskList); + } catch (IOException e) { + throw new DukeFileException(" :( OOPS!!! Something went wrong, aborting file save!"); + } + System.out.println(" Bye. Hope to see you again soon!"); + } + + /** + * Boolean result indicate to the program if it should be exited. + * @return True since command keyword matches "bye". + */ + @Override + public boolean isExit() { + return true; + } +} diff --git a/src/main/java/duke/command/Command.java b/src/main/java/duke/command/Command.java index 670237130d..c91e815093 100644 --- a/src/main/java/duke/command/Command.java +++ b/src/main/java/duke/command/Command.java @@ -3,6 +3,7 @@ import duke.Storage; import duke.TaskList; import duke.Ui; +import duke.exception.DukeException; /** * The Command Interface is an Interface that provides the platform for various Command to be executed. @@ -16,5 +17,11 @@ public interface Command { * @param ui Ui Object that deals with interaction with the user. * @param storage Storage Object that deals with the loading and Storing of Tasks. */ - public abstract void execute(TaskList taskList, Ui ui, Storage storage); + public abstract void execute(TaskList taskList, Ui ui, Storage storage) throws DukeException; + + /** + * Abstract method that other Command Object has to override to indicate to the program if it should be exited. + * @return True if user input bye, false otherwise. + */ + public abstract boolean isExit(); } diff --git a/src/main/java/duke/command/DeadlineCommand.java b/src/main/java/duke/command/DeadlineCommand.java index eed9f11752..f2b20d1b88 100644 --- a/src/main/java/duke/command/DeadlineCommand.java +++ b/src/main/java/duke/command/DeadlineCommand.java @@ -3,6 +3,10 @@ import duke.Storage; import duke.TaskList; import duke.Ui; +import duke.task.Deadline; + +import java.time.LocalDate; +import java.time.LocalTime; /** * The DeadlineCommand class is the Object that adds Deadline Object into the TaskList. @@ -12,17 +16,41 @@ */ public class DeadlineCommand implements Command { private String description; + private LocalDate date; + private LocalTime time; /** * Public constructor for DeadlineCommand. * @param description Description of the Task. */ - public DeadlineCommand(String description) { + public DeadlineCommand(String description, LocalDate date, LocalTime time) { this.description = description; + this.date = date; + this.time = time; } + /** + * Executes the Deadline function and add the Deadline Task into the TaskList. + * @param taskList Task Manager in charge of storing the Task required to be done. + * @param ui Ui Object that deals with interaction with the user. + * @param storage Storage Object that deals with the loading and Storing of Tasks. + */ @Override public void execute(TaskList taskList, Ui ui, Storage storage) { - System.out.println("to be completed" + description); + int taskCount = taskList.getTaskCount(); + taskList.addTask(new Deadline(description, date, time)); + System.out.println(" Got it. I've added this task:"); + System.out.println(" " + taskList.getTask(taskCount).toString()); + taskCount++; + System.out.println(" Now you have " + taskCount + " tasks in the list."); + } + + /** + * Boolean result indicate to the program if it should be exited. + * @return False since command keyword does not match "bye". + */ + @Override + public boolean isExit() { + return false; } } diff --git a/src/main/java/duke/command/DeleteCommand.java b/src/main/java/duke/command/DeleteCommand.java index 6845e7bb2f..312e6705fa 100644 --- a/src/main/java/duke/command/DeleteCommand.java +++ b/src/main/java/duke/command/DeleteCommand.java @@ -3,7 +3,6 @@ import duke.Storage; import duke.TaskList; import duke.Ui; -import duke.exception.DukeIndexException; /** * The DeleteCommand class is the Object that delete a Task from the TaskList. @@ -39,4 +38,13 @@ public void execute(TaskList taskList, Ui ui, Storage storage) { System.out.println(" Now you have " + taskList.getTaskCount() + " tasks in the list."); } } + + /** + * Boolean result indicate to the program if it should be exited. + * @return False since command keyword does not match "bye". + */ + @Override + public boolean isExit() { + return false; + } } diff --git a/src/main/java/duke/command/DoneCommand.java b/src/main/java/duke/command/DoneCommand.java index 022ae63e1a..43cb7d30af 100644 --- a/src/main/java/duke/command/DoneCommand.java +++ b/src/main/java/duke/command/DoneCommand.java @@ -37,4 +37,13 @@ public void execute(TaskList taskList, Ui ui, Storage storage) { System.out.println(" " + taskList.getTask(doneIndex).toString()); } } + + /** + * Boolean result indicate to the program if it should be exited. + * @return False since command keyword does not match "bye". + */ + @Override + public boolean isExit() { + return false; + } } diff --git a/src/main/java/duke/command/EventCommand.java b/src/main/java/duke/command/EventCommand.java new file mode 100644 index 0000000000..d725f9dac5 --- /dev/null +++ b/src/main/java/duke/command/EventCommand.java @@ -0,0 +1,57 @@ +package duke.command; + +import duke.Storage; +import duke.TaskList; +import duke.Ui; +import duke.task.Deadline; +import duke.task.Event; + +import java.time.LocalDate; +import java.time.LocalTime; + +/** + * The EventCommand class is the Object that adds Event Object into the TaskList. + * EventCommand implement Command interface. + * @author Lam Yue Wei + * @version CS2113 AY19/20 Sem 2 Duke + */ +public class EventCommand implements Command { + private String description; + private LocalDate date; + private LocalTime time; + + /** + * Public constructor for EventCommand. + * @param description Description of the Task. + */ + public EventCommand(String description, LocalDate date, LocalTime time) { + this.description = description; + this.date = date; + this.time = time; + } + + /** + * Executes the event function and add the Event Task into the TaskList. + * @param taskList Task Manager in charge of storing the Task required to be done. + * @param ui Ui Object that deals with interaction with the user. + * @param storage Storage Object that deals with the loading and Storing of Tasks. + */ + @Override + public void execute(TaskList taskList, Ui ui, Storage storage) { + int taskCount = taskList.getTaskCount(); + taskList.addTask(new Event(description, date, time)); + System.out.println(" Got it. I've added this task:"); + System.out.println(" " + taskList.getTask(taskCount).toString()); + taskCount++; + System.out.println(" Now you have " + taskCount + " tasks in the list."); + } + + /** + * Boolean result indicate to the program if it should be exited. + * @return False since command keyword does not match "bye". + */ + @Override + public boolean isExit() { + return false; + } +} diff --git a/src/main/java/duke/command/FindCommand.java b/src/main/java/duke/command/FindCommand.java index 53cf52c460..a20346d8df 100644 --- a/src/main/java/duke/command/FindCommand.java +++ b/src/main/java/duke/command/FindCommand.java @@ -45,4 +45,13 @@ public void execute(TaskList taskList, Ui ui, Storage storage) { System.out.println(" There is no matching tasks"); } } + + /** + * Boolean result indicate to the program if it should be exited. + * @return False since command keyword does not match "bye". + */ + @Override + public boolean isExit() { + return false; + } } diff --git a/src/main/java/duke/command/HelpCommand.java b/src/main/java/duke/command/HelpCommand.java index 2b191141ab..c449c2d7ee 100644 --- a/src/main/java/duke/command/HelpCommand.java +++ b/src/main/java/duke/command/HelpCommand.java @@ -28,4 +28,13 @@ public HelpCommand() { public void execute(TaskList taskList, Ui ui, Storage storage) { ui.printAvailableCommand(); } + + /** + * Boolean result indicate to the program if it should be exited. + * @return False since command keyword does not match "bye". + */ + @Override + public boolean isExit() { + return false; + } } diff --git a/src/main/java/duke/command/ListCommand.java b/src/main/java/duke/command/ListCommand.java index a9f82fe1e2..6225f5b7ca 100644 --- a/src/main/java/duke/command/ListCommand.java +++ b/src/main/java/duke/command/ListCommand.java @@ -35,4 +35,13 @@ public void execute(TaskList taskList, Ui ui, Storage storage) { } } } + + /** + * Boolean result indicate to the program if it should be exited. + * @return False since command keyword does not match "bye". + */ + @Override + public boolean isExit() { + return false; + } } diff --git a/src/main/java/duke/command/TodoCommand.java b/src/main/java/duke/command/TodoCommand.java index dfe7763528..a8d0716370 100644 --- a/src/main/java/duke/command/TodoCommand.java +++ b/src/main/java/duke/command/TodoCommand.java @@ -37,4 +37,13 @@ public void execute(TaskList taskList, Ui ui, Storage storage) { taskCount++; System.out.println(" Now you have " + taskCount + " tasks in the list."); } + + /** + * Boolean result indicate to the program if it should be exited. + * @return False since command keyword does not match "bye". + */ + @Override + public boolean isExit() { + return false; + } } diff --git a/src/main/java/duke/exception/DukeFileException.java b/src/main/java/duke/exception/DukeFileException.java new file mode 100644 index 0000000000..28709e9f61 --- /dev/null +++ b/src/main/java/duke/exception/DukeFileException.java @@ -0,0 +1,18 @@ +package duke.exception; + +/** + * The DukeFileException class is an Exception that is thrown when there are issue loading or storing database + * from or into the external hard disk. + * DukeFileException class extends from DukeException class. + * @author Lam Yue Wei + * @version CS2113 AY19/20 Sem 2 Duke + */ +public class DukeFileException extends DukeException { + /** + * Public constructor for DukeFileException. + * @param message Error message shown to the user. + */ + public DukeFileException(String message) { + super(message); + } +} diff --git a/src/main/java/duke/task/Deadline.java b/src/main/java/duke/task/Deadline.java index 67472c3ec4..36319328c4 100644 --- a/src/main/java/duke/task/Deadline.java +++ b/src/main/java/duke/task/Deadline.java @@ -29,6 +29,19 @@ public Deadline(String description, String dateTime) { time = LocalTime.parse(dateTime.split(" ")[1]); } + /** + * Public constructor for Deadline using LocalDate and LocalTime. + * @param description Description of the Deadline Task. + * @param date Due date of the Deadline Task. + * @param time Due time of the Deadline Task. + */ + public Deadline(String description, LocalDate date, LocalTime time) { + super(description); + this.date= date; + this.time = time; + this.dateTime = date.toString() + " " + time.toString(); + } + /** * Getter method for the date. * @return Due date. diff --git a/src/main/java/duke/task/Event.java b/src/main/java/duke/task/Event.java index 5647b1b9bc..3c5504728b 100644 --- a/src/main/java/duke/task/Event.java +++ b/src/main/java/duke/task/Event.java @@ -19,7 +19,7 @@ public class Event extends Task { /** * Public constructor for Event. * @param description Description of the Event Task. - * @param dateTime Date of occurrence and time of the Event Task. + * @param dateTime Date and time of occurrence of the Event Task. */ public Event(String description, String dateTime) { super(description); @@ -28,6 +28,19 @@ public Event(String description, String dateTime) { time = LocalTime.parse(dateTime.split(" ")[1]); } + /** + * Public constructor for Event using LocalDate and LocalTime. + * @param description Description of the Event Task. + * @param date Date of occurrence of the Event Task. + * @param time Time of occurrence of the Event Task. + */ + public Event(String description, LocalDate date, LocalTime time) { + super(description); + this.date= date; + this.time = time; + this.dateTime = date.toString() + " " + time.toString(); + } + /** * Getter method for the date of occurrence. * @return Date of occurrence. diff --git a/src/main/java/duke/task/Task.java b/src/main/java/duke/task/Task.java index 5d4d7c16cb..6430e5b450 100644 --- a/src/main/java/duke/task/Task.java +++ b/src/main/java/duke/task/Task.java @@ -27,7 +27,6 @@ public String getStatusIcon() { } // Not immutable version - /** * Mark the task as done by setting isDone to true. */ diff --git a/text-ui-test/ACTUAL.TXT b/text-ui-test/ACTUAL.TXT index 8aab82c1bc..1348f865e8 100644 --- a/text-ui-test/ACTUAL.TXT +++ b/text-ui-test/ACTUAL.TXT @@ -1,3 +1,4 @@ + File does not exist. Launching new TaskList. ____________________________________________________________ Hello! I'm duke.Duke Here is the list of commands that are available: @@ -5,23 +6,19 @@ | Index | Input | Command | |-------+------------------+------------------------------------| | 01 | todo j | Add a task(j) without dateline | -|-------+------------------+------------------------------------| | 02 | deadline j /by d | Add a task(j) with due date d | -|-------+------------------+------------------------------------| | 03 | event j /at d | Add a task(j) that start at date d | -|-------+------------------+------------------------------------| | 04 | list | List out all the stored task | -|-------+------------------+------------------------------------| | 05 | done i | Mark task i as done | -|-------+------------------+------------------------------------| -| 06 | delete i | Delete task(i) | -|-------+------------------+------------------------------------| +| 06 | delete i | Delete task i | | 07 | find j | Find all task with description j | -|-------+------------------+------------------------------------| | 08 | help | List out all the commands | -|-------+------------------+------------------------------------| | 09 | bye | Terminate the program | -|---------------------------------------------------------------| +|-------+------------------+------------------------------------| +| j - refers to String description of Task | +| d - refers to date & time of Task in format: YYYY-MM-DD HH:MM | +| i - refers to int index of Task | ++---------------------------------------------------------------+ What can I do for you? ____________________________________________________________ @@ -165,23 +162,19 @@ | Index | Input | Command | |-------+------------------+------------------------------------| | 01 | todo j | Add a task(j) without dateline | -|-------+------------------+------------------------------------| | 02 | deadline j /by d | Add a task(j) with due date d | -|-------+------------------+------------------------------------| | 03 | event j /at d | Add a task(j) that start at date d | -|-------+------------------+------------------------------------| | 04 | list | List out all the stored task | -|-------+------------------+------------------------------------| | 05 | done i | Mark task i as done | -|-------+------------------+------------------------------------| -| 06 | delete i | Delete task(i) | -|-------+------------------+------------------------------------| +| 06 | delete i | Delete task i | | 07 | find j | Find all task with description j | -|-------+------------------+------------------------------------| | 08 | help | List out all the commands | -|-------+------------------+------------------------------------| | 09 | bye | Terminate the program | -|---------------------------------------------------------------| +|-------+------------------+------------------------------------| +| j - refers to String description of Task | +| d - refers to date & time of Task in format: YYYY-MM-DD HH:MM | +| i - refers to int index of Task | ++---------------------------------------------------------------+ ____________________________________________________________ ____________________________________________________________ @@ -233,7 +226,25 @@ ____________________________________________________________ ____________________________________________________________ - :( OOPS!!! Missing date for deadline. + :( OOPS!!! Missing date and time for deadline. + ____________________________________________________________ + + ____________________________________________________________ + :( OOPS!!! Missing Date or Time for deadline. + ____________________________________________________________ + + ____________________________________________________________ + :( OOPS!!! Please enter a valid date and time + Date and time format: YYYY-MM-DD HH:MM + ____________________________________________________________ + + ____________________________________________________________ + :( OOPS!!! Please enter a valid date and time + Date and time format: YYYY-MM-DD HH:MM + ____________________________________________________________ + + ____________________________________________________________ + :( OOPS!!! Extra arguments found for deadline. ____________________________________________________________ ____________________________________________________________ @@ -241,7 +252,25 @@ ____________________________________________________________ ____________________________________________________________ - :( OOPS!!! Missing date for event. + :( OOPS!!! Missing date and time for event. + ____________________________________________________________ + + ____________________________________________________________ + :( OOPS!!! Missing Date or Time for event. + ____________________________________________________________ + + ____________________________________________________________ + :( OOPS!!! Please enter a valid date and time + Date and time format: YYYY-MM-DD HH:MM + ____________________________________________________________ + + ____________________________________________________________ + :( OOPS!!! Please enter a valid date and time + Date and time format: YYYY-MM-DD HH:MM + ____________________________________________________________ + + ____________________________________________________________ + :( OOPS!!! Extra arguments found for event. ____________________________________________________________ ____________________________________________________________ diff --git a/text-ui-test/EXPECTED.txt b/text-ui-test/EXPECTED.txt index 8aab82c1bc..1348f865e8 100644 --- a/text-ui-test/EXPECTED.txt +++ b/text-ui-test/EXPECTED.txt @@ -1,3 +1,4 @@ + File does not exist. Launching new TaskList. ____________________________________________________________ Hello! I'm duke.Duke Here is the list of commands that are available: @@ -5,23 +6,19 @@ | Index | Input | Command | |-------+------------------+------------------------------------| | 01 | todo j | Add a task(j) without dateline | -|-------+------------------+------------------------------------| | 02 | deadline j /by d | Add a task(j) with due date d | -|-------+------------------+------------------------------------| | 03 | event j /at d | Add a task(j) that start at date d | -|-------+------------------+------------------------------------| | 04 | list | List out all the stored task | -|-------+------------------+------------------------------------| | 05 | done i | Mark task i as done | -|-------+------------------+------------------------------------| -| 06 | delete i | Delete task(i) | -|-------+------------------+------------------------------------| +| 06 | delete i | Delete task i | | 07 | find j | Find all task with description j | -|-------+------------------+------------------------------------| | 08 | help | List out all the commands | -|-------+------------------+------------------------------------| | 09 | bye | Terminate the program | -|---------------------------------------------------------------| +|-------+------------------+------------------------------------| +| j - refers to String description of Task | +| d - refers to date & time of Task in format: YYYY-MM-DD HH:MM | +| i - refers to int index of Task | ++---------------------------------------------------------------+ What can I do for you? ____________________________________________________________ @@ -165,23 +162,19 @@ | Index | Input | Command | |-------+------------------+------------------------------------| | 01 | todo j | Add a task(j) without dateline | -|-------+------------------+------------------------------------| | 02 | deadline j /by d | Add a task(j) with due date d | -|-------+------------------+------------------------------------| | 03 | event j /at d | Add a task(j) that start at date d | -|-------+------------------+------------------------------------| | 04 | list | List out all the stored task | -|-------+------------------+------------------------------------| | 05 | done i | Mark task i as done | -|-------+------------------+------------------------------------| -| 06 | delete i | Delete task(i) | -|-------+------------------+------------------------------------| +| 06 | delete i | Delete task i | | 07 | find j | Find all task with description j | -|-------+------------------+------------------------------------| | 08 | help | List out all the commands | -|-------+------------------+------------------------------------| | 09 | bye | Terminate the program | -|---------------------------------------------------------------| +|-------+------------------+------------------------------------| +| j - refers to String description of Task | +| d - refers to date & time of Task in format: YYYY-MM-DD HH:MM | +| i - refers to int index of Task | ++---------------------------------------------------------------+ ____________________________________________________________ ____________________________________________________________ @@ -233,7 +226,25 @@ ____________________________________________________________ ____________________________________________________________ - :( OOPS!!! Missing date for deadline. + :( OOPS!!! Missing date and time for deadline. + ____________________________________________________________ + + ____________________________________________________________ + :( OOPS!!! Missing Date or Time for deadline. + ____________________________________________________________ + + ____________________________________________________________ + :( OOPS!!! Please enter a valid date and time + Date and time format: YYYY-MM-DD HH:MM + ____________________________________________________________ + + ____________________________________________________________ + :( OOPS!!! Please enter a valid date and time + Date and time format: YYYY-MM-DD HH:MM + ____________________________________________________________ + + ____________________________________________________________ + :( OOPS!!! Extra arguments found for deadline. ____________________________________________________________ ____________________________________________________________ @@ -241,7 +252,25 @@ ____________________________________________________________ ____________________________________________________________ - :( OOPS!!! Missing date for event. + :( OOPS!!! Missing date and time for event. + ____________________________________________________________ + + ____________________________________________________________ + :( OOPS!!! Missing Date or Time for event. + ____________________________________________________________ + + ____________________________________________________________ + :( OOPS!!! Please enter a valid date and time + Date and time format: YYYY-MM-DD HH:MM + ____________________________________________________________ + + ____________________________________________________________ + :( OOPS!!! Please enter a valid date and time + Date and time format: YYYY-MM-DD HH:MM + ____________________________________________________________ + + ____________________________________________________________ + :( OOPS!!! Extra arguments found for event. ____________________________________________________________ ____________________________________________________________ diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index cc42d4d21c..fc950fa6f8 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -33,7 +33,15 @@ bye there todo deadline deadline complete ip coding +deadline ip round 1 /by abc +deadline ip round 2 /by 2020-20-20 16:30 +deadline ip round 3 /by 20-11-22 abc123 +deadline ip round 4 /by 2020-11-22 12:24 to 12:27 event event complete ip coding +event ip round 1 /at abc +event ip round 2 /at 2020-20-20 16:30 +event ip round 3 /at 20-11-22 abc123 +event ip round 4 /at 2020-11-22 12:24 to 12:27 complete everything bye From 2ce54f1a63790857608a0425fa5f6dbfc1ce9803 Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Mon, 16 Mar 2020 20:29:04 +0800 Subject: [PATCH 43/45] Minor edit on javadoc --- docs/README.md | 2 +- src/main/java/duke/Duke.java | 8 +------- src/main/java/duke/Storage.java | 2 +- src/main/java/duke/command/DoneCommand.java | 2 +- src/main/java/duke/command/EventCommand.java | 1 - src/main/java/duke/task/Todo.java | 2 +- 6 files changed, 5 insertions(+), 12 deletions(-) diff --git a/docs/README.md b/docs/README.md index dee3a9b13a..6a768b3999 100644 --- a/docs/README.md +++ b/docs/README.md @@ -57,7 +57,7 @@ Command: Terminate the program and automatically help you store the Task into yo | Index | Input | Command | | ----- | ----- | --------------- | | 01 | todo description | Add a todo task with description | -| 02 | dateline description /by YYYY-MM-DD HH:MM | Add a deadline task description and due date | +| 02 | deadline description /by YYYY-MM-DD HH:MM | Add a deadline task description and due date | | 03 | event description /at YYYY-MM-DD HH:MM | Add a event task description and due date | | 04 | list | List out all the stored task | | 05 | done index | Mark task index as done | diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index c9dfe801bd..41aa297fa3 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,13 +1,7 @@ package duke; import duke.command.Command; -import duke.exception.*; -import duke.task.*; - -import java.time.format.DateTimeParseException; -import java.util.ArrayList; -import java.io.FileNotFoundException; -import java.io.IOException; +import duke.exception.DukeException; import static duke.Constant.FILE_PATH; diff --git a/src/main/java/duke/Storage.java b/src/main/java/duke/Storage.java index d79fb0f45a..5ce27bcada 100644 --- a/src/main/java/duke/Storage.java +++ b/src/main/java/duke/Storage.java @@ -85,7 +85,7 @@ public void writeFileTask(String filePath, String taskToAdd) throws IOException * Convert the tasks in TaskList into a suitable String for saving and pass this String to writeFileTask method * to write it into an external file for storage. * @param taskList Task manager that deals with getting and setting Task Object. - * @throws IOException + * @throws IOException If input or output operation failed. */ public void saveTask(TaskList taskList) throws IOException { Path path = Paths.get(FILE_NAME); diff --git a/src/main/java/duke/command/DoneCommand.java b/src/main/java/duke/command/DoneCommand.java index 43cb7d30af..1e9a035f6e 100644 --- a/src/main/java/duke/command/DoneCommand.java +++ b/src/main/java/duke/command/DoneCommand.java @@ -32,7 +32,7 @@ public void execute(TaskList taskList, Ui ui, Storage storage) { if (doneIndex >= taskList.getTaskCount() || doneIndex < 0) { System.out.println(" :( OOPS!!! Invalid index for done."); } else { - taskList.getTask(doneIndex).markAsDone(); + taskList.doneTask(doneIndex); System.out.println(" Nice! I've marked this task as done:"); System.out.println(" " + taskList.getTask(doneIndex).toString()); } diff --git a/src/main/java/duke/command/EventCommand.java b/src/main/java/duke/command/EventCommand.java index d725f9dac5..707efb7faa 100644 --- a/src/main/java/duke/command/EventCommand.java +++ b/src/main/java/duke/command/EventCommand.java @@ -3,7 +3,6 @@ import duke.Storage; import duke.TaskList; import duke.Ui; -import duke.task.Deadline; import duke.task.Event; import java.time.LocalDate; diff --git a/src/main/java/duke/task/Todo.java b/src/main/java/duke/task/Todo.java index 97f8019685..54039bff73 100644 --- a/src/main/java/duke/task/Todo.java +++ b/src/main/java/duke/task/Todo.java @@ -8,7 +8,7 @@ */ public class Todo extends Task { /** - * Public constructor for Task. + * Public constructor for Todo. * @param description Description of the Task. */ public Todo(String description) { From 5df548e82410733212c98ef221fa5955a6837444 Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Mon, 16 Mar 2020 21:14:36 +0800 Subject: [PATCH 44/45] Bug Fix on Storage, add exception in Parser --- src/main/java/duke/Parser.java | 6 ++++++ src/main/java/duke/Storage.java | 10 +++++++--- src/main/java/duke/Ui.java | 2 +- src/main/java/duke/task/Deadline.java | 8 ++++++++ src/main/java/duke/task/Event.java | 8 ++++++++ text-ui-test/ACTUAL.TXT | 8 ++++++++ text-ui-test/EXPECTED.txt | 8 ++++++++ text-ui-test/input.txt | 2 ++ 8 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java index 512a250212..207258adbc 100644 --- a/src/main/java/duke/Parser.java +++ b/src/main/java/duke/Parser.java @@ -179,6 +179,9 @@ public DeadlineCommand parseDeadlineCommand(String userCommand) throws DukeArgum if (!userCommand.contains(DEADLINE_COMMAND_DELIMITER)) { throw new DukeArgumentException(" :( OOPS!!! Missing date and time for deadline."); } + if (getDescription(userCommand, DEADLINE_COMMAND_DELIMITER).length() == 0) { + throw new DukeArgumentException(" :( OOPS!!! Missing description for deadline."); + } String description = getDescription(userCommand, DEADLINE_COMMAND_DELIMITER); LocalDate date = getDate(userCommand, DEADLINE_COMMAND_DELIMITER); @@ -201,6 +204,9 @@ public EventCommand parseEventCommand(String userCommand) throws DukeArgumentExc if (!userCommand.contains(EVENT_COMMAND_DELIMITER)) { throw new DukeArgumentException(" :( OOPS!!! Missing date and time for event."); } + if (getDescription(userCommand, EVENT_COMMAND_DELIMITER).length() == 0) { + throw new DukeArgumentException(" :( OOPS!!! Missing description for event."); + } String description = getDescription(userCommand, EVENT_COMMAND_DELIMITER); LocalDate date = getDate(userCommand, EVENT_COMMAND_DELIMITER); diff --git a/src/main/java/duke/Storage.java b/src/main/java/duke/Storage.java index 5ce27bcada..eee445901d 100644 --- a/src/main/java/duke/Storage.java +++ b/src/main/java/duke/Storage.java @@ -1,5 +1,6 @@ package duke; +import duke.exception.DukeDateTimeException; import duke.exception.DukeFileException; import duke.task.Deadline; import duke.task.Event; @@ -13,6 +14,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.time.format.DateTimeParseException; import java.util.ArrayList; import java.util.Scanner; @@ -40,7 +42,7 @@ public Storage(String filePath) { * start of the programs launch. * @return ArrayList of Task stored in the file if it exist. */ - public ArrayList load() throws DukeFileException { + public ArrayList load() throws DukeFileException, DukeDateTimeException { ArrayList tasks = new ArrayList<>(); int taskCount = 0; try { @@ -66,6 +68,8 @@ public ArrayList load() throws DukeFileException { return tasks; } catch (FileNotFoundException e) { throw new DukeFileException(" File does not exist. Launching new TaskList."); + } catch (DateTimeParseException e) { + throw new DukeDateTimeException(" Error loading Date/Time. Launching new TaskList."); } } @@ -102,12 +106,12 @@ public void saveTask(TaskList taskList) throws IOException { if (taskList.getTask(i) instanceof Deadline) { Deadline deadline = (Deadline) taskList.getTask(i); taskToAdd = taskToAdd + "D | " + (deadline.getIsDone() ? 1 : 0) + " | "; - taskToAdd = taskToAdd + deadline.getDescription() + " | " + deadline.getDate(); + taskToAdd = taskToAdd + deadline.getDescription() + " | " + deadline.getDateTime(); } if (taskList.getTask(i) instanceof Event) { Event event = (Event) taskList.getTask(i); taskToAdd = taskToAdd + "E | " + (event.getIsDone() ? 1 : 0) + " | "; - taskToAdd = taskToAdd + event.getDescription() + " | " + event.getDate(); + taskToAdd = taskToAdd + event.getDescription() + " | " + event.getDateTime(); } taskToAdd += "\n"; } diff --git a/src/main/java/duke/Ui.java b/src/main/java/duke/Ui.java index c05e1f12fb..8770944a10 100644 --- a/src/main/java/duke/Ui.java +++ b/src/main/java/duke/Ui.java @@ -23,7 +23,7 @@ public Ui() { public String getUserCommand() { String userCommand; System.out.println(); - userCommand = sc.nextLine(); + userCommand = sc.nextLine().strip(); System.out.println(" ____________________________________________________________"); return userCommand; } diff --git a/src/main/java/duke/task/Deadline.java b/src/main/java/duke/task/Deadline.java index 36319328c4..bd33520239 100644 --- a/src/main/java/duke/task/Deadline.java +++ b/src/main/java/duke/task/Deadline.java @@ -58,6 +58,14 @@ public String getTime() { return this.time.toString(); } + /** + * Getter method for String representation of the date and time. + * @return String representation of the date and time + */ + public String getDateTime() { + return this.dateTime; + } + /** * Return a String representation of this Deadline. * @return The Deadline's icon, followed by the Task's toString, followed by the due date and time. diff --git a/src/main/java/duke/task/Event.java b/src/main/java/duke/task/Event.java index 3c5504728b..a750d06663 100644 --- a/src/main/java/duke/task/Event.java +++ b/src/main/java/duke/task/Event.java @@ -57,6 +57,14 @@ public String getTime() { return this.time.toString(); } + /** + * Getter method for String representation of the date and time. + * @return String representation of the date and time + */ + public String getDateTime() { + return this.dateTime; + } + /** * Return a String representation of this Event. * @return The Event's icon, followed by the Task's toString, followed by the date and time of occurrence. diff --git a/text-ui-test/ACTUAL.TXT b/text-ui-test/ACTUAL.TXT index 1348f865e8..7af7c5b575 100644 --- a/text-ui-test/ACTUAL.TXT +++ b/text-ui-test/ACTUAL.TXT @@ -247,6 +247,10 @@ :( OOPS!!! Extra arguments found for deadline. ____________________________________________________________ + ____________________________________________________________ + :( OOPS!!! Missing description for deadline. + ____________________________________________________________ + ____________________________________________________________ :( OOPS!!! Missing description for event. ____________________________________________________________ @@ -273,6 +277,10 @@ :( OOPS!!! Extra arguments found for event. ____________________________________________________________ + ____________________________________________________________ + :( OOPS!!! Missing description for event. + ____________________________________________________________ + ____________________________________________________________ :( OOPS!!! Command does not exist. To view the list of commands available use the command: help diff --git a/text-ui-test/EXPECTED.txt b/text-ui-test/EXPECTED.txt index 1348f865e8..7af7c5b575 100644 --- a/text-ui-test/EXPECTED.txt +++ b/text-ui-test/EXPECTED.txt @@ -247,6 +247,10 @@ :( OOPS!!! Extra arguments found for deadline. ____________________________________________________________ + ____________________________________________________________ + :( OOPS!!! Missing description for deadline. + ____________________________________________________________ + ____________________________________________________________ :( OOPS!!! Missing description for event. ____________________________________________________________ @@ -273,6 +277,10 @@ :( OOPS!!! Extra arguments found for event. ____________________________________________________________ + ____________________________________________________________ + :( OOPS!!! Missing description for event. + ____________________________________________________________ + ____________________________________________________________ :( OOPS!!! Command does not exist. To view the list of commands available use the command: help diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index fc950fa6f8..4c0e75dd86 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -37,11 +37,13 @@ deadline ip round 1 /by abc deadline ip round 2 /by 2020-20-20 16:30 deadline ip round 3 /by 20-11-22 abc123 deadline ip round 4 /by 2020-11-22 12:24 to 12:27 +deadline /by 2020-11-22 12:34 event event complete ip coding event ip round 1 /at abc event ip round 2 /at 2020-20-20 16:30 event ip round 3 /at 20-11-22 abc123 event ip round 4 /at 2020-11-22 12:24 to 12:27 +event /at 2020-11-22 12:34 complete everything bye From c182a6aed48ad6a9a946bfb490c7dcbc266a22e1 Mon Sep 17 00:00:00 2001 From: lamyuewei Date: Mon, 16 Mar 2020 21:52:53 +0800 Subject: [PATCH 45/45] Package Storage, Ui, Parser, Constant, TaskList Object --- src/main/java/duke/Duke.java | 6 +++++- src/main/java/duke/command/ByeCommand.java | 6 +++--- src/main/java/duke/command/Command.java | 6 +++--- src/main/java/duke/command/DeadlineCommand.java | 6 +++--- src/main/java/duke/command/DeleteCommand.java | 6 +++--- src/main/java/duke/command/DoneCommand.java | 6 +++--- src/main/java/duke/command/EventCommand.java | 6 +++--- src/main/java/duke/command/FindCommand.java | 6 +++--- src/main/java/duke/command/HelpCommand.java | 6 +++--- src/main/java/duke/command/ListCommand.java | 6 +++--- src/main/java/duke/command/TodoCommand.java | 6 +++--- src/main/java/duke/{ => constant}/Constant.java | 2 +- src/main/java/duke/{ => data}/TaskList.java | 2 +- src/main/java/duke/{ => parser}/Parser.java | 4 ++-- src/main/java/duke/{ => storage}/Storage.java | 5 +++-- src/main/java/duke/{ => ui}/Ui.java | 2 +- text-ui-test/runtest.bat | 3 ++- 17 files changed, 45 insertions(+), 39 deletions(-) rename src/main/java/duke/{ => constant}/Constant.java (98%) rename src/main/java/duke/{ => data}/TaskList.java (98%) rename src/main/java/duke/{ => parser}/Parser.java (99%) rename src/main/java/duke/{ => storage}/Storage.java (98%) rename src/main/java/duke/{ => ui}/Ui.java (99%) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 41aa297fa3..a22c905662 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,9 +1,13 @@ package duke; import duke.command.Command; +import duke.data.TaskList; import duke.exception.DukeException; +import duke.parser.Parser; +import duke.storage.Storage; +import duke.ui.Ui; -import static duke.Constant.FILE_PATH; +import static duke.constant.Constant.FILE_PATH; /** * Duke is a chatbot that manages Task for user. diff --git a/src/main/java/duke/command/ByeCommand.java b/src/main/java/duke/command/ByeCommand.java index e54a2f3e04..c0f851cf53 100644 --- a/src/main/java/duke/command/ByeCommand.java +++ b/src/main/java/duke/command/ByeCommand.java @@ -1,8 +1,8 @@ package duke.command; -import duke.Storage; -import duke.TaskList; -import duke.Ui; +import duke.storage.Storage; +import duke.data.TaskList; +import duke.ui.Ui; import duke.exception.DukeFileException; import java.io.IOException; diff --git a/src/main/java/duke/command/Command.java b/src/main/java/duke/command/Command.java index c91e815093..0d5d075523 100644 --- a/src/main/java/duke/command/Command.java +++ b/src/main/java/duke/command/Command.java @@ -1,8 +1,8 @@ package duke.command; -import duke.Storage; -import duke.TaskList; -import duke.Ui; +import duke.storage.Storage; +import duke.data.TaskList; +import duke.ui.Ui; import duke.exception.DukeException; /** diff --git a/src/main/java/duke/command/DeadlineCommand.java b/src/main/java/duke/command/DeadlineCommand.java index f2b20d1b88..790eaec06c 100644 --- a/src/main/java/duke/command/DeadlineCommand.java +++ b/src/main/java/duke/command/DeadlineCommand.java @@ -1,8 +1,8 @@ package duke.command; -import duke.Storage; -import duke.TaskList; -import duke.Ui; +import duke.storage.Storage; +import duke.data.TaskList; +import duke.ui.Ui; import duke.task.Deadline; import java.time.LocalDate; diff --git a/src/main/java/duke/command/DeleteCommand.java b/src/main/java/duke/command/DeleteCommand.java index 312e6705fa..888b527639 100644 --- a/src/main/java/duke/command/DeleteCommand.java +++ b/src/main/java/duke/command/DeleteCommand.java @@ -1,8 +1,8 @@ package duke.command; -import duke.Storage; -import duke.TaskList; -import duke.Ui; +import duke.storage.Storage; +import duke.data.TaskList; +import duke.ui.Ui; /** * The DeleteCommand class is the Object that delete a Task from the TaskList. diff --git a/src/main/java/duke/command/DoneCommand.java b/src/main/java/duke/command/DoneCommand.java index 1e9a035f6e..9cb3cd8ca3 100644 --- a/src/main/java/duke/command/DoneCommand.java +++ b/src/main/java/duke/command/DoneCommand.java @@ -1,8 +1,8 @@ package duke.command; -import duke.Storage; -import duke.TaskList; -import duke.Ui; +import duke.storage.Storage; +import duke.data.TaskList; +import duke.ui.Ui; /** * The DoneCommand class is the Object that mark a Task in the TaskList as completed. diff --git a/src/main/java/duke/command/EventCommand.java b/src/main/java/duke/command/EventCommand.java index 707efb7faa..d10e739bba 100644 --- a/src/main/java/duke/command/EventCommand.java +++ b/src/main/java/duke/command/EventCommand.java @@ -1,8 +1,8 @@ package duke.command; -import duke.Storage; -import duke.TaskList; -import duke.Ui; +import duke.storage.Storage; +import duke.data.TaskList; +import duke.ui.Ui; import duke.task.Event; import java.time.LocalDate; diff --git a/src/main/java/duke/command/FindCommand.java b/src/main/java/duke/command/FindCommand.java index a20346d8df..0f653be438 100644 --- a/src/main/java/duke/command/FindCommand.java +++ b/src/main/java/duke/command/FindCommand.java @@ -1,8 +1,8 @@ package duke.command; -import duke.Storage; -import duke.TaskList; -import duke.Ui; +import duke.storage.Storage; +import duke.data.TaskList; +import duke.ui.Ui; /** * The FindCommand class is the Object that find all Task with description that matches a keyword or phrase. diff --git a/src/main/java/duke/command/HelpCommand.java b/src/main/java/duke/command/HelpCommand.java index c449c2d7ee..f2d82833f3 100644 --- a/src/main/java/duke/command/HelpCommand.java +++ b/src/main/java/duke/command/HelpCommand.java @@ -1,8 +1,8 @@ package duke.command; -import duke.Storage; -import duke.TaskList; -import duke.Ui; +import duke.storage.Storage; +import duke.data.TaskList; +import duke.ui.Ui; /** * The HelpCommand class is the Object that provides the user with help by showing the list of available commands. diff --git a/src/main/java/duke/command/ListCommand.java b/src/main/java/duke/command/ListCommand.java index 6225f5b7ca..b3c75b0cb0 100644 --- a/src/main/java/duke/command/ListCommand.java +++ b/src/main/java/duke/command/ListCommand.java @@ -1,8 +1,8 @@ package duke.command; -import duke.Storage; -import duke.TaskList; -import duke.Ui; +import duke.storage.Storage; +import duke.data.TaskList; +import duke.ui.Ui; /** * The ListCommand class is the Object that provides the user with the list of Tasks stored. diff --git a/src/main/java/duke/command/TodoCommand.java b/src/main/java/duke/command/TodoCommand.java index a8d0716370..5873ea6a39 100644 --- a/src/main/java/duke/command/TodoCommand.java +++ b/src/main/java/duke/command/TodoCommand.java @@ -1,8 +1,8 @@ package duke.command; -import duke.Storage; -import duke.TaskList; -import duke.Ui; +import duke.storage.Storage; +import duke.data.TaskList; +import duke.ui.Ui; import duke.task.Todo; /** diff --git a/src/main/java/duke/Constant.java b/src/main/java/duke/constant/Constant.java similarity index 98% rename from src/main/java/duke/Constant.java rename to src/main/java/duke/constant/Constant.java index f3f573691a..b724c5eef7 100644 --- a/src/main/java/duke/Constant.java +++ b/src/main/java/duke/constant/Constant.java @@ -1,4 +1,4 @@ -package duke; +package duke.constant; /** * The Constant class is the class that keeps a record of all the constants used across all Duke package. diff --git a/src/main/java/duke/TaskList.java b/src/main/java/duke/data/TaskList.java similarity index 98% rename from src/main/java/duke/TaskList.java rename to src/main/java/duke/data/TaskList.java index 8b0a1d6fe3..3a74211edd 100644 --- a/src/main/java/duke/TaskList.java +++ b/src/main/java/duke/data/TaskList.java @@ -1,4 +1,4 @@ -package duke; +package duke.data; import duke.task.Task; diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/parser/Parser.java similarity index 99% rename from src/main/java/duke/Parser.java rename to src/main/java/duke/parser/Parser.java index 207258adbc..f4f527f2e3 100644 --- a/src/main/java/duke/Parser.java +++ b/src/main/java/duke/parser/Parser.java @@ -1,4 +1,4 @@ -package duke; +package duke.parser; import duke.command.*; import duke.exception.DukeArgumentException; @@ -10,7 +10,7 @@ import java.time.LocalTime; import java.time.format.DateTimeParseException; -import static duke.Constant.*; +import static duke.constant.Constant.*; /** * The Parser class is in charged of parsing user input into a Command Object. diff --git a/src/main/java/duke/Storage.java b/src/main/java/duke/storage/Storage.java similarity index 98% rename from src/main/java/duke/Storage.java rename to src/main/java/duke/storage/Storage.java index eee445901d..97c441acf5 100644 --- a/src/main/java/duke/Storage.java +++ b/src/main/java/duke/storage/Storage.java @@ -1,5 +1,6 @@ -package duke; +package duke.storage; +import duke.data.TaskList; import duke.exception.DukeDateTimeException; import duke.exception.DukeFileException; import duke.task.Deadline; @@ -18,7 +19,7 @@ import java.util.ArrayList; import java.util.Scanner; -import static duke.Constant.FILE_NAME; +import static duke.constant.Constant.FILE_NAME; /** * The Storage class is the class handles the loading of Task from a specified filePath and diff --git a/src/main/java/duke/Ui.java b/src/main/java/duke/ui/Ui.java similarity index 99% rename from src/main/java/duke/Ui.java rename to src/main/java/duke/ui/Ui.java index 8770944a10..955f18f9eb 100644 --- a/src/main/java/duke/Ui.java +++ b/src/main/java/duke/ui/Ui.java @@ -1,4 +1,4 @@ -package duke; +package duke.ui; import java.util.Scanner; diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 55719d2dc6..e6bb97d5e2 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -7,7 +7,8 @@ REM delete output from previous run del ACTUAL.TXT REM compile the code into the bin folder -javac -cp ..\src -Xlint:none -d ..\bin ..\src\main\java\duke\*.java ..\src\main\java\duke\task\*.java ..\src\main\java\duke\exception\*.java ..\src\main\java\duke\command\*.java +javac -cp ..\src -Xlint:none -d ..\bin ..\src\main\java\duke\*.java ..\src\main\java\duke\command\*.java ..\src\main\java\duke\constant\*.java ..\src\main\java\duke\data\*.java ..\src\main\java\duke\exception\*.java ..\src\main\java\duke\parser\*.java ..\src\main\java\duke\storage\*.java ..\src\main\java\duke\task\*.java ..\src\main\java\duke\ui\*.java + IF ERRORLEVEL 1 ( echo ********** BUILD FAILURE ********** exit /b 1