From 105a3975cdc4281150c3c64c2c75c3d6fcad7288 Mon Sep 17 00:00:00 2001 From: Aiman Imtiaz Date: Sun, 23 Jan 2022 12:08:57 +0800 Subject: [PATCH 01/24] level-1 --- src/main/java/Duke.java | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5d313334c..546b779e3 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,10 +1,42 @@ +import java.util.Scanner; + public class Duke { + + public static void echoMessage(String line){ + String message = "\t____________________________________________________________\n" + + "\t" + line + "\n" + + "\t____________________________________________________________"; + System.out.println(message); + } + public static void main(String[] args) { + String line; + Scanner in = new Scanner(System.in); + String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" + "| | | | | | | |/ / _ \\\n" + "| |_| | |_| | < __/\n" + "|____/ \\__,_|_|\\_\\___|\n"; System.out.println("Hello from\n" + logo); + + String greeting = "\t____________________________________________________________\n" + + "\t Hello! I'm Duke\n" + + "\t What can I do for you?\n" + + "\t____________________________________________________________"; + + String bye = "\t____________________________________________________________\n" + + "\t Bye. Hope to see you again soon!\n" + + "\t____________________________________________________________"; + + System.out.println(greeting); + + line = in.nextLine(); + + while (!line.contains("bye")){ + echoMessage(line); + line = in.nextLine(); + } + System.out.println(bye); } } From 7305ab45630e143285180cbe086794244875d1b5 Mon Sep 17 00:00:00 2001 From: Aiman Imtiaz Date: Sun, 23 Jan 2022 17:42:05 +0800 Subject: [PATCH 02/24] level-2 --- src/main/java/Duke.java | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 546b779e3..e6225a0d4 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -2,13 +2,28 @@ public class Duke { - public static void echoMessage(String line){ - String message = "\t____________________________________________________________\n" + - "\t" + line + "\n" + - "\t____________________________________________________________"; + static String[] textList = new String[100]; + static int currentCount = 0; + static String dashedLine = "\t____________________________________________________________"; + + public static void addToList(String line){ + textList[currentCount] = line; + currentCount += 1; + String message = dashedLine + "\n" + + "\t" + "added:" + line + "\n" + + dashedLine; System.out.println(message); } + public static void printList(){ + System.out.print(dashedLine); + for (int j = 0; j < currentCount; j++){ + System.out.print("\n"); + System.out.print("\t" + (j+1) + ". " + textList[j]); + } + System.out.println("\n" + dashedLine); + } + public static void main(String[] args) { String line; Scanner in = new Scanner(System.in); @@ -20,23 +35,25 @@ public static void main(String[] args) { + "|____/ \\__,_|_|\\_\\___|\n"; System.out.println("Hello from\n" + logo); - String greeting = "\t____________________________________________________________\n" + + String greeting = dashedLine + "\n" + "\t Hello! I'm Duke\n" + "\t What can I do for you?\n" + - "\t____________________________________________________________"; + dashedLine; - String bye = "\t____________________________________________________________\n" + + String bye = dashedLine + "\n" + "\t Bye. Hope to see you again soon!\n" + - "\t____________________________________________________________"; + dashedLine; System.out.println(greeting); line = in.nextLine(); while (!line.contains("bye")){ - echoMessage(line); + if (line.equals("list")){ + printList(); + } else addToList(line); line = in.nextLine(); } - System.out.println(bye); + System.out.print(bye); } } From f9f6090931b18dd7dc912aa66c5052254c677160 Mon Sep 17 00:00:00 2001 From: Aiman Imtiaz Date: Sun, 23 Jan 2022 19:28:50 +0800 Subject: [PATCH 03/24] level-3 --- src/main/java/Duke.java | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index e6225a0d4..0020be329 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -2,12 +2,32 @@ public class Duke { - static String[] textList = new String[100]; + static String[] taskList = new String[100]; + static Boolean[] taskStatusList = new Boolean [100]; static int currentCount = 0; static String dashedLine = "\t____________________________________________________________"; + public static void markTask(int index){ + taskStatusList[index - 1] = true; + String message = dashedLine + "\n" + + "\t Nice! I've marked this task as done: \n" + + "\t \t [X] " + taskList[index - 1] + "\n" + + dashedLine ; + System.out.println(message); + } + + public static void unmarkTask(int index){ + taskStatusList[index - 1] = false; + String message = dashedLine + "\n" + + "\tOK, I've marked this task as not done yet: \n" + + "\t \t [ ] " + taskList[index - 1] + "\n" + + dashedLine ; + System.out.println(message); + } + public static void addToList(String line){ - textList[currentCount] = line; + taskList[currentCount] = line; + taskStatusList[currentCount] = false; currentCount += 1; String message = dashedLine + "\n" + "\t" + "added:" + line + "\n" + @@ -18,8 +38,12 @@ public static void addToList(String line){ public static void printList(){ System.out.print(dashedLine); for (int j = 0; j < currentCount; j++){ + String indicator; + if (taskStatusList[j]){ + indicator = "[X]"; + } else indicator = "[ ]"; System.out.print("\n"); - System.out.print("\t" + (j+1) + ". " + textList[j]); + System.out.print("\t" + (j+1) + "." + indicator + " " + taskList[j]); } System.out.println("\n" + dashedLine); } @@ -51,9 +75,16 @@ public static void main(String[] args) { while (!line.contains("bye")){ if (line.equals("list")){ printList(); + } else if (line.startsWith("mark")){ + int indexToMark = Integer.parseInt(line.substring(5)); + markTask(indexToMark); + } else if(line.startsWith("unmark")){ + int indexToUnmark = Integer.parseInt(line.substring(7)); + unmarkTask(indexToUnmark); } else addToList(line); line = in.nextLine(); } + System.out.print(bye); } } From def2ed71816647defd302f580e307129b6c734f3 Mon Sep 17 00:00:00 2001 From: Aiman Imtiaz Date: Sun, 23 Jan 2022 20:46:54 +0800 Subject: [PATCH 04/24] A-Classes --- src/main/java/Task.java | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 src/main/java/Task.java diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 000000000..4ec445449 --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,2 @@ +package PACKAGE_NAME;public class Task { +} From dc8f9394c2e0845dbc6b14d1bb703bf985f37bf3 Mon Sep 17 00:00:00 2001 From: Aiman Imtiaz Date: Sun, 23 Jan 2022 20:47:05 +0800 Subject: [PATCH 05/24] A-Classes --- src/main/java/Duke.java | 10 +++++----- src/main/java/Task.java | 7 ++++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 0020be329..3e6aff3a9 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -2,7 +2,7 @@ public class Duke { - static String[] taskList = new String[100]; + static Task[] taskList = new Task[100]; static Boolean[] taskStatusList = new Boolean [100]; static int currentCount = 0; static String dashedLine = "\t____________________________________________________________"; @@ -11,7 +11,7 @@ public static void markTask(int index){ taskStatusList[index - 1] = true; String message = dashedLine + "\n" + "\t Nice! I've marked this task as done: \n" + - "\t \t [X] " + taskList[index - 1] + "\n" + + "\t \t [X] " + taskList[index - 1].task + "\n" + dashedLine ; System.out.println(message); } @@ -20,13 +20,13 @@ public static void unmarkTask(int index){ taskStatusList[index - 1] = false; String message = dashedLine + "\n" + "\tOK, I've marked this task as not done yet: \n" + - "\t \t [ ] " + taskList[index - 1] + "\n" + + "\t \t [ ] " + taskList[index - 1].task + "\n" + dashedLine ; System.out.println(message); } public static void addToList(String line){ - taskList[currentCount] = line; + taskList[currentCount] = new Task(line); taskStatusList[currentCount] = false; currentCount += 1; String message = dashedLine + "\n" + @@ -43,7 +43,7 @@ public static void printList(){ indicator = "[X]"; } else indicator = "[ ]"; System.out.print("\n"); - System.out.print("\t" + (j+1) + "." + indicator + " " + taskList[j]); + System.out.print("\t" + (j+1) + "." + indicator + " " + taskList[j].task); } System.out.println("\n" + dashedLine); } diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 4ec445449..af692447c 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -1,2 +1,7 @@ -package PACKAGE_NAME;public class Task { +public class Task { + String task; + + public Task(String task){ + this.task = task; + } } From 85317bb43f5bf16c94ec1a9f5ea493ba1eff57b2 Mon Sep 17 00:00:00 2001 From: Aiman Imtiaz Date: Sun, 23 Jan 2022 20:52:20 +0800 Subject: [PATCH 06/24] 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 3e6aff3a9..877d36412 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -16,7 +16,7 @@ public static void markTask(int index){ System.out.println(message); } - public static void unmarkTask(int index){ + public static void unMarkTask(int index){ taskStatusList[index - 1] = false; String message = dashedLine + "\n" + "\tOK, I've marked this task as not done yet: \n" + @@ -80,7 +80,7 @@ public static void main(String[] args) { markTask(indexToMark); } else if(line.startsWith("unmark")){ int indexToUnmark = Integer.parseInt(line.substring(7)); - unmarkTask(indexToUnmark); + unMarkTask(indexToUnmark); } else addToList(line); line = in.nextLine(); } From 45b8d57139b05a3194ebad55d31885673a858e1b Mon Sep 17 00:00:00 2001 From: Aiman Imtiaz Date: Sat, 5 Feb 2022 20:50:57 +0800 Subject: [PATCH 07/24] Level-4 commit --- src/main/java/Deadline.java | 2 ++ src/main/java/Event.java | 2 ++ src/main/java/Todo.java | 2 ++ 3 files changed, 6 insertions(+) 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..623a1f49d --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,2 @@ +package PACKAGE_NAME;public class Deadline { +} diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 000000000..fe6147652 --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,2 @@ +package PACKAGE_NAME;public class Event { +} diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java new file mode 100644 index 000000000..73a10cb4d --- /dev/null +++ b/src/main/java/Todo.java @@ -0,0 +1,2 @@ +package PACKAGE_NAME;public class Todo { +} From 0b3eff583d7ddb2291c515436bd126ca61503a26 Mon Sep 17 00:00:00 2001 From: Aiman Imtiaz Date: Sat, 5 Feb 2022 21:13:38 +0800 Subject: [PATCH 08/24] A-CodeQuality --- src/main/java/Deadline.java | 27 ++++++++++++- src/main/java/Duke.java | 76 +++++++++++++++++++++++-------------- src/main/java/Event.java | 26 ++++++++++++- src/main/java/Task.java | 28 +++++++++++--- src/main/java/Todo.java | 26 ++++++++++++- 5 files changed, 145 insertions(+), 38 deletions(-) diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index 623a1f49d..8b8a373e4 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -1,2 +1,27 @@ -package PACKAGE_NAME;public class Deadline { +public class Deadline extends Todo { + public String taskKind = "[D]"; + protected String by; + + public Deadline(String description, String by) { + super(description); + this.by = by; + } + + @Override + public String toString(){ + String indicator; + if (this.isDone){ + indicator = "[X]"; + } else indicator = "[ ]"; + String message = "[D]" + indicator + description + + " (by: " + by + ")"; + return message; + } + public void setBy(String by) { + this.by = by; + } + + public String getBy() { + return by; + } } diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 877d36412..d5481c010 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -3,49 +3,44 @@ public class Duke { static Task[] taskList = new Task[100]; - static Boolean[] taskStatusList = new Boolean [100]; static int currentCount = 0; - static String dashedLine = "\t____________________________________________________________"; + final static String DASHED_LINE = "\t____________________________________________________________"; public static void markTask(int index){ - taskStatusList[index - 1] = true; - String message = dashedLine + "\n" + + taskList[index - 1].setDone(true); + String message = DASHED_LINE + "\n" + "\t Nice! I've marked this task as done: \n" + - "\t \t [X] " + taskList[index - 1].task + "\n" + - dashedLine ; + "\t \t" + taskList[index - 1].toString() + "\n" + + DASHED_LINE; System.out.println(message); } public static void unMarkTask(int index){ - taskStatusList[index - 1] = false; - String message = dashedLine + "\n" + + taskList[index - 1].setDone(false); + String message = DASHED_LINE + "\n" + "\tOK, I've marked this task as not done yet: \n" + - "\t \t [ ] " + taskList[index - 1].task + "\n" + - dashedLine ; + "\t \t" + taskList[index - 1].toString() + "\n" + + DASHED_LINE; System.out.println(message); } - public static void addToList(String line){ - taskList[currentCount] = new Task(line); - taskStatusList[currentCount] = false; - currentCount += 1; - String message = dashedLine + "\n" + - "\t" + "added:" + line + "\n" + - dashedLine; + public static void printAddedItem(Task task){ + String message = DASHED_LINE + "\n" + + "\t Got it. I've added this task:" + "\n" + + "\t \t" + task.toString() + "\n" + + "\t Now you have " + currentCount + + " tasks in the list." + "\n" + + DASHED_LINE; System.out.println(message); } public static void printList(){ - System.out.print(dashedLine); + System.out.print(DASHED_LINE); for (int j = 0; j < currentCount; j++){ - String indicator; - if (taskStatusList[j]){ - indicator = "[X]"; - } else indicator = "[ ]"; System.out.print("\n"); - System.out.print("\t" + (j+1) + "." + indicator + " " + taskList[j].task); + System.out.print("\t" + (j+1) + "." + taskList[j].toString()); } - System.out.println("\n" + dashedLine); + System.out.println("\n" + DASHED_LINE); } public static void main(String[] args) { @@ -59,19 +54,20 @@ public static void main(String[] args) { + "|____/ \\__,_|_|\\_\\___|\n"; System.out.println("Hello from\n" + logo); - String greeting = dashedLine + "\n" + + String greeting = DASHED_LINE + "\n" + "\t Hello! I'm Duke\n" + "\t What can I do for you?\n" + - dashedLine; + DASHED_LINE; - String bye = dashedLine + "\n" + + String bye = DASHED_LINE + "\n" + "\t Bye. Hope to see you again soon!\n" + - dashedLine; + DASHED_LINE; System.out.println(greeting); line = in.nextLine(); + while (!line.contains("bye")){ if (line.equals("list")){ printList(); @@ -81,7 +77,29 @@ public static void main(String[] args) { } else if(line.startsWith("unmark")){ int indexToUnmark = Integer.parseInt(line.substring(7)); unMarkTask(indexToUnmark); - } else addToList(line); + } else if (line.startsWith("todo")){ + String todoDescription = line.substring(4); + Todo task = new Todo(todoDescription); + taskList[currentCount] = task; + currentCount += 1; + printAddedItem(task); + } else if (line.startsWith("deadline")){ + int byIndex = line.indexOf("/by"); + String deadlineDescription = line.substring(8, byIndex - 1); + String by = line.substring(byIndex + 3); + Deadline task = new Deadline(deadlineDescription, by); + taskList[currentCount] = task; + currentCount += 1; + printAddedItem(task); + } else if (line.startsWith("event")){ + int atIndex = line.indexOf("/at"); + String eventDescription = line.substring(5, atIndex - 1); + String at = line.substring(atIndex + 3); + Event task = new Event(eventDescription, at); + taskList[currentCount] = task; + currentCount += 1; + printAddedItem(task); + } line = in.nextLine(); } diff --git a/src/main/java/Event.java b/src/main/java/Event.java index fe6147652..cd2f6fe84 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -1,2 +1,26 @@ -package PACKAGE_NAME;public class Event { +public class Event extends Todo { + public String taskKind = "[E]"; + protected String at; + + public Event(String description, String at) { + super(description); + this.at = at; + } + + @Override + public String toString(){ + String indicator; + if (this.isDone){ + indicator = "[X]"; + } else indicator = "[ ]"; + String message = "[D]" + indicator + description + + " (at: " + at + ")"; + return message; + } + public void setAt(String at) { + this.at = at; + } + public String getAt() { + return at; + } } diff --git a/src/main/java/Task.java b/src/main/java/Task.java index af692447c..e21c62092 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -1,7 +1,25 @@ -public class Task { - String task; +public abstract class Task { + private boolean isDone; + public String taskKind = "[ ]"; + protected String description; + public Task(String description) { + this.description = description; + } + + @Override + public String toString(){ + return "description: " + description; + } + + public void setDone(boolean done) { + this.isDone = done; + } + + public boolean isDone() { + return isDone; + } - public Task(String task){ - this.task = task; + public String getDescription() { + return description; } -} +} \ No newline at end of file diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java index 73a10cb4d..28d7df27a 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/Todo.java @@ -1,2 +1,24 @@ -package PACKAGE_NAME;public class Todo { -} +public class Todo extends Task { + public String taskKind = "[T]"; + protected boolean isDone = false; + public Todo(String description) { + super(description); + isDone = false; + } + + @Override + public String toString(){ + String indicator; + if (this.isDone){ + indicator = "[X]"; + } else indicator = "[ ]"; + String message = "[T]" + indicator + description; + return message; + } + public void setDone(boolean done) { + isDone = done; + } + public boolean isDone() { + return isDone; + } +} \ No newline at end of file From e342d67bf305c68e8cfc3ea0c7cb6c62ae9a976e Mon Sep 17 00:00:00 2001 From: Aiman Imtiaz Date: Sun, 6 Feb 2022 18:12:52 +0800 Subject: [PATCH 09/24] Level-5 changes --- src/main/java/IllegalDescription.java | 2 ++ src/main/java/IllegalKeyword.java | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 src/main/java/IllegalDescription.java create mode 100644 src/main/java/IllegalKeyword.java diff --git a/src/main/java/IllegalDescription.java b/src/main/java/IllegalDescription.java new file mode 100644 index 000000000..7d698614d --- /dev/null +++ b/src/main/java/IllegalDescription.java @@ -0,0 +1,2 @@ +package PACKAGE_NAME;public class IllegalDescription { +} diff --git a/src/main/java/IllegalKeyword.java b/src/main/java/IllegalKeyword.java new file mode 100644 index 000000000..d2fcfa5ec --- /dev/null +++ b/src/main/java/IllegalKeyword.java @@ -0,0 +1,2 @@ +package PACKAGE_NAME;public class IllegalKeyword { +} From f966812f154e9bf06f2ca16684f4bfb38fc1362b Mon Sep 17 00:00:00 2001 From: Aiman Imtiaz Date: Sun, 6 Feb 2022 18:13:05 +0800 Subject: [PATCH 10/24] Level-5 changes --- src/main/java/Duke.java | 93 +++++++++++++++++---------- src/main/java/IllegalDescription.java | 2 +- src/main/java/IllegalKeyword.java | 2 +- 3 files changed, 60 insertions(+), 37 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index d5481c010..8e98efa1b 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -6,7 +6,7 @@ public class Duke { static int currentCount = 0; final static String DASHED_LINE = "\t____________________________________________________________"; - public static void markTask(int index){ + private static void markTask(int index){ taskList[index - 1].setDone(true); String message = DASHED_LINE + "\n" + "\t Nice! I've marked this task as done: \n" + @@ -15,7 +15,7 @@ public static void markTask(int index){ System.out.println(message); } - public static void unMarkTask(int index){ + private static void unMarkTask(int index){ taskList[index - 1].setDone(false); String message = DASHED_LINE + "\n" + "\tOK, I've marked this task as not done yet: \n" + @@ -24,7 +24,7 @@ public static void unMarkTask(int index){ System.out.println(message); } - public static void printAddedItem(Task task){ + private static void printAddedItem(Task task){ String message = DASHED_LINE + "\n" + "\t Got it. I've added this task:" + "\n" + "\t \t" + task.toString() + "\n" + @@ -34,7 +34,7 @@ public static void printAddedItem(Task task){ System.out.println(message); } - public static void printList(){ + private static void printList(){ System.out.print(DASHED_LINE); for (int j = 0; j < currentCount; j++){ System.out.print("\n"); @@ -43,6 +43,8 @@ public static void printList(){ System.out.println("\n" + DASHED_LINE); } + + public static void main(String[] args) { String line; Scanner in = new Scanner(System.in); @@ -69,40 +71,61 @@ public static void main(String[] args) { while (!line.contains("bye")){ - if (line.equals("list")){ - printList(); - } else if (line.startsWith("mark")){ - int indexToMark = Integer.parseInt(line.substring(5)); - markTask(indexToMark); - } else if(line.startsWith("unmark")){ - int indexToUnmark = Integer.parseInt(line.substring(7)); - unMarkTask(indexToUnmark); - } else if (line.startsWith("todo")){ - String todoDescription = line.substring(4); - Todo task = new Todo(todoDescription); - taskList[currentCount] = task; - currentCount += 1; - printAddedItem(task); - } else if (line.startsWith("deadline")){ - int byIndex = line.indexOf("/by"); - String deadlineDescription = line.substring(8, byIndex - 1); - String by = line.substring(byIndex + 3); - Deadline task = new Deadline(deadlineDescription, by); - taskList[currentCount] = task; - currentCount += 1; - printAddedItem(task); - } else if (line.startsWith("event")){ - int atIndex = line.indexOf("/at"); - String eventDescription = line.substring(5, atIndex - 1); - String at = line.substring(atIndex + 3); - Event task = new Event(eventDescription, at); - taskList[currentCount] = task; - currentCount += 1; - printAddedItem(task); + try{ + processLine(line); + + } catch (IllegalKeyword e){ + System.out.println("What are you saying?"); + + } catch (IllegalDescription e){ + System.out.println("No description added."); } + line = in.nextLine(); } - System.out.print(bye); } + + private static void processLine(String line) throws IllegalKeyword, IllegalDescription { + if (line.equals("list")){ + printList(); + } else if (line.startsWith("mark")){ + int indexToMark = Integer.parseInt(line.substring(5)); + markTask(indexToMark); + } else if(line.startsWith("unmark")){ + int indexToUnmark = Integer.parseInt(line.substring(7)); + unMarkTask(indexToUnmark); + } else if (line.startsWith("todo")){ + if (line.length() < 5){ + throw new IllegalDescription(); + } + String todoDescription = line.substring(4); + Todo task = new Todo(todoDescription); + taskList[currentCount] = task; + currentCount += 1; + printAddedItem(task); + } else if (line.startsWith("deadline")){ + if (line.length() < 9 || !line.contains("/by")){ + throw new IllegalDescription(); + } + int byIndex = line.indexOf("/by"); + String deadlineDescription = line.substring(8, byIndex - 1); + String by = line.substring(byIndex + 3); + Deadline task = new Deadline(deadlineDescription, by); + taskList[currentCount] = task; + currentCount += 1; + printAddedItem(task); + } else if (line.startsWith("event")){ + if (line.length() < 6 || !line.contains("/at")){ + throw new IllegalDescription(); + } + int atIndex = line.indexOf("/at"); + String eventDescription = line.substring(5, atIndex - 1); + String at = line.substring(atIndex + 3); + Event task = new Event(eventDescription, at); + taskList[currentCount] = task; + currentCount += 1; + printAddedItem(task); + } else throw new IllegalKeyword(); + } } diff --git a/src/main/java/IllegalDescription.java b/src/main/java/IllegalDescription.java index 7d698614d..e27a258e1 100644 --- a/src/main/java/IllegalDescription.java +++ b/src/main/java/IllegalDescription.java @@ -1,2 +1,2 @@ -package PACKAGE_NAME;public class IllegalDescription { +public class IllegalDescription extends Exception { } diff --git a/src/main/java/IllegalKeyword.java b/src/main/java/IllegalKeyword.java index d2fcfa5ec..867793ff2 100644 --- a/src/main/java/IllegalKeyword.java +++ b/src/main/java/IllegalKeyword.java @@ -1,2 +1,2 @@ -package PACKAGE_NAME;public class IllegalKeyword { +public class IllegalKeyword extends Exception { } From 65e343e7e43d7550469ab701b7cbadd6217a068b Mon Sep 17 00:00:00 2001 From: Aiman Imtiaz Date: Sun, 6 Feb 2022 18:41:16 +0800 Subject: [PATCH 11/24] A-Packages --- src/main/java/{ => duke}/Deadline.java | 0 src/main/java/{ => duke}/Duke.java | 2 ++ src/main/java/{ => duke}/Event.java | 0 src/main/java/{ => duke}/IllegalDescription.java | 0 src/main/java/{ => duke}/IllegalKeyword.java | 0 src/main/java/{ => duke}/Task.java | 0 src/main/java/{ => duke}/Todo.java | 0 7 files changed, 2 insertions(+) rename src/main/java/{ => duke}/Deadline.java (100%) rename src/main/java/{ => duke}/Duke.java (99%) rename src/main/java/{ => duke}/Event.java (100%) rename src/main/java/{ => duke}/IllegalDescription.java (100%) rename src/main/java/{ => duke}/IllegalKeyword.java (100%) rename src/main/java/{ => duke}/Task.java (100%) rename src/main/java/{ => duke}/Todo.java (100%) diff --git a/src/main/java/Deadline.java b/src/main/java/duke/Deadline.java similarity index 100% rename from src/main/java/Deadline.java rename to src/main/java/duke/Deadline.java diff --git a/src/main/java/Duke.java b/src/main/java/duke/Duke.java similarity index 99% rename from src/main/java/Duke.java rename to src/main/java/duke/Duke.java index 8e98efa1b..8327cf7da 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,3 +1,5 @@ + + import java.util.Scanner; public class Duke { diff --git a/src/main/java/Event.java b/src/main/java/duke/Event.java similarity index 100% rename from src/main/java/Event.java rename to src/main/java/duke/Event.java diff --git a/src/main/java/IllegalDescription.java b/src/main/java/duke/IllegalDescription.java similarity index 100% rename from src/main/java/IllegalDescription.java rename to src/main/java/duke/IllegalDescription.java diff --git a/src/main/java/IllegalKeyword.java b/src/main/java/duke/IllegalKeyword.java similarity index 100% rename from src/main/java/IllegalKeyword.java rename to src/main/java/duke/IllegalKeyword.java diff --git a/src/main/java/Task.java b/src/main/java/duke/Task.java similarity index 100% rename from src/main/java/Task.java rename to src/main/java/duke/Task.java diff --git a/src/main/java/Todo.java b/src/main/java/duke/Todo.java similarity index 100% rename from src/main/java/Todo.java rename to src/main/java/duke/Todo.java From 4075505bd8c43a4755edf77dcdfc83fbca953063 Mon Sep 17 00:00:00 2001 From: Aiman Imtiaz Date: Sun, 6 Feb 2022 18:41:23 +0800 Subject: [PATCH 12/24] A-Packages --- src/main/java/duke/Deadline.java | 2 ++ src/main/java/duke/Duke.java | 22 +++++++++++++++++++--- src/main/java/duke/Event.java | 2 ++ src/main/java/duke/IllegalDescription.java | 1 + src/main/java/duke/IllegalKeyword.java | 1 + src/main/java/duke/Task.java | 2 ++ src/main/java/duke/Todo.java | 2 ++ 7 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/main/java/duke/Deadline.java b/src/main/java/duke/Deadline.java index 8b8a373e4..bd269e685 100644 --- a/src/main/java/duke/Deadline.java +++ b/src/main/java/duke/Deadline.java @@ -1,3 +1,5 @@ +package duke; + public class Deadline extends Todo { public String taskKind = "[D]"; protected String by; diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 8327cf7da..d8d60ea84 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,4 +1,4 @@ - +package duke; import java.util.Scanner; @@ -45,6 +45,22 @@ private static void printList(){ System.out.println("\n" + DASHED_LINE); } + private static void printIllegalKeyword(){ + String message = DASHED_LINE + "\n" + + "\t You typed an illegal keyword." + "\n" + + "\t I have no idea what you are trying to say. :(" + "\n" + + DASHED_LINE; + System.out.println(message); + } + + private static void printIllegalDescription(){ + String message = DASHED_LINE + "\n" + + "\t You did not add any description." + "\n" + + "\t I can't do much. Try again!" + "\n" + + DASHED_LINE; + System.out.println(message); + } + public static void main(String[] args) { @@ -77,10 +93,10 @@ public static void main(String[] args) { processLine(line); } catch (IllegalKeyword e){ - System.out.println("What are you saying?"); + printIllegalKeyword(); } catch (IllegalDescription e){ - System.out.println("No description added."); + printIllegalDescription(); } line = in.nextLine(); diff --git a/src/main/java/duke/Event.java b/src/main/java/duke/Event.java index cd2f6fe84..02df0db8b 100644 --- a/src/main/java/duke/Event.java +++ b/src/main/java/duke/Event.java @@ -1,3 +1,5 @@ +package duke; + public class Event extends Todo { public String taskKind = "[E]"; protected String at; diff --git a/src/main/java/duke/IllegalDescription.java b/src/main/java/duke/IllegalDescription.java index e27a258e1..31f6bf3d6 100644 --- a/src/main/java/duke/IllegalDescription.java +++ b/src/main/java/duke/IllegalDescription.java @@ -1,2 +1,3 @@ +package duke; public class IllegalDescription extends Exception { } diff --git a/src/main/java/duke/IllegalKeyword.java b/src/main/java/duke/IllegalKeyword.java index 867793ff2..5cb16c730 100644 --- a/src/main/java/duke/IllegalKeyword.java +++ b/src/main/java/duke/IllegalKeyword.java @@ -1,2 +1,3 @@ +package duke; public class IllegalKeyword extends Exception { } diff --git a/src/main/java/duke/Task.java b/src/main/java/duke/Task.java index e21c62092..c92861e9a 100644 --- a/src/main/java/duke/Task.java +++ b/src/main/java/duke/Task.java @@ -1,3 +1,5 @@ +package duke; + public abstract class Task { private boolean isDone; public String taskKind = "[ ]"; diff --git a/src/main/java/duke/Todo.java b/src/main/java/duke/Todo.java index 28d7df27a..03c36f984 100644 --- a/src/main/java/duke/Todo.java +++ b/src/main/java/duke/Todo.java @@ -1,3 +1,5 @@ +package duke; + public class Todo extends Task { public String taskKind = "[T]"; protected boolean isDone = false; From 358bfbb83ba37ef224835a662b8871b56445cf40 Mon Sep 17 00:00:00 2001 From: Aiman Imtiaz Date: Thu, 10 Feb 2022 11:03:09 +0800 Subject: [PATCH 13/24] A-Exceptions --- src/main/java/duke/Duke.java | 14 +++++++------- src/main/java/duke/DukeIllegalDescription.java | 3 +++ src/main/java/duke/DukeIllegalKeyword.java | 3 +++ src/main/java/duke/IllegalDescription.java | 3 --- src/main/java/duke/IllegalKeyword.java | 3 --- 5 files changed, 13 insertions(+), 13 deletions(-) create mode 100644 src/main/java/duke/DukeIllegalDescription.java create mode 100644 src/main/java/duke/DukeIllegalKeyword.java delete mode 100644 src/main/java/duke/IllegalDescription.java delete mode 100644 src/main/java/duke/IllegalKeyword.java diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index d8d60ea84..f264f9fa4 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -92,10 +92,10 @@ public static void main(String[] args) { try{ processLine(line); - } catch (IllegalKeyword e){ + } catch (DukeIllegalKeyword e){ printIllegalKeyword(); - } catch (IllegalDescription e){ + } catch (DukeIllegalDescription e){ printIllegalDescription(); } @@ -104,7 +104,7 @@ public static void main(String[] args) { System.out.print(bye); } - private static void processLine(String line) throws IllegalKeyword, IllegalDescription { + private static void processLine(String line) throws DukeIllegalKeyword, DukeIllegalDescription { if (line.equals("list")){ printList(); } else if (line.startsWith("mark")){ @@ -115,7 +115,7 @@ private static void processLine(String line) throws IllegalKeyword, IllegalDescr unMarkTask(indexToUnmark); } else if (line.startsWith("todo")){ if (line.length() < 5){ - throw new IllegalDescription(); + throw new DukeIllegalDescription(); } String todoDescription = line.substring(4); Todo task = new Todo(todoDescription); @@ -124,7 +124,7 @@ private static void processLine(String line) throws IllegalKeyword, IllegalDescr printAddedItem(task); } else if (line.startsWith("deadline")){ if (line.length() < 9 || !line.contains("/by")){ - throw new IllegalDescription(); + throw new DukeIllegalDescription(); } int byIndex = line.indexOf("/by"); String deadlineDescription = line.substring(8, byIndex - 1); @@ -135,7 +135,7 @@ private static void processLine(String line) throws IllegalKeyword, IllegalDescr printAddedItem(task); } else if (line.startsWith("event")){ if (line.length() < 6 || !line.contains("/at")){ - throw new IllegalDescription(); + throw new DukeIllegalDescription(); } int atIndex = line.indexOf("/at"); String eventDescription = line.substring(5, atIndex - 1); @@ -144,6 +144,6 @@ private static void processLine(String line) throws IllegalKeyword, IllegalDescr taskList[currentCount] = task; currentCount += 1; printAddedItem(task); - } else throw new IllegalKeyword(); + } else throw new DukeIllegalKeyword(); } } diff --git a/src/main/java/duke/DukeIllegalDescription.java b/src/main/java/duke/DukeIllegalDescription.java new file mode 100644 index 000000000..7279cd0de --- /dev/null +++ b/src/main/java/duke/DukeIllegalDescription.java @@ -0,0 +1,3 @@ +package duke; +public class DukeIllegalDescription extends Exception { +} diff --git a/src/main/java/duke/DukeIllegalKeyword.java b/src/main/java/duke/DukeIllegalKeyword.java new file mode 100644 index 000000000..80a8259ef --- /dev/null +++ b/src/main/java/duke/DukeIllegalKeyword.java @@ -0,0 +1,3 @@ +package duke; +public class DukeIllegalKeyword extends Exception { +} diff --git a/src/main/java/duke/IllegalDescription.java b/src/main/java/duke/IllegalDescription.java deleted file mode 100644 index 31f6bf3d6..000000000 --- a/src/main/java/duke/IllegalDescription.java +++ /dev/null @@ -1,3 +0,0 @@ -package duke; -public class IllegalDescription extends Exception { -} diff --git a/src/main/java/duke/IllegalKeyword.java b/src/main/java/duke/IllegalKeyword.java deleted file mode 100644 index 5cb16c730..000000000 --- a/src/main/java/duke/IllegalKeyword.java +++ /dev/null @@ -1,3 +0,0 @@ -package duke; -public class IllegalKeyword extends Exception { -} From 8cf48ca42b78474fe8c38574e4cae2a141989882 Mon Sep 17 00:00:00 2001 From: Aiman Imtiaz Date: Sat, 12 Feb 2022 15:52:48 +0800 Subject: [PATCH 14/24] A-Collections --- src/main/java/duke/Duke.java | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index f264f9fa4..0a7d36219 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,27 +1,28 @@ package duke; +import java.util.ArrayList; import java.util.Scanner; public class Duke { - static Task[] taskList = new Task[100]; - static int currentCount = 0; + static ArrayList taskList = new ArrayList(); +// static int currentCount = 0; final static String DASHED_LINE = "\t____________________________________________________________"; private static void markTask(int index){ - taskList[index - 1].setDone(true); + taskList.get(index - 1).setDone(true); String message = DASHED_LINE + "\n" + "\t Nice! I've marked this task as done: \n" + - "\t \t" + taskList[index - 1].toString() + "\n" + + "\t \t" + taskList.get(index - 1).toString() + "\n" + DASHED_LINE; System.out.println(message); } private static void unMarkTask(int index){ - taskList[index - 1].setDone(false); + taskList.get(index - 1).setDone(false); String message = DASHED_LINE + "\n" + "\tOK, I've marked this task as not done yet: \n" + - "\t \t" + taskList[index - 1].toString() + "\n" + + "\t \t" + taskList.get(index - 1).toString() + "\n" + DASHED_LINE; System.out.println(message); } @@ -30,7 +31,7 @@ private static void printAddedItem(Task task){ String message = DASHED_LINE + "\n" + "\t Got it. I've added this task:" + "\n" + "\t \t" + task.toString() + "\n" + - "\t Now you have " + currentCount + + "\t Now you have " + taskList.size() + " tasks in the list." + "\n" + DASHED_LINE; System.out.println(message); @@ -38,9 +39,9 @@ private static void printAddedItem(Task task){ private static void printList(){ System.out.print(DASHED_LINE); - for (int j = 0; j < currentCount; j++){ + for (int j = 0; j < taskList.size(); j++){ System.out.print("\n"); - System.out.print("\t" + (j+1) + "." + taskList[j].toString()); + System.out.print("\t" + (j+1) + "." + taskList.get(j).toString()); } System.out.println("\n" + DASHED_LINE); } @@ -119,8 +120,8 @@ private static void processLine(String line) throws DukeIllegalKeyword, DukeIlle } String todoDescription = line.substring(4); Todo task = new Todo(todoDescription); - taskList[currentCount] = task; - currentCount += 1; + taskList.add(task); +// currentCount += 1; printAddedItem(task); } else if (line.startsWith("deadline")){ if (line.length() < 9 || !line.contains("/by")){ @@ -130,8 +131,8 @@ private static void processLine(String line) throws DukeIllegalKeyword, DukeIlle String deadlineDescription = line.substring(8, byIndex - 1); String by = line.substring(byIndex + 3); Deadline task = new Deadline(deadlineDescription, by); - taskList[currentCount] = task; - currentCount += 1; + taskList.add(task); +// currentCount += 1; printAddedItem(task); } else if (line.startsWith("event")){ if (line.length() < 6 || !line.contains("/at")){ @@ -141,8 +142,8 @@ private static void processLine(String line) throws DukeIllegalKeyword, DukeIlle String eventDescription = line.substring(5, atIndex - 1); String at = line.substring(atIndex + 3); Event task = new Event(eventDescription, at); - taskList[currentCount] = task; - currentCount += 1; + taskList.add(task); +// currentCount += 1; printAddedItem(task); } else throw new DukeIllegalKeyword(); } From e94392e3b373dacc91bd7e24ad177ab352adbe14 Mon Sep 17 00:00:00 2001 From: Aiman Imtiaz Date: Sat, 12 Feb 2022 16:01:58 +0800 Subject: [PATCH 15/24] Level-6 --- src/main/java/duke/Duke.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 0a7d36219..ba711104d 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -37,6 +37,16 @@ private static void printAddedItem(Task task){ System.out.println(message); } + private static void printDeletedItem(Task task){ + String message = DASHED_LINE + "\n" + + "\t Got it. I've removed this task:" + "\n" + + "\t \t" + task.toString() + "\n" + + "\t Now you have " + taskList.size() + + " tasks in the list." + "\n" + + DASHED_LINE; + System.out.println(message); + } + private static void printList(){ System.out.print(DASHED_LINE); for (int j = 0; j < taskList.size(); j++){ @@ -145,6 +155,14 @@ private static void processLine(String line) throws DukeIllegalKeyword, DukeIlle taskList.add(task); // currentCount += 1; printAddedItem(task); + } else if (line.startsWith("delete")) { + if (line.length() < 8) { + throw new DukeIllegalDescription(); + } + int indexToDelete = Integer.parseInt(line.substring(7)); + Task deletedTask = taskList.get(indexToDelete); + taskList.remove(indexToDelete); + printDeletedItem(deletedTask); } else throw new DukeIllegalKeyword(); } } From 583ad592573f8661077ca71a6b534a3b9cabc170 Mon Sep 17 00:00:00 2001 From: Aiman Imtiaz Date: Sat, 12 Feb 2022 17:15:55 +0800 Subject: [PATCH 16/24] Level-7 --- src/main/java/duke/Duke.java | 10 ++- src/main/java/duke/FileAccess.java | 114 +++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+), 3 deletions(-) create mode 100644 src/main/java/duke/FileAccess.java diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index f264f9fa4..34e589775 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,6 +1,9 @@ package duke; +import java.io.FileWriter; +import java.io.IOException; import java.util.Scanner; +import java.io.File; public class Duke { @@ -61,9 +64,7 @@ private static void printIllegalDescription(){ System.out.println(message); } - - - public static void main(String[] args) { + public static void main(String[] args) throws IOException { String line; Scanner in = new Scanner(System.in); @@ -74,6 +75,8 @@ public static void main(String[] args) { + "|____/ \\__,_|_|\\_\\___|\n"; System.out.println("Hello from\n" + logo); + FileAccess.loadFromFile(); + String greeting = DASHED_LINE + "\n" + "\t Hello! I'm Duke\n" + "\t What can I do for you?\n" + @@ -102,6 +105,7 @@ public static void main(String[] args) { line = in.nextLine(); } System.out.print(bye); + FileAccess.saveToFile(); } private static void processLine(String line) throws DukeIllegalKeyword, DukeIllegalDescription { diff --git a/src/main/java/duke/FileAccess.java b/src/main/java/duke/FileAccess.java new file mode 100644 index 000000000..8056f75e8 --- /dev/null +++ b/src/main/java/duke/FileAccess.java @@ -0,0 +1,114 @@ +package duke; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +public class FileAccess { + final static String FILE_NAME = "ip/data/duke.txt"; + + private static int boolToInt(boolean b) { + return Boolean.compare(b, false); + } + + private static void writeToFile(String filePath, String textToAdd) throws IOException { + FileWriter fw = new FileWriter(filePath); + fw.write(textToAdd); + fw.close(); + } + + private static void readFromFile(String filePath) throws FileNotFoundException { + File f = new File(filePath); // create a File for the given file path + Scanner s = new Scanner(f); // create a Scanner using the File as the source + while (s.hasNext()) { + Task task = lineToTask(s.nextLine()); + Duke.taskList.add(task); + } + } + + private static Task lineToTask(String line){ + Task task = null; + int isDoneInt = 0; + char indicator = line.charAt(0); + switch (indicator) { + case 'D': + int byIndex = line.indexOf("|", 4); + String deadlineDescription = line.substring(8, byIndex - 2); + String by = line.substring(byIndex + 2); + task = new Deadline(deadlineDescription, by); + isDoneInt = Integer.parseInt(line.substring(4)); + if (isDoneInt != 0) task.setDone(true); + break; + case 'E': + int atIndex = line.indexOf("|", 4); + String eventDescription = line.substring(8, atIndex - 2); + String at = line.substring(atIndex + 2); + task = new Event(eventDescription, at); + isDoneInt = Integer.parseInt(line.substring(4)); + if (isDoneInt != 0) task.setDone(true); + break; + case 'T': + String todoDescription = line.substring(8); + task = new Todo(todoDescription); + isDoneInt = Integer.parseInt(line.substring(4)); + if (isDoneInt != 0) task.setDone(true); + break; + } + return task; + } + + private static String taskToLine(Task task) { + String line = ""; + switch (task.taskKind) { + case "[D]": + Deadline deadline = (Deadline) task; + line = "D" + " | " + + boolToInt(deadline.isDone()) + + " | " + deadline.description + + " | " + deadline.getBy(); + break; + case "E": + Event event = (Event) task; + line = "E" + " | " + + boolToInt(event.isDone()) + + " | " + event.description + + " | " + event.getAt(); + break; + case "[T]": + Todo todo = (Todo) task; + line = "T" + " | " + + boolToInt(todo.isDone()) + + " | " + todo.description; + break; + default: + // code block + } + return line; + } + + public static void saveToFile() throws IOException { + String line; + try { + for (Task task: Duke.taskList){ + line = taskToLine(task); + writeToFile(FILE_NAME, line + System.lineSeparator()); + } + } catch (IOException e) { + System.out.println("Something went wrong: " + e.getMessage()); + } + } + + public static void loadFromFile(){ + try { + readFromFile(FILE_NAME); + } catch (FileNotFoundException e) { + System.out.println("File not found"); + } + } + + + + +} From ad34576179d52926c91e520f250d567af5a8f7ed Mon Sep 17 00:00:00 2001 From: Aiman Imtiaz Date: Sat, 12 Feb 2022 21:03:29 +0800 Subject: [PATCH 17/24] fixed some errors --- src/main/java/duke/Duke.java | 4 ++-- src/main/java/duke/FileAccess.java | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index b741b8fc9..461629449 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,12 +1,12 @@ package duke; +import java.io.IOException; import java.util.ArrayList; import java.util.Scanner; -import java.io.File; public class Duke { - static ArrayList taskList = new ArrayList(); + static ArrayList taskList = new ArrayList<>(); // static int currentCount = 0; final static String DASHED_LINE = "\t____________________________________________________________"; diff --git a/src/main/java/duke/FileAccess.java b/src/main/java/duke/FileAccess.java index 8056f75e8..3d6b42e26 100644 --- a/src/main/java/duke/FileAccess.java +++ b/src/main/java/duke/FileAccess.java @@ -13,14 +13,14 @@ private static int boolToInt(boolean b) { return Boolean.compare(b, false); } - private static void writeToFile(String filePath, String textToAdd) throws IOException { - FileWriter fw = new FileWriter(filePath); + private static void writeToFile(String textToAdd) throws IOException { + FileWriter fw = new FileWriter(FileAccess.FILE_NAME); fw.write(textToAdd); fw.close(); } - private static void readFromFile(String filePath) throws FileNotFoundException { - File f = new File(filePath); // create a File for the given file path + private static void readFromFile() throws FileNotFoundException { + File f = new File(FileAccess.FILE_NAME); // create a File for the given file path Scanner s = new Scanner(f); // create a Scanner using the File as the source while (s.hasNext()) { Task task = lineToTask(s.nextLine()); @@ -30,7 +30,7 @@ private static void readFromFile(String filePath) throws FileNotFoundException { private static Task lineToTask(String line){ Task task = null; - int isDoneInt = 0; + int isDoneInt; char indicator = line.charAt(0); switch (indicator) { case 'D': @@ -88,12 +88,12 @@ private static String taskToLine(Task task) { return line; } - public static void saveToFile() throws IOException { + public static void saveToFile(){ String line; try { for (Task task: Duke.taskList){ line = taskToLine(task); - writeToFile(FILE_NAME, line + System.lineSeparator()); + writeToFile(line + System.lineSeparator()); } } catch (IOException e) { System.out.println("Something went wrong: " + e.getMessage()); @@ -102,7 +102,7 @@ public static void saveToFile() throws IOException { public static void loadFromFile(){ try { - readFromFile(FILE_NAME); + readFromFile(); } catch (FileNotFoundException e) { System.out.println("File not found"); } From c249ac66f5264ef8909db5d8fba9cb861f6728e8 Mon Sep 17 00:00:00 2001 From: Aiman Imtiaz Date: Fri, 4 Mar 2022 21:39:44 +0800 Subject: [PATCH 18/24] A-MoreOOP --- data/duke.txt | 1 + src/main/java/META-INF/MANIFEST.MF | 3 + src/main/java/duke/Duke.java | 166 +---------------------------- src/main/java/duke/FileAccess.java | 6 +- src/main/java/duke/Run.java | 34 ++++++ src/main/java/duke/TaskList.java | 7 ++ src/main/java/duke/UI.java | 136 +++++++++++++++++++++++ 7 files changed, 186 insertions(+), 167 deletions(-) create mode 100644 data/duke.txt create mode 100644 src/main/java/META-INF/MANIFEST.MF create mode 100644 src/main/java/duke/Run.java create mode 100644 src/main/java/duke/TaskList.java create mode 100644 src/main/java/duke/UI.java diff --git a/data/duke.txt b/data/duke.txt new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/data/duke.txt @@ -0,0 +1 @@ + diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 000000000..6e864153e --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: duke.Duke + diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 461629449..95dc0a551 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,170 +1,8 @@ package duke; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Scanner; - public class Duke { - static ArrayList taskList = new ArrayList<>(); -// static int currentCount = 0; - final static String DASHED_LINE = "\t____________________________________________________________"; - - private static void markTask(int index){ - taskList.get(index - 1).setDone(true); - String message = DASHED_LINE + "\n" + - "\t Nice! I've marked this task as done: \n" + - "\t \t" + taskList.get(index - 1).toString() + "\n" + - DASHED_LINE; - System.out.println(message); - } - - private static void unMarkTask(int index){ - taskList.get(index - 1).setDone(false); - String message = DASHED_LINE + "\n" + - "\tOK, I've marked this task as not done yet: \n" + - "\t \t" + taskList.get(index - 1).toString() + "\n" + - DASHED_LINE; - System.out.println(message); - } - - private static void printAddedItem(Task task){ - String message = DASHED_LINE + "\n" + - "\t Got it. I've added this task:" + "\n" + - "\t \t" + task.toString() + "\n" + - "\t Now you have " + taskList.size() + - " tasks in the list." + "\n" + - DASHED_LINE; - System.out.println(message); - } - - private static void printDeletedItem(Task task){ - String message = DASHED_LINE + "\n" + - "\t Got it. I've removed this task:" + "\n" + - "\t \t" + task.toString() + "\n" + - "\t Now you have " + taskList.size() + - " tasks in the list." + "\n" + - DASHED_LINE; - System.out.println(message); - } - - private static void printList(){ - System.out.print(DASHED_LINE); - for (int j = 0; j < taskList.size(); j++){ - System.out.print("\n"); - System.out.print("\t" + (j+1) + "." + taskList.get(j).toString()); - } - System.out.println("\n" + DASHED_LINE); - } - - private static void printIllegalKeyword(){ - String message = DASHED_LINE + "\n" + - "\t You typed an illegal keyword." + "\n" + - "\t I have no idea what you are trying to say. :(" + "\n" + - DASHED_LINE; - System.out.println(message); - } - - private static void printIllegalDescription(){ - String message = DASHED_LINE + "\n" + - "\t You did not add any description." + "\n" + - "\t I can't do much. Try again!" + "\n" + - DASHED_LINE; - System.out.println(message); - } - - public static void main(String[] args) throws IOException { - String line; - Scanner in = new Scanner(System.in); - - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - - FileAccess.loadFromFile(); - - String greeting = DASHED_LINE + "\n" + - "\t Hello! I'm Duke\n" + - "\t What can I do for you?\n" + - DASHED_LINE; - - String bye = DASHED_LINE + "\n" + - "\t Bye. Hope to see you again soon!\n" + - DASHED_LINE; - - System.out.println(greeting); - - line = in.nextLine(); - - - while (!line.contains("bye")){ - try{ - processLine(line); - - } catch (DukeIllegalKeyword e){ - printIllegalKeyword(); - - } catch (DukeIllegalDescription e){ - printIllegalDescription(); - } - - line = in.nextLine(); - } - System.out.print(bye); - FileAccess.saveToFile(); - } - - private static void processLine(String line) throws DukeIllegalKeyword, DukeIllegalDescription { - if (line.equals("list")){ - printList(); - } else if (line.startsWith("mark")){ - int indexToMark = Integer.parseInt(line.substring(5)); - markTask(indexToMark); - } else if(line.startsWith("unmark")){ - int indexToUnmark = Integer.parseInt(line.substring(7)); - unMarkTask(indexToUnmark); - } else if (line.startsWith("todo")){ - if (line.length() < 5){ - throw new DukeIllegalDescription(); - } - String todoDescription = line.substring(4); - Todo task = new Todo(todoDescription); - taskList.add(task); -// currentCount += 1; - printAddedItem(task); - } else if (line.startsWith("deadline")){ - if (line.length() < 9 || !line.contains("/by")){ - throw new DukeIllegalDescription(); - } - int byIndex = line.indexOf("/by"); - String deadlineDescription = line.substring(8, byIndex - 1); - String by = line.substring(byIndex + 3); - Deadline task = new Deadline(deadlineDescription, by); - taskList.add(task); -// currentCount += 1; - printAddedItem(task); - } else if (line.startsWith("event")){ - if (line.length() < 6 || !line.contains("/at")){ - throw new DukeIllegalDescription(); - } - int atIndex = line.indexOf("/at"); - String eventDescription = line.substring(5, atIndex - 1); - String at = line.substring(atIndex + 3); - Event task = new Event(eventDescription, at); - taskList.add(task); -// currentCount += 1; - printAddedItem(task); - } else if (line.startsWith("delete")) { - if (line.length() < 8) { - throw new DukeIllegalDescription(); - } - int indexToDelete = Integer.parseInt(line.substring(7)); - Task deletedTask = taskList.get(indexToDelete); - taskList.remove(indexToDelete); - printDeletedItem(deletedTask); - } else throw new DukeIllegalKeyword(); + public static void main(String[] args) { + Run.run(); } } diff --git a/src/main/java/duke/FileAccess.java b/src/main/java/duke/FileAccess.java index 3d6b42e26..0e69e8d9b 100644 --- a/src/main/java/duke/FileAccess.java +++ b/src/main/java/duke/FileAccess.java @@ -7,7 +7,7 @@ import java.util.Scanner; public class FileAccess { - final static String FILE_NAME = "ip/data/duke.txt"; + final static String FILE_NAME = "/Users/aimanimtiaz/software-engineering/ip/data/duke.txt"; private static int boolToInt(boolean b) { return Boolean.compare(b, false); @@ -24,7 +24,7 @@ private static void readFromFile() throws FileNotFoundException { Scanner s = new Scanner(f); // create a Scanner using the File as the source while (s.hasNext()) { Task task = lineToTask(s.nextLine()); - Duke.taskList.add(task); + TaskList.taskList.add(task); } } @@ -91,7 +91,7 @@ private static String taskToLine(Task task) { public static void saveToFile(){ String line; try { - for (Task task: Duke.taskList){ + for (Task task: TaskList.taskList){ line = taskToLine(task); writeToFile(line + System.lineSeparator()); } diff --git a/src/main/java/duke/Run.java b/src/main/java/duke/Run.java new file mode 100644 index 000000000..ca941682d --- /dev/null +++ b/src/main/java/duke/Run.java @@ -0,0 +1,34 @@ +package duke; + +import java.util.Scanner; + +public class Run { + public static void run(){ + String line; + Scanner in = new Scanner(System.in); + + System.out.println("Hello from\n" + UI.logo); + + FileAccess.loadFromFile(); + + System.out.println(UI.greeting); + + line = in.nextLine(); + + while (!line.contains("bye")){ + try{ + UI.processLine(line); + + } catch (DukeIllegalKeyword e){ + UI.printIllegalKeyword(); + + } catch (DukeIllegalDescription e){ + UI.printIllegalDescription(); + } + + line = in.nextLine(); + } + System.out.print(UI.bye); + FileAccess.saveToFile(); + } +} diff --git a/src/main/java/duke/TaskList.java b/src/main/java/duke/TaskList.java new file mode 100644 index 000000000..a30682bcd --- /dev/null +++ b/src/main/java/duke/TaskList.java @@ -0,0 +1,7 @@ +package duke; + +import java.util.ArrayList; + +public class TaskList { + static ArrayList taskList = new ArrayList<>(); +} diff --git a/src/main/java/duke/UI.java b/src/main/java/duke/UI.java new file mode 100644 index 000000000..0667806d2 --- /dev/null +++ b/src/main/java/duke/UI.java @@ -0,0 +1,136 @@ +package duke; + +public class UI { + + // static int currentCount = 0; + final static String DASHED_LINE = "\t____________________________________________________________"; + + private static void markTask(int index){ + TaskList.taskList.get(index - 1).setDone(true); + String message = DASHED_LINE + "\n" + + "\t Nice! I've marked this task as done: \n" + + "\t \t" + TaskList.taskList.get(index - 1).toString() + "\n" + + DASHED_LINE; + System.out.println(message); + } + + private static void unMarkTask(int index){ + TaskList.taskList.get(index - 1).setDone(false); + String message = DASHED_LINE + "\n" + + "\tOK, I've marked this task as not done yet: \n" + + "\t \t" + TaskList.taskList.get(index - 1).toString() + "\n" + + DASHED_LINE; + System.out.println(message); + } + + private static void printAddedItem(Task task){ + String message = DASHED_LINE + "\n" + + "\t Got it. I've added this task:" + "\n" + + "\t \t" + task.toString() + "\n" + + "\t Now you have " + TaskList.taskList.size() + + " tasks in the list." + "\n" + + DASHED_LINE; + System.out.println(message); + } + + private static void printDeletedItem(Task task){ + String message = DASHED_LINE + "\n" + + "\t Got it. I've removed this task:" + "\n" + + "\t \t" + task.toString() + "\n" + + "\t Now you have " + TaskList.taskList.size() + + " tasks in the list." + "\n" + + DASHED_LINE; + System.out.println(message); + } + + private static void printList(){ + System.out.print(DASHED_LINE); + for (int j = 0; j < TaskList.taskList.size(); j++){ + System.out.print("\n"); + System.out.print("\t" + (j+1) + "." + TaskList.taskList.get(j).toString()); + } + System.out.println("\n" + DASHED_LINE); + } + + static void processLine(String line) throws DukeIllegalKeyword, DukeIllegalDescription { + if (line.equals("list")){ + printList(); + } else if (line.startsWith("mark")){ + int indexToMark = Integer.parseInt(line.substring(5)); + markTask(indexToMark); + } else if(line.startsWith("unmark")){ + int indexToUnmark = Integer.parseInt(line.substring(7)); + unMarkTask(indexToUnmark); + } else if (line.startsWith("todo")){ + if (line.length() < 5){ + throw new DukeIllegalDescription(); + } + String todoDescription = line.substring(4); + Todo task = new Todo(todoDescription); + TaskList.taskList.add(task); +// currentCount += 1; + printAddedItem(task); + } else if (line.startsWith("deadline")){ + if (line.length() < 9 || !line.contains("/by")){ + throw new DukeIllegalDescription(); + } + int byIndex = line.indexOf("/by"); + String deadlineDescription = line.substring(8, byIndex - 1); + String by = line.substring(byIndex + 3); + Deadline task = new Deadline(deadlineDescription, by); + TaskList.taskList.add(task); +// currentCount += 1; + printAddedItem(task); + } else if (line.startsWith("event")){ + if (line.length() < 6 || !line.contains("/at")){ + throw new DukeIllegalDescription(); + } + int atIndex = line.indexOf("/at"); + String eventDescription = line.substring(5, atIndex - 1); + String at = line.substring(atIndex + 3); + Event task = new Event(eventDescription, at); + TaskList.taskList.add(task); +// currentCount += 1; + printAddedItem(task); + } else if (line.startsWith("delete")) { + if (line.length() < 8) { + throw new DukeIllegalDescription(); + } + int indexToDelete = Integer.parseInt(line.substring(7)); + Task deletedTask = TaskList.taskList.get(indexToDelete); + TaskList.taskList.remove(indexToDelete); + printDeletedItem(deletedTask); + } else throw new DukeIllegalKeyword(); + } + + static void printIllegalKeyword(){ + String message = DASHED_LINE + "\n" + + "\t You typed an illegal keyword." + "\n" + + "\t I have no idea what you are trying to say. :(" + "\n" + + DASHED_LINE; + System.out.println(message); + } + + static void printIllegalDescription(){ + String message = DASHED_LINE + "\n" + + "\t You did not add any description." + "\n" + + "\t I can't do much. Try again!" + "\n" + + DASHED_LINE; + System.out.println(message); + } + + final static String logo = " ____ _ \n" + + "| _ \\ _ _| | _____ \n" + + "| | | | | | | |/ / _ \\\n" + + "| |_| | |_| | < __/\n" + + "|____/ \\__,_|_|\\_\\___|\n"; + + final static String greeting = UI.DASHED_LINE + "\n" + + "\t Hello! I'm Duke\n" + + "\t What can I do for you?\n" + + UI.DASHED_LINE; + + final static String bye = UI.DASHED_LINE + "\n" + + "\t Bye. Hope to see you again soon!\n" + + UI.DASHED_LINE; +} From a9f60b21dfe5211c84edf832dc090ae2af82ba28 Mon Sep 17 00:00:00 2001 From: Aiman Imtiaz Date: Fri, 4 Mar 2022 23:02:34 +0800 Subject: [PATCH 19/24] Level-8 --- src/main/java/duke/Deadline.java | 16 ++++++++++------ src/main/java/duke/Duke.java | 4 +++- src/main/java/duke/Event.java | 3 ++- src/main/java/duke/FileAccess.java | 22 +++++++++++++--------- src/main/java/duke/Run.java | 5 +++-- src/main/java/duke/Todo.java | 3 ++- src/main/java/duke/UI.java | 8 +++++--- 7 files changed, 38 insertions(+), 23 deletions(-) diff --git a/src/main/java/duke/Deadline.java b/src/main/java/duke/Deadline.java index bd269e685..f51f53316 100644 --- a/src/main/java/duke/Deadline.java +++ b/src/main/java/duke/Deadline.java @@ -1,12 +1,16 @@ package duke; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + public class Deadline extends Todo { - public String taskKind = "[D]"; - protected String by; + protected LocalDate by; + public String taskKind; - public Deadline(String description, String by) { + public Deadline(String description, LocalDate by) { super(description); this.by = by; + this.taskKind = "[D]"; } @Override @@ -16,14 +20,14 @@ public String toString(){ indicator = "[X]"; } else indicator = "[ ]"; String message = "[D]" + indicator + description - + " (by: " + by + ")"; + + " (by: " + getBy() + ")"; return message; } public void setBy(String by) { - this.by = by; + this.by = LocalDate.parse(by); } public String getBy() { - return by; + return by.format(DateTimeFormatter.ofPattern("MMM d yyyy")); } } diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 95dc0a551..d1bc38bf4 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,8 +1,10 @@ package duke; +import java.io.IOException; + public class Duke { - public static void main(String[] args) { + public static void main(String[] args) throws IOException { Run.run(); } } diff --git a/src/main/java/duke/Event.java b/src/main/java/duke/Event.java index 02df0db8b..2b1c487d7 100644 --- a/src/main/java/duke/Event.java +++ b/src/main/java/duke/Event.java @@ -1,12 +1,13 @@ package duke; public class Event extends Todo { - public String taskKind = "[E]"; + public String taskKind; protected String at; public Event(String description, String at) { super(description); this.at = at; + this.taskKind = "[E]"; } @Override diff --git a/src/main/java/duke/FileAccess.java b/src/main/java/duke/FileAccess.java index 0e69e8d9b..f44bdd596 100644 --- a/src/main/java/duke/FileAccess.java +++ b/src/main/java/duke/FileAccess.java @@ -4,6 +4,7 @@ import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; +import java.time.LocalDate; import java.util.Scanner; public class FileAccess { @@ -13,11 +14,11 @@ private static int boolToInt(boolean b) { return Boolean.compare(b, false); } - private static void writeToFile(String textToAdd) throws IOException { - FileWriter fw = new FileWriter(FileAccess.FILE_NAME); - fw.write(textToAdd); - fw.close(); - } +// private static void writeToFile(String textToAdd) throws IOException { +// FileWriter fw = new FileWriter(FileAccess.FILE_NAME); +// fw.write(textToAdd); +// fw.close(); +// } private static void readFromFile() throws FileNotFoundException { File f = new File(FileAccess.FILE_NAME); // create a File for the given file path @@ -37,7 +38,7 @@ private static Task lineToTask(String line){ int byIndex = line.indexOf("|", 4); String deadlineDescription = line.substring(8, byIndex - 2); String by = line.substring(byIndex + 2); - task = new Deadline(deadlineDescription, by); + task = new Deadline(deadlineDescription, LocalDate.parse(by)); isDoneInt = Integer.parseInt(line.substring(4)); if (isDoneInt != 0) task.setDone(true); break; @@ -69,7 +70,7 @@ private static String taskToLine(Task task) { " | " + deadline.description + " | " + deadline.getBy(); break; - case "E": + case "[E]": Event event = (Event) task; line = "E" + " | " + boolToInt(event.isDone()) + @@ -88,13 +89,16 @@ private static String taskToLine(Task task) { return line; } - public static void saveToFile(){ + public static void saveToFile() throws IOException { String line; try { + FileWriter fw = new FileWriter(FileAccess.FILE_NAME); for (Task task: TaskList.taskList){ line = taskToLine(task); - writeToFile(line + System.lineSeparator()); + fw.append(line + System.lineSeparator()); } + fw.flush(); + fw.close(); } catch (IOException e) { System.out.println("Something went wrong: " + e.getMessage()); } diff --git a/src/main/java/duke/Run.java b/src/main/java/duke/Run.java index ca941682d..b55aa08fb 100644 --- a/src/main/java/duke/Run.java +++ b/src/main/java/duke/Run.java @@ -1,9 +1,10 @@ package duke; +import java.io.IOException; import java.util.Scanner; public class Run { - public static void run(){ + public static void run() throws IOException { String line; Scanner in = new Scanner(System.in); @@ -28,7 +29,7 @@ public static void run(){ line = in.nextLine(); } - System.out.print(UI.bye); FileAccess.saveToFile(); + System.out.print(UI.bye); } } diff --git a/src/main/java/duke/Todo.java b/src/main/java/duke/Todo.java index 03c36f984..006a58419 100644 --- a/src/main/java/duke/Todo.java +++ b/src/main/java/duke/Todo.java @@ -1,11 +1,12 @@ package duke; public class Todo extends Task { - public String taskKind = "[T]"; + public String taskKind; protected boolean isDone = false; public Todo(String description) { super(description); isDone = false; + this.taskKind = "[T]"; } @Override diff --git a/src/main/java/duke/UI.java b/src/main/java/duke/UI.java index 0667806d2..eed03c05e 100644 --- a/src/main/java/duke/UI.java +++ b/src/main/java/duke/UI.java @@ -1,5 +1,7 @@ package duke; +import java.time.LocalDate; + public class UI { // static int currentCount = 0; @@ -76,8 +78,8 @@ static void processLine(String line) throws DukeIllegalKeyword, DukeIllegalDescr } int byIndex = line.indexOf("/by"); String deadlineDescription = line.substring(8, byIndex - 1); - String by = line.substring(byIndex + 3); - Deadline task = new Deadline(deadlineDescription, by); + String by = line.substring(byIndex + 4); + Deadline task = new Deadline(deadlineDescription, LocalDate.parse(by)); TaskList.taskList.add(task); // currentCount += 1; printAddedItem(task); @@ -87,7 +89,7 @@ static void processLine(String line) throws DukeIllegalKeyword, DukeIllegalDescr } int atIndex = line.indexOf("/at"); String eventDescription = line.substring(5, atIndex - 1); - String at = line.substring(atIndex + 3); + String at = line.substring(atIndex + 4); Event task = new Event(eventDescription, at); TaskList.taskList.add(task); // currentCount += 1; From 817a229572fac3faadb1b79b98f30cf11a8243e7 Mon Sep 17 00:00:00 2001 From: Aiman Imtiaz Date: Sat, 5 Mar 2022 12:37:04 +0800 Subject: [PATCH 20/24] Level-9 --- data/duke.txt | 1 - src/main/java/duke/Duke.java | 6 +- src/main/java/duke/FileAccess.java | 80 +------------ src/main/java/duke/Parser.java | 117 +++++++++++++++++++ src/main/java/duke/{Run.java => Runner.java} | 10 +- src/main/java/duke/Searcher.java | 18 +++ src/main/java/duke/UI.java | 72 +++--------- 7 files changed, 166 insertions(+), 138 deletions(-) create mode 100644 src/main/java/duke/Parser.java rename src/main/java/duke/{Run.java => Runner.java} (74%) create mode 100644 src/main/java/duke/Searcher.java diff --git a/data/duke.txt b/data/duke.txt index 8b1378917..e69de29bb 100644 --- a/data/duke.txt +++ b/data/duke.txt @@ -1 +0,0 @@ - diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 95dc0a551..7be303ed9 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,8 +1,10 @@ package duke; +import java.io.IOException; + public class Duke { - public static void main(String[] args) { - Run.run(); + public static void main(String[] args) throws IOException { + Runner.run(); } } diff --git a/src/main/java/duke/FileAccess.java b/src/main/java/duke/FileAccess.java index 0e69e8d9b..a3dd44274 100644 --- a/src/main/java/duke/FileAccess.java +++ b/src/main/java/duke/FileAccess.java @@ -9,92 +9,24 @@ public class FileAccess { final static String FILE_NAME = "/Users/aimanimtiaz/software-engineering/ip/data/duke.txt"; - private static int boolToInt(boolean b) { - return Boolean.compare(b, false); - } - - private static void writeToFile(String textToAdd) throws IOException { - FileWriter fw = new FileWriter(FileAccess.FILE_NAME); - fw.write(textToAdd); - fw.close(); - } - private static void readFromFile() throws FileNotFoundException { File f = new File(FileAccess.FILE_NAME); // create a File for the given file path Scanner s = new Scanner(f); // create a Scanner using the File as the source while (s.hasNext()) { - Task task = lineToTask(s.nextLine()); + Task task = Parser.lineToTask(s.nextLine()); TaskList.taskList.add(task); } } - private static Task lineToTask(String line){ - Task task = null; - int isDoneInt; - char indicator = line.charAt(0); - switch (indicator) { - case 'D': - int byIndex = line.indexOf("|", 4); - String deadlineDescription = line.substring(8, byIndex - 2); - String by = line.substring(byIndex + 2); - task = new Deadline(deadlineDescription, by); - isDoneInt = Integer.parseInt(line.substring(4)); - if (isDoneInt != 0) task.setDone(true); - break; - case 'E': - int atIndex = line.indexOf("|", 4); - String eventDescription = line.substring(8, atIndex - 2); - String at = line.substring(atIndex + 2); - task = new Event(eventDescription, at); - isDoneInt = Integer.parseInt(line.substring(4)); - if (isDoneInt != 0) task.setDone(true); - break; - case 'T': - String todoDescription = line.substring(8); - task = new Todo(todoDescription); - isDoneInt = Integer.parseInt(line.substring(4)); - if (isDoneInt != 0) task.setDone(true); - break; - } - return task; - } - - private static String taskToLine(Task task) { - String line = ""; - switch (task.taskKind) { - case "[D]": - Deadline deadline = (Deadline) task; - line = "D" + " | " + - boolToInt(deadline.isDone()) + - " | " + deadline.description + - " | " + deadline.getBy(); - break; - case "E": - Event event = (Event) task; - line = "E" + " | " + - boolToInt(event.isDone()) + - " | " + event.description + - " | " + event.getAt(); - break; - case "[T]": - Todo todo = (Todo) task; - line = "T" + " | " + - boolToInt(todo.isDone()) + - " | " + todo.description; - break; - default: - // code block - } - return line; - } - - public static void saveToFile(){ + public static void saveToFile() throws IOException { + FileWriter fw = new FileWriter(FileAccess.FILE_NAME); String line; try { for (Task task: TaskList.taskList){ - line = taskToLine(task); - writeToFile(line + System.lineSeparator()); + line = Parser.taskToLine(task); + fw.write(line + System.lineSeparator()); } + fw.close(); } catch (IOException e) { System.out.println("Something went wrong: " + e.getMessage()); } diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java new file mode 100644 index 000000000..5b4f52e28 --- /dev/null +++ b/src/main/java/duke/Parser.java @@ -0,0 +1,117 @@ +package duke; + +public class Parser { + + static Task lineToTask(String line){ + Task task = null; + int isDoneInt; + char indicator = line.charAt(0); + switch (indicator) { + case 'D': + int byIndex = line.indexOf("|", 8); + String deadlineDescription = line.substring(8, byIndex - 1); + String by = line.substring(byIndex + 2); + task = new Deadline(deadlineDescription, by); + isDoneInt = Integer.parseInt(line.substring(4, 5)); + if (isDoneInt != 0) task.setDone(true); + break; + case 'E': + int atIndex = line.indexOf("|", 8); + String eventDescription = line.substring(8, atIndex - 1); + String at = line.substring(atIndex + 2); + task = new Event(eventDescription, at); + isDoneInt = Integer.parseInt(line.substring(4, 5)); + if (isDoneInt != 0) task.setDone(true); + break; + case 'T': + String todoDescription = line.substring(8); + task = new Todo(todoDescription); + isDoneInt = Integer.parseInt(line.substring(4, 5)); + if (isDoneInt != 0) task.setDone(true); + break; + } + return task; + } + + static String taskToLine(Task task) { + String line = ""; + // code block + if (task instanceof Deadline) { + Deadline deadline = (Deadline) task; + line = "D" + " | " + + boolToInt(deadline.isDone()) + + " | " + deadline.description + + " | " + deadline.getBy(); + } else if (task instanceof Event) { + Event event = (Event) task; + line = "E" + " | " + + boolToInt(event.isDone()) + + " | " + event.description + + " | " + event.getAt(); + } else if (task instanceof Todo) { + Todo todo = (Todo) task; + line = "T" + " | " + + boolToInt(todo.isDone()) + + " | " + todo.description; + } + return line; + } + + private static int boolToInt(boolean b) { + return Boolean.compare(b, false); + } + + static void processLine(String line) throws DukeIllegalKeyword, DukeIllegalDescription { + if (line.equals("list")){ + UI.printList(); + } else if (line.startsWith("mark")){ + int indexToMark = Integer.parseInt(line.substring(5)); + UI.markTask(indexToMark); + } else if(line.startsWith("unmark")){ + int indexToUnmark = Integer.parseInt(line.substring(7)); + UI.unMarkTask(indexToUnmark); + } else if (line.startsWith("todo")){ + if (line.length() < 5){ + throw new DukeIllegalDescription(); + } + String todoDescription = line.substring(4); + Todo task = new Todo(todoDescription); + TaskList.taskList.add(task); + UI.printAddedItem(task); + } else if (line.startsWith("deadline")){ + if (line.length() < 9 || !line.contains("/by")){ + throw new DukeIllegalDescription(); + } + int byIndex = line.indexOf("/by"); + String deadlineDescription = line.substring(8, byIndex - 1); + String by = line.substring(byIndex + 3); + Deadline task = new Deadline(deadlineDescription, by); + TaskList.taskList.add(task); + UI.printAddedItem(task); + } else if (line.startsWith("event")){ + if (line.length() < 6 || !line.contains("/at")){ + throw new DukeIllegalDescription(); + } + int atIndex = line.indexOf("/at"); + String eventDescription = line.substring(5, atIndex - 1); + String at = line.substring(atIndex + 3); + Event task = new Event(eventDescription, at); + TaskList.taskList.add(task); + UI.printAddedItem(task); + } else if (line.startsWith("delete")) { + if (line.length() < 8) { + throw new DukeIllegalDescription(); + } + int indexToDelete = Integer.parseInt(line.substring(7)); + Task deletedTask = TaskList.taskList.get(indexToDelete - 1); + TaskList.taskList.remove(indexToDelete - 1); + UI.printDeletedItem(deletedTask); + } else if (line.startsWith("find")) { + if (line.length() < 6) { + throw new DukeIllegalDescription(); + } + String stringToSearch = line.substring(5); + Searcher.searchInList(stringToSearch); + }else throw new DukeIllegalKeyword(); + } +} diff --git a/src/main/java/duke/Run.java b/src/main/java/duke/Runner.java similarity index 74% rename from src/main/java/duke/Run.java rename to src/main/java/duke/Runner.java index ca941682d..83b18edb0 100644 --- a/src/main/java/duke/Run.java +++ b/src/main/java/duke/Runner.java @@ -1,9 +1,11 @@ package duke; +import java.io.IOException; import java.util.Scanner; -public class Run { - public static void run(){ +public class Runner { + + public static void run() throws IOException { String line; Scanner in = new Scanner(System.in); @@ -17,13 +19,15 @@ public static void run(){ while (!line.contains("bye")){ try{ - UI.processLine(line); + Parser.processLine(line); } catch (DukeIllegalKeyword e){ UI.printIllegalKeyword(); } catch (DukeIllegalDescription e){ UI.printIllegalDescription(); + } catch (Exception e){ + UI.printIllegalTerm(); } line = in.nextLine(); diff --git a/src/main/java/duke/Searcher.java b/src/main/java/duke/Searcher.java new file mode 100644 index 000000000..72c8a129c --- /dev/null +++ b/src/main/java/duke/Searcher.java @@ -0,0 +1,18 @@ +package duke; + +import static duke.UI.DASHED_LINE; + +public class Searcher { + + static void searchInList(String keyWord){ + System.out.println(DASHED_LINE); + System.out.print("\t Here are the matching tasks in your list:"); + for (int j = 0; j < TaskList.taskList.size(); j++){ + if (TaskList.taskList.get(j).getDescription().contains(keyWord)){ + System.out.print("\n"); + System.out.print("\t" + (j+1) + "." + TaskList.taskList.get(j).toString()); + } + } + System.out.println("\n" + DASHED_LINE); + } +} diff --git a/src/main/java/duke/UI.java b/src/main/java/duke/UI.java index 0667806d2..075e5c19e 100644 --- a/src/main/java/duke/UI.java +++ b/src/main/java/duke/UI.java @@ -2,10 +2,9 @@ public class UI { - // static int currentCount = 0; - final static String DASHED_LINE = "\t____________________________________________________________"; + final static String DASHED_LINE = "\t____________________________________________________________"; - private static void markTask(int index){ + static void markTask(int index){ TaskList.taskList.get(index - 1).setDone(true); String message = DASHED_LINE + "\n" + "\t Nice! I've marked this task as done: \n" + @@ -14,7 +13,7 @@ private static void markTask(int index){ System.out.println(message); } - private static void unMarkTask(int index){ + static void unMarkTask(int index){ TaskList.taskList.get(index - 1).setDone(false); String message = DASHED_LINE + "\n" + "\tOK, I've marked this task as not done yet: \n" + @@ -23,7 +22,7 @@ private static void unMarkTask(int index){ System.out.println(message); } - private static void printAddedItem(Task task){ + static void printAddedItem(Task task){ String message = DASHED_LINE + "\n" + "\t Got it. I've added this task:" + "\n" + "\t \t" + task.toString() + "\n" + @@ -33,7 +32,7 @@ private static void printAddedItem(Task task){ System.out.println(message); } - private static void printDeletedItem(Task task){ + static void printDeletedItem(Task task){ String message = DASHED_LINE + "\n" + "\t Got it. I've removed this task:" + "\n" + "\t \t" + task.toString() + "\n" + @@ -43,7 +42,7 @@ private static void printDeletedItem(Task task){ System.out.println(message); } - private static void printList(){ + static void printList(){ System.out.print(DASHED_LINE); for (int j = 0; j < TaskList.taskList.size(); j++){ System.out.print("\n"); @@ -52,57 +51,6 @@ private static void printList(){ System.out.println("\n" + DASHED_LINE); } - static void processLine(String line) throws DukeIllegalKeyword, DukeIllegalDescription { - if (line.equals("list")){ - printList(); - } else if (line.startsWith("mark")){ - int indexToMark = Integer.parseInt(line.substring(5)); - markTask(indexToMark); - } else if(line.startsWith("unmark")){ - int indexToUnmark = Integer.parseInt(line.substring(7)); - unMarkTask(indexToUnmark); - } else if (line.startsWith("todo")){ - if (line.length() < 5){ - throw new DukeIllegalDescription(); - } - String todoDescription = line.substring(4); - Todo task = new Todo(todoDescription); - TaskList.taskList.add(task); -// currentCount += 1; - printAddedItem(task); - } else if (line.startsWith("deadline")){ - if (line.length() < 9 || !line.contains("/by")){ - throw new DukeIllegalDescription(); - } - int byIndex = line.indexOf("/by"); - String deadlineDescription = line.substring(8, byIndex - 1); - String by = line.substring(byIndex + 3); - Deadline task = new Deadline(deadlineDescription, by); - TaskList.taskList.add(task); -// currentCount += 1; - printAddedItem(task); - } else if (line.startsWith("event")){ - if (line.length() < 6 || !line.contains("/at")){ - throw new DukeIllegalDescription(); - } - int atIndex = line.indexOf("/at"); - String eventDescription = line.substring(5, atIndex - 1); - String at = line.substring(atIndex + 3); - Event task = new Event(eventDescription, at); - TaskList.taskList.add(task); -// currentCount += 1; - printAddedItem(task); - } else if (line.startsWith("delete")) { - if (line.length() < 8) { - throw new DukeIllegalDescription(); - } - int indexToDelete = Integer.parseInt(line.substring(7)); - Task deletedTask = TaskList.taskList.get(indexToDelete); - TaskList.taskList.remove(indexToDelete); - printDeletedItem(deletedTask); - } else throw new DukeIllegalKeyword(); - } - static void printIllegalKeyword(){ String message = DASHED_LINE + "\n" + "\t You typed an illegal keyword." + "\n" + @@ -119,6 +67,14 @@ static void printIllegalDescription(){ System.out.println(message); } + static void printIllegalTerm(){ + String message = DASHED_LINE + "\n" + + "\t You did not make any sense" + "\n" + + "\t I can't do much. Try again!" + "\n" + + DASHED_LINE; + System.out.println(message); + } + final static String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" + "| | | | | | | |/ / _ \\\n" From 27f788f5f30dfdaac18a325fc22c4c2501fb4597 Mon Sep 17 00:00:00 2001 From: Aiman Imtiaz Date: Sat, 5 Mar 2022 13:13:25 +0800 Subject: [PATCH 21/24] merged Level-9 with master --- data/duke.txt | 4 ++++ src/main/java/duke/Parser.java | 10 ++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/data/duke.txt b/data/duke.txt index e69de29bb..babe7c017 100644 --- a/data/duke.txt +++ b/data/duke.txt @@ -0,0 +1,4 @@ +T | 1 | cry +D | 0 | cry loudly | 2022-09-03 +E | 0 | eat | today +D | 1 | something | 2089-09-11 diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java index 5b4f52e28..8c45aa463 100644 --- a/src/main/java/duke/Parser.java +++ b/src/main/java/duke/Parser.java @@ -1,5 +1,7 @@ package duke; +import java.time.LocalDate; + public class Parser { static Task lineToTask(String line){ @@ -11,7 +13,7 @@ static Task lineToTask(String line){ int byIndex = line.indexOf("|", 8); String deadlineDescription = line.substring(8, byIndex - 1); String by = line.substring(byIndex + 2); - task = new Deadline(deadlineDescription, by); + task = new Deadline(deadlineDescription, LocalDate.parse(by)); isDoneInt = Integer.parseInt(line.substring(4, 5)); if (isDoneInt != 0) task.setDone(true); break; @@ -41,7 +43,7 @@ static String taskToLine(Task task) { line = "D" + " | " + boolToInt(deadline.isDone()) + " | " + deadline.description + - " | " + deadline.getBy(); + " | " + deadline.by.toString(); } else if (task instanceof Event) { Event event = (Event) task; line = "E" + " | " + @@ -84,8 +86,8 @@ static void processLine(String line) throws DukeIllegalKeyword, DukeIllegalDescr } int byIndex = line.indexOf("/by"); String deadlineDescription = line.substring(8, byIndex - 1); - String by = line.substring(byIndex + 3); - Deadline task = new Deadline(deadlineDescription, by); + String by = line.substring(byIndex + 4); + Deadline task = new Deadline(deadlineDescription, LocalDate.parse(by)); TaskList.taskList.add(task); UI.printAddedItem(task); } else if (line.startsWith("event")){ From 36172be931de49e6a2b20c454e7565e7954ea014 Mon Sep 17 00:00:00 2001 From: Aiman Imtiaz Date: Sun, 6 Mar 2022 20:22:59 +0800 Subject: [PATCH 22/24] A-JavaDoc --- data/duke.txt | 4 +-- src/main/java/duke/Duke.java | 11 +++++++ src/main/java/duke/FileAccess.java | 25 ++++++++++++++-- src/main/java/duke/Parser.java | 30 +++++++++++++++++++ src/main/java/duke/Runner.java | 9 ++++++ src/main/java/duke/Searcher.java | 8 ++++++ src/main/java/duke/TaskList.java | 3 ++ src/main/java/duke/UI.java | 46 +++++++++++++++++++++++++++++- 8 files changed, 129 insertions(+), 7 deletions(-) diff --git a/data/duke.txt b/data/duke.txt index babe7c017..0f6ec97f8 100644 --- a/data/duke.txt +++ b/data/duke.txt @@ -1,4 +1,2 @@ -T | 1 | cry -D | 0 | cry loudly | 2022-09-03 -E | 0 | eat | today D | 1 | something | 2089-09-11 +T | 0 | sljf diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 7be303ed9..5a26c60d2 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -2,8 +2,19 @@ import java.io.IOException; +/** + * Starts the program. + */ public class Duke { + final static String FILE_NAME = "/Users/aimanimtiaz/software-engineering/ip/data/duke.txt"; + + /** + * Runs the main duke program using the Runner class. + * + * @param args arguments to run the program, can be left empty + * @throws IOException exception could be thrown if reading or writing from a file is not successful + */ public static void main(String[] args) throws IOException { Runner.run(); } diff --git a/src/main/java/duke/FileAccess.java b/src/main/java/duke/FileAccess.java index a3dd44274..29bb3ec36 100644 --- a/src/main/java/duke/FileAccess.java +++ b/src/main/java/duke/FileAccess.java @@ -6,11 +6,20 @@ import java.io.IOException; import java.util.Scanner; +/** + * Provides methods for storing to and loading from the storage file. + */ public class FileAccess { - final static String FILE_NAME = "/Users/aimanimtiaz/software-engineering/ip/data/duke.txt"; + /** + * Reads all the existing tasks from a text file and adds them to the TaskList. + * + * @throws FileNotFoundException exception if the file does not exist + * @see Parser + * @see TaskList + */ private static void readFromFile() throws FileNotFoundException { - File f = new File(FileAccess.FILE_NAME); // create a File for the given file path + File f = new File(Duke.FILE_NAME); // create a File for the given file path Scanner s = new Scanner(f); // create a Scanner using the File as the source while (s.hasNext()) { Task task = Parser.lineToTask(s.nextLine()); @@ -18,8 +27,15 @@ private static void readFromFile() throws FileNotFoundException { } } + /** + * Saves the entire TaskList to the given text file/ + * + * @throws IOException exception if file cannot be written to + * @see Parser + * @see TaskList + */ public static void saveToFile() throws IOException { - FileWriter fw = new FileWriter(FileAccess.FILE_NAME); + FileWriter fw = new FileWriter(Duke.FILE_NAME); String line; try { for (Task task: TaskList.taskList){ @@ -32,6 +48,9 @@ public static void saveToFile() throws IOException { } } + /** + * Tries to read from file and prints a message if the file does not exist. + */ public static void loadFromFile(){ try { readFromFile(); diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java index 8c45aa463..c0df1f3db 100644 --- a/src/main/java/duke/Parser.java +++ b/src/main/java/duke/Parser.java @@ -4,6 +4,13 @@ public class Parser { + /** + * Parses a string to a Task object by figuring out the kind of Task, + * and all other fields required for the relevant class. + * + * @param line the string that needs to be parsed as a Task + * @return Task the task object which can be added to the TaskList + */ static Task lineToTask(String line){ Task task = null; int isDoneInt; @@ -35,6 +42,14 @@ static Task lineToTask(String line){ return task; } + /** + * Appropriately converts a Task to a string object in a way that all + * information about the Task object is preserved. Every field of the + * object is converted to a string and the final line is constructed. + * + * @param task the Task object which needs to be converted to string + * @return the string that can be written to a text file as a single line + */ static String taskToLine(Task task) { String line = ""; // code block @@ -59,10 +74,25 @@ static String taskToLine(Task task) { return line; } + /** + * Converts boolean to integer. + * + * @param b the boolean value to be turned either to 0 or 1 + * @return 0 or 1 + */ private static int boolToInt(boolean b) { return Boolean.compare(b, false); } + + /** + * Each line that the user inputs is parsed and processed. + * + * @param line the line from the command line that needs to be parsed in order + * for appropriate action to be taken + * @throws DukeIllegalKeyword throws exception if invalid keyword is typed + * @throws DukeIllegalDescription throws exception if no description is added + */ static void processLine(String line) throws DukeIllegalKeyword, DukeIllegalDescription { if (line.equals("list")){ UI.printList(); diff --git a/src/main/java/duke/Runner.java b/src/main/java/duke/Runner.java index 83b18edb0..19d03aa46 100644 --- a/src/main/java/duke/Runner.java +++ b/src/main/java/duke/Runner.java @@ -3,8 +3,17 @@ import java.io.IOException; import java.util.Scanner; +/** + * Loads previous data from file and starts requesting input from user. + */ public class Runner { + /** + * Loads previous tasks from file and starts requesting input and processing it + * line by line until the user inputs "bye". + * + * @throws IOException exception in case file access if unsuccessful + */ public static void run() throws IOException { String line; Scanner in = new Scanner(System.in); diff --git a/src/main/java/duke/Searcher.java b/src/main/java/duke/Searcher.java index 72c8a129c..e06fac45e 100644 --- a/src/main/java/duke/Searcher.java +++ b/src/main/java/duke/Searcher.java @@ -2,8 +2,16 @@ import static duke.UI.DASHED_LINE; +/** + * Class used to search for a keyword inside the list of tasks. + */ public class Searcher { + /** + * This method prints out any task whose description contains + * the keyword we are looking for. + * @param keyWord the string user searched for + */ static void searchInList(String keyWord){ System.out.println(DASHED_LINE); System.out.print("\t Here are the matching tasks in your list:"); diff --git a/src/main/java/duke/TaskList.java b/src/main/java/duke/TaskList.java index a30682bcd..f9a7f5e0b 100644 --- a/src/main/java/duke/TaskList.java +++ b/src/main/java/duke/TaskList.java @@ -2,6 +2,9 @@ import java.util.ArrayList; +/** + * The main list where all the tasks are stored while the program is running. + */ public class TaskList { static ArrayList taskList = new ArrayList<>(); } diff --git a/src/main/java/duke/UI.java b/src/main/java/duke/UI.java index ef7c6c040..d6de715ea 100644 --- a/src/main/java/duke/UI.java +++ b/src/main/java/duke/UI.java @@ -1,9 +1,18 @@ package duke; +/** + * The main UI which helps print relevant output. + */ public class UI { final static String DASHED_LINE = "\t____________________________________________________________"; + /** + * When user requests to mark a task, this method not only marks the + * task as done, but also prints out the relevant message. + * + * @param index the index of the task to mark + */ static void markTask(int index){ TaskList.taskList.get(index - 1).setDone(true); String message = DASHED_LINE + "\n" + @@ -13,6 +22,12 @@ static void markTask(int index){ System.out.println(message); } + /** + * Marks a task as not done and prints out the relevant message as + * confirmation. + * + * @param index the index of the task to unmark + */ static void unMarkTask(int index){ TaskList.taskList.get(index - 1).setDone(false); String message = DASHED_LINE + "\n" + @@ -22,6 +37,11 @@ static void unMarkTask(int index){ System.out.println(message); } + /** + * Pretty prints the recently added task with a message confimation. + * + * @param task the task which was just added to the TaskList + */ static void printAddedItem(Task task){ String message = DASHED_LINE + "\n" + "\t Got it. I've added this task:" + "\n" + @@ -32,6 +52,11 @@ static void printAddedItem(Task task){ System.out.println(message); } + /** + * Pretty prints the recently deleted task which confirms deletion. + * + * @param task + */ static void printDeletedItem(Task task){ String message = DASHED_LINE + "\n" + "\t Got it. I've removed this task:" + "\n" + @@ -42,6 +67,10 @@ static void printDeletedItem(Task task){ System.out.println(message); } + /** + * Prints out all tasks in the TaskList when the user requests to view + * all tasks present. + */ static void printList(){ System.out.print(DASHED_LINE); for (int j = 0; j < TaskList.taskList.size(); j++){ @@ -52,7 +81,11 @@ static void printList(){ } - + /** + * Prints out an error message when the DukeIllegalKeyword exception is thrown. + * + * @see DukeIllegalKeyword + */ static void printIllegalKeyword(){ String message = DASHED_LINE + "\n" + "\t You typed an illegal keyword." + "\n" + @@ -61,6 +94,11 @@ static void printIllegalKeyword(){ System.out.println(message); } + /** + * Prints out an error message when the DukeIllegalDescription exception is thrown. + * + * @see DukeIllegalDescription + */ static void printIllegalDescription(){ String message = DASHED_LINE + "\n" + "\t You did not add any description." + "\n" + @@ -69,6 +107,12 @@ static void printIllegalDescription(){ System.out.println(message); } + /** + * Prints out an error message when the command cannot be parsed and *any* + * kind of exception is thrown. + * + * @see Parser + */ static void printIllegalTerm(){ String message = DASHED_LINE + "\n" + "\t You did not make any sense" + "\n" + From 22a0f184a4c259d8f826d43fe42b2fc94076a09c Mon Sep 17 00:00:00 2001 From: Aiman Imtiaz Date: Sun, 6 Mar 2022 21:27:06 +0800 Subject: [PATCH 23/24] User Guide --- data/duke.txt | 4 +- docs/README.md | 195 ++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 188 insertions(+), 11 deletions(-) diff --git a/data/duke.txt b/data/duke.txt index 0f6ec97f8..ba3a8db4f 100644 --- a/data/duke.txt +++ b/data/duke.txt @@ -1,2 +1,4 @@ D | 1 | something | 2089-09-11 -T | 0 | sljf +T | 0 | read 30 pages of Dune +D | 0 | submit ip | 2022-03-04 +E | 0 | HI lecture | 12 pm diff --git a/docs/README.md b/docs/README.md index 8077118eb..c371f606e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,29 +1,204 @@ # User Guide +_Duke_ is an application designed for managing to-do lists, optimized for use via a __Command Line Interface (CLI)__. + +```` +Hello from + ____ _ +| _ \ _ _| | _____ +| | | | | | | |/ / _ \ +| |_| | |_| | < __/ +|____/ \__,_|_|\_\___| + + ____________________________________________________________ + Hello! I'm Duke + What can I do for you? + ____________________________________________________________ + +```` ## Features -### Feature-ABC +### Adding a deadline -Description of the feature. +Adds a deadline to the list with the date by which the deadline is due. -### Feature-XYZ +### Adding an event -Description of the feature. +Adds an event and when it's happening to the list. -## Usage +### Adding a general to-do task + +Adds a todo task with a description with no other information required. + +### Delete an item from the list + +Deletes a task from the main list. + +### List all tasks + +List all items present in the list on the screen, while indicating what kind of task it is, whether it is done or not and any other information attached to the specific kind of task. + +### Search for items in the list -### `Keyword` - Describe action +Searches for tasks that match the search string, and displays. -Describe the action and its outcome. +### Mark an item as done + +Indicates that the task is done and reflects it when the tasks are printed on screen. + +### Re-mark an item as not done yet + +Un-marks the task and indicates it as not done again. + +## Usage + +### `todo` - add a to-do task Example of usage: -`keyword (optional arguments)` +`todo read 30 pages of Dune` + +Expected outcome: + +``` + ____________________________________________________________ + Got it. I've added this task: + [T][ ] read 30 pages of Dune + Now you have 3 tasks in the list. + ____________________________________________________________ +``` +The output message shows that the task is added, and prints out the number of tasks that are now present in the list. + +### `deadline` - add a deadline task + +Takes a deadline's description and the due date in `yyyy-mm-dd` format, and adds the deadline to the list. + +Example of usage: + +`deadline submit ip /by 2022-03-04` + +Expected outcome: + +``` + ____________________________________________________________ + Got it. I've added this task: + [D][ ] submit ip (by: Mar 4 2022) + Now you have 4 tasks in the list. + ____________________________________________________________ +``` +The output shows that the deadline is added, and prints out the number of tasks that are now present in the list. + +### `event` - add an event task + +Takes an event's description and when the event is taking place using the `/at` keyword, and adds the event to the list. + +Example of usage: + +`event HI lecture /at 12 pm` + +Expected outcome: + +``` + ____________________________________________________________ + Got it. I've added this task: + [D][ ] HI lecture (at: 12 pm) + Now you have 5 tasks in the list. + ____________________________________________________________ +``` +The output shows that the event is added, and prints out the number of tasks that are now present in the list. + +### `list` - display all items + +Example of usage: + +`list` + +Expected outcome: + +``` + ____________________________________________________________ + 1.[D][X] something (by: Sep 11 2089) + 2.[T][ ] sljf + 3.[T][ ] read 30 pages of Dune + 4.[D][ ] submit ip (by: Mar 4 2022) + 5.[D][ ] HI lecture (at: 12 pm) + ____________________________________________________________ +``` +The output shows all the tasks currently in the program, and shows the kind of task it is and whether it is done or not. + +- `[X]` indicates done and `[ ]` indicates not done. +- `[D]` indicates that the task is a deadline, `[E]` indicates events, and `[T]` indicates to-do tasks + + +### `mark` - mark an task as done + +Marks a task using the task number. + +Example of usage: + +`mark 4` + +Expected outcome: + +``` + ____________________________________________________________ + Nice! I've marked this task as done: + [D][X] submit ip (by: Mar 4 2022) + ____________________________________________________________ +``` +The output shows that the task is marked as done and indicates it when the task is printed. + +### `umark` - unmark a task as not done yet + +Un-marks a task using the task number. + +Example of usage: + +`unmark 4` + +Expected outcome: + +``` + ____________________________________________________________ + OK, I've marked this task as not done yet: + [D][ ] submit ip (by: Mar 4 2022) + ____________________________________________________________ +``` +The output shows that the task is marked as done and indicates it when the task is printed. + +### `delete` - deletes a task + +Deletes a task using the task number. + +Example of usage: + +`delete 2` Expected outcome: -Description of the outcome. +``` + ____________________________________________________________ + Got it. I've removed this task: + [T][ ] sljf + Now you have 4 tasks in the list. + ____________________________________________________________ +``` +The output shows that the task is removed from the list and indicates the remaining number of tasks. + +### `find` - searches in the list + +Searches inside the list by looking for the search string in the descriptions of all tasks. + +Example of usage: + +`find Dune` + +Expected outcome: ``` -expected output + ____________________________________________________________ + Here are the matching tasks in your list: + 2.[T][ ] read 30 pages of Dune + ____________________________________________________________ ``` + From 6146f8aaf3fe9dcbdda3889701de18c17c3f0f76 Mon Sep 17 00:00:00 2001 From: Aiman Imtiaz <49554923+aiman-imtiaz@users.noreply.github.com> Date: Sun, 6 Mar 2022 21:30:09 +0800 Subject: [PATCH 24/24] Set theme jekyll-theme-minimal --- docs/_config.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/_config.yml diff --git a/docs/_config.yml b/docs/_config.yml new file mode 100644 index 000000000..2f7efbeab --- /dev/null +++ b/docs/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-minimal \ No newline at end of file