From 95705903d0c835d4d00d500b470a800266c6f46b Mon Sep 17 00:00:00 2001 From: jiajuinphoon Date: Tue, 28 Jan 2020 13:57:10 +0800 Subject: [PATCH 01/14] Small change for lvl 0 --- src/main/java/Duke.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5d313334cc..97bb43f583 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,10 +1,18 @@ public class Duke { public static void main(String[] args) { + System.out.println("Hello ! I'm Duke\n"); + System.out.println("What can I do for you ? \n"); + System.out.println("--------------------------\n"); + String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" + "| | | | | | | |/ / _ \\\n" + "| |_| | |_| | < __/\n" + "|____/ \\__,_|_|\\_\\___|\n"; System.out.println("Hello from\n" + logo); + + System.out.println("--------------------------\n"); + System.out.println("Bye. Hope to see you again soon!\n"); + } } From 694acbb5446114b12dc535f1965eccd443389e03 Mon Sep 17 00:00:00 2001 From: jiajuinphoon Date: Wed, 29 Jan 2020 22:59:33 +0800 Subject: [PATCH 02/14] Level 1 completed --- src/main/java/Duke.java | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 97bb43f583..69df92ad8e 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,18 +1,45 @@ +import java.util.Scanner; + public class Duke { + + //level 1 greet, echo, bye (function) + public static void echoCommand(String line) + { + String comparator = "bye"; + System.out.println("--------------------------"); + + if(line.equals(comparator)) + { + System.out.println("Bye. Hope to see you again soon!"); + System.out.println("---------------------------"); + } + else + { + System.out.println(line); + System.out.println("---------------------------"); + String command; + Scanner in = new Scanner(System.in); + command = in.nextLine(); + echoCommand(command); + } + } public static void main(String[] args) { System.out.println("Hello ! I'm Duke\n"); System.out.println("What can I do for you ? \n"); - System.out.println("--------------------------\n"); - String logo = " ____ _ \n" + //level 1 - greet, echo, exit + String line; + Scanner in = new Scanner(System.in); + line = in.nextLine(); + echoCommand(line); + + /*String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" + "| | | | | | | |/ / _ \\\n" + "| |_| | |_| | < __/\n" + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); + System.out.println("Hello from\n" + logo);*/ - System.out.println("--------------------------\n"); - System.out.println("Bye. Hope to see you again soon!\n"); } } From 0ea94bafa9be0e7aac8d675ad0445d0124ae7e18 Mon Sep 17 00:00:00 2001 From: jiajuinphoon Date: Thu, 30 Jan 2020 14:07:16 +0800 Subject: [PATCH 03/14] Level 2 completed --- src/main/java/Duke.java | 69 +++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 27 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 69df92ad8e..d4b9cc1dda 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,37 +1,53 @@ +import java.util.Arrays; import java.util.Scanner; public class Duke { - //level 1 greet, echo, bye (function) - public static void echoCommand(String line) - { - String comparator = "bye"; - System.out.println("--------------------------"); - - if(line.equals(comparator)) - { - System.out.println("Bye. Hope to see you again soon!"); - System.out.println("---------------------------"); - } - else - { - System.out.println(line); - System.out.println("---------------------------"); - String command; - Scanner in = new Scanner(System.in); - command = in.nextLine(); - echoCommand(command); - } - } public static void main(String[] args) { System.out.println("Hello ! I'm Duke\n"); System.out.println("What can I do for you ? \n"); - //level 1 - greet, echo, exit - String line; - Scanner in = new Scanner(System.in); - line = in.nextLine(); - echoCommand(line); + String command; + int i = 0; + String[] list = new String[100]; + Scanner in = new Scanner (System.in); + command = in.nextLine(); + String option_1 = "bye"; + String option_2 = "list"; + + while (true) + { + if (command.equals(option_1)) + { + System.out.println("------------------------"); + System.out.println("Bye, see you again soon!"); + System.out.println("------------------------"); + System.exit(0); + } + else if (command.equals(option_2)) + { + System.out.println("------------------------"); + + for (int j = 0; j < i; j++) + { + System.out.print(j+1); + System.out.print(". "); + System.out.println(list[j]); + } + + System.out.println("------------------------"); + command = in.nextLine(); + } + else + { + list[i] = command; + System.out.println("------------------------"); + System.out.println("Added: " + command); + System.out.println("------------------------"); + i++; + command = in.nextLine(); + } + } /*String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" @@ -40,6 +56,5 @@ public static void main(String[] args) { + "|____/ \\__,_|_|\\_\\___|\n"; System.out.println("Hello from\n" + logo);*/ - } } From f5475ad6485706d92f1e254737f21b6238a67a9e Mon Sep 17 00:00:00 2001 From: jiajuinphoon Date: Fri, 31 Jan 2020 13:41:22 +0800 Subject: [PATCH 04/14] Level 3 completed --- src/main/java/Duke.java | 73 +++++++++++++++++++++++++++++++---------- src/main/java/Task.java | 29 ++++++++++++++++ 2 files changed, 85 insertions(+), 17 deletions(-) create mode 100644 src/main/java/Task.java diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index d4b9cc1dda..9a3fd04fc3 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,22 +1,41 @@ -import java.util.Arrays; +import java.util.ArrayList; import java.util.Scanner; public class Duke { + public static Task getTheTask(ArrayList List, int j) + { + return List.get(j); + } + + public static void addTask(String description, ArrayList List) + { + Task t = new Task(description); + List.add(t); + } + + public static void updateCommand(Task task, ArrayList List, int count) + { + List.set(count,task); + } + public static void main(String[] args) { System.out.println("Hello ! I'm Duke\n"); System.out.println("What can I do for you ? \n"); String command; - int i = 0; - String[] list = new String[100]; + ArrayList list = new ArrayList<>(); Scanner in = new Scanner (System.in); - command = in.nextLine(); String option_1 = "bye"; String option_2 = "list"; + String option_3 = "done"; while (true) { + // cannot use in.nextLine() since it will treat (done (taskNumber)) as one string + // thus will not lead us to the done statement + command = in.next(); + if (command.equals(option_1)) { System.out.println("------------------------"); @@ -27,25 +46,45 @@ public static void main(String[] args) { else if (command.equals(option_2)) { System.out.println("------------------------"); - - for (int j = 0; j < i; j++) + int count = 1; + System.out.println(" Here are the tasks in your list: "); + for (Task t : list) { - System.out.print(j+1); - System.out.print(". "); - System.out.println(list[j]); + System.out.print(count); + System.out.print(".["); + System.out.print(t.getStatusIcon()); + System.out.print("]"); + System.out.println(t.description); + count++; } - System.out.println("------------------------"); - command = in.nextLine(); + } + else if (command.equals(option_3)) + { + int taskNumber = in.nextInt(); + Task t = getTheTask(list,taskNumber-1); + t.markAsDone(); + updateCommand(t,list,taskNumber-1); + System.out.println("------------------------------------------"); + System.out.print("Nice! I've marked this task as done: ["); + System.out.print(t.getStatusIcon()); + System.out.print("]"); + System.out.println(t.description); + System.out.println("------------------------------------------"); } else { - list[i] = command; - System.out.println("------------------------"); - System.out.println("Added: " + command); - System.out.println("------------------------"); - i++; - command = in.nextLine(); + // if there is no "done", "bye", "list" in the string + String splitter = in.nextLine(); + // concat() method returns a String with the value of the String passed into the method, + // appended to the end of the String, used to invoke this method. + command = command.concat(splitter); + addTask(command,list); + Task newAddCommand = getTheTask(list, list.size()-1); + System.out.println("-------------------------------------"); + System.out.print("Successfully added: "); + System.out.println(newAddCommand.description); + System.out.println("--------------------------------------"); } } diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 0000000000..c9f28d66e4 --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,29 @@ +public class Task { + protected String description; + protected boolean isDone; + + public Task(String description) { + this.description = description; + this.isDone = false; + } + + public String getDescription() { + return description; + } + + public boolean isDone() { + return isDone; + } + + public void setDescription(String description) { + this.description = description; + } + + public void markAsDone() { + isDone = true; + } + + public String getStatusIcon() { + return (isDone ? "\u2713" : "\u2718"); //return tick or X symbols + } +} \ No newline at end of file From b3c6870494eea9af2c7c55bfc23fc9b929ff75a4 Mon Sep 17 00:00:00 2001 From: jiajuinphoon Date: Mon, 10 Feb 2020 23:15:07 +0800 Subject: [PATCH 05/14] level 4 completed --- src/main/java/Command.java | 25 +++++++++ src/main/java/Deadlines.java | 23 ++++++++ src/main/java/Duke.java | 106 +++++++++++++++++++++-------------- src/main/java/Events.java | 22 ++++++++ src/main/java/Task.java | 15 +++++ src/main/java/ToDos.java | 12 ++++ 6 files changed, 160 insertions(+), 43 deletions(-) create mode 100644 src/main/java/Command.java create mode 100644 src/main/java/Deadlines.java create mode 100644 src/main/java/Events.java create mode 100644 src/main/java/ToDos.java diff --git a/src/main/java/Command.java b/src/main/java/Command.java new file mode 100644 index 0000000000..51afb3b8a4 --- /dev/null +++ b/src/main/java/Command.java @@ -0,0 +1,25 @@ +public class Command { + private String nameOfCommand; + private String Argument; + + public Command(String Command, String Args) { + this.nameOfCommand = Command; + this.Argument = Args; + } + + public String getCommandName() { + return nameOfCommand; + } + + public void setCommandName(String commandName) { + nameOfCommand = commandName; + } + + public String getArgs() { + return Argument; + } + + public void setArgs(String args) { + Argument = args; + } +} \ No newline at end of file diff --git a/src/main/java/Deadlines.java b/src/main/java/Deadlines.java new file mode 100644 index 0000000000..08444f36ac --- /dev/null +++ b/src/main/java/Deadlines.java @@ -0,0 +1,23 @@ +public class Deadlines extends Task { + protected String dueDate; + + public Deadlines(String description, String dueDate) { + super(description); + super.setTaskType("D"); + this.dueDate = dueDate; + + } + + public String getDueDate() { + return dueDate; + } + + public void setDueDate(String dueDate) { + this.dueDate = dueDate; + } + + @Override + public String toString() { + return "[" + super.getTaskType() + "]" + super.toString() + "(by: " + getDueDate() + ")"; + } +} \ No newline at end of file diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 9a3fd04fc3..36dcdd2839 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -3,16 +3,24 @@ public class Duke { + private static Command splitCommand(String line) { + String word; + String argument; + try { + word = line.substring(0, line.indexOf(' ')); + argument = line.substring(line.indexOf(' ') + 1); + } catch (IndexOutOfBoundsException e) { + word = line; + argument = " "; + } + return new Command(word, argument); + } + public static Task getTheTask(ArrayList List, int j) { return List.get(j); } - public static void addTask(String description, ArrayList List) - { - Task t = new Task(description); - List.add(t); - } public static void updateCommand(Task task, ArrayList List, int count) { @@ -24,44 +32,40 @@ public static void main(String[] args) { System.out.println("What can I do for you ? \n"); String command; + String description; ArrayList list = new ArrayList<>(); Scanner in = new Scanner (System.in); String option_1 = "bye"; String option_2 = "list"; String option_3 = "done"; + String option_4 = "todo"; + String option_5 = "event"; + String option_6 = "deadline"; while (true) { - // cannot use in.nextLine() since it will treat (done (taskNumber)) as one string - // thus will not lead us to the done statement - command = in.next(); + command = in.nextLine(); + final Command option = splitCommand(command); + String choice = option.getCommandName(); - if (command.equals(option_1)) - { + if (choice.equals(option_1)) { System.out.println("------------------------"); System.out.println("Bye, see you again soon!"); System.out.println("------------------------"); System.exit(0); - } - else if (command.equals(option_2)) - { + } else if (choice.equals(option_2)) { System.out.println("------------------------"); int count = 1; System.out.println(" Here are the tasks in your list: "); - for (Task t : list) - { + for (Task t : list) { System.out.print(count); - System.out.print(".["); - System.out.print(t.getStatusIcon()); - System.out.print("]"); - System.out.println(t.description); + System.out.print("."); + System.out.println(t.toString()); count++; } System.out.println("------------------------"); - } - else if (command.equals(option_3)) - { - int taskNumber = in.nextInt(); + } else if (choice.equals(option_3)) { + int taskNumber = Integer.parseInt(String.valueOf(option.getArgs())); Task t = getTheTask(list,taskNumber-1); t.markAsDone(); updateCommand(t,list,taskNumber-1); @@ -71,29 +75,45 @@ else if (command.equals(option_3)) System.out.print("]"); System.out.println(t.description); System.out.println("------------------------------------------"); - } - else - { + } else if (choice.equals(option_4)) { + Task newTask = new ToDos(option.getArgs()); + list.add(newTask); + System.out.println("------------------------"); + System.out.println("Added : "); + System.out.println(newTask.toString()); + System.out.printf("You have %d tasks in your list ^^ \n" , list.size()); + System.out.println("------------------------"); + } else if (choice.equals(option_5)) { + final int indexOfAtPrefix = option.getArgs().indexOf("/at"); + description = option.getArgs().substring(0, indexOfAtPrefix); + String Time = option.getArgs().substring(indexOfAtPrefix + 3).trim(); + Task newEvent = new Events(description, Time); + list.add(newEvent); + System.out.println("------------------------"); + System.out.println("Added : "); + System.out.println(newEvent.toString()); + System.out.printf("You have %d tasks in your list ^^ \n" , list.size()); + System.out.println("------------------------"); + } else if (choice.equals(option_6)) { + final int indexOfByPrefix = option.getArgs().indexOf("/by"); + description = option.getArgs().substring(0, indexOfByPrefix); + String Date = option.getArgs().substring(indexOfByPrefix + 3).trim(); + Task newDeadline = new Deadlines(description, Date); + list.add(newDeadline); + System.out.println("------------------------"); + System.out.println("Added : "); + System.out.println(newDeadline.toString()); + System.out.printf("You have %d tasks in your list ^^ \n" , list.size()); + System.out.println("------------------------"); + + + } else { // if there is no "done", "bye", "list" in the string - String splitter = in.nextLine(); - // concat() method returns a String with the value of the String passed into the method, - // appended to the end of the String, used to invoke this method. - command = command.concat(splitter); - addTask(command,list); - Task newAddCommand = getTheTask(list, list.size()-1); - System.out.println("-------------------------------------"); - System.out.print("Successfully added: "); - System.out.println(newAddCommand.description); - System.out.println("--------------------------------------"); + System.out.println("-------------------------------------------"); + System.out.println("Try again maybe? Choose the right option :) "); + System.out.println("--------------------------------------------"); } } - /*String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo);*/ - } } diff --git a/src/main/java/Events.java b/src/main/java/Events.java new file mode 100644 index 0000000000..f476ca3d8f --- /dev/null +++ b/src/main/java/Events.java @@ -0,0 +1,22 @@ +public class Events extends Task { + protected String timeOfEvent; + + public Events(String description, String timeOfEvent) { + super(description); + super.setTaskType("E"); + this.timeOfEvent = timeOfEvent; + } + + public String getTimeOfEvent() { + return timeOfEvent; + } + + public void setTimeOfEvent(String timeOfEvent) { + this.timeOfEvent = timeOfEvent; + } + + @Override + public String toString() { + return "[" + super.getTaskType() + "]" + super.toString() + "(at: " + getTimeOfEvent() + ")"; + } +} \ No newline at end of file diff --git a/src/main/java/Task.java b/src/main/java/Task.java index c9f28d66e4..131909b085 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -1,10 +1,12 @@ public class Task { protected String description; protected boolean isDone; + protected String taskType; public Task(String description) { this.description = description; this.isDone = false; + this.taskType = null; } public String getDescription() { @@ -23,7 +25,20 @@ public void markAsDone() { isDone = true; } + public String getTaskType() { + return taskType; + } + + public void setTaskType(String taskType) { + this.taskType = taskType; + } + public String getStatusIcon() { return (isDone ? "\u2713" : "\u2718"); //return tick or X symbols } + + @Override + public String toString() { + return "[" + getStatusIcon() + "]" + description; + } } \ No newline at end of file diff --git a/src/main/java/ToDos.java b/src/main/java/ToDos.java new file mode 100644 index 0000000000..1cb70c274c --- /dev/null +++ b/src/main/java/ToDos.java @@ -0,0 +1,12 @@ +public class ToDos extends Task { + + public ToDos(String description) { + super(description); + super.setTaskType("T"); + } + + @Override + public String toString() { + return "[" + super.getTaskType() + "]" + super.toString(); + } +} \ No newline at end of file From f1ac18634931c1a6c615043d48b15a38dd3f3a8a Mon Sep 17 00:00:00 2001 From: jiajuinphoon Date: Tue, 11 Feb 2020 23:12:42 +0800 Subject: [PATCH 06/14] level-5, can handle the error for todo and other unrelated command --- src/main/java/Duke.java | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 36dcdd2839..ad8674a565 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -77,12 +77,19 @@ public static void main(String[] args) { System.out.println("------------------------------------------"); } else if (choice.equals(option_4)) { Task newTask = new ToDos(option.getArgs()); - list.add(newTask); - System.out.println("------------------------"); - System.out.println("Added : "); - System.out.println(newTask.toString()); - System.out.printf("You have %d tasks in your list ^^ \n" , list.size()); - System.out.println("------------------------"); + if ( option.getArgs() == " ") + { + System.out.println("-------------------------------------------"); + System.out.println("Uh Oh! The description cannot be empty ~"); + System.out.println("-------------------------------------------"); + } else { + list.add(newTask); + System.out.println("------------------------"); + System.out.println("Added : "); + System.out.println(newTask.toString()); + System.out.printf("You have %d tasks in your list ^^ \n" , list.size()); + } + } else if (choice.equals(option_5)) { final int indexOfAtPrefix = option.getArgs().indexOf("/at"); description = option.getArgs().substring(0, indexOfAtPrefix); @@ -94,6 +101,7 @@ public static void main(String[] args) { System.out.println(newEvent.toString()); System.out.printf("You have %d tasks in your list ^^ \n" , list.size()); System.out.println("------------------------"); + } else if (choice.equals(option_6)) { final int indexOfByPrefix = option.getArgs().indexOf("/by"); description = option.getArgs().substring(0, indexOfByPrefix); @@ -105,8 +113,6 @@ public static void main(String[] args) { System.out.println(newDeadline.toString()); System.out.printf("You have %d tasks in your list ^^ \n" , list.size()); System.out.println("------------------------"); - - } else { // if there is no "done", "bye", "list" in the string System.out.println("-------------------------------------------"); From 98f8a6d44954cbe2e0b5ebbc8662d4eb0e205f90 Mon Sep 17 00:00:00 2001 From: jiajuinphoon Date: Tue, 18 Feb 2020 13:37:20 +0800 Subject: [PATCH 07/14] level-6 done --- src/main/java/Duke.java | 42 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index ad8674a565..fbcbff1223 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -3,6 +3,12 @@ public class Duke { + private static final String ERROR_DELETE_MESSAGE = "|| OOPS! I can't delete that because" + + " you haven't" + " added task %s yet!"; + private static final String ERROR_MESSAGE = "|| OOPS! The %s of a %s command cannot be empty.\n"; + private static final String ERROR_DELETE_PARAM = "|| Parameters: delete [TASK NUMBER]\n"; + private static final String ERROR_DELETE_EXAMPLE = "|| Example: delete 1"; + private static Command splitCommand(String line) { String word; String argument; @@ -16,6 +22,25 @@ private static Command splitCommand(String line) { return new Command(word, argument); } + private static void executeDeleteCommand(ArrayList taskList, Command command) throws NumberFormatException, IndexOutOfBoundsException { + int index; + if (command.getArgs() == null) { + throw new NumberFormatException(); + } + index = Integer.parseInt(String.valueOf(command.getArgs())); + if (index > taskList.size()) { + throw new IndexOutOfBoundsException(); + } + Task t = taskList.get(index - 1); + taskList.remove(index - 1); + System.out.println("-------------------------------------------"); + System.out.println(" Noted! I've removed this task:"); + System.out.println(t.toString()); + System.out.printf(" Now you have %d tasks in your list.\n", taskList.size()); + System.out.println("-------------------------------------------"); + + } + public static Task getTheTask(ArrayList List, int j) { return List.get(j); @@ -41,7 +66,7 @@ public static void main(String[] args) { String option_4 = "todo"; String option_5 = "event"; String option_6 = "deadline"; - + String option_7 = "delete"; while (true) { command = in.nextLine(); @@ -88,6 +113,8 @@ public static void main(String[] args) { System.out.println("Added : "); System.out.println(newTask.toString()); System.out.printf("You have %d tasks in your list ^^ \n" , list.size()); + System.out.println("------------------------"); + } } else if (choice.equals(option_5)) { @@ -113,6 +140,19 @@ public static void main(String[] args) { System.out.println(newDeadline.toString()); System.out.printf("You have %d tasks in your list ^^ \n" , list.size()); System.out.println("------------------------"); + } else if (choice.equals(option_7)){ + try { + executeDeleteCommand(list, option); + } catch (NumberFormatException e) { + System.out.println("------------------------------------------"); + System.out.println(String.format(ERROR_MESSAGE, "task number", option_7) + + ERROR_DELETE_PARAM + ERROR_DELETE_EXAMPLE); + System.out.println("------------------------------------------"); + } catch (IndexOutOfBoundsException e) { + System.out.println("------------------------------------------"); + System.out.println(String.format(ERROR_DELETE_MESSAGE, option.getArgs())); + System.out.println("------------------------------------------"); + } } else { // if there is no "done", "bye", "list" in the string System.out.println("-------------------------------------------"); From 2889871d295391ae8104e500dcc67d1c85dc7841 Mon Sep 17 00:00:00 2001 From: jiajuinphoon Date: Sat, 22 Feb 2020 17:55:39 +0800 Subject: [PATCH 08/14] level-6-completed --- src/main/java/Duke.java | 2 +- src/main/java/META-INF/MANIFEST.MF | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 src/main/java/META-INF/MANIFEST.MF diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index ad8674a565..57b4022aae 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -97,7 +97,7 @@ public static void main(String[] args) { Task newEvent = new Events(description, Time); list.add(newEvent); System.out.println("------------------------"); - System.out.println("Added : "); + System.out.println("Added: "); System.out.println(newEvent.toString()); System.out.printf("You have %d tasks in your list ^^ \n" , list.size()); System.out.println("------------------------"); diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..9f37e4e0aa --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: Duke + From 75452fab1191e84803367096246cc4363e42cfa2 Mon Sep 17 00:00:00 2001 From: jiajuinphoon Date: Mon, 24 Feb 2020 16:14:01 +0800 Subject: [PATCH 09/14] small change for level-6 --- src/main/java/Duke.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 08c67bddc1..2f3db2c94d 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -3,11 +3,11 @@ public class Duke { - private static final String ERROR_DELETE_MESSAGE = "|| OOPS! I can't delete that because" + private static final String ERROR_DELETE_MESSAGE = "I can't delete that because" + " you haven't" + " added task %s yet!"; - private static final String ERROR_MESSAGE = "|| OOPS! The %s of a %s command cannot be empty.\n"; - private static final String ERROR_DELETE_PARAM = "|| Parameters: delete [TASK NUMBER]\n"; - private static final String ERROR_DELETE_EXAMPLE = "|| Example: delete 1"; + private static final String ERROR_MESSAGE = "The %s of a %s command cannot be empty.\n"; + private static final String ERROR_DELETE_PARAM = "Parameters: delete [TASK NUMBER]\n"; + private static final String ERROR_DELETE_EXAMPLE = "Example: delete 1"; private static Command splitCommand(String line) { String word; From 158f4574eec22c81b9d294fa90e0d3e1920ba576 Mon Sep 17 00:00:00 2001 From: jiajuinphoon Date: Tue, 25 Feb 2020 18:57:25 +0800 Subject: [PATCH 10/14] level-7-completed. Able to save data into file. --- data/duke.txt | 2 + src/main/java/Duke.java | 196 ++++++++++++++++-- src/main/java/{ => duke/command}/Command.java | 2 + .../java/duke/exception/DukeException.java | 8 + src/main/java/{ => duke/task}/Deadlines.java | 2 + src/main/java/{ => duke/task}/Events.java | 4 + src/main/java/{ => duke/task}/Task.java | 4 +- src/main/java/{ => duke/task}/ToDos.java | 4 + 8 files changed, 203 insertions(+), 19 deletions(-) create mode 100644 data/duke.txt rename src/main/java/{ => duke/command}/Command.java (95%) create mode 100644 src/main/java/duke/exception/DukeException.java rename src/main/java/{ => duke/task}/Deadlines.java (96%) rename src/main/java/{ => duke/task}/Events.java (92%) rename src/main/java/{ => duke/task}/Task.java (94%) rename src/main/java/{ => duke/task}/ToDos.java (85%) diff --git a/data/duke.txt b/data/duke.txt new file mode 100644 index 0000000000..be072a3ff5 --- /dev/null +++ b/data/duke.txt @@ -0,0 +1,2 @@ +T | 1 | borrow book +E | 0 | project meeting|Mon 2-4pm diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 2f3db2c94d..cf32fc4930 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,12 +1,31 @@ +import duke.command.Command; +import duke.task.Deadlines; +import duke.task.Events; +import duke.task.Task; +import duke.task.ToDos; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import duke.exception.DukeException; +import java.util.List; import java.util.ArrayList; import java.util.Scanner; public class Duke { + private static final Path FILENAME = Paths.get(System.getProperty("user.dir"), "data", "duke.txt"); + private static String fileDoneStatus; private static final String ERROR_DELETE_MESSAGE = "I can't delete that because" - + " you haven't" + " added task %s yet!"; - private static final String ERROR_MESSAGE = "The %s of a %s command cannot be empty.\n"; - private static final String ERROR_DELETE_PARAM = "Parameters: delete [TASK NUMBER]\n"; + + " you haven't" + " added task %s yet"; + private static final String ERROR_MESSAGE = "The %s of a %s command should not be empty.\n"; + private static final String ERROR_DELETE_PARAM = "What to do: delete [TASK NUMBER]\n"; private static final String ERROR_DELETE_EXAMPLE = "Example: delete 1"; private static Command splitCommand(String line) { @@ -22,7 +41,22 @@ private static Command splitCommand(String line) { return new Command(word, argument); } - private static void executeDeleteCommand(ArrayList taskList, Command command) throws NumberFormatException, IndexOutOfBoundsException { + private static void printTasks(ArrayList List) throws DukeException { + int count = 1; + if (List.size() == 0) { + throw new DukeException(); + } else { + System.out.println("Here you go. These are tasks that you have saved ~ :"); + for (Task t : List) { + System.out.print(count); + System.out.print(". "); + System.out.println(t.toString()); + count++; + } + } + } + + private static void deleteTaskCommand(ArrayList taskList, Command command) throws NumberFormatException, IndexOutOfBoundsException { int index; if (command.getArgs() == null) { throw new NumberFormatException(); @@ -33,6 +67,7 @@ private static void executeDeleteCommand(ArrayList taskList, Command comma } Task t = taskList.get(index - 1); taskList.remove(index - 1); + deleteOnFile(index); System.out.println("-------------------------------------------"); System.out.println(" Noted! I've removed this task:"); System.out.println(t.toString()); @@ -52,14 +87,135 @@ public static void updateCommand(Task task, ArrayList List, int count) List.set(count,task); } + private static void readExistFile(ArrayList List) throws IOException { + FileReader fr = new FileReader(String.valueOf(FILENAME)); // file from data/duke.txt + BufferedReader br = new BufferedReader(fr); + String lining; + while ((lining = br.readLine()) != null) { + String[] parse = lining.trim().split("\\s*\\|\\s*"); + if (parse.length == 3) { + ToDos t = new ToDos(parse[2]); + if (parse[1].equals("1")) { + t.markAsDone(); + } + List.add(t); + } else if (parse.length == 4) { + if (parse[0].equals("D")) { + Deadlines d = new Deadlines(parse[2], parse[3]); + if (parse[1].equals("1")) { + d.markAsDone(); + } + List.add(d); + } else { + Events e = new Events(parse[2], parse[3]); + if (parse[1].equals("1")) { + e.markAsDone(); + } + List.add(e); + } + } + + } + br.close(); + fr.close(); + } + + private static void saveTaskList(ArrayList List) { + boolean isExistedFile = Files.exists(FILENAME); + try { + if (isExistedFile) { + FileWriter fw = new FileWriter(String.valueOf(FILENAME)); + Writer output = new BufferedWriter(fw); + for (Task t : List) { + if (t.getStatusIcon().equals("\u2718")) { + fileDoneStatus = "0"; + } else { + fileDoneStatus = "1"; + } + //must use if-else statement + //instanceof does not allow switch statement + if (t instanceof ToDos) { + output.write( + t.getTaskType() + " | " + fileDoneStatus + " | " + t.description + + "\n"); + } else if (t instanceof Events) { + output.write( + t.getTaskType() + " | " + fileDoneStatus + " | " + t.description + + "|" + ((Events) t).getTimeOfEvent() + "\n"); + } else if (t instanceof Deadlines) { + output.write( + t.getTaskType() + " | " + fileDoneStatus + " | " + t.description + + "|" + ((Deadlines) t).getDueDate() + "\n"); + } + } + output.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void updateFile(int line, Task t) { + if (t.getStatusIcon().equals("\u2718")) { + fileDoneStatus = "0"; + } else { + fileDoneStatus = "1"; + } + try { + List lines = new ArrayList<>( + Files.readAllLines(FILENAME, StandardCharsets.UTF_8)); + + if (t instanceof ToDos) { + lines.set(line - 1, + t.getTaskType() + " | " + fileDoneStatus + " | " + t.description + "\n"); + } else if (t instanceof Events) { + lines.set(line - 1, + t.getTaskType() + " | " + fileDoneStatus + " | " + t.description + "| " + + ((Events) t).getTimeOfEvent() + "\n"); + } else if (t instanceof Deadlines) { + lines.set(line - 1, + t.getTaskType() + " | " + fileDoneStatus + " | " + t.description + "| " + + ((Deadlines) t).getDueDate() + "\n"); + Files.write(FILENAME, lines, StandardCharsets.UTF_8); + } + Files.write(FILENAME, lines, StandardCharsets.UTF_8); + } catch (IOException e) { + System.out.println(e.getMessage()); + } + + } + + public static void deleteOnFile(int numberToDelete) { + try { + List lines = new ArrayList<>(Files.readAllLines(FILENAME, StandardCharsets.UTF_8)); + lines.remove(numberToDelete - 1); + Files.write(FILENAME, lines, StandardCharsets.UTF_8); + } catch (IOException e) { + System.out.println(e.getMessage()); + } + } + public static void main(String[] args) { - System.out.println("Hello ! I'm Duke\n"); - System.out.println("What can I do for you ? \n"); + System.out.println("Hello ! I'm Sheena ~ "); + System.out.println("What can I do for you ?"); + String command; String description; ArrayList list = new ArrayList<>(); Scanner in = new Scanner (System.in); + System.out.println("Let me see if you have any previous saved file"); + try { + readExistFile(list); + printTasks(list); + System.out.println("Let's begin to add more tasks!"); + + } catch (IOException | DukeException e) { + System.out.println("--------------------------------------"); + System.out.println("Uhm, we shall create a new one ^^"); + System.out.println("---------------------------------------\n"); + } + String option_1 = "bye"; String option_2 = "list"; String option_3 = "done"; @@ -69,24 +225,26 @@ public static void main(String[] args) { String option_7 = "delete"; while (true) { + command = in.nextLine(); final Command option = splitCommand(command); String choice = option.getCommandName(); if (choice.equals(option_1)) { + System.out.println("Let me save down everything ^^"); + saveTaskList(list); System.out.println("------------------------"); - System.out.println("Bye, see you again soon!"); + System.out.println("Here's a message from Sheena: "); + System.out.println("Bye bye people, see you again soon!"); System.out.println("------------------------"); System.exit(0); } else if (choice.equals(option_2)) { - System.out.println("------------------------"); - int count = 1; - System.out.println(" Here are the tasks in your list: "); - for (Task t : list) { - System.out.print(count); - System.out.print("."); - System.out.println(t.toString()); - count++; + try { + printTasks(list); + } catch (DukeException e) { + System.out.println("------------------------"); + System.out.println("Erm. You don't have any task yet..."); + System.out.println("------------------------"); } System.out.println("------------------------"); } else if (choice.equals(option_3)) { @@ -100,6 +258,7 @@ public static void main(String[] args) { System.out.print("]"); System.out.println(t.description); System.out.println("------------------------------------------"); + updateFile(taskNumber,t); } else if (choice.equals(option_4)) { Task newTask = new ToDos(option.getArgs()); if ( option.getArgs() == " ") @@ -114,9 +273,8 @@ public static void main(String[] args) { System.out.println(newTask.toString()); System.out.printf("You have %d tasks in your list ^^ \n" , list.size()); System.out.println("------------------------"); - + saveTaskList(list); } - } else if (choice.equals(option_5)) { final int indexOfAtPrefix = option.getArgs().indexOf("/at"); description = option.getArgs().substring(0, indexOfAtPrefix); @@ -128,6 +286,7 @@ public static void main(String[] args) { System.out.println(newEvent.toString()); System.out.printf("You have %d tasks in your list ^^ \n" , list.size()); System.out.println("------------------------"); + saveTaskList(list); } else if (choice.equals(option_6)) { final int indexOfByPrefix = option.getArgs().indexOf("/by"); @@ -140,9 +299,10 @@ public static void main(String[] args) { System.out.println(newDeadline.toString()); System.out.printf("You have %d tasks in your list ^^ \n" , list.size()); System.out.println("------------------------"); + saveTaskList(list); } else if (choice.equals(option_7)){ try { - executeDeleteCommand(list, option); + deleteTaskCommand(list, option); } catch (NumberFormatException e) { System.out.println("------------------------------------------"); System.out.println(String.format(ERROR_MESSAGE, "task number", option_7) diff --git a/src/main/java/Command.java b/src/main/java/duke/command/Command.java similarity index 95% rename from src/main/java/Command.java rename to src/main/java/duke/command/Command.java index 51afb3b8a4..ad8e2e3482 100644 --- a/src/main/java/Command.java +++ b/src/main/java/duke/command/Command.java @@ -1,3 +1,5 @@ +package duke.command; + public class Command { private String nameOfCommand; private String Argument; diff --git a/src/main/java/duke/exception/DukeException.java b/src/main/java/duke/exception/DukeException.java new file mode 100644 index 0000000000..021e6fdbd9 --- /dev/null +++ b/src/main/java/duke/exception/DukeException.java @@ -0,0 +1,8 @@ +package duke.exception; + +public class DukeException extends Exception{ +} + +class EmptyListException extends Exception{ + +} diff --git a/src/main/java/Deadlines.java b/src/main/java/duke/task/Deadlines.java similarity index 96% rename from src/main/java/Deadlines.java rename to src/main/java/duke/task/Deadlines.java index 08444f36ac..5a22f3e0e1 100644 --- a/src/main/java/Deadlines.java +++ b/src/main/java/duke/task/Deadlines.java @@ -1,3 +1,5 @@ +package duke.task; + public class Deadlines extends Task { protected String dueDate; diff --git a/src/main/java/Events.java b/src/main/java/duke/task/Events.java similarity index 92% rename from src/main/java/Events.java rename to src/main/java/duke/task/Events.java index f476ca3d8f..d274285bed 100644 --- a/src/main/java/Events.java +++ b/src/main/java/duke/task/Events.java @@ -1,3 +1,7 @@ +package duke.task; + +import duke.task.Task; + public class Events extends Task { protected String timeOfEvent; diff --git a/src/main/java/Task.java b/src/main/java/duke/task/Task.java similarity index 94% rename from src/main/java/Task.java rename to src/main/java/duke/task/Task.java index 131909b085..7d1bfdb547 100644 --- a/src/main/java/Task.java +++ b/src/main/java/duke/task/Task.java @@ -1,5 +1,7 @@ +package duke.task; + public class Task { - protected String description; + public String description; protected boolean isDone; protected String taskType; diff --git a/src/main/java/ToDos.java b/src/main/java/duke/task/ToDos.java similarity index 85% rename from src/main/java/ToDos.java rename to src/main/java/duke/task/ToDos.java index 1cb70c274c..9338cd703e 100644 --- a/src/main/java/ToDos.java +++ b/src/main/java/duke/task/ToDos.java @@ -1,3 +1,7 @@ +package duke.task; + +import duke.task.Task; + public class ToDos extends Task { public ToDos(String description) { From 1409a2a8215e1e03b3eaa3104a9a5cf0ea41f4b1 Mon Sep 17 00:00:00 2001 From: jiajuinphoon Date: Tue, 25 Feb 2020 19:15:12 +0800 Subject: [PATCH 11/14] Small changes for the program. --- src/main/java/Duke.java | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index cf32fc4930..f7438110f6 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -22,9 +22,9 @@ public class Duke { private static final Path FILENAME = Paths.get(System.getProperty("user.dir"), "data", "duke.txt"); private static String fileDoneStatus; - private static final String ERROR_DELETE_MESSAGE = "I can't delete that because" + private static final String ERROR_DELETE_MESSAGE = "Sheena: I can't delete that because" + " you haven't" + " added task %s yet"; - private static final String ERROR_MESSAGE = "The %s of a %s command should not be empty.\n"; + private static final String ERROR_MESSAGE = "Sheena: The %s of a %s command should not be empty.\n"; private static final String ERROR_DELETE_PARAM = "What to do: delete [TASK NUMBER]\n"; private static final String ERROR_DELETE_EXAMPLE = "Example: delete 1"; @@ -46,7 +46,7 @@ private static void printTasks(ArrayList List) throws DukeException { if (List.size() == 0) { throw new DukeException(); } else { - System.out.println("Here you go. These are tasks that you have saved ~ :"); + System.out.println("Sheena: These are tasks that you have saved ~ :"); for (Task t : List) { System.out.print(count); System.out.print(". "); @@ -69,9 +69,9 @@ private static void deleteTaskCommand(ArrayList taskList, Command command) taskList.remove(index - 1); deleteOnFile(index); System.out.println("-------------------------------------------"); - System.out.println(" Noted! I've removed this task:"); + System.out.println("Sheena: Noted! I've removed this task:"); System.out.println(t.toString()); - System.out.printf(" Now you have %d tasks in your list.\n", taskList.size()); + System.out.printf("Sheena: Now you have %d tasks in your list.\n", taskList.size()); System.out.println("-------------------------------------------"); } @@ -204,15 +204,15 @@ public static void main(String[] args) { String description; ArrayList list = new ArrayList<>(); Scanner in = new Scanner (System.in); - System.out.println("Let me see if you have any previous saved file"); + System.out.println("Sheena: Let me see if you have any previous saved file"); try { readExistFile(list); printTasks(list); - System.out.println("Let's begin to add more tasks!"); + System.out.println("Sheena: Let's begin to add more tasks!"); } catch (IOException | DukeException e) { System.out.println("--------------------------------------"); - System.out.println("Uhm, we shall create a new one ^^"); + System.out.println("Sheena: Uhm, we shall create a new one ^^"); System.out.println("---------------------------------------\n"); } @@ -231,11 +231,10 @@ public static void main(String[] args) { String choice = option.getCommandName(); if (choice.equals(option_1)) { - System.out.println("Let me save down everything ^^"); + System.out.println("Sheena: Let me save down everything ^^"); saveTaskList(list); System.out.println("------------------------"); - System.out.println("Here's a message from Sheena: "); - System.out.println("Bye bye people, see you again soon!"); + System.out.println("Sheena: Bye bye people, see you again soon!"); System.out.println("------------------------"); System.exit(0); } else if (choice.equals(option_2)) { @@ -243,7 +242,7 @@ public static void main(String[] args) { printTasks(list); } catch (DukeException e) { System.out.println("------------------------"); - System.out.println("Erm. You don't have any task yet..."); + System.out.println("Sheena: Erm. You don't have any task yet..."); System.out.println("------------------------"); } System.out.println("------------------------"); @@ -253,7 +252,7 @@ public static void main(String[] args) { t.markAsDone(); updateCommand(t,list,taskNumber-1); System.out.println("------------------------------------------"); - System.out.print("Nice! I've marked this task as done: ["); + System.out.print("Sheena: Nice! I've marked this task as done: ["); System.out.print(t.getStatusIcon()); System.out.print("]"); System.out.println(t.description); @@ -264,14 +263,14 @@ public static void main(String[] args) { if ( option.getArgs() == " ") { System.out.println("-------------------------------------------"); - System.out.println("Uh Oh! The description cannot be empty ~"); + System.out.println("Sheena: Uh Oh! The description cannot be empty ~"); System.out.println("-------------------------------------------"); } else { list.add(newTask); System.out.println("------------------------"); System.out.println("Added : "); System.out.println(newTask.toString()); - System.out.printf("You have %d tasks in your list ^^ \n" , list.size()); + System.out.printf("Sheena: You have %d tasks in your list ^^ \n" , list.size()); System.out.println("------------------------"); saveTaskList(list); } @@ -284,7 +283,7 @@ public static void main(String[] args) { System.out.println("------------------------"); System.out.println("Added: "); System.out.println(newEvent.toString()); - System.out.printf("You have %d tasks in your list ^^ \n" , list.size()); + System.out.printf("Sheena: You have %d tasks in your list ^^ \n" , list.size()); System.out.println("------------------------"); saveTaskList(list); @@ -297,7 +296,7 @@ public static void main(String[] args) { System.out.println("------------------------"); System.out.println("Added : "); System.out.println(newDeadline.toString()); - System.out.printf("You have %d tasks in your list ^^ \n" , list.size()); + System.out.printf("Sheena: You have %d tasks in your list ^^ \n" , list.size()); System.out.println("------------------------"); saveTaskList(list); } else if (choice.equals(option_7)){ @@ -316,7 +315,7 @@ public static void main(String[] args) { } else { // if there is no "done", "bye", "list" in the string System.out.println("-------------------------------------------"); - System.out.println("Try again maybe? Choose the right option :) "); + System.out.println("Sheena: Try again maybe? Choose the right option :) "); System.out.println("--------------------------------------------"); } } From ec880be98a990b8046c94fb8426d973205b3dd14 Mon Sep 17 00:00:00 2001 From: jiajuinphoon Date: Mon, 2 Mar 2020 00:01:07 +0800 Subject: [PATCH 12/14] Done for A-MoreOOP, Level-9 and added some basic JavaDoc, several files for different command for easier aceess. --- duke.txt | 4 + src/main/java/Duke.java | 356 +++--------------- src/main/java/duke/Ui/TextUi.java | 71 ++++ src/main/java/duke/command/Command.java | 21 +- src/main/java/duke/command/CommandBye.java | 15 + src/main/java/duke/command/CommandClear.java | 17 + .../java/duke/command/CommandDeadline.java | 34 ++ src/main/java/duke/command/CommandDelete.java | 30 ++ src/main/java/duke/command/CommandDone.java | 30 ++ src/main/java/duke/command/CommandEvent.java | 36 ++ src/main/java/duke/command/CommandFind.java | 31 ++ src/main/java/duke/command/CommandList.java | 23 ++ src/main/java/duke/command/CommandOption.java | 11 + src/main/java/duke/command/CommandToDo.java | 36 ++ src/main/java/duke/command/FalseCommand.java | 15 + .../java/duke/exception/DukeException.java | 8 - .../DuplicateInformationException.java | 8 + .../exception/IncorrectValueException.java | 8 + .../duke/exception/TaskNotFoundException.java | 4 + src/main/java/duke/parser/Parser.java | 101 +++++ src/main/java/duke/storage/ReadTaskList.java | 44 +++ src/main/java/duke/storage/SaveTaskList.java | 44 +++ src/main/java/duke/storage/Storage.java | 85 +++++ src/main/java/duke/task/Deadlines.java | 6 + src/main/java/duke/task/Events.java | 6 + src/main/java/duke/task/Task.java | 9 +- src/main/java/duke/task/ToDos.java | 5 + src/main/java/duke/taskList/TaskList.java | 189 ++++++++++ 28 files changed, 933 insertions(+), 314 deletions(-) create mode 100644 duke.txt create mode 100644 src/main/java/duke/Ui/TextUi.java create mode 100644 src/main/java/duke/command/CommandBye.java create mode 100644 src/main/java/duke/command/CommandClear.java create mode 100644 src/main/java/duke/command/CommandDeadline.java create mode 100644 src/main/java/duke/command/CommandDelete.java create mode 100644 src/main/java/duke/command/CommandDone.java create mode 100644 src/main/java/duke/command/CommandEvent.java create mode 100644 src/main/java/duke/command/CommandFind.java create mode 100644 src/main/java/duke/command/CommandList.java create mode 100644 src/main/java/duke/command/CommandOption.java create mode 100644 src/main/java/duke/command/CommandToDo.java create mode 100644 src/main/java/duke/command/FalseCommand.java delete mode 100644 src/main/java/duke/exception/DukeException.java create mode 100644 src/main/java/duke/exception/DuplicateInformationException.java create mode 100644 src/main/java/duke/exception/IncorrectValueException.java create mode 100644 src/main/java/duke/exception/TaskNotFoundException.java create mode 100644 src/main/java/duke/parser/Parser.java create mode 100644 src/main/java/duke/storage/ReadTaskList.java create mode 100644 src/main/java/duke/storage/SaveTaskList.java create mode 100644 src/main/java/duke/storage/Storage.java create mode 100644 src/main/java/duke/taskList/TaskList.java diff --git a/duke.txt b/duke.txt new file mode 100644 index 0000000000..e3a6446603 --- /dev/null +++ b/duke.txt @@ -0,0 +1,4 @@ +T | 1 | buy food +T | 1 | miss Sheena +T | 0 | love Sheena forever +T | 0 | I love you Coco diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index f7438110f6..65c858e702 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,324 +1,78 @@ import duke.command.Command; -import duke.task.Deadlines; -import duke.task.Events; -import duke.task.Task; -import duke.task.ToDos; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.Writer; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import duke.exception.DukeException; -import java.util.List; -import java.util.ArrayList; -import java.util.Scanner; - +import duke.command.CommandOption; +import duke.command.CommandBye; +import duke.taskList.TaskList; +import duke.parser.Parser; +import duke.storage.Storage; +import duke.storage.Storage.StorageFilePathException; +import duke.Ui.TextUi; + +/** + * The main program should keep it short + * Exits when command "bye" stated + * + */ public class Duke { - private static final Path FILENAME = Paths.get(System.getProperty("user.dir"), "data", "duke.txt"); - private static String fileDoneStatus; - private static final String ERROR_DELETE_MESSAGE = "Sheena: I can't delete that because" - + " you haven't" + " added task %s yet"; - private static final String ERROR_MESSAGE = "Sheena: The %s of a %s command should not be empty.\n"; - private static final String ERROR_DELETE_PARAM = "What to do: delete [TASK NUMBER]\n"; - private static final String ERROR_DELETE_EXAMPLE = "Example: delete 1"; + private TextUi ui; + public Storage storage; + private TaskList list; - private static Command splitCommand(String line) { - String word; - String argument; - try { - word = line.substring(0, line.indexOf(' ')); - argument = line.substring(line.indexOf(' ') + 1); - } catch (IndexOutOfBoundsException e) { - word = line; - argument = " "; - } - return new Command(word, argument); + public static void main(String... launchArgs) { + new Duke().runTheProgram(launchArgs); } - private static void printTasks(ArrayList List) throws DukeException { - int count = 1; - if (List.size() == 0) { - throw new DukeException(); - } else { - System.out.println("Sheena: These are tasks that you have saved ~ :"); - for (Task t : List) { - System.out.print(count); - System.out.print(". "); - System.out.println(t.toString()); - count++; - } - } + public void runTheProgram(String[] launchArgs) { + start(launchArgs); + runCommand(); + exit(); } - private static void deleteTaskCommand(ArrayList taskList, Command command) throws NumberFormatException, IndexOutOfBoundsException { - int index; - if (command.getArgs() == null) { - throw new NumberFormatException(); - } - index = Integer.parseInt(String.valueOf(command.getArgs())); - if (index > taskList.size()) { - throw new IndexOutOfBoundsException(); + private void start(String[] launchArgs) { + try { + this.ui = new TextUi(); + this.storage = initializeStorage(launchArgs); + this.list = storage.load(); + ui.welcomeMessage(storage.getPath()); + ui.storedList(); + } catch (Storage.StorageOperationException | StorageFilePathException e) { + ui.failed(); + throw new RuntimeException(e); } - Task t = taskList.get(index - 1); - taskList.remove(index - 1); - deleteOnFile(index); - System.out.println("-------------------------------------------"); - System.out.println("Sheena: Noted! I've removed this task:"); - System.out.println(t.toString()); - System.out.printf("Sheena: Now you have %d tasks in your list.\n", taskList.size()); - System.out.println("-------------------------------------------"); - } - public static Task getTheTask(ArrayList List, int j) - { - return List.get(j); + private void exit(){ + ui.goodbye(); + System.exit(0); } - - public static void updateCommand(Task task, ArrayList List, int count) - { - List.set(count,task); + /** run the program until the user type "bye" */ + private void runCommand(){ + Command command; + do { + String userCommand = ui.getUserCommand(); + command = new Parser().parseCommand(userCommand); + CommandOption result = executeCommand(command); + ui.printResult(result); + } while (!CommandBye.isExit(command)); } - private static void readExistFile(ArrayList List) throws IOException { - FileReader fr = new FileReader(String.valueOf(FILENAME)); // file from data/duke.txt - BufferedReader br = new BufferedReader(fr); - String lining; - while ((lining = br.readLine()) != null) { - String[] parse = lining.trim().split("\\s*\\|\\s*"); - if (parse.length == 3) { - ToDos t = new ToDos(parse[2]); - if (parse[1].equals("1")) { - t.markAsDone(); - } - List.add(t); - } else if (parse.length == 4) { - if (parse[0].equals("D")) { - Deadlines d = new Deadlines(parse[2], parse[3]); - if (parse[1].equals("1")) { - d.markAsDone(); - } - List.add(d); - } else { - Events e = new Events(parse[2], parse[3]); - if (parse[1].equals("1")) { - e.markAsDone(); - } - List.add(e); - } + private CommandOption executeCommand(Command command) { + try { + command.setData(list); + storage.save(list); + return command.execute(); + } catch (Exception e) { + ui.PresentMessages(e.getMessage()); + throw new RuntimeException(e); } - } - br.close(); - fr.close(); } - private static void saveTaskList(ArrayList List) { - boolean isExistedFile = Files.exists(FILENAME); - try { - if (isExistedFile) { - FileWriter fw = new FileWriter(String.valueOf(FILENAME)); - Writer output = new BufferedWriter(fw); - for (Task t : List) { - if (t.getStatusIcon().equals("\u2718")) { - fileDoneStatus = "0"; - } else { - fileDoneStatus = "1"; - } - //must use if-else statement - //instanceof does not allow switch statement - if (t instanceof ToDos) { - output.write( - t.getTaskType() + " | " + fileDoneStatus + " | " + t.description - + "\n"); - } else if (t instanceof Events) { - output.write( - t.getTaskType() + " | " + fileDoneStatus + " | " + t.description - + "|" + ((Events) t).getTimeOfEvent() + "\n"); - } else if (t instanceof Deadlines) { - output.write( - t.getTaskType() + " | " + fileDoneStatus + " | " + t.description - + "|" + ((Deadlines) t).getDueDate() + "\n"); - } - } - output.close(); - } - } catch (IOException e) { - e.printStackTrace(); - } + private Storage initializeStorage(String[] launchArgs) throws StorageFilePathException { + boolean isStorageFileSpecified = launchArgs.length > 0; + return !isStorageFileSpecified ? new Storage() : new Storage(launchArgs[0]); } - public static void updateFile(int line, Task t) { - if (t.getStatusIcon().equals("\u2718")) { - fileDoneStatus = "0"; - } else { - fileDoneStatus = "1"; - } - try { - List lines = new ArrayList<>( - Files.readAllLines(FILENAME, StandardCharsets.UTF_8)); - if (t instanceof ToDos) { - lines.set(line - 1, - t.getTaskType() + " | " + fileDoneStatus + " | " + t.description + "\n"); - } else if (t instanceof Events) { - lines.set(line - 1, - t.getTaskType() + " | " + fileDoneStatus + " | " + t.description + "| " - + ((Events) t).getTimeOfEvent() + "\n"); - } else if (t instanceof Deadlines) { - lines.set(line - 1, - t.getTaskType() + " | " + fileDoneStatus + " | " + t.description + "| " - + ((Deadlines) t).getDueDate() + "\n"); - Files.write(FILENAME, lines, StandardCharsets.UTF_8); - } - Files.write(FILENAME, lines, StandardCharsets.UTF_8); - } catch (IOException e) { - System.out.println(e.getMessage()); - } - - } - - public static void deleteOnFile(int numberToDelete) { - try { - List lines = new ArrayList<>(Files.readAllLines(FILENAME, StandardCharsets.UTF_8)); - lines.remove(numberToDelete - 1); - Files.write(FILENAME, lines, StandardCharsets.UTF_8); - } catch (IOException e) { - System.out.println(e.getMessage()); - } - } - - public static void main(String[] args) { - System.out.println("Hello ! I'm Sheena ~ "); - System.out.println("What can I do for you ?"); - - - String command; - String description; - ArrayList list = new ArrayList<>(); - Scanner in = new Scanner (System.in); - System.out.println("Sheena: Let me see if you have any previous saved file"); - try { - readExistFile(list); - printTasks(list); - System.out.println("Sheena: Let's begin to add more tasks!"); - - } catch (IOException | DukeException e) { - System.out.println("--------------------------------------"); - System.out.println("Sheena: Uhm, we shall create a new one ^^"); - System.out.println("---------------------------------------\n"); - } - - String option_1 = "bye"; - String option_2 = "list"; - String option_3 = "done"; - String option_4 = "todo"; - String option_5 = "event"; - String option_6 = "deadline"; - String option_7 = "delete"; - while (true) - { - - command = in.nextLine(); - final Command option = splitCommand(command); - String choice = option.getCommandName(); - - if (choice.equals(option_1)) { - System.out.println("Sheena: Let me save down everything ^^"); - saveTaskList(list); - System.out.println("------------------------"); - System.out.println("Sheena: Bye bye people, see you again soon!"); - System.out.println("------------------------"); - System.exit(0); - } else if (choice.equals(option_2)) { - try { - printTasks(list); - } catch (DukeException e) { - System.out.println("------------------------"); - System.out.println("Sheena: Erm. You don't have any task yet..."); - System.out.println("------------------------"); - } - System.out.println("------------------------"); - } else if (choice.equals(option_3)) { - int taskNumber = Integer.parseInt(String.valueOf(option.getArgs())); - Task t = getTheTask(list,taskNumber-1); - t.markAsDone(); - updateCommand(t,list,taskNumber-1); - System.out.println("------------------------------------------"); - System.out.print("Sheena: Nice! I've marked this task as done: ["); - System.out.print(t.getStatusIcon()); - System.out.print("]"); - System.out.println(t.description); - System.out.println("------------------------------------------"); - updateFile(taskNumber,t); - } else if (choice.equals(option_4)) { - Task newTask = new ToDos(option.getArgs()); - if ( option.getArgs() == " ") - { - System.out.println("-------------------------------------------"); - System.out.println("Sheena: Uh Oh! The description cannot be empty ~"); - System.out.println("-------------------------------------------"); - } else { - list.add(newTask); - System.out.println("------------------------"); - System.out.println("Added : "); - System.out.println(newTask.toString()); - System.out.printf("Sheena: You have %d tasks in your list ^^ \n" , list.size()); - System.out.println("------------------------"); - saveTaskList(list); - } - } else if (choice.equals(option_5)) { - final int indexOfAtPrefix = option.getArgs().indexOf("/at"); - description = option.getArgs().substring(0, indexOfAtPrefix); - String Time = option.getArgs().substring(indexOfAtPrefix + 3).trim(); - Task newEvent = new Events(description, Time); - list.add(newEvent); - System.out.println("------------------------"); - System.out.println("Added: "); - System.out.println(newEvent.toString()); - System.out.printf("Sheena: You have %d tasks in your list ^^ \n" , list.size()); - System.out.println("------------------------"); - saveTaskList(list); - - } else if (choice.equals(option_6)) { - final int indexOfByPrefix = option.getArgs().indexOf("/by"); - description = option.getArgs().substring(0, indexOfByPrefix); - String Date = option.getArgs().substring(indexOfByPrefix + 3).trim(); - Task newDeadline = new Deadlines(description, Date); - list.add(newDeadline); - System.out.println("------------------------"); - System.out.println("Added : "); - System.out.println(newDeadline.toString()); - System.out.printf("Sheena: You have %d tasks in your list ^^ \n" , list.size()); - System.out.println("------------------------"); - saveTaskList(list); - } else if (choice.equals(option_7)){ - try { - deleteTaskCommand(list, option); - } catch (NumberFormatException e) { - System.out.println("------------------------------------------"); - System.out.println(String.format(ERROR_MESSAGE, "task number", option_7) - + ERROR_DELETE_PARAM + ERROR_DELETE_EXAMPLE); - System.out.println("------------------------------------------"); - } catch (IndexOutOfBoundsException e) { - System.out.println("------------------------------------------"); - System.out.println(String.format(ERROR_DELETE_MESSAGE, option.getArgs())); - System.out.println("------------------------------------------"); - } - } else { - // if there is no "done", "bye", "list" in the string - System.out.println("-------------------------------------------"); - System.out.println("Sheena: Try again maybe? Choose the right option :) "); - System.out.println("--------------------------------------------"); - } - } - - } } diff --git a/src/main/java/duke/Ui/TextUi.java b/src/main/java/duke/Ui/TextUi.java new file mode 100644 index 0000000000..ff6e24a2d5 --- /dev/null +++ b/src/main/java/duke/Ui/TextUi.java @@ -0,0 +1,71 @@ +package duke.Ui; +import duke.command.CommandOption; +import duke.taskList.TaskList; +import java.io.InputStream; +import java.io.PrintStream; +import java.util.Scanner; + +public class TextUi { + + private final Scanner in; + private final PrintStream out; + + public TextUi() { + this(System.in, System.out); + } + + public TextUi(InputStream in, PrintStream out) { + this.in = new Scanner(in); + this.out = out; + } + + public String getUserCommand() { + out.print("Sheena: Please enter your command ~ \n"); + String Input = in.nextLine(); + PresentMessages("Sheena: Yay! This is your input (" + Input + ") !"); + return Input; + } + + public void welcomeMessage(String storageFile) { + String Info = String.format(USING_STORAGE, storageFile); + PresentMessages(WELCOME, Info); + } + + public void goodbye() { + PresentMessages(GOODBYE); + } + + public void failed() { + PresentMessages(FAILED); + } + + /** + * Shows message(s) to the user + */ + public void PresentMessages(String... message) { + for (String a : message) { + out.println(a); + } + } + + public void printResult(CommandOption result) { + PresentMessages(result.feedback); + } + + + public void storedList() { + if (TaskList.size() <= 0) { + System.out.println("\nSheena: Hmm nothing here.\nSheena: It's okay! Let me create a new one!"); + } else { + System.out.println("---------------------------------------------------------"); + System.out.println("Sheena: Yay! I successfully retreat your previous list!"); + TaskList.storedTaskList(); + System.out.println("---------------------------------------------------------"); + } + } + + public static final String GOODBYE = "Sheena: I will miss you! Hope to see you again soon!"; + public static final String FAILED = "Sheena: Erm can't run now. Gonna Exit first."; + public static final String WELCOME = "Hello! I'm Sheena ^^ \nWhat can I do for you ?"; + public static final String USING_STORAGE = "Sheena: using storage file ( %1$s )"; +} diff --git a/src/main/java/duke/command/Command.java b/src/main/java/duke/command/Command.java index ad8e2e3482..2bdbf32bbe 100644 --- a/src/main/java/duke/command/Command.java +++ b/src/main/java/duke/command/Command.java @@ -1,12 +1,27 @@ package duke.command; +import duke.taskList.TaskList; +import duke.task.Task; +import java.util.ArrayList; + public class Command { private String nameOfCommand; private String Argument; + protected TaskList taskList; + + + public static final String MESSAGE_TASKS_LISTED_OVERVIEW = "Sheena: Yay! %1$d tasks listed!"; + + public static String getMessageForTaskListShownSummary(ArrayList tasksDisplayed) { + return String.format(MESSAGE_TASKS_LISTED_OVERVIEW, tasksDisplayed.size()); + } + + public CommandOption execute() { + throw new UnsupportedOperationException("This method must be implemented by child classes"); + } - public Command(String Command, String Args) { - this.nameOfCommand = Command; - this.Argument = Args; + public void setData(TaskList taskList) { + this.taskList = taskList; } public String getCommandName() { diff --git a/src/main/java/duke/command/CommandBye.java b/src/main/java/duke/command/CommandBye.java new file mode 100644 index 0000000000..fce5bdc075 --- /dev/null +++ b/src/main/java/duke/command/CommandBye.java @@ -0,0 +1,15 @@ +package duke.command; + +public class CommandBye extends Command { + + public static final String EXIT = "Sheena: Let me save down everything ^^\n "; + + @Override + public CommandOption execute() { + return new CommandOption(EXIT); + } + + public static boolean isExit(Command command) { + return command instanceof CommandBye; // instanceof returns false if it is null + } +} diff --git a/src/main/java/duke/command/CommandClear.java b/src/main/java/duke/command/CommandClear.java new file mode 100644 index 0000000000..63acb9c1bb --- /dev/null +++ b/src/main/java/duke/command/CommandClear.java @@ -0,0 +1,17 @@ +package duke.command; + +import duke.taskList.TaskList; + +public class CommandClear extends Command { + + public static final String SUCCESS = "Sheena: So sad but yeah the list has been cleared.."; + + public CommandClear() { + } + + @Override + public CommandOption execute() { + TaskList.clear(); + return new CommandOption(SUCCESS); + } +} diff --git a/src/main/java/duke/command/CommandDeadline.java b/src/main/java/duke/command/CommandDeadline.java new file mode 100644 index 0000000000..7aed8ff46f --- /dev/null +++ b/src/main/java/duke/command/CommandDeadline.java @@ -0,0 +1,34 @@ +package duke.command; + +import duke.taskList.TaskList; +import duke.task.Deadlines; + +public class CommandDeadline extends Command { + + public static final String SUCCESS = "Sheena: YAY! This task is added: \n" + +"\n%s.\n Sheena: Now you have %d tasks in your list ~ "; + + public static final String DUPLICATE = "Sheena: Erm. This task is already in the list..."; + + private Deadlines Add; + + public CommandDeadline(Deadlines Add){ + this.Add = Add; + } + public CommandDeadline(String desc,String dueDate) throws StringIndexOutOfBoundsException { + if (desc.isEmpty() || dueDate.isEmpty()) { + throw new StringIndexOutOfBoundsException(); + } + this.Add = new Deadlines(desc,dueDate); + } + + @Override + public CommandOption execute() { + try { + TaskList.add(Add); + return new CommandOption(String.format(SUCCESS, Add.toString(),TaskList.size())); + } catch (TaskList.DuplicateTaskException dpe) { + return new CommandOption(DUPLICATE); + } + } +} diff --git a/src/main/java/duke/command/CommandDelete.java b/src/main/java/duke/command/CommandDelete.java new file mode 100644 index 0000000000..64437f0da8 --- /dev/null +++ b/src/main/java/duke/command/CommandDelete.java @@ -0,0 +1,30 @@ +package duke.command; +import duke.taskList.TaskList; +import duke.task.Task; + +public class CommandDelete extends Command { + + int deleteIndex; + + public CommandDelete(int targetIndex) { + this.deleteIndex = targetIndex; + } + + public static final String INVALID_TASK = "Sheena: I can't delete, you have not added task %s yet.."; + + public static final String DELETE = "Sheena: YAY! You deleted task: %1$s !\n"; + + @Override + + public CommandOption execute() { + try { + Task t = TaskList.retrieve(deleteIndex-1); + TaskList.remove(deleteIndex-1); + return new CommandOption(String.format(DELETE,t.toString()) + + "\nNow you have " + TaskList.size() + " tasks in your list ~"); + + } catch (IndexOutOfBoundsException | TaskList.TaskNotFoundException ie) { + return new CommandOption(String.format(INVALID_TASK,deleteIndex)); + } + } +} diff --git a/src/main/java/duke/command/CommandDone.java b/src/main/java/duke/command/CommandDone.java new file mode 100644 index 0000000000..94e141bd11 --- /dev/null +++ b/src/main/java/duke/command/CommandDone.java @@ -0,0 +1,30 @@ +package duke.command; +import duke.taskList.TaskList; +import duke.task.Task; + +public class CommandDone extends Command { + + int numberToMark; + + public static final String MARK_TASK_DONE = "Sheena: YAY! I have marked it as done: %1$s"; + public static final String INVALID_TASK = "Sheena: Erm. Maybe you provided a wrong number ?"; + public static final String TASK_NOT_EXIST = "Sheena: Erm, I can't delete because you have not add task %s yet.."; + + public CommandDone(int numberToMark) { + this.numberToMark = numberToMark; + } + + + @Override + public CommandOption execute() { + try { + Task t = TaskList.markAsDone(numberToMark-1); + return new CommandOption(String.format(MARK_TASK_DONE,t.toString())); + } catch (TaskList.TaskNotFoundException tnf) { + return new CommandOption(TASK_NOT_EXIST); + } catch (IndexOutOfBoundsException ie) { + //ie: if the user type 0 / number that is not within the list + return new CommandOption(INVALID_TASK); + } + } +} diff --git a/src/main/java/duke/command/CommandEvent.java b/src/main/java/duke/command/CommandEvent.java new file mode 100644 index 0000000000..c5a818915b --- /dev/null +++ b/src/main/java/duke/command/CommandEvent.java @@ -0,0 +1,36 @@ +package duke.command; + +import duke.taskList.TaskList; +import duke.task.Events; + +public class CommandEvent extends Command { + + public static final String SUCCESS = "Sheena: YAY! added this task: \n" + +"\t%s.\n Sheena: Now you have %d tasks in your list ~"; + + public static final String DUPLICATE = "Sheena: Erm. This task is already in the list..."; + + private Events Add; + + public CommandEvent(Events Add) { + this.Add = Add; + } + + public CommandEvent(String desc, String date) throws StringIndexOutOfBoundsException { + if(!(!desc.isEmpty()) || !(!date.isEmpty())){ + throw new StringIndexOutOfBoundsException(); + } + this.Add = new Events(desc, date); + } + + @Override + public CommandOption execute() { + try { + TaskList.add(Add); + return new CommandOption(String.format(SUCCESS, Add, TaskList.size())); + } catch (TaskList.DuplicateTaskException dpe) { + return new CommandOption(DUPLICATE); + } + + } +} diff --git a/src/main/java/duke/command/CommandFind.java b/src/main/java/duke/command/CommandFind.java new file mode 100644 index 0000000000..c73c8ba308 --- /dev/null +++ b/src/main/java/duke/command/CommandFind.java @@ -0,0 +1,31 @@ +package duke.command; + +import duke.taskList.TaskList; +import duke.task.Task; +import duke.Ui.TextUi; +import java.util.ArrayList; + +import static duke.taskList.TaskList.filterTheList; +public class CommandFind extends Command{ + + public static final String EMPTY_LIST_MESSAGE = "Sheena: Erm, List is currently empty."; + String Keyword; + public CommandFind (String filtered_word){ + + this.Keyword = filtered_word; + } + + @Override + public CommandOption execute() { + try { + ArrayList duplicateList = TaskList.copy(); + ArrayList listToFilter = filterTheList(duplicateList, Keyword); + System.out.println("Sheena: Yay! Here are the matching tasks in your list:\n"); + TaskList.printList(listToFilter); + return new CommandOption(String.format(getMessageForTaskListShownSummary(listToFilter),listToFilter)); + } catch (NullPointerException e) { + return new CommandOption(EMPTY_LIST_MESSAGE); + } + + } +} diff --git a/src/main/java/duke/command/CommandList.java b/src/main/java/duke/command/CommandList.java new file mode 100644 index 0000000000..5608d63f20 --- /dev/null +++ b/src/main/java/duke/command/CommandList.java @@ -0,0 +1,23 @@ +package duke.command; +import duke.taskList.TaskList; +import duke.task.Task; +import java.util.ArrayList; + +public class CommandList extends Command{ + + public static final String EMPTY_LIST = "Sheena: Erm. There is nothing in the list..."; + + @Override + public CommandOption execute() { + try { + + ArrayList duplicateTaskList = TaskList.copy(); + System.out.println("Sheena: Yay! Now you have these ~"); + TaskList.printList(duplicateTaskList); + return new CommandOption(String.format(getMessageForTaskListShownSummary(duplicateTaskList),duplicateTaskList)); + } catch (NullPointerException e) { + return new CommandOption(EMPTY_LIST); + } + + } +} diff --git a/src/main/java/duke/command/CommandOption.java b/src/main/java/duke/command/CommandOption.java new file mode 100644 index 0000000000..31f44d2339 --- /dev/null +++ b/src/main/java/duke/command/CommandOption.java @@ -0,0 +1,11 @@ +package duke.command; + +public class CommandOption { + + public final String feedback; + + public CommandOption(String feedback) { + this.feedback = feedback; + + } +} diff --git a/src/main/java/duke/command/CommandToDo.java b/src/main/java/duke/command/CommandToDo.java new file mode 100644 index 0000000000..18c624d920 --- /dev/null +++ b/src/main/java/duke/command/CommandToDo.java @@ -0,0 +1,36 @@ +package duke.command; +import duke.taskList.TaskList; +import duke.task.ToDos; + +public class CommandToDo extends Command { + + private ToDos Add; + + public CommandToDo(ToDos Add) { + this.Add = Add; + } + + public CommandToDo(String desc) throws NullPointerException { + if (!(!desc.isEmpty())) { + throw new NullPointerException(); + } + this.Add = new ToDos(desc); + } + + public static final String SUCCESS = "Sheena: Yay! I've added this task: \n" + + "\n %s.\nNow you have %d tasks in your list ~ "; + public static final String DUPLICATE_TASK = "Sheena: This task already exists in the list ~"; + public static final String ERROR = "Sheena: Sorry, but the %s of a todo command cannot be empty ~"; + + @Override + public CommandOption execute() { + try { + taskList.add(Add); + return new CommandOption(String.format(SUCCESS, Add.toString(), taskList.size())); + } catch (NullPointerException NPE) { + return new CommandOption(String.format(ERROR, "description")); + } catch (TaskList.DuplicateTaskException dpe) { + return new CommandOption(DUPLICATE_TASK); + } + } +} diff --git a/src/main/java/duke/command/FalseCommand.java b/src/main/java/duke/command/FalseCommand.java new file mode 100644 index 0000000000..ef07480996 --- /dev/null +++ b/src/main/java/duke/command/FalseCommand.java @@ -0,0 +1,15 @@ +package duke.command; + +public class FalseCommand extends Command { + + public final String feedback; + + public FalseCommand(String feedbackToUser) { + this.feedback = feedbackToUser; + } + + @Override + public CommandOption execute() { + return new CommandOption(feedback); + } +} diff --git a/src/main/java/duke/exception/DukeException.java b/src/main/java/duke/exception/DukeException.java deleted file mode 100644 index 021e6fdbd9..0000000000 --- a/src/main/java/duke/exception/DukeException.java +++ /dev/null @@ -1,8 +0,0 @@ -package duke.exception; - -public class DukeException extends Exception{ -} - -class EmptyListException extends Exception{ - -} diff --git a/src/main/java/duke/exception/DuplicateInformationException.java b/src/main/java/duke/exception/DuplicateInformationException.java new file mode 100644 index 0000000000..7a0407a520 --- /dev/null +++ b/src/main/java/duke/exception/DuplicateInformationException.java @@ -0,0 +1,8 @@ +package duke.exception; + +public abstract class DuplicateInformationException extends IncorrectValueException { + + public DuplicateInformationException(String message) { + super(message); + } +} diff --git a/src/main/java/duke/exception/IncorrectValueException.java b/src/main/java/duke/exception/IncorrectValueException.java new file mode 100644 index 0000000000..cac30126cf --- /dev/null +++ b/src/main/java/duke/exception/IncorrectValueException.java @@ -0,0 +1,8 @@ +package duke.exception; + +public class IncorrectValueException extends Exception { + + public IncorrectValueException(String message) { + super(message); + } +} diff --git a/src/main/java/duke/exception/TaskNotFoundException.java b/src/main/java/duke/exception/TaskNotFoundException.java new file mode 100644 index 0000000000..43adc5cd04 --- /dev/null +++ b/src/main/java/duke/exception/TaskNotFoundException.java @@ -0,0 +1,4 @@ +package duke.exception; + +public class TaskNotFoundException { +} diff --git a/src/main/java/duke/parser/Parser.java b/src/main/java/duke/parser/Parser.java new file mode 100644 index 0000000000..85d2ba4fa1 --- /dev/null +++ b/src/main/java/duke/parser/Parser.java @@ -0,0 +1,101 @@ +package duke.parser; +import duke.command.Command; +import duke.command.CommandToDo; +import duke.command.CommandEvent; +import duke.command.CommandDeadline; +import duke.command.CommandDone; +import duke.command.CommandDelete; +import duke.command.CommandList; +import duke.command.CommandClear; +import duke.command.CommandBye; +import duke.command.FalseCommand; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class Parser { + + public static final Pattern COMMAND_FORMAT = Pattern.compile("(?^[\\S]+)(?[\\d\\s\\S]*$)"); + public static final String INVALID_TASK = "Sheena: Erm. This number is invalid..Maybe try another number?"; + public static final String ERROR = "Sheena: Erm, The %s of a %s command cannot be empty."; + public static final String TRY_AGAIN = "Sheena: Try again maybe? This is not part of the command."; + + public Command parseCommand(String userInput) { + final Matcher matcher = COMMAND_FORMAT.matcher(userInput.trim()); + if (!matcher.matches()) { + System.out.println("Sheena: Erm, This is a wrong command. Wanna try again? "); + } + + final String commandWord = matcher.group("commandWord").trim(); + final String arguments = matcher.group("arguments").trim(); + + if (commandWord.equals("bye")) { + + return new CommandBye(); + + } else if (commandWord.equals("list")) { + + return new CommandList(); + + } else if (commandWord.equals("done")) { + + try { + final int targetIndex = parseArgsAsDisplayedIndex(arguments); + return new CommandDone(targetIndex); + } catch (NumberFormatException nfe) { + return new FalseCommand(INVALID_TASK); + } + + } else if (commandWord.equals("todo")) { + try { + return new CommandToDo(arguments); + } catch (NullPointerException npe) { + return new FalseCommand(String.format(ERROR, "description", "todo")); + } + + } else if (commandWord.equals("event")) { + + try { + final int indexOfAtPrefix = arguments.indexOf("/at"); + + String description = arguments.substring(0, indexOfAtPrefix); + String timeOfEvent = arguments.substring(indexOfAtPrefix + 3).trim(); + return new CommandEvent(description, timeOfEvent); + } catch (StringIndexOutOfBoundsException iob) { + return new FalseCommand(String.format(ERROR, "description and/or time", "event")); + } + + } else if (commandWord.equals("deadline")) { + + try { + final int indexOfByPrefix = arguments.trim().indexOf("/by"); + String description = arguments.trim().substring(0, indexOfByPrefix); + String dueDate = arguments.substring(indexOfByPrefix + 3).trim(); + return new CommandDeadline(description, dueDate); + } catch (StringIndexOutOfBoundsException iob) { + return new FalseCommand(String.format(ERROR, "description and/or due date", "deadline")); + } + + } else if (commandWord.equals("delete")) { + + try { + final int targetIndex = parseArgsAsDisplayedIndex(arguments); + return new CommandDelete(targetIndex); + } catch (NumberFormatException nfe) { + return new FalseCommand(INVALID_TASK); + } + + } else if (commandWord.equals("clear")){ + + return new CommandClear(); + + } else { + return new FalseCommand(TRY_AGAIN); + } + + } + + private int parseArgsAsDisplayedIndex(String args) throws NumberFormatException { + return Integer.parseInt(args.trim()); + } +} + diff --git a/src/main/java/duke/storage/ReadTaskList.java b/src/main/java/duke/storage/ReadTaskList.java new file mode 100644 index 0000000000..603744e0c6 --- /dev/null +++ b/src/main/java/duke/storage/ReadTaskList.java @@ -0,0 +1,44 @@ +package duke.storage; +import duke.taskList.TaskList; +import duke.task.Deadlines; +import duke.task.Events; +import duke.task.Task; +import duke.task.ToDos; +import java.util.*; + +public class ReadTaskList { + + public static TaskList accessTaskList(List saveTaskList) throws TaskList.DuplicateTaskException { + final List readTasks = new ArrayList<>(); + for (String saveTask : saveTaskList) { + readTasks.add(accessTask(saveTask)); + } + return new TaskList(readTasks); + } + + private static Task accessTask(String savedTask) { + String[] parse = savedTask.split("\\s*\\|\\s*"); + if (parse.length == 3) { + ToDos t = new ToDos(parse[2]); + if (parse[1].equals("1")) { + t.markAsDone(); + } + return t; + } else if (parse.length == 4) { + if (parse[0].equals("D")) { + Deadlines d = new Deadlines(parse[2], parse[3]); + if (parse[1].equals("1")) { + d.markAsDone(); + } + return d; + } else { + Events e = new Events(parse[2], parse[3]); + if (parse[1].equals("1")) { + e.markAsDone(); + } + return e; + } + } + return null; + } +} diff --git a/src/main/java/duke/storage/SaveTaskList.java b/src/main/java/duke/storage/SaveTaskList.java new file mode 100644 index 0000000000..1a93f35903 --- /dev/null +++ b/src/main/java/duke/storage/SaveTaskList.java @@ -0,0 +1,44 @@ +package duke.storage; +import duke.taskList.TaskList; +import duke.task.Deadlines; +import duke.task.Events; +import duke.task.Task; +import duke.task.ToDos; +import java.util.*; +import java.util.ArrayList; + +public class SaveTaskList { + + public static List saveTaskList(TaskList toSave) { + final List saveTask = new ArrayList<>(); + toSave.getAllTasks().forEach(task -> saveTask.add(storeTask(task))); + return saveTask; + } + + private static String storeTask(Task t) { + String fileDoneStatus; + if (t.getStatusIcon().equals("\u2718")) { + fileDoneStatus = "0"; + } else { + fileDoneStatus = "1"; + } + final StringBuilder storedTask = new StringBuilder(); + if (t instanceof ToDos){ + storedTask.append(t.getTaskType()); + storedTask.append(" | ").append(fileDoneStatus); + storedTask.append(" | ").append(t.description); + } else if (t instanceof Deadlines) { + storedTask.append(t.getTaskType()); + storedTask.append(" | ").append(fileDoneStatus); + storedTask.append(" | ").append(t.description).append(" | "); + storedTask.append(((Deadlines) t).getDueDate()); + } else if (t instanceof Events) { + storedTask.append(t.getTaskType()); + storedTask.append(" | ").append(fileDoneStatus); + storedTask.append(" | ").append(t.description).append(" | "); + storedTask.append(((Events) t).getTimeOfEvent()); + } + + return storedTask.toString(); + } +} diff --git a/src/main/java/duke/storage/Storage.java b/src/main/java/duke/storage/Storage.java new file mode 100644 index 0000000000..c0ace8acbd --- /dev/null +++ b/src/main/java/duke/storage/Storage.java @@ -0,0 +1,85 @@ +package duke.storage; +import duke.taskList.TaskList; +import duke.exception.IncorrectValueException; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; + +/** + * Represents the file used to store address book data. + */ + +public class Storage { + /** Default file path used if the user doesn't provide the file name. */ + public static final String DEFAULT_FILE = "duke.txt"; + public final Path path; + + + public Storage() throws StorageFilePathException { + this(DEFAULT_FILE); + } + + public Storage(String filePath) throws StorageFilePathException { + path = Paths.get(filePath); + if (!isValidPath(path)) { + throw new StorageFilePathException("Storage file should end with '.txt'"); + } + } + + private static boolean isValidPath(Path filePath) { + return filePath.toString().endsWith(".txt"); + } + + /** + * Saves the {@code addressBook} data to the storage file. + * + * @throws StorageOperationException if there were errors converting and/or storing data to file. + */ + public void save(TaskList tasklist) throws StorageOperationException { + try { + List writeTaskList = SaveTaskList.saveTaskList(tasklist); + Files.write(path, writeTaskList); + } catch (IOException ioe) { + throw new StorageOperationException("Error writing to file: " + path); + } + } + + public TaskList load() throws StorageOperationException { + + if (!Files.isRegularFile(path) || !Files.exists(path) ) { + return new TaskList(); + } + + try { + return ReadTaskList.accessTaskList(Files.readAllLines(path)); + } catch (FileNotFoundException fnfe) { + throw new AssertionError("Sheena: The non-existent file scenario is already handled."); + // other errors + } catch (IOException ioe) { + throw new StorageOperationException("Sheena: Error writing to file " + path); + } catch (IncorrectValueException ive) { + throw new StorageOperationException("Sheena: Hey! File contains illegal data!"); + } + } + + public String getPath() { + return path.toString(); + } + + + public static class StorageFilePathException extends IncorrectValueException { + public StorageFilePathException(String message) { + super(message); + } + } + + public static class StorageOperationException extends Exception { + public StorageOperationException(String message) { + super(message); + } + } + +} \ No newline at end of file diff --git a/src/main/java/duke/task/Deadlines.java b/src/main/java/duke/task/Deadlines.java index 5a22f3e0e1..00e159269e 100644 --- a/src/main/java/duke/task/Deadlines.java +++ b/src/main/java/duke/task/Deadlines.java @@ -22,4 +22,10 @@ public void setDueDate(String dueDate) { public String toString() { return "[" + super.getTaskType() + "]" + super.toString() + "(by: " + getDueDate() + ")"; } + + @Override + public boolean isSameTask(Task toCheck) { + return (toCheck == this) || ( !(toCheck == null) && toCheck.getDescription().equals(this.getDescription()) + && ((Deadlines) toCheck).getDueDate().equals(this.getDueDate())); + } } \ No newline at end of file diff --git a/src/main/java/duke/task/Events.java b/src/main/java/duke/task/Events.java index d274285bed..95fa86c772 100644 --- a/src/main/java/duke/task/Events.java +++ b/src/main/java/duke/task/Events.java @@ -23,4 +23,10 @@ public void setTimeOfEvent(String timeOfEvent) { public String toString() { return "[" + super.getTaskType() + "]" + super.toString() + "(at: " + getTimeOfEvent() + ")"; } + + @Override + public boolean isSameTask(Task toCheck) { + return (toCheck == this) || ( !(toCheck == null) && toCheck.getDescription().equals(this.getDescription()) + && ((Events) toCheck).getTimeOfEvent().equals(this.getTimeOfEvent())); + } } \ No newline at end of file diff --git a/src/main/java/duke/task/Task.java b/src/main/java/duke/task/Task.java index 7d1bfdb547..5047e04555 100644 --- a/src/main/java/duke/task/Task.java +++ b/src/main/java/duke/task/Task.java @@ -2,8 +2,8 @@ public class Task { public String description; - protected boolean isDone; - protected String taskType; + public boolean isDone; + public String taskType; public Task(String description) { this.description = description; @@ -39,8 +39,13 @@ public String getStatusIcon() { return (isDone ? "\u2713" : "\u2718"); //return tick or X symbols } + @Override public String toString() { return "[" + getStatusIcon() + "]" + description; } + + public boolean isSameTask(Task toCheck){ + return (toCheck == this) || ( !(toCheck == null) && toCheck.getDescription().equals(this.getDescription())); + } } \ No newline at end of file diff --git a/src/main/java/duke/task/ToDos.java b/src/main/java/duke/task/ToDos.java index 9338cd703e..4777596f33 100644 --- a/src/main/java/duke/task/ToDos.java +++ b/src/main/java/duke/task/ToDos.java @@ -13,4 +13,9 @@ public ToDos(String description) { public String toString() { return "[" + super.getTaskType() + "]" + super.toString(); } + + @Override + public boolean isSameTask(Task toCheck) { + return super.isSameTask(toCheck); + } } \ No newline at end of file diff --git a/src/main/java/duke/taskList/TaskList.java b/src/main/java/duke/taskList/TaskList.java new file mode 100644 index 0000000000..86b63c6d2c --- /dev/null +++ b/src/main/java/duke/taskList/TaskList.java @@ -0,0 +1,189 @@ +package duke.taskList; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; +import duke.task.Deadlines; +import duke.task.Events; +import duke.task.Task; +import duke.task.ToDos; +import duke.exception.DuplicateInformationException; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + + +/** + * Represents the entire task list. Contains the data of the task list. + */ +public class TaskList { + + public static ArrayList taskList = new ArrayList<>(); + + public TaskList() { + } + + /** + * Constructs a list from the items in the given collection. + * + * @param Tasks a collection of tasks + * @throws DuplicateTaskException if the {@code persons} contains duplicate tasks + */ + public TaskList(List Tasks) throws DuplicateTaskException { + if (!uniqueElements(Tasks)) { + throw new DuplicateTaskException(); + } + taskList.addAll(Tasks); + } + + + public static boolean contains(Task toCheck) { + for (Task a : taskList) { + if (a instanceof ToDos && toCheck instanceof ToDos) { + return (((ToDos)a).isSameTask(toCheck)); + } else if (a instanceof Events && toCheck instanceof Events) { + return (((Events)a).isSameTask(toCheck)); + } else if (a instanceof Deadlines && toCheck instanceof Deadlines) { + return (((Deadlines)a).isSameTask(toCheck)); + } + } + return false; + } + + /** + * Adds one task to the list. + * + * @throws DuplicateTaskException if the task to add is a duplicate of an existing task in the list. + */ + public static void add(Task toAdd) throws DuplicateTaskException { + if (contains(toAdd)) { + throw new DuplicateTaskException(); + } + taskList.add(toAdd); + } + + public static Task retrieve(int targetIndex) { + return taskList.get(targetIndex); + } + + /** + * Removes task from the list. + * + * @throws TaskNotFoundException if no such task could be found in the list. + */ + public static void remove(int toRemove) throws TaskNotFoundException { + Task t = taskList.get(toRemove); + final boolean taskFoundAndDeleted = taskList.remove(t); + if (!taskFoundAndDeleted) { + throw new TaskNotFoundException(); + } + } + + + public static int size() { + return taskList.size(); + } + + /** + * Clears task list. + */ + public static void clear() { + taskList.clear(); + } + + /** + * @return the duplicate task list + */ + public static ArrayList copy() { + + return (new ArrayList<>(taskList)); + } + + /** + * Shows to user all elements in task list. + */ + public static void printList(ArrayList taskList) throws NullPointerException { + int taskCounter = 1; + if (taskList.size() == 0) { + throw new NullPointerException(); + } else { + System.out.println("----------------------------"); + System.out.println("Sheena: Well, you have these items in your list: \n"); + for (Task t : taskList) { + System.out.println(" " + taskCounter + ". " + t.toString()); + taskCounter++; + } + System.out.println("----------------------------"); + } + } + + public static ArrayList filterTheList(ArrayList taskList, String keyword) { + + return (ArrayList) taskList.stream() + .filter(task -> task.description.contains(keyword)) + .collect(Collectors.toList()); + } + + /** + * Marks a task as [done]. + */ + public static Task markAsDone(int targetIndex) throws TaskNotFoundException { + Task t = TaskList.retrieve(targetIndex); + t.markAsDone(); + final boolean taskFound_Marked = t.isDone; + if (!taskFound_Marked) { + throw new TaskNotFoundException(); + } + return t; + } + + /** + * Returns a new task list of all tasks in list at the time of the call. + */ + public ArrayList getAllTasks() { + return taskList; + } + + + /** + * Signals that an operation would have violated the 'no duplicates' property of the list. + */ + public static class DuplicateTaskException extends DuplicateInformationException { + protected DuplicateTaskException() { + super("Sheena: Erm. There will be duplicate tasks tho.."); + } + } + + + public static class TaskNotFoundException extends Exception { + protected TaskNotFoundException() { + super("Sheena: Erm, I can't delete because you haven't added that task.."); + } + } + + + public static boolean uniqueElements(Collection items) { + final Set testSet = new HashSet<>(); + for (Object item : items) { + final boolean itemExists = !testSet.add(item); // see Set documentation + if (itemExists) { + return false; + } + } + return true; + } + + public static void storedTaskList() throws NullPointerException { + int counter = 1; + if (taskList.size() == 0) { + throw new NullPointerException(); + } else { + for (Task t : taskList) { + System.out.println(" " + counter + ". " + t.toString()); + counter++; + } + } + } + + +} From f074ee301046235de373204481efe93cdc1db8ca Mon Sep 17 00:00:00 2001 From: jiajuinphoon <42569361+jiajuinphoon@users.noreply.github.com> Date: Mon, 2 Mar 2020 12:13:57 +0800 Subject: [PATCH 13/14] Update README.md A-UserGuide-done --- docs/README.md | 173 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 163 insertions(+), 10 deletions(-) diff --git a/docs/README.md b/docs/README.md index fd44069597..d5e94b427a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,20 +1,173 @@ -# User Guide +# User Guide for Application SHEENA ## Features -### Feature 1 -Description of feature. +### 1. Add a todo task -## Usage +Users are able to add one specific task every time they type "todo" command +A capital letter "T" will shown when you successfully added the task. +A tick or cross will shown besides the capital letter "E" to indicate whether the task is done by the user. -### `Keyword` - Describe action +"todo" - to indicate the system that this is a todo task +"description" - describe the task -Describe action and its outcome. -Example of usage: +Format: todo description -`keyword (optional arguments)` +Eg: todo Love Sheena. -Expected outcome: +IMPORTANT: User must provide a description. -`outcome` +Outcome: +[T].[tick / cross] todo Love Sheena + + +### 2. Add an Event task + +Users are able to add one specific event task every time they type "event" command +We will use /at to differentiate the time +A capital letter "E" will shown when you successfully added the event. +A tick or cross will shown besides the capital letter "E" to indicate whether the event is done by the user. + + +"event" - to indicate the system that this is a todo task +"/at" - to indicate the system that the time is behind the /at +"description" - describe the event +"time" - describe the details for time (at: Mon 2-4pm) + +Format: event (description) /at (time) + +Eg: event Love Coco /at Mon 2-4pm + +IMPORTANT: User must provide a description and time. + +Outcome: +[E][tick / cross] event Love Coco (at: Mon 2-4pm) + + + +### 3. Add a Deadline task + +Users are able to add one specific deadline task every time they type "event" command +We will use /by to differentiate the day +A capital letter "D" will shown when you successfully added the deadline. +A tick or cross will shown besides the capital letter "E" to indicate whether the task is done by the user. + + +"event" - to indicate the system that this is a todo task +"/by" - to indicate the system that the day is behind the /by +"description" - describe the event +"day" - describe the details for day (Eg: Sunday) + +Format: event (description) /by (day) + +Eg: deadline I love you Sheena /by Sunday + +IMPORTANT: User must provide a description and day. + +Outcome: +[D][tick / cross] event I love you Sheena (by: Sunday) + + +### 4. List Down the task List + +Users are able to retrieve the task that they had saved. + +"list" - to list down the task. + +Format: list + +Eg: list + +Outcome: + +Sheena: Yay! Now you have these ~ +---------------------------- +Sheena: Well, you have these items in your list: + + 1. [T][✓]buy food + 2. [T][✓]miss Sheena + 3. [T][✘]love Sheena forever + 4. [T][✘]I love you Coco +---------------------------- +Sheena: Yay! 4 tasks listed! + + +### 5. Delete A Task. + +Users are able to delete one specific event task every time they type "delete" command + + +"delete" - to indicate the system that this is a delete function +"taskNumber" - indicate the index number for the specific task (eg: 5) + +Format: delete taskNumber + +Eg: delete 5 + +IMPORTANT: User must provide a description and time. + +Outcome: + +Sheena: YAY! You deleted task: [T][✘]buy books ! + +Now you have (taskNumber-1) tasks in your list ~ + + +### 6. Find a task + +Users are able to add one specific event task every time they type "find" command + + +"find" - to indicate the system that this is a todo task +"description" - describe the thing you want to find + +Format: find (description) + +Eg: find Sheena + +IMPORTANT: User must provide a description and time. + +Outcome: +Sheena: Yay! Here are the matching tasks in your list: + +---------------------------- +Sheena: Well, you have these items in your list: + + 1. [T][✓]miss Sheena + 2. [T][✘]love Sheena forever +---------------------------- +Sheena: Yay! 2 tasks listed! + + +### 7. Clear the list + +Users are able to clear the task list + + +"clear" - to indicate the system that user is clearing the task + +Format: clear + +Eg: clear + +Outcome: +Sheena: So sad but yeah the list has been cleared.. + + +### 8. Exit the program + +Users are able to exit program. The task will be saved in a text file (eg: duke.txt) + + +"bye" - to indicate the system that user is going to exit the program + +Format: bye + +Eg: bye + +Outcome: + +Sheena: Let me save down everything ^^ + +Sheena: I will miss you! Hope to see you again soon! From 60f8c552682623b2e8099af1ddeaeb3fb14c0b42 Mon Sep 17 00:00:00 2001 From: jiajuinphoon Date: Mon, 2 Mar 2020 12:16:49 +0800 Subject: [PATCH 14/14] Small change for adding back find function. --- src/main/java/duke/parser/Parser.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/duke/parser/Parser.java b/src/main/java/duke/parser/Parser.java index 85d2ba4fa1..f77b4fc69c 100644 --- a/src/main/java/duke/parser/Parser.java +++ b/src/main/java/duke/parser/Parser.java @@ -3,6 +3,7 @@ import duke.command.CommandToDo; import duke.command.CommandEvent; import duke.command.CommandDeadline; +import duke.command.CommandFind; import duke.command.CommandDone; import duke.command.CommandDelete; import duke.command.CommandList; @@ -88,6 +89,9 @@ public Command parseCommand(String userInput) { return new CommandClear(); + } else if (commandWord.equals("find")){ + + return new CommandFind(arguments); } else { return new FalseCommand(TRY_AGAIN); }