From fff13bd5b7c985c6249935ecc044ab964e615e9c Mon Sep 17 00:00:00 2001 From: NgYJ02 <91600220+NgYJ02@users.noreply.github.com> Date: Fri, 27 Jan 2023 10:31:08 +0800 Subject: [PATCH 01/27] Level 1. Greet, Echo, Exit --- src/main/java/Duke.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5d313334c..4815e8156 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,3 +1,5 @@ +import java.util.Scanner; + public class Duke { public static void main(String[] args) { String logo = " ____ _ \n" @@ -6,5 +8,15 @@ public static void main(String[] args) { + "| |_| | |_| | < __/\n" + "|____/ \\__,_|_|\\_\\___|\n"; System.out.println("Hello from\n" + logo); + System.out.println("Hello! I'm Duke"); + System.out.println("What can I do for you?\n"); + Scanner scan = new Scanner(System.in); + String input=scan.nextLine(); + while (!input.equals("bye")) { + System.out.println(input); + input = scan.nextLine(); + } + System.out.println("Bye. Hope to see you again soon!"); + } } From d5c0add196d5ed6e3939325ecd942c6a69295fa6 Mon Sep 17 00:00:00 2001 From: NgYJ02 <91600220+NgYJ02@users.noreply.github.com> Date: Fri, 27 Jan 2023 10:33:11 +0800 Subject: [PATCH 02/27] Level 1. Greet, Echo, Exit --- src/main/java/Duke.class | Bin 0 -> 1409 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/main/java/Duke.class diff --git a/src/main/java/Duke.class b/src/main/java/Duke.class new file mode 100644 index 0000000000000000000000000000000000000000..2b142ac5edfe89702c80cb453126a650cd70cc03 GIT binary patch literal 1409 zcmaJ>>uwWA6#mA6tg|dQI9x($VA6(QhmeJqYn_G?(=-MLkc@%~kyaCDNEWYm%)gZIWa#qMzK@eTS&c6cX6d7QTU zelB+n%xtHq?#%fjS$VGAF}_{C;d%2O9c_4|c^!KUHV#;D92~@_CSML4D4|PpPQZ!3>Dt6q#VdNQ(H$_91Rah7Lp|5vHi?s-K%rIN%8mHxxr5|pW zii2A=j^L<;V-AjEl3`*muY8zNPpR74f!8ZrB!1F&s{VCE5?%8bLxC8DhADY5c^H@lCvM3{=8a@|6J_Q7Nml2V)7gAg|ptBANC^BS2`H!ypp=3Bx7{Wpp=ZN#owzP2`3l>}l7jUuvW>N~N zgXFVB1VnHj72WQ8sf!GYpL6h(d#|n=JudTSwaImIDy|E@*J-l60NmQ3BzA+v%&KC^9RK>DV zI@XbBtx3J3w&L6x{(Hc# z(^U~}1u~wgD%D6@rNNZk*RGyj6XRv2*W{19mY%dj3RDo+SAJQ-8n3>38^fZGIQC z`MF)pzrr}d%#r}F|Nmrcej(LF%%l-#DHf$c5p42%fd1$XPSeXXheH%Shcb1*9ZcXi oLOIBM#+-%o7N#c2qLg}B#P1}tl Date: Fri, 27 Jan 2023 10:49:19 +0800 Subject: [PATCH 03/27] Level 2. Add, List --- src/main/java/Duke.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 4815e8156..d3fea70b7 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,3 +1,4 @@ +import java.util.ArrayList; import java.util.Scanner; public class Duke { @@ -10,10 +11,20 @@ public static void main(String[] args) { System.out.println("Hello from\n" + logo); System.out.println("Hello! I'm Duke"); System.out.println("What can I do for you?\n"); + ArrayList inputList = new ArrayList(); Scanner scan = new Scanner(System.in); - String input=scan.nextLine(); + String input = scan.nextLine(); while (!input.equals("bye")) { - System.out.println(input); + if (input.equals("list")) { + int a = 1; + for (String i : inputList) { + System.out.println(a + ". " + i); + a++; + } + } else { + System.out.println("added: " + input); + inputList.add(input); + } input = scan.nextLine(); } System.out.println("Bye. Hope to see you again soon!"); From 6b160da8b8af04f394366d12bfe26a0559f9794f Mon Sep 17 00:00:00 2001 From: NgYJ02 <91600220+NgYJ02@users.noreply.github.com> Date: Fri, 27 Jan 2023 11:06:46 +0800 Subject: [PATCH 04/27] Level 2 --- src/main/java/Duke.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index d3fea70b7..fd1eec54f 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -11,19 +11,19 @@ public static void main(String[] args) { System.out.println("Hello from\n" + logo); System.out.println("Hello! I'm Duke"); System.out.println("What can I do for you?\n"); - ArrayList inputList = new ArrayList(); + ArrayList inputs = new ArrayList(); Scanner scan = new Scanner(System.in); String input = scan.nextLine(); while (!input.equals("bye")) { if (input.equals("list")) { int a = 1; - for (String i : inputList) { + for (String i : inputs) { System.out.println(a + ". " + i); a++; } } else { System.out.println("added: " + input); - inputList.add(input); + inputs.add(input); } input = scan.nextLine(); } From ef4b3fb580a9045d29f7dc100f702580fef68a56 Mon Sep 17 00:00:00 2001 From: NgYJ02 <91600220+NgYJ02@users.noreply.github.com> Date: Sun, 29 Jan 2023 15:15:27 +0800 Subject: [PATCH 05/27] Level 3. Mark as Done --- src/main/java/Duke.java | 33 ++++++++++++++++++++++++--------- src/main/java/Task.java | 26 ++++++++++++++++++++++++++ 2 files changed, 50 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 fd1eec54f..a69ee72a9 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -11,23 +11,38 @@ public static void main(String[] args) { System.out.println("Hello from\n" + logo); System.out.println("Hello! I'm Duke"); System.out.println("What can I do for you?\n"); - ArrayList inputs = new ArrayList(); + ArrayList tasks = new ArrayList(); Scanner scan = new Scanner(System.in); - String input = scan.nextLine(); - while (!input.equals("bye")) { - if (input.equals("list")) { + String desc = scan.nextLine(); + while (!desc.equals("bye")) { + if (desc.equals("list")) { int a = 1; - for (String i : inputs) { - System.out.println(a + ". " + i); + System.out.println("Here are the tasks in the list:"); + for (Task i : tasks) { + System.out.println(a + ". [" + i.getStatusIcon() + "] " + i.getDescription()); a++; } + } else if (desc.matches("mark [0-9]{1,2}")) { + String[] marks = desc.split(" "); + tasks.get(Integer.parseInt(marks[1]) - 1).markAsDone(); + System.out.println("Nice! I've marked this task as done:"); + System.out.println("[" + tasks.get(Integer.parseInt(marks[1]) - 1).getStatusIcon() + "] " + + tasks.get(Integer.parseInt(marks[1]) - 1).getDescription()); + } else if (desc.matches("unmark [0-9]{1,2}")) { + String[] marks = desc.split(" "); + tasks.get(Integer.parseInt(marks[1]) - 1).markAsNotDone(); + System.out.println("OK, I've marked this task as not done yet:"); + System.out.println("[" + tasks.get(Integer.parseInt(marks[1]) - 1).getStatusIcon() + "] " + + tasks.get(Integer.parseInt(marks[1]) - 1).getDescription()); } else { - System.out.println("added: " + input); - inputs.add(input); + Task task = new Task(desc); + System.out.println("added: " + desc); + tasks.add(task); } - input = scan.nextLine(); + desc = scan.nextLine(); } System.out.println("Bye. Hope to see you again soon!"); } + } diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 000000000..70159ec98 --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,26 @@ +public class Task { + protected String description; + protected boolean isDone; + + public Task(String description) { + this.description = description; + this.isDone = false; + } + + public String getDescription() { + return description; + } + + public String getStatusIcon() { + return (isDone ? "X" : " "); + } + + public void markAsDone() { + isDone=true; + } + + public void markAsNotDone() { + isDone = false; + } + +} \ No newline at end of file From 443d336566b1766b5bb54e30b4312d0fc68bea7e Mon Sep 17 00:00:00 2001 From: NgYJ02 <91600220+NgYJ02@users.noreply.github.com> Date: Thu, 2 Feb 2023 11:23:30 +0800 Subject: [PATCH 06/27] Level 4. ToDos, Events, Deadlines --- src/main/java/Deadline.java | 14 ++++++++++++ src/main/java/Duke.java | 45 ++++++++++++++++++++++++++++++------- src/main/java/Event.java | 15 +++++++++++++ src/main/java/Task.java | 23 ++++++++++++++++++- src/main/java/Todo.java | 10 +++++++++ 5 files changed, 98 insertions(+), 9 deletions(-) create mode 100644 src/main/java/Deadline.java create mode 100644 src/main/java/Event.java create mode 100644 src/main/java/Todo.java diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java new file mode 100644 index 000000000..caf76614e --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,14 @@ +public class Deadline extends Task { + protected String deadlineDay; + + public Deadline(String description, String deadlineDay) { + super(description); + this.deadlineDay=deadlineDay; + } + + @Override + public String toString(){ + return "[D]"+super.toString()+" (by: "+this.deadlineDay+")"; + } + +} diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index a69ee72a9..0e0f2317a 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -14,31 +14,60 @@ public static void main(String[] args) { ArrayList tasks = new ArrayList(); Scanner scan = new Scanner(System.in); String desc = scan.nextLine(); + String output = new String(); while (!desc.equals("bye")) { if (desc.equals("list")) { int a = 1; + output="Here are the tasks in the list:"+System.lineSeparator()+Task.printTasksList(tasks); System.out.println("Here are the tasks in the list:"); for (Task i : tasks) { - System.out.println(a + ". [" + i.getStatusIcon() + "] " + i.getDescription()); + System.out.println(a + ". " + i.toString()); a++; } } else if (desc.matches("mark [0-9]{1,2}")) { String[] marks = desc.split(" "); tasks.get(Integer.parseInt(marks[1]) - 1).markAsDone(); - System.out.println("Nice! I've marked this task as done:"); - System.out.println("[" + tasks.get(Integer.parseInt(marks[1]) - 1).getStatusIcon() + "] " + - tasks.get(Integer.parseInt(marks[1]) - 1).getDescription()); + output = "Nice! I've marked this task as done:" + System.lineSeparator() + + tasks.get(Integer.parseInt(marks[1]) - 1).toString(); } else if (desc.matches("unmark [0-9]{1,2}")) { String[] marks = desc.split(" "); tasks.get(Integer.parseInt(marks[1]) - 1).markAsNotDone(); - System.out.println("OK, I've marked this task as not done yet:"); - System.out.println("[" + tasks.get(Integer.parseInt(marks[1]) - 1).getStatusIcon() + "] " + - tasks.get(Integer.parseInt(marks[1]) - 1).getDescription()); + output = "OK, I've marked this task as not done yet:" + System.lineSeparator() + + tasks.get(Integer.parseInt(marks[1]) - 1).toString(); + } else if (desc.startsWith("todo", 0)) { + String toDoDesc = desc.split("todo")[1].trim(); + Task toDo = new Todo(toDoDesc); + tasks.add(toDo); + output = "Got it. I've added this task:" + System.lineSeparator() + + toDo.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks + + " in the list."; + } else if (desc.startsWith("deadline", 0)) { + String deadlineDesc = desc.split("/")[0].split("deadline")[1].trim(); + String deadlineDay = desc.split("/")[1].trim(); + Task deadline = new Deadline(deadlineDesc, deadlineDay); + tasks.add(deadline); + output = "Got it. I've added this task:" + System.lineSeparator() + + deadline.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks + + " in the list."; + } else if (desc.startsWith("event", 0)) { + String eventDesc = desc.split("/")[0].split("event")[1].trim(); + String start = desc.split("/")[1].trim(); + String end = desc.split("/")[2].trim(); + Task event = new Event(eventDesc, start, end); + tasks.add(event); + output = "Got it. I've added this task:" + System.lineSeparator() + + event.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks + + " in the list."; } else { Task task = new Task(desc); - System.out.println("added: " + desc); tasks.add(task); + output = "Got it. I've added this task:" + System.lineSeparator() + + task.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks + + " in the list."; } + System.out.println("____________________________________________________"); + System.out.println(output); + System.out.println("____________________________________________________"); desc = scan.nextLine(); } System.out.println("Bye. Hope to see you again soon!"); diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 000000000..2631e66b4 --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,15 @@ +public class Event extends Task { + protected String start; + protected String end; + + public Event(String description, String start, String end){ + super(description); + this.start=start; + this.end=end; + } + + @Override + public String toString(){ + return "[E]"+super.toString()+" (from: "+start+" to: "+end+")"; + } +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 70159ec98..99b4308c2 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -1,10 +1,27 @@ +import java.util.ArrayList; + public class Task { protected String description; protected boolean isDone; + static int numberOfTasks = 0; public Task(String description) { this.description = description; this.isDone = false; + numberOfTasks++; + } + + public static String printTasksList(ArrayList tasks) { + String tasksList = new String(); + int count = 1; + for (Task i : tasks) { + tasksList += count + ". " + i.toString(); + if (count < numberOfTasks) { + tasksList += System.lineSeparator(); + } + count++; + } + return tasksList; } public String getDescription() { @@ -16,11 +33,15 @@ public String getStatusIcon() { } public void markAsDone() { - isDone=true; + isDone = true; } public void markAsNotDone() { isDone = false; } + public String toString() { + return "[" + this.getStatusIcon() + "]" + "\t" + this.getDescription(); + } + } \ No newline at end of file diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java new file mode 100644 index 000000000..cca26ad9e --- /dev/null +++ b/src/main/java/Todo.java @@ -0,0 +1,10 @@ +public class Todo extends Task{ + public Todo (String description){ + super(description); + } + + @Override + public String toString(){ + return "[T]"+super.toString(); + } +} From 49f3394f968c04cedf0e6031bec86f8cedb4683a Mon Sep 17 00:00:00 2001 From: NgYJ02 <91600220+NgYJ02@users.noreply.github.com> Date: Thu, 2 Feb 2023 11:31:48 +0800 Subject: [PATCH 07/27] A-CodingStandard --- src/main/java/Duke.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 0e0f2317a..0b7230e69 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -65,9 +65,9 @@ public static void main(String[] args) { + task.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks + " in the list."; } - System.out.println("____________________________________________________"); + System.out.println("___________________________________________________"); System.out.println(output); - System.out.println("____________________________________________________"); + System.out.println("___________________________________________________"); desc = scan.nextLine(); } System.out.println("Bye. Hope to see you again soon!"); From 03e770e9bda521fd2748713fb1bdf608e2fded2b Mon Sep 17 00:00:00 2001 From: NgYJ02 <91600220+NgYJ02@users.noreply.github.com> Date: Thu, 2 Feb 2023 12:08:55 +0800 Subject: [PATCH 08/27] A-CodeQuality --- src/main/java/Deadline.java | 2 +- src/main/java/Duke.java | 109 ++++++++++++++++++------------------ src/main/java/Event.java | 2 +- 3 files changed, 56 insertions(+), 57 deletions(-) diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index caf76614e..3ad042345 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -8,7 +8,7 @@ public Deadline(String description, String deadlineDay) { @Override public String toString(){ - return "[D]"+super.toString()+" (by: "+this.deadlineDay+")"; + return "[D]"+super.toString()+" ("+this.deadlineDay+")"; } } diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 0b7230e69..abf246841 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -12,63 +12,62 @@ public static void main(String[] args) { System.out.println("Hello! I'm Duke"); System.out.println("What can I do for you?\n"); ArrayList tasks = new ArrayList(); - Scanner scan = new Scanner(System.in); - String desc = scan.nextLine(); - String output = new String(); - while (!desc.equals("bye")) { - if (desc.equals("list")) { - int a = 1; - output="Here are the tasks in the list:"+System.lineSeparator()+Task.printTasksList(tasks); - System.out.println("Here are the tasks in the list:"); - for (Task i : tasks) { - System.out.println(a + ". " + i.toString()); - a++; + try (Scanner scan = new Scanner(System.in)) { + String input = scan.nextLine(); + String output = new String(); + while (!input.equals("bye")) { + if (input.equals("list")) { + output = "Here are the tasks in the list:" + System.lineSeparator() + Task.printTasksList(tasks); + + } else if (input.matches("mark [0-9]{1,2}")) { + String[] marks = input.split(" "); + tasks.get(Integer.parseInt(marks[1]) - 1).markAsDone(); + output = "Nice! I've marked this task as done:" + System.lineSeparator() + + tasks.get(Integer.parseInt(marks[1]) - 1).toString(); + } else if (input.matches("unmark [0-9]{1,2}")) { + String[] marks = input.split(" "); + tasks.get(Integer.parseInt(marks[1]) - 1).markAsNotDone(); + output = "OK, I've marked this task as not done yet:" + System.lineSeparator() + + tasks.get(Integer.parseInt(marks[1]) - 1).toString(); + } else if (input.startsWith("todo", 0)) { + String toDoDesc = input.split("todo")[1].trim(); + Task toDo = new Todo(toDoDesc); + tasks.add(toDo); + output = "Got it. I've added this task:" + System.lineSeparator() + + toDo.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks + + " in the list."; + } else if (input.startsWith("deadline", 0)) { + String deadlineDesc = input.split("/")[0].split("deadline")[1].trim(); + String deadlineDay = input.split("/")[1].trim(); + Task deadline = new Deadline(deadlineDesc, deadlineDay); + tasks.add(deadline); + output = "Got it. I've added this task:" + System.lineSeparator() + + deadline.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks + + " in the list."; + } else if (input.startsWith("event", 0)) { + String eventDesc = input.split("/")[0].split("event")[1].trim(); + String start = input.split("/")[1].trim(); + String end = input.split("/")[2].trim(); + Task event = new Event(eventDesc, start, end); + tasks.add(event); + output = "Got it. I've added this task:" + System.lineSeparator() + + event.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks + + " in the list."; + } else { + Task task = new Task(input); + tasks.add(task); + output = "Got it. I've added this task:" + System.lineSeparator() + + task.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks + + " in the list."; } - } else if (desc.matches("mark [0-9]{1,2}")) { - String[] marks = desc.split(" "); - tasks.get(Integer.parseInt(marks[1]) - 1).markAsDone(); - output = "Nice! I've marked this task as done:" + System.lineSeparator() - + tasks.get(Integer.parseInt(marks[1]) - 1).toString(); - } else if (desc.matches("unmark [0-9]{1,2}")) { - String[] marks = desc.split(" "); - tasks.get(Integer.parseInt(marks[1]) - 1).markAsNotDone(); - output = "OK, I've marked this task as not done yet:" + System.lineSeparator() - + tasks.get(Integer.parseInt(marks[1]) - 1).toString(); - } else if (desc.startsWith("todo", 0)) { - String toDoDesc = desc.split("todo")[1].trim(); - Task toDo = new Todo(toDoDesc); - tasks.add(toDo); - output = "Got it. I've added this task:" + System.lineSeparator() - + toDo.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks - + " in the list."; - } else if (desc.startsWith("deadline", 0)) { - String deadlineDesc = desc.split("/")[0].split("deadline")[1].trim(); - String deadlineDay = desc.split("/")[1].trim(); - Task deadline = new Deadline(deadlineDesc, deadlineDay); - tasks.add(deadline); - output = "Got it. I've added this task:" + System.lineSeparator() - + deadline.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks - + " in the list."; - } else if (desc.startsWith("event", 0)) { - String eventDesc = desc.split("/")[0].split("event")[1].trim(); - String start = desc.split("/")[1].trim(); - String end = desc.split("/")[2].trim(); - Task event = new Event(eventDesc, start, end); - tasks.add(event); - output = "Got it. I've added this task:" + System.lineSeparator() - + event.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks - + " in the list."; - } else { - Task task = new Task(desc); - tasks.add(task); - output = "Got it. I've added this task:" + System.lineSeparator() - + task.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks - + " in the list."; + System.out.println("___________________________________________________"); + System.out.println(output); + System.out.println("___________________________________________________"); + input = scan.nextLine(); } - System.out.println("___________________________________________________"); - System.out.println(output); - System.out.println("___________________________________________________"); - desc = scan.nextLine(); + } catch (NumberFormatException e) { + // TODO Auto-generated catch block + e.printStackTrace(); } System.out.println("Bye. Hope to see you again soon!"); diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 2631e66b4..6b29c0826 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -10,6 +10,6 @@ public Event(String description, String start, String end){ @Override public String toString(){ - return "[E]"+super.toString()+" (from: "+start+" to: "+end+")"; + return "[E]"+super.toString()+" ("+start+" "+end+")"; } } From c010346b7c2608e5fbfbb865095db7d166401a1c Mon Sep 17 00:00:00 2001 From: NgYJ02 <91600220+NgYJ02@users.noreply.github.com> Date: Wed, 8 Feb 2023 00:51:59 +0800 Subject: [PATCH 09/27] A-Exception --- src/main/java/DukeException.java | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/main/java/DukeException.java diff --git a/src/main/java/DukeException.java b/src/main/java/DukeException.java new file mode 100644 index 000000000..44fab4de1 --- /dev/null +++ b/src/main/java/DukeException.java @@ -0,0 +1,5 @@ +public class DukeException extends Exception { + public DukeException (String message){ + super(message); + } +} From caa5969043e5d38f6aaf233975b89b1026218639 Mon Sep 17 00:00:00 2001 From: NgYJ02 <91600220+NgYJ02@users.noreply.github.com> Date: Wed, 8 Feb 2023 00:57:09 +0800 Subject: [PATCH 10/27] Level 5. Handle Errors --- src/main/java/Duke.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index abf246841..fcc6ae90a 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -2,7 +2,7 @@ import java.util.Scanner; public class Duke { - public static void main(String[] args) { + public static void main(String[] args) throws DukeException { String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" + "| | | | | | | |/ / _ \\\n" @@ -16,15 +16,16 @@ public static void main(String[] args) { String input = scan.nextLine(); String output = new String(); while (!input.equals("bye")) { - if (input.equals("list")) { + try{ + if (input.equals("list")) { output = "Here are the tasks in the list:" + System.lineSeparator() + Task.printTasksList(tasks); - } else if (input.matches("mark [0-9]{1,2}")) { + } else if (input.startsWith("mark")) { String[] marks = input.split(" "); tasks.get(Integer.parseInt(marks[1]) - 1).markAsDone(); output = "Nice! I've marked this task as done:" + System.lineSeparator() + tasks.get(Integer.parseInt(marks[1]) - 1).toString(); - } else if (input.matches("unmark [0-9]{1,2}")) { + } else if (input.startsWith("unmark")) { String[] marks = input.split(" "); tasks.get(Integer.parseInt(marks[1]) - 1).markAsNotDone(); output = "OK, I've marked this task as not done yet:" + System.lineSeparator() @@ -54,12 +55,12 @@ public static void main(String[] args) { + event.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks + " in the list."; } else { - Task task = new Task(input); - tasks.add(task); - output = "Got it. I've added this task:" + System.lineSeparator() - + task.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks - + " in the list."; + output = "OOPS!!! I'm sorry, but I don't know what that means :-("; + }} catch (ArrayIndexOutOfBoundsException e) + { + output="Please provide the necessary information for the task."; } + System.out.println("___________________________________________________"); System.out.println(output); System.out.println("___________________________________________________"); From 06d3da3a74a7798e5967711c77c47219a2480f78 Mon Sep 17 00:00:00 2001 From: NgYJ02 <91600220+NgYJ02@users.noreply.github.com> Date: Wed, 8 Feb 2023 01:16:11 +0800 Subject: [PATCH 11/27] Organize into packages --- src/main/java/Duke.java | 6 ++++++ src/main/java/{ => Exception}/DukeException.java | 2 ++ src/main/java/{ => Task}/Deadline.java | 2 ++ src/main/java/{ => Task}/Event.java | 2 ++ src/main/java/{ => Task}/Task.java | 4 +++- src/main/java/{ => Task}/Todo.java | 2 ++ 6 files changed, 17 insertions(+), 1 deletion(-) rename src/main/java/{ => Exception}/DukeException.java (85%) rename src/main/java/{ => Task}/Deadline.java (95%) rename src/main/java/{ => Task}/Event.java (95%) rename src/main/java/{ => Task}/Task.java (94%) rename src/main/java/{ => Task}/Todo.java (92%) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index fcc6ae90a..e81b2b489 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,6 +1,12 @@ import java.util.ArrayList; import java.util.Scanner; +import Exception.DukeException; +import Task.Deadline; +import Task.Event; +import Task.Task; +import Task.Todo; + public class Duke { public static void main(String[] args) throws DukeException { String logo = " ____ _ \n" diff --git a/src/main/java/DukeException.java b/src/main/java/Exception/DukeException.java similarity index 85% rename from src/main/java/DukeException.java rename to src/main/java/Exception/DukeException.java index 44fab4de1..a52b51828 100644 --- a/src/main/java/DukeException.java +++ b/src/main/java/Exception/DukeException.java @@ -1,3 +1,5 @@ +package Exception; + public class DukeException extends Exception { public DukeException (String message){ super(message); diff --git a/src/main/java/Deadline.java b/src/main/java/Task/Deadline.java similarity index 95% rename from src/main/java/Deadline.java rename to src/main/java/Task/Deadline.java index 3ad042345..4df609574 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Task/Deadline.java @@ -1,3 +1,5 @@ +package Task; + public class Deadline extends Task { protected String deadlineDay; diff --git a/src/main/java/Event.java b/src/main/java/Task/Event.java similarity index 95% rename from src/main/java/Event.java rename to src/main/java/Task/Event.java index 6b29c0826..443cd84e9 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Task/Event.java @@ -1,3 +1,5 @@ +package Task; + public class Event extends Task { protected String start; protected String end; diff --git a/src/main/java/Task.java b/src/main/java/Task/Task.java similarity index 94% rename from src/main/java/Task.java rename to src/main/java/Task/Task.java index 99b4308c2..01e14d411 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task/Task.java @@ -1,9 +1,11 @@ +package Task; + import java.util.ArrayList; public class Task { protected String description; protected boolean isDone; - static int numberOfTasks = 0; + public static int numberOfTasks = 0; public Task(String description) { this.description = description; diff --git a/src/main/java/Todo.java b/src/main/java/Task/Todo.java similarity index 92% rename from src/main/java/Todo.java rename to src/main/java/Task/Todo.java index cca26ad9e..e2c54d76a 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/Task/Todo.java @@ -1,3 +1,5 @@ +package Task; + public class Todo extends Task{ public Todo (String description){ super(description); From 161d9d3161afbaf3f4df07e77551e6477dbb66b6 Mon Sep 17 00:00:00 2001 From: NgYJ02 <91600220+NgYJ02@users.noreply.github.com> Date: Wed, 15 Feb 2023 15:57:18 +0800 Subject: [PATCH 12/27] Level 6 --- src/main/java/Duke.java | 90 ++++++++++++++++++++---------------- src/main/java/Task/Task.java | 4 ++ 2 files changed, 53 insertions(+), 41 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index e81b2b489..67c54d055 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -22,49 +22,57 @@ public static void main(String[] args) throws DukeException { String input = scan.nextLine(); String output = new String(); while (!input.equals("bye")) { - try{ + try { if (input.equals("list")) { - output = "Here are the tasks in the list:" + System.lineSeparator() + Task.printTasksList(tasks); + output = "Here are the tasks in the list:" + System.lineSeparator() + + Task.printTasksList(tasks); - } else if (input.startsWith("mark")) { - String[] marks = input.split(" "); - tasks.get(Integer.parseInt(marks[1]) - 1).markAsDone(); - output = "Nice! I've marked this task as done:" + System.lineSeparator() - + tasks.get(Integer.parseInt(marks[1]) - 1).toString(); - } else if (input.startsWith("unmark")) { - String[] marks = input.split(" "); - tasks.get(Integer.parseInt(marks[1]) - 1).markAsNotDone(); - output = "OK, I've marked this task as not done yet:" + System.lineSeparator() - + tasks.get(Integer.parseInt(marks[1]) - 1).toString(); - } else if (input.startsWith("todo", 0)) { - String toDoDesc = input.split("todo")[1].trim(); - Task toDo = new Todo(toDoDesc); - tasks.add(toDo); - output = "Got it. I've added this task:" + System.lineSeparator() - + toDo.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks - + " in the list."; - } else if (input.startsWith("deadline", 0)) { - String deadlineDesc = input.split("/")[0].split("deadline")[1].trim(); - String deadlineDay = input.split("/")[1].trim(); - Task deadline = new Deadline(deadlineDesc, deadlineDay); - tasks.add(deadline); - output = "Got it. I've added this task:" + System.lineSeparator() - + deadline.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks - + " in the list."; - } else if (input.startsWith("event", 0)) { - String eventDesc = input.split("/")[0].split("event")[1].trim(); - String start = input.split("/")[1].trim(); - String end = input.split("/")[2].trim(); - Task event = new Event(eventDesc, start, end); - tasks.add(event); - output = "Got it. I've added this task:" + System.lineSeparator() - + event.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks - + " in the list."; - } else { - output = "OOPS!!! I'm sorry, but I don't know what that means :-("; - }} catch (ArrayIndexOutOfBoundsException e) - { - output="Please provide the necessary information for the task."; + } else if (input.startsWith("mark")) { + String[] marks = input.split(" "); + tasks.get(Integer.parseInt(marks[1]) - 1).markAsDone(); + output = "Nice! I've marked this task as done:" + System.lineSeparator() + + tasks.get(Integer.parseInt(marks[1]) - 1).toString(); + } else if (input.startsWith("unmark")) { + String[] marks = input.split(" "); + tasks.get(Integer.parseInt(marks[1]) - 1).markAsNotDone(); + output = "OK, I've marked this task as not done yet:" + System.lineSeparator() + + tasks.get(Integer.parseInt(marks[1]) - 1).toString(); + } else if (input.startsWith("todo", 0)) { + String toDoDesc = input.split("todo")[1].trim(); + Task toDo = new Todo(toDoDesc); + tasks.add(toDo); + output = "Got it. I've added this task:" + System.lineSeparator() + + toDo.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks + + " in the list."; + } else if (input.startsWith("deadline", 0)) { + String deadlineDesc = input.split("/")[0].split("deadline")[1].trim(); + String deadlineDay = input.split("/")[1].trim(); + Task deadline = new Deadline(deadlineDesc, deadlineDay); + tasks.add(deadline); + output = "Got it. I've added this task:" + System.lineSeparator() + + deadline.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks + + " in the list."; + } else if (input.startsWith("event", 0)) { + String eventDesc = input.split("/")[0].split("event")[1].trim(); + String start = input.split("/")[1].trim(); + String end = input.split("/")[2].trim(); + Task event = new Event(eventDesc, start, end); + tasks.add(event); + output = "Got it. I've added this task:" + System.lineSeparator() + + event.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks + + " in the list."; + } else if (input.startsWith("delete")) { + int toDelete = Integer.parseInt(input.split(" ")[1]); + output = "Noted. I've removed this task:" + System.lineSeparator() + + tasks.get(toDelete - 1).toString(); + tasks.remove(toDelete - 1); + Task.decrementNumberOfTasks(); + output += System.lineSeparator() + "Now you have " + Task.numberOfTasks + " tasks in the list."; + } else { + output = "OOPS!!! I'm sorry, but I don't know what that means :-("; + } + } catch (ArrayIndexOutOfBoundsException e) { + output = "Please provide the necessary information for the task."; } System.out.println("___________________________________________________"); diff --git a/src/main/java/Task/Task.java b/src/main/java/Task/Task.java index 01e14d411..c521106b3 100644 --- a/src/main/java/Task/Task.java +++ b/src/main/java/Task/Task.java @@ -13,6 +13,10 @@ public Task(String description) { numberOfTasks++; } + public static void decrementNumberOfTasks() { + numberOfTasks--; + } + public static String printTasksList(ArrayList tasks) { String tasksList = new String(); int count = 1; From 16726496168d0ce3f83fe1375b1be945c7794dd8 Mon Sep 17 00:00:00 2001 From: NgYJ02 <91600220+NgYJ02@users.noreply.github.com> Date: Wed, 15 Feb 2023 16:01:21 +0800 Subject: [PATCH 13/27] A-Collections --- src/main/java/Duke.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 67c54d055..23f4a55e1 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -17,7 +17,7 @@ public static void main(String[] args) throws DukeException { System.out.println("Hello from\n" + logo); System.out.println("Hello! I'm Duke"); System.out.println("What can I do for you?\n"); - ArrayList tasks = new ArrayList(); + ArrayList tasks = new ArrayList();// using ArrayList to store tasks instead of array try (Scanner scan = new Scanner(System.in)) { String input = scan.nextLine(); String output = new String(); From 89262489692a223ca98a39169a1ee4d4e1f01dd6 Mon Sep 17 00:00:00 2001 From: NgYJ02 <91600220+NgYJ02@users.noreply.github.com> Date: Sun, 19 Feb 2023 11:10:07 +0800 Subject: [PATCH 14/27] Level-7 --- src/main/java/Duke.java | 8 +++- src/main/java/DukeStorage.java | 65 ++++++++++++++++++++++++++++++++ src/main/java/Task/Deadline.java | 20 ++++++++++ src/main/java/Task/Event.java | 27 +++++++++++-- src/main/java/Task/Task.java | 12 +++++- src/main/java/Task/Todo.java | 16 ++++++++ 6 files changed, 142 insertions(+), 6 deletions(-) create mode 100644 src/main/java/DukeStorage.java diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 23f4a55e1..ded3500bf 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,3 +1,4 @@ +import java.io.IOException; import java.util.ArrayList; import java.util.Scanner; @@ -8,7 +9,7 @@ import Task.Todo; public class Duke { - public static void main(String[] args) throws DukeException { + public static void main(String[] args) throws DukeException, IOException { String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" + "| | | | | | | |/ / _ \\\n" @@ -17,7 +18,9 @@ public static void main(String[] args) throws DukeException { System.out.println("Hello from\n" + logo); System.out.println("Hello! I'm Duke"); System.out.println("What can I do for you?\n"); - ArrayList tasks = new ArrayList();// using ArrayList to store tasks instead of array + DukeStorage storage = new DukeStorage("data/duke.txt"); + + ArrayList tasks = storage.loadTaskList(); try (Scanner scan = new Scanner(System.in)) { String input = scan.nextLine(); String output = new String(); @@ -85,6 +88,7 @@ public static void main(String[] args) throws DukeException { e.printStackTrace(); } System.out.println("Bye. Hope to see you again soon!"); + storage.saveTaskList(tasks); } diff --git a/src/main/java/DukeStorage.java b/src/main/java/DukeStorage.java new file mode 100644 index 000000000..edc732d84 --- /dev/null +++ b/src/main/java/DukeStorage.java @@ -0,0 +1,65 @@ +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.Scanner; + +import Task.Task; +import Task.Deadline; +import Task.Todo; +import Task.Event; + +public class DukeStorage { + private static String filePath; + + public DukeStorage(String filePath) { + this.filePath = filePath; + } + + public void saveTaskList(ArrayList tasks) { + try { + File file = new File(filePath); + if (!file.exists()) { + file.getParentFile().mkdirs(); + file.createNewFile(); + } + FileWriter writer = new FileWriter(file); + for (Task task : tasks) { + writer.write(task.toFileString() + "\n"); + } + writer.close(); + } catch (IOException e) { + System.out.println("Error saving file: " + e.getMessage()); + } + } + + public static ArrayList loadTaskList() throws IOException { + ArrayList tasks = new ArrayList<>(); + Task.numberOfTasks=0; + try { + File file = new File(filePath); + if (!file.exists()) { + file.getParentFile().mkdirs(); + file.createNewFile(); + } + Scanner scanner = new Scanner(file); + while (scanner.hasNext()) { + String line = scanner.nextLine(); + Task task = new Task(null); + if (line.startsWith("T")) { + task = Todo.fromFileString(line); + } else if (line.startsWith("D")) { + task = Deadline.fromFileString(line); + } else if (line.startsWith("E")) { + task = Event.fromFileString(line); + } + tasks.add(task); + } + scanner.close(); + } catch (FileNotFoundException e) { + System.out.println("Error loading file: " + e.getMessage()); + } + return tasks; + } +} diff --git a/src/main/java/Task/Deadline.java b/src/main/java/Task/Deadline.java index 4df609574..60740059c 100644 --- a/src/main/java/Task/Deadline.java +++ b/src/main/java/Task/Deadline.java @@ -1,5 +1,6 @@ package Task; + public class Deadline extends Task { protected String deadlineDay; @@ -8,9 +9,28 @@ public Deadline(String description, String deadlineDay) { this.deadlineDay=deadlineDay; } + public Deadline(String description, String deadlineDay, boolean isDone){ + super(description, isDone); + this.deadlineDay=deadlineDay; + } + @Override public String toString(){ return "[D]"+super.toString()+" ("+this.deadlineDay+")"; } + @Override + public String toFileString() { + return "D | " + (isDone ? 1 : 0) + " | " + description + " | " + + deadlineDay; + } + + public static Deadline fromFileString(String line) { + String[] parts = line.split(" \\| "); + boolean isDone = Integer.parseInt(parts[1]) == 1; + String description = parts[2]; + String deadlineDay = parts[3]; + return new Deadline(description, deadlineDay, isDone); + } + } diff --git a/src/main/java/Task/Event.java b/src/main/java/Task/Event.java index 443cd84e9..6e8923efb 100644 --- a/src/main/java/Task/Event.java +++ b/src/main/java/Task/Event.java @@ -4,14 +4,35 @@ public class Event extends Task { protected String start; protected String end; - public Event(String description, String start, String end){ + public Event(String description, String start, String end) { super(description); + this.start = start; + this.end = end; + } + + public Event(String description, String start, String end, boolean isDone){ + super(description, isDone); this.start=start; this.end=end; } @Override - public String toString(){ - return "[E]"+super.toString()+" ("+start+" "+end+")"; + public String toString() { + return "[E]" + super.toString() + " (" + start + " " + end + ")"; + } + + @Override + public String toFileString() { + return "E | " + (isDone ? 1 : 0) + " | " + description + " | " + + start + " | " + end; + } + + public static Event fromFileString(String line) { + String[] parts = line.split(" \\| "); + boolean isDone = Integer.parseInt(parts[1]) == 1; + String description = parts[2]; + String start = parts[3]; + String end=parts[4]; + return new Event(description, start, end, isDone); } } diff --git a/src/main/java/Task/Task.java b/src/main/java/Task/Task.java index c521106b3..32744375b 100644 --- a/src/main/java/Task/Task.java +++ b/src/main/java/Task/Task.java @@ -5,7 +5,7 @@ public class Task { protected String description; protected boolean isDone; - public static int numberOfTasks = 0; + public static int numberOfTasks=0; public Task(String description) { this.description = description; @@ -13,6 +13,12 @@ public Task(String description) { numberOfTasks++; } + public Task(String description, boolean isDone) { + this.description = description; + this.isDone = isDone; + numberOfTasks++; + } + public static void decrementNumberOfTasks() { numberOfTasks--; } @@ -50,4 +56,8 @@ public String toString() { return "[" + this.getStatusIcon() + "]" + "\t" + this.getDescription(); } + public String toFileString() { + return "Task"; + } + } \ No newline at end of file diff --git a/src/main/java/Task/Todo.java b/src/main/java/Task/Todo.java index e2c54d76a..316f26316 100644 --- a/src/main/java/Task/Todo.java +++ b/src/main/java/Task/Todo.java @@ -5,8 +5,24 @@ public Todo (String description){ super(description); } + public Todo (String description, boolean isDone){ + super(description, isDone); + } + @Override public String toString(){ return "[T]"+super.toString(); } + + @Override + public String toFileString() { + return "T | " + (isDone ? 1 : 0) + " | " + description; + } + + public static Todo fromFileString(String line) { + String[] parts = line.split(" \\| "); + boolean isDone = Integer.parseInt(parts[1]) == 1; + String description = parts[2]; + return new Todo(description, isDone); + } } From 2657473b2fcd086883eb458ff3d362ba725215c7 Mon Sep 17 00:00:00 2001 From: NgYJ02 <91600220+NgYJ02@users.noreply.github.com> Date: Sun, 19 Feb 2023 11:14:26 +0800 Subject: [PATCH 15/27] undo Level-7 --- src/main/java/Duke.java | 2 +- src/main/java/DukeStorage.java | 65 ---------------------------------- 2 files changed, 1 insertion(+), 66 deletions(-) delete mode 100644 src/main/java/DukeStorage.java diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index ded3500bf..499dfe3a4 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -88,7 +88,7 @@ public static void main(String[] args) throws DukeException, IOException { e.printStackTrace(); } System.out.println("Bye. Hope to see you again soon!"); - storage.saveTaskList(tasks); + } diff --git a/src/main/java/DukeStorage.java b/src/main/java/DukeStorage.java deleted file mode 100644 index edc732d84..000000000 --- a/src/main/java/DukeStorage.java +++ /dev/null @@ -1,65 +0,0 @@ -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.FileNotFoundException; -import java.util.ArrayList; -import java.util.Scanner; - -import Task.Task; -import Task.Deadline; -import Task.Todo; -import Task.Event; - -public class DukeStorage { - private static String filePath; - - public DukeStorage(String filePath) { - this.filePath = filePath; - } - - public void saveTaskList(ArrayList tasks) { - try { - File file = new File(filePath); - if (!file.exists()) { - file.getParentFile().mkdirs(); - file.createNewFile(); - } - FileWriter writer = new FileWriter(file); - for (Task task : tasks) { - writer.write(task.toFileString() + "\n"); - } - writer.close(); - } catch (IOException e) { - System.out.println("Error saving file: " + e.getMessage()); - } - } - - public static ArrayList loadTaskList() throws IOException { - ArrayList tasks = new ArrayList<>(); - Task.numberOfTasks=0; - try { - File file = new File(filePath); - if (!file.exists()) { - file.getParentFile().mkdirs(); - file.createNewFile(); - } - Scanner scanner = new Scanner(file); - while (scanner.hasNext()) { - String line = scanner.nextLine(); - Task task = new Task(null); - if (line.startsWith("T")) { - task = Todo.fromFileString(line); - } else if (line.startsWith("D")) { - task = Deadline.fromFileString(line); - } else if (line.startsWith("E")) { - task = Event.fromFileString(line); - } - tasks.add(task); - } - scanner.close(); - } catch (FileNotFoundException e) { - System.out.println("Error loading file: " + e.getMessage()); - } - return tasks; - } -} From a31c6c2173ebed83e119f7322871d4d4eb2a867f Mon Sep 17 00:00:00 2001 From: NgYJ02 <91600220+NgYJ02@users.noreply.github.com> Date: Sun, 19 Feb 2023 11:36:54 +0800 Subject: [PATCH 16/27] branch-Level-7 --- src/main/java/Duke.java | 2 +- src/main/java/DukeStorage.java | 65 ++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 src/main/java/DukeStorage.java diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 499dfe3a4..ded3500bf 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -88,7 +88,7 @@ public static void main(String[] args) throws DukeException, IOException { e.printStackTrace(); } System.out.println("Bye. Hope to see you again soon!"); - + storage.saveTaskList(tasks); } diff --git a/src/main/java/DukeStorage.java b/src/main/java/DukeStorage.java new file mode 100644 index 000000000..f649a8775 --- /dev/null +++ b/src/main/java/DukeStorage.java @@ -0,0 +1,65 @@ +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.Scanner; + +import Task.Task; +import Task.Deadline; +import Task.Todo; +import Task.Event; + +public class DukeStorage { + private static String filePath; + + public DukeStorage(String filePath) { + this.filePath = filePath; + } + + public void saveTaskList(ArrayList tasks) { + try { + File file = new File(filePath); + if (!file.exists()) { + file.getParentFile().mkdirs(); + file.createNewFile(); + } + FileWriter writer = new FileWriter(file); + for (Task task : tasks) { + writer.write(task.toFileString() + "\n"); + } + writer.close(); + } catch (IOException e) { + System.out.println("Error saving file: " + e.getMessage()); + } + } + + public static ArrayList loadTaskList() throws IOException { + ArrayList tasks = new ArrayList<>(); + Task.numberOfTasks = 0; + try { + File file = new File(filePath); + if (!file.exists()) { + file.getParentFile().mkdirs(); + file.createNewFile(); + } + Scanner scanner = new Scanner(file); + while (scanner.hasNext()) { + String line = scanner.nextLine(); + Task task = new Task(null); + if (line.startsWith("T")) { + task = Todo.fromFileString(line); + } else if (line.startsWith("D")) { + task = Deadline.fromFileString(line); + } else if (line.startsWith("E")) { + task = Event.fromFileString(line); + } + tasks.add(task); + } + scanner.close(); + } catch (FileNotFoundException e) { + System.out.println("Error loading file: " + e.getMessage()); + } + return tasks; + } +} From 9f407e0fa0612d3a34f0167bc7b6ab5e01d5e994 Mon Sep 17 00:00:00 2001 From: NgYJ02 <91600220+NgYJ02@users.noreply.github.com> Date: Sun, 19 Feb 2023 11:39:11 +0800 Subject: [PATCH 17/27] Level-7 --- src/main/java/DukeStorage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/DukeStorage.java b/src/main/java/DukeStorage.java index f649a8775..a2b711340 100644 --- a/src/main/java/DukeStorage.java +++ b/src/main/java/DukeStorage.java @@ -14,7 +14,7 @@ public class DukeStorage { private static String filePath; public DukeStorage(String filePath) { - this.filePath = filePath; + DukeStorage.filePath = filePath; } public void saveTaskList(ArrayList tasks) { From cd97e4c431fdeb90f1cb74390e98eda9ad5ae6e4 Mon Sep 17 00:00:00 2001 From: NgYJ02 <91600220+NgYJ02@users.noreply.github.com> Date: Fri, 3 Mar 2023 19:03:33 +0800 Subject: [PATCH 18/27] NumberOfTask debug --- src/main/java/Duke.java | 2 +- src/main/java/DukeStorage.java | 12 ++++++------ src/main/java/Task/Task.java | 6 +++++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index ded3500bf..a44d54c07 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -19,7 +19,7 @@ public static void main(String[] args) throws DukeException, IOException { System.out.println("Hello! I'm Duke"); System.out.println("What can I do for you?\n"); DukeStorage storage = new DukeStorage("data/duke.txt"); - + Task.numberOfTasks = 0; ArrayList tasks = storage.loadTaskList(); try (Scanner scan = new Scanner(System.in)) { String input = scan.nextLine(); diff --git a/src/main/java/DukeStorage.java b/src/main/java/DukeStorage.java index a2b711340..b89651ac9 100644 --- a/src/main/java/DukeStorage.java +++ b/src/main/java/DukeStorage.java @@ -36,7 +36,6 @@ public void saveTaskList(ArrayList tasks) { public static ArrayList loadTaskList() throws IOException { ArrayList tasks = new ArrayList<>(); - Task.numberOfTasks = 0; try { File file = new File(filePath); if (!file.exists()) { @@ -46,15 +45,16 @@ public static ArrayList loadTaskList() throws IOException { Scanner scanner = new Scanner(file); while (scanner.hasNext()) { String line = scanner.nextLine(); - Task task = new Task(null); if (line.startsWith("T")) { - task = Todo.fromFileString(line); + Task task = Todo.fromFileString(line); + tasks.add(task); } else if (line.startsWith("D")) { - task = Deadline.fromFileString(line); + Task task = Deadline.fromFileString(line); + tasks.add(task); } else if (line.startsWith("E")) { - task = Event.fromFileString(line); + Task task = Event.fromFileString(line); + tasks.add(task); } - tasks.add(task); } scanner.close(); } catch (FileNotFoundException e) { diff --git a/src/main/java/Task/Task.java b/src/main/java/Task/Task.java index 32744375b..b1b0355b7 100644 --- a/src/main/java/Task/Task.java +++ b/src/main/java/Task/Task.java @@ -10,12 +10,16 @@ public class Task { public Task(String description) { this.description = description; this.isDone = false; - numberOfTasks++; + addNumberOfTasks(); } public Task(String description, boolean isDone) { this.description = description; this.isDone = isDone; + addNumberOfTasks(); + } + + public static void addNumberOfTasks(){ numberOfTasks++; } From a17811341b219ce78feb0e04b09d7790e164b094 Mon Sep 17 00:00:00 2001 From: NgYJ02 <91600220+NgYJ02@users.noreply.github.com> Date: Fri, 3 Mar 2023 21:58:34 +0800 Subject: [PATCH 19/27] A-MoreOOP --- src/main/java/Duke.java | 119 ++++++++++--------- src/main/java/Parser/Parser.java | 90 ++++++++++++++ src/main/java/{ => Storage}/DukeStorage.java | 1 + src/main/java/Task/Task.java | 19 +-- src/main/java/Task/TaskList.java | 38 ++++++ src/main/java/UI/Ui.java | 92 ++++++++++++++ 6 files changed, 287 insertions(+), 72 deletions(-) create mode 100644 src/main/java/Parser/Parser.java rename src/main/java/{ => Storage}/DukeStorage.java (99%) create mode 100644 src/main/java/Task/TaskList.java create mode 100644 src/main/java/UI/Ui.java diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index a44d54c07..3e8823c69 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,95 +1,104 @@ import java.io.IOException; -import java.util.ArrayList; import java.util.Scanner; import Exception.DukeException; +import Parser.Parser; +import Storage.DukeStorage; import Task.Deadline; import Task.Event; import Task.Task; +import Task.TaskList; import Task.Todo; +import UI.Ui; public class Duke { - public static void main(String[] args) throws DukeException, IOException { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - System.out.println("Hello! I'm Duke"); - System.out.println("What can I do for you?\n"); - DukeStorage storage = new DukeStorage("data/duke.txt"); + + public Duke(String filePath) throws DukeException, IOException { + Ui.greet(); + DukeStorage storage = new DukeStorage(filePath); Task.numberOfTasks = 0; - ArrayList tasks = storage.loadTaskList(); + TaskList taskList = new TaskList(storage); try (Scanner scan = new Scanner(System.in)) { String input = scan.nextLine(); - String output = new String(); while (!input.equals("bye")) { try { if (input.equals("list")) { - output = "Here are the tasks in the list:" + System.lineSeparator() - + Task.printTasksList(tasks); + Ui.printList(taskList.getTasks()); } else if (input.startsWith("mark")) { - String[] marks = input.split(" "); - tasks.get(Integer.parseInt(marks[1]) - 1).markAsDone(); - output = "Nice! I've marked this task as done:" + System.lineSeparator() - + tasks.get(Integer.parseInt(marks[1]) - 1).toString(); + String[] marks = Parser.processInput(input); + int index = Parser.checkActionInputValidity(marks); + if (index == -1) { + throw new Exception(); + } + taskList.getTasks().get(index).markAsDone(); + Ui.markMessage(taskList.getTasks(), index); } else if (input.startsWith("unmark")) { - String[] marks = input.split(" "); - tasks.get(Integer.parseInt(marks[1]) - 1).markAsNotDone(); - output = "OK, I've marked this task as not done yet:" + System.lineSeparator() - + tasks.get(Integer.parseInt(marks[1]) - 1).toString(); + String[] marks = Parser.processInput(input); + int index = Parser.checkActionInputValidity(marks); + if (index == -1) { + throw new Exception(); + } + taskList.getTasks().get(index).markAsNotDone(); + Ui.unmarkMessage(taskList.getTasks(), index); } else if (input.startsWith("todo", 0)) { - String toDoDesc = input.split("todo")[1].trim(); + String toDoDesc = Parser.processTodoString(input); + if (toDoDesc == "") { + throw new Exception(); + } Task toDo = new Todo(toDoDesc); - tasks.add(toDo); - output = "Got it. I've added this task:" + System.lineSeparator() - + toDo.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks - + " in the list."; + taskList.addTask(toDo); + Ui.printConfirmation(toDo, "TODO"); } else if (input.startsWith("deadline", 0)) { - String deadlineDesc = input.split("/")[0].split("deadline")[1].trim(); - String deadlineDay = input.split("/")[1].trim(); + String[] deadlineArray = Parser.processDeadlineString(input); + if (deadlineArray.length == 0) { + throw new Exception(); + } + String deadlineDesc = deadlineArray[0]; + String deadlineDay = deadlineArray[1]; Task deadline = new Deadline(deadlineDesc, deadlineDay); - tasks.add(deadline); - output = "Got it. I've added this task:" + System.lineSeparator() - + deadline.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks - + " in the list."; + taskList.addTask(deadline); + Ui.printConfirmation(deadline, "DEADLINE"); } else if (input.startsWith("event", 0)) { - String eventDesc = input.split("/")[0].split("event")[1].trim(); - String start = input.split("/")[1].trim(); - String end = input.split("/")[2].trim(); + String[] eventArray = Parser.processEventString(input); + if (eventArray.length == 0) { + throw new Exception(); + } + String eventDesc = eventArray[0]; + String start = eventArray[1]; + String end = eventArray[2]; Task event = new Event(eventDesc, start, end); - tasks.add(event); - output = "Got it. I've added this task:" + System.lineSeparator() - + event.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks - + " in the list."; + taskList.addTask(event); + Ui.printConfirmation(event, "EVENT"); } else if (input.startsWith("delete")) { - int toDelete = Integer.parseInt(input.split(" ")[1]); - output = "Noted. I've removed this task:" + System.lineSeparator() - + tasks.get(toDelete - 1).toString(); - tasks.remove(toDelete - 1); + String[] deleteStrings = Parser.processInput(input); + int toDelete = Parser.checkActionInputValidity(deleteStrings); + if (toDelete == -1) { + throw new Exception(); + } + Task deleteTask = taskList.getTasks().get(toDelete); + taskList.removeTask(deleteTask); Task.decrementNumberOfTasks(); - output += System.lineSeparator() + "Now you have " + Task.numberOfTasks + " tasks in the list."; + Ui.printConfirmation(deleteTask, "DELETE"); } else { - output = "OOPS!!! I'm sorry, but I don't know what that means :-("; + Ui.printConfirmation(null, "UNRECOGNIZED"); + ; } - } catch (ArrayIndexOutOfBoundsException e) { - output = "Please provide the necessary information for the task."; + } catch (Exception e) { + Ui.printIncompleteMessage(); } - System.out.println("___________________________________________________"); - System.out.println(output); - System.out.println("___________________________________________________"); input = scan.nextLine(); } } catch (NumberFormatException e) { - // TODO Auto-generated catch block e.printStackTrace(); } - System.out.println("Bye. Hope to see you again soon!"); - storage.saveTaskList(tasks); + Ui.bye(); + storage.saveTaskList(taskList.getTasks()); + } + public static void main(String[] args) throws DukeException, IOException { + new Duke("data/duke.txt"); } } diff --git a/src/main/java/Parser/Parser.java b/src/main/java/Parser/Parser.java new file mode 100644 index 000000000..82be2a037 --- /dev/null +++ b/src/main/java/Parser/Parser.java @@ -0,0 +1,90 @@ +package Parser; + +import Task.Task; + +public class Parser { + + public static final String ERROR_MESSAGE = "Invalid input."; + + public static String[] processInput(String input) { + String[] inputs = input.split(" ", 2); + return inputs; + } + + public static int checkActionInputValidity(String[] input) { + try { + if (input.length == 1) { + System.out.println(ERROR_MESSAGE); + return -1; + } + int taskIndex = Integer.parseInt(input[1]); + if (taskIndex > Task.numberOfTasks || taskIndex < 1) { + throw new IndexOutOfBoundsException(ERROR_MESSAGE); + } + return taskIndex - 1; + } catch (NumberFormatException nonIntegerIndex) { + System.out.println(ERROR_MESSAGE); + return -1; + } catch (IndexOutOfBoundsException outOfBoundsIndex) { + System.out.println(ERROR_MESSAGE); + return -1; + } + } + + public static String processTodoString(String input) { + try { + String task = input.split("todo")[1].trim(); + if (task.equals("")) { + System.out.println(ERROR_MESSAGE); + return task; + } + return task; + } catch (IndexOutOfBoundsException e) { + System.out.println(ERROR_MESSAGE); + return ""; + } + } + + public static String[] processDeadlineString(String input) { + try { + String deadlineDesc = input.split("/")[0].split("deadline")[1].trim(); + String deadlineDay = input.split("/")[1].trim(); + + String[] deadlineArray = { deadlineDesc, deadlineDay }; + + for (int i = 0; i < 2; i++) { + deadlineArray[i] = deadlineArray[i].trim(); + if (deadlineArray[i].equals("")) { + throw new IndexOutOfBoundsException(); + } + } + return deadlineArray; + } catch (IndexOutOfBoundsException outOfBoundsException) { + System.out.println(ERROR_MESSAGE); + return new String[0]; + } + } + + public static String[] processEventString(String input) { + try { + String eventDesc = input.split("/")[0].split("event")[1].trim(); + String start = input.split("/")[1].trim(); + String end = input.split("/")[2].trim(); + + String[] eventArray = { eventDesc, start, end }; + + for (int i = 0; i < 3; i++) { + eventArray[i] = eventArray[i].trim(); + if (eventArray[i].equals("")) { + throw new IndexOutOfBoundsException(); + } + } + return eventArray; + } catch (IndexOutOfBoundsException outOfBoundsException) { + System.out.println(ERROR_MESSAGE); + return new String[0]; + } + + } + +} diff --git a/src/main/java/DukeStorage.java b/src/main/java/Storage/DukeStorage.java similarity index 99% rename from src/main/java/DukeStorage.java rename to src/main/java/Storage/DukeStorage.java index b89651ac9..8e934f755 100644 --- a/src/main/java/DukeStorage.java +++ b/src/main/java/Storage/DukeStorage.java @@ -1,3 +1,4 @@ +package Storage; import java.io.File; import java.io.FileWriter; import java.io.IOException; diff --git a/src/main/java/Task/Task.java b/src/main/java/Task/Task.java index b1b0355b7..c7ddff55a 100644 --- a/src/main/java/Task/Task.java +++ b/src/main/java/Task/Task.java @@ -1,11 +1,9 @@ package Task; -import java.util.ArrayList; - public class Task { protected String description; protected boolean isDone; - public static int numberOfTasks=0; + public static int numberOfTasks = 0; public Task(String description) { this.description = description; @@ -19,7 +17,7 @@ public Task(String description, boolean isDone) { addNumberOfTasks(); } - public static void addNumberOfTasks(){ + public static void addNumberOfTasks() { numberOfTasks++; } @@ -27,19 +25,6 @@ public static void decrementNumberOfTasks() { numberOfTasks--; } - public static String printTasksList(ArrayList tasks) { - String tasksList = new String(); - int count = 1; - for (Task i : tasks) { - tasksList += count + ". " + i.toString(); - if (count < numberOfTasks) { - tasksList += System.lineSeparator(); - } - count++; - } - return tasksList; - } - public String getDescription() { return description; } diff --git a/src/main/java/Task/TaskList.java b/src/main/java/Task/TaskList.java new file mode 100644 index 000000000..cabc70f87 --- /dev/null +++ b/src/main/java/Task/TaskList.java @@ -0,0 +1,38 @@ +package Task; + +import java.io.IOException; +import java.util.ArrayList; +import Storage.DukeStorage; + +public class TaskList { + private ArrayList tasks; + + public TaskList(DukeStorage storage) throws IOException{ + tasks = storage.loadTaskList(); + } + + public void addTask(Task task) { + tasks.add(task); + } + + public void removeTask(Task task) { + tasks.remove(task); + } + + public ArrayList getTasks() { + return tasks; + } + + public static String printTasksList(ArrayList tasks) { + String tasksList = new String(); + int count = 1; + for (Task i : tasks) { + tasksList += count + ". " + i.toString(); + if (count < Task.numberOfTasks) { + tasksList += System.lineSeparator(); + } + count++; + } + return tasksList; + } +} \ No newline at end of file diff --git a/src/main/java/UI/Ui.java b/src/main/java/UI/Ui.java new file mode 100644 index 000000000..dc1975f68 --- /dev/null +++ b/src/main/java/UI/Ui.java @@ -0,0 +1,92 @@ +package UI; + +import java.util.ArrayList; + +import Task.Task; +import Task.TaskList; + +public class Ui { + final static String LINEBREAK = "______________________________________________________"; + final static String LOGO = " ____ _ \n" + + "| _ \\ _ _| | _____ \n" + + "| | | | | | | |/ / _ \\\n" + + "| |_| | |_| | < __/\n" + + "|____/ \\__,_|_|\\_\\___|"; + final static String WELCOME_MESSAGE = "Hello! I'm Duke\nWhat can I do for you?"; + final static String EXIT_MESSAGE = "Bye. Hope to see you again soon."; + final static String UNRECOGNIZED_ACTION = "OOPS!!! I'm sorry, but I don't know what that means :-("; + final static String INCOMPLETE_ACTION = "Please provide the necessary information for the task."; + + final static String LIST = "list"; + final static String MARK = "mark"; + final static String UNMARK = "unmark"; + final static String TODO = "todo"; + final static String DEADLINE = "deadline"; + final static String EVENT = "event"; + final static String DELETE = "delete"; + + final static String LIST_MESSAGE = "Here are the tasks in the list:"; + final static String MARK_MESSAGE = "Nice! I've marked this task as done:"; + final static String UNMARK_MESSAGE = "OK, I've marked this task as not done yet:"; + final static String ADD_TASK_MESSAGE = "Got it. I've added this task:"; + final static String DELETE_TASK_MESSAGE = "Noted. I've removed this task:"; + + public final static void greet() { + System.out.println(LOGO + "\n" + WELCOME_MESSAGE); + } + + public final static void bye() { + System.out.println(LINEBREAK + "\n" + EXIT_MESSAGE + "\n" + LINEBREAK); + } + + public static void printList(ArrayList tasks) { + String output = LIST_MESSAGE + System.lineSeparator() + + TaskList.printTasksList(tasks); + System.out.println(LINEBREAK); + System.out.println(output); + System.out.println(LINEBREAK); + } + + public static void markMessage(ArrayList tasks, int index) { + System.out.println(LINEBREAK); + System.out.println(MARK_MESSAGE); + System.out.println(tasks.get(index).toString()); + System.out.println(LINEBREAK); + } + + public static void unmarkMessage(ArrayList tasks, int index) { + System.out.println(LINEBREAK); + System.out.println(UNMARK_MESSAGE); + System.out.println(tasks.get(index).toString()); + System.out.println(LINEBREAK); + } + + public static void printConfirmation(Task newTask, String action) { + System.out.println(LINEBREAK); + switch (action) { + case "TODO": + case "DEADLINE": + case "EVENT": + System.out.println(ADD_TASK_MESSAGE); + System.out.println(newTask.toString()); + break; + + case "DELETE": + System.out.println(DELETE_TASK_MESSAGE); + System.out.println(newTask.toString()); + break; + + default: + System.out.println(UNRECOGNIZED_ACTION); + } + System.out.println("Now you have " + Task.numberOfTasks + " tasks in the list"); + System.out.println(LINEBREAK); + + } + + public static void printIncompleteMessage() { + System.out.println(INCOMPLETE_ACTION); + System.out.println(LINEBREAK); + } + +} From 2c054d451ece764ec9736d36300c5c0fa07ce088 Mon Sep 17 00:00:00 2001 From: NgYJ02 <91600220+NgYJ02@users.noreply.github.com> Date: Fri, 3 Mar 2023 22:48:19 +0800 Subject: [PATCH 20/27] Level-9 --- src/main/java/Duke.java | 6 ++++++ src/main/java/Parser/Parser.java | 14 ++++++++++++++ src/main/java/Task/TaskList.java | 13 +++++++++++++ src/main/java/UI/Ui.java | 9 +++++++++ 4 files changed, 42 insertions(+) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 3e8823c69..1ad2b3fdd 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -41,6 +41,12 @@ public Duke(String filePath) throws DukeException, IOException { } taskList.getTasks().get(index).markAsNotDone(); Ui.unmarkMessage(taskList.getTasks(), index); + } else if (input.startsWith("find")) { + String findString = Parser.processFindString(input); + if (findString == "") { + throw new Exception(); + } + Ui.findTask(taskList.getTasks(), findString); } else if (input.startsWith("todo", 0)) { String toDoDesc = Parser.processTodoString(input); if (toDoDesc == "") { diff --git a/src/main/java/Parser/Parser.java b/src/main/java/Parser/Parser.java index 82be2a037..ef3081259 100644 --- a/src/main/java/Parser/Parser.java +++ b/src/main/java/Parser/Parser.java @@ -30,6 +30,20 @@ public static int checkActionInputValidity(String[] input) { return -1; } } + + public static String processFindString(String input) { + try { + String findString = input.split("find")[1].trim(); + if (findString.equals("")) { + System.out.println(ERROR_MESSAGE); + return findString; + } + return findString; + } catch (IndexOutOfBoundsException e) { + System.out.println(ERROR_MESSAGE); + return ""; + } + } public static String processTodoString(String input) { try { diff --git a/src/main/java/Task/TaskList.java b/src/main/java/Task/TaskList.java index cabc70f87..b8d32aa23 100644 --- a/src/main/java/Task/TaskList.java +++ b/src/main/java/Task/TaskList.java @@ -35,4 +35,17 @@ public static String printTasksList(ArrayList tasks) { } return tasksList; } + + public static String findList(ArrayList tasks, String input) { + String findList = new String(); + int count = 1; + for (Task i : tasks) { + if (i.toString().contains(input)){ + findList+= count + ". " + i.toString(); + findList += System.lineSeparator(); + count++; + } + } + return findList; + } } \ No newline at end of file diff --git a/src/main/java/UI/Ui.java b/src/main/java/UI/Ui.java index dc1975f68..f7d634d32 100644 --- a/src/main/java/UI/Ui.java +++ b/src/main/java/UI/Ui.java @@ -26,6 +26,7 @@ public class Ui { final static String DELETE = "delete"; final static String LIST_MESSAGE = "Here are the tasks in the list:"; + final static String FIND_MESSAGE = "Here are the matching tasks in your list:"; final static String MARK_MESSAGE = "Nice! I've marked this task as done:"; final static String UNMARK_MESSAGE = "OK, I've marked this task as not done yet:"; final static String ADD_TASK_MESSAGE = "Got it. I've added this task:"; @@ -47,6 +48,14 @@ public static void printList(ArrayList tasks) { System.out.println(LINEBREAK); } + public static void findTask(ArrayList tasks, String input) { + String output = FIND_MESSAGE + System.lineSeparator() + + TaskList.findList(tasks, input); + System.out.println(LINEBREAK); + System.out.println(output); + System.out.println(LINEBREAK); + } + public static void markMessage(ArrayList tasks, int index) { System.out.println(LINEBREAK); System.out.println(MARK_MESSAGE); From 10af1c0bcdbaf7e639d02da282492af53ff70126 Mon Sep 17 00:00:00 2001 From: NgYJ02 <91600220+NgYJ02@users.noreply.github.com> Date: Fri, 3 Mar 2023 23:41:35 +0800 Subject: [PATCH 21/27] add JavaDoc --- src/main/java/Duke.java | 16 +++++++- src/main/java/Exception/DukeException.java | 7 +++- src/main/java/Parser/Parser.java | 41 +++++++++++++++++- src/main/java/Storage/DukeStorage.java | 19 +++++++++ src/main/java/Task/Deadline.java | 46 ++++++++++++++++++--- src/main/java/Task/Event.java | 45 ++++++++++++++++++-- src/main/java/Task/Task.java | 48 ++++++++++++++++++++++ src/main/java/Task/TaskList.java | 46 +++++++++++++++++++-- src/main/java/Task/Todo.java | 32 +++++++++++++++ src/main/java/UI/Ui.java | 47 +++++++++++++++++++++ 10 files changed, 330 insertions(+), 17 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 1ad2b3fdd..1b300df32 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -12,7 +12,14 @@ import UI.Ui; public class Duke { - + /** + * Constructor to initiate the program + * + * @param filePath the path to the file + * @throws DukeException + * @throws IOException + * + */ public Duke(String filePath) throws DukeException, IOException { Ui.greet(); DukeStorage storage = new DukeStorage(filePath); @@ -103,6 +110,13 @@ public Duke(String filePath) throws DukeException, IOException { storage.saveTaskList(taskList.getTasks()); } + /** + * main function + * + * @throws DukeException + * @throws IOException + * + */ public static void main(String[] args) throws DukeException, IOException { new Duke("data/duke.txt"); } diff --git a/src/main/java/Exception/DukeException.java b/src/main/java/Exception/DukeException.java index a52b51828..790f25ba2 100644 --- a/src/main/java/Exception/DukeException.java +++ b/src/main/java/Exception/DukeException.java @@ -1,7 +1,12 @@ package Exception; public class DukeException extends Exception { - public DukeException (String message){ + /** + * This method throws an exception. + * + * @param message the exception message + */ + public DukeException(String message) { super(message); } } diff --git a/src/main/java/Parser/Parser.java b/src/main/java/Parser/Parser.java index ef3081259..262709b92 100644 --- a/src/main/java/Parser/Parser.java +++ b/src/main/java/Parser/Parser.java @@ -3,14 +3,27 @@ import Task.Task; public class Parser { - + // Error String public static final String ERROR_MESSAGE = "Invalid input."; + /** + * This method splits the input with spaces. + * Maximum length is two. + * + * @param input the input string + * @return the splitted string in a string array + */ public static String[] processInput(String input) { String[] inputs = input.split(" ", 2); return inputs; } + /** + * This method checks the validity of input. + * + * @param input the input string array + * @return the index of the tasks desired, else -1 if invalid + */ public static int checkActionInputValidity(String[] input) { try { if (input.length == 1) { @@ -30,7 +43,13 @@ public static int checkActionInputValidity(String[] input) { return -1; } } - + + /** + * This method checks the validity of find input. + * + * @param input the input string + * @return the keyword, else an empty string if invalid + */ public static String processFindString(String input) { try { String findString = input.split("find")[1].trim(); @@ -45,6 +64,12 @@ public static String processFindString(String input) { } } + /** + * This method checks the validity of todo input. + * + * @param input the input string + * @return the todo task, else an empty string if invalid + */ public static String processTodoString(String input) { try { String task = input.split("todo")[1].trim(); @@ -59,6 +84,12 @@ public static String processTodoString(String input) { } } + /** + * This method checks the validity of deadline input. + * + * @param input the input string + * @return the deadline info in string array, else an empty string if invalid + */ public static String[] processDeadlineString(String input) { try { String deadlineDesc = input.split("/")[0].split("deadline")[1].trim(); @@ -79,6 +110,12 @@ public static String[] processDeadlineString(String input) { } } + /** + * This method checks the validity of event input. + * + * @param input the input string + * @return the event info in string array, else an empty string if invalid + */ public static String[] processEventString(String input) { try { String eventDesc = input.split("/")[0].split("event")[1].trim(); diff --git a/src/main/java/Storage/DukeStorage.java b/src/main/java/Storage/DukeStorage.java index 8e934f755..aa6d46d16 100644 --- a/src/main/java/Storage/DukeStorage.java +++ b/src/main/java/Storage/DukeStorage.java @@ -1,4 +1,5 @@ package Storage; + import java.io.File; import java.io.FileWriter; import java.io.IOException; @@ -12,12 +13,24 @@ import Task.Event; public class DukeStorage { + // filePath of the file private static String filePath; + /** + * Constructor + * + * @param filePath the path to the file + */ public DukeStorage(String filePath) { DukeStorage.filePath = filePath; } + /** + * This method save the task list. + * + * @param tasks the task list + * + */ public void saveTaskList(ArrayList tasks) { try { File file = new File(filePath); @@ -35,6 +48,12 @@ public void saveTaskList(ArrayList tasks) { } } + /** + * This method loads the task list. + * + * @return the task list + * @throws IOException + */ public static ArrayList loadTaskList() throws IOException { ArrayList tasks = new ArrayList<>(); try { diff --git a/src/main/java/Task/Deadline.java b/src/main/java/Task/Deadline.java index 60740059c..a003f08ee 100644 --- a/src/main/java/Task/Deadline.java +++ b/src/main/java/Task/Deadline.java @@ -1,30 +1,64 @@ package Task; - public class Deadline extends Task { + // deadline day protected String deadlineDay; + /** + * Constructor + * + * @param description deadline description + * @param deadlineDay deadline day + * + */ public Deadline(String description, String deadlineDay) { super(description); - this.deadlineDay=deadlineDay; + this.deadlineDay = deadlineDay; } - public Deadline(String description, String deadlineDay, boolean isDone){ + /** + * Constructor + * + * @param description deadline description + * @param deadlineDay deadline day + * @param isDone whether the task is done or not + * + */ + public Deadline(String description, String deadlineDay, boolean isDone) { super(description, isDone); - this.deadlineDay=deadlineDay; + this.deadlineDay = deadlineDay; } + /** + * toString method + * + * @return string description + * + */ @Override - public String toString(){ - return "[D]"+super.toString()+" ("+this.deadlineDay+")"; + public String toString() { + return "[D]" + super.toString() + " (" + this.deadlineDay + ")"; } + /** + * toString method when saving in file + * + * @return string description to be saved in file + * + */ @Override public String toFileString() { return "D | " + (isDone ? 1 : 0) + " | " + description + " | " + deadlineDay; } + /** + * toString method + * + * @param line input string from file + * @return deadline item + * + */ public static Deadline fromFileString(String line) { String[] parts = line.split(" \\| "); boolean isDone = Integer.parseInt(parts[1]) == 1; diff --git a/src/main/java/Task/Event.java b/src/main/java/Task/Event.java index 6e8923efb..4d2d2f3d2 100644 --- a/src/main/java/Task/Event.java +++ b/src/main/java/Task/Event.java @@ -1,38 +1,75 @@ package Task; public class Event extends Task { + // Attributes of Event instances protected String start; protected String end; + /** + * Constructor + * + * @param description event description + * @param start start of event + * @param end end of event + * + */ public Event(String description, String start, String end) { super(description); this.start = start; this.end = end; } - public Event(String description, String start, String end, boolean isDone){ + /** + * Constructor + * + * @param description event description + * @param start start of event + * @param end end of event + * @param isDone whether event is done or not + * + */ + public Event(String description, String start, String end, boolean isDone) { super(description, isDone); - this.start=start; - this.end=end; + this.start = start; + this.end = end; } + /** + * toString method + * + * @return string description + * + */ @Override public String toString() { return "[E]" + super.toString() + " (" + start + " " + end + ")"; } + /** + * toString method when saving in file + * + * @return string description to be saved in file + * + */ @Override public String toFileString() { return "E | " + (isDone ? 1 : 0) + " | " + description + " | " + start + " | " + end; } + /** + * toString method + * + * @param line input string from file + * @return deadline item + * + */ public static Event fromFileString(String line) { String[] parts = line.split(" \\| "); boolean isDone = Integer.parseInt(parts[1]) == 1; String description = parts[2]; String start = parts[3]; - String end=parts[4]; + String end = parts[4]; return new Event(description, start, end, isDone); } } diff --git a/src/main/java/Task/Task.java b/src/main/java/Task/Task.java index c7ddff55a..c1b97c98e 100644 --- a/src/main/java/Task/Task.java +++ b/src/main/java/Task/Task.java @@ -1,50 +1,98 @@ package Task; public class Task { + // attributes protected String description; protected boolean isDone; public static int numberOfTasks = 0; + /** + * Constuctor + * + * @param description task description + * + */ public Task(String description) { this.description = description; this.isDone = false; addNumberOfTasks(); } + /** + * Constuctor + * + * @param description task description + * @param isDone whether the task is done or not + * + */ public Task(String description, boolean isDone) { this.description = description; this.isDone = isDone; addNumberOfTasks(); } + /** + * increment the number of tasks + */ public static void addNumberOfTasks() { numberOfTasks++; } + /** + * decrement the number of tasks + */ public static void decrementNumberOfTasks() { numberOfTasks--; } + /** + * getter for description + * + * @return description string + */ public String getDescription() { return description; } + /** + * getter for status icon + * + * @return status icon + */ public String getStatusIcon() { return (isDone ? "X" : " "); } + /** + * mark task as done + */ public void markAsDone() { isDone = true; } + /** + * mark task as not done + */ public void markAsNotDone() { isDone = false; } + /** + * toString method + * + * @return string description + * + */ public String toString() { return "[" + this.getStatusIcon() + "]" + "\t" + this.getDescription(); } + /** + * toString method when saving in file + * + * @return string description to be saved in file + * + */ public String toFileString() { return "Task"; } diff --git a/src/main/java/Task/TaskList.java b/src/main/java/Task/TaskList.java index b8d32aa23..e660dd74c 100644 --- a/src/main/java/Task/TaskList.java +++ b/src/main/java/Task/TaskList.java @@ -5,24 +5,56 @@ import Storage.DukeStorage; public class TaskList { + // array list of tasks private ArrayList tasks; - public TaskList(DukeStorage storage) throws IOException{ + /** + * Constructor + * + * @param storage the storage file + * @throws IOException + * + */ + public TaskList(DukeStorage storage) throws IOException { tasks = storage.loadTaskList(); } + /** + * add task to the list + * + * @param task task to be added + * + */ public void addTask(Task task) { tasks.add(task); } + /** + * remove task from the list + * + * @param task task to be removed + * + */ public void removeTask(Task task) { tasks.remove(task); } + /** + * get the list of tasks + * + * @return the list of tasks + * + */ public ArrayList getTasks() { return tasks; } + /** + * print the list of tasks + * + * @param tasks the list of tasks + * @return the list of tasks in string format + */ public static String printTasksList(ArrayList tasks) { String tasksList = new String(); int count = 1; @@ -36,12 +68,20 @@ public static String printTasksList(ArrayList tasks) { return tasksList; } + /** + * find all tasks containing a given string + * + * @param tasks the list of tasks + * @param input the string to search + * @return the list of tasks containing the given string + * + */ public static String findList(ArrayList tasks, String input) { String findList = new String(); int count = 1; for (Task i : tasks) { - if (i.toString().contains(input)){ - findList+= count + ". " + i.toString(); + if (i.toString().contains(input)) { + findList += count + ". " + i.toString(); findList += System.lineSeparator(); count++; } diff --git a/src/main/java/Task/Todo.java b/src/main/java/Task/Todo.java index 316f26316..268a35046 100644 --- a/src/main/java/Task/Todo.java +++ b/src/main/java/Task/Todo.java @@ -1,24 +1,56 @@ package Task; public class Todo extends Task{ + /** + * constructor + * + * @param description description of the task + * + */ public Todo (String description){ super(description); } + /** + * constructor + * + * @param description description of the task\ + * @param isDone true if the task is done, false otherwise + * + */ public Todo (String description, boolean isDone){ super(description, isDone); } + /** + * toString method + * + * @return string description + * + */ @Override public String toString(){ return "[T]"+super.toString(); } + /** + * toString method when saving in file + * + * @return string description to be saved in file + * + */ @Override public String toFileString() { return "T | " + (isDone ? 1 : 0) + " | " + description; } + /** + * toString method + * + * @param line input string from file + * @return deadline item + * + */ public static Todo fromFileString(String line) { String[] parts = line.split(" \\| "); boolean isDone = Integer.parseInt(parts[1]) == 1; diff --git a/src/main/java/UI/Ui.java b/src/main/java/UI/Ui.java index f7d634d32..ead99dc7a 100644 --- a/src/main/java/UI/Ui.java +++ b/src/main/java/UI/Ui.java @@ -6,6 +6,7 @@ import Task.TaskList; public class Ui { + // Message strings final static String LINEBREAK = "______________________________________________________"; final static String LOGO = " ____ _ \n" + "| _ \\ _ _| | _____ \n" @@ -32,14 +33,28 @@ public class Ui { final static String ADD_TASK_MESSAGE = "Got it. I've added this task:"; final static String DELETE_TASK_MESSAGE = "Noted. I've removed this task:"; + /** + * print welcome message + * + */ public final static void greet() { System.out.println(LOGO + "\n" + WELCOME_MESSAGE); } + /** + * print bye message + * + */ public final static void bye() { System.out.println(LINEBREAK + "\n" + EXIT_MESSAGE + "\n" + LINEBREAK); } + /** + * print the list of tasks + * + * @param tasks list of tasks + * + */ public static void printList(ArrayList tasks) { String output = LIST_MESSAGE + System.lineSeparator() + TaskList.printTasksList(tasks); @@ -48,6 +63,13 @@ public static void printList(ArrayList tasks) { System.out.println(LINEBREAK); } + /** + * print the list of tasks containing the given string + * + * @param tasks list of tasks + * @param input the string to check + * + */ public static void findTask(ArrayList tasks, String input) { String output = FIND_MESSAGE + System.lineSeparator() + TaskList.findList(tasks, input); @@ -56,6 +78,13 @@ public static void findTask(ArrayList tasks, String input) { System.out.println(LINEBREAK); } + /** + * mark task message + * + * @param tasks the list of tasks + * @param index the index of the task + * + */ public static void markMessage(ArrayList tasks, int index) { System.out.println(LINEBREAK); System.out.println(MARK_MESSAGE); @@ -63,6 +92,13 @@ public static void markMessage(ArrayList tasks, int index) { System.out.println(LINEBREAK); } + /** + * unmark task message + * + * @param tasks the list of tasks + * @param index the index of the task + * + */ public static void unmarkMessage(ArrayList tasks, int index) { System.out.println(LINEBREAK); System.out.println(UNMARK_MESSAGE); @@ -70,6 +106,13 @@ public static void unmarkMessage(ArrayList tasks, int index) { System.out.println(LINEBREAK); } + /** + * print confirmation message + * + * @param newTask the relevant task + * @param action the action to perform on the task + * + */ public static void printConfirmation(Task newTask, String action) { System.out.println(LINEBREAK); switch (action) { @@ -93,6 +136,10 @@ public static void printConfirmation(Task newTask, String action) { } + /** + * print incomplete input message + * + */ public static void printIncompleteMessage() { System.out.println(INCOMPLETE_ACTION); System.out.println(LINEBREAK); From f2ad4656e8612770b17c0c1c7268ea0303410985 Mon Sep 17 00:00:00 2001 From: Ng Yong Jian <91600220+ngyongjian@users.noreply.github.com> Date: Sat, 4 Mar 2023 00:37:32 +0800 Subject: [PATCH 22/27] Update README.md --- README.md | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 8715d4d91..1ad40b5d2 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,31 @@ -# Duke project template +# Duke - User Guide -This is a project template for a greenfield Java project. It's named after the Java mascot _Duke_. Given below are instructions on how to use it. +Duke is a personal task manager designed to help you stay organized and on top of your to-do list. With its automated features, Duke streamlines task management and can significantly improve your productivity. -## Setting up in Intellij +## Usage -Prerequisites: JDK 11, update Intellij to the most recent version. +###todo {Task} - Add a Todo Task +Example: `todo return book` +Expected outcome: + ``` + Got it. I've added this task: + [T][ ] return book + ``` + +###deadline {Task} /by {Date/Time} - Add a Deadline Task +Example: `deadline return book /by Sun` +Expected outcome: + ``` + Got it. I've added this task: + [D][ ] return book (by Sun) + ``` -1. Open Intellij (if you are not in the welcome screen, click `File` > `Close Project` to close the existing project first) -1. Open the project into Intellij as follows: - 1. Click `Open`. - 1. Select the project directory, and click `OK`. - 1. If there are any further prompts, accept the defaults. -1. Configure the project to use **JDK 11** (not other versions) as explained in [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk).
- In the same dialog, set the **Project language level** field to the `SDK default` option. -3. After that, locate the `src/main/java/Duke.java` file, right-click it, and choose `Run Duke.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output: +###event {Task} /from {Date/Time} /to {Date/Time} - Add a Event Task +Example: `event party /from Fri 6pm /to 8pm` +Expected outcome: ``` - Hello from - ____ _ - | _ \ _ _| | _____ - | | | | | | | |/ / _ \ - | |_| | |_| | < __/ - |____/ \__,_|_|\_\___| + Got it. I've added this task: + [E][ ] party (from Fri 6pm to 8pm) ``` + + From ddc4626102b123d9d1e26183f65930ee9b076bef Mon Sep 17 00:00:00 2001 From: Ng Yong Jian <91600220+ngyongjian@users.noreply.github.com> Date: Sat, 4 Mar 2023 00:37:54 +0800 Subject: [PATCH 23/27] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1ad40b5d2..0c4be3baa 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Duke is a personal task manager designed to help you stay organized and on top o ## Usage -###todo {Task} - Add a Todo Task +### todo {Task} - Add a Todo Task Example: `todo return book` Expected outcome: ``` @@ -12,7 +12,7 @@ Expected outcome: [T][ ] return book ``` -###deadline {Task} /by {Date/Time} - Add a Deadline Task +### deadline {Task} /by {Date/Time} - Add a Deadline Task Example: `deadline return book /by Sun` Expected outcome: ``` @@ -20,7 +20,7 @@ Expected outcome: [D][ ] return book (by Sun) ``` -###event {Task} /from {Date/Time} /to {Date/Time} - Add a Event Task +### event {Task} /from {Date/Time} /to {Date/Time} - Add a Event Task Example: `event party /from Fri 6pm /to 8pm` Expected outcome: ``` From 30670cef26d04154637ad444555184480a9665f6 Mon Sep 17 00:00:00 2001 From: Ng Yong Jian <91600220+ngyongjian@users.noreply.github.com> Date: Sat, 4 Mar 2023 00:40:59 +0800 Subject: [PATCH 24/27] Update README.md --- README.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/README.md b/README.md index 0c4be3baa..992a3f98f 100644 --- a/README.md +++ b/README.md @@ -28,4 +28,50 @@ Expected outcome: [E][ ] party (from Fri 6pm to 8pm) ``` +### mark {Task} /from {Date/Time} /to {Date/Time} - Add a Event Task +Example: `event party /from Fri 6pm /to 8pm` +Expected outcome: + ``` + Got it. I've added this task: + [E][ ] party (from Fri 6pm to 8pm) + ``` + +### unmark {Task} /from {Date/Time} /to {Date/Time} - Add a Event Task +Example: `event party /from Fri 6pm /to 8pm` +Expected outcome: + ``` + Got it. I've added this task: + [E][ ] party (from Fri 6pm to 8pm) + ``` + +### list {Task} /from {Date/Time} /to {Date/Time} - Add a Event Task +Example: `event party /from Fri 6pm /to 8pm` +Expected outcome: + ``` + Got it. I've added this task: + [E][ ] party (from Fri 6pm to 8pm) + ``` + +### find {Task} /from {Date/Time} /to {Date/Time} - Add a Event Task +Example: `event party /from Fri 6pm /to 8pm` +Expected outcome: + ``` + Got it. I've added this task: + [E][ ] party (from Fri 6pm to 8pm) + ``` + +### delete {Task} /from {Date/Time} /to {Date/Time} - Add a Event Task +Example: `event party /from Fri 6pm /to 8pm` +Expected outcome: + ``` + Got it. I've added this task: + [E][ ] party (from Fri 6pm to 8pm) + ``` + +### bye - Leave program +Example: `bye` +Expected outcome: + ``` + Bye. Hope to see you again soon. + ``` From 478a610db111fd3364a4d214bc9c8e22c277fb9f Mon Sep 17 00:00:00 2001 From: Ng Yong Jian <91600220+ngyongjian@users.noreply.github.com> Date: Sat, 4 Mar 2023 15:38:26 +0800 Subject: [PATCH 25/27] Update README.md --- README.md | 54 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 992a3f98f..3adeda4e8 100644 --- a/README.md +++ b/README.md @@ -5,15 +5,15 @@ Duke is a personal task manager designed to help you stay organized and on top o ## Usage ### todo {Task} - Add a Todo Task -Example: `todo return book` +Example: `todo study` Expected outcome: ``` Got it. I've added this task: - [T][ ] return book + [T][ ] study ``` ### deadline {Task} /by {Date/Time} - Add a Deadline Task -Example: `deadline return book /by Sun` +Example: `deadline return book /by Sun` Expected outcome: ``` Got it. I've added this task: @@ -21,55 +21,57 @@ Expected outcome: ``` ### event {Task} /from {Date/Time} /to {Date/Time} - Add a Event Task -Example: `event party /from Fri 6pm /to 8pm` +Example: `event party /from Fri 6pm /to 8pm` Expected outcome: ``` Got it. I've added this task: [E][ ] party (from Fri 6pm to 8pm) ``` -### mark {Task} /from {Date/Time} /to {Date/Time} - Add a Event Task -Example: `event party /from Fri 6pm /to 8pm` +### mark {Task Index} - Mark Task as Done +Example: `mark 1` Expected outcome: ``` - Got it. I've added this task: - [E][ ] party (from Fri 6pm to 8pm) + Nice! I've marked this task as done: + [T][X] study ``` -### unmark {Task} /from {Date/Time} /to {Date/Time} - Add a Event Task -Example: `event party /from Fri 6pm /to 8pm` +### unmark {Task Index} - Mark Task as Not Done +Example: `unmark 2` Expected outcome: ``` - Got it. I've added this task: - [E][ ] party (from Fri 6pm to 8pm) + OK, I've marked this task as not done yet: + [D][ ] return book (by Sun) ``` -### list {Task} /from {Date/Time} /to {Date/Time} - Add a Event Task -Example: `event party /from Fri 6pm /to 8pm` +### list - List All Tasks +Example: `list` Expected outcome: ``` - Got it. I've added this task: - [E][ ] party (from Fri 6pm to 8pm) + 1. [T][ ] study + 2. [D][ ] return book (by Sun) + 3. [E][ ] party (from Fri 6pm to 8pm) ``` -### find {Task} /from {Date/Time} /to {Date/Time} - Add a Event Task -Example: `event party /from Fri 6pm /to 8pm` +### find {Keyword} - Find Task(s) Containing Certain Keyword +Example: `find book` Expected outcome: ``` - Got it. I've added this task: - [E][ ] party (from Fri 6pm to 8pm) + Here are the matching tasks in your list: + 1. [T][ ] read book + 2. [D][ ] return book (by Sun) ``` -### delete {Task} /from {Date/Time} /to {Date/Time} - Add a Event Task -Example: `event party /from Fri 6pm /to 8pm` +### delete {Task Index} - Delete Task +Example: `delete 4` Expected outcome: ``` - Got it. I've added this task: - [E][ ] party (from Fri 6pm to 8pm) + Noted. I've removed this task: + [T][ ] read book ``` -### bye - Leave program -Example: `bye` +### bye - Leave Program +Example: `bye` Expected outcome: ``` Bye. Hope to see you again soon. From d35fc8f5d9bc843daa2ff13a6e981fbb4643f791 Mon Sep 17 00:00:00 2001 From: Ng Yong Jian <91600220+ngyongjian@users.noreply.github.com> Date: Sat, 4 Mar 2023 15:50:43 +0800 Subject: [PATCH 26/27] Update README.md --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 3adeda4e8..900d89b81 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,21 @@ Duke is a personal task manager designed to help you stay organized and on top of your to-do list. With its automated features, Duke streamlines task management and can significantly improve your productivity. +## Features + +### 3 Types of Tasks +- `todo` - Adds a simple todo task +- `deadline` - Adds a deadline task with a due date +- `event` - Adds an event task with a start time and an end time + +### Other Functions +- `mark` - Mark task as done +- `unmark` - Mark task as not done +- `list` - List all tasks +- `find` - Find task(s) containing certain substring +- `delete` - Delete a task +- `bye` - Exit program + ## Usage ### todo {Task} - Add a Todo Task From f8ea312173c991a55f9f4a0ebeb8993403902385 Mon Sep 17 00:00:00 2001 From: Ng Yong Jian <91600220+ngyongjian@users.noreply.github.com> Date: Sat, 4 Mar 2023 15:51:27 +0800 Subject: [PATCH 27/27] Update README.md --- docs/README.md | 105 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 85 insertions(+), 20 deletions(-) diff --git a/docs/README.md b/docs/README.md index 8077118eb..900d89b81 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,29 +1,94 @@ -# User Guide +# Duke - User Guide -## Features +Duke is a personal task manager designed to help you stay organized and on top of your to-do list. With its automated features, Duke streamlines task management and can significantly improve your productivity. -### Feature-ABC +## Features -Description of the feature. +### 3 Types of Tasks +- `todo` - Adds a simple todo task +- `deadline` - Adds a deadline task with a due date +- `event` - Adds an event task with a start time and an end time -### Feature-XYZ - -Description of the feature. +### Other Functions +- `mark` - Mark task as done +- `unmark` - Mark task as not done +- `list` - List all tasks +- `find` - Find task(s) containing certain substring +- `delete` - Delete a task +- `bye` - Exit program ## Usage -### `Keyword` - Describe action - -Describe the action and its outcome. - -Example of usage: - -`keyword (optional arguments)` - +### todo {Task} - Add a Todo Task +Example: `todo study` Expected outcome: + ``` + Got it. I've added this task: + [T][ ] study + ``` + +### deadline {Task} /by {Date/Time} - Add a Deadline Task +Example: `deadline return book /by Sun` +Expected outcome: + ``` + Got it. I've added this task: + [D][ ] return book (by Sun) + ``` -Description of the outcome. - -``` -expected output -``` +### event {Task} /from {Date/Time} /to {Date/Time} - Add a Event Task +Example: `event party /from Fri 6pm /to 8pm` +Expected outcome: + ``` + Got it. I've added this task: + [E][ ] party (from Fri 6pm to 8pm) + ``` + +### mark {Task Index} - Mark Task as Done +Example: `mark 1` +Expected outcome: + ``` + Nice! I've marked this task as done: + [T][X] study + ``` + +### unmark {Task Index} - Mark Task as Not Done +Example: `unmark 2` +Expected outcome: + ``` + OK, I've marked this task as not done yet: + [D][ ] return book (by Sun) + ``` + +### list - List All Tasks +Example: `list` +Expected outcome: + ``` + 1. [T][ ] study + 2. [D][ ] return book (by Sun) + 3. [E][ ] party (from Fri 6pm to 8pm) + ``` + +### find {Keyword} - Find Task(s) Containing Certain Keyword +Example: `find book` +Expected outcome: + ``` + Here are the matching tasks in your list: + 1. [T][ ] read book + 2. [D][ ] return book (by Sun) + ``` + +### delete {Task Index} - Delete Task +Example: `delete 4` +Expected outcome: + ``` + Noted. I've removed this task: + [T][ ] read book + ``` + +### bye - Leave Program +Example: `bye` +Expected outcome: + ``` + Bye. Hope to see you again soon. + ``` +