From 03559aabe85f3f2b90f4260d1b81c8bfaa17101f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ege=20Demirk=C4=B1rkan?= Date: Wed, 19 Jan 2022 05:27:11 +0800 Subject: [PATCH 01/26] Ignore .class files --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index f69985ef1..e113020ce 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,8 @@ src/main/resources/docs/ # MacOS custom attributes files created by Finder .DS_Store *.iml +# class files generated by java +*.class bin/ /text-ui-test/ACTUAL.txt From 039cea9d4b07aa83a2cb74ad6cbe72e9658666f3 Mon Sep 17 00:00:00 2001 From: edemirkirkan Date: Wed, 19 Jan 2022 05:53:24 +0800 Subject: [PATCH 02/26] Implement initial skeletal version of JRobo --- src/main/java/Duke.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5d313334c..bce018d33 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,10 +1,10 @@ public class Duke { public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); + System.out.println("____________________________________________________________\n" + + "Hello from JRobo! I'm your personal assistant!\n" + + "Nice to meet you. What can I do for you?\n" + + "____________________________________________________________\n" + + "Bye. Hope to see you again soon!\n" + + "____________________________________________________________"); } } From 2ef4b256c4af9a4df9279189a2fb99a15727ac1a Mon Sep 17 00:00:00 2001 From: edemirkirkan Date: Fri, 28 Jan 2022 11:47:36 +0800 Subject: [PATCH 03/26] Implement a skeletal version --- src/main/java/Duke.java | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index bce018d33..91cf7092f 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,10 +1,26 @@ +import java.util.Scanner; public class Duke { public static void main(String[] args) { - System.out.println("____________________________________________________________\n" - + "Hello from JRobo! I'm your personal assistant!\n" - + "Nice to meet you. What can I do for you?\n" - + "____________________________________________________________\n" - + "Bye. Hope to see you again soon!\n" - + "____________________________________________________________"); + Scanner scanner = new Scanner(System.in); + print("Hello from JRobo! I'm your personal assistant!\n\t" + "Nice to meet you. What can I do for you?"); + + String input; + + while (true) { + input = scanner.nextLine(); + if (input.equals("bye")) { + break; + } + print(input); + } + + print("Bye. Hope to see you again soon!"); + scanner.close(); + } + + public static void print(String s) { + System.out.println("\t____________________________________________________________\n\t" + + s + + "\n\t____________________________________________________________"); } } From 3fee1e916d3da3a9ac7be18863f412b972670d8a Mon Sep 17 00:00:00 2001 From: edemirkirkan Date: Fri, 28 Jan 2022 12:00:10 +0800 Subject: [PATCH 04/26] Implement task history --- src/main/java/Duke.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 91cf7092f..96a4ef06a 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,6 +1,7 @@ -import java.util.Scanner; +import java.util.*; public class Duke { public static void main(String[] args) { + List tasks = new ArrayList<>(); Scanner scanner = new Scanner(System.in); print("Hello from JRobo! I'm your personal assistant!\n\t" + "Nice to meet you. What can I do for you?"); @@ -8,10 +9,15 @@ public static void main(String[] args) { while (true) { input = scanner.nextLine(); + if (input.equals("list")) { + displayList(tasks); + continue; + } if (input.equals("bye")) { break; } - print(input); + tasks.add(input); + print("added: " + input); } print("Bye. Hope to see you again soon!"); @@ -23,4 +29,13 @@ public static void print(String s) { + s + "\n\t____________________________________________________________"); } + + public static void displayList(List tasks) { + System.out.println("\t____________________________________________________________"); + int index = 1; + for (String s : tasks) { + System.out.println("\t" + index++ + ". " + s); + } + System.out.println("\t____________________________________________________________"); + } } From e6cfbb5dbaeba1b65542ee282e41d933eaf96662 Mon Sep 17 00:00:00 2001 From: edemirkirkan Date: Fri, 28 Jan 2022 12:36:06 +0800 Subject: [PATCH 05/26] Implement task management --- src/main/java/Duke.java | 64 +++++++++++++++++++++++++++++++++++++---- src/main/java/Task.java | 25 ++++++++++++++++ 2 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 src/main/java/Task.java diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 96a4ef06a..d9f6bd82f 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,14 +1,22 @@ import java.util.*; public class Duke { public static void main(String[] args) { - List tasks = new ArrayList<>(); + List tasks = new ArrayList<>(); Scanner scanner = new Scanner(System.in); - print("Hello from JRobo! I'm your personal assistant!\n\t" + "Nice to meet you. What can I do for you?"); + print("Hello from JRobo! I'm your personal assistant!\n\tNice to meet you. What can I do for you?"); String input; while (true) { input = scanner.nextLine(); + if (input.startsWith("mark")) { + markTask(tasks, input); + continue; + } + if (input.startsWith("unmark")) { + unmarkTask(tasks, input); + continue; + } if (input.equals("list")) { displayList(tasks); continue; @@ -16,7 +24,8 @@ public static void main(String[] args) { if (input.equals("bye")) { break; } - tasks.add(input); + Task task = new Task(input); + tasks.add(task); print("added: " + input); } @@ -30,12 +39,55 @@ public static void print(String s) { + "\n\t____________________________________________________________"); } - public static void displayList(List tasks) { + public static void displayList(List tasks) { System.out.println("\t____________________________________________________________"); + System.out.println("\tHere are the tasks in your list:"); int index = 1; - for (String s : tasks) { - System.out.println("\t" + index++ + ". " + s); + for (Task t : tasks) { + System.out.println("\t" + index++ + ".[" + t.getStatusIcon() + "] " + t.getDescription()); } System.out.println("\t____________________________________________________________"); } + + public static void markTask(List tasks, String input) { + String numberString = input.substring(4).trim(); + try { + int taskNumber = Integer.parseInt(numberString); + Task task = tasks.get(taskNumber - 1); + if (task.getStatusIcon().equals("X")) { + print("This task is already marked"); + return; + } + task.markAsDone(); + print("Nice! I've marked this task as done:\n\t\t[" + task.getStatusIcon() + "] " + task.getDescription()); + return; + } catch(NumberFormatException e) { + print("Invalid command"); + return; + } catch(IndexOutOfBoundsException e) { + print("Please enter a valid task number to mark"); + return; + } + } + + public static void unmarkTask(List tasks, String input) { + String numberString = input.substring(6).trim(); + try { + int taskNumber = Integer.parseInt(numberString); + Task task = tasks.get(taskNumber - 1); + if (!task.getStatusIcon().equals("X")) { + print("This task is already unmarked"); + return; + } + task.markAsUndone(); + print("Nice! I've marked this task as undone:\n\t\t[" + task.getStatusIcon() + "] " + task.getDescription()); + return; + } catch(NumberFormatException e) { + print("Invalid command"); + return; + } catch(IndexOutOfBoundsException e) { + print("Please enter a valid task number to unmark"); + return; + } + } } diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 000000000..04dccd16a --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,25 @@ +public class Task { + protected String description; + protected boolean isDone; + + public Task(String description) { + this.description = description; + this.isDone = false; + } + + public String getStatusIcon() { + return (isDone ? "X" : " "); // mark done task with X + } + + public String getDescription() { + return description; + } + + public void markAsDone() { + this.isDone = true; + } + + public void markAsUndone() { + this.isDone = false; + } +} From 73b4a69c95731a10d7cad961d4fb7b8869d40fdc Mon Sep 17 00:00:00 2001 From: edemirkirkan Date: Fri, 28 Jan 2022 13:15:40 +0800 Subject: [PATCH 06/26] Standardize coding style conventions --- src/main/java/Duke.java | 40 ++++++++++++++++++---------------------- src/main/java/Task.java | 2 +- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index d9f6bd82f..8f7eaf0fe 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,7 +1,9 @@ -import java.util.*; +import java.util.Scanner; +import java.util.ArrayList; + public class Duke { public static void main(String[] args) { - List tasks = new ArrayList<>(); + ArrayList tasks = new ArrayList<>(); Scanner scanner = new Scanner(System.in); print("Hello from JRobo! I'm your personal assistant!\n\tNice to meet you. What can I do for you?"); @@ -34,12 +36,10 @@ public static void main(String[] args) { } public static void print(String s) { - System.out.println("\t____________________________________________________________\n\t" - + s - + "\n\t____________________________________________________________"); + System.out.println("\t____________________________________________________________\n\t" + s + "\n\t____________________________________________________________"); } - public static void displayList(List tasks) { + public static void displayList(ArrayList tasks) { System.out.println("\t____________________________________________________________"); System.out.println("\tHere are the tasks in your list:"); int index = 1; @@ -49,7 +49,7 @@ public static void displayList(List tasks) { System.out.println("\t____________________________________________________________"); } - public static void markTask(List tasks, String input) { + public static void markTask(ArrayList tasks, String input) { String numberString = input.substring(4).trim(); try { int taskNumber = Integer.parseInt(numberString); @@ -59,18 +59,16 @@ public static void markTask(List tasks, String input) { return; } task.markAsDone(); - print("Nice! I've marked this task as done:\n\t\t[" + task.getStatusIcon() + "] " + task.getDescription()); - return; - } catch(NumberFormatException e) { + print("Nice! I've marked this task as done:\n\t\t[" + task.getStatusIcon() + "] " + + task.getDescription()); + } catch (NumberFormatException e) { print("Invalid command"); - return; - } catch(IndexOutOfBoundsException e) { + } catch (IndexOutOfBoundsException e) { print("Please enter a valid task number to mark"); - return; - } + } } - public static void unmarkTask(List tasks, String input) { + public static void unmarkTask(ArrayList tasks, String input) { String numberString = input.substring(6).trim(); try { int taskNumber = Integer.parseInt(numberString); @@ -80,14 +78,12 @@ public static void unmarkTask(List tasks, String input) { return; } task.markAsUndone(); - print("Nice! I've marked this task as undone:\n\t\t[" + task.getStatusIcon() + "] " + task.getDescription()); - return; - } catch(NumberFormatException e) { + print("Nice! I've marked this task as undone:\n\t\t[" + task.getStatusIcon() + "] " + + task.getDescription()); + } catch (NumberFormatException e) { print("Invalid command"); - return; - } catch(IndexOutOfBoundsException e) { + } catch (IndexOutOfBoundsException e) { print("Please enter a valid task number to unmark"); - return; - } + } } } diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 04dccd16a..297e31831 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -8,7 +8,7 @@ public Task(String description) { } public String getStatusIcon() { - return (isDone ? "X" : " "); // mark done task with X + return (isDone ? "X" : " "); } public String getDescription() { From c1fb01eb67388a878885e89ea935a71996a0cad1 Mon Sep 17 00:00:00 2001 From: edemirkirkan Date: Thu, 3 Feb 2022 00:21:14 +0800 Subject: [PATCH 07/26] Implement todos, deadlines, and events --- src/main/java/Deadline.java | 14 +++++ src/main/java/Duke.java | 105 ++++++++++----------------------- src/main/java/Event.java | 15 +++++ src/main/java/InputParser.java | 84 ++++++++++++++++++++++++++ src/main/java/Task.java | 11 ++++ src/main/java/TaskManager.java | 103 ++++++++++++++++++++++++++++++++ src/main/java/Todo.java | 12 ++++ 7 files changed, 269 insertions(+), 75 deletions(-) create mode 100644 src/main/java/Deadline.java create mode 100644 src/main/java/Event.java create mode 100644 src/main/java/InputParser.java create mode 100644 src/main/java/TaskManager.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..0bfcc263a --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,14 @@ +public class Deadline extends Task { + + protected String by; + + public Deadline(String description, String by) { + super(description); + this.by = by; + } + + @Override + public String toString() { + return "[D]" + super.toString() + " (by:" + by + ")"; + } +} \ No newline at end of file diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 8f7eaf0fe..b3a978ca0 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,89 +1,44 @@ import java.util.Scanner; -import java.util.ArrayList; public class Duke { public static void main(String[] args) { - ArrayList tasks = new ArrayList<>(); Scanner scanner = new Scanner(System.in); - print("Hello from JRobo! I'm your personal assistant!\n\tNice to meet you. What can I do for you?"); - - String input; - + TaskManager manager = new TaskManager(); + manager.welcomeUser(); + label: while (true) { - input = scanner.nextLine(); - if (input.startsWith("mark")) { - markTask(tasks, input); - continue; - } - if (input.startsWith("unmark")) { - unmarkTask(tasks, input); - continue; - } - if (input.equals("list")) { - displayList(tasks); + String input = scanner.nextLine(); + InputParser parser = new InputParser(input); + + if (!parser.isValidCommand()) { + manager.giveError(); continue; } - if (input.equals("bye")) { + String command = parser.getPrefix(); + switch (command) { + case "mark": + case "m": + manager.markTask(parser.getBody()); + break; + case "unmark": + case "um": + manager.unmarkTask(parser.getBody()); + break; + case "list": + case "ls": + manager.displayTaskList(); + break; + case "bye": + case "b": + case "quit": + case "q": + break label; + default: + manager.addTask(parser.getBody(), parser.getSuffix(), parser.getType()); break; } - Task task = new Task(input); - tasks.add(task); - print("added: " + input); } - - print("Bye. Hope to see you again soon!"); + manager.farewellUser(); scanner.close(); } - - public static void print(String s) { - System.out.println("\t____________________________________________________________\n\t" + s + "\n\t____________________________________________________________"); - } - - public static void displayList(ArrayList tasks) { - System.out.println("\t____________________________________________________________"); - System.out.println("\tHere are the tasks in your list:"); - int index = 1; - for (Task t : tasks) { - System.out.println("\t" + index++ + ".[" + t.getStatusIcon() + "] " + t.getDescription()); - } - System.out.println("\t____________________________________________________________"); - } - - public static void markTask(ArrayList tasks, String input) { - String numberString = input.substring(4).trim(); - try { - int taskNumber = Integer.parseInt(numberString); - Task task = tasks.get(taskNumber - 1); - if (task.getStatusIcon().equals("X")) { - print("This task is already marked"); - return; - } - task.markAsDone(); - print("Nice! I've marked this task as done:\n\t\t[" + task.getStatusIcon() + "] " - + task.getDescription()); - } catch (NumberFormatException e) { - print("Invalid command"); - } catch (IndexOutOfBoundsException e) { - print("Please enter a valid task number to mark"); - } - } - - public static void unmarkTask(ArrayList tasks, String input) { - String numberString = input.substring(6).trim(); - try { - int taskNumber = Integer.parseInt(numberString); - Task task = tasks.get(taskNumber - 1); - if (!task.getStatusIcon().equals("X")) { - print("This task is already unmarked"); - return; - } - task.markAsUndone(); - print("Nice! I've marked this task as undone:\n\t\t[" + task.getStatusIcon() + "] " - + task.getDescription()); - } catch (NumberFormatException e) { - print("Invalid command"); - } catch (IndexOutOfBoundsException e) { - print("Please enter a valid task number to unmark"); - } - } } diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 000000000..73e570f35 --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,15 @@ +public class Event extends Task { + + protected String by; + protected String at; + + public Event(String description, String at) { + super(description); + this.at = at; + } + + @Override + public String toString() { + return "[E]" + super.toString() + " (at:" + at + ")"; + } +} \ No newline at end of file diff --git a/src/main/java/InputParser.java b/src/main/java/InputParser.java new file mode 100644 index 000000000..08a5a1ede --- /dev/null +++ b/src/main/java/InputParser.java @@ -0,0 +1,84 @@ +public class InputParser { + protected String[] args; + protected static String[] validCommands = {"mark", "m", "unmark", "um", "todo", "t", "deadline", "d", "event", "e", "list", "ls", "bye", "exit", "quit", "q"}; + + public InputParser(String input) { + this.args = input.split(" "); + } + + public String getPrefix() { + for (String s : validCommands) { + String command = args[0]; + if (command.equalsIgnoreCase(s)) { + return command.toLowerCase(); + } + } + return null; + } + + public String getBody() { + int suffixIndex = findSuffixIndex(); + + StringBuilder description = new StringBuilder(); + int n = suffixIndex == -1 ? args.length : suffixIndex; + for (int i = 1; i < n; i++) { + description.append(" ").append(args[i]); + } + + return description.toString(); + } + + public String getSuffix() { + int suffixIndex = findSuffixIndex(); + if (suffixIndex == -1) { + return null; + } + + StringBuilder detail = new StringBuilder(); + for (int i = suffixIndex + 1; i < args.length; i++) { + detail.append(" ").append(args[i]); + } + return detail.toString(); + } + + public boolean isValidCommand() { + return !(getPrefix() == null || ((getPrefix().equals("list") || getPrefix().equals("ls")) && !getBody().equals(""))); + } + + public String getType() { + boolean isEvent = false; + boolean isDeadline = false; + for (String s : args) { + if (s.equals("/at")) { + isEvent = true; + } + if (s.equals("/by")) { + isDeadline = true; + } + } + + if (!isDeadline && !isEvent && (getPrefix().equals("todo") || getPrefix().equals("t"))) { + return "todo"; + } + if (isDeadline && (getPrefix().equals("deadline") || getPrefix().equals("d"))) { + return "deadline"; + } + if (isEvent && (getPrefix().equals("event") || getPrefix().equals("e"))) { + return "event"; + } + + return "invalid"; + } + + private int findSuffixIndex() { + int found = -1; + for (int i = 0; i < args.length; i++) { + String s = args[i]; + if (s.equals("/at") || s.equals("/by")) { + found = i; + break; + } + } + return found; + } +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 297e31831..0b1f47e0b 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -1,10 +1,16 @@ public class Task { protected String description; protected boolean isDone; + protected static int taskCount = 0; public Task(String description) { this.description = description; this.isDone = false; + taskCount++; + } + + public static int getTaskCount() { + return taskCount; } public String getStatusIcon() { @@ -22,4 +28,9 @@ public void markAsDone() { public void markAsUndone() { this.isDone = false; } + + @Override + public String toString() { + return "[" + getStatusIcon() + "]" + getDescription(); + } } diff --git a/src/main/java/TaskManager.java b/src/main/java/TaskManager.java new file mode 100644 index 000000000..2371273dd --- /dev/null +++ b/src/main/java/TaskManager.java @@ -0,0 +1,103 @@ +import java.util.ArrayList; + +public class TaskManager { + ArrayList tasks; + + public TaskManager() { + this.tasks = new ArrayList<>(); + } + + protected void printWithSeparator(String... strings) { + System.out.println("\t____________________________________________________________"); + for (String s : strings) { + System.out.println("\t" + s); + } + System.out.println("\t____________________________________________________________"); + } + + public void welcomeUser() { + printWithSeparator("Hello from JRobo! I'm your personal assistant!", + "Nice to meet you. What can I do for you?"); + } + + public void displayTaskList() { + if (tasks.size() == 0) { + printWithSeparator("You have no tasks to list."); + return; + } + System.out.println("\t____________________________________________________________"); + System.out.println("\tHere are the tasks in your list:"); + int taskCount = Task.getTaskCount(); + for (int i = 0; i < taskCount; i++) { + Task t = tasks.get(i); + System.out.println("\t" + (i + 1) + "." + t); + } + System.out.println("\t____________________________________________________________"); + } + + public void markTask(String input) { + String numberString = input.trim(); + try { + int taskNumber = Integer.parseInt(numberString); + Task task = tasks.get(taskNumber - 1); + if (task.getStatusIcon().equals("X")) { + printWithSeparator("This task is already marked"); + return; + } + task.markAsDone(); + printWithSeparator("Nice! I've marked this task as done:", "\t[" + task.getStatusIcon() + "] " + + task.getDescription()); + } catch (NumberFormatException e) { + printWithSeparator("Invalid command"); + } catch (IndexOutOfBoundsException e) { + printWithSeparator("Please enter a valid task number to mark"); + } + } + + public void unmarkTask(String input) { + String numberString = input.trim(); + try { + int taskNumber = Integer.parseInt(numberString); + Task task = tasks.get(taskNumber - 1); + if (!task.getStatusIcon().equals("X")) { + printWithSeparator("This task is already unmarked"); + return; + } + task.markAsUndone(); + printWithSeparator("Nice! I've marked this task as undone:", "\t[" + task.getStatusIcon() + "] " + + task.getDescription()); + } catch (NumberFormatException e) { + printWithSeparator("Invalid command"); + } catch (IndexOutOfBoundsException e) { + printWithSeparator("Please enter a valid task number to unmark"); + } + } + + public void addTask(String description, String detail, String type) { + Task task; + switch (type) { + case "todo": + task = new Todo(description); + break; + case "deadline": + task = new Deadline(description, detail); + break; + case "event": + task = new Event(description, detail); + break; + default: + giveError(); + return; + } + tasks.add(task); + printWithSeparator("Got it. I've added this task: ", "\t" + task, "Now, you have " + Task.taskCount + " in the list."); + } + + public void farewellUser() { + printWithSeparator("Bye. Hope to see you again soon!"); + } + + public void giveError() { + printWithSeparator("Invalid command!"); + } +} diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java new file mode 100644 index 000000000..e0e40d5d9 --- /dev/null +++ b/src/main/java/Todo.java @@ -0,0 +1,12 @@ +public class Todo extends Task { + + + public Todo(String description) { + super(description); + } + + @Override + public String toString() { + return "[T]" + super.toString(); + } +} \ No newline at end of file From 9bd9d210a54a21499346af2789cd715727bb2c35 Mon Sep 17 00:00:00 2001 From: edemirkirkan Date: Thu, 3 Feb 2022 01:41:45 +0800 Subject: [PATCH 08/26] Implement text-ui-test --- README.md | 21 +++-- src/main/java/{Duke.java => JRobo.java} | 2 +- src/main/java/TaskManager.java | 2 +- text-ui-test/EXPECTED.TXT | 100 ++++++++++++++++++++++-- text-ui-test/input.txt | 20 +++++ text-ui-test/runtest.bat | 2 +- text-ui-test/runtest.sh | 3 +- 7 files changed, 131 insertions(+), 19 deletions(-) rename src/main/java/{Duke.java => JRobo.java} (98%) diff --git a/README.md b/README.md index 8715d4d91..7ec02f362 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,24 @@ -# Duke project template +# JRobo project template -This is a project template for a greenfield Java project. It's named after the Java mascot _Duke_. Given below are instructions on how to use it. +This is a project template for a greenfield Java project. It's named after the Java mascot _Duke_. Given below are +instructions on how to use it. ## Setting up in Intellij Prerequisites: JDK 11, update Intellij to the most recent version. -1. Open Intellij (if you are not in the welcome screen, click `File` > `Close Project` to close the existing project first) +1. Open Intellij (if you are not in the welcome screen, click `File` > `Close Project` to close the existing project + first) 1. Open the project into Intellij as follows: - 1. Click `Open`. - 1. Select the project directory, and click `OK`. - 1. If there are any further prompts, accept the defaults. -1. Configure the project to use **JDK 11** (not other versions) as explained in [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk).
+ 1. Click `Open`. + 1. Select the project directory, and click `OK`. + 1. If there are any further prompts, accept the defaults. +1. Configure the project to use **JDK 11** (not other versions) as explained + in [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk).
In the same dialog, set the **Project language level** field to the `SDK default` option. -3. After that, locate the `src/main/java/Duke.java` file, right-click it, and choose `Run Duke.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output: +3. After that, locate the `src/main/java/JRobo.java` file, right-click it, and choose `Run JRobo.main()` (if the code + editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the + below as the output: ``` Hello from ____ _ diff --git a/src/main/java/Duke.java b/src/main/java/JRobo.java similarity index 98% rename from src/main/java/Duke.java rename to src/main/java/JRobo.java index b3a978ca0..7bba32977 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/JRobo.java @@ -1,6 +1,6 @@ import java.util.Scanner; -public class Duke { +public class JRobo { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); TaskManager manager = new TaskManager(); diff --git a/src/main/java/TaskManager.java b/src/main/java/TaskManager.java index 2371273dd..512f8cd00 100644 --- a/src/main/java/TaskManager.java +++ b/src/main/java/TaskManager.java @@ -90,7 +90,7 @@ public void addTask(String description, String detail, String type) { return; } tasks.add(task); - printWithSeparator("Got it. I've added this task: ", "\t" + task, "Now, you have " + Task.taskCount + " in the list."); + printWithSeparator("Got it. I've added this task:", "\t" + task, "Now, you have " + Task.taskCount + " in the list."); } public void farewellUser() { diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 657e74f6e..003ae5f22 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,7 +1,93 @@ -Hello from - ____ _ -| _ \ _ _| | _____ -| | | | | | | |/ / _ \ -| |_| | |_| | < __/ -|____/ \__,_|_|\_\___| - + ____________________________________________________________ + Hello from JRobo! I'm your personal assistant! + Nice to meet you. What can I do for you? + ____________________________________________________________ + ____________________________________________________________ + Got it. I've added this task: + [T][ ] get a good grade from CS2113 + Now, you have 1 in the list. + ____________________________________________________________ + ____________________________________________________________ + Got it. I've added this task: + [D][ ] work hard (by: May) + Now, you have 2 in the list. + ____________________________________________________________ + ____________________________________________________________ + Got it. I've added this task: + [E][ ] attend group meeting (at: Thursday 10PM) + Now, you have 3 in the list. + ____________________________________________________________ + ____________________________________________________________ + Nice! I've marked this task as done: + [X] attend group meeting + ____________________________________________________________ + ____________________________________________________________ + This task is already marked + ____________________________________________________________ + ____________________________________________________________ + Here are the tasks in your list: + 1.[T][ ] get a good grade from CS2113 + 2.[D][ ] work hard (by: May) + 3.[E][X] attend group meeting (at: Thursday 10PM) + ____________________________________________________________ + ____________________________________________________________ + Here are the tasks in your list: + 1.[T][ ] get a good grade from CS2113 + 2.[D][ ] work hard (by: May) + 3.[E][X] attend group meeting (at: Thursday 10PM) + ____________________________________________________________ + ____________________________________________________________ + Got it. I've added this task: + [E][ ] attend lecture (at: Friday 4PM) + Now, you have 4 in the list. + ____________________________________________________________ + ____________________________________________________________ + This task is already unmarked + ____________________________________________________________ + ____________________________________________________________ + Nice! I've marked this task as done: + [X] attend lecture + ____________________________________________________________ + ____________________________________________________________ + Nice! I've marked this task as undone: + [ ] attend lecture + ____________________________________________________________ + ____________________________________________________________ + Here are the tasks in your list: + 1.[T][ ] get a good grade from CS2113 + 2.[D][ ] work hard (by: May) + 3.[E][X] attend group meeting (at: Thursday 10PM) + 4.[E][ ] attend lecture (at: Friday 4PM) + ____________________________________________________________ + ____________________________________________________________ + Invalid command! + ____________________________________________________________ + ____________________________________________________________ + Invalid command! + ____________________________________________________________ + ____________________________________________________________ + Invalid command! + ____________________________________________________________ + ____________________________________________________________ + Invalid command! + ____________________________________________________________ + ____________________________________________________________ + Got it. I've added this task: + [D][ ] everything seems fine (by: now) + Now, you have 5 in the list. + ____________________________________________________________ + ____________________________________________________________ + Here are the tasks in your list: + 1.[T][ ] get a good grade from CS2113 + 2.[D][ ] work hard (by: May) + 3.[E][X] attend group meeting (at: Thursday 10PM) + 4.[E][ ] attend lecture (at: Friday 4PM) + 5.[D][ ] everything seems fine (by: now) + ____________________________________________________________ + ____________________________________________________________ + Nice! I've marked this task as done: + [X] everything seems fine + ____________________________________________________________ + ____________________________________________________________ + Bye. Hope to see you again soon! + ____________________________________________________________ diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index e69de29bb..68bcd3345 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -0,0 +1,20 @@ +todo get a good grade from CS2113 +deadline work hard /by May +event attend group meeting /at Thursday 10PM +mark 3 +m 3 +list +ls +e attend lecture /at Friday 4PM +unmark 4 +mark 4 +um 4 +ls +deadline test /at wrong format +event test /by wrong format +todo test /by wrong format +todo test /at wrong format +deadline everything seems fine /by now +ls +m 5 +quit diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 087374464..52821ac1a 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -15,7 +15,7 @@ IF ERRORLEVEL 1 ( REM no error here, errorlevel == 0 REM run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT -java -classpath ..\bin Duke < input.txt > ACTUAL.TXT +java -classpath ..\bin JRobo < input.txt > ACTUAL.TXT REM compare the output to the expected output FC ACTUAL.TXT EXPECTED.TXT diff --git a/text-ui-test/runtest.sh b/text-ui-test/runtest.sh index c9ec87003..31c1c7cc4 100644 --- a/text-ui-test/runtest.sh +++ b/text-ui-test/runtest.sh @@ -20,7 +20,7 @@ then fi # run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT -java -classpath ../bin Duke < input.txt > ACTUAL.TXT +java -classpath ../bin JRobo < input.txt > ACTUAL.TXT # convert to UNIX format cp EXPECTED.TXT EXPECTED-UNIX.TXT @@ -28,6 +28,7 @@ dos2unix ACTUAL.TXT EXPECTED-UNIX.TXT # compare the output to the expected output diff ACTUAL.TXT EXPECTED-UNIX.TXT +# shellcheck disable=SC2181 if [ $? -eq 0 ] then echo "Test result: PASSED" From 5ad4499a5cb213fc8ca7716cc2fc1187976e13cb Mon Sep 17 00:00:00 2001 From: edemirkirkan Date: Thu, 3 Feb 2022 01:59:38 +0800 Subject: [PATCH 09/26] General refactor --- src/main/java/Event.java | 1 - src/main/java/InputParser.java | 5 ++--- src/main/java/JRobo.java | 7 ++++++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 73e570f35..b14e94a5f 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -1,6 +1,5 @@ public class Event extends Task { - protected String by; protected String at; public Event(String description, String at) { diff --git a/src/main/java/InputParser.java b/src/main/java/InputParser.java index 08a5a1ede..a1042503f 100644 --- a/src/main/java/InputParser.java +++ b/src/main/java/InputParser.java @@ -24,7 +24,6 @@ public String getBody() { for (int i = 1; i < n; i++) { description.append(" ").append(args[i]); } - return description.toString(); } @@ -42,7 +41,8 @@ public String getSuffix() { } public boolean isValidCommand() { - return !(getPrefix() == null || ((getPrefix().equals("list") || getPrefix().equals("ls")) && !getBody().equals(""))); + return !(getPrefix() == null || ((getPrefix().equals("list") || getPrefix().equals("ls")) + && !getBody().equals(""))); } public String getType() { @@ -66,7 +66,6 @@ public String getType() { if (isEvent && (getPrefix().equals("event") || getPrefix().equals("e"))) { return "event"; } - return "invalid"; } diff --git a/src/main/java/JRobo.java b/src/main/java/JRobo.java index 7bba32977..9dae0327f 100644 --- a/src/main/java/JRobo.java +++ b/src/main/java/JRobo.java @@ -4,6 +4,11 @@ public class JRobo { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); TaskManager manager = new TaskManager(); + run(scanner, manager); + scanner.close(); + } + + public static void run(Scanner scanner, TaskManager manager) { manager.welcomeUser(); label: while (true) { @@ -39,6 +44,6 @@ public static void main(String[] args) { } } manager.farewellUser(); - scanner.close(); } + } From c1ec3f62ef12006369736d30f730b478e4f9726b Mon Sep 17 00:00:00 2001 From: edemirkirkan Date: Fri, 11 Feb 2022 09:46:22 +0800 Subject: [PATCH 10/26] Add input validations --- src/main/java/InputParser.java | 4 ++-- src/main/java/InvalidFormatException.java | 5 +++++ src/main/java/InvalidTypeException.java | 5 +++++ src/main/java/JRobo.java | 6 +++++- src/main/java/TaskManager.java | 5 ++--- 5 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 src/main/java/InvalidFormatException.java create mode 100644 src/main/java/InvalidTypeException.java diff --git a/src/main/java/InputParser.java b/src/main/java/InputParser.java index a1042503f..7e5751a96 100644 --- a/src/main/java/InputParser.java +++ b/src/main/java/InputParser.java @@ -45,7 +45,7 @@ public boolean isValidCommand() { && !getBody().equals(""))); } - public String getType() { + public String getType() throws InvalidFormatException { boolean isEvent = false; boolean isDeadline = false; for (String s : args) { @@ -66,7 +66,7 @@ public String getType() { if (isEvent && (getPrefix().equals("event") || getPrefix().equals("e"))) { return "event"; } - return "invalid"; + throw new InvalidFormatException("Invalid command format!"); } private int findSuffixIndex() { diff --git a/src/main/java/InvalidFormatException.java b/src/main/java/InvalidFormatException.java new file mode 100644 index 000000000..9f50c694e --- /dev/null +++ b/src/main/java/InvalidFormatException.java @@ -0,0 +1,5 @@ +public class InvalidFormatException extends Exception { + public InvalidFormatException(String errorMessage) { + super(errorMessage); + } +} \ No newline at end of file diff --git a/src/main/java/InvalidTypeException.java b/src/main/java/InvalidTypeException.java new file mode 100644 index 000000000..63383d505 --- /dev/null +++ b/src/main/java/InvalidTypeException.java @@ -0,0 +1,5 @@ +public class InvalidTypeException extends Exception { + public InvalidTypeException(String errorMessage) { + super(errorMessage); + } +} \ No newline at end of file diff --git a/src/main/java/JRobo.java b/src/main/java/JRobo.java index 9dae0327f..75409f372 100644 --- a/src/main/java/JRobo.java +++ b/src/main/java/JRobo.java @@ -39,7 +39,11 @@ public static void run(Scanner scanner, TaskManager manager) { case "q": break label; default: - manager.addTask(parser.getBody(), parser.getSuffix(), parser.getType()); + try { + manager.addTask(parser.getBody(), parser.getSuffix(), parser.getType()); + } catch (InvalidFormatException | InvalidTypeException e) { + manager.printWithSeparator(e.getMessage()); + } break; } } diff --git a/src/main/java/TaskManager.java b/src/main/java/TaskManager.java index 512f8cd00..0abf623ef 100644 --- a/src/main/java/TaskManager.java +++ b/src/main/java/TaskManager.java @@ -73,7 +73,7 @@ public void unmarkTask(String input) { } } - public void addTask(String description, String detail, String type) { + public void addTask(String description, String detail, String type) throws InvalidTypeException { Task task; switch (type) { case "todo": @@ -86,8 +86,7 @@ public void addTask(String description, String detail, String type) { task = new Event(description, detail); break; default: - giveError(); - return; + throw new InvalidTypeException("Invalid command!"); } tasks.add(task); printWithSeparator("Got it. I've added this task:", "\t" + task, "Now, you have " + Task.taskCount + " in the list."); From 4bac0881a625d7926b7a423adef011e3bc3cafde Mon Sep 17 00:00:00 2001 From: edemirkirkan Date: Fri, 11 Feb 2022 10:00:21 +0800 Subject: [PATCH 11/26] Add packages --- src/main/java/JRobo.java | 3 +++ src/main/java/{ => jrobo/command}/InputParser.java | 2 ++ src/main/java/{ => jrobo/task}/Deadline.java | 4 ++++ src/main/java/{ => jrobo/task}/Event.java | 4 ++++ src/main/java/{ => jrobo/task}/Task.java | 2 ++ src/main/java/{ => jrobo/task}/TaskManager.java | 7 +++++++ src/main/java/{ => jrobo/task}/Todo.java | 4 ++++ 7 files changed, 26 insertions(+) rename src/main/java/{ => jrobo/command}/InputParser.java (99%) rename src/main/java/{ => jrobo/task}/Deadline.java (86%) rename src/main/java/{ => jrobo/task}/Event.java (85%) rename src/main/java/{ => jrobo/task}/Task.java (97%) rename src/main/java/{ => jrobo/task}/TaskManager.java (96%) rename src/main/java/{ => jrobo/task}/Todo.java (81%) diff --git a/src/main/java/JRobo.java b/src/main/java/JRobo.java index 9dae0327f..e33ed14a6 100644 --- a/src/main/java/JRobo.java +++ b/src/main/java/JRobo.java @@ -1,3 +1,6 @@ +import jrobo.command.InputParser; +import jrobo.task.TaskManager; + import java.util.Scanner; public class JRobo { diff --git a/src/main/java/InputParser.java b/src/main/java/jrobo/command/InputParser.java similarity index 99% rename from src/main/java/InputParser.java rename to src/main/java/jrobo/command/InputParser.java index a1042503f..1ed89986f 100644 --- a/src/main/java/InputParser.java +++ b/src/main/java/jrobo/command/InputParser.java @@ -1,3 +1,5 @@ +package jrobo.command; + public class InputParser { protected String[] args; protected static String[] validCommands = {"mark", "m", "unmark", "um", "todo", "t", "deadline", "d", "event", "e", "list", "ls", "bye", "exit", "quit", "q"}; diff --git a/src/main/java/Deadline.java b/src/main/java/jrobo/task/Deadline.java similarity index 86% rename from src/main/java/Deadline.java rename to src/main/java/jrobo/task/Deadline.java index 0bfcc263a..5079fd08f 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/jrobo/task/Deadline.java @@ -1,3 +1,7 @@ +package jrobo.task; + +import jrobo.task.Task; + public class Deadline extends Task { protected String by; diff --git a/src/main/java/Event.java b/src/main/java/jrobo/task/Event.java similarity index 85% rename from src/main/java/Event.java rename to src/main/java/jrobo/task/Event.java index b14e94a5f..e301ea9a9 100644 --- a/src/main/java/Event.java +++ b/src/main/java/jrobo/task/Event.java @@ -1,3 +1,7 @@ +package jrobo.task; + +import jrobo.task.Task; + public class Event extends Task { protected String at; diff --git a/src/main/java/Task.java b/src/main/java/jrobo/task/Task.java similarity index 97% rename from src/main/java/Task.java rename to src/main/java/jrobo/task/Task.java index 0b1f47e0b..70335d4f6 100644 --- a/src/main/java/Task.java +++ b/src/main/java/jrobo/task/Task.java @@ -1,3 +1,5 @@ +package jrobo.task; + public class Task { protected String description; protected boolean isDone; diff --git a/src/main/java/TaskManager.java b/src/main/java/jrobo/task/TaskManager.java similarity index 96% rename from src/main/java/TaskManager.java rename to src/main/java/jrobo/task/TaskManager.java index 512f8cd00..2c571622c 100644 --- a/src/main/java/TaskManager.java +++ b/src/main/java/jrobo/task/TaskManager.java @@ -1,3 +1,10 @@ +package jrobo.task; + +import jrobo.task.Deadline; +import jrobo.task.Event; +import jrobo.task.Task; +import jrobo.task.Todo; + import java.util.ArrayList; public class TaskManager { diff --git a/src/main/java/Todo.java b/src/main/java/jrobo/task/Todo.java similarity index 81% rename from src/main/java/Todo.java rename to src/main/java/jrobo/task/Todo.java index e0e40d5d9..d8c06d034 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/jrobo/task/Todo.java @@ -1,3 +1,7 @@ +package jrobo.task; + +import jrobo.task.Task; + public class Todo extends Task { From 32a083890dca747429bc75f99ac30228fbc13ca2 Mon Sep 17 00:00:00 2001 From: edemirkirkan Date: Fri, 11 Feb 2022 10:12:58 +0800 Subject: [PATCH 12/26] Add packages --- src/main/java/JRobo.java | 2 +- src/main/java/jrobo/command/InputParser.java | 2 ++ .../{ => jrobo/exception}/InvalidFormatException.java | 2 ++ .../java/{ => jrobo/exception}/InvalidTypeException.java | 2 ++ src/main/java/jrobo/task/TaskManager.java | 8 +++----- 5 files changed, 10 insertions(+), 6 deletions(-) rename src/main/java/{ => jrobo/exception}/InvalidFormatException.java (85%) rename src/main/java/{ => jrobo/exception}/InvalidTypeException.java (84%) diff --git a/src/main/java/JRobo.java b/src/main/java/JRobo.java index 9ce7fb7c6..abf699202 100644 --- a/src/main/java/JRobo.java +++ b/src/main/java/JRobo.java @@ -44,7 +44,7 @@ public static void run(Scanner scanner, TaskManager manager) { default: try { manager.addTask(parser.getBody(), parser.getSuffix(), parser.getType()); - } catch (InvalidFormatException | InvalidTypeException e) { + } catch (jrobo.exception.InvalidFormatException | jrobo.exception.InvalidTypeException e) { manager.printWithSeparator(e.getMessage()); } break; diff --git a/src/main/java/jrobo/command/InputParser.java b/src/main/java/jrobo/command/InputParser.java index 3c7551a47..a6b22eb1c 100644 --- a/src/main/java/jrobo/command/InputParser.java +++ b/src/main/java/jrobo/command/InputParser.java @@ -1,5 +1,7 @@ package jrobo.command; +import jrobo.exception.InvalidFormatException; + public class InputParser { protected String[] args; protected static String[] validCommands = {"mark", "m", "unmark", "um", "todo", "t", "deadline", "d", "event", "e", "list", "ls", "bye", "exit", "quit", "q"}; diff --git a/src/main/java/InvalidFormatException.java b/src/main/java/jrobo/exception/InvalidFormatException.java similarity index 85% rename from src/main/java/InvalidFormatException.java rename to src/main/java/jrobo/exception/InvalidFormatException.java index 9f50c694e..77dea8383 100644 --- a/src/main/java/InvalidFormatException.java +++ b/src/main/java/jrobo/exception/InvalidFormatException.java @@ -1,3 +1,5 @@ +package jrobo.exception; + public class InvalidFormatException extends Exception { public InvalidFormatException(String errorMessage) { super(errorMessage); diff --git a/src/main/java/InvalidTypeException.java b/src/main/java/jrobo/exception/InvalidTypeException.java similarity index 84% rename from src/main/java/InvalidTypeException.java rename to src/main/java/jrobo/exception/InvalidTypeException.java index 63383d505..e68c420a7 100644 --- a/src/main/java/InvalidTypeException.java +++ b/src/main/java/jrobo/exception/InvalidTypeException.java @@ -1,3 +1,5 @@ +package jrobo.exception; + public class InvalidTypeException extends Exception { public InvalidTypeException(String errorMessage) { super(errorMessage); diff --git a/src/main/java/jrobo/task/TaskManager.java b/src/main/java/jrobo/task/TaskManager.java index b72dec711..44453d7b5 100644 --- a/src/main/java/jrobo/task/TaskManager.java +++ b/src/main/java/jrobo/task/TaskManager.java @@ -1,9 +1,7 @@ package jrobo.task; -import jrobo.task.Deadline; -import jrobo.task.Event; -import jrobo.task.Task; -import jrobo.task.Todo; + +import jrobo.exception.InvalidTypeException; import java.util.ArrayList; @@ -14,7 +12,7 @@ public TaskManager() { this.tasks = new ArrayList<>(); } - protected void printWithSeparator(String... strings) { + public void printWithSeparator(String... strings) { System.out.println("\t____________________________________________________________"); for (String s : strings) { System.out.println("\t" + s); From 2192bdf49d5bdf696a3f0b597710b9ba575ab32e Mon Sep 17 00:00:00 2001 From: edemirkirkan Date: Fri, 18 Feb 2022 08:07:43 +0800 Subject: [PATCH 13/26] Implement delete task capability --- src/main/java/JRobo.java | 51 +++++++++++--------- src/main/java/jrobo/command/InputParser.java | 2 +- src/main/java/jrobo/task/TaskManager.java | 14 +++++- 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/src/main/java/JRobo.java b/src/main/java/JRobo.java index abf699202..65485a4b6 100644 --- a/src/main/java/JRobo.java +++ b/src/main/java/JRobo.java @@ -23,31 +23,36 @@ public static void run(Scanner scanner, TaskManager manager) { continue; } String command = parser.getPrefix(); - switch (command) { - case "mark": - case "m": - manager.markTask(parser.getBody()); - break; - case "unmark": - case "um": - manager.unmarkTask(parser.getBody()); - break; - case "list": - case "ls": - manager.displayTaskList(); - break; - case "bye": - case "b": - case "quit": - case "q": - break label; - default: - try { + try { + switch (command) { + case "mark": + case "m": + manager.markTask(parser.getBody()); + break; + case "unmark": + case "um": + manager.unmarkTask(parser.getBody()); + break; + case "list": + case "ls": + manager.displayTaskList(); + break; + case "delete": + case "del": + manager.deleteTask(Integer.parseInt(parser.getBody().trim())); + break; + case "bye": + case "b": + case "quit": + case "q": + break label; + default: + manager.addTask(parser.getBody(), parser.getSuffix(), parser.getType()); - } catch (jrobo.exception.InvalidFormatException | jrobo.exception.InvalidTypeException e) { - manager.printWithSeparator(e.getMessage()); + break; } - break; + } catch (jrobo.exception.InvalidFormatException | jrobo.exception.InvalidTypeException | NumberFormatException e) { + manager.printWithSeparator(e.getMessage()); } } manager.farewellUser(); diff --git a/src/main/java/jrobo/command/InputParser.java b/src/main/java/jrobo/command/InputParser.java index a6b22eb1c..5b041d525 100644 --- a/src/main/java/jrobo/command/InputParser.java +++ b/src/main/java/jrobo/command/InputParser.java @@ -4,7 +4,7 @@ public class InputParser { protected String[] args; - protected static String[] validCommands = {"mark", "m", "unmark", "um", "todo", "t", "deadline", "d", "event", "e", "list", "ls", "bye", "exit", "quit", "q"}; + protected static String[] validCommands = {"mark", "m", "unmark", "um", "todo", "t", "deadline", "d", "event", "e", "list", "ls", "bye", "exit", "quit", "q", "delete", "del"}; public InputParser(String input) { this.args = input.split(" "); diff --git a/src/main/java/jrobo/task/TaskManager.java b/src/main/java/jrobo/task/TaskManager.java index 44453d7b5..d1c3d3016 100644 --- a/src/main/java/jrobo/task/TaskManager.java +++ b/src/main/java/jrobo/task/TaskManager.java @@ -32,7 +32,7 @@ public void displayTaskList() { } System.out.println("\t____________________________________________________________"); System.out.println("\tHere are the tasks in your list:"); - int taskCount = Task.getTaskCount(); + int taskCount = tasks.size(); for (int i = 0; i < taskCount; i++) { Task t = tasks.get(i); System.out.println("\t" + (i + 1) + "." + t); @@ -94,7 +94,17 @@ public void addTask(String description, String detail, String type) throws Inval throw new InvalidTypeException("Invalid command!"); } tasks.add(task); - printWithSeparator("Got it. I've added this task:", "\t" + task, "Now, you have " + Task.taskCount + " in the list."); + printWithSeparator("Got it. I've added this task:", "\t" + task, "Now, you have " + tasks.size() + " in the list."); + } + + public void deleteTask(int index) { + if (tasks.size() == 0) { + printWithSeparator("Invalid command! Nothing to delete."); + return; + } + printWithSeparator("Noted. I've removed this task:", "\t" + tasks.get(index - 1).toString(), + "Now you have " + (tasks.size() - 1) + " tasks in the list."); + tasks.remove(index - 1); } public void farewellUser() { From f76aa33eec17bf09e0613940135b1af81f27a287 Mon Sep 17 00:00:00 2001 From: edemirkirkan Date: Fri, 18 Feb 2022 09:48:08 +0800 Subject: [PATCH 14/26] Implement save and load capabilities --- data/tasks.txt | 3 ++ src/main/java/JRobo.java | 7 ++- src/main/java/jrobo/command/InputParser.java | 21 ++++++++ src/main/java/jrobo/task/TaskManager.java | 56 +++++++++++++++++++- 4 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 data/tasks.txt diff --git a/data/tasks.txt b/data/tasks.txt new file mode 100644 index 000000000..4ae62f51d --- /dev/null +++ b/data/tasks.txt @@ -0,0 +1,3 @@ +[T][ ] sadlaskld +[T][ ] asdşaslşdasldas +[T][ ] asdöa sdasda diff --git a/src/main/java/JRobo.java b/src/main/java/JRobo.java index 65485a4b6..bc9b22e68 100644 --- a/src/main/java/JRobo.java +++ b/src/main/java/JRobo.java @@ -1,13 +1,18 @@ import jrobo.command.InputParser; +import jrobo.task.Task; import jrobo.task.TaskManager; +import java.io.FileWriter; +import java.io.IOException; import java.util.Scanner; public class JRobo { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); TaskManager manager = new TaskManager(); + manager.load(); run(scanner, manager); + manager.save(); scanner.close(); } @@ -48,7 +53,7 @@ public static void run(Scanner scanner, TaskManager manager) { break label; default: - manager.addTask(parser.getBody(), parser.getSuffix(), parser.getType()); + manager.addTask(parser.getBody(), parser.getSuffix(), parser.getType(), false); break; } } catch (jrobo.exception.InvalidFormatException | jrobo.exception.InvalidTypeException | NumberFormatException e) { diff --git a/src/main/java/jrobo/command/InputParser.java b/src/main/java/jrobo/command/InputParser.java index 5b041d525..8c261b24a 100644 --- a/src/main/java/jrobo/command/InputParser.java +++ b/src/main/java/jrobo/command/InputParser.java @@ -73,6 +73,27 @@ public String getType() throws InvalidFormatException { throw new InvalidFormatException("Invalid command format!"); } + public String[] loadParse(String taskStr) { + int index = taskStr.lastIndexOf(']'); + String prefix = taskStr.substring(0, index); + String body; + String suffix; + boolean isDeadline = prefix.contains("D"); + boolean isEvent = prefix.contains("E"); + if (isEvent) { + suffix = taskStr.substring(taskStr.indexOf("at:") + 3, taskStr.length() - 1); + body = taskStr.substring(index + 1, taskStr.indexOf('(') - 1); + return new String[] {body, suffix, "event"}; + } else if (isDeadline) { + suffix = taskStr.substring(taskStr.indexOf("by:") + 3, taskStr.length() - 1); + body = taskStr.substring(index + 1, taskStr.indexOf('(') - 1); + return new String[] {body, suffix, "deadline"}; + } else { + body = taskStr.substring(index + 1); + return new String[] {body, "", "todo"}; + } + } + private int findSuffixIndex() { int found = -1; for (int i = 0; i < args.length; i++) { diff --git a/src/main/java/jrobo/task/TaskManager.java b/src/main/java/jrobo/task/TaskManager.java index d1c3d3016..846d4d9ff 100644 --- a/src/main/java/jrobo/task/TaskManager.java +++ b/src/main/java/jrobo/task/TaskManager.java @@ -1,9 +1,15 @@ package jrobo.task; +import jrobo.command.InputParser; import jrobo.exception.InvalidTypeException; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; import java.util.ArrayList; +import java.util.Scanner; public class TaskManager { ArrayList tasks; @@ -78,7 +84,8 @@ public void unmarkTask(String input) { } } - public void addTask(String description, String detail, String type) throws InvalidTypeException { + public void addTask(String description, String detail, String type, boolean loadFlag) + throws InvalidTypeException { Task task; switch (type) { case "todo": @@ -94,7 +101,10 @@ public void addTask(String description, String detail, String type) throws Inval throw new InvalidTypeException("Invalid command!"); } tasks.add(task); - printWithSeparator("Got it. I've added this task:", "\t" + task, "Now, you have " + tasks.size() + " in the list."); + if (!loadFlag) { + printWithSeparator("Got it. I've added this task:", "\t" + task, + "Now, you have " + tasks.size() + " in the list."); + } } public void deleteTask(int index) { @@ -114,4 +124,46 @@ public void farewellUser() { public void giveError() { printWithSeparator("Invalid command!"); } + + public void save() { + try { + FileWriter fileWriter = new FileWriter("./ip/data/tasks.txt", true); + clear(); + for (Task task : tasks) { + fileWriter.write(task.toString() + "\n"); + } + fileWriter.close(); + } catch (IOException e) { + printWithSeparator(e.getMessage()); + } + } + + public void load() { + try { + File file = new File("./ip/data/tasks.txt"); + + Scanner scanner = new Scanner(file); + + while (scanner.hasNext()) { + String taskStr = scanner.nextLine(); + InputParser parser = new InputParser(taskStr); + String[] taskDetails = parser.loadParse(taskStr); + addTask(taskDetails[0], taskDetails[1], taskDetails[2], true); + } + } catch (IOException | InvalidTypeException e) { + printWithSeparator(e.getMessage()); + } + } + + public void clear() { + try { + FileWriter fwOb = new FileWriter("./ip/data/tasks.txt", false); + PrintWriter pwOb = new PrintWriter(fwOb, false); + pwOb.flush(); + pwOb.close(); + fwOb.close(); + } catch (IOException e) { + printWithSeparator(e.getMessage()); + } + } } From 1a2c296ef7219f3eb24d4fd0e8b144c61e104068 Mon Sep 17 00:00:00 2001 From: edemirkirkan Date: Fri, 18 Feb 2022 11:17:36 +0800 Subject: [PATCH 15/26] Creating binary JAR file --- data/tasks.txt | 4 +--- src/main/java/META-INF/MANIFEST.MF | 3 +++ 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 src/main/java/META-INF/MANIFEST.MF diff --git a/data/tasks.txt b/data/tasks.txt index 4ae62f51d..3f5f57048 100644 --- a/data/tasks.txt +++ b/data/tasks.txt @@ -1,3 +1 @@ -[T][ ] sadlaskld -[T][ ] asdşaslşdasldas -[T][ ] asdöa sdasda +[E][ ] Ege Demirkirkan attend CS2113 lecture (at: Friday 18 Feb 2022 from 4 to 6pm) diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 000000000..924ce173d --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: JRobo + From 2d2161c3d3698c53306efb04dcef7d0daefff5be Mon Sep 17 00:00:00 2001 From: edemirkirkan Date: Wed, 23 Feb 2022 17:48:26 +0800 Subject: [PATCH 16/26] add storage and ui classes --- data/tasks.txt | 1 + src/main/java/JRobo.java | 62 ++++------------------ src/main/java/jrobo/storage/Storage.java | 62 ++++++++++++++++++++++ src/main/java/jrobo/task/TaskManager.java | 49 +----------------- src/main/java/jrobo/ui/UI.java | 63 +++++++++++++++++++++++ 5 files changed, 137 insertions(+), 100 deletions(-) create mode 100644 src/main/java/jrobo/storage/Storage.java create mode 100644 src/main/java/jrobo/ui/UI.java diff --git a/data/tasks.txt b/data/tasks.txt index 3f5f57048..cb32cef2a 100644 --- a/data/tasks.txt +++ b/data/tasks.txt @@ -1 +1,2 @@ [E][ ] Ege Demirkirkan attend CS2113 lecture (at: Friday 18 Feb 2022 from 4 to 6pm) +[D][ ] meet your girlfrind (by: tommorow) diff --git a/src/main/java/JRobo.java b/src/main/java/JRobo.java index bc9b22e68..55b17cfe0 100644 --- a/src/main/java/JRobo.java +++ b/src/main/java/JRobo.java @@ -1,66 +1,22 @@ -import jrobo.command.InputParser; -import jrobo.task.Task; +import jrobo.storage.Storage; import jrobo.task.TaskManager; +import jrobo.ui.UI; -import java.io.FileWriter; -import java.io.IOException; import java.util.Scanner; public class JRobo { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); TaskManager manager = new TaskManager(); - manager.load(); - run(scanner, manager); - manager.save(); + Storage storage = new Storage(manager); + UI ui = new UI(scanner, manager); + run(storage, ui); scanner.close(); } - public static void run(Scanner scanner, TaskManager manager) { - manager.welcomeUser(); - label: - while (true) { - String input = scanner.nextLine(); - InputParser parser = new InputParser(input); - - if (!parser.isValidCommand()) { - manager.giveError(); - continue; - } - String command = parser.getPrefix(); - try { - switch (command) { - case "mark": - case "m": - manager.markTask(parser.getBody()); - break; - case "unmark": - case "um": - manager.unmarkTask(parser.getBody()); - break; - case "list": - case "ls": - manager.displayTaskList(); - break; - case "delete": - case "del": - manager.deleteTask(Integer.parseInt(parser.getBody().trim())); - break; - case "bye": - case "b": - case "quit": - case "q": - break label; - default: - - manager.addTask(parser.getBody(), parser.getSuffix(), parser.getType(), false); - break; - } - } catch (jrobo.exception.InvalidFormatException | jrobo.exception.InvalidTypeException | NumberFormatException e) { - manager.printWithSeparator(e.getMessage()); - } - } - manager.farewellUser(); + public static void run(Storage storage, UI ui) { + storage.load(); + ui.setView(); + storage.save(); } - } diff --git a/src/main/java/jrobo/storage/Storage.java b/src/main/java/jrobo/storage/Storage.java new file mode 100644 index 000000000..cc86a18e8 --- /dev/null +++ b/src/main/java/jrobo/storage/Storage.java @@ -0,0 +1,62 @@ +package jrobo.storage; + +import jrobo.command.InputParser; +import jrobo.exception.InvalidTypeException; +import jrobo.task.Task; +import jrobo.task.TaskManager; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class Storage { + TaskManager manager; + + public Storage(TaskManager manager) { + this.manager = manager; + } + + public void save() { + try { + FileWriter fileWriter = new FileWriter("./ip/data/tasks.txt", true); + clear(); + for (Task task : manager.getTaskList()) { + fileWriter.write(task.toString() + "\n"); + } + fileWriter.close(); + } catch (IOException e) { + manager.printWithSeparator(e.getMessage()); + } + } + + public void load() { + try { + File file = new File("./ip/data/tasks.txt"); + + Scanner scanner = new Scanner(file); + + while (scanner.hasNext()) { + String taskStr = scanner.nextLine(); + InputParser parser = new InputParser(taskStr); + String[] taskDetails = parser.loadParse(taskStr); + manager.addTask(taskDetails[0], taskDetails[1], taskDetails[2], true); + } + } catch (IOException | InvalidTypeException e) { + manager.printWithSeparator(e.getMessage()); + } + } + + private void clear() { + try { + FileWriter fwOb = new FileWriter("./ip/data/tasks.txt", false); + PrintWriter pwOb = new PrintWriter(fwOb, false); + pwOb.flush(); + pwOb.close(); + fwOb.close(); + } catch (IOException e) { + manager.printWithSeparator(e.getMessage()); + } + } +} diff --git a/src/main/java/jrobo/task/TaskManager.java b/src/main/java/jrobo/task/TaskManager.java index 846d4d9ff..92f16cbf0 100644 --- a/src/main/java/jrobo/task/TaskManager.java +++ b/src/main/java/jrobo/task/TaskManager.java @@ -1,15 +1,8 @@ package jrobo.task; - -import jrobo.command.InputParser; import jrobo.exception.InvalidTypeException; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; import java.util.ArrayList; -import java.util.Scanner; public class TaskManager { ArrayList tasks; @@ -125,45 +118,7 @@ public void giveError() { printWithSeparator("Invalid command!"); } - public void save() { - try { - FileWriter fileWriter = new FileWriter("./ip/data/tasks.txt", true); - clear(); - for (Task task : tasks) { - fileWriter.write(task.toString() + "\n"); - } - fileWriter.close(); - } catch (IOException e) { - printWithSeparator(e.getMessage()); - } - } - - public void load() { - try { - File file = new File("./ip/data/tasks.txt"); - - Scanner scanner = new Scanner(file); - - while (scanner.hasNext()) { - String taskStr = scanner.nextLine(); - InputParser parser = new InputParser(taskStr); - String[] taskDetails = parser.loadParse(taskStr); - addTask(taskDetails[0], taskDetails[1], taskDetails[2], true); - } - } catch (IOException | InvalidTypeException e) { - printWithSeparator(e.getMessage()); - } - } - - public void clear() { - try { - FileWriter fwOb = new FileWriter("./ip/data/tasks.txt", false); - PrintWriter pwOb = new PrintWriter(fwOb, false); - pwOb.flush(); - pwOb.close(); - fwOb.close(); - } catch (IOException e) { - printWithSeparator(e.getMessage()); - } + public ArrayList getTaskList() { + return tasks; } } diff --git a/src/main/java/jrobo/ui/UI.java b/src/main/java/jrobo/ui/UI.java new file mode 100644 index 000000000..e82fe3986 --- /dev/null +++ b/src/main/java/jrobo/ui/UI.java @@ -0,0 +1,63 @@ +package jrobo.ui; + +import jrobo.command.InputParser; +import jrobo.task.TaskManager; + +import java.util.Scanner; + +public class UI { + Scanner scanner; + TaskManager manager; + + public UI(Scanner scanner, TaskManager manager) { + this.scanner = scanner; + this.manager = manager; + } + + public void setView() { + manager.welcomeUser(); + label: + while (true) { + String input = scanner.nextLine(); + InputParser parser = new InputParser(input); + + if (!parser.isValidCommand()) { + manager.giveError(); + continue; + } + String command = parser.getPrefix(); + try { + switch (command) { + case "mark": + case "m": + manager.markTask(parser.getBody()); + break; + case "unmark": + case "um": + manager.unmarkTask(parser.getBody()); + break; + case "list": + case "ls": + manager.displayTaskList(); + break; + case "delete": + case "del": + manager.deleteTask(Integer.parseInt(parser.getBody().trim())); + break; + case "bye": + case "b": + case "quit": + case "q": + break label; + default: + + manager.addTask(parser.getBody(), parser.getSuffix(), parser.getType(), false); + break; + } + } catch (jrobo.exception.InvalidFormatException | jrobo.exception.InvalidTypeException | NumberFormatException e) { + manager.printWithSeparator(e.getMessage()); + } + } + manager.farewellUser(); + } +} From 5dca80318ed64328683061ae70926759647475a0 Mon Sep 17 00:00:00 2001 From: edemirkirkan Date: Wed, 23 Feb 2022 18:04:40 +0800 Subject: [PATCH 17/26] add date capabilities --- src/main/java/jrobo/task/Deadline.java | 10 +++++++++- src/main/java/jrobo/task/Event.java | 11 +++++++++-- src/main/java/jrobo/task/Todo.java | 2 -- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/jrobo/task/Deadline.java b/src/main/java/jrobo/task/Deadline.java index 5079fd08f..3e4d19a2d 100644 --- a/src/main/java/jrobo/task/Deadline.java +++ b/src/main/java/jrobo/task/Deadline.java @@ -1,6 +1,8 @@ package jrobo.task; -import jrobo.task.Task; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; public class Deadline extends Task { @@ -9,6 +11,12 @@ public class Deadline extends Task { public Deadline(String description, String by) { super(description); this.by = by; + try { + LocalDate date = LocalDate.parse(by.trim()); + this.by = " " + date.format(DateTimeFormatter.ofPattern("MMM d yyyy")); + } catch (DateTimeParseException e) { + this.by = by; + } } @Override diff --git a/src/main/java/jrobo/task/Event.java b/src/main/java/jrobo/task/Event.java index e301ea9a9..eb9b8afab 100644 --- a/src/main/java/jrobo/task/Event.java +++ b/src/main/java/jrobo/task/Event.java @@ -1,6 +1,8 @@ package jrobo.task; -import jrobo.task.Task; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; public class Event extends Task { @@ -8,7 +10,12 @@ public class Event extends Task { public Event(String description, String at) { super(description); - this.at = at; + try { + LocalDate date = LocalDate.parse(at.trim()); + this.at = " " + date.format(DateTimeFormatter.ofPattern("MMM d yyyy")); + } catch (DateTimeParseException e) { + this.at = at; + } } @Override diff --git a/src/main/java/jrobo/task/Todo.java b/src/main/java/jrobo/task/Todo.java index d8c06d034..7adcdcb7c 100644 --- a/src/main/java/jrobo/task/Todo.java +++ b/src/main/java/jrobo/task/Todo.java @@ -1,7 +1,5 @@ package jrobo.task; -import jrobo.task.Task; - public class Todo extends Task { From fc6a3223788386405121fdd79ce76adf652fb463 Mon Sep 17 00:00:00 2001 From: edemirkirkan Date: Wed, 23 Feb 2022 18:23:54 +0800 Subject: [PATCH 18/26] add find task command --- src/main/java/jrobo/command/InputParser.java | 3 ++- src/main/java/jrobo/task/TaskManager.java | 13 +++++++++++++ src/main/java/jrobo/ui/UI.java | 4 ++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/jrobo/command/InputParser.java b/src/main/java/jrobo/command/InputParser.java index 8c261b24a..4b0bb4bce 100644 --- a/src/main/java/jrobo/command/InputParser.java +++ b/src/main/java/jrobo/command/InputParser.java @@ -4,7 +4,8 @@ public class InputParser { protected String[] args; - protected static String[] validCommands = {"mark", "m", "unmark", "um", "todo", "t", "deadline", "d", "event", "e", "list", "ls", "bye", "exit", "quit", "q", "delete", "del"}; + protected static String[] validCommands = {"mark", "m", "unmark", "um", "todo", "t", "deadline", "d", + "event", "e", "list", "ls", "bye", "exit", "quit", "q", "delete", "del", "find", "f"}; public InputParser(String input) { this.args = input.split(" "); diff --git a/src/main/java/jrobo/task/TaskManager.java b/src/main/java/jrobo/task/TaskManager.java index 92f16cbf0..fccff04bc 100644 --- a/src/main/java/jrobo/task/TaskManager.java +++ b/src/main/java/jrobo/task/TaskManager.java @@ -7,6 +7,7 @@ public class TaskManager { ArrayList tasks; + public TaskManager() { this.tasks = new ArrayList<>(); } @@ -121,4 +122,16 @@ public void giveError() { public ArrayList getTaskList() { return tasks; } + + public void findTask(String toFind) { + System.out.println("\t____________________________________________________________"); + System.out.println("\tHere are the matching tasks in your list:"); + int index = 1; + for (Task t : tasks) { + if (t.getDescription().toLowerCase().contains(toFind.toLowerCase())) { + System.out.println("\t" + (index++) + "." + t); + } + } + System.out.println("\t____________________________________________________________"); + } } diff --git a/src/main/java/jrobo/ui/UI.java b/src/main/java/jrobo/ui/UI.java index e82fe3986..0789e61a7 100644 --- a/src/main/java/jrobo/ui/UI.java +++ b/src/main/java/jrobo/ui/UI.java @@ -44,6 +44,10 @@ public void setView() { case "del": manager.deleteTask(Integer.parseInt(parser.getBody().trim())); break; + case "find": + case "f": + manager.findTask(parser.getBody()); + break; case "bye": case "b": case "quit": From 29892882ea6f0b42baa6e6b3e9bc1f48b13d7648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ege=20Demirk=C4=B1rkan?= Date: Wed, 23 Feb 2022 20:26:57 +0800 Subject: [PATCH 19/26] Set theme jekyll-theme-architect --- _config.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 _config.yml diff --git a/_config.yml b/_config.yml new file mode 100644 index 000000000..3397c9a49 --- /dev/null +++ b/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-architect \ No newline at end of file From d891fd58586d134abce29904ef58fe0abc964193 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ege=20Demirk=C4=B1rkan?= Date: Wed, 23 Feb 2022 20:29:04 +0800 Subject: [PATCH 20/26] Set theme jekyll-theme-tactile --- _config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_config.yml b/_config.yml index 3397c9a49..259a24e4d 100644 --- a/_config.yml +++ b/_config.yml @@ -1 +1 @@ -theme: jekyll-theme-architect \ No newline at end of file +theme: jekyll-theme-tactile \ No newline at end of file From 20632e845c8542117efb925dd42af4e567b0830d Mon Sep 17 00:00:00 2001 From: edemirkirkan Date: Wed, 23 Feb 2022 21:26:10 +0800 Subject: [PATCH 21/26] add documentation --- src/main/java/jrobo/command/InputParser.java | 42 +++++++++++++++++++- src/main/java/jrobo/storage/Storage.java | 13 +++++- src/main/java/jrobo/task/Task.java | 30 ++++++++++++-- src/main/java/jrobo/task/TaskManager.java | 39 ++++++++++++++++++ src/main/java/jrobo/ui/UI.java | 9 +++++ 5 files changed, 127 insertions(+), 6 deletions(-) diff --git a/src/main/java/jrobo/command/InputParser.java b/src/main/java/jrobo/command/InputParser.java index 4b0bb4bce..29129d654 100644 --- a/src/main/java/jrobo/command/InputParser.java +++ b/src/main/java/jrobo/command/InputParser.java @@ -2,6 +2,12 @@ import jrobo.exception.InvalidFormatException; +/** + * InputParser is the class that receives and validate the input commands coming from CLI. + * + * @author Ege Demirkirkan + */ + public class InputParser { protected String[] args; protected static String[] validCommands = {"mark", "m", "unmark", "um", "todo", "t", "deadline", "d", @@ -11,6 +17,11 @@ public InputParser(String input) { this.args = input.split(" "); } + /** + * Returns the keyword of the user's command as a String object. + * + * @return the command's keyword + */ public String getPrefix() { for (String s : validCommands) { String command = args[0]; @@ -21,6 +32,11 @@ public String getPrefix() { return null; } + /** + * Returns the description of the user's CLI task command + * + * @return the task commands' description + */ public String getBody() { int suffixIndex = findSuffixIndex(); @@ -32,6 +48,11 @@ public String getBody() { return description.toString(); } + /** + * Returns the time details of the user's CLI task command + * + * @return the task commands' details regarding time + */ public String getSuffix() { int suffixIndex = findSuffixIndex(); if (suffixIndex == -1) { @@ -45,11 +66,23 @@ public String getSuffix() { return detail.toString(); } + /** + * Returns a boolean value that determines whether the CLI command is valid and properly formatted. + * + * @return a true or false according to correctness of command's format + */ public boolean isValidCommand() { return !(getPrefix() == null || ((getPrefix().equals("list") || getPrefix().equals("ls")) && !getBody().equals(""))); } + /** + * Returns the type of the task given in the command + * + * @return "todo", "deadline", or "event" + * @throws InvalidFormatException if the format of the command is wrong, + * display the related error text + */ public String getType() throws InvalidFormatException { boolean isEvent = false; boolean isDeadline = false; @@ -74,7 +107,14 @@ public String getType() throws InvalidFormatException { throw new InvalidFormatException("Invalid command format!"); } - public String[] loadParse(String taskStr) { + /** + * Returns the necessary information to be able to recreate Task objects. + * + * @param taskStr String object extracted from the text file that is used as a storage + * @return three element array, in which, command's description, time detail, and type respectively. + * @see jrobo.task.Task + */ + public String[] strToTask(String taskStr) { int index = taskStr.lastIndexOf(']'); String prefix = taskStr.substring(0, index); String body; diff --git a/src/main/java/jrobo/storage/Storage.java b/src/main/java/jrobo/storage/Storage.java index cc86a18e8..f493ee56b 100644 --- a/src/main/java/jrobo/storage/Storage.java +++ b/src/main/java/jrobo/storage/Storage.java @@ -11,6 +11,11 @@ import java.io.PrintWriter; import java.util.Scanner; +/** + * Storage is the class that provides save and load functionalities on each run of the program. + * + * @author Ege Demirkirkan + */ public class Storage { TaskManager manager; @@ -18,6 +23,9 @@ public Storage(TaskManager manager) { this.manager = manager; } + /** + * This method saves tasks to the storage + */ public void save() { try { FileWriter fileWriter = new FileWriter("./ip/data/tasks.txt", true); @@ -31,6 +39,9 @@ public void save() { } } + /** + * This method loads tasks from the storage + */ public void load() { try { File file = new File("./ip/data/tasks.txt"); @@ -40,7 +51,7 @@ public void load() { while (scanner.hasNext()) { String taskStr = scanner.nextLine(); InputParser parser = new InputParser(taskStr); - String[] taskDetails = parser.loadParse(taskStr); + String[] taskDetails = parser.strToTask(taskStr); manager.addTask(taskDetails[0], taskDetails[1], taskDetails[2], true); } } catch (IOException | InvalidTypeException e) { diff --git a/src/main/java/jrobo/task/Task.java b/src/main/java/jrobo/task/Task.java index 70335d4f6..9e8f72c56 100644 --- a/src/main/java/jrobo/task/Task.java +++ b/src/main/java/jrobo/task/Task.java @@ -1,5 +1,10 @@ package jrobo.task; +/** + * Task is the parent class of Deadline, Event, Todo. + * + * @author Ege Demirkirkan + */ public class Task { protected String description; protected boolean isDone; @@ -11,26 +16,43 @@ public Task(String description) { taskCount++; } - public static int getTaskCount() { - return taskCount; - } - + /** + * Returns task's status icon. + * + * @return "X" or " " according to the done status of the task + */ public String getStatusIcon() { return (isDone ? "X" : " "); } + /** + * Returns the main text of the task. + * + * @return description of the task + */ public String getDescription() { return description; } + /** + * Setter for isDone field. + */ public void markAsDone() { this.isDone = true; } + /** + * Setter for isDone field. + */ public void markAsUndone() { this.isDone = false; } + /** + * Returns a String object representing the Task + * + * @return the String that represents the task in the following format; [{status_icon}]{description} + */ @Override public String toString() { return "[" + getStatusIcon() + "]" + getDescription(); diff --git a/src/main/java/jrobo/task/TaskManager.java b/src/main/java/jrobo/task/TaskManager.java index fccff04bc..edc865f70 100644 --- a/src/main/java/jrobo/task/TaskManager.java +++ b/src/main/java/jrobo/task/TaskManager.java @@ -4,6 +4,12 @@ import java.util.ArrayList; +/** + * TaskManager is the class that manages everything regarding Task, Deadline, Event, Todo classes + * + * @author Ege Demirkirkan + */ + public class TaskManager { ArrayList tasks; @@ -25,6 +31,9 @@ public void welcomeUser() { "Nice to meet you. What can I do for you?"); } + /** + * This method displays all the tasks kept in the storage. + */ public void displayTaskList() { if (tasks.size() == 0) { printWithSeparator("You have no tasks to list."); @@ -40,6 +49,11 @@ public void displayTaskList() { System.out.println("\t____________________________________________________________"); } + /** + * This method is used for handle 'mark' command. It changes the status icon of the task. + * + * @param input String object representing the command in the following format; 'mark {int}' + */ public void markTask(String input) { String numberString = input.trim(); try { @@ -59,6 +73,11 @@ public void markTask(String input) { } } + /** + * This method is used for handle 'unmark' command. It changes the status icon of the task. + * + * @param input String object representing the command in the following format; 'unmark {int}' + */ public void unmarkTask(String input) { String numberString = input.trim(); try { @@ -78,6 +97,16 @@ public void unmarkTask(String input) { } } + /** + * This method add a task to the storage of the program. + * + * @param description main text of the task + * @param detail time detail of the task, null if the command is not the type deadline or event. + * @param type type of the task + * @param loadFlag boolean value that represents whether the task should be loaded + * @throws InvalidTypeException if the type of the command is wrong, + * displays the related error text + */ public void addTask(String description, String detail, String type, boolean loadFlag) throws InvalidTypeException { Task task; @@ -101,6 +130,11 @@ public void addTask(String description, String detail, String type, boolean load } } + /** + * This method delete a task from the storage of the program. + * + * @param index specifies the task to remove + */ public void deleteTask(int index) { if (tasks.size() == 0) { printWithSeparator("Invalid command! Nothing to delete."); @@ -123,6 +157,11 @@ public ArrayList getTaskList() { return tasks; } + /** + * This method search through the storage to find the related task to the search key + * + * @param toFind search key + */ public void findTask(String toFind) { System.out.println("\t____________________________________________________________"); System.out.println("\tHere are the matching tasks in your list:"); diff --git a/src/main/java/jrobo/ui/UI.java b/src/main/java/jrobo/ui/UI.java index 0789e61a7..5f5f13b70 100644 --- a/src/main/java/jrobo/ui/UI.java +++ b/src/main/java/jrobo/ui/UI.java @@ -5,6 +5,12 @@ import java.util.Scanner; +/** + * UI is the class that provides the program with the CLI view. + * + * @author Ege Demirkirkan + */ + public class UI { Scanner scanner; TaskManager manager; @@ -14,6 +20,9 @@ public UI(Scanner scanner, TaskManager manager) { this.manager = manager; } + /** + * This method creates and maintain the CLI view of the program. + */ public void setView() { manager.welcomeUser(); label: From b291c9685517ecb6e76acd252c9a8d08d332296c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ege=20Demirk=C4=B1rkan?= Date: Wed, 23 Feb 2022 21:30:40 +0800 Subject: [PATCH 22/26] Set theme jekyll-theme-tactile --- 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..259a24e4d --- /dev/null +++ b/docs/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-tactile \ No newline at end of file From a1203f00ca4496e39c3ca13113f9b5339193667a Mon Sep 17 00:00:00 2001 From: edemirkirkan Date: Thu, 24 Feb 2022 02:09:28 +0800 Subject: [PATCH 23/26] change README.md --- docs/README.md | 106 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 90 insertions(+), 16 deletions(-) diff --git a/docs/README.md b/docs/README.md index 8077118eb..eda2cf485 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,29 +1,103 @@ -# User Guide +# JRobo | Personal Todo App -## Features +JRobo is a command line application that you can use as your personal task tracker assistant. -### Feature-ABC +JRobo consists of various different commands and three type of tasks, which are **todo**, **deadline**, and **event**. +

+**Todos** are tasks that do not have any specific time or duration. +
+**Deadlines** are tasks that have a specific deadline that can be specified while adding. +
+**Events** are tasks that have a specific time and duration that can be specified while adding. -Description of the feature. +Note that, even if the application is terminated, JRobo will keep all tasks for you in his memory. -### Feature-XYZ +## Commands -Description of the feature. +### Add Task -## Usage +Tasks can be added using **todo**, **deadline**, **event** commands, or with their shortcut notations. -### `Keyword` - Describe action +#### Command format: -Describe the action and its outcome. +`todo{description}`
+`deadline {description}/by {any time}`
+`event {description} /at {any time}` -Example of usage: +#### Shortcuts: -`keyword (optional arguments)` +`t {description}`
+`d {description} /by {any time}`
+`e {description} /at {any time}` -Expected outcome: +### Remove Task -Description of the outcome. +Tasks can be removed using **delete** command, or with its shortcut **del**. -``` -expected output -``` +#### Command format: + +`delete {task_number}` + +#### Shortcuts: + +`del {task_number}` + +### List All Tasks + +All tasks can be listed using **list** command, or with its shortcut **ls**. + +#### Command format: + +`list` + +#### Shortcuts: + +`ls` + +### Mark Task as Done + +Tasks can be marked as done using **mark** command, or with its shortcut **m**. + +#### Command format: + +`mark {task_number}` + +#### Shortcuts: + +`m {task_number}` + +### Unmark Task as Done + +Tasks can be marked as done using **unmark** command, or with its shortcut **um**. + +#### Command format: + +`unmark {task_number}` + +#### Shortcuts: + +`um {task_number}` + +### Find Specific Task + +All tasks can be searched and filtered using **find** command, or with its shortcut **f**. + +#### Command format: + +`find {search_key` + +#### Shortcuts: + +`f {search_key}` + +### Termination + +Application can be quited using **quit** command, or with its shortcut **q**. + +#### Command format: + +`quit` + +#### Shortcuts: + +`q` From 57f74766ec04f391dd21d61e51d8bca97e3414b3 Mon Sep 17 00:00:00 2001 From: edemirkirkan Date: Thu, 24 Feb 2022 02:14:22 +0800 Subject: [PATCH 24/26] change README.md --- docs/README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/README.md b/docs/README.md index eda2cf485..5238ba4bf 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,5 +1,7 @@ # JRobo | Personal Todo App +## User Guide + JRobo is a command line application that you can use as your personal task tracker assistant. JRobo consists of various different commands and three type of tasks, which are **todo**, **deadline**, and **event**. @@ -20,7 +22,7 @@ Tasks can be added using **todo**, **deadline**, **event** commands, or with the #### Command format: -`todo{description}`
+`todo {description}`
`deadline {description}/by {any time}`
`event {description} /at {any time}` @@ -54,7 +56,7 @@ All tasks can be listed using **list** command, or with its shortcut **ls**. `ls` -### Mark Task as Done +### Check Task Tasks can be marked as done using **mark** command, or with its shortcut **m**. @@ -66,7 +68,7 @@ Tasks can be marked as done using **mark** command, or with its shortcut **m**. `m {task_number}` -### Unmark Task as Done +### Uncheck Task Tasks can be marked as done using **unmark** command, or with its shortcut **um**. From 80c8dc270892b74dd4e004ef08b3887f3a25322e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ege=20Demirk=C4=B1rkan?= Date: Thu, 24 Feb 2022 02:18:08 +0800 Subject: [PATCH 25/26] Update README.md --- README.md | 134 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 105 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 7ec02f362..5238ba4bf 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,105 @@ -# JRobo project template - -This is a project template for a greenfield Java project. It's named after the Java mascot _Duke_. Given below are -instructions on how to use it. - -## Setting up in Intellij - -Prerequisites: JDK 11, update Intellij to the most recent version. - -1. Open Intellij (if you are not in the welcome screen, click `File` > `Close Project` to close the existing project - first) -1. Open the project into Intellij as follows: - 1. Click `Open`. - 1. Select the project directory, and click `OK`. - 1. If there are any further prompts, accept the defaults. -1. Configure the project to use **JDK 11** (not other versions) as explained - in [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk).
- In the same dialog, set the **Project language level** field to the `SDK default` option. -3. After that, locate the `src/main/java/JRobo.java` file, right-click it, and choose `Run JRobo.main()` (if the code - editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the - below as the output: - ``` - Hello from - ____ _ - | _ \ _ _| | _____ - | | | | | | | |/ / _ \ - | |_| | |_| | < __/ - |____/ \__,_|_|\_\___| - ``` +# JRobo | Personal Todo App + +## User Guide + +JRobo is a command line application that you can use as your personal task tracker assistant. + +JRobo consists of various different commands and three type of tasks, which are **todo**, **deadline**, and **event**. +

+**Todos** are tasks that do not have any specific time or duration. +
+**Deadlines** are tasks that have a specific deadline that can be specified while adding. +
+**Events** are tasks that have a specific time and duration that can be specified while adding. + +Note that, even if the application is terminated, JRobo will keep all tasks for you in his memory. + +## Commands + +### Add Task + +Tasks can be added using **todo**, **deadline**, **event** commands, or with their shortcut notations. + +#### Command format: + +`todo {description}`
+`deadline {description}/by {any time}`
+`event {description} /at {any time}` + +#### Shortcuts: + +`t {description}`
+`d {description} /by {any time}`
+`e {description} /at {any time}` + +### Remove Task + +Tasks can be removed using **delete** command, or with its shortcut **del**. + +#### Command format: + +`delete {task_number}` + +#### Shortcuts: + +`del {task_number}` + +### List All Tasks + +All tasks can be listed using **list** command, or with its shortcut **ls**. + +#### Command format: + +`list` + +#### Shortcuts: + +`ls` + +### Check Task + +Tasks can be marked as done using **mark** command, or with its shortcut **m**. + +#### Command format: + +`mark {task_number}` + +#### Shortcuts: + +`m {task_number}` + +### Uncheck Task + +Tasks can be marked as done using **unmark** command, or with its shortcut **um**. + +#### Command format: + +`unmark {task_number}` + +#### Shortcuts: + +`um {task_number}` + +### Find Specific Task + +All tasks can be searched and filtered using **find** command, or with its shortcut **f**. + +#### Command format: + +`find {search_key` + +#### Shortcuts: + +`f {search_key}` + +### Termination + +Application can be quited using **quit** command, or with its shortcut **q**. + +#### Command format: + +`quit` + +#### Shortcuts: + +`q` From a1d5bd76169c22b01572b62005f0d158c77c6896 Mon Sep 17 00:00:00 2001 From: edemirkirkan Date: Thu, 24 Feb 2022 02:58:04 +0800 Subject: [PATCH 26/26] Update javadoc --- src/main/java/jrobo/task/TaskManager.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/jrobo/task/TaskManager.java b/src/main/java/jrobo/task/TaskManager.java index edc865f70..6cbddc4e4 100644 --- a/src/main/java/jrobo/task/TaskManager.java +++ b/src/main/java/jrobo/task/TaskManager.java @@ -153,6 +153,11 @@ public void giveError() { printWithSeparator("Invalid command!"); } + /** + * Getter for the tasks field. + * + * @return ArrayList + */ public ArrayList getTaskList() { return tasks; }