From cfa100be5ea0a2b8307534b5184e1f09eff836ab Mon Sep 17 00:00:00 2001 From: wingho2 Date: Thu, 2 Sep 2021 02:57:16 +0800 Subject: [PATCH 01/62] Change the dukes speech Change the initial string that printed --- src/main/java/Duke.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5d313334c..e9d5545e0 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -5,6 +5,11 @@ public static void main(String[] args) { + "| | | | | | | |/ / _ \\\n" + "| |_| | |_| | < __/\n" + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); + System.out.println("H____________________________________________________________\n" + + " Hello! I'm Duke\n" + + " What can I do for you?\n" + + "____________________________________________________________\n" + + " Bye. Hope to see you again soon!\n" + + "____________________________________________________________" + logo); } } From 58398a497eb8665301e37d4c7f9e270216489c91 Mon Sep 17 00:00:00 2001 From: wingho2 Date: Thu, 2 Sep 2021 03:19:38 +0800 Subject: [PATCH 02/62] Add a echo functions that repeat commands entered by the user and exit on bye Import a Scanner class and add a to that echo input. --- src/main/java/Duke.java | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index e9d5545e0..527c7f380 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,3 +1,5 @@ +import java.util.Scanner; + public class Duke { public static void main(String[] args) { String logo = " ____ _ \n" @@ -5,11 +7,24 @@ public static void main(String[] args) { + "| | | | | | | |/ / _ \\\n" + "| |_| | |_| | < __/\n" + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("H____________________________________________________________\n" + + System.out.println( logo + + "____________________________________________________________\n" + " Hello! I'm Duke\n" + " What can I do for you?\n" + - "____________________________________________________________\n" + - " Bye. Hope to see you again soon!\n" + - "____________________________________________________________" + logo); + "____________________________________________________________\n"); + Scanner in = new Scanner(System.in); + while(true) { + String echo = in.nextLine(); + String echoLower = echo.toLowerCase(); + if (echoLower.equals("bye")) { + System.out.println( + "____________________________________________________________\n" + + "Bye. Hope to see you again soon!\n" + + "____________________________________________________________"); + break; + }else { + System.out.println("____________________________________________________________\n" + echo + System.lineSeparator() + "____________________________________________________________"); + } + } } } From 7b1d07416b52516f72e0deed0ed0cad11198b3a3 Mon Sep 17 00:00:00 2001 From: wingho2 Date: Thu, 2 Sep 2021 03:36:24 +0800 Subject: [PATCH 03/62] Add the ability to store text input into a list and display it back when list is called Add a array of size 100 that store string --- src/main/java/Duke.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 527c7f380..5828895bb 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -13,6 +13,8 @@ public static void main(String[] args) { " What can I do for you?\n" + "____________________________________________________________\n"); Scanner in = new Scanner(System.in); + String[] list = new String[100]; + int listIndex = 0; while(true) { String echo = in.nextLine(); String echoLower = echo.toLowerCase(); @@ -22,8 +24,14 @@ public static void main(String[] args) { "Bye. Hope to see you again soon!\n" + "____________________________________________________________"); break; + }else if(echoLower.equals("list")) { + for(int i = 0; i < listIndex; i ++){ + System.out.println((i + 1) + ". "+ list[i]); + } }else { - System.out.println("____________________________________________________________\n" + echo + System.lineSeparator() + "____________________________________________________________"); + list[listIndex] = echoLower; + listIndex += 1; + System.out.println("____________________________________________________________\n" + "added: " + echo + System.lineSeparator() + "____________________________________________________________"); } } } From 1d74b399dc6148fb1abb99aaa4f4c8894c65132c Mon Sep 17 00:00:00 2001 From: wingho2 Date: Thu, 2 Sep 2021 04:26:26 +0800 Subject: [PATCH 04/62] Add the ability to mark task as done Add Task class iinstead of just storing the tasks as strings --- src/main/java/Duke.java | 13 ++++++++++--- src/main/java/Task.java | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 src/main/java/Task.java diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5828895bb..5d2b11ec0 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -13,7 +13,7 @@ public static void main(String[] args) { " What can I do for you?\n" + "____________________________________________________________\n"); Scanner in = new Scanner(System.in); - String[] list = new String[100]; + Task[] list = new Task[100]; int listIndex = 0; while(true) { String echo = in.nextLine(); @@ -26,10 +26,17 @@ public static void main(String[] args) { break; }else if(echoLower.equals("list")) { for(int i = 0; i < listIndex; i ++){ - System.out.println((i + 1) + ". "+ list[i]); + System.out.println((i + 1) + ". ["+ list[i].getStatusIcon() + "] " + list[i].getDescription()); + } + }else if(echoLower.equals("done")) { + int taskDone = Integer.parseInt(in.nextLine()); + list[taskDone-1].markAsDone(); + for(int i = 0; i < listIndex; i ++){ + System.out.println((i + 1) + ". ["+ list[i].getStatusIcon() + "] " + list[i].getDescription()); } }else { - list[listIndex] = echoLower; + Task t = new Task(echoLower); + list[listIndex] = t; listIndex += 1; System.out.println("____________________________________________________________\n" + "added: " + echo + System.lineSeparator() + "____________________________________________________________"); } diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 000000000..43892d06a --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,18 @@ +public class Task { + protected String description; + protected boolean isDone; + + public Task(String description){ + this.description = description; + this.isDone = false; + } + public void markAsDone(){ + isDone = true; + } + public String getDescription(){ + return description; + } + public String getStatusIcon(){ + return(isDone?"X":" "); + } +} From eed209d88120cf3574245650416e0d73d01537cd Mon Sep 17 00:00:00 2001 From: wingho2 Date: Thu, 2 Sep 2021 10:58:36 +0800 Subject: [PATCH 05/62] Add catergory to the task, todo,deadlines and events Added 3 class that inherit from --- src/main/java/Deadline.java | 10 ++++++++++ src/main/java/Duke.java | 31 ++++++++++++++++++++++++------- src/main/java/Event.java | 10 ++++++++++ src/main/java/Task.java | 3 +++ src/main/java/Todo.java | 11 +++++++++++ 5 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 src/main/java/Deadline.java create mode 100644 src/main/java/Event.java create mode 100644 src/main/java/Todo.java diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java new file mode 100644 index 000000000..0a982641a --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,10 @@ +public class Deadline extends Task{ + protected String by; + public Deadline(String description, String by){ + super(description); + this.by = by; + } + public String toString(){ + return "[D]" + super.toString() + "by: " + by + ")"; + } +} diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5d2b11ec0..0272f1beb 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -26,19 +26,36 @@ public static void main(String[] args) { break; }else if(echoLower.equals("list")) { for(int i = 0; i < listIndex; i ++){ - System.out.println((i + 1) + ". ["+ list[i].getStatusIcon() + "] " + list[i].getDescription()); + System.out.println((i + 1) + ". " + list[i].toString()); } }else if(echoLower.equals("done")) { int taskDone = Integer.parseInt(in.nextLine()); - list[taskDone-1].markAsDone(); - for(int i = 0; i < listIndex; i ++){ - System.out.println((i + 1) + ". ["+ list[i].getStatusIcon() + "] " + list[i].getDescription()); + list[taskDone - 1].markAsDone(); + for (int i = 0; i < listIndex; i++) { + System.out.println((i + 1) + ". " + list[i].toString()); } - }else { - Task t = new Task(echoLower); + }else if(echoLower.startsWith("event")){ + int startOfTime = echoLower.indexOf("/"); + String description = echoLower.substring(6,startOfTime); + String time = echoLower.substring(startOfTime + 1); + Task t = new Event(description, time); + list[listIndex] = t; + listIndex += 1; + System.out.println("Got it. I've added this task: " + System.lineSeparator() + t.toString() + System.lineSeparator() + "Now you have " + listIndex+" tasks in the list."); + }else if (echoLower.startsWith("todo")){ + String description = echoLower.substring(5); + Task t = new Todo(description); + list[listIndex] = t; + listIndex += 1; + System.out.println("Got it. I've added this task: " + System.lineSeparator() + t.toString() + System.lineSeparator() + "Now you have " + listIndex +" tasks in the list."); + }else if(echoLower.startsWith("deadline")){ + int startOfDeadline = echoLower.indexOf("/"); + String description = echoLower.substring(9,startOfDeadline); + String deadline = echoLower.substring(startOfDeadline + 1); + Task t = new Deadline(description, deadline); list[listIndex] = t; listIndex += 1; - System.out.println("____________________________________________________________\n" + "added: " + echo + System.lineSeparator() + "____________________________________________________________"); + System.out.println("Got it. I've added this task: " + System.lineSeparator() + t.toString() + System.lineSeparator() + "Now you have " + listIndex +" tasks in the list."); } } } diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 000000000..2c9bbf309 --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,10 @@ +public class Event extends Task{ + protected String time; + public Event(String description, String time){ + super(description); + this.time = time; + } + public String toString(){ + return "[E]" + super.toString() + "(at:" + time + ")"; + } +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 43892d06a..5ca9a6c07 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -15,4 +15,7 @@ public String getDescription(){ public String getStatusIcon(){ return(isDone?"X":" "); } + public String toString(){ + return "[" + getStatusIcon() + "]" + description; + } } diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java new file mode 100644 index 000000000..4eaa3416d --- /dev/null +++ b/src/main/java/Todo.java @@ -0,0 +1,11 @@ +public class Todo extends Task{ + + public Todo(String description){ + super(description); + } + + @Override + public String toString() { + return "[T]" + super.toString(); + } +} From f4fecb4162a7c2a85ef6e293db53c0e0f0ccf91d Mon Sep 17 00:00:00 2001 From: wingho2 Date: Sat, 4 Sep 2021 11:59:07 +0800 Subject: [PATCH 06/62] Refactor the code to remove duplcated functions Improve the naming to be more descriptive of the variable it represent Use constants to remove the need for magic numbers Change array into arraylist to prevent overflow of task in the array --- src/main/java/Deadline.java | 13 ++++-- src/main/java/Duke.java | 73 +++++++++++++++------------------- src/main/java/Event.java | 13 ++++-- src/main/java/ListManager.java | 44 ++++++++++++++++++++ src/main/java/Logo.java | 14 +++++++ src/main/java/Task.java | 8 ++-- src/main/java/ToDo.java | 13 ++++++ src/main/java/Todo.java | 11 ----- 8 files changed, 125 insertions(+), 64 deletions(-) create mode 100644 src/main/java/ListManager.java create mode 100644 src/main/java/Logo.java create mode 100644 src/main/java/ToDo.java delete mode 100644 src/main/java/Todo.java diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index 0a982641a..c0ba168a3 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -1,10 +1,15 @@ public class Deadline extends Task{ - protected String by; - public Deadline(String description, String by){ + + private static final String TASK_SYMBOL = "[D]"; + protected String dueDate; + + public Deadline(String description, String dueDate){ super(description); - this.by = by; + this.dueDate = dueDate; } + + @Override public String toString(){ - return "[D]" + super.toString() + "by: " + by + ")"; + return TASK_SYMBOL + super.toString() + "(by: " + dueDate + ")"; } } diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 0272f1beb..e8f603802 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,61 +1,50 @@ import java.util.Scanner; +import java.util.ArrayList; public class Duke { + private static final String COMMAND_EXIT = "bye"; + private static final String COMMAND_VIEW_LIST = "list"; + private static final String COMMAND_COMPLETE_TASK = "done"; + private static final String COMMAND_ADD_TODO = "todo"; + private static final String COMMAND_ADD_EVENT = "event"; + private static final String COMMAND_ADD_DEADLINE = "deadline"; + + private static void startDuke(){ + System.out.println(Logo.logo +Logo.divider + "Hello! I'm Duke\n" + " What can I do for you?\n" + Logo.divider); + } + + private static void endDuke(){ + System.out.println(Logo.divider + "Bye. Hope to see you again soon!\n" + Logo.divider + Logo.bye); + } + public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println( logo + - "____________________________________________________________\n" + - " Hello! I'm Duke\n" + - " What can I do for you?\n" + - "____________________________________________________________\n"); + startDuke(); Scanner in = new Scanner(System.in); - Task[] list = new Task[100]; - int listIndex = 0; + ArrayList list = new ArrayList(); + ListManager listManager = new ListManager(list); while(true) { String echo = in.nextLine(); String echoLower = echo.toLowerCase(); - if (echoLower.equals("bye")) { - System.out.println( - "____________________________________________________________\n" + - "Bye. Hope to see you again soon!\n" + - "____________________________________________________________"); + if (echoLower.equals(COMMAND_EXIT)) { + endDuke(); break; - }else if(echoLower.equals("list")) { - for(int i = 0; i < listIndex; i ++){ - System.out.println((i + 1) + ". " + list[i].toString()); - } - }else if(echoLower.equals("done")) { - int taskDone = Integer.parseInt(in.nextLine()); - list[taskDone - 1].markAsDone(); - for (int i = 0; i < listIndex; i++) { - System.out.println((i + 1) + ". " + list[i].toString()); - } - }else if(echoLower.startsWith("event")){ + }else if(echoLower.equals(COMMAND_VIEW_LIST)) { + listManager.printList(); + }else if(echoLower.startsWith(COMMAND_COMPLETE_TASK)) { + listManager.completeTask(); + }else if(echoLower.startsWith(COMMAND_ADD_EVENT)){ int startOfTime = echoLower.indexOf("/"); String description = echoLower.substring(6,startOfTime); String time = echoLower.substring(startOfTime + 1); - Task t = new Event(description, time); - list[listIndex] = t; - listIndex += 1; - System.out.println("Got it. I've added this task: " + System.lineSeparator() + t.toString() + System.lineSeparator() + "Now you have " + listIndex+" tasks in the list."); - }else if (echoLower.startsWith("todo")){ + listManager.addEvent(description,time); + }else if (echoLower.startsWith(COMMAND_ADD_TODO)){ String description = echoLower.substring(5); - Task t = new Todo(description); - list[listIndex] = t; - listIndex += 1; - System.out.println("Got it. I've added this task: " + System.lineSeparator() + t.toString() + System.lineSeparator() + "Now you have " + listIndex +" tasks in the list."); - }else if(echoLower.startsWith("deadline")){ + listManager.addTodo(description); + }else if(echoLower.startsWith(COMMAND_ADD_DEADLINE)){ int startOfDeadline = echoLower.indexOf("/"); String description = echoLower.substring(9,startOfDeadline); String deadline = echoLower.substring(startOfDeadline + 1); - Task t = new Deadline(description, deadline); - list[listIndex] = t; - listIndex += 1; - System.out.println("Got it. I've added this task: " + System.lineSeparator() + t.toString() + System.lineSeparator() + "Now you have " + listIndex +" tasks in the list."); + listManager.addDeadline(description,deadline); } } } diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 2c9bbf309..2cda9cdbc 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -1,10 +1,15 @@ public class Event extends Task{ - protected String time; - public Event(String description, String time){ + + private static final String TASK_SYMBOL = "[E]"; + protected String startTime; + + public Event(String description, String startTime){ super(description); - this.time = time; + this.startTime = startTime; } + + @Override public String toString(){ - return "[E]" + super.toString() + "(at:" + time + ")"; + return TASK_SYMBOL + super.toString() + "(at:" + startTime + ")"; } } diff --git a/src/main/java/ListManager.java b/src/main/java/ListManager.java new file mode 100644 index 000000000..bcc82ef6f --- /dev/null +++ b/src/main/java/ListManager.java @@ -0,0 +1,44 @@ +import java.util.ArrayList; + +public class ListManager { + private static ArrayList list; + + public ListManager(ArrayList list){ + this.list = list; + } + + public void printList(){ + for(int i = 0; i < list.size(); i++){ + int itemIndex= i + 1; + System.out.println(itemIndex + ". " + list.get(i).toString()); + } + } + + public void completeTask(){ + printList(); + } + + private void printAddItem(Task t){ + System.out.println("Got it. I've added this task: " + System.lineSeparator() + + t.toString() + System.lineSeparator() + "Now you have " + + list.size() +" tasks in the list."); + } + + public void addTodo(String description){ + Task t = new ToDo(description); + list.add(t); + printAddItem(t); + } + + public void addEvent(String description, String time){ + Task t = new Event(description, time); + list.add(t); + printAddItem(t); + } + + public void addDeadline(String description, String deadline){ + Task t = new Deadline(description, deadline); + list.add(t); + printAddItem(t); + } +} diff --git a/src/main/java/Logo.java b/src/main/java/Logo.java new file mode 100644 index 000000000..4523ebf8c --- /dev/null +++ b/src/main/java/Logo.java @@ -0,0 +1,14 @@ +public class Logo { + public static final String divider = "____________________________________________________________\n"; + public static final String logo = " ____ _ \n" + + "| _ \\ _ _| | _____ \n" + + "| | | | | | | |/ / _ \\\n" + + "| |_| | |_| | < __/\n" + + "|____/ \\__,_|_|\\_\\___|\n"; + public static final String bye ="_______________.___.___________\n" + + "\\______ \\__ | |\\_ _____/\n" + + " | | _// | | | __)_ \n" + + " | | \\\\____ | | \\\n" + + " |______ // ______|/_______ /\n" + + " \\/ \\/ \\/"; +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 5ca9a6c07..9576f8c41 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -1,4 +1,6 @@ public class Task { + private static final String completeStatusIcon = "[X]"; + private static final String incompleteStatusIcon = "[ ]"; protected String description; protected boolean isDone; @@ -6,16 +8,16 @@ public Task(String description){ this.description = description; this.isDone = false; } - public void markAsDone(){ + public void setDone(){ isDone = true; } public String getDescription(){ return description; } public String getStatusIcon(){ - return(isDone?"X":" "); + return(isDone ? completeStatusIcon : incompleteStatusIcon); } public String toString(){ - return "[" + getStatusIcon() + "]" + description; + return getStatusIcon() + description; } } diff --git a/src/main/java/ToDo.java b/src/main/java/ToDo.java new file mode 100644 index 000000000..c65b0b035 --- /dev/null +++ b/src/main/java/ToDo.java @@ -0,0 +1,13 @@ +public class ToDo extends Task{ + + private static final String TASK_SYMBOL = "[T]"; + + public ToDo(String description){ + super(description); + } + + @Override + public String toString() { + return TASK_SYMBOL + super.toString(); + } +} diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java deleted file mode 100644 index 4eaa3416d..000000000 --- a/src/main/java/Todo.java +++ /dev/null @@ -1,11 +0,0 @@ -public class Todo extends Task{ - - public Todo(String description){ - super(description); - } - - @Override - public String toString() { - return "[T]" + super.toString(); - } -} From b8ad62dc1e6057f585c017f8f424d06036a6a0a2 Mon Sep 17 00:00:00 2001 From: wingho2 Date: Sun, 5 Sep 2021 19:29:22 +0800 Subject: [PATCH 07/62] Added the ability to add mutiple task in the same line and the ability to set multiple task as done in the same line Added a interface to listManager to make it easier to know what listMananger does --- src/main/java/Deadline.java | 2 +- src/main/java/Duke.java | 40 +++-------- src/main/java/Event.java | 2 +- src/main/java/InputHandler.java | 123 ++++++++++++++++++++++++++++++++ src/main/java/ListManager.java | 14 ++-- src/main/java/Logo.java | 2 + src/main/java/Task.java | 8 ++- src/main/java/TaskList.java | 7 ++ 8 files changed, 157 insertions(+), 41 deletions(-) create mode 100644 src/main/java/InputHandler.java create mode 100644 src/main/java/TaskList.java diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index c0ba168a3..dc882d765 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -1,7 +1,7 @@ public class Deadline extends Task{ private static final String TASK_SYMBOL = "[D]"; - protected String dueDate; + private String dueDate; public Deadline(String description, String dueDate){ super(description); diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index e8f603802..acf1a77a3 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -2,14 +2,11 @@ import java.util.ArrayList; public class Duke { - private static final String COMMAND_EXIT = "bye"; - private static final String COMMAND_VIEW_LIST = "list"; - private static final String COMMAND_COMPLETE_TASK = "done"; - private static final String COMMAND_ADD_TODO = "todo"; - private static final String COMMAND_ADD_EVENT = "event"; - private static final String COMMAND_ADD_DEADLINE = "deadline"; + + protected static boolean isOnline; private static void startDuke(){ + isOnline = true; System.out.println(Logo.logo +Logo.divider + "Hello! I'm Duke\n" + " What can I do for you?\n" + Logo.divider); } @@ -20,32 +17,13 @@ private static void endDuke(){ public static void main(String[] args) { startDuke(); Scanner in = new Scanner(System.in); - ArrayList list = new ArrayList(); + ArrayList list = new ArrayList<>(); ListManager listManager = new ListManager(list); - while(true) { - String echo = in.nextLine(); - String echoLower = echo.toLowerCase(); - if (echoLower.equals(COMMAND_EXIT)) { - endDuke(); - break; - }else if(echoLower.equals(COMMAND_VIEW_LIST)) { - listManager.printList(); - }else if(echoLower.startsWith(COMMAND_COMPLETE_TASK)) { - listManager.completeTask(); - }else if(echoLower.startsWith(COMMAND_ADD_EVENT)){ - int startOfTime = echoLower.indexOf("/"); - String description = echoLower.substring(6,startOfTime); - String time = echoLower.substring(startOfTime + 1); - listManager.addEvent(description,time); - }else if (echoLower.startsWith(COMMAND_ADD_TODO)){ - String description = echoLower.substring(5); - listManager.addTodo(description); - }else if(echoLower.startsWith(COMMAND_ADD_DEADLINE)){ - int startOfDeadline = echoLower.indexOf("/"); - String description = echoLower.substring(9,startOfDeadline); - String deadline = echoLower.substring(startOfDeadline + 1); - listManager.addDeadline(description,deadline); - } + while(isOnline) { + String userInput = in.nextLine().toLowerCase().trim(); + InputHandler inputManager = new InputHandler(userInput, listManager); + inputManager.handleInput(); } + endDuke(); } } diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 2cda9cdbc..e6bb1591f 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -1,7 +1,7 @@ public class Event extends Task{ private static final String TASK_SYMBOL = "[E]"; - protected String startTime; + private String startTime; public Event(String description, String startTime){ super(description); diff --git a/src/main/java/InputHandler.java b/src/main/java/InputHandler.java new file mode 100644 index 000000000..7d4f8c1de --- /dev/null +++ b/src/main/java/InputHandler.java @@ -0,0 +1,123 @@ +public class InputHandler { + + private static final String COMMAND_EXIT = "bye"; + private static final String COMMAND_VIEW_LIST = "list"; + private static final String COMMAND_COMPLETE_TASK = "done"; + private static final String COMMAND_ADD_TODO = "todo"; + private static final String COMMAND_ADD_EVENT = "event"; + private static final String COMMAND_ADD_DEADLINE = "deadline"; + private static final String EVENT_TIME = "at"; + private static final String DEADLINE_DATE = "by"; + + private String description; + private final ListManager listManager; + + public InputHandler(String description, ListManager listManager){ + this.description = description; + this.listManager = listManager; + } + + private String taskCategory(String userInput){ + if(userInput.startsWith(COMMAND_EXIT)){ + return COMMAND_EXIT; + } + if(userInput.startsWith(COMMAND_VIEW_LIST)) { + return COMMAND_VIEW_LIST; + } + if(userInput.startsWith(COMMAND_ADD_DEADLINE)){ + return COMMAND_ADD_DEADLINE; + } + if (userInput.startsWith(COMMAND_ADD_TODO)) { + return COMMAND_ADD_TODO; + } + if(userInput.startsWith(COMMAND_ADD_EVENT)){ + return COMMAND_ADD_EVENT; + } + if (userInput.startsWith(COMMAND_COMPLETE_TASK)){ + return COMMAND_COMPLETE_TASK; + } + return null; + } + + private void handleEvent(String eventInput){ + String taskDescription = eventInput.replaceFirst(COMMAND_ADD_EVENT,"").trim(); + int startOfEventTime = taskDescription.indexOf(EVENT_TIME); + String eventDescription = taskDescription.substring(0,startOfEventTime).trim(); + String eventTime = taskDescription.replaceFirst(eventDescription,"").replaceFirst(EVENT_TIME,"").strip(); + listManager.addEvent(eventDescription,eventTime); + } + + private void handleDeadline(String deadlineInput){ + String taskDescription = deadlineInput.replaceFirst(COMMAND_ADD_DEADLINE,"").trim(); + int startOfDeadlineDate = taskDescription.indexOf(DEADLINE_DATE); + String deadlineDescription = taskDescription.substring(0,startOfDeadlineDate).trim(); + String deadlineDate = taskDescription.replaceFirst(deadlineDescription,"").replaceFirst(DEADLINE_DATE,"").strip(); + listManager.addDeadline(deadlineDescription,deadlineDate); + } + + private void handleToDo(String toDoInput){ + String taskDescription = toDoInput.replaceFirst(COMMAND_ADD_TODO,"").trim(); + listManager.addTodo(taskDescription); + } + + private void handleDone(String userInput){ + String taskDone = userInput.replaceFirst(COMMAND_COMPLETE_TASK,"").trim(); + String[] taskDoneArray = taskDone.split(","); + for (String s: taskDoneArray) { + int taskDoneIndex = Integer.parseInt(s); + listManager.completeTask(taskDoneIndex - 1); + } + } + + public void handleInput(){ + boolean isAddingTask = false; + description = description.replaceAll("/",""); + if(description.contains(COMMAND_ADD_DEADLINE)){ + isAddingTask = true; + description = description.replaceAll(COMMAND_ADD_DEADLINE,"/"+ COMMAND_ADD_DEADLINE); + } + if(description.contains(COMMAND_ADD_TODO)){ + isAddingTask = true; + description = description.replaceAll(COMMAND_ADD_TODO,"/"+ COMMAND_ADD_TODO); + } + if(description.contains(COMMAND_ADD_EVENT)){ + isAddingTask = true; + description = description.replaceAll(COMMAND_ADD_EVENT,"/"+ COMMAND_ADD_EVENT); + } + if(isAddingTask) { + String[] commandList = description.split("/"); + for (int i = 1; i < commandList.length; i++) { + handleCommand(commandList[i]); + } + }else{ + handleCommand(description); + } + } + + private void handleCommand(String userInput){ + String inputCommand = taskCategory(userInput); + switch(inputCommand){ + case COMMAND_EXIT: + Duke.isOnline = false; + break; + case COMMAND_VIEW_LIST: + listManager.printList(); + break; + case COMMAND_COMPLETE_TASK: + handleDone(userInput); + listManager.printList(); + System.out.println(Logo.divider); + break; + case COMMAND_ADD_EVENT: + handleEvent(userInput); + break; + case COMMAND_ADD_TODO: + handleToDo(userInput); + break; + case COMMAND_ADD_DEADLINE: + handleDeadline(userInput); + break; + } + } +} + diff --git a/src/main/java/ListManager.java b/src/main/java/ListManager.java index bcc82ef6f..f51052ec4 100644 --- a/src/main/java/ListManager.java +++ b/src/main/java/ListManager.java @@ -1,7 +1,7 @@ import java.util.ArrayList; -public class ListManager { - private static ArrayList list; +public class ListManager implements TaskList{ + private final ArrayList list; public ListManager(ArrayList list){ this.list = list; @@ -14,10 +14,6 @@ public void printList(){ } } - public void completeTask(){ - printList(); - } - private void printAddItem(Task t){ System.out.println("Got it. I've added this task: " + System.lineSeparator() + t.toString() + System.lineSeparator() + "Now you have " @@ -41,4 +37,10 @@ public void addDeadline(String description, String deadline){ list.add(t); printAddItem(t); } + + public void completeTask(int t){ + Task doneTask = list.get(t); + doneTask.setDone(); + System.out.println(Logo.divider + "Nice! I've marked this task as done: " + doneTask.getDescription()); + } } diff --git a/src/main/java/Logo.java b/src/main/java/Logo.java index 4523ebf8c..30dd16eea 100644 --- a/src/main/java/Logo.java +++ b/src/main/java/Logo.java @@ -1,10 +1,12 @@ public class Logo { public static final String divider = "____________________________________________________________\n"; + public static final String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" + "| | | | | | | |/ / _ \\\n" + "| |_| | |_| | < __/\n" + "|____/ \\__,_|_|\\_\\___|\n"; + public static final String bye ="_______________.___.___________\n" + "\\______ \\__ | |\\_ _____/\n" + " | | _// | | | __)_ \n" + diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 9576f8c41..4df0d0fbf 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -1,22 +1,26 @@ public class Task { private static final String completeStatusIcon = "[X]"; private static final String incompleteStatusIcon = "[ ]"; - protected String description; - protected boolean isDone; + private String description; + private boolean isDone; public Task(String description){ this.description = description; this.isDone = false; } + public void setDone(){ isDone = true; } + public String getDescription(){ return description; } + public String getStatusIcon(){ return(isDone ? completeStatusIcon : incompleteStatusIcon); } + public String toString(){ return getStatusIcon() + description; } diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java new file mode 100644 index 000000000..502f4a726 --- /dev/null +++ b/src/main/java/TaskList.java @@ -0,0 +1,7 @@ +public interface TaskList { + void printList(); + void addTodo(String description); + void addEvent(String description, String time); + void addDeadline(String description, String deadline); + void completeTask(int t); +} From 37abf0dd2561355b6d0e8cb607de99579c8f455c Mon Sep 17 00:00:00 2001 From: wingho2 Date: Mon, 6 Sep 2021 02:11:03 +0800 Subject: [PATCH 08/62] Added a way to print words like what was printed for duke but based on user input Added a class artbot that use 2D array to create and merge the string to form the shape of letters --- src/main/java/ArtBot.java | 150 ++++++++++++++++++++++++ src/main/java/InputHandler.java | 1 + src/main/java/Logo.java | 189 ++++++++++++++++++++++++++++++- src/main/java/Task.java | 4 +- src/main/java/TaskInterface.java | 5 + 5 files changed, 342 insertions(+), 7 deletions(-) create mode 100644 src/main/java/ArtBot.java create mode 100644 src/main/java/TaskInterface.java diff --git a/src/main/java/ArtBot.java b/src/main/java/ArtBot.java new file mode 100644 index 000000000..b657543e5 --- /dev/null +++ b/src/main/java/ArtBot.java @@ -0,0 +1,150 @@ +import java.util.ArrayList; +import java.util.Arrays; + +public class ArtBot { + + private final String userInput; + + public ArtBot(String userInput){ + this.userInput = userInput; + } + + private String[] getLogo(String letter){ + String[] letterArt; + switch(letter) { + case "A": + letterArt = Logo.A.split("\n"); + break; + case "B": + letterArt = Logo.B.split("\n"); + break; + case "C": + letterArt = Logo.C.split("\n"); + break; + case "D": + letterArt = Logo.D.split("\n"); + break; + case "E": + letterArt = Logo.E.split("\n"); + break; + case "F": + letterArt = Logo.F.split("\n"); + break; + case "G": + letterArt = Logo.G.split("\n"); + break; + case "H": + letterArt = Logo.H.split("\n"); + break; + case "I": + letterArt = Logo.I.split("\n"); + break; + case "J": + letterArt = Logo.J.split("\n"); + break; + case "K": + letterArt = Logo.K.split("\n"); + break; + case "L": + letterArt = Logo.L.split("\n"); + break; + case "M": + letterArt = Logo.M.split("\n"); + break; + case "N": + letterArt = Logo.N.split("\n"); + break; + case "O": + letterArt = Logo.O.split("\n"); + break; + case "P": + letterArt = Logo.P.split("\n"); + break; + case "Q": + letterArt = Logo.Q.split("\n"); + break; + case "R": + letterArt = Logo.R.split("\n"); + break; + case "S": + letterArt = Logo.S.split("\n"); + break; + case "T": + letterArt = Logo.T.split("\n"); + break; + case "U": + letterArt = Logo.U.split("\n"); + break; + case "V": + letterArt = Logo.V.split("\n"); + break; + case "W": + letterArt = Logo.W.split("\n"); + break; + case "X": + letterArt = Logo.X.split("\n"); + break; + case "Y": + letterArt = Logo.Y.split("\n"); + break; + case "Z": + letterArt = Logo.Z.split("\n"); + break; + case "0": + letterArt = Logo.ZERO.split("\n"); + break; + case "1": + letterArt = Logo.One.split("\n"); + break; + case "2": + letterArt = Logo.Two.split("\n"); + break; + case "3": + letterArt = Logo.THREE.split("\n"); + break; + case "4": + letterArt = Logo.FOUR.split("\n"); + break; + case "5": + letterArt = Logo.FIVE.split("\n"); + break; + case "6": + letterArt = Logo.SIX.split("\n"); + break; + case "7": + letterArt = Logo.SEVEN.split("\n"); + break; + case "8": + letterArt = Logo.EIGHT.split("\n"); + break; + case "9": + letterArt = Logo.NINE.split("\n"); + break; + default: + letterArt = null; + break; + } + return letterArt; + } + + public void drawArt(){ + String[] charArray = userInput.split("(?!^)"); + ArrayList artArray = new ArrayList<>(); + String[] mergeString = new String[5]; + for(String s:charArray){ + String[] letterArtForm = getLogo(s); + artArray.add(letterArtForm); + } + for(int i = 0; i < 5; i++){ + StringBuilder sb = new StringBuilder(); + for(int j = 0; j < artArray.size(); j ++){ + String temp = artArray.get(j)[i]; + sb.append(temp); + } + mergeString[i] = sb.toString(); + } + for(int i = 0; i < 5; i++){ + System.out.println(mergeString[i]); + } + } +} diff --git a/src/main/java/InputHandler.java b/src/main/java/InputHandler.java index 7d4f8c1de..0c2238f4f 100644 --- a/src/main/java/InputHandler.java +++ b/src/main/java/InputHandler.java @@ -8,6 +8,7 @@ public class InputHandler { private static final String COMMAND_ADD_DEADLINE = "deadline"; private static final String EVENT_TIME = "at"; private static final String DEADLINE_DATE = "by"; + private static final String COMMAND_HELP = "!"; private String description; private final ListManager listManager; diff --git a/src/main/java/Logo.java b/src/main/java/Logo.java index 30dd16eea..ac4ae9780 100644 --- a/src/main/java/Logo.java +++ b/src/main/java/Logo.java @@ -1,16 +1,195 @@ public class Logo { public static final String divider = "____________________________________________________________\n"; - public static final String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" + "| | | | | | | |/ / _ \\\n" + "| |_| | |_| | < __/\n" + "|____/ \\__,_|_|\\_\\___|\n"; - public static final String bye ="_______________.___.___________\n" + "\\______ \\__ | |\\_ _____/\n" + " | | _// | | | __)_ \n" + " | | \\\\____ | | \\\n" + - " |______ // ______|/_______ /\n" + - " \\/ \\/ \\/"; -} + " |________// ______|/_________/\n"; + public static final String A = " _____ \n" + + " / _ \\ \n" + + " / /_\\ \\ \n" + + "/ | \\\n" + + "\\____|____/\n"; + public static final String B = "__________ \n" + + "\\______ \\\n" + + " | | _/\n" + + " | | \\\n" + + " |________/\n"; + public static final String C = "_________ \n" + + "\\_ ___ \\ \n" + + "/ \\ \\/ \n" + + "\\ \\____\n" + + " \\________/\n"; + public static final String D = "________ \n" + + "\\______ \\ \n" + + " | | \\ \n" + + " | ` \\\n" + + "/_________/\n"; + public static final String E = "___________\n" + + "\\_ _____/\n" + + " | __)_ \n" + + " | \\\n" + + "/_________/"; + public static final String F = "___________\n" + + "\\_ _____/\n" + + " | __) \n" + + " | \\ \n" + + " \\_____/ \n"; + public static final String G = " ________ \n" + + " / _____/ \n" + + "/ \\ ___ \n" + + "\\ \\_\\ \\\n" + + " \\________/"; + public static final String H = " ___ ___ \n" + + " / | \\ \n" + + "/ ~ \\\n" + + "\\ Y /\n" + + " \\___|___/ "; + public static final String I = ".___ \n" + + "| |\n" + + "| |\n" + + "| |\n" + + "|___|"; + public static final String J = " ____.\n" + + " | |\n" + + " | |\n" + + "/\\__| |\n" + + "\\________|"; + public static final String K = " ____ __.\n" + + "| |/ _|\n" + + "| < \n" + + "| | \\ \n" + + "|____|___\\"; + public static final String L = ".____ \n" + + "| | \n" + + "| | \n" + + "| |___ \n" + + "|________\\"; + public static final String M = " _____ \n" + + " / \\ \n" + + " / \\ / \\ \n" + + "/ Y \\\n" + + "\\____|____/"; + public static final String N = " _______ \n" + + " \\ \\ \n" + + " / | \\ \n" + + "/ | \\\n" + + "\\____|____/"; + public static final String O = "________ \n" + + "\\_____ \\ \n" + + " / | \\ \n" + + "/ | \\\n" + + "\\_______ /"; + public static final String P = "__________ \n" + + "\\______ \\\n" + + " | ___/\n" + + " | | \n" + + " |____| "; + public static final String Q = "________ \n" + + "\\_____ \\ \n" + + " / / \\ \\ \n" + + "/ \\_/. \\\n" + + "\\_____\\ \\_/"; + public static final String R = "__________ \n" + + "\\______ \\\n" + + " | _/\n" + + " | | \\\n" + + " |____|___/"; + public static final String S = " _________\n" + + " / _____/\n" + + " \\_____ \\ \n" + + " / \\\n" + + "/_________/"; + public static final String T = "___________\n" + + "\\__ ___/\n" + + " | | \n" + + " | | \n" + + " |____| "; + public static final String U = " ____ ___ \n" + + "| | \\\n" + + "| | /\n" + + "| | / \n" + + "|______/ "; + public static final String V = "____ ____\n" + + "\\ \\ / /\n" + + " \\ Y / \n" + + " \\ / \n" + + " \\___/ "; + public static final String W = " __ __ \n" + + "/ \\ / \\\n" + + "\\ \\/\\/ /\n" + + " \\ / \n" + + " \\__/\\ / "; + public static final String X = "____ ___\n" + + "\\ \\/ /\n" + + " \\ / \n" + + " / \\ \n" + + "/___/\\ \\"; + public static final String Y = "_____.___.\n" + + "\\__ | |\n" + + " / | |\n" + + " \\____ |\n" + + " / ______|"; + public static final String Z = "__________\n" + + "\\____ /\n" + + " / / \n" + + " / /_ \n" + + "/_______ \\"; + public static final String ZERO = "_______ \n" + + "\\ _ \\ \n" + + "/ /_\\ \\ \n" + + "\\ \\_/ \\\n" + + " \\______/"; + public static final String One = " ____ \n" + + "/_ |\n" + + " | |\n" + + " | |\n" + + " |___|"; + public static final String Two = "________ \n" + + "\\_____ \\ \n" + + " / ____/ \n" + + "/ \\ \n" + + "\\________\\"; + public static final String THREE = "________ \n" + + "\\_____ \\ \n" + + " _(__ < \n" + + " / \\\n" + + "/________/"; + public static final String FOUR = " _____ \n" + + " / | | \n" + + " / | |_\n" + + "/ ^ /\n" + + "\\____ |"; + public static final String FIVE = " .________\n" + + " | ____/\n" + + " |____ \\ \n" + + " / \\\n" + + "/________/"; + public static final String SIX = " ________\n" + + " / _____/\n" + + "/ __ \\ \n" + + "\\ |__\\ \\\n" + + " \\_______/"; + public static final String SEVEN = "_________ \n" + + "\\______ \\\n" + + " / /\n" + + " / / \n" + + " /____/ "; + public static final String EIGHT = " ______ \n" + + " / __ \\ \n" + + " > < \n" + + "/ -- \\\n" + + "\\________/"; + public static final String NINE = " ________ \n" + + "/ __ \\\n" + + "\\____ /\n" + + " / / \n" + + " /____/"; + + +} \ No newline at end of file diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 4df0d0fbf..adffb4c36 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -1,7 +1,7 @@ -public class Task { +public class Task implements TaskInterface{ private static final String completeStatusIcon = "[X]"; private static final String incompleteStatusIcon = "[ ]"; - private String description; + private final String description; private boolean isDone; public Task(String description){ diff --git a/src/main/java/TaskInterface.java b/src/main/java/TaskInterface.java new file mode 100644 index 000000000..7c68d8eaa --- /dev/null +++ b/src/main/java/TaskInterface.java @@ -0,0 +1,5 @@ +public interface TaskInterface { + void setDone(); + String getDescription(); + String getStatusIcon(); +} From 1e6963b2786b175260af0c15230000bdcb1e7183 Mon Sep 17 00:00:00 2001 From: wingho2 Date: Mon, 6 Sep 2021 19:00:47 +0800 Subject: [PATCH 09/62] Added testing --- src/main/java/ArtBot.java | 11 +++--- src/main/java/ArtInterface.java | 3 ++ src/main/java/CommandInterface.java | 3 ++ src/main/java/CommandManager.java | 55 +++++++++++++++++++++++++++++ src/main/java/Duke.java | 15 +++++--- src/main/java/InputHandler.java | 51 ++++++++++++++++++++------ src/main/java/InputInterface.java | 3 ++ src/main/java/ListManager.java | 42 +++++++++++++++++++--- src/main/java/TaskList.java | 5 ++- text-ui-test/EXPECTED.txt | 7 ++++ text-ui-test/input.txt | 10 ++++++ text-ui-test/runtest.bat | 6 ++-- 12 files changed, 182 insertions(+), 29 deletions(-) create mode 100644 src/main/java/ArtInterface.java create mode 100644 src/main/java/CommandInterface.java create mode 100644 src/main/java/CommandManager.java create mode 100644 src/main/java/InputInterface.java create mode 100644 text-ui-test/EXPECTED.txt diff --git a/src/main/java/ArtBot.java b/src/main/java/ArtBot.java index b657543e5..16cc752c1 100644 --- a/src/main/java/ArtBot.java +++ b/src/main/java/ArtBot.java @@ -1,7 +1,6 @@ import java.util.ArrayList; -import java.util.Arrays; -public class ArtBot { +public class ArtBot implements ArtInterface{ private final String userInput; @@ -132,13 +131,13 @@ public void drawArt(){ ArrayList artArray = new ArrayList<>(); String[] mergeString = new String[5]; for(String s:charArray){ - String[] letterArtForm = getLogo(s); - artArray.add(letterArtForm); + String[] letterInArtForm = getLogo(s); + artArray.add(letterInArtForm); } for(int i = 0; i < 5; i++){ StringBuilder sb = new StringBuilder(); - for(int j = 0; j < artArray.size(); j ++){ - String temp = artArray.get(j)[i]; + for (String[] strings : artArray) { + String temp = strings[i]; sb.append(temp); } mergeString[i] = sb.toString(); diff --git a/src/main/java/ArtInterface.java b/src/main/java/ArtInterface.java new file mode 100644 index 000000000..28950776e --- /dev/null +++ b/src/main/java/ArtInterface.java @@ -0,0 +1,3 @@ +public interface ArtInterface { + void drawArt(); +} diff --git a/src/main/java/CommandInterface.java b/src/main/java/CommandInterface.java new file mode 100644 index 000000000..f406dc728 --- /dev/null +++ b/src/main/java/CommandInterface.java @@ -0,0 +1,3 @@ +public interface CommandInterface { + void handleCommand(); +} diff --git a/src/main/java/CommandManager.java b/src/main/java/CommandManager.java new file mode 100644 index 000000000..4d3f9e57a --- /dev/null +++ b/src/main/java/CommandManager.java @@ -0,0 +1,55 @@ +public class CommandManager implements CommandInterface{ + + private static final String COMMAND_HELP = "!help"; + private static final String COMMAND_LIST_HELP = "!list"; + private static final String COMMAND_EVENT_HELP = "!event"; + private static final String COMMAND_DEADLINE_HELP = "!deadline"; + private static final String COMMAND_ECHO = "!echo"; + private static final String MESSAGE_HELP = "List of Commands:\n" + + " echo - Repeat whatever was typed - !echo to repeat in art form\n" + + " list - Display List - !list for details\n" + + " todo - Add ToDo Task\n" + + " event - Add Event Task - !event for details\n" + + " deadline - Add Deadline Task - !deadline for details\n" + + " bye - Shut Down"; + private static final String MESSAGE_LIST_HELP = "list displays all tasks\n" + + "list todo displays all todo tasks\n" + + "list event displays all event tasks\n" + + "list deadline displays all deadline tasks\n"; + private static final String MESSAGE_EVENT_HELP = "event command requires a timing indicated using \"at\" [timing]"; + private static final String MESSAGE_DEADLINE_HELP = "deadline command requires a end time indicated using \"by\"[end time]"; + + private final String description; + + public CommandManager(String description){ + this.description = description; + } + + private void handleArtCommand(){ + String removeCommand = description.replaceFirst(COMMAND_ECHO,"").trim().toUpperCase(); + System.out.println(removeCommand); + ArtBot artBot = new ArtBot(removeCommand); + artBot.drawArt(); + } + + public void handleCommand(){ + if(description.startsWith(COMMAND_ECHO)){ + handleArtCommand(); + return; + } + switch(description) { + case COMMAND_HELP: + System.out.println(MESSAGE_HELP); + break; + case COMMAND_LIST_HELP: + System.out.println(MESSAGE_LIST_HELP); + break; + case COMMAND_EVENT_HELP: + System.out.println(MESSAGE_EVENT_HELP); + break; + case COMMAND_DEADLINE_HELP: + System.out.println(MESSAGE_DEADLINE_HELP); + break; + } + } +} diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index acf1a77a3..e1d922892 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -2,16 +2,18 @@ import java.util.ArrayList; public class Duke { + private static final String MESSAGE_HI = "Hello! I'm Duke\n" + "What can I do for you?\n" + "!help for Command List\n"; + private static final String MESSAGE_BYE = "Bye. Hope to see you again soon!\n"; protected static boolean isOnline; private static void startDuke(){ isOnline = true; - System.out.println(Logo.logo +Logo.divider + "Hello! I'm Duke\n" + " What can I do for you?\n" + Logo.divider); + System.out.println(Logo.logo +Logo.divider + MESSAGE_HI + Logo.divider); } private static void endDuke(){ - System.out.println(Logo.divider + "Bye. Hope to see you again soon!\n" + Logo.divider + Logo.bye); + System.out.println(Logo.divider + MESSAGE_BYE + Logo.divider + Logo.bye); } public static void main(String[] args) { @@ -21,8 +23,13 @@ public static void main(String[] args) { ListManager listManager = new ListManager(list); while(isOnline) { String userInput = in.nextLine().toLowerCase().trim(); - InputHandler inputManager = new InputHandler(userInput, listManager); - inputManager.handleInput(); + if(userInput.startsWith("!")){ + CommandManager commandManager = new CommandManager(userInput); + commandManager.handleCommand(); + }else { + InputHandler inputManager = new InputHandler(userInput, listManager); + inputManager.handleInput(); + } } endDuke(); } diff --git a/src/main/java/InputHandler.java b/src/main/java/InputHandler.java index 0c2238f4f..4cc6398dd 100644 --- a/src/main/java/InputHandler.java +++ b/src/main/java/InputHandler.java @@ -1,14 +1,16 @@ -public class InputHandler { +import java.util.Objects; + +public class InputHandler implements InputInterface{ private static final String COMMAND_EXIT = "bye"; private static final String COMMAND_VIEW_LIST = "list"; + private static final String COMMAND_ECHO = "echo"; private static final String COMMAND_COMPLETE_TASK = "done"; private static final String COMMAND_ADD_TODO = "todo"; private static final String COMMAND_ADD_EVENT = "event"; private static final String COMMAND_ADD_DEADLINE = "deadline"; private static final String EVENT_TIME = "at"; private static final String DEADLINE_DATE = "by"; - private static final String COMMAND_HELP = "!"; private String description; private final ListManager listManager; @@ -28,15 +30,18 @@ private String taskCategory(String userInput){ if(userInput.startsWith(COMMAND_ADD_DEADLINE)){ return COMMAND_ADD_DEADLINE; } - if (userInput.startsWith(COMMAND_ADD_TODO)) { + if(userInput.startsWith(COMMAND_ADD_TODO)) { return COMMAND_ADD_TODO; } if(userInput.startsWith(COMMAND_ADD_EVENT)){ return COMMAND_ADD_EVENT; } - if (userInput.startsWith(COMMAND_COMPLETE_TASK)){ + if(userInput.startsWith(COMMAND_COMPLETE_TASK)){ return COMMAND_COMPLETE_TASK; } + if (userInput.startsWith(COMMAND_ECHO)){ + return COMMAND_ECHO; + } return null; } @@ -57,19 +62,37 @@ private void handleDeadline(String deadlineInput){ } private void handleToDo(String toDoInput){ - String taskDescription = toDoInput.replaceFirst(COMMAND_ADD_TODO,"").trim(); - listManager.addTodo(taskDescription); + String removeCommand = toDoInput.replaceFirst(COMMAND_ADD_TODO,"").trim(); + listManager.addTodo(removeCommand); } private void handleDone(String userInput){ - String taskDone = userInput.replaceFirst(COMMAND_COMPLETE_TASK,"").trim(); - String[] taskDoneArray = taskDone.split(","); + String removeCommand = userInput.replaceFirst(COMMAND_COMPLETE_TASK,"").trim(); + String[] taskDoneArray = removeCommand.split(","); for (String s: taskDoneArray) { int taskDoneIndex = Integer.parseInt(s); listManager.completeTask(taskDoneIndex - 1); } } + private void handleEcho(String userInput){ + String removeCommand = userInput.replaceFirst(COMMAND_ECHO,"").trim(); + System.out.println(removeCommand); + } + + private void handleList(String userInput){ + String removeCommand = userInput.replaceFirst(COMMAND_VIEW_LIST,"").trim(); + if(removeCommand.contains(COMMAND_ADD_TODO)){ + listManager.printToDo(); + }else if(removeCommand.contains(COMMAND_ADD_EVENT)) { + listManager.printEvent(); + }else if(removeCommand.contains(COMMAND_ADD_DEADLINE)){ + listManager.printDeadline(); + }else { + listManager.printList(); + } + } + public void handleInput(){ boolean isAddingTask = false; description = description.replaceAll("/",""); @@ -85,6 +108,9 @@ public void handleInput(){ isAddingTask = true; description = description.replaceAll(COMMAND_ADD_EVENT,"/"+ COMMAND_ADD_EVENT); } + if(description.startsWith(COMMAND_VIEW_LIST)){ + isAddingTask = false; + } if(isAddingTask) { String[] commandList = description.split("/"); for (int i = 1; i < commandList.length; i++) { @@ -97,12 +123,12 @@ public void handleInput(){ private void handleCommand(String userInput){ String inputCommand = taskCategory(userInput); - switch(inputCommand){ + switch(Objects.requireNonNull(inputCommand)){ case COMMAND_EXIT: Duke.isOnline = false; break; case COMMAND_VIEW_LIST: - listManager.printList(); + handleList(userInput); break; case COMMAND_COMPLETE_TASK: handleDone(userInput); @@ -118,6 +144,11 @@ private void handleCommand(String userInput){ case COMMAND_ADD_DEADLINE: handleDeadline(userInput); break; + case COMMAND_ECHO: + handleEcho(userInput); + break; + default: + break; } } } diff --git a/src/main/java/InputInterface.java b/src/main/java/InputInterface.java new file mode 100644 index 000000000..75f6f2fb9 --- /dev/null +++ b/src/main/java/InputInterface.java @@ -0,0 +1,3 @@ +public interface InputInterface { + void handleInput(); +} diff --git a/src/main/java/ListManager.java b/src/main/java/ListManager.java index f51052ec4..63b32c664 100644 --- a/src/main/java/ListManager.java +++ b/src/main/java/ListManager.java @@ -1,6 +1,12 @@ import java.util.ArrayList; public class ListManager implements TaskList{ + + private static final String MESSAGE_TASK_ADDED = "Got it. I've added this task: "; + private static final String MESSAGE_TASK_COMPLETE = "Nice! I've marked this task as done: "; + private static final String MESSAGE_TASK_IN_LIST = " tasks in the list."; + private static final String MESSAGE_TASK_NOW = "Now you have "; + private static final String MESSAGE_SPACER = ". "; private final ArrayList list; public ListManager(ArrayList list){ @@ -10,14 +16,40 @@ public ListManager(ArrayList list){ public void printList(){ for(int i = 0; i < list.size(); i++){ int itemIndex= i + 1; - System.out.println(itemIndex + ". " + list.get(i).toString()); + System.out.println(itemIndex + MESSAGE_SPACER + list.get(i).toString()); + } + } + + public void printToDo(){ + for(int i = 0; i < list.size(); i++){ + int itemIndex= i + 1; + if(list.get(i) instanceof ToDo ) { + System.out.println(itemIndex + MESSAGE_SPACER + list.get(i).toString()); + } + } + } + + public void printEvent(){ + for(int i = 0; i < list.size(); i++){ + int itemIndex= i + 1; + if(list.get(i) instanceof Event ) { + System.out.println(itemIndex + MESSAGE_SPACER + list.get(i).toString()); + } + } + } + + public void printDeadline(){ + for(int i = 0; i < list.size(); i++){ + int itemIndex= i + 1; + if(list.get(i) instanceof Deadline ) { + System.out.println(itemIndex + MESSAGE_SPACER + list.get(i).toString()); + } } } private void printAddItem(Task t){ - System.out.println("Got it. I've added this task: " + System.lineSeparator() - + t.toString() + System.lineSeparator() + "Now you have " - + list.size() +" tasks in the list."); + System.out.println(MESSAGE_TASK_ADDED + System.lineSeparator() + t.toString() + System.lineSeparator() + MESSAGE_TASK_NOW + + list.size() + MESSAGE_TASK_IN_LIST); } public void addTodo(String description){ @@ -41,6 +73,6 @@ public void addDeadline(String description, String deadline){ public void completeTask(int t){ Task doneTask = list.get(t); doneTask.setDone(); - System.out.println(Logo.divider + "Nice! I've marked this task as done: " + doneTask.getDescription()); + System.out.println(Logo.divider + MESSAGE_TASK_COMPLETE + doneTask.getDescription()); } } diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java index 502f4a726..13378c61f 100644 --- a/src/main/java/TaskList.java +++ b/src/main/java/TaskList.java @@ -1,7 +1,10 @@ public interface TaskList { void printList(); + void printToDo(); + void printEvent(); + void printDeadline(); void addTodo(String description); void addEvent(String description, String time); - void addDeadline(String description, String deadline); + void addDeadline(String description, String deadline); void completeTask(int t); } diff --git a/text-ui-test/EXPECTED.txt b/text-ui-test/EXPECTED.txt new file mode 100644 index 000000000..657e74f6e --- /dev/null +++ b/text-ui-test/EXPECTED.txt @@ -0,0 +1,7 @@ +Hello from + ____ _ +| _ \ _ _| | _____ +| | | | | | | |/ / _ \ +| |_| | |_| | < __/ +|____/ \__,_|_|\_\___| + diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index e69de29bb..3e6015cc7 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -0,0 +1,10 @@ +echo Hi +!echo hi +todo watch et1231 livestream todo watch hankyuu livestream +todo watch haxxnini livestream +deadline reach mystic by this season event game session at 10pm +!help +list +done 1,2,3 +list +bye \ No newline at end of file diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 087374464..c5ec8c787 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -4,7 +4,7 @@ REM create bin directory if it doesn't exist if not exist ..\bin mkdir ..\bin REM delete output from previous run -if exist ACTUAL.TXT del ACTUAL.TXT +del ACTUAL.txt REM compile the code into the bin folder javac -cp ..\src\main\java -Xlint:none -d ..\bin ..\src\main\java\*.java @@ -15,7 +15,7 @@ IF ERRORLEVEL 1 ( REM no error here, errorlevel == 0 REM run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT -java -classpath ..\bin Duke < input.txt > ACTUAL.TXT +java -classpath ..\bin Duke < input.txt > ACTUAL.txt REM compare the output to the expected output -FC ACTUAL.TXT EXPECTED.TXT +FC ACTUAL.txt EXPECTED.txt \ No newline at end of file From 2f491b7d77ac50365a153a949c67e9c07e63afa9 Mon Sep 17 00:00:00 2001 From: wingho2 Date: Tue, 7 Sep 2021 02:44:41 +0800 Subject: [PATCH 10/62] Add a lot of exceptions to prevent any errors --- src/main/java/ArtBot.java | 5 +- src/main/java/ArtInterface.java | 2 +- src/main/java/CommandException.java | 12 +++ src/main/java/CommandManager.java | 6 +- src/main/java/Duke.java | 20 ++-- src/main/java/ErrorList.java | 17 ++++ src/main/java/InputHandler.java | 139 +++++++++++++++++++++------- src/main/java/InputInterface.java | 2 +- src/main/java/ListManager.java | 45 ++++++++- src/main/java/Logo.java | 1 + src/main/java/TaskList.java | 11 ++- 11 files changed, 203 insertions(+), 57 deletions(-) create mode 100644 src/main/java/CommandException.java create mode 100644 src/main/java/ErrorList.java diff --git a/src/main/java/ArtBot.java b/src/main/java/ArtBot.java index 16cc752c1..8d8881f53 100644 --- a/src/main/java/ArtBot.java +++ b/src/main/java/ArtBot.java @@ -126,12 +126,15 @@ private String[] getLogo(String letter){ return letterArt; } - public void drawArt(){ + public void drawArt() throws CommandException{ String[] charArray = userInput.split("(?!^)"); ArrayList artArray = new ArrayList<>(); String[] mergeString = new String[5]; for(String s:charArray){ String[] letterInArtForm = getLogo(s); + if(letterInArtForm == null){ + throw new CommandException(ErrorList.ERROR_LETTER_NOT_FOUND); + } artArray.add(letterInArtForm); } for(int i = 0; i < 5; i++){ diff --git a/src/main/java/ArtInterface.java b/src/main/java/ArtInterface.java index 28950776e..2e90c19a9 100644 --- a/src/main/java/ArtInterface.java +++ b/src/main/java/ArtInterface.java @@ -1,3 +1,3 @@ public interface ArtInterface { - void drawArt(); + void drawArt() throws CommandException; } diff --git a/src/main/java/CommandException.java b/src/main/java/CommandException.java new file mode 100644 index 000000000..480282fde --- /dev/null +++ b/src/main/java/CommandException.java @@ -0,0 +1,12 @@ +public class CommandException extends Exception{ + + private String errorMessage; + + public CommandException(String errorMessage){ + this.errorMessage = errorMessage; + } + + public void handleException(){ + System.out.println(errorMessage); + } +} diff --git a/src/main/java/CommandManager.java b/src/main/java/CommandManager.java index 4d3f9e57a..62966822c 100644 --- a/src/main/java/CommandManager.java +++ b/src/main/java/CommandManager.java @@ -29,7 +29,11 @@ private void handleArtCommand(){ String removeCommand = description.replaceFirst(COMMAND_ECHO,"").trim().toUpperCase(); System.out.println(removeCommand); ArtBot artBot = new ArtBot(removeCommand); - artBot.drawArt(); + try { + artBot.drawArt(); + }catch (CommandException e){ + e.handleException(); + } } public void handleCommand(){ diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index e1d922892..c2200c182 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -9,7 +9,7 @@ public class Duke { private static void startDuke(){ isOnline = true; - System.out.println(Logo.logo +Logo.divider + MESSAGE_HI + Logo.divider); + System.out.println(Logo.logo +Logo.divider + MESSAGE_HI + Logo.dividerWithoutNewLine); } private static void endDuke(){ @@ -23,13 +23,17 @@ public static void main(String[] args) { ListManager listManager = new ListManager(list); while(isOnline) { String userInput = in.nextLine().toLowerCase().trim(); - if(userInput.startsWith("!")){ - CommandManager commandManager = new CommandManager(userInput); - commandManager.handleCommand(); - }else { - InputHandler inputManager = new InputHandler(userInput, listManager); - inputManager.handleInput(); - } + if (userInput.startsWith("!")) { + CommandManager commandManager = new CommandManager(userInput); + commandManager.handleCommand(); + } else { + InputHandler inputManager = new InputHandler(userInput, listManager); + try { + inputManager.handleInput(); + }catch(CommandException e){ + e.handleException(); + } + } } endDuke(); } diff --git a/src/main/java/ErrorList.java b/src/main/java/ErrorList.java new file mode 100644 index 000000000..bc3c06197 --- /dev/null +++ b/src/main/java/ErrorList.java @@ -0,0 +1,17 @@ +public class ErrorList { + public static final String ERROR_NULL = "☹ OOPS!!! Input cannot be empty."; + public static final String ERROR_UNKNOWN_COMMAND = "☹ OOPS!!! I'm sorry, but I don't know what that means :-(\n" + "" + + "Defaulting to Echo. Type !help to see the list of Commands"; + public static final String ERROR_EMPTY_LIST = "☹ OOPS!!! List is empty. Add tasks to the list."; + public static final String ERROR_EMPTY_TODO_LIST = "☹ OOPS!!! There is no To Do task in list. Add To Do tasks to the list."; + public static final String ERROR_EMPTY_EVENT_LIST = "☹ OOPS!!! There is no Event task in list. Add Events to the list."; + public static final String ERROR_EMPTY_DEADLINE_LIST = "☹ OOPS!!! There is no Deadline task in list. Add Deadlines to the list."; + public static final String ERROR_EMPTY_TODO_INPUT = "☹ OOPS!!! The description of a todo cannot be empty.\n"; + public static final String ERROR_EMPTY_EVENT_INPUT = "☹ OOPS!!! The description of a event cannot be empty.\n"; + public static final String ERROR_EMPTY_DEADLINE_INPUT = "☹ OOPS!!! The description of a deadline cannot be empty.\n"; + public static final String ERROR_EMPTY_ECHO_INPUT = "☹ OOPS!!! The description of a echo cannot be empty.\n"; + public static final String ERROR_EMPTY_EVENT_TIME = "☹ OOPS!!! The timing of a event cannot be empty.\n"; + public static final String ERROR_EMPTY_DEADLINE_TIME = "☹ OOPS!!! The due date of a deadline cannot be empty.\n"; + public static final String ERROR_DONE_TASK_NOT_IN_LIST ="☹ OOPS!!! Task done not found in list\n"; + public static final String ERROR_LETTER_NOT_FOUND = "☹ OOPS!!! Something went wrong. Do not input space or symbols.\n"; +} diff --git a/src/main/java/InputHandler.java b/src/main/java/InputHandler.java index 4cc6398dd..a615e29fb 100644 --- a/src/main/java/InputHandler.java +++ b/src/main/java/InputHandler.java @@ -45,24 +45,39 @@ private String taskCategory(String userInput){ return null; } - private void handleEvent(String eventInput){ + private void handleEvent(String eventInput) throws CommandException{ String taskDescription = eventInput.replaceFirst(COMMAND_ADD_EVENT,"").trim(); + if(!taskDescription.contains(EVENT_TIME)){ + throw new CommandException(ErrorList.ERROR_EMPTY_EVENT_TIME); + } int startOfEventTime = taskDescription.indexOf(EVENT_TIME); String eventDescription = taskDescription.substring(0,startOfEventTime).trim(); + if(eventDescription.isEmpty()){ + throw new CommandException(ErrorList.ERROR_EMPTY_EVENT_INPUT); + } String eventTime = taskDescription.replaceFirst(eventDescription,"").replaceFirst(EVENT_TIME,"").strip(); listManager.addEvent(eventDescription,eventTime); } - private void handleDeadline(String deadlineInput){ + private void handleDeadline(String deadlineInput) throws CommandException{ String taskDescription = deadlineInput.replaceFirst(COMMAND_ADD_DEADLINE,"").trim(); + if(!taskDescription.contains(DEADLINE_DATE)){ + throw new CommandException(ErrorList.ERROR_EMPTY_DEADLINE_TIME); + } int startOfDeadlineDate = taskDescription.indexOf(DEADLINE_DATE); String deadlineDescription = taskDescription.substring(0,startOfDeadlineDate).trim(); + if(deadlineDescription.isEmpty()){ + throw new CommandException(ErrorList.ERROR_EMPTY_DEADLINE_INPUT); + } String deadlineDate = taskDescription.replaceFirst(deadlineDescription,"").replaceFirst(DEADLINE_DATE,"").strip(); listManager.addDeadline(deadlineDescription,deadlineDate); } - private void handleToDo(String toDoInput){ + private void handleToDo(String toDoInput) throws CommandException{ String removeCommand = toDoInput.replaceFirst(COMMAND_ADD_TODO,"").trim(); + if(removeCommand.isEmpty()){ + throw new CommandException(ErrorList.ERROR_EMPTY_TODO_INPUT); + } listManager.addTodo(removeCommand); } @@ -71,29 +86,54 @@ private void handleDone(String userInput){ String[] taskDoneArray = removeCommand.split(","); for (String s: taskDoneArray) { int taskDoneIndex = Integer.parseInt(s); - listManager.completeTask(taskDoneIndex - 1); + try { + listManager.completeTask(taskDoneIndex - 1); + }catch (CommandException e){ + e.handleException(); + } } } - private void handleEcho(String userInput){ + private void handleEcho(String userInput) throws CommandException{ String removeCommand = userInput.replaceFirst(COMMAND_ECHO,"").trim(); + if(removeCommand.isEmpty()){ + throw new CommandException(ErrorList.ERROR_EMPTY_ECHO_INPUT); + } System.out.println(removeCommand); } - private void handleList(String userInput){ + private void handleList(String userInput) throws CommandException{ + if(listManager.getListSize() == 0){ + throw new CommandException(ErrorList.ERROR_EMPTY_LIST); + } String removeCommand = userInput.replaceFirst(COMMAND_VIEW_LIST,"").trim(); if(removeCommand.contains(COMMAND_ADD_TODO)){ - listManager.printToDo(); + try { + listManager.printToDo(); + }catch (CommandException e){ + e.handleException(); + } }else if(removeCommand.contains(COMMAND_ADD_EVENT)) { - listManager.printEvent(); + try { + listManager.printEvent(); + }catch (CommandException e){ + e.handleException(); + } }else if(removeCommand.contains(COMMAND_ADD_DEADLINE)){ - listManager.printDeadline(); + try { + listManager.printDeadline(); + }catch (CommandException e){ + e.handleException(); + } }else { listManager.printList(); } } - public void handleInput(){ + public void handleInput() throws CommandException{ + if(description.isEmpty()){ + throw new CommandException(ErrorList.ERROR_NULL); + } boolean isAddingTask = false; description = description.replaceAll("/",""); if(description.contains(COMMAND_ADD_DEADLINE)){ @@ -123,32 +163,59 @@ public void handleInput(){ private void handleCommand(String userInput){ String inputCommand = taskCategory(userInput); - switch(Objects.requireNonNull(inputCommand)){ - case COMMAND_EXIT: - Duke.isOnline = false; - break; - case COMMAND_VIEW_LIST: - handleList(userInput); - break; - case COMMAND_COMPLETE_TASK: - handleDone(userInput); - listManager.printList(); - System.out.println(Logo.divider); - break; - case COMMAND_ADD_EVENT: - handleEvent(userInput); - break; - case COMMAND_ADD_TODO: - handleToDo(userInput); - break; - case COMMAND_ADD_DEADLINE: - handleDeadline(userInput); - break; - case COMMAND_ECHO: - handleEcho(userInput); - break; - default: - break; + try { + switch (Objects.requireNonNull(inputCommand)) { + case COMMAND_EXIT: + Duke.isOnline = false; + break; + case COMMAND_VIEW_LIST: + try { + handleList(userInput); + }catch (CommandException e){ + e.handleException(); + } + break; + case COMMAND_COMPLETE_TASK: + handleDone(userInput); + listManager.printList(); + System.out.println(Logo.divider); + break; + case COMMAND_ADD_EVENT: + try { + handleEvent(userInput); + }catch (CommandException e){ + e.handleException(); + } + break; + case COMMAND_ADD_TODO: + try { + handleToDo(userInput); + }catch(CommandException e){ + e.handleException(); + } + break; + case COMMAND_ADD_DEADLINE: + try { + handleDeadline(userInput); + }catch (CommandException e){ + e.handleException(); + } + break; + case COMMAND_ECHO: + try { + handleEcho(userInput); + }catch (CommandException e){ + e.handleException(); + } + break; + } + }catch(NullPointerException e){ + try { + System.out.println(ErrorList.ERROR_UNKNOWN_COMMAND); + handleEcho(userInput); + }catch (CommandException commandException){ + commandException.handleException(); + } } } } diff --git a/src/main/java/InputInterface.java b/src/main/java/InputInterface.java index 75f6f2fb9..22aaff4a7 100644 --- a/src/main/java/InputInterface.java +++ b/src/main/java/InputInterface.java @@ -1,3 +1,3 @@ public interface InputInterface { - void handleInput(); + void handleInput() throws CommandException; } diff --git a/src/main/java/ListManager.java b/src/main/java/ListManager.java index 63b32c664..bfb85ff7d 100644 --- a/src/main/java/ListManager.java +++ b/src/main/java/ListManager.java @@ -20,7 +20,17 @@ public void printList(){ } } - public void printToDo(){ + public void printToDo() throws CommandException{ + boolean haveToDo = false; + for(int i = 1; i <= list.size(); i++){ + if(list.get(i) instanceof ToDo){ + haveToDo = true; + break; + } + } + if(!haveToDo){ + throw new CommandException(ErrorList.ERROR_EMPTY_TODO_LIST); + } for(int i = 0; i < list.size(); i++){ int itemIndex= i + 1; if(list.get(i) instanceof ToDo ) { @@ -29,7 +39,17 @@ public void printToDo(){ } } - public void printEvent(){ + public void printEvent() throws CommandException{ + boolean haveEvent = false; + for(int i = 1; i <= list.size(); i++){ + if(list.get(i) instanceof Event) { + haveEvent = true; + break; + } + } + if(!haveEvent){ + throw new CommandException(ErrorList.ERROR_EMPTY_EVENT_LIST); + } for(int i = 0; i < list.size(); i++){ int itemIndex= i + 1; if(list.get(i) instanceof Event ) { @@ -38,7 +58,17 @@ public void printEvent(){ } } - public void printDeadline(){ + public void printDeadline() throws CommandException{ + boolean haveDeadline = false; + for(int i = 1; i <= list.size(); i++){ + if(list.get(i) instanceof Deadline) { + haveDeadline = true; + break; + } + } + if(!haveDeadline){ + throw new CommandException(ErrorList.ERROR_EMPTY_DEADLINE_LIST); + } for(int i = 0; i < list.size(); i++){ int itemIndex= i + 1; if(list.get(i) instanceof Deadline ) { @@ -70,9 +100,16 @@ public void addDeadline(String description, String deadline){ printAddItem(t); } - public void completeTask(int t){ + public void completeTask(int t) throws CommandException{ + if (t > list.size() || t < 0){ + throw new CommandException(ErrorList.ERROR_DONE_TASK_NOT_IN_LIST); + } Task doneTask = list.get(t); doneTask.setDone(); System.out.println(Logo.divider + MESSAGE_TASK_COMPLETE + doneTask.getDescription()); } + + public int getListSize(){ + return list.size(); + } } diff --git a/src/main/java/Logo.java b/src/main/java/Logo.java index ac4ae9780..9814b05fe 100644 --- a/src/main/java/Logo.java +++ b/src/main/java/Logo.java @@ -1,5 +1,6 @@ public class Logo { public static final String divider = "____________________________________________________________\n"; + public static final String dividerWithoutNewLine = "____________________________________________________________"; public static final String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" + "| | | | | | | |/ / _ \\\n" diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java index 13378c61f..75ac48539 100644 --- a/src/main/java/TaskList.java +++ b/src/main/java/TaskList.java @@ -1,10 +1,11 @@ public interface TaskList { - void printList(); - void printToDo(); - void printEvent(); - void printDeadline(); + void printList() throws CommandException; + void printToDo() throws CommandException; + void printEvent() throws CommandException; + void printDeadline() throws CommandException; void addTodo(String description); void addEvent(String description, String time); void addDeadline(String description, String deadline); - void completeTask(int t); + void completeTask(int t) throws CommandException; + int getListSize(); } From 4a089015ecb5e14f906a292f87efce73d7cf05a4 Mon Sep 17 00:00:00 2001 From: wingho2 Date: Tue, 7 Sep 2021 02:52:05 +0800 Subject: [PATCH 11/62] Changing some Strings --- src/main/java/CommandManager.java | 8 ++++---- src/main/java/InputHandler.java | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/CommandManager.java b/src/main/java/CommandManager.java index 62966822c..7387befaf 100644 --- a/src/main/java/CommandManager.java +++ b/src/main/java/CommandManager.java @@ -43,16 +43,16 @@ public void handleCommand(){ } switch(description) { case COMMAND_HELP: - System.out.println(MESSAGE_HELP); + System.out.println(Logo.divider + MESSAGE_HELP + Logo.divider); break; case COMMAND_LIST_HELP: - System.out.println(MESSAGE_LIST_HELP); + System.out.println(Logo.divider + MESSAGE_LIST_HELP + Logo.divider); break; case COMMAND_EVENT_HELP: - System.out.println(MESSAGE_EVENT_HELP); + System.out.println(Logo.divider + MESSAGE_EVENT_HELP + Logo.divider); break; case COMMAND_DEADLINE_HELP: - System.out.println(MESSAGE_DEADLINE_HELP); + System.out.println(Logo.divider + MESSAGE_DEADLINE_HELP + Logo.divider); break; } } diff --git a/src/main/java/InputHandler.java b/src/main/java/InputHandler.java index a615e29fb..cabeaf920 100644 --- a/src/main/java/InputHandler.java +++ b/src/main/java/InputHandler.java @@ -107,6 +107,7 @@ private void handleList(String userInput) throws CommandException{ throw new CommandException(ErrorList.ERROR_EMPTY_LIST); } String removeCommand = userInput.replaceFirst(COMMAND_VIEW_LIST,"").trim(); + System.out.println(Logo.divider); if(removeCommand.contains(COMMAND_ADD_TODO)){ try { listManager.printToDo(); @@ -128,6 +129,7 @@ private void handleList(String userInput) throws CommandException{ }else { listManager.printList(); } + System.out.println(Logo.divider); } public void handleInput() throws CommandException{ From 50ed25dfed694c1b80dd333664221180935635ab Mon Sep 17 00:00:00 2001 From: wingho2 Date: Tue, 7 Sep 2021 03:04:01 +0800 Subject: [PATCH 12/62] Further fixes to the String printed --- src/main/java/CommandManager.java | 2 +- src/main/java/InputHandler.java | 10 ++++++---- src/main/java/ListManager.java | 6 ++++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/CommandManager.java b/src/main/java/CommandManager.java index 7387befaf..391af8b23 100644 --- a/src/main/java/CommandManager.java +++ b/src/main/java/CommandManager.java @@ -11,7 +11,7 @@ public class CommandManager implements CommandInterface{ " todo - Add ToDo Task\n" + " event - Add Event Task - !event for details\n" + " deadline - Add Deadline Task - !deadline for details\n" + - " bye - Shut Down"; + " bye - Shut Down\n"; private static final String MESSAGE_LIST_HELP = "list displays all tasks\n" + "list todo displays all todo tasks\n" + "list event displays all event tasks\n" + diff --git a/src/main/java/InputHandler.java b/src/main/java/InputHandler.java index cabeaf920..c08d405e1 100644 --- a/src/main/java/InputHandler.java +++ b/src/main/java/InputHandler.java @@ -84,6 +84,7 @@ private void handleToDo(String toDoInput) throws CommandException{ private void handleDone(String userInput){ String removeCommand = userInput.replaceFirst(COMMAND_COMPLETE_TASK,"").trim(); String[] taskDoneArray = removeCommand.split(","); + System.out.println(Logo.dividerWithoutNewLine); for (String s: taskDoneArray) { int taskDoneIndex = Integer.parseInt(s); try { @@ -92,6 +93,7 @@ private void handleDone(String userInput){ e.handleException(); } } + System.out.println(Logo.dividerWithoutNewLine); } private void handleEcho(String userInput) throws CommandException{ @@ -99,7 +101,7 @@ private void handleEcho(String userInput) throws CommandException{ if(removeCommand.isEmpty()){ throw new CommandException(ErrorList.ERROR_EMPTY_ECHO_INPUT); } - System.out.println(removeCommand); + System.out.println(Logo.divider + removeCommand + Logo.divider); } private void handleList(String userInput) throws CommandException{ @@ -107,7 +109,7 @@ private void handleList(String userInput) throws CommandException{ throw new CommandException(ErrorList.ERROR_EMPTY_LIST); } String removeCommand = userInput.replaceFirst(COMMAND_VIEW_LIST,"").trim(); - System.out.println(Logo.divider); + System.out.println(Logo.dividerWithoutNewLine); if(removeCommand.contains(COMMAND_ADD_TODO)){ try { listManager.printToDo(); @@ -129,7 +131,7 @@ private void handleList(String userInput) throws CommandException{ }else { listManager.printList(); } - System.out.println(Logo.divider); + System.out.println(Logo.dividerWithoutNewLine); } public void handleInput() throws CommandException{ @@ -180,7 +182,7 @@ private void handleCommand(String userInput){ case COMMAND_COMPLETE_TASK: handleDone(userInput); listManager.printList(); - System.out.println(Logo.divider); + System.out.println(Logo.dividerWithoutNewLine); break; case COMMAND_ADD_EVENT: try { diff --git a/src/main/java/ListManager.java b/src/main/java/ListManager.java index bfb85ff7d..c7e2d9961 100644 --- a/src/main/java/ListManager.java +++ b/src/main/java/ListManager.java @@ -85,19 +85,25 @@ private void printAddItem(Task t){ public void addTodo(String description){ Task t = new ToDo(description); list.add(t); + System.out.println(Logo.dividerWithoutNewLine); printAddItem(t); + System.out.println(Logo.dividerWithoutNewLine); } public void addEvent(String description, String time){ Task t = new Event(description, time); list.add(t); + System.out.println(Logo.dividerWithoutNewLine); printAddItem(t); + System.out.println(Logo.dividerWithoutNewLine); } public void addDeadline(String description, String deadline){ Task t = new Deadline(description, deadline); list.add(t); + System.out.println(Logo.dividerWithoutNewLine); printAddItem(t); + System.out.println(Logo.dividerWithoutNewLine); } public void completeTask(int t) throws CommandException{ From 23053160a6399c59778805700c5e66b2ff0e7d96 Mon Sep 17 00:00:00 2001 From: wingho2 Date: Tue, 7 Sep 2021 11:59:48 +0800 Subject: [PATCH 13/62] Minimal packaging --- src/main/java/{ => duke}/ArtBot.java | 2 ++ src/main/java/{ => duke}/ArtInterface.java | 2 ++ src/main/java/{ => duke}/CommandException.java | 2 ++ src/main/java/{ => duke}/CommandInterface.java | 2 ++ src/main/java/{ => duke}/CommandManager.java | 2 ++ src/main/java/{ => duke}/Deadline.java | 2 ++ src/main/java/{ => duke}/Duke.java | 2 ++ src/main/java/{ => duke}/ErrorList.java | 2 ++ src/main/java/{ => duke}/Event.java | 2 ++ src/main/java/{ => duke}/InputHandler.java | 2 ++ src/main/java/{ => duke}/InputInterface.java | 2 ++ src/main/java/{ => duke}/ListManager.java | 2 ++ src/main/java/{ => duke}/Logo.java | 2 ++ src/main/java/{ => duke}/Task.java | 2 ++ src/main/java/{ => duke}/TaskInterface.java | 2 ++ src/main/java/{ => duke}/TaskList.java | 2 ++ src/main/java/{ => duke}/ToDo.java | 2 ++ 17 files changed, 34 insertions(+) rename src/main/java/{ => duke}/ArtBot.java (99%) rename src/main/java/{ => duke}/ArtInterface.java (83%) rename src/main/java/{ => duke}/CommandException.java (94%) rename src/main/java/{ => duke}/CommandInterface.java (81%) rename src/main/java/{ => duke}/CommandManager.java (99%) rename src/main/java/{ => duke}/Deadline.java (96%) rename src/main/java/{ => duke}/Duke.java (98%) rename src/main/java/{ => duke}/ErrorList.java (99%) rename src/main/java/{ => duke}/Event.java (96%) rename src/main/java/{ => duke}/InputHandler.java (99%) rename src/main/java/{ => duke}/InputInterface.java (84%) rename src/main/java/{ => duke}/ListManager.java (99%) rename src/main/java/{ => duke}/Logo.java (99%) rename src/main/java/{ => duke}/Task.java (97%) rename src/main/java/{ => duke}/TaskInterface.java (88%) rename src/main/java/{ => duke}/TaskList.java (96%) rename src/main/java/{ => duke}/ToDo.java (94%) diff --git a/src/main/java/ArtBot.java b/src/main/java/duke/ArtBot.java similarity index 99% rename from src/main/java/ArtBot.java rename to src/main/java/duke/ArtBot.java index 8d8881f53..b46cf2a6b 100644 --- a/src/main/java/ArtBot.java +++ b/src/main/java/duke/ArtBot.java @@ -1,3 +1,5 @@ +package duke; + import java.util.ArrayList; public class ArtBot implements ArtInterface{ diff --git a/src/main/java/ArtInterface.java b/src/main/java/duke/ArtInterface.java similarity index 83% rename from src/main/java/ArtInterface.java rename to src/main/java/duke/ArtInterface.java index 2e90c19a9..d061d470d 100644 --- a/src/main/java/ArtInterface.java +++ b/src/main/java/duke/ArtInterface.java @@ -1,3 +1,5 @@ +package duke; + public interface ArtInterface { void drawArt() throws CommandException; } diff --git a/src/main/java/CommandException.java b/src/main/java/duke/CommandException.java similarity index 94% rename from src/main/java/CommandException.java rename to src/main/java/duke/CommandException.java index 480282fde..8a14ff1ef 100644 --- a/src/main/java/CommandException.java +++ b/src/main/java/duke/CommandException.java @@ -1,3 +1,5 @@ +package duke; + public class CommandException extends Exception{ private String errorMessage; diff --git a/src/main/java/CommandInterface.java b/src/main/java/duke/CommandInterface.java similarity index 81% rename from src/main/java/CommandInterface.java rename to src/main/java/duke/CommandInterface.java index f406dc728..1a467afb1 100644 --- a/src/main/java/CommandInterface.java +++ b/src/main/java/duke/CommandInterface.java @@ -1,3 +1,5 @@ +package duke; + public interface CommandInterface { void handleCommand(); } diff --git a/src/main/java/CommandManager.java b/src/main/java/duke/CommandManager.java similarity index 99% rename from src/main/java/CommandManager.java rename to src/main/java/duke/CommandManager.java index 391af8b23..0b735be6e 100644 --- a/src/main/java/CommandManager.java +++ b/src/main/java/duke/CommandManager.java @@ -1,3 +1,5 @@ +package duke; + public class CommandManager implements CommandInterface{ private static final String COMMAND_HELP = "!help"; diff --git a/src/main/java/Deadline.java b/src/main/java/duke/Deadline.java similarity index 96% rename from src/main/java/Deadline.java rename to src/main/java/duke/Deadline.java index dc882d765..66af7d403 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/duke/Deadline.java @@ -1,3 +1,5 @@ +package duke; + public class Deadline extends Task{ private static final String TASK_SYMBOL = "[D]"; diff --git a/src/main/java/Duke.java b/src/main/java/duke/Duke.java similarity index 98% rename from src/main/java/Duke.java rename to src/main/java/duke/Duke.java index c2200c182..2e3f6783e 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,3 +1,5 @@ +package duke; + import java.util.Scanner; import java.util.ArrayList; diff --git a/src/main/java/ErrorList.java b/src/main/java/duke/ErrorList.java similarity index 99% rename from src/main/java/ErrorList.java rename to src/main/java/duke/ErrorList.java index bc3c06197..1157d1389 100644 --- a/src/main/java/ErrorList.java +++ b/src/main/java/duke/ErrorList.java @@ -1,3 +1,5 @@ +package duke; + public class ErrorList { public static final String ERROR_NULL = "☹ OOPS!!! Input cannot be empty."; public static final String ERROR_UNKNOWN_COMMAND = "☹ OOPS!!! I'm sorry, but I don't know what that means :-(\n" + "" + diff --git a/src/main/java/Event.java b/src/main/java/duke/Event.java similarity index 96% rename from src/main/java/Event.java rename to src/main/java/duke/Event.java index e6bb1591f..d67ce9f5a 100644 --- a/src/main/java/Event.java +++ b/src/main/java/duke/Event.java @@ -1,3 +1,5 @@ +package duke; + public class Event extends Task{ private static final String TASK_SYMBOL = "[E]"; diff --git a/src/main/java/InputHandler.java b/src/main/java/duke/InputHandler.java similarity index 99% rename from src/main/java/InputHandler.java rename to src/main/java/duke/InputHandler.java index c08d405e1..1928ebcde 100644 --- a/src/main/java/InputHandler.java +++ b/src/main/java/duke/InputHandler.java @@ -1,3 +1,5 @@ +package duke; + import java.util.Objects; public class InputHandler implements InputInterface{ diff --git a/src/main/java/InputInterface.java b/src/main/java/duke/InputInterface.java similarity index 84% rename from src/main/java/InputInterface.java rename to src/main/java/duke/InputInterface.java index 22aaff4a7..077524732 100644 --- a/src/main/java/InputInterface.java +++ b/src/main/java/duke/InputInterface.java @@ -1,3 +1,5 @@ +package duke; + public interface InputInterface { void handleInput() throws CommandException; } diff --git a/src/main/java/ListManager.java b/src/main/java/duke/ListManager.java similarity index 99% rename from src/main/java/ListManager.java rename to src/main/java/duke/ListManager.java index c7e2d9961..a3e0a865f 100644 --- a/src/main/java/ListManager.java +++ b/src/main/java/duke/ListManager.java @@ -1,3 +1,5 @@ +package duke; + import java.util.ArrayList; public class ListManager implements TaskList{ diff --git a/src/main/java/Logo.java b/src/main/java/duke/Logo.java similarity index 99% rename from src/main/java/Logo.java rename to src/main/java/duke/Logo.java index 9814b05fe..a7e41e8c3 100644 --- a/src/main/java/Logo.java +++ b/src/main/java/duke/Logo.java @@ -1,3 +1,5 @@ +package duke; + public class Logo { public static final String divider = "____________________________________________________________\n"; public static final String dividerWithoutNewLine = "____________________________________________________________"; diff --git a/src/main/java/Task.java b/src/main/java/duke/Task.java similarity index 97% rename from src/main/java/Task.java rename to src/main/java/duke/Task.java index adffb4c36..967eb06b3 100644 --- a/src/main/java/Task.java +++ b/src/main/java/duke/Task.java @@ -1,3 +1,5 @@ +package duke; + public class Task implements TaskInterface{ private static final String completeStatusIcon = "[X]"; private static final String incompleteStatusIcon = "[ ]"; diff --git a/src/main/java/TaskInterface.java b/src/main/java/duke/TaskInterface.java similarity index 88% rename from src/main/java/TaskInterface.java rename to src/main/java/duke/TaskInterface.java index 7c68d8eaa..77a3a2aec 100644 --- a/src/main/java/TaskInterface.java +++ b/src/main/java/duke/TaskInterface.java @@ -1,3 +1,5 @@ +package duke; + public interface TaskInterface { void setDone(); String getDescription(); diff --git a/src/main/java/TaskList.java b/src/main/java/duke/TaskList.java similarity index 96% rename from src/main/java/TaskList.java rename to src/main/java/duke/TaskList.java index 75ac48539..89da73966 100644 --- a/src/main/java/TaskList.java +++ b/src/main/java/duke/TaskList.java @@ -1,3 +1,5 @@ +package duke; + public interface TaskList { void printList() throws CommandException; void printToDo() throws CommandException; diff --git a/src/main/java/ToDo.java b/src/main/java/duke/ToDo.java similarity index 94% rename from src/main/java/ToDo.java rename to src/main/java/duke/ToDo.java index c65b0b035..6c8c13677 100644 --- a/src/main/java/ToDo.java +++ b/src/main/java/duke/ToDo.java @@ -1,3 +1,5 @@ +package duke; + public class ToDo extends Task{ private static final String TASK_SYMBOL = "[T]"; From 57771c8b5d8e363595b4ca8576a218cc35d915f3 Mon Sep 17 00:00:00 2001 From: wingho2 Date: Tue, 7 Sep 2021 12:03:09 +0800 Subject: [PATCH 14/62] More packages --- src/main/java/duke/{ => task}/Deadline.java | 0 src/main/java/duke/{ => task}/Event.java | 0 src/main/java/duke/{ => task}/Task.java | 0 src/main/java/duke/{ => task}/ToDo.java | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename src/main/java/duke/{ => task}/Deadline.java (100%) rename src/main/java/duke/{ => task}/Event.java (100%) rename src/main/java/duke/{ => task}/Task.java (100%) rename src/main/java/duke/{ => task}/ToDo.java (100%) diff --git a/src/main/java/duke/Deadline.java b/src/main/java/duke/task/Deadline.java similarity index 100% rename from src/main/java/duke/Deadline.java rename to src/main/java/duke/task/Deadline.java diff --git a/src/main/java/duke/Event.java b/src/main/java/duke/task/Event.java similarity index 100% rename from src/main/java/duke/Event.java rename to src/main/java/duke/task/Event.java diff --git a/src/main/java/duke/Task.java b/src/main/java/duke/task/Task.java similarity index 100% rename from src/main/java/duke/Task.java rename to src/main/java/duke/task/Task.java diff --git a/src/main/java/duke/ToDo.java b/src/main/java/duke/task/ToDo.java similarity index 100% rename from src/main/java/duke/ToDo.java rename to src/main/java/duke/task/ToDo.java From a9d7713cad4b0abd86edaaeca5a2940f8f91e7f0 Mon Sep 17 00:00:00 2001 From: wingho2 Date: Tue, 7 Sep 2021 12:03:20 +0800 Subject: [PATCH 15/62] Fix packages --- src/main/java/duke/Duke.java | 2 ++ src/main/java/duke/ListManager.java | 5 +++++ src/main/java/duke/task/Deadline.java | 2 +- src/main/java/duke/task/Event.java | 2 +- src/main/java/duke/task/Task.java | 6 ++++-- src/main/java/duke/task/ToDo.java | 2 +- 6 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 2e3f6783e..750fa99ac 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,5 +1,7 @@ package duke; +import duke.task.Task; + import java.util.Scanner; import java.util.ArrayList; diff --git a/src/main/java/duke/ListManager.java b/src/main/java/duke/ListManager.java index a3e0a865f..f92e99247 100644 --- a/src/main/java/duke/ListManager.java +++ b/src/main/java/duke/ListManager.java @@ -1,5 +1,10 @@ package duke; +import duke.task.Deadline; +import duke.task.Event; +import duke.task.Task; +import duke.task.ToDo; + import java.util.ArrayList; public class ListManager implements TaskList{ diff --git a/src/main/java/duke/task/Deadline.java b/src/main/java/duke/task/Deadline.java index 66af7d403..485e17c4b 100644 --- a/src/main/java/duke/task/Deadline.java +++ b/src/main/java/duke/task/Deadline.java @@ -1,4 +1,4 @@ -package duke; +package duke.task; public class Deadline extends Task{ diff --git a/src/main/java/duke/task/Event.java b/src/main/java/duke/task/Event.java index d67ce9f5a..de41247f6 100644 --- a/src/main/java/duke/task/Event.java +++ b/src/main/java/duke/task/Event.java @@ -1,4 +1,4 @@ -package duke; +package duke.task; public class Event extends Task{ diff --git a/src/main/java/duke/task/Task.java b/src/main/java/duke/task/Task.java index 967eb06b3..3c660700b 100644 --- a/src/main/java/duke/task/Task.java +++ b/src/main/java/duke/task/Task.java @@ -1,6 +1,8 @@ -package duke; +package duke.task; -public class Task implements TaskInterface{ +import duke.TaskInterface; + +public class Task implements TaskInterface { private static final String completeStatusIcon = "[X]"; private static final String incompleteStatusIcon = "[ ]"; private final String description; diff --git a/src/main/java/duke/task/ToDo.java b/src/main/java/duke/task/ToDo.java index 6c8c13677..a113a4dfb 100644 --- a/src/main/java/duke/task/ToDo.java +++ b/src/main/java/duke/task/ToDo.java @@ -1,4 +1,4 @@ -package duke; +package duke.task; public class ToDo extends Task{ From c383114b5c020d78037ea8b28241432b72305f74 Mon Sep 17 00:00:00 2001 From: wingho2 Date: Wed, 15 Sep 2021 12:43:44 +0800 Subject: [PATCH 16/62] Add a delete function to class ListManager and class inputhandler when delete is called --- src/main/java/duke/ErrorList.java | 1 + src/main/java/duke/InputHandler.java | 37 +++++++++-- src/main/java/duke/ListManager.java | 15 ++++- text-ui-test/EXPECTED.txt | 95 ++++++++++++++++++++++++++-- text-ui-test/input.txt | 6 +- 5 files changed, 141 insertions(+), 13 deletions(-) diff --git a/src/main/java/duke/ErrorList.java b/src/main/java/duke/ErrorList.java index 1157d1389..61179c96d 100644 --- a/src/main/java/duke/ErrorList.java +++ b/src/main/java/duke/ErrorList.java @@ -15,5 +15,6 @@ public class ErrorList { public static final String ERROR_EMPTY_EVENT_TIME = "☹ OOPS!!! The timing of a event cannot be empty.\n"; public static final String ERROR_EMPTY_DEADLINE_TIME = "☹ OOPS!!! The due date of a deadline cannot be empty.\n"; public static final String ERROR_DONE_TASK_NOT_IN_LIST ="☹ OOPS!!! Task done not found in list\n"; + public static final String ERROR_DELETE_TASK ="☹ OOPS!!! Cannot remove task that does not exist.\n"; public static final String ERROR_LETTER_NOT_FOUND = "☹ OOPS!!! Something went wrong. Do not input space or symbols.\n"; } diff --git a/src/main/java/duke/InputHandler.java b/src/main/java/duke/InputHandler.java index 1928ebcde..7d4d2fce4 100644 --- a/src/main/java/duke/InputHandler.java +++ b/src/main/java/duke/InputHandler.java @@ -13,6 +13,7 @@ public class InputHandler implements InputInterface{ private static final String COMMAND_ADD_DEADLINE = "deadline"; private static final String EVENT_TIME = "at"; private static final String DEADLINE_DATE = "by"; + private static final String COMMAND_DELETE = "delete"; private String description; private final ListManager listManager; @@ -44,6 +45,9 @@ private String taskCategory(String userInput){ if (userInput.startsWith(COMMAND_ECHO)){ return COMMAND_ECHO; } + if(userInput.startsWith(COMMAND_DELETE)){ + return COMMAND_DELETE; + } return null; } @@ -103,7 +107,7 @@ private void handleEcho(String userInput) throws CommandException{ if(removeCommand.isEmpty()){ throw new CommandException(ErrorList.ERROR_EMPTY_ECHO_INPUT); } - System.out.println(Logo.divider + removeCommand + Logo.divider); + System.out.println(Logo.divider + removeCommand + System.lineSeparator() + Logo.divider); } private void handleList(String userInput) throws CommandException{ @@ -136,29 +140,44 @@ private void handleList(String userInput) throws CommandException{ System.out.println(Logo.dividerWithoutNewLine); } + private void handleDelete(String userInput)throws CommandException{ + String removeCommand = userInput.replaceFirst(COMMAND_DELETE,"").trim(); + String[] taskDoneArray = removeCommand.split(","); + System.out.println(Logo.dividerWithoutNewLine); + for (String s: taskDoneArray) { + int taskDoneIndex = Integer.parseInt(s); + try { + listManager.deleteTask(taskDoneIndex - 1); + }catch (CommandException e){ + e.handleException(); + } + } + System.out.println(Logo.dividerWithoutNewLine); + } + public void handleInput() throws CommandException{ if(description.isEmpty()){ throw new CommandException(ErrorList.ERROR_NULL); } boolean isAddingTask = false; - description = description.replaceAll("/",""); + description = description.replaceAll(";",""); if(description.contains(COMMAND_ADD_DEADLINE)){ isAddingTask = true; - description = description.replaceAll(COMMAND_ADD_DEADLINE,"/"+ COMMAND_ADD_DEADLINE); + description = description.replaceAll(COMMAND_ADD_DEADLINE,";"+ COMMAND_ADD_DEADLINE); } if(description.contains(COMMAND_ADD_TODO)){ isAddingTask = true; - description = description.replaceAll(COMMAND_ADD_TODO,"/"+ COMMAND_ADD_TODO); + description = description.replaceAll(COMMAND_ADD_TODO,";"+ COMMAND_ADD_TODO); } if(description.contains(COMMAND_ADD_EVENT)){ isAddingTask = true; - description = description.replaceAll(COMMAND_ADD_EVENT,"/"+ COMMAND_ADD_EVENT); + description = description.replaceAll(COMMAND_ADD_EVENT,";"+ COMMAND_ADD_EVENT); } if(description.startsWith(COMMAND_VIEW_LIST)){ isAddingTask = false; } if(isAddingTask) { - String[] commandList = description.split("/"); + String[] commandList = description.split(";"); for (int i = 1; i < commandList.length; i++) { handleCommand(commandList[i]); } @@ -214,6 +233,12 @@ private void handleCommand(String userInput){ e.handleException(); } break; + case COMMAND_DELETE: + try{ + handleDelete(userInput); + }catch (CommandException e){ + e.handleException();; + } } }catch(NullPointerException e){ try { diff --git a/src/main/java/duke/ListManager.java b/src/main/java/duke/ListManager.java index f92e99247..c5d8c8be2 100644 --- a/src/main/java/duke/ListManager.java +++ b/src/main/java/duke/ListManager.java @@ -12,7 +12,9 @@ public class ListManager implements TaskList{ private static final String MESSAGE_TASK_ADDED = "Got it. I've added this task: "; private static final String MESSAGE_TASK_COMPLETE = "Nice! I've marked this task as done: "; private static final String MESSAGE_TASK_IN_LIST = " tasks in the list."; + private static final String MESSAGE_LIST_TASK = "Here are the tasks in your list:"; private static final String MESSAGE_TASK_NOW = "Now you have "; + private static final String MESSAGE_DELETE = "Noted. I've removed this task: "; private static final String MESSAGE_SPACER = ". "; private final ArrayList list; @@ -21,6 +23,7 @@ public ListManager(ArrayList list){ } public void printList(){ + System.out.println(MESSAGE_LIST_TASK); for(int i = 0; i < list.size(); i++){ int itemIndex= i + 1; System.out.println(itemIndex + MESSAGE_SPACER + list.get(i).toString()); @@ -119,7 +122,17 @@ public void completeTask(int t) throws CommandException{ } Task doneTask = list.get(t); doneTask.setDone(); - System.out.println(Logo.divider + MESSAGE_TASK_COMPLETE + doneTask.getDescription()); + System.out.println(Logo.divider + MESSAGE_TASK_COMPLETE + doneTask.toString()); + } + + public void deleteTask(int t) throws CommandException{ + if(t > list.size() || t < 0){ + throw new CommandException(ErrorList.ERROR_DELETE_TASK); + } + Task removeTask = list.get(t); + list.remove(t); + System.out.println(MESSAGE_DELETE + System.lineSeparator() + removeTask.toString() + System.lineSeparator() + + MESSAGE_TASK_NOW + list.size() + MESSAGE_TASK_IN_LIST); } public int getListSize(){ diff --git a/text-ui-test/EXPECTED.txt b/text-ui-test/EXPECTED.txt index 657e74f6e..019693f50 100644 --- a/text-ui-test/EXPECTED.txt +++ b/text-ui-test/EXPECTED.txt @@ -1,7 +1,94 @@ -Hello from - ____ _ -| _ \ _ _| | _____ + ____ _ +| _ \ _ _| | _____ | | | | | | | |/ / _ \ | |_| | |_| | < __/ |____/ \__,_|_|\_\___| - +____________________________________________________________ +Hello! I'm Duke +What can I do for you? +!help for Command List +____________________________________________________________ +____________________________________________________________ +hi +____________________________________________________________ +HI + ___ ___ .___ + / | \ | | +/ ~ \| | +\ Y /| | + \___|___/ |___| + ____________________________________________________________ + Got it. I've added this task: + [T][ ]watch et1231 livestream + Now you have 1 tasks in the list. + ____________________________________________________________ + ____________________________________________________________ + Got it. I've added this task: + [T][ ]watch hankyuu livestream + Now you have 2 tasks in the list. + ____________________________________________________________ +____________________________________________________________ +Got it. I've added this task: +[T][ ]watch haxxnini livestream +Now you have 3 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Got it. I've added this task: +[D][ ]reach radiant(by: this season) +Now you have 4 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Got it. I've added this task: +[E][ ]g2 vs sentinel(at:12am) +Now you have 5 tasks in the list. +____________________________________________________________ +____________________________________________________________ +List of Commands: + echo - Repeat whatever was typed - !echo to repeat in art form + list - Display List - !list for details + todo - Add ToDo Task + event - Add Event Task - !event for details + deadline - Add Deadline Task - !deadline for details + bye - Shut Down +____________________________________________________________ +____________________________________________________________ +Here are the tasks in your list: +1. [T][ ]watch et1231 livestream +2. [T][ ]watch hankyuu livestream +3. [T][ ]watch haxxnini livestream +4. [D][ ]reach radiant(by: this season) +5. [E][ ]g2 vs sentinel(at:12am) +____________________________________________________________ +____________________________________________________________ +Nice! I've marked this task as done: [T][X]watch et1231 livestream +____________________________________________________________ +Nice! I've marked this task as done: [T][X]watch hankyuu livestream +____________________________________________________________ +Nice! I've marked this task as done: [D][X]reach radiant(by: this season) +____________________________________________________________ +Here are the tasks in your list: +1. [T][X]watch et1231 livestream +2. [T][X]watch hankyuu livestream +3. [T][ ]watch haxxnini livestream +4. [D][X]reach radiant(by: this season) +5. [E][ ]g2 vs sentinel(at:12am) +____________________________________________________________ +____________________________________________________________ +Noted. I've removed this task: [T][X]watch et1231 livestream +Now you have 4 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Here are the tasks in your list: +1. [T][X]watch hankyuu livestream +2. [T][ ]watch haxxnini livestream +3. [D][X]reach radiant(by: this season) +4. [E][ ]g2 vs sentinel(at:12am) +____________________________________________________________ +____________________________________________________________ +Bye. Hope to see you again soon! +____________________________________________________________ +_______________.___.___________ +\______ \__ | |\_ _____/ + | | _// | | | __)_ + | | \\____ | | \ + |________// ______|/_________/ \ No newline at end of file diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index 3e6015cc7..46a629146 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -2,9 +2,11 @@ echo Hi !echo hi todo watch et1231 livestream todo watch hankyuu livestream todo watch haxxnini livestream -deadline reach mystic by this season event game session at 10pm +deadline reach radiant by this season +event G2 vs Sentinel at 12am !help list -done 1,2,3 +done 1,2,4 +delete 1 list bye \ No newline at end of file From 5ee47d481c88ce0db280a5008a90479ce853e466 Mon Sep 17 00:00:00 2001 From: wingho2 Date: Wed, 15 Sep 2021 13:19:47 +0800 Subject: [PATCH 17/62] Some formatting words changes --- data/duke.txt | 0 src/main/java/duke/CommandManager.java | 8 ++++---- src/main/java/duke/ListManager.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) create mode 100644 data/duke.txt diff --git a/data/duke.txt b/data/duke.txt new file mode 100644 index 000000000..e69de29bb diff --git a/src/main/java/duke/CommandManager.java b/src/main/java/duke/CommandManager.java index 0b735be6e..91819cbf7 100644 --- a/src/main/java/duke/CommandManager.java +++ b/src/main/java/duke/CommandManager.java @@ -45,16 +45,16 @@ public void handleCommand(){ } switch(description) { case COMMAND_HELP: - System.out.println(Logo.divider + MESSAGE_HELP + Logo.divider); + System.out.println(Logo.divider + MESSAGE_HELP + Logo.dividerWithoutNewLine); break; case COMMAND_LIST_HELP: - System.out.println(Logo.divider + MESSAGE_LIST_HELP + Logo.divider); + System.out.println(Logo.divider + MESSAGE_LIST_HELP + Logo.dividerWithoutNewLine); break; case COMMAND_EVENT_HELP: - System.out.println(Logo.divider + MESSAGE_EVENT_HELP + Logo.divider); + System.out.println(Logo.divider + MESSAGE_EVENT_HELP + Logo.dividerWithoutNewLine); break; case COMMAND_DEADLINE_HELP: - System.out.println(Logo.divider + MESSAGE_DEADLINE_HELP + Logo.divider); + System.out.println(Logo.divider + MESSAGE_DEADLINE_HELP + Logo.dividerWithoutNewLine); break; } } diff --git a/src/main/java/duke/ListManager.java b/src/main/java/duke/ListManager.java index c5d8c8be2..6c7b7066a 100644 --- a/src/main/java/duke/ListManager.java +++ b/src/main/java/duke/ListManager.java @@ -122,7 +122,7 @@ public void completeTask(int t) throws CommandException{ } Task doneTask = list.get(t); doneTask.setDone(); - System.out.println(Logo.divider + MESSAGE_TASK_COMPLETE + doneTask.toString()); + System.out.println(MESSAGE_TASK_COMPLETE + doneTask.toString()); } public void deleteTask(int t) throws CommandException{ From 6ee2be3a498af13f5c24b319abb37c3527d4693d Mon Sep 17 00:00:00 2001 From: wingho2 Date: Wed, 15 Sep 2021 18:02:50 +0800 Subject: [PATCH 18/62] Add the save function to txt files Added a file class to interact with txt files --- duke.txt | 4 ++ src/main/java/META-INF/MANIFEST.MF | 3 + src/main/java/duke/CommandManager.java | 12 ++-- src/main/java/duke/Duke.java | 8 ++- src/main/java/duke/FileManager.java | 82 ++++++++++++++++++++++++++ src/main/java/duke/InputHandler.java | 19 +++--- src/main/java/duke/ListManager.java | 38 +++++++----- src/main/java/duke/TaskList.java | 8 +-- src/main/java/duke/task/Deadline.java | 5 ++ src/main/java/duke/task/Event.java | 5 ++ src/main/java/duke/task/Task.java | 11 +++- src/main/java/duke/task/ToDo.java | 5 ++ text-ui-test/EXPECTED.txt | 47 ++++++++++----- text-ui-test/input.txt | 7 ++- text-ui-test/runtest.sh | 38 ------------ 15 files changed, 201 insertions(+), 91 deletions(-) create mode 100644 duke.txt create mode 100644 src/main/java/META-INF/MANIFEST.MF create mode 100644 src/main/java/duke/FileManager.java delete mode 100644 text-ui-test/runtest.sh diff --git a/duke.txt b/duke.txt new file mode 100644 index 000000000..e2e428b17 --- /dev/null +++ b/duke.txt @@ -0,0 +1,4 @@ +[T];[ ];watch youtube +[T];[ ];watch +[T];[ ];watch douyin +[T];[ ];tiktok diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 000000000..2c9a9745c --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: duke.Duke + diff --git a/src/main/java/duke/CommandManager.java b/src/main/java/duke/CommandManager.java index 0b735be6e..9bb9a1798 100644 --- a/src/main/java/duke/CommandManager.java +++ b/src/main/java/duke/CommandManager.java @@ -18,8 +18,8 @@ public class CommandManager implements CommandInterface{ "list todo displays all todo tasks\n" + "list event displays all event tasks\n" + "list deadline displays all deadline tasks\n"; - private static final String MESSAGE_EVENT_HELP = "event command requires a timing indicated using \"at\" [timing]"; - private static final String MESSAGE_DEADLINE_HELP = "deadline command requires a end time indicated using \"by\"[end time]"; + private static final String MESSAGE_EVENT_HELP = "event command requires a timing indicated using \"at\" [timing]\n"; + private static final String MESSAGE_DEADLINE_HELP = "deadline command requires a end time indicated using \"by\"[end time]\n"; private final String description; @@ -45,16 +45,16 @@ public void handleCommand(){ } switch(description) { case COMMAND_HELP: - System.out.println(Logo.divider + MESSAGE_HELP + Logo.divider); + System.out.println(Logo.divider + MESSAGE_HELP + Logo.dividerWithoutNewLine); break; case COMMAND_LIST_HELP: - System.out.println(Logo.divider + MESSAGE_LIST_HELP + Logo.divider); + System.out.println(Logo.divider + MESSAGE_LIST_HELP + Logo.dividerWithoutNewLine); break; case COMMAND_EVENT_HELP: - System.out.println(Logo.divider + MESSAGE_EVENT_HELP + Logo.divider); + System.out.println(Logo.divider + MESSAGE_EVENT_HELP + Logo.dividerWithoutNewLine); break; case COMMAND_DEADLINE_HELP: - System.out.println(Logo.divider + MESSAGE_DEADLINE_HELP + Logo.divider); + System.out.println(Logo.divider + MESSAGE_DEADLINE_HELP + Logo.dividerWithoutNewLine); break; } } diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 750fa99ac..ca944da6a 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -25,18 +25,24 @@ public static void main(String[] args) { Scanner in = new Scanner(System.in); ArrayList list = new ArrayList<>(); ListManager listManager = new ListManager(list); + FileManager fileManager = new FileManager(listManager); + fileManager.covertStringToTask(); while(isOnline) { String userInput = in.nextLine().toLowerCase().trim(); if (userInput.startsWith("!")) { CommandManager commandManager = new CommandManager(userInput); commandManager.handleCommand(); } else { - InputHandler inputManager = new InputHandler(userInput, listManager); + InputHandler inputManager = new InputHandler(userInput, listManager, fileManager); try { inputManager.handleInput(); }catch(CommandException e){ e.handleException(); } + fileManager.writeToFile(list.get(0),false); + for (int i = 1; i < list.size(); i ++) { + fileManager.writeToFile(list.get(i), true); + } } } endDuke(); diff --git a/src/main/java/duke/FileManager.java b/src/main/java/duke/FileManager.java new file mode 100644 index 000000000..9a9bcaa70 --- /dev/null +++ b/src/main/java/duke/FileManager.java @@ -0,0 +1,82 @@ +package duke; + +import duke.task.Event; +import duke.task.Task; +import duke.task.ToDo; + +import java.io.File; +import java.io.FileWriter; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Scanner; + +public class FileManager { + + private static final String FILE_NAME = "duke.txt"; + private static final String FILE_CREATED = "File created to store data: "; + + private File file; + private final ListManager listManager; + + public FileManager(ListManager listManager){ + this.listManager = listManager; + try{ + file = new File(FILE_NAME); + if(file.createNewFile()){ + System.out.println(FILE_CREATED + file.getName() + System.lineSeparator() + file.getAbsolutePath()); + } + }catch(IOException e){ + e.printStackTrace(); + } + } + + private ArrayList readFile(){ + ArrayList list = new ArrayList<>(); + try { + Scanner scanner = new Scanner(file); + while(scanner.hasNext()){ + list.add(scanner.nextLine()); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + return list; + } + + public void covertStringToTask() { + ArrayList stringList = readFile(); + int index = 0; + for (String s : stringList) { + String[] splitString = s.split(";"); + switch (splitString[0]){ + case "[T]": + listManager.addTodo(splitString[2], true); + break; + case "[E]": + listManager.addEvent(splitString[2],splitString[3], true); + break; + case"[D]": + listManager.addDeadline(splitString[2],splitString[3], true); + } + if (splitString[1].equals("[X]")){ + try { + listManager.completeTask(index, true); + } catch (CommandException e) { + e.handleException(); + } + } + index += 1; + } + } + + public void writeToFile(Task t, boolean isAppend){ + try { + FileWriter fileWriter = new FileWriter(file, isAppend); + fileWriter.write(t.toFile()); + fileWriter.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/duke/InputHandler.java b/src/main/java/duke/InputHandler.java index 7d4d2fce4..cdd6fe19c 100644 --- a/src/main/java/duke/InputHandler.java +++ b/src/main/java/duke/InputHandler.java @@ -14,13 +14,16 @@ public class InputHandler implements InputInterface{ private static final String EVENT_TIME = "at"; private static final String DEADLINE_DATE = "by"; private static final String COMMAND_DELETE = "delete"; + private static final String MESSAGE_TASK_COMPLETE = "Nice! I've marked this task as done: "; private String description; private final ListManager listManager; + private final FileManager fileManager; - public InputHandler(String description, ListManager listManager){ + public InputHandler(String description, ListManager listManager, FileManager fileManager){ this.description = description; this.listManager = listManager; + this.fileManager = fileManager; } private String taskCategory(String userInput){ @@ -62,7 +65,7 @@ private void handleEvent(String eventInput) throws CommandException{ throw new CommandException(ErrorList.ERROR_EMPTY_EVENT_INPUT); } String eventTime = taskDescription.replaceFirst(eventDescription,"").replaceFirst(EVENT_TIME,"").strip(); - listManager.addEvent(eventDescription,eventTime); + listManager.addEvent(eventDescription,eventTime, false); } private void handleDeadline(String deadlineInput) throws CommandException{ @@ -76,7 +79,7 @@ private void handleDeadline(String deadlineInput) throws CommandException{ throw new CommandException(ErrorList.ERROR_EMPTY_DEADLINE_INPUT); } String deadlineDate = taskDescription.replaceFirst(deadlineDescription,"").replaceFirst(DEADLINE_DATE,"").strip(); - listManager.addDeadline(deadlineDescription,deadlineDate); + listManager.addDeadline(deadlineDescription,deadlineDate, false); } private void handleToDo(String toDoInput) throws CommandException{ @@ -84,17 +87,17 @@ private void handleToDo(String toDoInput) throws CommandException{ if(removeCommand.isEmpty()){ throw new CommandException(ErrorList.ERROR_EMPTY_TODO_INPUT); } - listManager.addTodo(removeCommand); + listManager.addTodo(removeCommand,false); } private void handleDone(String userInput){ String removeCommand = userInput.replaceFirst(COMMAND_COMPLETE_TASK,"").trim(); String[] taskDoneArray = removeCommand.split(","); - System.out.println(Logo.dividerWithoutNewLine); + System.out.println(Logo.dividerWithoutNewLine + System.lineSeparator() + MESSAGE_TASK_COMPLETE); for (String s: taskDoneArray) { int taskDoneIndex = Integer.parseInt(s); try { - listManager.completeTask(taskDoneIndex - 1); + listManager.completeTask(taskDoneIndex - 1, false); }catch (CommandException e){ e.handleException(); } @@ -107,7 +110,7 @@ private void handleEcho(String userInput) throws CommandException{ if(removeCommand.isEmpty()){ throw new CommandException(ErrorList.ERROR_EMPTY_ECHO_INPUT); } - System.out.println(Logo.divider + removeCommand + System.lineSeparator() + Logo.divider); + System.out.println(Logo.divider + removeCommand + System.lineSeparator() + Logo.dividerWithoutNewLine); } private void handleList(String userInput) throws CommandException{ @@ -237,7 +240,7 @@ private void handleCommand(String userInput){ try{ handleDelete(userInput); }catch (CommandException e){ - e.handleException();; + e.handleException(); } } }catch(NullPointerException e){ diff --git a/src/main/java/duke/ListManager.java b/src/main/java/duke/ListManager.java index c5d8c8be2..19d7563e2 100644 --- a/src/main/java/duke/ListManager.java +++ b/src/main/java/duke/ListManager.java @@ -10,12 +10,12 @@ public class ListManager implements TaskList{ private static final String MESSAGE_TASK_ADDED = "Got it. I've added this task: "; - private static final String MESSAGE_TASK_COMPLETE = "Nice! I've marked this task as done: "; private static final String MESSAGE_TASK_IN_LIST = " tasks in the list."; private static final String MESSAGE_LIST_TASK = "Here are the tasks in your list:"; private static final String MESSAGE_TASK_NOW = "Now you have "; private static final String MESSAGE_DELETE = "Noted. I've removed this task: "; private static final String MESSAGE_SPACER = ". "; + private final ArrayList list; public ListManager(ArrayList list){ @@ -92,37 +92,45 @@ private void printAddItem(Task t){ + list.size() + MESSAGE_TASK_IN_LIST); } - public void addTodo(String description){ + public void addTodo(String description, boolean isFromFile){ Task t = new ToDo(description); list.add(t); - System.out.println(Logo.dividerWithoutNewLine); - printAddItem(t); - System.out.println(Logo.dividerWithoutNewLine); + if(!isFromFile) { + System.out.println(Logo.dividerWithoutNewLine); + printAddItem(t); + System.out.println(Logo.dividerWithoutNewLine); + } } - public void addEvent(String description, String time){ + public void addEvent(String description, String time, boolean isFromFile){ Task t = new Event(description, time); list.add(t); - System.out.println(Logo.dividerWithoutNewLine); - printAddItem(t); - System.out.println(Logo.dividerWithoutNewLine); + if(!isFromFile) { + System.out.println(Logo.dividerWithoutNewLine); + printAddItem(t); + System.out.println(Logo.dividerWithoutNewLine); + } } - public void addDeadline(String description, String deadline){ + public void addDeadline(String description, String deadline, boolean isFromFile){ Task t = new Deadline(description, deadline); list.add(t); - System.out.println(Logo.dividerWithoutNewLine); - printAddItem(t); - System.out.println(Logo.dividerWithoutNewLine); + if(!isFromFile) { + System.out.println(Logo.dividerWithoutNewLine); + printAddItem(t); + System.out.println(Logo.dividerWithoutNewLine); + } } - public void completeTask(int t) throws CommandException{ + public void completeTask(int t, boolean isFromFile) throws CommandException{ if (t > list.size() || t < 0){ throw new CommandException(ErrorList.ERROR_DONE_TASK_NOT_IN_LIST); } Task doneTask = list.get(t); doneTask.setDone(); - System.out.println(Logo.divider + MESSAGE_TASK_COMPLETE + doneTask.toString()); + if (!isFromFile) { + System.out.println(doneTask.toString()); + } } public void deleteTask(int t) throws CommandException{ diff --git a/src/main/java/duke/TaskList.java b/src/main/java/duke/TaskList.java index 89da73966..221c1893f 100644 --- a/src/main/java/duke/TaskList.java +++ b/src/main/java/duke/TaskList.java @@ -5,9 +5,9 @@ public interface TaskList { void printToDo() throws CommandException; void printEvent() throws CommandException; void printDeadline() throws CommandException; - void addTodo(String description); - void addEvent(String description, String time); - void addDeadline(String description, String deadline); - void completeTask(int t) throws CommandException; + void addTodo(String description, boolean isFromFile); + void addEvent(String description, String time, boolean isFromFile); + void addDeadline(String description, String deadline, boolean isFromFile); + void completeTask(int t, boolean isFromFile) throws CommandException; int getListSize(); } diff --git a/src/main/java/duke/task/Deadline.java b/src/main/java/duke/task/Deadline.java index 485e17c4b..d69335883 100644 --- a/src/main/java/duke/task/Deadline.java +++ b/src/main/java/duke/task/Deadline.java @@ -14,4 +14,9 @@ public Deadline(String description, String dueDate){ public String toString(){ return TASK_SYMBOL + super.toString() + "(by: " + dueDate + ")"; } + + @Override + public String toFile(){ + return TASK_SYMBOL + SEPARATOR + super.toFile() + SEPARATOR + dueDate + System.lineSeparator(); + } } diff --git a/src/main/java/duke/task/Event.java b/src/main/java/duke/task/Event.java index de41247f6..88c7dbef5 100644 --- a/src/main/java/duke/task/Event.java +++ b/src/main/java/duke/task/Event.java @@ -14,4 +14,9 @@ public Event(String description, String startTime){ public String toString(){ return TASK_SYMBOL + super.toString() + "(at:" + startTime + ")"; } + + @Override + public String toFile(){ + return TASK_SYMBOL + SEPARATOR + super.toString() + SEPARATOR + startTime + System.lineSeparator(); + } } diff --git a/src/main/java/duke/task/Task.java b/src/main/java/duke/task/Task.java index 3c660700b..058822daf 100644 --- a/src/main/java/duke/task/Task.java +++ b/src/main/java/duke/task/Task.java @@ -3,10 +3,11 @@ import duke.TaskInterface; public class Task implements TaskInterface { - private static final String completeStatusIcon = "[X]"; - private static final String incompleteStatusIcon = "[ ]"; + private static final String COMPLETE_STATUS_ICON = "[X]"; + private static final String INCOMPLETE_STATUS_ICON = "[ ]"; private final String description; private boolean isDone; + protected static final String SEPARATOR = ";"; public Task(String description){ this.description = description; @@ -22,10 +23,14 @@ public String getDescription(){ } public String getStatusIcon(){ - return(isDone ? completeStatusIcon : incompleteStatusIcon); + return(isDone ? COMPLETE_STATUS_ICON : INCOMPLETE_STATUS_ICON); } public String toString(){ return getStatusIcon() + description; } + + public String toFile(){ + return getStatusIcon() + SEPARATOR + description; + } } diff --git a/src/main/java/duke/task/ToDo.java b/src/main/java/duke/task/ToDo.java index a113a4dfb..b16728be6 100644 --- a/src/main/java/duke/task/ToDo.java +++ b/src/main/java/duke/task/ToDo.java @@ -12,4 +12,9 @@ public ToDo(String description){ public String toString() { return TASK_SYMBOL + super.toString(); } + + @Override + public String toFile(){ + return TASK_SYMBOL + SEPARATOR + super.toFile() +System.lineSeparator(); + } } diff --git a/text-ui-test/EXPECTED.txt b/text-ui-test/EXPECTED.txt index 019693f50..fdd68277b 100644 --- a/text-ui-test/EXPECTED.txt +++ b/text-ui-test/EXPECTED.txt @@ -43,15 +43,6 @@ Got it. I've added this task: Now you have 5 tasks in the list. ____________________________________________________________ ____________________________________________________________ -List of Commands: - echo - Repeat whatever was typed - !echo to repeat in art form - list - Display List - !list for details - todo - Add ToDo Task - event - Add Event Task - !event for details - deadline - Add Deadline Task - !deadline for details - bye - Shut Down -____________________________________________________________ -____________________________________________________________ Here are the tasks in your list: 1. [T][ ]watch et1231 livestream 2. [T][ ]watch hankyuu livestream @@ -60,11 +51,10 @@ Here are the tasks in your list: 5. [E][ ]g2 vs sentinel(at:12am) ____________________________________________________________ ____________________________________________________________ -Nice! I've marked this task as done: [T][X]watch et1231 livestream -____________________________________________________________ -Nice! I've marked this task as done: [T][X]watch hankyuu livestream -____________________________________________________________ -Nice! I've marked this task as done: [D][X]reach radiant(by: this season) +Nice! I've marked this task as done: +[T][X]watch et1231 livestream +[T][X]watch hankyuu livestream +[D][X]reach radiant(by: this season) ____________________________________________________________ Here are the tasks in your list: 1. [T][X]watch et1231 livestream @@ -74,7 +64,8 @@ Here are the tasks in your list: 5. [E][ ]g2 vs sentinel(at:12am) ____________________________________________________________ ____________________________________________________________ -Noted. I've removed this task: [T][X]watch et1231 livestream +Noted. I've removed this task: +[T][X]watch et1231 livestream Now you have 4 tasks in the list. ____________________________________________________________ ____________________________________________________________ @@ -84,6 +75,32 @@ Here are the tasks in your list: 3. [D][X]reach radiant(by: this season) 4. [E][ ]g2 vs sentinel(at:12am) ____________________________________________________________ +☹ OOPS!!! I'm sorry, but I don't know what that means :-( +Defaulting to Echo. Type !help to see the list of Commands +____________________________________________________________ +random command +____________________________________________________________ +____________________________________________________________ +List of Commands: + echo - Repeat whatever was typed - !echo to repeat in art form + list - Display List - !list for details + todo - Add ToDo Task + event - Add Event Task - !event for details + deadline - Add Deadline Task - !deadline for details + bye - Shut Down +____________________________________________________________ +____________________________________________________________ +list displays all tasks +list todo displays all todo tasks +list event displays all event tasks +list deadline displays all deadline tasks +____________________________________________________________ +____________________________________________________________ +event command requires a timing indicated using "at" [timing] +____________________________________________________________ +____________________________________________________________ +deadline command requires a end time indicated using "by"[end time] +____________________________________________________________ ____________________________________________________________ Bye. Hope to see you again soon! ____________________________________________________________ diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index 46a629146..b6cbef585 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -1,12 +1,17 @@ echo Hi !echo hi +list todo watch et1231 livestream todo watch hankyuu livestream todo watch haxxnini livestream deadline reach radiant by this season event G2 vs Sentinel at 12am -!help list done 1,2,4 delete 1 list +random command +!help +!list +!event +!deadline bye \ No newline at end of file diff --git a/text-ui-test/runtest.sh b/text-ui-test/runtest.sh deleted file mode 100644 index c9ec87003..000000000 --- a/text-ui-test/runtest.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env bash - -# create bin directory if it doesn't exist -if [ ! -d "../bin" ] -then - mkdir ../bin -fi - -# delete output from previous run -if [ -e "./ACTUAL.TXT" ] -then - rm ACTUAL.TXT -fi - -# compile the code into the bin folder, terminates if error occurred -if ! javac -cp ../src/main/java -Xlint:none -d ../bin ../src/main/java/*.java -then - echo "********** BUILD FAILURE **********" - exit 1 -fi - -# run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT -java -classpath ../bin Duke < input.txt > ACTUAL.TXT - -# convert to UNIX format -cp EXPECTED.TXT EXPECTED-UNIX.TXT -dos2unix ACTUAL.TXT EXPECTED-UNIX.TXT - -# compare the output to the expected output -diff ACTUAL.TXT EXPECTED-UNIX.TXT -if [ $? -eq 0 ] -then - echo "Test result: PASSED" - exit 0 -else - echo "Test result: FAILED" - exit 1 -fi \ No newline at end of file From ec11a9f68e26da4b649fa62fba9686b1fc732a6d Mon Sep 17 00:00:00 2001 From: wingho2 Date: Wed, 15 Sep 2021 18:13:25 +0800 Subject: [PATCH 19/62] remove some bugged files --- text-ui-test/EXPECTED.TXT | 7 --- text-ui-test/EXPECTED.txt | 111 -------------------------------------- 2 files changed, 118 deletions(-) delete mode 100644 text-ui-test/EXPECTED.TXT delete mode 100644 text-ui-test/EXPECTED.txt diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT deleted file mode 100644 index 657e74f6e..000000000 --- a/text-ui-test/EXPECTED.TXT +++ /dev/null @@ -1,7 +0,0 @@ -Hello from - ____ _ -| _ \ _ _| | _____ -| | | | | | | |/ / _ \ -| |_| | |_| | < __/ -|____/ \__,_|_|\_\___| - diff --git a/text-ui-test/EXPECTED.txt b/text-ui-test/EXPECTED.txt deleted file mode 100644 index fdd68277b..000000000 --- a/text-ui-test/EXPECTED.txt +++ /dev/null @@ -1,111 +0,0 @@ - ____ _ -| _ \ _ _| | _____ -| | | | | | | |/ / _ \ -| |_| | |_| | < __/ -|____/ \__,_|_|\_\___| -____________________________________________________________ -Hello! I'm Duke -What can I do for you? -!help for Command List -____________________________________________________________ -____________________________________________________________ -hi -____________________________________________________________ -HI - ___ ___ .___ - / | \ | | -/ ~ \| | -\ Y /| | - \___|___/ |___| - ____________________________________________________________ - Got it. I've added this task: - [T][ ]watch et1231 livestream - Now you have 1 tasks in the list. - ____________________________________________________________ - ____________________________________________________________ - Got it. I've added this task: - [T][ ]watch hankyuu livestream - Now you have 2 tasks in the list. - ____________________________________________________________ -____________________________________________________________ -Got it. I've added this task: -[T][ ]watch haxxnini livestream -Now you have 3 tasks in the list. -____________________________________________________________ -____________________________________________________________ -Got it. I've added this task: -[D][ ]reach radiant(by: this season) -Now you have 4 tasks in the list. -____________________________________________________________ -____________________________________________________________ -Got it. I've added this task: -[E][ ]g2 vs sentinel(at:12am) -Now you have 5 tasks in the list. -____________________________________________________________ -____________________________________________________________ -Here are the tasks in your list: -1. [T][ ]watch et1231 livestream -2. [T][ ]watch hankyuu livestream -3. [T][ ]watch haxxnini livestream -4. [D][ ]reach radiant(by: this season) -5. [E][ ]g2 vs sentinel(at:12am) -____________________________________________________________ -____________________________________________________________ -Nice! I've marked this task as done: -[T][X]watch et1231 livestream -[T][X]watch hankyuu livestream -[D][X]reach radiant(by: this season) -____________________________________________________________ -Here are the tasks in your list: -1. [T][X]watch et1231 livestream -2. [T][X]watch hankyuu livestream -3. [T][ ]watch haxxnini livestream -4. [D][X]reach radiant(by: this season) -5. [E][ ]g2 vs sentinel(at:12am) -____________________________________________________________ -____________________________________________________________ -Noted. I've removed this task: -[T][X]watch et1231 livestream -Now you have 4 tasks in the list. -____________________________________________________________ -____________________________________________________________ -Here are the tasks in your list: -1. [T][X]watch hankyuu livestream -2. [T][ ]watch haxxnini livestream -3. [D][X]reach radiant(by: this season) -4. [E][ ]g2 vs sentinel(at:12am) -____________________________________________________________ -☹ OOPS!!! I'm sorry, but I don't know what that means :-( -Defaulting to Echo. Type !help to see the list of Commands -____________________________________________________________ -random command -____________________________________________________________ -____________________________________________________________ -List of Commands: - echo - Repeat whatever was typed - !echo to repeat in art form - list - Display List - !list for details - todo - Add ToDo Task - event - Add Event Task - !event for details - deadline - Add Deadline Task - !deadline for details - bye - Shut Down -____________________________________________________________ -____________________________________________________________ -list displays all tasks -list todo displays all todo tasks -list event displays all event tasks -list deadline displays all deadline tasks -____________________________________________________________ -____________________________________________________________ -event command requires a timing indicated using "at" [timing] -____________________________________________________________ -____________________________________________________________ -deadline command requires a end time indicated using "by"[end time] -____________________________________________________________ -____________________________________________________________ -Bye. Hope to see you again soon! -____________________________________________________________ -_______________.___.___________ -\______ \__ | |\_ _____/ - | | _// | | | __)_ - | | \\____ | | \ - |________// ______|/_________/ \ No newline at end of file From 6d21d77f8f32a366991651d6c47a46ec2487535d Mon Sep 17 00:00:00 2001 From: wingho2 Date: Wed, 15 Sep 2021 18:21:22 +0800 Subject: [PATCH 20/62] debugging the file update when there is no task in the array --- duke.txt | 8 +-- src/main/java/duke/Duke.java | 8 ++- text-ui-test/EXPECTED.txt | 120 +++++++++++++++++++++++++++++++++++ text-ui-test/input.txt | 1 + 4 files changed, 130 insertions(+), 7 deletions(-) create mode 100644 text-ui-test/EXPECTED.txt diff --git a/duke.txt b/duke.txt index e2e428b17..77240b135 100644 --- a/duke.txt +++ b/duke.txt @@ -1,4 +1,4 @@ -[T];[ ];watch youtube -[T];[ ];watch -[T];[ ];watch douyin -[T];[ ];tiktok +[T];[X];watch hankyuu livestream +[T];[ ];watch haxxnini livestream +[D];[X];reach radiant;this season +[E];[ ]g2 vs sentinel;12am diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index ca944da6a..053a7fbd2 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -39,9 +39,11 @@ public static void main(String[] args) { }catch(CommandException e){ e.handleException(); } - fileManager.writeToFile(list.get(0),false); - for (int i = 1; i < list.size(); i ++) { - fileManager.writeToFile(list.get(i), true); + if(list.size() != 0) { + fileManager.writeToFile(list.get(0), false); + for (int i = 1; i < list.size(); i++) { + fileManager.writeToFile(list.get(i), true); + } } } } diff --git a/text-ui-test/EXPECTED.txt b/text-ui-test/EXPECTED.txt new file mode 100644 index 000000000..d8711c5de --- /dev/null +++ b/text-ui-test/EXPECTED.txt @@ -0,0 +1,120 @@ + ____ _ +| _ \ _ _| | _____ +| | | | | | | |/ / _ \ +| |_| | |_| | < __/ +|____/ \__,_|_|\_\___| +____________________________________________________________ +Hello! I'm Duke +What can I do for you? +!help for Command List +____________________________________________________________ +____________________________________________________________ +hi +____________________________________________________________ +HI + ___ ___ .___ + / | \ | | +/ ~ \| | +\ Y /| | + \___|___/ |___| + ☹ OOPS!!! List is empty. Add tasks to the list. +____________________________________________________________ +Got it. I've added this task: +[T][ ]watch et1231 livestream +Now you have 1 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Got it. I've added this task: +[T][ ]watch hankyuu livestream +Now you have 2 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Bye. Hope to see you again soon! +____________________________________________________________ +_______________.___.___________ +\______ \__ | |\_ _____/ + | | _// | | | __)_ + | | \\____ | | \ + |________// ______|/_________/ +____________________________________________________________ +Got it. I've added this task: +[T][ ]watch haxxnini livestream +Now you have 3 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Got it. I've added this task: +[D][ ]reach radiant(by: this season) +Now you have 4 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Got it. I've added this task: +[E][ ]g2 vs sentinel(at:12am) +Now you have 5 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Here are the tasks in your list: +1. [T][ ]watch et1231 livestream +2. [T][ ]watch hankyuu livestream +3. [T][ ]watch haxxnini livestream +4. [D][ ]reach radiant(by: this season) +5. [E][ ]g2 vs sentinel(at:12am) +____________________________________________________________ +____________________________________________________________ +Nice! I've marked this task as done: +[T][X]watch et1231 livestream +[T][X]watch hankyuu livestream +[D][X]reach radiant(by: this season) +____________________________________________________________ +Here are the tasks in your list: +1. [T][X]watch et1231 livestream +2. [T][X]watch hankyuu livestream +3. [T][ ]watch haxxnini livestream +4. [D][X]reach radiant(by: this season) +5. [E][ ]g2 vs sentinel(at:12am) +____________________________________________________________ +____________________________________________________________ +Noted. I've removed this task: +[T][X]watch et1231 livestream +Now you have 4 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Here are the tasks in your list: +1. [T][X]watch hankyuu livestream +2. [T][ ]watch haxxnini livestream +3. [D][X]reach radiant(by: this season) +4. [E][ ]g2 vs sentinel(at:12am) +____________________________________________________________ +☹ OOPS!!! I'm sorry, but I don't know what that means :-( +Defaulting to Echo. Type !help to see the list of Commands +____________________________________________________________ +random command +____________________________________________________________ +____________________________________________________________ +List of Commands: + echo - Repeat whatever was typed - !echo to repeat in art form + list - Display List - !list for details + todo - Add ToDo Task + event - Add Event Task - !event for details + deadline - Add Deadline Task - !deadline for details + bye - Shut Down +____________________________________________________________ +____________________________________________________________ +list displays all tasks +list todo displays all todo tasks +list event displays all event tasks +list deadline displays all deadline tasks +____________________________________________________________ +____________________________________________________________ +event command requires a timing indicated using "at" [timing] +____________________________________________________________ +____________________________________________________________ +deadline command requires a end time indicated using "by"[end time] +____________________________________________________________ +____________________________________________________________ +Bye. Hope to see you again soon! +____________________________________________________________ +_______________.___.___________ +\______ \__ | |\_ _____/ + | | _// | | | __)_ + | | \\____ | | \ + |________// ______|/_________/ \ No newline at end of file diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index b6cbef585..c1eb045ff 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -2,6 +2,7 @@ echo Hi !echo hi list todo watch et1231 livestream todo watch hankyuu livestream +bye todo watch haxxnini livestream deadline reach radiant by this season event G2 vs Sentinel at 12am From 8565495942af780e5cffb06329fa7547b5af82ce Mon Sep 17 00:00:00 2001 From: wingho2 Date: Sat, 25 Sep 2021 16:57:08 +0800 Subject: [PATCH 21/62] Change all the commands into their own class --- duke.txt | 7 +- src/main/java/duke/{ => ArtBot}/ArtBot.java | 46 +++- .../java/duke/{ => ArtBot}/ArtInterface.java | 4 +- src/main/java/duke/{ => ArtBot}/Logo.java | 2 +- .../java/duke/Command/AddDeadlineCommand.java | 31 +++ .../java/duke/Command/AddEventCommand.java | 30 ++ .../java/duke/Command/AddToDoCommand.java | 24 ++ src/main/java/duke/Command/ArtCommand.java | 18 ++ src/main/java/duke/Command/Command.java | 46 ++++ src/main/java/duke/Command/CommandGuide.java | 34 +++ src/main/java/duke/Command/DeleteCommand.java | 37 +++ src/main/java/duke/Command/DoneCommand.java | 30 ++ src/main/java/duke/Command/EchoCommand.java | 22 ++ src/main/java/duke/Command/ListCommand.java | 44 +++ src/main/java/duke/CommandInterface.java | 5 - src/main/java/duke/CommandManager.java | 61 ----- src/main/java/duke/Duke.java | 68 ++--- .../{ => ErrorHandling}/CommandException.java | 6 +- .../ErrorStaticString.java} | 27 +- src/main/java/duke/FileManager.java | 82 ------ src/main/java/duke/InputHandler.java | 256 ------------------ src/main/java/duke/InputInterface.java | 5 - src/main/java/duke/Parser/Parser.java | 186 +++++++++++++ src/main/java/duke/Storage/FileRead.java | 63 +++++ src/main/java/duke/Storage/FileWrite.java | 18 ++ src/main/java/duke/Storage/Storage.java | 58 ++++ .../TaskList.java} | 96 +++---- .../TaskListInterface.java} | 6 +- src/main/java/duke/Ui/Ui.java | 38 +++ src/main/java/duke/task/Event.java | 2 +- src/main/java/duke/task/Task.java | 2 - .../java/duke/{ => task}/TaskInterface.java | 2 +- src/main/java/duke/task/ToDo.java | 2 +- 33 files changed, 826 insertions(+), 532 deletions(-) rename src/main/java/duke/{ => ArtBot}/ArtBot.java (72%) rename src/main/java/duke/{ => ArtBot}/ArtInterface.java (54%) rename src/main/java/duke/{ => ArtBot}/Logo.java (99%) create mode 100644 src/main/java/duke/Command/AddDeadlineCommand.java create mode 100644 src/main/java/duke/Command/AddEventCommand.java create mode 100644 src/main/java/duke/Command/AddToDoCommand.java create mode 100644 src/main/java/duke/Command/ArtCommand.java create mode 100644 src/main/java/duke/Command/Command.java create mode 100644 src/main/java/duke/Command/CommandGuide.java create mode 100644 src/main/java/duke/Command/DeleteCommand.java create mode 100644 src/main/java/duke/Command/DoneCommand.java create mode 100644 src/main/java/duke/Command/EchoCommand.java create mode 100644 src/main/java/duke/Command/ListCommand.java delete mode 100644 src/main/java/duke/CommandInterface.java delete mode 100644 src/main/java/duke/CommandManager.java rename src/main/java/duke/{ => ErrorHandling}/CommandException.java (72%) rename src/main/java/duke/{ErrorList.java => ErrorHandling/ErrorStaticString.java} (60%) delete mode 100644 src/main/java/duke/FileManager.java delete mode 100644 src/main/java/duke/InputHandler.java delete mode 100644 src/main/java/duke/InputInterface.java create mode 100644 src/main/java/duke/Parser/Parser.java create mode 100644 src/main/java/duke/Storage/FileRead.java create mode 100644 src/main/java/duke/Storage/FileWrite.java create mode 100644 src/main/java/duke/Storage/Storage.java rename src/main/java/duke/{ListManager.java => TaskList/TaskList.java} (62%) rename src/main/java/duke/{TaskList.java => TaskList/TaskListInterface.java} (82%) create mode 100644 src/main/java/duke/Ui/Ui.java rename src/main/java/duke/{ => task}/TaskInterface.java (85%) diff --git a/duke.txt b/duke.txt index 77240b135..db47ab378 100644 --- a/duke.txt +++ b/duke.txt @@ -1,4 +1,3 @@ -[T];[X];watch hankyuu livestream -[T];[ ];watch haxxnini livestream -[D];[X];reach radiant;this season -[E];[ ]g2 vs sentinel;12am +[T];[ ];watch hank +[T];[ ];watch haxxnini +[T];[ ];watch nats diff --git a/src/main/java/duke/ArtBot.java b/src/main/java/duke/ArtBot/ArtBot.java similarity index 72% rename from src/main/java/duke/ArtBot.java rename to src/main/java/duke/ArtBot/ArtBot.java index b46cf2a6b..b1ced689f 100644 --- a/src/main/java/duke/ArtBot.java +++ b/src/main/java/duke/ArtBot/ArtBot.java @@ -1,8 +1,11 @@ -package duke; +package duke.ArtBot; + +import duke.ErrorHandling.CommandException; +import duke.ErrorHandling.ErrorStaticString; import java.util.ArrayList; -public class ArtBot implements ArtInterface{ +public class ArtBot implements ArtInterface { private final String userInput; @@ -128,27 +131,46 @@ private String[] getLogo(String letter){ return letterArt; } - public void drawArt() throws CommandException{ - String[] charArray = userInput.split("(?!^)"); - ArrayList artArray = new ArrayList<>(); - String[] mergeString = new String[5]; - for(String s:charArray){ + private ArrayList getLetterInArtForm(String[] inputArrayOfLetter) throws CommandException{ + ArrayList listToStoreLetterInArtForm = new ArrayList<>(); + for(String s:inputArrayOfLetter){ String[] letterInArtForm = getLogo(s); if(letterInArtForm == null){ - throw new CommandException(ErrorList.ERROR_LETTER_NOT_FOUND); + throw new CommandException(ErrorStaticString.ERROR_LETTER_NOT_FOUND); } - artArray.add(letterInArtForm); + listToStoreLetterInArtForm.add(letterInArtForm); } + return listToStoreLetterInArtForm; + } + + private String[] mergeArray(ArrayList arrayToMerge){ + String[] arrayToReturn = new String[5]; for(int i = 0; i < 5; i++){ StringBuilder sb = new StringBuilder(); - for (String[] strings : artArray) { + for (String[] strings : arrayToMerge) { String temp = strings[i]; sb.append(temp); } - mergeString[i] = sb.toString(); + arrayToReturn[i] = sb.toString(); } + return arrayToReturn; + } + + private void printArray(String[] array){ for(int i = 0; i < 5; i++){ - System.out.println(mergeString[i]); + System.out.println(array[i]); + } + } + + public void drawArt() { + String[] letterArray = userInput.split("(?!^)"); + ArrayList letterInArtFormList = null; + try { + letterInArtFormList = getLetterInArtForm(letterArray); + } catch (CommandException e) { + e.handleException(); } + String[] mergeLetterHorizontallyArray = mergeArray(letterInArtFormList); + printArray(mergeLetterHorizontallyArray); } } diff --git a/src/main/java/duke/ArtInterface.java b/src/main/java/duke/ArtBot/ArtInterface.java similarity index 54% rename from src/main/java/duke/ArtInterface.java rename to src/main/java/duke/ArtBot/ArtInterface.java index d061d470d..2169cb880 100644 --- a/src/main/java/duke/ArtInterface.java +++ b/src/main/java/duke/ArtBot/ArtInterface.java @@ -1,4 +1,6 @@ -package duke; +package duke.ArtBot; + +import duke.ErrorHandling.CommandException; public interface ArtInterface { void drawArt() throws CommandException; diff --git a/src/main/java/duke/Logo.java b/src/main/java/duke/ArtBot/Logo.java similarity index 99% rename from src/main/java/duke/Logo.java rename to src/main/java/duke/ArtBot/Logo.java index a7e41e8c3..3c302a5d6 100644 --- a/src/main/java/duke/Logo.java +++ b/src/main/java/duke/ArtBot/Logo.java @@ -1,4 +1,4 @@ -package duke; +package duke.ArtBot; public class Logo { public static final String divider = "____________________________________________________________\n"; diff --git a/src/main/java/duke/Command/AddDeadlineCommand.java b/src/main/java/duke/Command/AddDeadlineCommand.java new file mode 100644 index 000000000..fe136e038 --- /dev/null +++ b/src/main/java/duke/Command/AddDeadlineCommand.java @@ -0,0 +1,31 @@ +package duke.Command; + +import duke.ErrorHandling.CommandException; +import duke.ErrorHandling.ErrorStaticString; +import duke.Storage.Storage; +import duke.TaskList.TaskList; + +public class AddDeadlineCommand extends Command{ + + private final TaskList listManager; + + public AddDeadlineCommand(String taskInput, TaskList listManager){ + super(taskInput); + this.listManager = listManager; + } + + @Override + public void executeCommand() throws CommandException { + String taskDescription = taskInput.replaceFirst(COMMAND_ADD_DEADLINE, EMPTY_STRING).trim(); + if(!taskDescription.contains(DEADLINE_DATE)){ + throw new CommandException(ErrorStaticString.ERROR_EMPTY_DEADLINE_TIME); + } + int startOfDeadlineDate = taskDescription.indexOf(DEADLINE_DATE); + String deadlineDescription = taskDescription.substring(START_OF_STRING,startOfDeadlineDate).trim(); + if(deadlineDescription.isEmpty()){ + throw new CommandException(ErrorStaticString.ERROR_EMPTY_DEADLINE_INPUT); + } + String deadlineDate = taskDescription.replaceFirst(deadlineDescription, EMPTY_STRING).replaceFirst(DEADLINE_DATE,EMPTY_STRING).strip(); + listManager.addDeadline(deadlineDescription,deadlineDate, false); + } +} diff --git a/src/main/java/duke/Command/AddEventCommand.java b/src/main/java/duke/Command/AddEventCommand.java new file mode 100644 index 000000000..10d8a9941 --- /dev/null +++ b/src/main/java/duke/Command/AddEventCommand.java @@ -0,0 +1,30 @@ +package duke.Command; + +import duke.ErrorHandling.CommandException; +import duke.ErrorHandling.ErrorStaticString; +import duke.TaskList.TaskList; + +public class AddEventCommand extends Command{ + + private final TaskList listManager; + + public AddEventCommand(String taskInput, TaskList listManager){ + super(taskInput); + this.listManager = listManager; + } + + @Override + public void executeCommand() throws CommandException { + String taskDescription = taskInput.replaceFirst(COMMAND_ADD_EVENT, EMPTY_STRING).trim(); + if(!taskDescription.contains(EVENT_TIME)){ + throw new CommandException(ErrorStaticString.ERROR_EMPTY_EVENT_TIME); + } + int startOfEventTime = taskDescription.indexOf(EVENT_TIME); + String eventDescription = taskDescription.substring(START_OF_STRING,startOfEventTime).trim(); + if(eventDescription.isEmpty()){ + throw new CommandException(ErrorStaticString.ERROR_EMPTY_EVENT_INPUT); + } + String eventTime = taskDescription.replaceFirst(eventDescription, EMPTY_STRING).replaceFirst(EVENT_TIME,EMPTY_STRING).strip(); + listManager.addEvent(eventDescription,eventTime, false); + } +} diff --git a/src/main/java/duke/Command/AddToDoCommand.java b/src/main/java/duke/Command/AddToDoCommand.java new file mode 100644 index 000000000..a6d9f0e52 --- /dev/null +++ b/src/main/java/duke/Command/AddToDoCommand.java @@ -0,0 +1,24 @@ +package duke.Command; + +import duke.ErrorHandling.CommandException; +import duke.ErrorHandling.ErrorStaticString; +import duke.TaskList.TaskList; + +public class AddToDoCommand extends Command{ + + private final TaskList listManager; + + public AddToDoCommand(String taskInput, TaskList listManager){ + super(taskInput); + this.listManager = listManager; + } + + @Override + public void executeCommand() throws CommandException{ + String removeCommand = taskInput.replaceFirst(COMMAND_ADD_TODO, EMPTY_STRING).trim(); + if(removeCommand.isEmpty()){ + throw new CommandException(ErrorStaticString.ERROR_EMPTY_TODO_INPUT); + } + listManager.addTodo(removeCommand,false); + } +} diff --git a/src/main/java/duke/Command/ArtCommand.java b/src/main/java/duke/Command/ArtCommand.java new file mode 100644 index 000000000..46713f9dd --- /dev/null +++ b/src/main/java/duke/Command/ArtCommand.java @@ -0,0 +1,18 @@ +package duke.Command; + +import duke.ArtBot.ArtBot; + +public class ArtCommand extends CommandGuide{ + + + public ArtCommand(String userInput){ + super(userInput); + } + + public void handleArtCommand(){ + String removeCommand = taskInput.replaceFirst(COMMAND_ECHO_ART,EMPTY_STRING).trim().toUpperCase(); + System.out.println(removeCommand); + ArtBot artBot = new ArtBot(removeCommand); + artBot.drawArt(); + } +} diff --git a/src/main/java/duke/Command/Command.java b/src/main/java/duke/Command/Command.java new file mode 100644 index 000000000..bcc8d1e97 --- /dev/null +++ b/src/main/java/duke/Command/Command.java @@ -0,0 +1,46 @@ +package duke.Command; + +import duke.ErrorHandling.CommandException; + +public abstract class Command { + protected static final String COMMAND_HELP = "!help"; + protected static final String COMMAND_LIST_HELP = "!list"; + protected static final String COMMAND_EVENT_HELP = "!event"; + protected static final String COMMAND_ECHO_ART = "!echo"; + protected static final String COMMAND_DEADLINE_HELP = "!deadline"; + protected static final String COMMAND_VIEW_LIST = "list"; + protected static final String COMMAND_ECHO = "echo"; + protected static final String COMMAND_COMPLETE_TASK = "done"; + protected static final String COMMAND_ADD_TODO = "todo"; + protected static final String COMMAND_ADD_EVENT = "event"; + protected static final String COMMAND_ADD_DEADLINE = "deadline"; + protected static final String COMMAND_DELETE = "delete"; + protected static final String EVENT_TIME = "at "; + protected static final String DEADLINE_DATE = "by "; + protected static final String MESSAGE_TASK_COMPLETE = "Nice! I've marked this task as done: "; + protected static final String EMPTY_STRING = ""; + protected static final String SEPARATOR = ","; + protected static final int START_OF_STRING = 0; + + protected static final String MESSAGE_HELP = "List of Commands:\n" + + " echo - Repeat whatever was typed - !echo to repeat in art form\n" + + " list - Display List - !list for details\n" + + " todo - Add ToDo Task\n" + + " event - Add Event Task - !event for details\n" + + " deadline - Add Deadline Task - !deadline for details\n" + + " bye - Shut Down\n"; + protected static final String MESSAGE_LIST_HELP = "list displays all tasks\n" + + "list todo displays all todo tasks\n" + + "list event displays all event tasks\n" + + "list deadline displays all deadline tasks\n"; + protected static final String MESSAGE_EVENT_HELP = "event command requires a timing indicated using \"at\" [timing]\n"; + protected static final String MESSAGE_DEADLINE_HELP = "deadline command requires a end time indicated using \"by\"[end time]\n"; + + protected String taskInput; + + public Command(String taskInput){ + this.taskInput = taskInput; + } + + public abstract void executeCommand() throws CommandException; +} diff --git a/src/main/java/duke/Command/CommandGuide.java b/src/main/java/duke/Command/CommandGuide.java new file mode 100644 index 000000000..77e361ac3 --- /dev/null +++ b/src/main/java/duke/Command/CommandGuide.java @@ -0,0 +1,34 @@ +package duke.Command; + +import duke.ArtBot.Logo; + +public class CommandGuide extends Command{ + + + public CommandGuide(String userInput){ + super(userInput); + } + + @Override + public void executeCommand(){ + if(taskInput.startsWith(COMMAND_ECHO_ART)){ + ArtCommand artCommand = new ArtCommand(taskInput); + artCommand.handleArtCommand(); + return; + } + switch(taskInput) { + case COMMAND_HELP: + System.out.println(Logo.divider + MESSAGE_HELP + Logo.dividerWithoutNewLine); + break; + case COMMAND_LIST_HELP: + System.out.println(Logo.divider + MESSAGE_LIST_HELP + Logo.dividerWithoutNewLine); + break; + case COMMAND_EVENT_HELP: + System.out.println(Logo.divider + MESSAGE_EVENT_HELP + Logo.dividerWithoutNewLine); + break; + case COMMAND_DEADLINE_HELP: + System.out.println(Logo.divider + MESSAGE_DEADLINE_HELP + Logo.dividerWithoutNewLine); + break; + } + } +} diff --git a/src/main/java/duke/Command/DeleteCommand.java b/src/main/java/duke/Command/DeleteCommand.java new file mode 100644 index 000000000..46640c7bc --- /dev/null +++ b/src/main/java/duke/Command/DeleteCommand.java @@ -0,0 +1,37 @@ +package duke.Command; + +import duke.ArtBot.Logo; +import duke.ErrorHandling.CommandException; +import duke.TaskList.TaskList; + +import java.util.ArrayList; +import java.util.Collections; + +public class DeleteCommand extends Command{ + + private final TaskList listManager; + + public DeleteCommand(String userInput, TaskList listManager){ + super(userInput); + this.listManager = listManager; + } + + @Override + public void executeCommand()throws CommandException { + String removeCommand = taskInput.replaceFirst(COMMAND_DELETE,EMPTY_STRING).trim(); + String[] taskDoneArray = removeCommand.split(SEPARATOR); + ArrayList intArray = new ArrayList(); + for (String s: taskDoneArray){ + int taskDoneIndex = Integer.parseInt(s); + intArray.add(taskDoneIndex - 1); + } + Collections.sort(intArray, Collections.reverseOrder()); + for (Integer i: intArray) { + try { + listManager.deleteTask(i); + }catch (CommandException e){ + e.handleException(); + } + } + } +} diff --git a/src/main/java/duke/Command/DoneCommand.java b/src/main/java/duke/Command/DoneCommand.java new file mode 100644 index 000000000..2f2df8e27 --- /dev/null +++ b/src/main/java/duke/Command/DoneCommand.java @@ -0,0 +1,30 @@ +package duke.Command; + +import duke.ArtBot.Logo; +import duke.ErrorHandling.CommandException; +import duke.TaskList.TaskList; + +public class DoneCommand extends Command{ + + private final TaskList listManager; + + public DoneCommand(String userInput, TaskList listManager){ + super(userInput); + this.listManager = listManager; + } + + @Override + public void executeCommand(){ + String removeCommand = taskInput.replaceFirst(COMMAND_COMPLETE_TASK,EMPTY_STRING).trim(); + String[] taskDoneArray = removeCommand.split(SEPARATOR); + System.out.println(MESSAGE_TASK_COMPLETE); + for (String s: taskDoneArray) { + int taskDoneIndex = Integer.parseInt(s); + try { + listManager.completeTask(taskDoneIndex - 1, false); + }catch (CommandException e){ + e.handleException(); + } + } + } +} diff --git a/src/main/java/duke/Command/EchoCommand.java b/src/main/java/duke/Command/EchoCommand.java new file mode 100644 index 000000000..1cb2b9e77 --- /dev/null +++ b/src/main/java/duke/Command/EchoCommand.java @@ -0,0 +1,22 @@ +package duke.Command; + +import duke.ArtBot.Logo; +import duke.ErrorHandling.CommandException; +import duke.ErrorHandling.ErrorStaticString; + +public class EchoCommand extends Command{ + + + public EchoCommand(String userInput){ + super(userInput); + } + + public void executeCommand() throws CommandException { + String removeCommand = taskInput.replaceFirst(COMMAND_ECHO_ART, EMPTY_STRING).trim(); + if(removeCommand.isEmpty()){ + throw new CommandException(ErrorStaticString.ERROR_EMPTY_ECHO_INPUT); + } + System.out.println(removeCommand); + } + +} diff --git a/src/main/java/duke/Command/ListCommand.java b/src/main/java/duke/Command/ListCommand.java new file mode 100644 index 000000000..715cb97f1 --- /dev/null +++ b/src/main/java/duke/Command/ListCommand.java @@ -0,0 +1,44 @@ +package duke.Command; + +import duke.ArtBot.Logo; +import duke.ErrorHandling.CommandException; +import duke.ErrorHandling.ErrorStaticString; +import duke.TaskList.TaskList; + +public class ListCommand extends Command{ + + private final TaskList listManager; + + public ListCommand(String userInput, TaskList listManager){ + super(userInput); + this.listManager = listManager; + } + + public void executeCommand() throws CommandException { + if(listManager.getListSize() == 0){ + throw new CommandException(ErrorStaticString.ERROR_EMPTY_LIST); + } + String removeCommand = taskInput.replaceFirst(COMMAND_VIEW_LIST,EMPTY_STRING).trim(); + if(removeCommand.contains(COMMAND_ADD_TODO)){ + try { + listManager.printToDo(); + }catch (CommandException e){ + e.handleException(); + } + }else if(removeCommand.contains(COMMAND_ADD_EVENT)) { + try { + listManager.printEvent(); + }catch (CommandException e){ + e.handleException(); + } + }else if(removeCommand.contains(COMMAND_ADD_DEADLINE)){ + try { + listManager.printDeadline(); + }catch (CommandException e){ + e.handleException(); + } + }else { + listManager.printList(); + } + } +} diff --git a/src/main/java/duke/CommandInterface.java b/src/main/java/duke/CommandInterface.java deleted file mode 100644 index 1a467afb1..000000000 --- a/src/main/java/duke/CommandInterface.java +++ /dev/null @@ -1,5 +0,0 @@ -package duke; - -public interface CommandInterface { - void handleCommand(); -} diff --git a/src/main/java/duke/CommandManager.java b/src/main/java/duke/CommandManager.java deleted file mode 100644 index 9bb9a1798..000000000 --- a/src/main/java/duke/CommandManager.java +++ /dev/null @@ -1,61 +0,0 @@ -package duke; - -public class CommandManager implements CommandInterface{ - - private static final String COMMAND_HELP = "!help"; - private static final String COMMAND_LIST_HELP = "!list"; - private static final String COMMAND_EVENT_HELP = "!event"; - private static final String COMMAND_DEADLINE_HELP = "!deadline"; - private static final String COMMAND_ECHO = "!echo"; - private static final String MESSAGE_HELP = "List of Commands:\n" + - " echo - Repeat whatever was typed - !echo to repeat in art form\n" + - " list - Display List - !list for details\n" + - " todo - Add ToDo Task\n" + - " event - Add Event Task - !event for details\n" + - " deadline - Add Deadline Task - !deadline for details\n" + - " bye - Shut Down\n"; - private static final String MESSAGE_LIST_HELP = "list displays all tasks\n" + - "list todo displays all todo tasks\n" + - "list event displays all event tasks\n" + - "list deadline displays all deadline tasks\n"; - private static final String MESSAGE_EVENT_HELP = "event command requires a timing indicated using \"at\" [timing]\n"; - private static final String MESSAGE_DEADLINE_HELP = "deadline command requires a end time indicated using \"by\"[end time]\n"; - - private final String description; - - public CommandManager(String description){ - this.description = description; - } - - private void handleArtCommand(){ - String removeCommand = description.replaceFirst(COMMAND_ECHO,"").trim().toUpperCase(); - System.out.println(removeCommand); - ArtBot artBot = new ArtBot(removeCommand); - try { - artBot.drawArt(); - }catch (CommandException e){ - e.handleException(); - } - } - - public void handleCommand(){ - if(description.startsWith(COMMAND_ECHO)){ - handleArtCommand(); - return; - } - switch(description) { - case COMMAND_HELP: - System.out.println(Logo.divider + MESSAGE_HELP + Logo.dividerWithoutNewLine); - break; - case COMMAND_LIST_HELP: - System.out.println(Logo.divider + MESSAGE_LIST_HELP + Logo.dividerWithoutNewLine); - break; - case COMMAND_EVENT_HELP: - System.out.println(Logo.divider + MESSAGE_EVENT_HELP + Logo.dividerWithoutNewLine); - break; - case COMMAND_DEADLINE_HELP: - System.out.println(Logo.divider + MESSAGE_DEADLINE_HELP + Logo.dividerWithoutNewLine); - break; - } - } -} diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 053a7fbd2..7610a1bc7 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,52 +1,42 @@ package duke; -import duke.task.Task; - -import java.util.Scanner; -import java.util.ArrayList; +import duke.ErrorHandling.CommandException; +import duke.Parser.Parser; +import duke.Storage.Storage; +import duke.TaskList.TaskList; +import duke.Ui.Ui; public class Duke { - private static final String MESSAGE_HI = "Hello! I'm Duke\n" + "What can I do for you?\n" + "!help for Command List\n"; - private static final String MESSAGE_BYE = "Bye. Hope to see you again soon!\n"; - protected static boolean isOnline; + private final TaskList tasks; + private final Ui ui; - private static void startDuke(){ - isOnline = true; - System.out.println(Logo.logo +Logo.divider + MESSAGE_HI + Logo.dividerWithoutNewLine); + public Duke(){ + ui = new Ui(); + Storage storage = new Storage(); + tasks = new TaskList(storage.load()); } - private static void endDuke(){ - System.out.println(Logo.divider + MESSAGE_BYE + Logo.divider + Logo.bye); + public void run(){ + ui.Greetings(); + boolean isExit = false; + do { + try { + String fullCommand = ui.readCommand(); + ui.showLineWithoutNewLine(); + Parser parser = new Parser(fullCommand, tasks); + isExit = parser.isExit(); + parser.handleInput(); + }catch(CommandException e){ + ui.showError(e.getErrorMessage()); + }finally { + ui.showLine(); + } + }while (!isExit); + ui.Farewell(); } public static void main(String[] args) { - startDuke(); - Scanner in = new Scanner(System.in); - ArrayList list = new ArrayList<>(); - ListManager listManager = new ListManager(list); - FileManager fileManager = new FileManager(listManager); - fileManager.covertStringToTask(); - while(isOnline) { - String userInput = in.nextLine().toLowerCase().trim(); - if (userInput.startsWith("!")) { - CommandManager commandManager = new CommandManager(userInput); - commandManager.handleCommand(); - } else { - InputHandler inputManager = new InputHandler(userInput, listManager, fileManager); - try { - inputManager.handleInput(); - }catch(CommandException e){ - e.handleException(); - } - if(list.size() != 0) { - fileManager.writeToFile(list.get(0), false); - for (int i = 1; i < list.size(); i++) { - fileManager.writeToFile(list.get(i), true); - } - } - } - } - endDuke(); + new Duke().run(); } } diff --git a/src/main/java/duke/CommandException.java b/src/main/java/duke/ErrorHandling/CommandException.java similarity index 72% rename from src/main/java/duke/CommandException.java rename to src/main/java/duke/ErrorHandling/CommandException.java index 8a14ff1ef..fc4c01778 100644 --- a/src/main/java/duke/CommandException.java +++ b/src/main/java/duke/ErrorHandling/CommandException.java @@ -1,4 +1,4 @@ -package duke; +package duke.ErrorHandling; public class CommandException extends Exception{ @@ -11,4 +11,8 @@ public CommandException(String errorMessage){ public void handleException(){ System.out.println(errorMessage); } + + public String getErrorMessage(){ + return errorMessage; + } } diff --git a/src/main/java/duke/ErrorList.java b/src/main/java/duke/ErrorHandling/ErrorStaticString.java similarity index 60% rename from src/main/java/duke/ErrorList.java rename to src/main/java/duke/ErrorHandling/ErrorStaticString.java index 61179c96d..1b8c26e07 100644 --- a/src/main/java/duke/ErrorList.java +++ b/src/main/java/duke/ErrorHandling/ErrorStaticString.java @@ -1,20 +1,23 @@ -package duke; +package duke.ErrorHandling; -public class ErrorList { +public class ErrorStaticString { public static final String ERROR_NULL = "☹ OOPS!!! Input cannot be empty."; public static final String ERROR_UNKNOWN_COMMAND = "☹ OOPS!!! I'm sorry, but I don't know what that means :-(\n" + "" + - "Defaulting to Echo. Type !help to see the list of Commands"; + "Defaulting to Echo. Type !help to see the list of Commands\n"; public static final String ERROR_EMPTY_LIST = "☹ OOPS!!! List is empty. Add tasks to the list."; public static final String ERROR_EMPTY_TODO_LIST = "☹ OOPS!!! There is no To Do task in list. Add To Do tasks to the list."; public static final String ERROR_EMPTY_EVENT_LIST = "☹ OOPS!!! There is no Event task in list. Add Events to the list."; public static final String ERROR_EMPTY_DEADLINE_LIST = "☹ OOPS!!! There is no Deadline task in list. Add Deadlines to the list."; - public static final String ERROR_EMPTY_TODO_INPUT = "☹ OOPS!!! The description of a todo cannot be empty.\n"; - public static final String ERROR_EMPTY_EVENT_INPUT = "☹ OOPS!!! The description of a event cannot be empty.\n"; - public static final String ERROR_EMPTY_DEADLINE_INPUT = "☹ OOPS!!! The description of a deadline cannot be empty.\n"; - public static final String ERROR_EMPTY_ECHO_INPUT = "☹ OOPS!!! The description of a echo cannot be empty.\n"; - public static final String ERROR_EMPTY_EVENT_TIME = "☹ OOPS!!! The timing of a event cannot be empty.\n"; - public static final String ERROR_EMPTY_DEADLINE_TIME = "☹ OOPS!!! The due date of a deadline cannot be empty.\n"; - public static final String ERROR_DONE_TASK_NOT_IN_LIST ="☹ OOPS!!! Task done not found in list\n"; - public static final String ERROR_DELETE_TASK ="☹ OOPS!!! Cannot remove task that does not exist.\n"; - public static final String ERROR_LETTER_NOT_FOUND = "☹ OOPS!!! Something went wrong. Do not input space or symbols.\n"; + public static final String ERROR_EMPTY_TODO_INPUT = "☹ OOPS!!! The description of a todo cannot be empty."; + public static final String ERROR_EMPTY_EVENT_INPUT = "☹ OOPS!!! The description of a event cannot be empty."; + public static final String ERROR_EMPTY_DEADLINE_INPUT = "☹ OOPS!!! The description of a deadline cannot be empty."; + public static final String ERROR_EMPTY_ECHO_INPUT = "☹ OOPS!!! The description of a echo cannot be empty."; + public static final String ERROR_EMPTY_EVENT_TIME = "☹ OOPS!!! The timing of a event cannot be empty."; + public static final String ERROR_EMPTY_DEADLINE_TIME = "☹ OOPS!!! The due date of a deadline cannot be empty."; + public static final String ERROR_DONE_TASK_NOT_IN_LIST ="☹ OOPS!!! Task done not found in list"; + public static final String ERROR_DELETE_TASK ="☹ OOPS!!! Cannot remove task that does not exist."; + public static final String ERROR_LETTER_NOT_FOUND = "☹ OOPS!!! Something went wrong. Do not input space or symbols."; + public static final String ERROR_FILE_MESSAGE_CREATION = "Something went wrong with creating files"; + public static final String ERROR_FILE_MESSAGE_READING = "Something went wrong with reading the files"; + public static final String ERROR_FILE_MESSAGE_WRITING = "Something went wrong with writing to the files"; } diff --git a/src/main/java/duke/FileManager.java b/src/main/java/duke/FileManager.java deleted file mode 100644 index 9a9bcaa70..000000000 --- a/src/main/java/duke/FileManager.java +++ /dev/null @@ -1,82 +0,0 @@ -package duke; - -import duke.task.Event; -import duke.task.Task; -import duke.task.ToDo; - -import java.io.File; -import java.io.FileWriter; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Scanner; - -public class FileManager { - - private static final String FILE_NAME = "duke.txt"; - private static final String FILE_CREATED = "File created to store data: "; - - private File file; - private final ListManager listManager; - - public FileManager(ListManager listManager){ - this.listManager = listManager; - try{ - file = new File(FILE_NAME); - if(file.createNewFile()){ - System.out.println(FILE_CREATED + file.getName() + System.lineSeparator() + file.getAbsolutePath()); - } - }catch(IOException e){ - e.printStackTrace(); - } - } - - private ArrayList readFile(){ - ArrayList list = new ArrayList<>(); - try { - Scanner scanner = new Scanner(file); - while(scanner.hasNext()){ - list.add(scanner.nextLine()); - } - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - return list; - } - - public void covertStringToTask() { - ArrayList stringList = readFile(); - int index = 0; - for (String s : stringList) { - String[] splitString = s.split(";"); - switch (splitString[0]){ - case "[T]": - listManager.addTodo(splitString[2], true); - break; - case "[E]": - listManager.addEvent(splitString[2],splitString[3], true); - break; - case"[D]": - listManager.addDeadline(splitString[2],splitString[3], true); - } - if (splitString[1].equals("[X]")){ - try { - listManager.completeTask(index, true); - } catch (CommandException e) { - e.handleException(); - } - } - index += 1; - } - } - - public void writeToFile(Task t, boolean isAppend){ - try { - FileWriter fileWriter = new FileWriter(file, isAppend); - fileWriter.write(t.toFile()); - fileWriter.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } -} diff --git a/src/main/java/duke/InputHandler.java b/src/main/java/duke/InputHandler.java deleted file mode 100644 index cdd6fe19c..000000000 --- a/src/main/java/duke/InputHandler.java +++ /dev/null @@ -1,256 +0,0 @@ -package duke; - -import java.util.Objects; - -public class InputHandler implements InputInterface{ - - private static final String COMMAND_EXIT = "bye"; - private static final String COMMAND_VIEW_LIST = "list"; - private static final String COMMAND_ECHO = "echo"; - private static final String COMMAND_COMPLETE_TASK = "done"; - private static final String COMMAND_ADD_TODO = "todo"; - private static final String COMMAND_ADD_EVENT = "event"; - private static final String COMMAND_ADD_DEADLINE = "deadline"; - private static final String EVENT_TIME = "at"; - private static final String DEADLINE_DATE = "by"; - private static final String COMMAND_DELETE = "delete"; - private static final String MESSAGE_TASK_COMPLETE = "Nice! I've marked this task as done: "; - - private String description; - private final ListManager listManager; - private final FileManager fileManager; - - public InputHandler(String description, ListManager listManager, FileManager fileManager){ - this.description = description; - this.listManager = listManager; - this.fileManager = fileManager; - } - - private String taskCategory(String userInput){ - if(userInput.startsWith(COMMAND_EXIT)){ - return COMMAND_EXIT; - } - if(userInput.startsWith(COMMAND_VIEW_LIST)) { - return COMMAND_VIEW_LIST; - } - if(userInput.startsWith(COMMAND_ADD_DEADLINE)){ - return COMMAND_ADD_DEADLINE; - } - if(userInput.startsWith(COMMAND_ADD_TODO)) { - return COMMAND_ADD_TODO; - } - if(userInput.startsWith(COMMAND_ADD_EVENT)){ - return COMMAND_ADD_EVENT; - } - if(userInput.startsWith(COMMAND_COMPLETE_TASK)){ - return COMMAND_COMPLETE_TASK; - } - if (userInput.startsWith(COMMAND_ECHO)){ - return COMMAND_ECHO; - } - if(userInput.startsWith(COMMAND_DELETE)){ - return COMMAND_DELETE; - } - return null; - } - - private void handleEvent(String eventInput) throws CommandException{ - String taskDescription = eventInput.replaceFirst(COMMAND_ADD_EVENT,"").trim(); - if(!taskDescription.contains(EVENT_TIME)){ - throw new CommandException(ErrorList.ERROR_EMPTY_EVENT_TIME); - } - int startOfEventTime = taskDescription.indexOf(EVENT_TIME); - String eventDescription = taskDescription.substring(0,startOfEventTime).trim(); - if(eventDescription.isEmpty()){ - throw new CommandException(ErrorList.ERROR_EMPTY_EVENT_INPUT); - } - String eventTime = taskDescription.replaceFirst(eventDescription,"").replaceFirst(EVENT_TIME,"").strip(); - listManager.addEvent(eventDescription,eventTime, false); - } - - private void handleDeadline(String deadlineInput) throws CommandException{ - String taskDescription = deadlineInput.replaceFirst(COMMAND_ADD_DEADLINE,"").trim(); - if(!taskDescription.contains(DEADLINE_DATE)){ - throw new CommandException(ErrorList.ERROR_EMPTY_DEADLINE_TIME); - } - int startOfDeadlineDate = taskDescription.indexOf(DEADLINE_DATE); - String deadlineDescription = taskDescription.substring(0,startOfDeadlineDate).trim(); - if(deadlineDescription.isEmpty()){ - throw new CommandException(ErrorList.ERROR_EMPTY_DEADLINE_INPUT); - } - String deadlineDate = taskDescription.replaceFirst(deadlineDescription,"").replaceFirst(DEADLINE_DATE,"").strip(); - listManager.addDeadline(deadlineDescription,deadlineDate, false); - } - - private void handleToDo(String toDoInput) throws CommandException{ - String removeCommand = toDoInput.replaceFirst(COMMAND_ADD_TODO,"").trim(); - if(removeCommand.isEmpty()){ - throw new CommandException(ErrorList.ERROR_EMPTY_TODO_INPUT); - } - listManager.addTodo(removeCommand,false); - } - - private void handleDone(String userInput){ - String removeCommand = userInput.replaceFirst(COMMAND_COMPLETE_TASK,"").trim(); - String[] taskDoneArray = removeCommand.split(","); - System.out.println(Logo.dividerWithoutNewLine + System.lineSeparator() + MESSAGE_TASK_COMPLETE); - for (String s: taskDoneArray) { - int taskDoneIndex = Integer.parseInt(s); - try { - listManager.completeTask(taskDoneIndex - 1, false); - }catch (CommandException e){ - e.handleException(); - } - } - System.out.println(Logo.dividerWithoutNewLine); - } - - private void handleEcho(String userInput) throws CommandException{ - String removeCommand = userInput.replaceFirst(COMMAND_ECHO,"").trim(); - if(removeCommand.isEmpty()){ - throw new CommandException(ErrorList.ERROR_EMPTY_ECHO_INPUT); - } - System.out.println(Logo.divider + removeCommand + System.lineSeparator() + Logo.dividerWithoutNewLine); - } - - private void handleList(String userInput) throws CommandException{ - if(listManager.getListSize() == 0){ - throw new CommandException(ErrorList.ERROR_EMPTY_LIST); - } - String removeCommand = userInput.replaceFirst(COMMAND_VIEW_LIST,"").trim(); - System.out.println(Logo.dividerWithoutNewLine); - if(removeCommand.contains(COMMAND_ADD_TODO)){ - try { - listManager.printToDo(); - }catch (CommandException e){ - e.handleException(); - } - }else if(removeCommand.contains(COMMAND_ADD_EVENT)) { - try { - listManager.printEvent(); - }catch (CommandException e){ - e.handleException(); - } - }else if(removeCommand.contains(COMMAND_ADD_DEADLINE)){ - try { - listManager.printDeadline(); - }catch (CommandException e){ - e.handleException(); - } - }else { - listManager.printList(); - } - System.out.println(Logo.dividerWithoutNewLine); - } - - private void handleDelete(String userInput)throws CommandException{ - String removeCommand = userInput.replaceFirst(COMMAND_DELETE,"").trim(); - String[] taskDoneArray = removeCommand.split(","); - System.out.println(Logo.dividerWithoutNewLine); - for (String s: taskDoneArray) { - int taskDoneIndex = Integer.parseInt(s); - try { - listManager.deleteTask(taskDoneIndex - 1); - }catch (CommandException e){ - e.handleException(); - } - } - System.out.println(Logo.dividerWithoutNewLine); - } - - public void handleInput() throws CommandException{ - if(description.isEmpty()){ - throw new CommandException(ErrorList.ERROR_NULL); - } - boolean isAddingTask = false; - description = description.replaceAll(";",""); - if(description.contains(COMMAND_ADD_DEADLINE)){ - isAddingTask = true; - description = description.replaceAll(COMMAND_ADD_DEADLINE,";"+ COMMAND_ADD_DEADLINE); - } - if(description.contains(COMMAND_ADD_TODO)){ - isAddingTask = true; - description = description.replaceAll(COMMAND_ADD_TODO,";"+ COMMAND_ADD_TODO); - } - if(description.contains(COMMAND_ADD_EVENT)){ - isAddingTask = true; - description = description.replaceAll(COMMAND_ADD_EVENT,";"+ COMMAND_ADD_EVENT); - } - if(description.startsWith(COMMAND_VIEW_LIST)){ - isAddingTask = false; - } - if(isAddingTask) { - String[] commandList = description.split(";"); - for (int i = 1; i < commandList.length; i++) { - handleCommand(commandList[i]); - } - }else{ - handleCommand(description); - } - } - - private void handleCommand(String userInput){ - String inputCommand = taskCategory(userInput); - try { - switch (Objects.requireNonNull(inputCommand)) { - case COMMAND_EXIT: - Duke.isOnline = false; - break; - case COMMAND_VIEW_LIST: - try { - handleList(userInput); - }catch (CommandException e){ - e.handleException(); - } - break; - case COMMAND_COMPLETE_TASK: - handleDone(userInput); - listManager.printList(); - System.out.println(Logo.dividerWithoutNewLine); - break; - case COMMAND_ADD_EVENT: - try { - handleEvent(userInput); - }catch (CommandException e){ - e.handleException(); - } - break; - case COMMAND_ADD_TODO: - try { - handleToDo(userInput); - }catch(CommandException e){ - e.handleException(); - } - break; - case COMMAND_ADD_DEADLINE: - try { - handleDeadline(userInput); - }catch (CommandException e){ - e.handleException(); - } - break; - case COMMAND_ECHO: - try { - handleEcho(userInput); - }catch (CommandException e){ - e.handleException(); - } - break; - case COMMAND_DELETE: - try{ - handleDelete(userInput); - }catch (CommandException e){ - e.handleException(); - } - } - }catch(NullPointerException e){ - try { - System.out.println(ErrorList.ERROR_UNKNOWN_COMMAND); - handleEcho(userInput); - }catch (CommandException commandException){ - commandException.handleException(); - } - } - } -} - diff --git a/src/main/java/duke/InputInterface.java b/src/main/java/duke/InputInterface.java deleted file mode 100644 index 077524732..000000000 --- a/src/main/java/duke/InputInterface.java +++ /dev/null @@ -1,5 +0,0 @@ -package duke; - -public interface InputInterface { - void handleInput() throws CommandException; -} diff --git a/src/main/java/duke/Parser/Parser.java b/src/main/java/duke/Parser/Parser.java new file mode 100644 index 000000000..794b7fae0 --- /dev/null +++ b/src/main/java/duke/Parser/Parser.java @@ -0,0 +1,186 @@ +package duke.Parser; + +import duke.ArtBot.Logo; +import duke.Command.*; +import duke.ErrorHandling.CommandException; +import duke.ErrorHandling.ErrorStaticString; +import duke.Storage.Storage; +import duke.TaskList.TaskList; + +import java.util.Objects; + +public class Parser{ + + private static final String COMMAND_VIEW_LIST = "list"; + private static final String COMMAND_ECHO = "echo"; + private static final String COMMAND_COMPLETE_TASK = "done"; + private static final String COMMAND_ADD_TODO = "todo"; + private static final String COMMAND_ADD_EVENT = "event"; + private static final String COMMAND_ADD_DEADLINE = "deadline"; + private static final String COMMAND_DELETE = "delete"; + private static final String COMMAND_EXIT = "bye"; + private static final String EMPTY_STRING = ""; + private static final String COMMAND_GUIDE_INDICATOR = "!"; + private static final String SPLITTER = ";"; + + private String userInput; + private final TaskList listManager; + + public Parser(String userInput, TaskList listManager){ + this.userInput = userInput; + this.listManager = listManager; + } + + private String taskCategory(String userInput){ + if(userInput.startsWith(COMMAND_VIEW_LIST)) { + return COMMAND_VIEW_LIST; + } + if(userInput.startsWith(COMMAND_ADD_DEADLINE)){ + return COMMAND_ADD_DEADLINE; + } + if(userInput.startsWith(COMMAND_ADD_TODO)) { + return COMMAND_ADD_TODO; + } + if(userInput.startsWith(COMMAND_ADD_EVENT)){ + return COMMAND_ADD_EVENT; + } + if(userInput.startsWith(COMMAND_COMPLETE_TASK)){ + return COMMAND_COMPLETE_TASK; + } + if (userInput.startsWith(COMMAND_ECHO)){ + return COMMAND_ECHO; + } + if(userInput.startsWith(COMMAND_DELETE)){ + return COMMAND_DELETE; + } + return null; + } + + private boolean isTodo(){ + if(userInput.contains(COMMAND_ADD_TODO)){ + userInput = userInput.replaceAll(COMMAND_ADD_TODO,SPLITTER + COMMAND_ADD_TODO); + return true; + } + return false; + } + private boolean isEvent(){ + if(userInput.contains(COMMAND_ADD_EVENT)){ + userInput = userInput.replaceAll(COMMAND_ADD_EVENT,SPLITTER + COMMAND_ADD_EVENT); + return true; + } + return false; + } + private boolean isDeadline(){ + if(userInput.contains(COMMAND_ADD_DEADLINE)){ + userInput = userInput.replaceAll(COMMAND_ADD_DEADLINE,SPLITTER + COMMAND_ADD_DEADLINE); + return true; + } + return false; + } + + private boolean isList(){ + return userInput.startsWith(COMMAND_VIEW_LIST); + } + + public boolean isExit(){ + return userInput.startsWith(COMMAND_EXIT); + } + + public void handleInput() throws CommandException{ + if(userInput.isEmpty()){ + throw new CommandException(ErrorStaticString.ERROR_NULL); + } + if(userInput.startsWith(COMMAND_GUIDE_INDICATOR)){ + String userInputWithoutIndicator = userInput.replaceFirst(COMMAND_GUIDE_INDICATOR,EMPTY_STRING).trim(); + CommandGuide commandGuide = new CommandGuide(userInputWithoutIndicator); + commandGuide.executeCommand(); + }else{ + splitInputIfThereMoreThanOneCommand(); + } + } + + private void splitInputIfThereMoreThanOneCommand() { + userInput = userInput.replaceAll(SPLITTER,EMPTY_STRING); + boolean isAddingTask = false; + if (!isList()) { + isAddingTask = isTodo() || isEvent() || isDeadline(); + } + if(isAddingTask) { + String[] commandList = userInput.split(SPLITTER); + for (int i = 1; i < commandList.length; i++) { + handleCommand(commandList[i]); + } + }else{ + handleCommand(userInput); + } + } + + private void handleCommand(String inputCommand){ + String commandCategory = taskCategory(inputCommand); + try { + switch (Objects.requireNonNull(commandCategory)) { + case COMMAND_VIEW_LIST: + ListCommand listCommand = new ListCommand(inputCommand, listManager); + try { + listCommand.executeCommand(); + } catch (CommandException e) { + e.handleException(); + } + break; + case COMMAND_COMPLETE_TASK: + DoneCommand doneCommand = new DoneCommand(inputCommand, listManager); + doneCommand.executeCommand(); + listManager.printList(); + System.out.println(Logo.dividerWithoutNewLine); + break; + case COMMAND_ADD_EVENT: + AddEventCommand addEvent = new AddEventCommand(inputCommand, listManager); + try { + addEvent.executeCommand(); + } catch (CommandException e) { + e.handleException(); + } + break; + case COMMAND_ADD_TODO: + AddToDoCommand addToDo = new AddToDoCommand(inputCommand, listManager); + try { + addToDo.executeCommand(); + } catch (CommandException e) { + e.handleException(); + } + break; + case COMMAND_ADD_DEADLINE: + AddDeadlineCommand addDeadline = new AddDeadlineCommand(inputCommand, listManager); + try { + addDeadline.executeCommand(); + } catch (CommandException e) { + e.handleException(); + } + break; + case COMMAND_ECHO: + EchoCommand echoCommand = new EchoCommand(inputCommand); + try { + echoCommand.executeCommand(); + } catch (CommandException e) { + e.handleException(); + } + break; + case COMMAND_DELETE: + DeleteCommand deleteCommand = new DeleteCommand(inputCommand, listManager); + try { + deleteCommand.executeCommand(); + } catch (CommandException e) { + e.handleException(); + } + } + }catch(NullPointerException e){ + System.out.println(ErrorStaticString.ERROR_UNKNOWN_COMMAND); + EchoCommand echoCommand = new EchoCommand(inputCommand); + try { + echoCommand.executeCommand(); + } catch (CommandException echoE) { + echoE.handleException(); + } + } + } +} diff --git a/src/main/java/duke/Storage/FileRead.java b/src/main/java/duke/Storage/FileRead.java new file mode 100644 index 000000000..56b6f1475 --- /dev/null +++ b/src/main/java/duke/Storage/FileRead.java @@ -0,0 +1,63 @@ +package duke.Storage; + +import duke.ErrorHandling.CommandException; +import duke.ErrorHandling.ErrorStaticString; +import duke.TaskList.TaskList; +import duke.task.Task; +import java.io.File; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.Scanner; + +public class FileRead extends Storage{ + + private File file; + private TaskList listManager; + private ArrayList taskList; + + public FileRead(File file){ + taskList = new ArrayList<>(); + listManager = new TaskList(taskList); + this.file = file; + } + + private ArrayList readFile(File inputFile){ + ArrayList list = new ArrayList<>(); + try { + Scanner scanner = new Scanner(inputFile); + while(scanner.hasNext()){ + list.add(scanner.nextLine()); + } + } catch (FileNotFoundException e) { + System.out.println(ErrorStaticString.ERROR_FILE_MESSAGE_READING); + } + return list; + } + + public ArrayList convertFileToTask() { + ArrayList stringList = readFile(file); + int taskIndex = 0; + for (String s : stringList) { + String[] splitString = s.split(FILE_SEPARATOR); + switch (splitString[FILE_TASK_TYPE_POSITION]){ + case FILE_TODO_STATUS: + listManager.addTodo(splitString[FILE_TASK_DESCRIPTION_POSITION], true); + break; + case FILE_EVENT_STATUS: + listManager.addEvent(splitString[FILE_TASK_DESCRIPTION_POSITION],splitString[FILE_TASK_DETAILS_POSITION], true); + break; + case FILE_DEADLINE_STATUS: + listManager.addDeadline(splitString[FILE_TASK_DETAILS_POSITION],splitString[FILE_TASK_DETAILS_POSITION], true); + } + if (splitString[FILE_TASK_COMPLETE_POSITION].equals(FILE_COMPLETE_STATUS)){ + try { + listManager.completeTask(taskIndex, true); + } catch (CommandException e) { + e.handleException(); + } + } + taskIndex += 1; + } + return taskList; + } +} diff --git a/src/main/java/duke/Storage/FileWrite.java b/src/main/java/duke/Storage/FileWrite.java new file mode 100644 index 000000000..d74ea63e6 --- /dev/null +++ b/src/main/java/duke/Storage/FileWrite.java @@ -0,0 +1,18 @@ +package duke.Storage; + +import duke.ErrorHandling.ErrorStaticString; + +import java.io.IOException; + +public class FileWrite extends Storage{ + + public void writeToFile(String s, boolean isAppend){ + try { + java.io.FileWriter fileWriter = new java.io.FileWriter(file, isAppend); + fileWriter.write(s); + fileWriter.close(); + } catch (IOException e) { + System.out.println(ErrorStaticString.ERROR_FILE_MESSAGE_WRITING); + } + } +} diff --git a/src/main/java/duke/Storage/Storage.java b/src/main/java/duke/Storage/Storage.java new file mode 100644 index 000000000..99a958645 --- /dev/null +++ b/src/main/java/duke/Storage/Storage.java @@ -0,0 +1,58 @@ +package duke.Storage; + +import duke.ErrorHandling.ErrorStaticString; +import duke.task.Task; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; + +public class Storage { + + protected static final String FILE_NAME = "duke.txt"; + protected static final String FILE_CREATED = "File created: "; + protected static final String FILE_MESSAGE_AT = " at "; + protected static final String FILE_SEPARATOR = ";"; + protected static final String FILE_TODO_STATUS = "[T]"; + protected static final String FILE_DEADLINE_STATUS = "[D]"; + protected static final String FILE_EVENT_STATUS = "[E]"; + protected static final String FILE_COMPLETE_STATUS = "[X]"; + protected static final int FILE_TASK_TYPE_POSITION = 0; + protected static final int FILE_TASK_COMPLETE_POSITION = 1; + protected static final int FILE_TASK_DESCRIPTION_POSITION = 2; + protected static final int FILE_TASK_DETAILS_POSITION = 3; + + protected File file; + + public Storage(){ + try{ + file = new File(FILE_NAME); + if(file.createNewFile()){ + System.out.println(FILE_CREATED + file.getName() + FILE_MESSAGE_AT + file.getAbsolutePath()); + } + }catch(IOException e){ + System.out.println(ErrorStaticString.ERROR_FILE_MESSAGE_CREATION); + } + } + + public ArrayList load(){ + FileRead fileReader = new FileRead(file); + return fileReader.convertFileToTask(); + } + + public void appendTask(Task t){ + FileWrite fileWrite = new FileWrite(); + fileWrite.writeToFile(t.toFile(), true); + } + + public void writeTask(ArrayList list){ + StringBuilder stringBuilder = new StringBuilder(); + for(Task t: list) { + stringBuilder.append(t.toFile()); + stringBuilder.append(System.lineSeparator()); + } + String stringToWrite = stringBuilder.toString(); + FileWrite fileWrite = new FileWrite(); + fileWrite.writeToFile(stringToWrite, false); + } +} diff --git a/src/main/java/duke/ListManager.java b/src/main/java/duke/TaskList/TaskList.java similarity index 62% rename from src/main/java/duke/ListManager.java rename to src/main/java/duke/TaskList/TaskList.java index 29a7b46bc..73f0467b2 100644 --- a/src/main/java/duke/ListManager.java +++ b/src/main/java/duke/TaskList/TaskList.java @@ -1,13 +1,15 @@ -package duke; +package duke.TaskList; +import duke.ErrorHandling.CommandException; +import duke.ErrorHandling.ErrorStaticString; +import duke.Storage.Storage; import duke.task.Deadline; import duke.task.Event; import duke.task.Task; import duke.task.ToDo; - import java.util.ArrayList; -public class ListManager implements TaskList{ +public class TaskList implements TaskListInterface { private static final String MESSAGE_TASK_ADDED = "Got it. I've added this task: "; private static final String MESSAGE_TASK_IN_LIST = " tasks in the list."; @@ -18,87 +20,82 @@ public class ListManager implements TaskList{ private final ArrayList list; - public ListManager(ArrayList list){ + public TaskList(){ + list = new ArrayList<>(); + } + public TaskList(ArrayList list){ this.list = list; } - public void printList(){ + private void printer(ArrayList listToPrint){ System.out.println(MESSAGE_LIST_TASK); - for(int i = 0; i < list.size(); i++){ + for(int i = 0; i < listToPrint.size(); i++){ int itemIndex= i + 1; - System.out.println(itemIndex + MESSAGE_SPACER + list.get(i).toString()); + System.out.println(itemIndex + MESSAGE_SPACER + listToPrint.get(i).toString()); } } - public void printToDo() throws CommandException{ + public void printList(){ + printer(list); + } + + public void printToDo() throws CommandException { boolean haveToDo = false; - for(int i = 1; i <= list.size(); i++){ + ArrayList listOfToDo = new ArrayList<>(); + for(int i = 0; i < list.size(); i++){ if(list.get(i) instanceof ToDo){ haveToDo = true; - break; + listOfToDo.add(list.get(i)); } } if(!haveToDo){ - throw new CommandException(ErrorList.ERROR_EMPTY_TODO_LIST); - } - for(int i = 0; i < list.size(); i++){ - int itemIndex= i + 1; - if(list.get(i) instanceof ToDo ) { - System.out.println(itemIndex + MESSAGE_SPACER + list.get(i).toString()); - } + throw new CommandException(ErrorStaticString.ERROR_EMPTY_TODO_LIST); } + printer(listOfToDo); } public void printEvent() throws CommandException{ boolean haveEvent = false; - for(int i = 1; i <= list.size(); i++){ + ArrayList listOfEvent = new ArrayList<>(); + for(int i = 0; i < list.size(); i++){ if(list.get(i) instanceof Event) { haveEvent = true; - break; + listOfEvent.add(list.get(i)); } } if(!haveEvent){ - throw new CommandException(ErrorList.ERROR_EMPTY_EVENT_LIST); - } - for(int i = 0; i < list.size(); i++){ - int itemIndex= i + 1; - if(list.get(i) instanceof Event ) { - System.out.println(itemIndex + MESSAGE_SPACER + list.get(i).toString()); - } + throw new CommandException(ErrorStaticString.ERROR_EMPTY_EVENT_LIST); } + printer(listOfEvent); } public void printDeadline() throws CommandException{ boolean haveDeadline = false; - for(int i = 1; i <= list.size(); i++){ + ArrayList listOfDeadline = new ArrayList<>(); + for(int i = 0; i < list.size(); i++){ if(list.get(i) instanceof Deadline) { haveDeadline = true; - break; + listOfDeadline.add(list.get(i)); } } if(!haveDeadline){ - throw new CommandException(ErrorList.ERROR_EMPTY_DEADLINE_LIST); - } - for(int i = 0; i < list.size(); i++){ - int itemIndex= i + 1; - if(list.get(i) instanceof Deadline ) { - System.out.println(itemIndex + MESSAGE_SPACER + list.get(i).toString()); - } + throw new CommandException(ErrorStaticString.ERROR_EMPTY_DEADLINE_LIST); } + printer(listOfDeadline); } private void printAddItem(Task t){ System.out.println(MESSAGE_TASK_ADDED + System.lineSeparator() + t.toString() + System.lineSeparator() + MESSAGE_TASK_NOW - + list.size() + MESSAGE_TASK_IN_LIST); + + list.size() + MESSAGE_TASK_IN_LIST); } public void addTodo(String description, boolean isFromFile){ Task t = new ToDo(description); list.add(t); if(!isFromFile) { - System.out.println(Logo.dividerWithoutNewLine); printAddItem(t); - System.out.println(Logo.dividerWithoutNewLine); + Storage storage = new Storage(); + storage.appendTask(t); } } @@ -106,9 +103,9 @@ public void addEvent(String description, String time, boolean isFromFile){ Task t = new Event(description, time); list.add(t); if(!isFromFile) { - System.out.println(Logo.dividerWithoutNewLine); printAddItem(t); - System.out.println(Logo.dividerWithoutNewLine); + Storage storage = new Storage(); + storage.appendTask(t); } } @@ -116,31 +113,38 @@ public void addDeadline(String description, String deadline, boolean isFromFile Task t = new Deadline(description, deadline); list.add(t); if(!isFromFile) { - System.out.println(Logo.dividerWithoutNewLine); printAddItem(t); - System.out.println(Logo.dividerWithoutNewLine); + Storage storage = new Storage(); + storage.appendTask(t); } } public void completeTask(int t, boolean isFromFile) throws CommandException{ if (t > list.size() || t < 0){ - throw new CommandException(ErrorList.ERROR_DONE_TASK_NOT_IN_LIST); + throw new CommandException(ErrorStaticString.ERROR_DONE_TASK_NOT_IN_LIST); } Task doneTask = list.get(t); doneTask.setDone(); if (!isFromFile) { System.out.println(doneTask.toString()); + Storage storage = new Storage(); + storage.writeTask(list); } - } public void deleteTask(int t) throws CommandException{ if(t > list.size() || t < 0){ - throw new CommandException(ErrorList.ERROR_DELETE_TASK); + throw new CommandException(ErrorStaticString.ERROR_DELETE_TASK); } Task removeTask = list.get(t); list.remove(t); - System.out.println(MESSAGE_DELETE + System.lineSeparator() + removeTask.toString() + System.lineSeparator() + + printDeleteTask(removeTask); + Storage storage = new Storage(); + storage.writeTask(list); + } + + private void printDeleteTask(Task t){ + System.out.println(MESSAGE_DELETE + System.lineSeparator() + t.toString() + System.lineSeparator() + MESSAGE_TASK_NOW + list.size() + MESSAGE_TASK_IN_LIST); } diff --git a/src/main/java/duke/TaskList.java b/src/main/java/duke/TaskList/TaskListInterface.java similarity index 82% rename from src/main/java/duke/TaskList.java rename to src/main/java/duke/TaskList/TaskListInterface.java index 221c1893f..4a537cb07 100644 --- a/src/main/java/duke/TaskList.java +++ b/src/main/java/duke/TaskList/TaskListInterface.java @@ -1,6 +1,8 @@ -package duke; +package duke.TaskList; -public interface TaskList { +import duke.ErrorHandling.CommandException; + +public interface TaskListInterface { void printList() throws CommandException; void printToDo() throws CommandException; void printEvent() throws CommandException; diff --git a/src/main/java/duke/Ui/Ui.java b/src/main/java/duke/Ui/Ui.java new file mode 100644 index 000000000..b9f553c7e --- /dev/null +++ b/src/main/java/duke/Ui/Ui.java @@ -0,0 +1,38 @@ +package duke.Ui; + + +import duke.ArtBot.Logo; + +import java.util.Scanner; + +public class Ui { + + private static final String MESSAGE_HI = "Hello! I'm Duke\n" + "What can I do for you?\n" + "!help for Command List\n"; + private static final String MESSAGE_BYE = "Bye. Hope to see you again soon!\n"; + + public void Greetings(){ + System.out.println(Logo.logo +Logo.divider + MESSAGE_HI + Logo.dividerWithoutNewLine); + } + + public void Farewell(){ + System.out.println(MESSAGE_BYE + Logo.bye); + } + + public void showLine(){ + System.out.println(Logo.divider); + } + + public void showLineWithoutNewLine(){ + System.out.println(Logo.dividerWithoutNewLine); + } + + public String readCommand(){ + Scanner in = new Scanner(System.in); + return in.nextLine().toLowerCase().trim(); + } + + public void showError(String error){ + System.out.println(error); + } +} + diff --git a/src/main/java/duke/task/Event.java b/src/main/java/duke/task/Event.java index 88c7dbef5..52c196224 100644 --- a/src/main/java/duke/task/Event.java +++ b/src/main/java/duke/task/Event.java @@ -12,7 +12,7 @@ public Event(String description, String startTime){ @Override public String toString(){ - return TASK_SYMBOL + super.toString() + "(at:" + startTime + ")"; + return TASK_SYMBOL + super.toString() + "(at: " + startTime + ")"; } @Override diff --git a/src/main/java/duke/task/Task.java b/src/main/java/duke/task/Task.java index 058822daf..bb38dd86d 100644 --- a/src/main/java/duke/task/Task.java +++ b/src/main/java/duke/task/Task.java @@ -1,7 +1,5 @@ package duke.task; -import duke.TaskInterface; - public class Task implements TaskInterface { private static final String COMPLETE_STATUS_ICON = "[X]"; private static final String INCOMPLETE_STATUS_ICON = "[ ]"; diff --git a/src/main/java/duke/TaskInterface.java b/src/main/java/duke/task/TaskInterface.java similarity index 85% rename from src/main/java/duke/TaskInterface.java rename to src/main/java/duke/task/TaskInterface.java index 77a3a2aec..2ab7cfc4c 100644 --- a/src/main/java/duke/TaskInterface.java +++ b/src/main/java/duke/task/TaskInterface.java @@ -1,4 +1,4 @@ -package duke; +package duke.task; public interface TaskInterface { void setDone(); diff --git a/src/main/java/duke/task/ToDo.java b/src/main/java/duke/task/ToDo.java index b16728be6..98554f6b4 100644 --- a/src/main/java/duke/task/ToDo.java +++ b/src/main/java/duke/task/ToDo.java @@ -15,6 +15,6 @@ public String toString() { @Override public String toFile(){ - return TASK_SYMBOL + SEPARATOR + super.toFile() +System.lineSeparator(); + return TASK_SYMBOL + SEPARATOR + super.toFile() + System.lineSeparator(); } } From 80e1c4e53220e66ca47df013395176ec61c3333a Mon Sep 17 00:00:00 2001 From: wingho2 Date: Mon, 27 Sep 2021 01:46:17 +0800 Subject: [PATCH 22/62] Added a find date command that find task with a specific date --- duke.txt | 11 +- .../java/duke/Command/AddDeadlineCommand.java | 5 +- .../java/duke/Command/AddEventCommand.java | 4 +- src/main/java/duke/Command/Command.java | 3 + src/main/java/duke/Command/CommandGuide.java | 12 +- src/main/java/duke/Command/DeleteCommand.java | 21 +-- src/main/java/duke/Command/DoneCommand.java | 22 ++- src/main/java/duke/Command/EchoCommand.java | 2 +- .../java/duke/Command/FindDateCommand.java | 56 ++++++++ src/main/java/duke/Command/ListCommand.java | 1 - src/main/java/duke/Duke.java | 8 +- .../duke/ErrorHandling/ErrorStaticString.java | 25 +++- src/main/java/duke/Parser/Parser.java | 48 ++++--- src/main/java/duke/Storage/FileRead.java | 4 +- src/main/java/duke/Storage/Storage.java | 9 +- src/main/java/duke/TaskList/TaskList.java | 59 +++++--- .../java/duke/TaskList/TaskListInterface.java | 4 +- src/main/java/duke/Ui/Ui.java | 5 +- src/main/java/duke/task/Deadline.java | 92 +++++++++++- src/main/java/duke/task/Event.java | 91 +++++++++++- src/main/java/duke/task/Task.java | 8 ++ src/main/java/duke/task/ToDo.java | 2 +- text-ui-test/EXPECTED.txt | 135 ++++++++++++++---- text-ui-test/input.txt | 22 ++- 24 files changed, 513 insertions(+), 136 deletions(-) create mode 100644 src/main/java/duke/Command/FindDateCommand.java diff --git a/duke.txt b/duke.txt index db47ab378..5e2b38870 100644 --- a/duke.txt +++ b/duke.txt @@ -1,3 +1,8 @@ -[T];[ ];watch hank -[T];[ ];watch haxxnini -[T];[ ];watch nats +[T];[X];watch haxxnini livestream +[D];[ ];reach legend;this season +[D];[ ];reach gold;08:00 +[D];[ ];reach silver; 2020-10-10 +[D];[ ];reach bronze;08:00 2020-10-10 +[E];[ ];g2 vs sentinel;10pm +[E];[ ];g2 vs sentinel;10:00 +[E];[ ];g2 vs sentinel;10:00 2020-10-10 diff --git a/src/main/java/duke/Command/AddDeadlineCommand.java b/src/main/java/duke/Command/AddDeadlineCommand.java index fe136e038..9c312cd8a 100644 --- a/src/main/java/duke/Command/AddDeadlineCommand.java +++ b/src/main/java/duke/Command/AddDeadlineCommand.java @@ -2,7 +2,6 @@ import duke.ErrorHandling.CommandException; import duke.ErrorHandling.ErrorStaticString; -import duke.Storage.Storage; import duke.TaskList.TaskList; public class AddDeadlineCommand extends Command{ @@ -25,7 +24,7 @@ public void executeCommand() throws CommandException { if(deadlineDescription.isEmpty()){ throw new CommandException(ErrorStaticString.ERROR_EMPTY_DEADLINE_INPUT); } - String deadlineDate = taskDescription.replaceFirst(deadlineDescription, EMPTY_STRING).replaceFirst(DEADLINE_DATE,EMPTY_STRING).strip(); - listManager.addDeadline(deadlineDescription,deadlineDate, false); + String inputWithoutDescription = taskDescription.replaceFirst(deadlineDescription, EMPTY_STRING).replaceFirst(DEADLINE_DATE,EMPTY_STRING).strip(); + listManager.addDeadline(deadlineDescription, inputWithoutDescription, false); } } diff --git a/src/main/java/duke/Command/AddEventCommand.java b/src/main/java/duke/Command/AddEventCommand.java index 10d8a9941..0d321695e 100644 --- a/src/main/java/duke/Command/AddEventCommand.java +++ b/src/main/java/duke/Command/AddEventCommand.java @@ -24,7 +24,7 @@ public void executeCommand() throws CommandException { if(eventDescription.isEmpty()){ throw new CommandException(ErrorStaticString.ERROR_EMPTY_EVENT_INPUT); } - String eventTime = taskDescription.replaceFirst(eventDescription, EMPTY_STRING).replaceFirst(EVENT_TIME,EMPTY_STRING).strip(); - listManager.addEvent(eventDescription,eventTime, false); + String inputWithoutDescription = taskDescription.replaceFirst(eventDescription, EMPTY_STRING).replaceFirst(EVENT_TIME,EMPTY_STRING).strip(); + listManager.addEvent(eventDescription, inputWithoutDescription,false); } } diff --git a/src/main/java/duke/Command/Command.java b/src/main/java/duke/Command/Command.java index bcc8d1e97..7b257b851 100644 --- a/src/main/java/duke/Command/Command.java +++ b/src/main/java/duke/Command/Command.java @@ -11,6 +11,7 @@ public abstract class Command { protected static final String COMMAND_VIEW_LIST = "list"; protected static final String COMMAND_ECHO = "echo"; protected static final String COMMAND_COMPLETE_TASK = "done"; + protected static final String COMMAND_DATE_TASK = "date"; protected static final String COMMAND_ADD_TODO = "todo"; protected static final String COMMAND_ADD_EVENT = "event"; protected static final String COMMAND_ADD_DEADLINE = "deadline"; @@ -18,10 +19,12 @@ public abstract class Command { protected static final String EVENT_TIME = "at "; protected static final String DEADLINE_DATE = "by "; protected static final String MESSAGE_TASK_COMPLETE = "Nice! I've marked this task as done: "; + protected static final String DATE_PATTERN = "\\d{4}-\\d{1,2}-\\d{1,2}"; protected static final String EMPTY_STRING = ""; protected static final String SEPARATOR = ","; protected static final int START_OF_STRING = 0; + protected static final String MESSAGE_HELP = "List of Commands:\n" + " echo - Repeat whatever was typed - !echo to repeat in art form\n" + " list - Display List - !list for details\n" + diff --git a/src/main/java/duke/Command/CommandGuide.java b/src/main/java/duke/Command/CommandGuide.java index 77e361ac3..23015538d 100644 --- a/src/main/java/duke/Command/CommandGuide.java +++ b/src/main/java/duke/Command/CommandGuide.java @@ -5,8 +5,8 @@ public class CommandGuide extends Command{ - public CommandGuide(String userInput){ - super(userInput); + public CommandGuide(String taskInput){ + super(taskInput); } @Override @@ -18,16 +18,16 @@ public void executeCommand(){ } switch(taskInput) { case COMMAND_HELP: - System.out.println(Logo.divider + MESSAGE_HELP + Logo.dividerWithoutNewLine); + System.out.println(MESSAGE_HELP); break; case COMMAND_LIST_HELP: - System.out.println(Logo.divider + MESSAGE_LIST_HELP + Logo.dividerWithoutNewLine); + System.out.println(MESSAGE_LIST_HELP); break; case COMMAND_EVENT_HELP: - System.out.println(Logo.divider + MESSAGE_EVENT_HELP + Logo.dividerWithoutNewLine); + System.out.println(MESSAGE_EVENT_HELP); break; case COMMAND_DEADLINE_HELP: - System.out.println(Logo.divider + MESSAGE_DEADLINE_HELP + Logo.dividerWithoutNewLine); + System.out.println(MESSAGE_DEADLINE_HELP); break; } } diff --git a/src/main/java/duke/Command/DeleteCommand.java b/src/main/java/duke/Command/DeleteCommand.java index 46640c7bc..236ae0017 100644 --- a/src/main/java/duke/Command/DeleteCommand.java +++ b/src/main/java/duke/Command/DeleteCommand.java @@ -1,9 +1,8 @@ package duke.Command; -import duke.ArtBot.Logo; import duke.ErrorHandling.CommandException; +import duke.ErrorHandling.ErrorStaticString; import duke.TaskList.TaskList; - import java.util.ArrayList; import java.util.Collections; @@ -19,19 +18,21 @@ public DeleteCommand(String userInput, TaskList listManager){ @Override public void executeCommand()throws CommandException { String removeCommand = taskInput.replaceFirst(COMMAND_DELETE,EMPTY_STRING).trim(); + if(removeCommand.isEmpty()){ + throw new CommandException(ErrorStaticString.ERROR_DELETE_TASK_EMPTY); + } String[] taskDoneArray = removeCommand.split(SEPARATOR); - ArrayList intArray = new ArrayList(); + ArrayList intArray = new ArrayList<>(); for (String s: taskDoneArray){ - int taskDoneIndex = Integer.parseInt(s); - intArray.add(taskDoneIndex - 1); + int taskDoneIndex = Integer.parseInt(s) - 1; + intArray.add(taskDoneIndex); + if(taskDoneIndex > listManager.getListSize() || taskDoneIndex < 0){ + throw new CommandException(ErrorStaticString.ERROR_DELETE_TASK); + } } Collections.sort(intArray, Collections.reverseOrder()); for (Integer i: intArray) { - try { - listManager.deleteTask(i); - }catch (CommandException e){ - e.handleException(); - } + listManager.deleteTask(i); } } } diff --git a/src/main/java/duke/Command/DoneCommand.java b/src/main/java/duke/Command/DoneCommand.java index 2f2df8e27..840cbbf1c 100644 --- a/src/main/java/duke/Command/DoneCommand.java +++ b/src/main/java/duke/Command/DoneCommand.java @@ -1,9 +1,11 @@ package duke.Command; -import duke.ArtBot.Logo; import duke.ErrorHandling.CommandException; +import duke.ErrorHandling.ErrorStaticString; import duke.TaskList.TaskList; +import java.util.ArrayList; + public class DoneCommand extends Command{ private final TaskList listManager; @@ -14,17 +16,23 @@ public DoneCommand(String userInput, TaskList listManager){ } @Override - public void executeCommand(){ + public void executeCommand() throws CommandException{ String removeCommand = taskInput.replaceFirst(COMMAND_COMPLETE_TASK,EMPTY_STRING).trim(); + if(removeCommand.isEmpty()){ + throw new CommandException(ErrorStaticString.ERROR_DONE_TASK_EMPTY); + } String[] taskDoneArray = removeCommand.split(SEPARATOR); System.out.println(MESSAGE_TASK_COMPLETE); + ArrayList intArray = new ArrayList<>(); for (String s: taskDoneArray) { - int taskDoneIndex = Integer.parseInt(s); - try { - listManager.completeTask(taskDoneIndex - 1, false); - }catch (CommandException e){ - e.handleException(); + int taskDoneIndex = Integer.parseInt(s) - 1; + intArray.add(taskDoneIndex); + if(taskDoneIndex > listManager.getListSize() || taskDoneIndex < 0){ + throw new CommandException(ErrorStaticString.ERROR_DONE_TASK_NOT_IN_LIST); } } + for(Integer i: intArray){ + listManager.completeTask(i, false); + } } } diff --git a/src/main/java/duke/Command/EchoCommand.java b/src/main/java/duke/Command/EchoCommand.java index 1cb2b9e77..7cf62dbb6 100644 --- a/src/main/java/duke/Command/EchoCommand.java +++ b/src/main/java/duke/Command/EchoCommand.java @@ -12,7 +12,7 @@ public EchoCommand(String userInput){ } public void executeCommand() throws CommandException { - String removeCommand = taskInput.replaceFirst(COMMAND_ECHO_ART, EMPTY_STRING).trim(); + String removeCommand = taskInput.replaceFirst(COMMAND_ECHO, EMPTY_STRING).trim(); if(removeCommand.isEmpty()){ throw new CommandException(ErrorStaticString.ERROR_EMPTY_ECHO_INPUT); } diff --git a/src/main/java/duke/Command/FindDateCommand.java b/src/main/java/duke/Command/FindDateCommand.java new file mode 100644 index 000000000..ccc93fecb --- /dev/null +++ b/src/main/java/duke/Command/FindDateCommand.java @@ -0,0 +1,56 @@ +package duke.Command; + +import duke.ErrorHandling.CommandException; +import duke.ErrorHandling.ErrorStaticString; +import duke.TaskList.TaskList; + +import java.time.LocalDate; +import java.time.format.DateTimeParseException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class FindDateCommand extends Command{ + + private final TaskList taskList; + + public FindDateCommand(String taskInput, TaskList taskList){ + super(taskInput); + this.taskList = taskList; + } + + @Override + public void executeCommand() throws CommandException { + if(taskList.getListSize() == 0){ + throw new CommandException(ErrorStaticString.ERROR_EMPTY_LIST); + } + taskInput = taskInput.replaceFirst(COMMAND_DATE_TASK,EMPTY_STRING).trim(); + if(taskInput.isEmpty()){ + throw new CommandException(ErrorStaticString.ERROR_EMPTY_DATE_SEARCH_TASK); + } + try { + LocalDate localDate = LocalDate.parse(convertStringToDate()); + taskList.printDate(localDate); + }catch (DateTimeParseException e ){ + System.out.println(ErrorStaticString.ERROR_DATE_SEARCH); + } + } + + private Matcher findDate(String stringToSearch){ + Pattern pattern = Pattern.compile(DATE_PATTERN); + Matcher matcher = pattern.matcher(stringToSearch); + if(matcher.find()){ + return matcher; + } + return null; + } + + private String convertStringToDate(){ + Matcher dateMatcher = findDate(taskInput); + if(dateMatcher != null){ + int startIndexOfDate = dateMatcher.start(); + int endIndexOfDate = dateMatcher.end(); + return taskInput.substring(startIndexOfDate,endIndexOfDate); + } + return EMPTY_STRING; + } +} diff --git a/src/main/java/duke/Command/ListCommand.java b/src/main/java/duke/Command/ListCommand.java index 715cb97f1..22b8b3dd8 100644 --- a/src/main/java/duke/Command/ListCommand.java +++ b/src/main/java/duke/Command/ListCommand.java @@ -1,6 +1,5 @@ package duke.Command; -import duke.ArtBot.Logo; import duke.ErrorHandling.CommandException; import duke.ErrorHandling.ErrorStaticString; import duke.TaskList.TaskList; diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 7610a1bc7..019cbaa33 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -20,13 +20,15 @@ public Duke(){ public void run(){ ui.Greetings(); boolean isExit = false; - do { + do{ try { String fullCommand = ui.readCommand(); - ui.showLineWithoutNewLine(); + ui.showLine(); Parser parser = new Parser(fullCommand, tasks); isExit = parser.isExit(); - parser.handleInput(); + if(!isExit) { + parser.handleInput(); + } }catch(CommandException e){ ui.showError(e.getErrorMessage()); }finally { diff --git a/src/main/java/duke/ErrorHandling/ErrorStaticString.java b/src/main/java/duke/ErrorHandling/ErrorStaticString.java index 1b8c26e07..e44ffe979 100644 --- a/src/main/java/duke/ErrorHandling/ErrorStaticString.java +++ b/src/main/java/duke/ErrorHandling/ErrorStaticString.java @@ -4,20 +4,35 @@ public class ErrorStaticString { public static final String ERROR_NULL = "☹ OOPS!!! Input cannot be empty."; public static final String ERROR_UNKNOWN_COMMAND = "☹ OOPS!!! I'm sorry, but I don't know what that means :-(\n" + "" + "Defaulting to Echo. Type !help to see the list of Commands\n"; + public static final String ERROR_EMPTY_LIST = "☹ OOPS!!! List is empty. Add tasks to the list."; public static final String ERROR_EMPTY_TODO_LIST = "☹ OOPS!!! There is no To Do task in list. Add To Do tasks to the list."; public static final String ERROR_EMPTY_EVENT_LIST = "☹ OOPS!!! There is no Event task in list. Add Events to the list."; public static final String ERROR_EMPTY_DEADLINE_LIST = "☹ OOPS!!! There is no Deadline task in list. Add Deadlines to the list."; + public static final String ERROR_EMPTY_TODO_INPUT = "☹ OOPS!!! The description of a todo cannot be empty."; public static final String ERROR_EMPTY_EVENT_INPUT = "☹ OOPS!!! The description of a event cannot be empty."; public static final String ERROR_EMPTY_DEADLINE_INPUT = "☹ OOPS!!! The description of a deadline cannot be empty."; public static final String ERROR_EMPTY_ECHO_INPUT = "☹ OOPS!!! The description of a echo cannot be empty."; - public static final String ERROR_EMPTY_EVENT_TIME = "☹ OOPS!!! The timing of a event cannot be empty."; - public static final String ERROR_EMPTY_DEADLINE_TIME = "☹ OOPS!!! The due date of a deadline cannot be empty."; + + public static final String ERROR_EMPTY_EVENT_TIME = "☹ OOPS!!! The timing of the event not detected, use [at] to indicated the time."; + public static final String ERROR_EMPTY_DEADLINE_TIME = "☹ OOPS!!! The due date of a deadline not detected, use [by] to indicated the date."; + public static final String ERROR_DONE_TASK_NOT_IN_LIST ="☹ OOPS!!! Task done not found in list"; + public static final String ERROR_DONE_TASK_EMPTY ="☹ OOPS!!! Cannot set task as complete without index."; + public static final String ERROR_DELETE_TASK ="☹ OOPS!!! Cannot remove task that does not exist."; + public static final String ERROR_DELETE_TASK_EMPTY ="☹ OOPS!!! Cannot remove task without index."; + public static final String ERROR_LETTER_NOT_FOUND = "☹ OOPS!!! Something went wrong. Do not input space or symbols."; - public static final String ERROR_FILE_MESSAGE_CREATION = "Something went wrong with creating files"; - public static final String ERROR_FILE_MESSAGE_READING = "Something went wrong with reading the files"; - public static final String ERROR_FILE_MESSAGE_WRITING = "Something went wrong with writing to the files"; + + public static final String ERROR_FILE_MESSAGE_CREATION = "☹ OOPS!!! Something went wrong with creating files"; + public static final String ERROR_FILE_MESSAGE_READING = "☹ OOPS!!! Something went wrong with reading the files"; + public static final String ERROR_FILE_MESSAGE_WRITING = "☹ OOPS!!! Something went wrong with writing to the files"; + + public static final String ERROR_DATE_TIME_PARSE = "☹ OOPS!!! Something went wrong with reading date or time\n" + + "Format of Date: YYYY-MM-DD\n" + "Format of Time: HH:MM"; + public static final String ERROR_DATE_SEARCH = "☹ OOPS!!! Date searched is invalid. Please enter date in format of YYYY-MM-DD"; + public static final String ERROR_EMPTY_DATE_SEARCH_TASK = "☹ OOPS!!! No tasks with date found."; + public static final String ERROR_EMPTY_DATE_INPUT = "☹ OOPS!!! Date Searched cannot be Empty."; } diff --git a/src/main/java/duke/Parser/Parser.java b/src/main/java/duke/Parser/Parser.java index 794b7fae0..a29866a7c 100644 --- a/src/main/java/duke/Parser/Parser.java +++ b/src/main/java/duke/Parser/Parser.java @@ -1,10 +1,8 @@ package duke.Parser; -import duke.ArtBot.Logo; import duke.Command.*; import duke.ErrorHandling.CommandException; import duke.ErrorHandling.ErrorStaticString; -import duke.Storage.Storage; import duke.TaskList.TaskList; import java.util.Objects; @@ -19,6 +17,7 @@ public class Parser{ private static final String COMMAND_ADD_DEADLINE = "deadline"; private static final String COMMAND_DELETE = "delete"; private static final String COMMAND_EXIT = "bye"; + private static final String COMMAND_DATE_TASK = "date"; private static final String EMPTY_STRING = ""; private static final String COMMAND_GUIDE_INDICATOR = "!"; private static final String SPLITTER = ";"; @@ -31,28 +30,31 @@ public Parser(String userInput, TaskList listManager){ this.listManager = listManager; } - private String taskCategory(String userInput){ - if(userInput.startsWith(COMMAND_VIEW_LIST)) { + private String taskCategory(String userInput) { + if (userInput.startsWith(COMMAND_VIEW_LIST)) { return COMMAND_VIEW_LIST; } - if(userInput.startsWith(COMMAND_ADD_DEADLINE)){ + if (userInput.startsWith(COMMAND_ADD_DEADLINE)) { return COMMAND_ADD_DEADLINE; } - if(userInput.startsWith(COMMAND_ADD_TODO)) { + if (userInput.startsWith(COMMAND_ADD_TODO)) { return COMMAND_ADD_TODO; } - if(userInput.startsWith(COMMAND_ADD_EVENT)){ + if (userInput.startsWith(COMMAND_ADD_EVENT)) { return COMMAND_ADD_EVENT; } - if(userInput.startsWith(COMMAND_COMPLETE_TASK)){ + if (userInput.startsWith(COMMAND_COMPLETE_TASK)) { return COMMAND_COMPLETE_TASK; } - if (userInput.startsWith(COMMAND_ECHO)){ + if (userInput.startsWith(COMMAND_ECHO)) { return COMMAND_ECHO; } - if(userInput.startsWith(COMMAND_DELETE)){ + if (userInput.startsWith(COMMAND_DELETE)) { return COMMAND_DELETE; } + if (userInput.startsWith(COMMAND_DATE_TASK)) { + return COMMAND_DATE_TASK; + } return null; } @@ -91,8 +93,7 @@ public void handleInput() throws CommandException{ throw new CommandException(ErrorStaticString.ERROR_NULL); } if(userInput.startsWith(COMMAND_GUIDE_INDICATOR)){ - String userInputWithoutIndicator = userInput.replaceFirst(COMMAND_GUIDE_INDICATOR,EMPTY_STRING).trim(); - CommandGuide commandGuide = new CommandGuide(userInputWithoutIndicator); + CommandGuide commandGuide = new CommandGuide(userInput); commandGuide.executeCommand(); }else{ splitInputIfThereMoreThanOneCommand(); @@ -103,7 +104,10 @@ private void splitInputIfThereMoreThanOneCommand() { userInput = userInput.replaceAll(SPLITTER,EMPTY_STRING); boolean isAddingTask = false; if (!isList()) { - isAddingTask = isTodo() || isEvent() || isDeadline(); + Boolean isTodo = isTodo(); + Boolean isEvent = isEvent(); + Boolean isDeadline = isDeadline(); + isAddingTask = isTodo || isEvent || isDeadline; } if(isAddingTask) { String[] commandList = userInput.split(SPLITTER); @@ -129,9 +133,12 @@ private void handleCommand(String inputCommand){ break; case COMMAND_COMPLETE_TASK: DoneCommand doneCommand = new DoneCommand(inputCommand, listManager); - doneCommand.executeCommand(); - listManager.printList(); - System.out.println(Logo.dividerWithoutNewLine); + try { + doneCommand.executeCommand(); + listManager.printList(); + } catch (CommandException e) { + e.handleException(); + } break; case COMMAND_ADD_EVENT: AddEventCommand addEvent = new AddEventCommand(inputCommand, listManager); @@ -172,6 +179,15 @@ private void handleCommand(String inputCommand){ } catch (CommandException e) { e.handleException(); } + break; + case COMMAND_DATE_TASK: + FindDateCommand findDateCommand = new FindDateCommand(inputCommand, listManager); + try { + findDateCommand.executeCommand(); + }catch (CommandException e){ + e.handleException(); + } + break; } }catch(NullPointerException e){ System.out.println(ErrorStaticString.ERROR_UNKNOWN_COMMAND); diff --git a/src/main/java/duke/Storage/FileRead.java b/src/main/java/duke/Storage/FileRead.java index 56b6f1475..0dfaba889 100644 --- a/src/main/java/duke/Storage/FileRead.java +++ b/src/main/java/duke/Storage/FileRead.java @@ -44,10 +44,10 @@ public ArrayList convertFileToTask() { listManager.addTodo(splitString[FILE_TASK_DESCRIPTION_POSITION], true); break; case FILE_EVENT_STATUS: - listManager.addEvent(splitString[FILE_TASK_DESCRIPTION_POSITION],splitString[FILE_TASK_DETAILS_POSITION], true); + listManager.addEvent(splitString[FILE_TASK_DESCRIPTION_POSITION],splitString[FILE_TASK_DETAIL_POSITION], true); break; case FILE_DEADLINE_STATUS: - listManager.addDeadline(splitString[FILE_TASK_DETAILS_POSITION],splitString[FILE_TASK_DETAILS_POSITION], true); + listManager.addDeadline(splitString[FILE_TASK_DESCRIPTION_POSITION],splitString[FILE_TASK_DETAIL_POSITION],true); } if (splitString[FILE_TASK_COMPLETE_POSITION].equals(FILE_COMPLETE_STATUS)){ try { diff --git a/src/main/java/duke/Storage/Storage.java b/src/main/java/duke/Storage/Storage.java index 99a958645..cdda23556 100644 --- a/src/main/java/duke/Storage/Storage.java +++ b/src/main/java/duke/Storage/Storage.java @@ -20,7 +20,8 @@ public class Storage { protected static final int FILE_TASK_TYPE_POSITION = 0; protected static final int FILE_TASK_COMPLETE_POSITION = 1; protected static final int FILE_TASK_DESCRIPTION_POSITION = 2; - protected static final int FILE_TASK_DETAILS_POSITION = 3; + protected static final int FILE_TASK_DETAIL_POSITION = 3; + protected File file; @@ -41,8 +42,12 @@ public ArrayList load(){ } public void appendTask(Task t){ + StringBuilder stringBuilder = new StringBuilder(); FileWrite fileWrite = new FileWrite(); - fileWrite.writeToFile(t.toFile(), true); + stringBuilder.append(t.toFile()); + stringBuilder.append(System.lineSeparator()); + String stringToWrite = stringBuilder.toString(); + fileWrite.writeToFile(stringToWrite, true); } public void writeTask(ArrayList list){ diff --git a/src/main/java/duke/TaskList/TaskList.java b/src/main/java/duke/TaskList/TaskList.java index 73f0467b2..200c53d49 100644 --- a/src/main/java/duke/TaskList/TaskList.java +++ b/src/main/java/duke/TaskList/TaskList.java @@ -7,6 +7,8 @@ import duke.task.Event; import duke.task.Task; import duke.task.ToDo; + +import java.time.LocalDate; import java.util.ArrayList; public class TaskList implements TaskListInterface { @@ -39,13 +41,32 @@ public void printList(){ printer(list); } + public void printDate(LocalDate dateSearched) throws CommandException{ + boolean haveDate = false; + ArrayList listOfTaskWithDate = new ArrayList<>(); + for (Task t: list){ + String date = t.getDate(t.convertStringToDate(), true); + if(!date.equals("")) { + LocalDate localDate = LocalDate.parse(date); + if (dateSearched.equals(localDate)) { + haveDate = true; + listOfTaskWithDate.add(t); + } + } + } + if(!haveDate){ + throw new CommandException(ErrorStaticString.ERROR_EMPTY_DATE_INPUT); + } + printer(listOfTaskWithDate); + } + public void printToDo() throws CommandException { boolean haveToDo = false; ArrayList listOfToDo = new ArrayList<>(); - for(int i = 0; i < list.size(); i++){ - if(list.get(i) instanceof ToDo){ + for(Task t: list){ + if(t instanceof ToDo){ haveToDo = true; - listOfToDo.add(list.get(i)); + listOfToDo.add(t); } } if(!haveToDo){ @@ -57,10 +78,10 @@ public void printToDo() throws CommandException { public void printEvent() throws CommandException{ boolean haveEvent = false; ArrayList listOfEvent = new ArrayList<>(); - for(int i = 0; i < list.size(); i++){ - if(list.get(i) instanceof Event) { + for (Task t : list) { + if (t instanceof Event) { haveEvent = true; - listOfEvent.add(list.get(i)); + listOfEvent.add(t); } } if(!haveEvent){ @@ -72,10 +93,10 @@ public void printEvent() throws CommandException{ public void printDeadline() throws CommandException{ boolean haveDeadline = false; ArrayList listOfDeadline = new ArrayList<>(); - for(int i = 0; i < list.size(); i++){ - if(list.get(i) instanceof Deadline) { + for (Task task : list) { + if (task instanceof Deadline) { haveDeadline = true; - listOfDeadline.add(list.get(i)); + listOfDeadline.add(task); } } if(!haveDeadline){ @@ -99,20 +120,20 @@ public void addTodo(String description, boolean isFromFile){ } } - public void addEvent(String description, String time, boolean isFromFile){ - Task t = new Event(description, time); + public void addEvent (String description, String eventDateTime, boolean isFromFile){ + Task t = new Event(description, eventDateTime); list.add(t); - if(!isFromFile) { + if (!isFromFile) { printAddItem(t); Storage storage = new Storage(); storage.appendTask(t); } } - public void addDeadline(String description, String deadline, boolean isFromFile){ - Task t = new Deadline(description, deadline); + public void addDeadline(String description, String deadlineDateTime, boolean isFromFile){ + Task t = new Deadline(description, deadlineDateTime); list.add(t); - if(!isFromFile) { + if (!isFromFile) { printAddItem(t); Storage storage = new Storage(); storage.appendTask(t); @@ -120,9 +141,6 @@ public void addDeadline(String description, String deadline, boolean isFromFile } public void completeTask(int t, boolean isFromFile) throws CommandException{ - if (t > list.size() || t < 0){ - throw new CommandException(ErrorStaticString.ERROR_DONE_TASK_NOT_IN_LIST); - } Task doneTask = list.get(t); doneTask.setDone(); if (!isFromFile) { @@ -132,10 +150,7 @@ public void completeTask(int t, boolean isFromFile) throws CommandException{ } } - public void deleteTask(int t) throws CommandException{ - if(t > list.size() || t < 0){ - throw new CommandException(ErrorStaticString.ERROR_DELETE_TASK); - } + public void deleteTask(int t){ Task removeTask = list.get(t); list.remove(t); printDeleteTask(removeTask); diff --git a/src/main/java/duke/TaskList/TaskListInterface.java b/src/main/java/duke/TaskList/TaskListInterface.java index 4a537cb07..d221aa9e0 100644 --- a/src/main/java/duke/TaskList/TaskListInterface.java +++ b/src/main/java/duke/TaskList/TaskListInterface.java @@ -8,8 +8,8 @@ public interface TaskListInterface { void printEvent() throws CommandException; void printDeadline() throws CommandException; void addTodo(String description, boolean isFromFile); - void addEvent(String description, String time, boolean isFromFile); - void addDeadline(String description, String deadline, boolean isFromFile); + void addEvent(String description, String eventDateTime, boolean isFromFile); + void addDeadline(String description, String deadlineDateTime, boolean isFromFile); void completeTask(int t, boolean isFromFile) throws CommandException; int getListSize(); } diff --git a/src/main/java/duke/Ui/Ui.java b/src/main/java/duke/Ui/Ui.java index b9f553c7e..be9b41e19 100644 --- a/src/main/java/duke/Ui/Ui.java +++ b/src/main/java/duke/Ui/Ui.java @@ -19,13 +19,10 @@ public void Farewell(){ } public void showLine(){ - System.out.println(Logo.divider); - } - - public void showLineWithoutNewLine(){ System.out.println(Logo.dividerWithoutNewLine); } + public String readCommand(){ Scanner in = new Scanner(System.in); return in.nextLine().toLowerCase().trim(); diff --git a/src/main/java/duke/task/Deadline.java b/src/main/java/duke/task/Deadline.java index d69335883..cfe7b3045 100644 --- a/src/main/java/duke/task/Deadline.java +++ b/src/main/java/duke/task/Deadline.java @@ -1,22 +1,104 @@ package duke.task; +import duke.ErrorHandling.ErrorStaticString; + +import java.time.LocalDate; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + public class Deadline extends Task{ private static final String TASK_SYMBOL = "[D]"; - private String dueDate; + private final String deadlineDateTime; - public Deadline(String description, String dueDate){ + public Deadline(String description, String deadlineDateTime){ super(description); - this.dueDate = dueDate; + this.deadlineDateTime = deadlineDateTime; + } + + private Matcher findDate(String stringToSearch){ + Pattern pattern = Pattern.compile(DATE_PATTERN); + Matcher matcher = pattern.matcher(stringToSearch); + if(matcher.find()){ + return matcher; + } + return null; + } + + private Matcher findTime(String stringToSearch){ + Pattern pattern = Pattern.compile(TIME_PATTERN); + Matcher matcher = pattern.matcher(stringToSearch); + if(matcher.find()){ + return matcher; + } + return null; + } + + @Override + public String convertStringToDate(){ + Matcher dateMatcher = findDate(deadlineDateTime); + if(dateMatcher != null){ + int startIndexOfDate = dateMatcher.start(); + int endIndexOfDate = dateMatcher.end(); + return deadlineDateTime.substring(startIndexOfDate,endIndexOfDate); + } + return EMPTY_STRING; + } + + private String convertStringToTime(){ + Matcher timeMatcher = findTime(deadlineDateTime); + if(timeMatcher != null){ + int startIndexOfTime = timeMatcher.start(); + int endIndexOfTime = timeMatcher.end(); + return deadlineDateTime.substring(startIndexOfTime,endIndexOfTime); + } + return EMPTY_STRING; + } + + @Override + public String getDate(String date, boolean isForFile) { + if(!date.isEmpty()) { + try { + LocalDate parseDate = LocalDate.parse(date); + if (isForFile){ + return parseDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); + } + return parseDate.format(DateTimeFormatter.ofPattern("MMM dd yyyy")); + }catch (DateTimeParseException e){ + System.out.println(ErrorStaticString.ERROR_DATE_TIME_PARSE); + } + } + return EMPTY_STRING; + } + + private String getTime(String time, boolean isForFile) { + if(!time.isEmpty()) { + try { + LocalTime parseTime = LocalTime.parse(time); + if(isForFile){ + return parseTime.format(DateTimeFormatter.ofPattern("hh:mm")); + } + return parseTime.format(DateTimeFormatter.ofPattern("hh:mm a")); + }catch (DateTimeParseException e){ + System.out.println(ErrorStaticString.ERROR_DATE_TIME_PARSE); + } + } + if(getDate(convertStringToDate(),false).equals(EMPTY_STRING)) { + return deadlineDateTime; + } + return EMPTY_STRING; } @Override public String toString(){ - return TASK_SYMBOL + super.toString() + "(by: " + dueDate + ")"; + return TASK_SYMBOL + super.toString() + "(by: " + getTime(convertStringToTime(),false) + " " + getDate(convertStringToDate(),false) + ")"; } @Override public String toFile(){ - return TASK_SYMBOL + SEPARATOR + super.toFile() + SEPARATOR + dueDate + System.lineSeparator(); + return TASK_SYMBOL + SEPARATOR + super.toFile() + SEPARATOR + getTime(convertStringToTime(),true) + " " + getDate(convertStringToDate(),true); } } diff --git a/src/main/java/duke/task/Event.java b/src/main/java/duke/task/Event.java index 52c196224..40778a844 100644 --- a/src/main/java/duke/task/Event.java +++ b/src/main/java/duke/task/Event.java @@ -1,22 +1,103 @@ package duke.task; +import duke.ErrorHandling.ErrorStaticString; + +import java.time.LocalDate; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + public class Event extends Task{ private static final String TASK_SYMBOL = "[E]"; - private String startTime; + private final String eventDateTime; - public Event(String description, String startTime){ + public Event(String description, String eventDateTime){ super(description); - this.startTime = startTime; + this.eventDateTime = eventDateTime; + } + + private Matcher findDate(String stringToSearch){ + Pattern pattern = Pattern.compile(DATE_PATTERN); + Matcher matcher = pattern.matcher(stringToSearch); + if(matcher.find()){ + return matcher; + } + return null; + } + + private Matcher findTime(String stringToSearch){ + Pattern pattern = Pattern.compile(TIME_PATTERN); + Matcher matcher = pattern.matcher(stringToSearch); + if(matcher.find()){ + return matcher; + } + return null; + } + + public String convertStringToDate(){ + Matcher dateMatcher = findDate(eventDateTime); + if(dateMatcher != null){ + int startIndexOfDate = dateMatcher.start(); + int endIndexOfDate = dateMatcher.end(); + return eventDateTime.substring(startIndexOfDate,endIndexOfDate); + } + return EMPTY_STRING; + } + + private String convertStringToTime(){ + Matcher timeMatcher = findTime(eventDateTime); + if(timeMatcher != null){ + int startIndexOfTime = timeMatcher.start(); + int endIndexOfTime = timeMatcher.end(); + return eventDateTime.substring(startIndexOfTime,endIndexOfTime); + } + return EMPTY_STRING; + } + + @Override + public String getDate(String date, boolean isForFile) { + if(!date.isEmpty()) { + try { + LocalDate parseDate = LocalDate.parse(date); + if(isForFile){ + return parseDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); + } + return parseDate.format(DateTimeFormatter.ofPattern("MMM dd yyyy")); + }catch (DateTimeParseException e){ + System.out.println(ErrorStaticString.ERROR_DATE_TIME_PARSE); + } + } + return EMPTY_STRING; + } + + private String getTime(String time, boolean isForFile) { + if(!time.isEmpty()) { + try { + LocalTime parseTime = LocalTime.parse(time); + if(isForFile){ + return parseTime.format(DateTimeFormatter.ofPattern("hh:mm")); + } + return parseTime.format(DateTimeFormatter.ofPattern("hh:mm a")); + }catch (DateTimeParseException e){ + System.out.println(ErrorStaticString.ERROR_DATE_TIME_PARSE); + } + } + if(getDate(convertStringToDate(),false).equals(EMPTY_STRING)) { + return eventDateTime; + } + return EMPTY_STRING; } @Override public String toString(){ - return TASK_SYMBOL + super.toString() + "(at: " + startTime + ")"; + return TASK_SYMBOL + super.toString() + "(at: " + getTime(convertStringToTime(),false) + " " + getDate(convertStringToDate(), false) + ")"; } @Override public String toFile(){ - return TASK_SYMBOL + SEPARATOR + super.toString() + SEPARATOR + startTime + System.lineSeparator(); + return TASK_SYMBOL + SEPARATOR + super.toFile() + SEPARATOR + getTime(convertStringToTime(),true) + " " + getDate(convertStringToDate(),true); } } diff --git a/src/main/java/duke/task/Task.java b/src/main/java/duke/task/Task.java index bb38dd86d..4e1401a1a 100644 --- a/src/main/java/duke/task/Task.java +++ b/src/main/java/duke/task/Task.java @@ -3,6 +3,10 @@ public class Task implements TaskInterface { private static final String COMPLETE_STATUS_ICON = "[X]"; private static final String INCOMPLETE_STATUS_ICON = "[ ]"; + protected static final String DATE_PATTERN = "\\d{4}-\\d{1,2}-\\d{1,2}"; + protected static final String TIME_PATTERN = "\\d{2}:\\d{2}"; + protected static final String EMPTY_STRING = ""; + private final String description; private boolean isDone; protected static final String SEPARATOR = ";"; @@ -16,6 +20,10 @@ public void setDone(){ isDone = true; } + public String getDate(String date, boolean isForFile){return EMPTY_STRING;} + + public String convertStringToDate(){return EMPTY_STRING;} + public String getDescription(){ return description; } diff --git a/src/main/java/duke/task/ToDo.java b/src/main/java/duke/task/ToDo.java index 98554f6b4..d9904e98c 100644 --- a/src/main/java/duke/task/ToDo.java +++ b/src/main/java/duke/task/ToDo.java @@ -15,6 +15,6 @@ public String toString() { @Override public String toFile(){ - return TASK_SYMBOL + SEPARATOR + super.toFile() + System.lineSeparator(); + return TASK_SYMBOL + SEPARATOR + super.toFile(); } } diff --git a/text-ui-test/EXPECTED.txt b/text-ui-test/EXPECTED.txt index d8711c5de..d04327598 100644 --- a/text-ui-test/EXPECTED.txt +++ b/text-ui-test/EXPECTED.txt @@ -11,82 +11,153 @@ ____________________________________________________________ ____________________________________________________________ hi ____________________________________________________________ +____________________________________________________________ HI ___ ___ .___ / | \ | | / ~ \| | \ Y /| | \___|___/ |___| +____________________________________________________________ +____________________________________________________________ ☹ OOPS!!! List is empty. Add tasks to the list. ____________________________________________________________ +____________________________________________________________ Got it. I've added this task: [T][ ]watch et1231 livestream Now you have 1 tasks in the list. -____________________________________________________________ -____________________________________________________________ Got it. I've added this task: -[T][ ]watch hankyuu livestream +[E][ ]watch hankyuu livestream(at: midnight ) Now you have 2 tasks in the list. ____________________________________________________________ ____________________________________________________________ -Bye. Hope to see you again soon! -____________________________________________________________ -_______________.___.___________ -\______ \__ | |\_ _____/ - | | _// | | | __)_ - | | \\____ | | \ - |________// ______|/_________/ -____________________________________________________________ Got it. I've added this task: [T][ ]watch haxxnini livestream Now you have 3 tasks in the list. ____________________________________________________________ ____________________________________________________________ +☹ OOPS!!! The due date of a deadline not detected, use [by] to indicated the date. +____________________________________________________________ +____________________________________________________________ Got it. I've added this task: -[D][ ]reach radiant(by: this season) +[D][ ]reach legend(by: this season ) Now you have 4 tasks in the list. ____________________________________________________________ ____________________________________________________________ Got it. I've added this task: -[E][ ]g2 vs sentinel(at:12am) +[D][ ]reach gold(by: 08:00 PM ) Now you have 5 tasks in the list. ____________________________________________________________ ____________________________________________________________ +Got it. I've added this task: +[D][ ]reach silver(by: Oct 10 2020) +Now you have 6 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Got it. I've added this task: +[D][ ]reach bronze(by: 08:00 PM Oct 10 2020) +Now you have 7 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Here are the tasks in your list: +1. [D][ ]reach silver(by: Oct 10 2020) +2. [D][ ]reach bronze(by: 08:00 AM Oct 10 2020) +____________________________________________________________ +____________________________________________________________ +☹ OOPS!!! The timing of the event not detected, use [at] to indicated the time. +____________________________________________________________ +____________________________________________________________ +Here are the tasks in your list: +1. [E][ ]g2 vs sentinel(at: 12am) +____________________________________________________________ +____________________________________________________________ +Got it. I've added this task: +[E][ ]g2 vs sentinel(at: 10pm ) +Now you have 8 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Got it. I've added this task: +[E][ ]g2 vs sentinel(at: 10:00 PM ) +Now you have 9 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Got it. I've added this task: +[E][ ]g2 vs sentinel(at: 10:00 PM Oct 10 2020) +Now you have 10 tasks in the list. +____________________________________________________________ +____________________________________________________________ Here are the tasks in your list: 1. [T][ ]watch et1231 livestream -2. [T][ ]watch hankyuu livestream +2. [E][ ]watch hankyuu livestream(at: midnight ) 3. [T][ ]watch haxxnini livestream -4. [D][ ]reach radiant(by: this season) -5. [E][ ]g2 vs sentinel(at:12am) +4. [D][ ]reach legend(by: this season ) +5. [D][ ]reach gold(by: 08:00 AM ) +6. [D][ ]reach silver(by: Oct 10 2020) +7. [D][ ]reach bronze(by: 08:00 AM Oct 10 2020) +8. [E][ ]g2 vs sentinel(at: 10pm ) +9. [E][ ]g2 vs sentinel(at: 10:00 PM ) +10. [E][ ]g2 vs sentinel(at: 10:00 PM Oct 10 2020) +____________________________________________________________ +____________________________________________________________ +Here are the tasks in your list: +1. [T][ ]watch et1231 livestream +2. [T][ ]watch haxxnini livestream +____________________________________________________________ +____________________________________________________________ +Here are the tasks in your list: +1. [D][ ]reach legend(by: this season ) +2. [D][ ]reach gold(by: 08:00 AM ) +3. [D][ ]reach silver(by: Oct 10 2020) +4. [D][ ]reach bronze(by: 08:00 AM Oct 10 2020) +____________________________________________________________ +____________________________________________________________ +Here are the tasks in your list: +1. [E][ ]watch hankyuu livestream(at: midnight ) +2. [E][ ]g2 vs sentinel(at: 10pm ) +3. [E][ ]g2 vs sentinel(at: 10:00 PM ) +4. [E][ ]g2 vs sentinel(at: 10:00 PM Oct 10 2020) +____________________________________________________________ ____________________________________________________________ ____________________________________________________________ Nice! I've marked this task as done: [T][X]watch et1231 livestream -[T][X]watch hankyuu livestream -[D][X]reach radiant(by: this season) -____________________________________________________________ +[E][X]watch hankyuu livestream(at: midnight ) +[T][X]watch haxxnini livestream Here are the tasks in your list: 1. [T][X]watch et1231 livestream -2. [T][X]watch hankyuu livestream -3. [T][ ]watch haxxnini livestream -4. [D][X]reach radiant(by: this season) -5. [E][ ]g2 vs sentinel(at:12am) +2. [E][X]watch hankyuu livestream(at: midnight ) +3. [T][X]watch haxxnini livestream +4. [D][ ]reach legend(by: this season ) +5. [D][ ]reach gold(by: 08:00 AM ) +6. [D][ ]reach silver(by: Oct 10 2020) +7. [D][ ]reach bronze(by: 08:00 AM Oct 10 2020) +8. [E][ ]g2 vs sentinel(at: 10pm ) +9. [E][ ]g2 vs sentinel(at: 10:00 PM ) +10. [E][ ]g2 vs sentinel(at: 10:00 PM Oct 10 2020) ____________________________________________________________ ____________________________________________________________ Noted. I've removed this task: +[E][X]watch hankyuu livestream(at: midnight ) +Now you have 9 tasks in the list. +Noted. I've removed this task: [T][X]watch et1231 livestream -Now you have 4 tasks in the list. +Now you have 8 tasks in the list. ____________________________________________________________ ____________________________________________________________ Here are the tasks in your list: -1. [T][X]watch hankyuu livestream -2. [T][ ]watch haxxnini livestream -3. [D][X]reach radiant(by: this season) -4. [E][ ]g2 vs sentinel(at:12am) +1. [T][X]watch haxxnini livestream +2. [D][ ]reach legend(by: this season ) +3. [D][ ]reach gold(by: 08:00 AM ) +4. [D][ ]reach silver(by: Oct 10 2020) +5. [D][ ]reach bronze(by: 08:00 AM Oct 10 2020) +6. [E][ ]g2 vs sentinel(at: 10pm ) +7. [E][ ]g2 vs sentinel(at: 10:00 AM ) +8. [E][ ]g2 vs sentinel(at: 10:00 AM Oct 10 2020) +____________________________________________________________ ____________________________________________________________ ☹ OOPS!!! I'm sorry, but I don't know what that means :-( Defaulting to Echo. Type !help to see the list of Commands -____________________________________________________________ + random command ____________________________________________________________ ____________________________________________________________ @@ -97,22 +168,26 @@ List of Commands: event - Add Event Task - !event for details deadline - Add Deadline Task - !deadline for details bye - Shut Down + ____________________________________________________________ ____________________________________________________________ list displays all tasks list todo displays all todo tasks list event displays all event tasks list deadline displays all deadline tasks + ____________________________________________________________ ____________________________________________________________ event command requires a timing indicated using "at" [timing] + ____________________________________________________________ ____________________________________________________________ deadline command requires a end time indicated using "by"[end time] + ____________________________________________________________ ____________________________________________________________ -Bye. Hope to see you again soon! ____________________________________________________________ +Bye. Hope to see you again soon! _______________.___.___________ \______ \__ | |\_ _____/ | | _// | | | __)_ diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index c1eb045ff..3d85b04d7 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -1,14 +1,24 @@ echo Hi !echo hi list -todo watch et1231 livestream todo watch hankyuu livestream -bye +todo watch et1231 livestream event watch hankyuu livestream at midnight todo watch haxxnini livestream -deadline reach radiant by this season -event G2 vs Sentinel at 12am +deadline reach radiant +deadline reach legend by this season +deadline reach gold by 20:00 +deadline reach silver by 2020-10-10 +deadline reach bronze by 20:00 2020-10-10 +date 2020-10-10 +event G2 vs Sentinel +event G2 vs Sentinel at 10pm +event G2 vs Sentinel at 22:00 +event G2 vs Sentinel at 22:00 2020-10-10 list -done 1,2,4 -delete 1 +list todo +list deadline +list event +done 1,2,3 +delete 1,2 list random command !help From 71fb4c5077eff1d4e495e49ea5a62d695b641913 Mon Sep 17 00:00:00 2001 From: wingho2 Date: Mon, 27 Sep 2021 12:04:01 +0800 Subject: [PATCH 23/62] Added Find Keyword to search the list --- src/main/java/duke/Command/Command.java | 1 + .../java/duke/Command/FindDateCommand.java | 1 - .../java/duke/Command/FindKeywordCommand.java | 27 +++++++++++++++++++ src/main/java/duke/Parser/Parser.java | 11 ++++++++ src/main/java/duke/TaskList/TaskList.java | 26 +++++++++++++++++- 5 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 src/main/java/duke/Command/FindKeywordCommand.java diff --git a/src/main/java/duke/Command/Command.java b/src/main/java/duke/Command/Command.java index 7b257b851..e02282a01 100644 --- a/src/main/java/duke/Command/Command.java +++ b/src/main/java/duke/Command/Command.java @@ -16,6 +16,7 @@ public abstract class Command { protected static final String COMMAND_ADD_EVENT = "event"; protected static final String COMMAND_ADD_DEADLINE = "deadline"; protected static final String COMMAND_DELETE = "delete"; + protected static final String COMMAND_FIND_WORD = "find"; protected static final String EVENT_TIME = "at "; protected static final String DEADLINE_DATE = "by "; protected static final String MESSAGE_TASK_COMPLETE = "Nice! I've marked this task as done: "; diff --git a/src/main/java/duke/Command/FindDateCommand.java b/src/main/java/duke/Command/FindDateCommand.java index ccc93fecb..6f938acba 100644 --- a/src/main/java/duke/Command/FindDateCommand.java +++ b/src/main/java/duke/Command/FindDateCommand.java @@ -3,7 +3,6 @@ import duke.ErrorHandling.CommandException; import duke.ErrorHandling.ErrorStaticString; import duke.TaskList.TaskList; - import java.time.LocalDate; import java.time.format.DateTimeParseException; import java.util.regex.Matcher; diff --git a/src/main/java/duke/Command/FindKeywordCommand.java b/src/main/java/duke/Command/FindKeywordCommand.java new file mode 100644 index 000000000..a5eb459da --- /dev/null +++ b/src/main/java/duke/Command/FindKeywordCommand.java @@ -0,0 +1,27 @@ +package duke.Command; + +import duke.ErrorHandling.CommandException; +import duke.ErrorHandling.ErrorStaticString; +import duke.TaskList.TaskList; + +public class FindKeywordCommand extends Command{ + + private final TaskList taskList; + + public FindKeywordCommand(String taskInput, TaskList taskList){ + super(taskInput); + this.taskList = taskList; + } + + @Override + public void executeCommand() throws CommandException{ + if(taskList.getListSize() == 0){ + throw new CommandException(ErrorStaticString.ERROR_EMPTY_LIST); + } + taskInput = taskInput.replaceFirst(COMMAND_FIND_WORD,EMPTY_STRING).trim(); + if(taskInput.isEmpty()){ + throw new CommandException(ErrorStaticString.ERROR_EMPTY_LIST); + } + taskList.printWord(taskInput); + } +} diff --git a/src/main/java/duke/Parser/Parser.java b/src/main/java/duke/Parser/Parser.java index a29866a7c..1bc8e49b4 100644 --- a/src/main/java/duke/Parser/Parser.java +++ b/src/main/java/duke/Parser/Parser.java @@ -18,6 +18,7 @@ public class Parser{ private static final String COMMAND_DELETE = "delete"; private static final String COMMAND_EXIT = "bye"; private static final String COMMAND_DATE_TASK = "date"; + private static final String COMMAND_FIND_WORD = "find"; private static final String EMPTY_STRING = ""; private static final String COMMAND_GUIDE_INDICATOR = "!"; private static final String SPLITTER = ";"; @@ -55,6 +56,9 @@ private String taskCategory(String userInput) { if (userInput.startsWith(COMMAND_DATE_TASK)) { return COMMAND_DATE_TASK; } + if(userInput.startsWith(COMMAND_FIND_WORD)){ + return COMMAND_FIND_WORD; + } return null; } @@ -188,6 +192,13 @@ private void handleCommand(String inputCommand){ e.handleException(); } break; + case COMMAND_FIND_WORD: + FindKeywordCommand findKeywordCommand = new FindKeywordCommand(inputCommand, listManager); + try { + findKeywordCommand.executeCommand(); + }catch (CommandException e){ + e.handleException(); + } } }catch(NullPointerException e){ System.out.println(ErrorStaticString.ERROR_UNKNOWN_COMMAND); diff --git a/src/main/java/duke/TaskList/TaskList.java b/src/main/java/duke/TaskList/TaskList.java index 200c53d49..5163f06a5 100644 --- a/src/main/java/duke/TaskList/TaskList.java +++ b/src/main/java/duke/TaskList/TaskList.java @@ -16,6 +16,7 @@ public class TaskList implements TaskListInterface { private static final String MESSAGE_TASK_ADDED = "Got it. I've added this task: "; private static final String MESSAGE_TASK_IN_LIST = " tasks in the list."; private static final String MESSAGE_LIST_TASK = "Here are the tasks in your list:"; + private static final String MESSAGE_FIND_TASK = "Here are the matching tasks in your list:"; private static final String MESSAGE_TASK_NOW = "Now you have "; private static final String MESSAGE_DELETE = "Noted. I've removed this task: "; private static final String MESSAGE_SPACER = ". "; @@ -37,6 +38,14 @@ private void printer(ArrayList listToPrint){ } } + private void printerForFind(ArrayList listToPrint){ + System.out.println(MESSAGE_FIND_TASK); + for(int i = 0; i < listToPrint.size(); i++){ + int itemIndex= i + 1; + System.out.println(itemIndex + MESSAGE_SPACER + listToPrint.get(i).toString()); + } + } + public void printList(){ printer(list); } @@ -57,7 +66,22 @@ public void printDate(LocalDate dateSearched) throws CommandException{ if(!haveDate){ throw new CommandException(ErrorStaticString.ERROR_EMPTY_DATE_INPUT); } - printer(listOfTaskWithDate); + printerForFind(listOfTaskWithDate); + } + + public void printWord(String wordSearch) throws CommandException{ + boolean haveWord = false; + ArrayList listOfTaskWithWord = new ArrayList<>(); + for(Task t : list){ + if(t.getDescription().contains(wordSearch)){ + listOfTaskWithWord.add(t); + haveWord = true; + } + } + if(!haveWord){ + throw new CommandException(ErrorStaticString.ERROR_EMPTY_LIST); + } + printerForFind(listOfTaskWithWord); } public void printToDo() throws CommandException { From 30a5c96d5681b630458ef3ec55714633e9c9da0e Mon Sep 17 00:00:00 2001 From: wingho2 Date: Tue, 28 Sep 2021 14:27:07 +0800 Subject: [PATCH 24/62] Added Comment to All function and classes --- src/main/java/duke/ArtBot/ArtBot.java | 38 ++++- src/main/java/duke/ArtBot/Logo.java | 3 + src/main/java/duke/Command/ArtCommand.java | 12 +- src/main/java/duke/Command/ClearCommand.java | 29 ++++ src/main/java/duke/Command/Command.java | 12 ++ src/main/java/duke/Command/CommandGuide.java | 14 +- src/main/java/duke/Command/DeleteCommand.java | 18 ++ src/main/java/duke/Command/DoneCommand.java | 18 +- src/main/java/duke/Command/EchoCommand.java | 15 +- .../java/duke/Command/FindDateCommand.java | 27 +++ .../java/duke/Command/FindKeywordCommand.java | 14 ++ src/main/java/duke/Command/ListCommand.java | 15 ++ src/main/java/duke/Duke.java | 17 ++ .../duke/ErrorHandling/CommandException.java | 18 +- .../duke/ErrorHandling/ErrorStaticString.java | 3 + src/main/java/duke/Parser/Parser.java | 71 +++++++- src/main/java/duke/Storage/FileRead.java | 35 +++- src/main/java/duke/Storage/FileWrite.java | 11 +- src/main/java/duke/Storage/Storage.java | 45 ++++- src/main/java/duke/TaskList/TaskList.java | 154 ++++++++++++++++-- .../java/duke/TaskList/TaskListInterface.java | 7 +- src/main/java/duke/Ui/Ui.java | 38 ++++- src/main/java/duke/task/Deadline.java | 57 ++++++- src/main/java/duke/task/Event.java | 58 ++++++- src/main/java/duke/task/Task.java | 48 +++++- src/main/java/duke/task/TaskInterface.java | 4 + src/main/java/duke/task/ToDo.java | 18 ++ 27 files changed, 751 insertions(+), 48 deletions(-) create mode 100644 src/main/java/duke/Command/ClearCommand.java diff --git a/src/main/java/duke/ArtBot/ArtBot.java b/src/main/java/duke/ArtBot/ArtBot.java index b1ced689f..a2f7df19e 100644 --- a/src/main/java/duke/ArtBot/ArtBot.java +++ b/src/main/java/duke/ArtBot/ArtBot.java @@ -2,17 +2,32 @@ import duke.ErrorHandling.CommandException; import duke.ErrorHandling.ErrorStaticString; - import java.util.ArrayList; +/** + * Convert a string into graffiti form and print it out + */ public class ArtBot implements ArtInterface { private final String userInput; + /** + * Constructor for ArtBot + * Assign string to be drawn + * + * @param userInput String to be drawn + */ public ArtBot(String userInput){ this.userInput = userInput; } + /** + * Each Drawn version of a letter take up 5 line + * Convert letter into drawn version of string + * + * @param letter Letter to convert into array of string + * @return Array of string representing a letter + */ private String[] getLogo(String letter){ String[] letterArt; switch(letter) { @@ -131,6 +146,13 @@ private String[] getLogo(String letter){ return letterArt; } + /** + * Convert each letter of string into drawn form + * + * @param inputArrayOfLetter array of Char(letters) + * @return list of string array where each string array is drawn version of a letter + * @throws CommandException if char is anything other than A-Z,0-9 + */ private ArrayList getLetterInArtForm(String[] inputArrayOfLetter) throws CommandException{ ArrayList listToStoreLetterInArtForm = new ArrayList<>(); for(String s:inputArrayOfLetter){ @@ -143,6 +165,12 @@ private ArrayList getLetterInArtForm(String[] inputArrayOfLetter) thro return listToStoreLetterInArtForm; } + /** + * Merge same index of string in each string array + * First String in First String Array with First String in Second String Array and so on... + * @param arrayToMerge list of String Array to merge + * @return String Array of 5 String after all have been merged + */ private String[] mergeArray(ArrayList arrayToMerge){ String[] arrayToReturn = new String[5]; for(int i = 0; i < 5; i++){ @@ -156,12 +184,20 @@ private String[] mergeArray(ArrayList arrayToMerge){ return arrayToReturn; } + /** + * Print a array of 5 Strings + * + * @param array Array to print + */ private void printArray(String[] array){ for(int i = 0; i < 5; i++){ System.out.println(array[i]); } } + /** + * Handle interaction of other classes to echo a string in drawn form + */ public void drawArt() { String[] letterArray = userInput.split("(?!^)"); ArrayList letterInArtFormList = null; diff --git a/src/main/java/duke/ArtBot/Logo.java b/src/main/java/duke/ArtBot/Logo.java index 3c302a5d6..27b2da165 100644 --- a/src/main/java/duke/ArtBot/Logo.java +++ b/src/main/java/duke/ArtBot/Logo.java @@ -1,5 +1,8 @@ package duke.ArtBot; +/** + * Store Images formed by Strings + */ public class Logo { public static final String divider = "____________________________________________________________\n"; public static final String dividerWithoutNewLine = "____________________________________________________________"; diff --git a/src/main/java/duke/Command/ArtCommand.java b/src/main/java/duke/Command/ArtCommand.java index 46713f9dd..ca9d58cff 100644 --- a/src/main/java/duke/Command/ArtCommand.java +++ b/src/main/java/duke/Command/ArtCommand.java @@ -2,13 +2,23 @@ import duke.ArtBot.ArtBot; +/** + * Represent a command that echo string in graffiti form + */ public class ArtCommand extends CommandGuide{ - + /** + * Constructor for ArtCommand + * + * @param userInput Command input by user to process + */ public ArtCommand(String userInput){ super(userInput); } + /** + * Filter out string to echo in graffiti and hand over drawing to artbot class + */ public void handleArtCommand(){ String removeCommand = taskInput.replaceFirst(COMMAND_ECHO_ART,EMPTY_STRING).trim().toUpperCase(); System.out.println(removeCommand); diff --git a/src/main/java/duke/Command/ClearCommand.java b/src/main/java/duke/Command/ClearCommand.java new file mode 100644 index 000000000..f61bf7e92 --- /dev/null +++ b/src/main/java/duke/Command/ClearCommand.java @@ -0,0 +1,29 @@ +package duke.Command; + +import duke.TaskList.TaskList; + +/** + * Represent a command that clears all task in list + */ +public class ClearCommand extends Command{ + + private final TaskList taskList; + + /** + * Constructor for ClearCommand + * @param taskInput Command input by user to process + * @param taskList Tasklist to interact with list of task + */ + public ClearCommand(String taskInput, TaskList taskList){ + super(taskInput); + this.taskList = taskList; + } + + /** + * Clear the list in Tasklist + */ + @Override + public void executeCommand(){ + taskList.clearTask(); + } +} diff --git a/src/main/java/duke/Command/Command.java b/src/main/java/duke/Command/Command.java index e02282a01..96733477c 100644 --- a/src/main/java/duke/Command/Command.java +++ b/src/main/java/duke/Command/Command.java @@ -2,6 +2,9 @@ import duke.ErrorHandling.CommandException; +/** + * Represent a general structure for all commands + */ public abstract class Command { protected static final String COMMAND_HELP = "!help"; protected static final String COMMAND_LIST_HELP = "!list"; @@ -17,6 +20,7 @@ public abstract class Command { protected static final String COMMAND_ADD_DEADLINE = "deadline"; protected static final String COMMAND_DELETE = "delete"; protected static final String COMMAND_FIND_WORD = "find"; + protected static final String COMMAND_CLEAR_WORD = "clear"; protected static final String EVENT_TIME = "at "; protected static final String DEADLINE_DATE = "by "; protected static final String MESSAGE_TASK_COMPLETE = "Nice! I've marked this task as done: "; @@ -42,9 +46,17 @@ public abstract class Command { protected String taskInput; + /** + * Constructor for Command + * @param taskInput Command input to process + */ public Command(String taskInput){ this.taskInput = taskInput; } + /** + * A function to perform what the command is supposed to do + * @throws CommandException when error encountered for specific command + */ public abstract void executeCommand() throws CommandException; } diff --git a/src/main/java/duke/Command/CommandGuide.java b/src/main/java/duke/Command/CommandGuide.java index 23015538d..0889dcbe0 100644 --- a/src/main/java/duke/Command/CommandGuide.java +++ b/src/main/java/duke/Command/CommandGuide.java @@ -1,14 +1,22 @@ package duke.Command; -import duke.ArtBot.Logo; - +/** + * Represent multiple simple one word commands that mainly just print out messages + */ public class CommandGuide extends Command{ - + /** + * Constructor for CommandGuide + * + * @param taskInput Command input by user + */ public CommandGuide(String taskInput){ super(taskInput); } + /** + * Print out a fixed message depending on user input or hand over processing of input to ArtCommand + */ @Override public void executeCommand(){ if(taskInput.startsWith(COMMAND_ECHO_ART)){ diff --git a/src/main/java/duke/Command/DeleteCommand.java b/src/main/java/duke/Command/DeleteCommand.java index 236ae0017..aa1869ebe 100644 --- a/src/main/java/duke/Command/DeleteCommand.java +++ b/src/main/java/duke/Command/DeleteCommand.java @@ -6,15 +6,33 @@ import java.util.ArrayList; import java.util.Collections; +/** + * Represent a command that remove a task from list + */ public class DeleteCommand extends Command{ private final TaskList listManager; + /** + * Constructor for DeleteCommand + * + * @param userInput Command input by user to process + * @param listManager Tasklist to interact with list of task + */ public DeleteCommand(String userInput, TaskList listManager){ super(userInput); this.listManager = listManager; } + /** + * Handle removing multiple task from list + * Extract index of task separated with ",' and put into a list + * Convert index of task into int by parsing + * Sort int list into decreasing order so that the correct task will be deleted + * Removal of task is handled in Tasklist and according to the order by Sorted int list + * + * @throws CommandException if task to delete is empty or if deleting a task that non-existent + */ @Override public void executeCommand()throws CommandException { String removeCommand = taskInput.replaceFirst(COMMAND_DELETE,EMPTY_STRING).trim(); diff --git a/src/main/java/duke/Command/DoneCommand.java b/src/main/java/duke/Command/DoneCommand.java index 840cbbf1c..4767e6432 100644 --- a/src/main/java/duke/Command/DoneCommand.java +++ b/src/main/java/duke/Command/DoneCommand.java @@ -3,18 +3,34 @@ import duke.ErrorHandling.CommandException; import duke.ErrorHandling.ErrorStaticString; import duke.TaskList.TaskList; - import java.util.ArrayList; +/** + * Represent a command that set task as completed + */ public class DoneCommand extends Command{ private final TaskList listManager; + /** + * Constructor for DoneCommand + * + * @param userInput Command input by user to process + * @param listManager Tasklist to interact with list of task + */ public DoneCommand(String userInput, TaskList listManager){ super(userInput); this.listManager = listManager; } + /** + * Handle setting multiple tasks as completed + * Filter out Command and split index of task into array of string by "," + * Convert index of task in string into integer + * Set each task as done in TaskList class + * + * @throws CommandException if task to set as complete is empty or if task to set as complete does not exist + */ @Override public void executeCommand() throws CommandException{ String removeCommand = taskInput.replaceFirst(COMMAND_COMPLETE_TASK,EMPTY_STRING).trim(); diff --git a/src/main/java/duke/Command/EchoCommand.java b/src/main/java/duke/Command/EchoCommand.java index 7cf62dbb6..ef4502cf5 100644 --- a/src/main/java/duke/Command/EchoCommand.java +++ b/src/main/java/duke/Command/EchoCommand.java @@ -1,16 +1,27 @@ package duke.Command; -import duke.ArtBot.Logo; import duke.ErrorHandling.CommandException; import duke.ErrorHandling.ErrorStaticString; +/** + * Represent a command the echo back what was input by user + */ public class EchoCommand extends Command{ - + /** + * Constructor for Echo Command + * + * @param userInput Command input by user to process + */ public EchoCommand(String userInput){ super(userInput); } + /** + * Remove command from string and echo back remaining string + * + * @throws CommandException if string to echo is empty + */ public void executeCommand() throws CommandException { String removeCommand = taskInput.replaceFirst(COMMAND_ECHO, EMPTY_STRING).trim(); if(removeCommand.isEmpty()){ diff --git a/src/main/java/duke/Command/FindDateCommand.java b/src/main/java/duke/Command/FindDateCommand.java index 6f938acba..f7af509e6 100644 --- a/src/main/java/duke/Command/FindDateCommand.java +++ b/src/main/java/duke/Command/FindDateCommand.java @@ -8,15 +8,30 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +/** + * Represent a command that filter out task with a specific date and print to user + */ public class FindDateCommand extends Command{ private final TaskList taskList; + /** + * Constructor for FindDateCommand + * + * @param taskInput Command input by user to process + * @param taskList Tasklist to interact with list of task + */ public FindDateCommand(String taskInput, TaskList taskList){ super(taskInput); this.taskList = taskList; } + /** + * Filter out date to search and convert to LocalDate object + * Pass searching of date to TaskList + * + * @throws CommandException if list is empty or if date to search is empty + */ @Override public void executeCommand() throws CommandException { if(taskList.getListSize() == 0){ @@ -34,6 +49,13 @@ public void executeCommand() throws CommandException { } } + /** + * Find first instance of a date by finding a string in a pattern + * Pattern:4int-2int-2int + * + * @param stringToSearch String that contain date + * @return Null if no date is found or return a matcher object that found date + */ private Matcher findDate(String stringToSearch){ Pattern pattern = Pattern.compile(DATE_PATTERN); Matcher matcher = pattern.matcher(stringToSearch); @@ -43,6 +65,11 @@ private Matcher findDate(String stringToSearch){ return null; } + /** + * Extract string containing date + * + * @return string containing date or Empty String if no date found + */ private String convertStringToDate(){ Matcher dateMatcher = findDate(taskInput); if(dateMatcher != null){ diff --git a/src/main/java/duke/Command/FindKeywordCommand.java b/src/main/java/duke/Command/FindKeywordCommand.java index a5eb459da..98dbaf972 100644 --- a/src/main/java/duke/Command/FindKeywordCommand.java +++ b/src/main/java/duke/Command/FindKeywordCommand.java @@ -4,15 +4,29 @@ import duke.ErrorHandling.ErrorStaticString; import duke.TaskList.TaskList; +/** + * Represent a command that filter out tasks containing a word and print to user + */ public class FindKeywordCommand extends Command{ private final TaskList taskList; + /** + * Constructor for FindKeywordCommand + * + * @param taskInput Command input by user to process + * @param taskList Tasklist to interact with list of task + */ public FindKeywordCommand(String taskInput, TaskList taskList){ super(taskInput); this.taskList = taskList; } + /** + * Filter out the word to search and pass the searching of the word to TaskList + * + * @throws CommandException if list is empty or if word to search is empty + */ @Override public void executeCommand() throws CommandException{ if(taskList.getListSize() == 0){ diff --git a/src/main/java/duke/Command/ListCommand.java b/src/main/java/duke/Command/ListCommand.java index 22b8b3dd8..ec563607e 100644 --- a/src/main/java/duke/Command/ListCommand.java +++ b/src/main/java/duke/Command/ListCommand.java @@ -4,15 +4,30 @@ import duke.ErrorHandling.ErrorStaticString; import duke.TaskList.TaskList; +/** + * Represent a command that handle showing all tasks to user + */ public class ListCommand extends Command{ private final TaskList listManager; + /** + * Constructor for ListCommand + * @param userInput Command Input by user to process + * @param listManager Tasklist to interact with list of task + */ public ListCommand(String userInput, TaskList listManager){ super(userInput); this.listManager = listManager; } + /** + * Process list input to print whole list or list of a certain type + * Remove the command by replacing command with empty string + * Remove the need for using separators + * + * @throws CommandException if list is empty + */ public void executeCommand() throws CommandException { if(listManager.getListSize() == 0){ throw new CommandException(ErrorStaticString.ERROR_EMPTY_LIST); diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 019cbaa33..2a855b98a 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -6,17 +6,31 @@ import duke.TaskList.TaskList; import duke.Ui.Ui; +/** + * Main Class of the Duke program + * Handle the integration of classes to provide the necessary functions to the user + */ public class Duke { private final TaskList tasks; private final Ui ui; + /** + * Constructor for Duke class + * Creates an instance of all the necessary class for the program to run + */ public Duke(){ ui = new Ui(); Storage storage = new Storage(); tasks = new TaskList(storage.load()); } + /** + * Main function of Duke + * Integrate the Ui class that handles taking in input of the user with + * the Parser class that handles the response to the input + * Keep running until the system is terminated by a string bye + */ public void run(){ ui.Greetings(); boolean isExit = false; @@ -38,6 +52,9 @@ public void run(){ ui.Farewell(); } + /** + * Starts the programs + */ public static void main(String[] args) { new Duke().run(); } diff --git a/src/main/java/duke/ErrorHandling/CommandException.java b/src/main/java/duke/ErrorHandling/CommandException.java index fc4c01778..f2ee2f719 100644 --- a/src/main/java/duke/ErrorHandling/CommandException.java +++ b/src/main/java/duke/ErrorHandling/CommandException.java @@ -1,17 +1,33 @@ package duke.ErrorHandling; +/** + * Represent a error resulting from input of user + */ public class CommandException extends Exception{ - private String errorMessage; + private final String errorMessage; + /** + * Constructor for CommandException + * Create error message of this instance of exception + * + * @param errorMessage Error message to print + */ public CommandException(String errorMessage){ this.errorMessage = errorMessage; } + /** + * Print Error Message + */ public void handleException(){ System.out.println(errorMessage); } + /** + * Get Error Message of error + * @return Error Message + */ public String getErrorMessage(){ return errorMessage; } diff --git a/src/main/java/duke/ErrorHandling/ErrorStaticString.java b/src/main/java/duke/ErrorHandling/ErrorStaticString.java index e44ffe979..2bb6e2ac9 100644 --- a/src/main/java/duke/ErrorHandling/ErrorStaticString.java +++ b/src/main/java/duke/ErrorHandling/ErrorStaticString.java @@ -1,5 +1,8 @@ package duke.ErrorHandling; +/** + * Contain Error Messages + */ public class ErrorStaticString { public static final String ERROR_NULL = "☹ OOPS!!! Input cannot be empty."; public static final String ERROR_UNKNOWN_COMMAND = "☹ OOPS!!! I'm sorry, but I don't know what that means :-(\n" + "" + diff --git a/src/main/java/duke/Parser/Parser.java b/src/main/java/duke/Parser/Parser.java index 1bc8e49b4..9a68fe485 100644 --- a/src/main/java/duke/Parser/Parser.java +++ b/src/main/java/duke/Parser/Parser.java @@ -4,9 +4,11 @@ import duke.ErrorHandling.CommandException; import duke.ErrorHandling.ErrorStaticString; import duke.TaskList.TaskList; - import java.util.Objects; +/** + * Main Class handling the processing of input by user + */ public class Parser{ private static final String COMMAND_VIEW_LIST = "list"; @@ -19,6 +21,7 @@ public class Parser{ private static final String COMMAND_EXIT = "bye"; private static final String COMMAND_DATE_TASK = "date"; private static final String COMMAND_FIND_WORD = "find"; + private static final String COMMAND_CLEAR_WORD = "clear"; private static final String EMPTY_STRING = ""; private static final String COMMAND_GUIDE_INDICATOR = "!"; private static final String SPLITTER = ";"; @@ -26,11 +29,23 @@ public class Parser{ private String userInput; private final TaskList listManager; + /** + * Constructor for Parser + * + * @param userInput User input to process + * @param listManager Tasklist to interact with list of task + */ public Parser(String userInput, TaskList listManager){ this.userInput = userInput; this.listManager = listManager; } + /** + * Extract Command Category by checking starting string in input + * + * @param userInput Single line of String containing one command + * @return String representing task category + */ private String taskCategory(String userInput) { if (userInput.startsWith(COMMAND_VIEW_LIST)) { return COMMAND_VIEW_LIST; @@ -59,9 +74,17 @@ private String taskCategory(String userInput) { if(userInput.startsWith(COMMAND_FIND_WORD)){ return COMMAND_FIND_WORD; } + if(userInput.startsWith(COMMAND_CLEAR_WORD)){ + return COMMAND_CLEAR_WORD; + } return null; } + /** + * Check if there is ToDo Command in input + * + * @return if ToDo Command is present + */ private boolean isTodo(){ if(userInput.contains(COMMAND_ADD_TODO)){ userInput = userInput.replaceAll(COMMAND_ADD_TODO,SPLITTER + COMMAND_ADD_TODO); @@ -69,6 +92,12 @@ private boolean isTodo(){ } return false; } + + /** + * Check if there is Event Command in input + * + * @return if Event Command is present + */ private boolean isEvent(){ if(userInput.contains(COMMAND_ADD_EVENT)){ userInput = userInput.replaceAll(COMMAND_ADD_EVENT,SPLITTER + COMMAND_ADD_EVENT); @@ -76,6 +105,12 @@ private boolean isEvent(){ } return false; } + + /** + * Check if there is DeadLine Command in input + * + * @return if DeadLine Command is present + */ private boolean isDeadline(){ if(userInput.contains(COMMAND_ADD_DEADLINE)){ userInput = userInput.replaceAll(COMMAND_ADD_DEADLINE,SPLITTER + COMMAND_ADD_DEADLINE); @@ -84,14 +119,31 @@ private boolean isDeadline(){ return false; } + /** + * Check if Command input is list + * + * @return if Command is list + */ private boolean isList(){ return userInput.startsWith(COMMAND_VIEW_LIST); } + /** + * Check if Command input is exit + * + * @return if Command is exit + */ public boolean isExit(){ return userInput.startsWith(COMMAND_EXIT); } + /** + * Does initial checking of input before handing further checking to another function + * Check if input is empty + * Check if input begin with "!" + * + * @throws CommandException if input empty + */ public void handleInput() throws CommandException{ if(userInput.isEmpty()){ throw new CommandException(ErrorStaticString.ERROR_NULL); @@ -104,6 +156,12 @@ public void handleInput() throws CommandException{ } } + /** + * Check if Command is adding task to list + * if adding task to list, split command according to adding command word + * Allows for adding of multiple tasks in one line + * Splitting input into multiple commands if command is for adding in task + */ private void splitInputIfThereMoreThanOneCommand() { userInput = userInput.replaceAll(SPLITTER,EMPTY_STRING); boolean isAddingTask = false; @@ -123,6 +181,12 @@ private void splitInputIfThereMoreThanOneCommand() { } } + /** + * Handle One Command by Creating an instance of the Command + * Hand execution of Command to the individual instance of Command + * + * @param inputCommand String representing one Command, and it's input for the command + */ private void handleCommand(String inputCommand){ String commandCategory = taskCategory(inputCommand); try { @@ -199,6 +263,11 @@ private void handleCommand(String inputCommand){ }catch (CommandException e){ e.handleException(); } + break; + case COMMAND_CLEAR_WORD: + ClearCommand clearCommand = new ClearCommand(inputCommand, listManager); + clearCommand.executeCommand(); + break; } }catch(NullPointerException e){ System.out.println(ErrorStaticString.ERROR_UNKNOWN_COMMAND); diff --git a/src/main/java/duke/Storage/FileRead.java b/src/main/java/duke/Storage/FileRead.java index 0dfaba889..716475bea 100644 --- a/src/main/java/duke/Storage/FileRead.java +++ b/src/main/java/duke/Storage/FileRead.java @@ -1,6 +1,5 @@ package duke.Storage; -import duke.ErrorHandling.CommandException; import duke.ErrorHandling.ErrorStaticString; import duke.TaskList.TaskList; import duke.task.Task; @@ -9,18 +8,35 @@ import java.util.ArrayList; import java.util.Scanner; +/** + * Handle reading from file and + * Making sense of String from file + */ public class FileRead extends Storage{ - private File file; - private TaskList listManager; - private ArrayList taskList; + private final File file; + private final TaskList listManager; + private final ArrayList taskList; + /** + * Constructor for FileRead + * Creates new arraylist to store task from text file in + * Create Tasklist interact with arraylist after processing string in text file + * + * @param file file to read from + */ public FileRead(File file){ taskList = new ArrayList<>(); listManager = new TaskList(taskList); this.file = file; } + /** + * Read from file and store each line into arraylist + * + * @param inputFile file to read from + * @return list of String from file + */ private ArrayList readFile(File inputFile){ ArrayList list = new ArrayList<>(); try { @@ -34,6 +50,11 @@ private ArrayList readFile(File inputFile){ return list; } + /** + * Process String from files into task + * + * @return list of task from file + */ public ArrayList convertFileToTask() { ArrayList stringList = readFile(file); int taskIndex = 0; @@ -50,11 +71,7 @@ public ArrayList convertFileToTask() { listManager.addDeadline(splitString[FILE_TASK_DESCRIPTION_POSITION],splitString[FILE_TASK_DETAIL_POSITION],true); } if (splitString[FILE_TASK_COMPLETE_POSITION].equals(FILE_COMPLETE_STATUS)){ - try { - listManager.completeTask(taskIndex, true); - } catch (CommandException e) { - e.handleException(); - } + listManager.completeTask(taskIndex, true); } taskIndex += 1; } diff --git a/src/main/java/duke/Storage/FileWrite.java b/src/main/java/duke/Storage/FileWrite.java index d74ea63e6..e3d0251e6 100644 --- a/src/main/java/duke/Storage/FileWrite.java +++ b/src/main/java/duke/Storage/FileWrite.java @@ -1,11 +1,20 @@ package duke.Storage; import duke.ErrorHandling.ErrorStaticString; - import java.io.IOException; +/** + * Handles writing string to file + */ public class FileWrite extends Storage{ + /** + * Append new string to file or + * Overwrite existing file with new string + * + * @param s String to write to file + * @param isAppend Boolean to indicate whether to overwrite file with new content or append to current file + */ public void writeToFile(String s, boolean isAppend){ try { java.io.FileWriter fileWriter = new java.io.FileWriter(file, isAppend); diff --git a/src/main/java/duke/Storage/Storage.java b/src/main/java/duke/Storage/Storage.java index cdda23556..ce0b3bd50 100644 --- a/src/main/java/duke/Storage/Storage.java +++ b/src/main/java/duke/Storage/Storage.java @@ -2,11 +2,17 @@ import duke.ErrorHandling.ErrorStaticString; import duke.task.Task; - import java.io.File; +import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; +/** + * Handle interaction between Duke and text file + * Create the file if file is not found + * Contain function to write to file + * Contain function to read from file + */ public class Storage { protected static final String FILE_NAME = "duke.txt"; @@ -17,14 +23,20 @@ public class Storage { protected static final String FILE_DEADLINE_STATUS = "[D]"; protected static final String FILE_EVENT_STATUS = "[E]"; protected static final String FILE_COMPLETE_STATUS = "[X]"; + protected static final String EMPTY_STRING = ""; protected static final int FILE_TASK_TYPE_POSITION = 0; protected static final int FILE_TASK_COMPLETE_POSITION = 1; protected static final int FILE_TASK_DESCRIPTION_POSITION = 2; protected static final int FILE_TASK_DETAIL_POSITION = 3; - protected File file; + /** + * Constructor for Storage + * Create duke.txt file if not found + * Print file name and location if created + * @throws IOException if file cannot be created + */ public Storage(){ try{ file = new File(FILE_NAME); @@ -36,11 +48,20 @@ public Storage(){ } } + /** + * Load task from text file into list + * @return list of task from text file + */ public ArrayList load(){ FileRead fileReader = new FileRead(file); return fileReader.convertFileToTask(); } + /** + * Write new task at end of text file + * + * @param t Task to write into text file + */ public void appendTask(Task t){ StringBuilder stringBuilder = new StringBuilder(); FileWrite fileWrite = new FileWrite(); @@ -50,6 +71,11 @@ public void appendTask(Task t){ fileWrite.writeToFile(stringToWrite, true); } + /** + * Write all tasks in list to text file + * + * @param list list of task to get task to write to text file + */ public void writeTask(ArrayList list){ StringBuilder stringBuilder = new StringBuilder(); for(Task t: list) { @@ -60,4 +86,19 @@ public void writeTask(ArrayList list){ FileWrite fileWrite = new FileWrite(); fileWrite.writeToFile(stringToWrite, false); } + + /** + * Write empty string to text file to clear its content + * + * @throws IOException if file is not found + */ + public void writeClearTask(){ + try { + FileWriter fileWriter = new FileWriter(file,false); + fileWriter.write(EMPTY_STRING); + fileWriter.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } } diff --git a/src/main/java/duke/TaskList/TaskList.java b/src/main/java/duke/TaskList/TaskList.java index 5163f06a5..e3a3c3469 100644 --- a/src/main/java/duke/TaskList/TaskList.java +++ b/src/main/java/duke/TaskList/TaskList.java @@ -7,55 +7,73 @@ import duke.task.Event; import duke.task.Task; import duke.task.ToDo; - import java.time.LocalDate; import java.util.ArrayList; +/** + * Serve as an interface for Arraylist storing the tasks + * Responsible for manipulation and interaction of the Arraylist + */ public class TaskList implements TaskListInterface { private static final String MESSAGE_TASK_ADDED = "Got it. I've added this task: "; private static final String MESSAGE_TASK_IN_LIST = " tasks in the list."; private static final String MESSAGE_LIST_TASK = "Here are the tasks in your list:"; - private static final String MESSAGE_FIND_TASK = "Here are the matching tasks in your list:"; + private static final String MESSAGE_LIST_TODO = "Here are the ToDo tasks in your list:"; + private static final String MESSAGE_LIST_EVENT = "Here are the Event tasks in your list:"; + private static final String MESSAGE_LIST_DEADLINE = "Here are the Deadline tasks in your list:"; + private static final String MESSAGE_LIST_FIND = "Here are the matching tasks in your list:"; + private static final String MESSAGE_LIST_FIND_DATE = "Here are the tasks with matching dates in your list:"; private static final String MESSAGE_TASK_NOW = "Now you have "; private static final String MESSAGE_DELETE = "Noted. I've removed this task: "; private static final String MESSAGE_SPACER = ". "; + private static final String EMPTY_STRING = ""; private final ArrayList list; - public TaskList(){ - list = new ArrayList<>(); - } + /** + * Constructor for the class to assign the arraylist to be manipulated + * + * @param list Arraylist that store the tasks + */ public TaskList(ArrayList list){ this.list = list; } + /** + * Loops through a list of task and print each task + * + * @param listToPrint Arraylist containing tasks to print + */ private void printer(ArrayList listToPrint){ - System.out.println(MESSAGE_LIST_TASK); - for(int i = 0; i < listToPrint.size(); i++){ - int itemIndex= i + 1; - System.out.println(itemIndex + MESSAGE_SPACER + listToPrint.get(i).toString()); - } - } - - private void printerForFind(ArrayList listToPrint){ - System.out.println(MESSAGE_FIND_TASK); for(int i = 0; i < listToPrint.size(); i++){ int itemIndex= i + 1; System.out.println(itemIndex + MESSAGE_SPACER + listToPrint.get(i).toString()); } } + /** + * Print all the task in the list + */ public void printList(){ + System.out.println(MESSAGE_LIST_TASK); printer(list); } + /** + * Print all the task with a specific date + * Sort out the task with the same date into a new list + * Print the new list + * + * @param dateSearched Date being search as LocalDate object + * @throws CommandException if no task with the date searched was found + */ public void printDate(LocalDate dateSearched) throws CommandException{ boolean haveDate = false; ArrayList listOfTaskWithDate = new ArrayList<>(); for (Task t: list){ String date = t.getDate(t.convertStringToDate(), true); - if(!date.equals("")) { + if(!date.equals(EMPTY_STRING)) { LocalDate localDate = LocalDate.parse(date); if (dateSearched.equals(localDate)) { haveDate = true; @@ -66,9 +84,18 @@ public void printDate(LocalDate dateSearched) throws CommandException{ if(!haveDate){ throw new CommandException(ErrorStaticString.ERROR_EMPTY_DATE_INPUT); } - printerForFind(listOfTaskWithDate); + System.out.println(MESSAGE_LIST_FIND_DATE); + printer(listOfTaskWithDate); } + /** + * Print all tasks containing a specific string + * Sort out all tasks containing the string to a new list + * Print the new list + * + * @param wordSearch String to be searched + * @throws CommandException if no tasks with the word to be searched was found + */ public void printWord(String wordSearch) throws CommandException{ boolean haveWord = false; ArrayList listOfTaskWithWord = new ArrayList<>(); @@ -81,9 +108,17 @@ public void printWord(String wordSearch) throws CommandException{ if(!haveWord){ throw new CommandException(ErrorStaticString.ERROR_EMPTY_LIST); } - printerForFind(listOfTaskWithWord); + System.out.println(MESSAGE_LIST_FIND); + printer(listOfTaskWithWord); } + /** + * Print all the Todo task in the list + * Sort out all the Todo task into a new list + * Print the new list + * + * @throws CommandException if no Todo task is found in list + */ public void printToDo() throws CommandException { boolean haveToDo = false; ArrayList listOfToDo = new ArrayList<>(); @@ -96,9 +131,17 @@ public void printToDo() throws CommandException { if(!haveToDo){ throw new CommandException(ErrorStaticString.ERROR_EMPTY_TODO_LIST); } + System.out.println(MESSAGE_LIST_TODO); printer(listOfToDo); } + /** + * Print all the Event Task in list + * Sort out the Event Task into a new list + * Print the new list + * + * @throws CommandException if Event task is not found in list + */ public void printEvent() throws CommandException{ boolean haveEvent = false; ArrayList listOfEvent = new ArrayList<>(); @@ -111,9 +154,17 @@ public void printEvent() throws CommandException{ if(!haveEvent){ throw new CommandException(ErrorStaticString.ERROR_EMPTY_EVENT_LIST); } + System.out.println(MESSAGE_LIST_EVENT); printer(listOfEvent); } + /** + * Print all Deadline task list + * Sort out Deadline task into new list + * Print new list + * + * @throws CommandException if Deadline task is not found in list + */ public void printDeadline() throws CommandException{ boolean haveDeadline = false; ArrayList listOfDeadline = new ArrayList<>(); @@ -126,14 +177,28 @@ public void printDeadline() throws CommandException{ if(!haveDeadline){ throw new CommandException(ErrorStaticString.ERROR_EMPTY_DEADLINE_LIST); } + System.out.println(MESSAGE_LIST_DEADLINE); printer(listOfDeadline); } + /** + * Print message when a task is added + * + * @param t Task added to the list + */ private void printAddItem(Task t){ System.out.println(MESSAGE_TASK_ADDED + System.lineSeparator() + t.toString() + System.lineSeparator() + MESSAGE_TASK_NOW + list.size() + MESSAGE_TASK_IN_LIST); } + /** + * Adds ToDo task to list + * Print task added + * Write task to text file + * + * @param description Description of the task + * @param isFromFile Boolean variable representing if task added is from text file + */ public void addTodo(String description, boolean isFromFile){ Task t = new ToDo(description); list.add(t); @@ -144,6 +209,15 @@ public void addTodo(String description, boolean isFromFile){ } } + /** + * Add Event Task to list + * Print task added + * Write task to text file + * + * @param description Description of event + * @param eventDateTime Date and Time of event in String + * @param isFromFile Boolean variable representing if task added is from text file + */ public void addEvent (String description, String eventDateTime, boolean isFromFile){ Task t = new Event(description, eventDateTime); list.add(t); @@ -154,6 +228,15 @@ public void addEvent (String description, String eventDateTime, boolean isFromFi } } + /** + * Add Deadline Task to list + * Print task added + * Write task to text file + * + * @param description Description of deadline + * @param deadlineDateTime Date and Time of deadline in String + * @param isFromFile Boolean variable representing if task added is from text file + */ public void addDeadline(String description, String deadlineDateTime, boolean isFromFile){ Task t = new Deadline(description, deadlineDateTime); list.add(t); @@ -164,7 +247,15 @@ public void addDeadline(String description, String deadlineDateTime, boolean isF } } - public void completeTask(int t, boolean isFromFile) throws CommandException{ + /** + * Set task as done + * Print out task set as done + * Write whole list to text file to update task as done + * + * @param t Index of Task to set as done + * @param isFromFile Boolean variable representing if task added is from text file + */ + public void completeTask(int t, boolean isFromFile){ Task doneTask = list.get(t); doneTask.setDone(); if (!isFromFile) { @@ -174,6 +265,13 @@ public void completeTask(int t, boolean isFromFile) throws CommandException{ } } + /** + * Remove task from list + * Print task deleted + * Write whole list text file to remove task in text file + * + * @param t Index of Task to delete + */ public void deleteTask(int t){ Task removeTask = list.get(t); list.remove(t); @@ -182,11 +280,31 @@ public void deleteTask(int t){ storage.writeTask(list); } + /** + * Print task deleted message + * @param t Task to delete + */ private void printDeleteTask(Task t){ System.out.println(MESSAGE_DELETE + System.lineSeparator() + t.toString() + System.lineSeparator() + MESSAGE_TASK_NOW + list.size() + MESSAGE_TASK_IN_LIST); } + /** + * Remove all task in list + * Print list is empty + * Write empty string to text file to clear text file + */ + public void clearTask(){ + list.clear(); + Storage storage = new Storage(); + storage.writeClearTask(); + } + + /** + * To get the number of tasks stored in the arraylist + * + * @return size of the arraylist + */ public int getListSize(){ return list.size(); } diff --git a/src/main/java/duke/TaskList/TaskListInterface.java b/src/main/java/duke/TaskList/TaskListInterface.java index d221aa9e0..2ba478dbf 100644 --- a/src/main/java/duke/TaskList/TaskListInterface.java +++ b/src/main/java/duke/TaskList/TaskListInterface.java @@ -1,15 +1,20 @@ package duke.TaskList; import duke.ErrorHandling.CommandException; +import java.time.LocalDate; public interface TaskListInterface { void printList() throws CommandException; + void printDate(LocalDate dateSearched) throws CommandException; + void printWord(String wordSearch) throws CommandException; void printToDo() throws CommandException; void printEvent() throws CommandException; void printDeadline() throws CommandException; void addTodo(String description, boolean isFromFile); void addEvent(String description, String eventDateTime, boolean isFromFile); void addDeadline(String description, String deadlineDateTime, boolean isFromFile); - void completeTask(int t, boolean isFromFile) throws CommandException; + void completeTask(int t, boolean isFromFile); + void deleteTask(int t); + void clearTask(); int getListSize(); } diff --git a/src/main/java/duke/Ui/Ui.java b/src/main/java/duke/Ui/Ui.java index be9b41e19..8ed7f08d3 100644 --- a/src/main/java/duke/Ui/Ui.java +++ b/src/main/java/duke/Ui/Ui.java @@ -1,33 +1,63 @@ package duke.Ui; - import duke.ArtBot.Logo; - import java.util.Scanner; +/** + * Handles the Interaction between the user and the program + * Contains the function that greets the user when program is started + * Contains the function that bid farewell to the user when the program ends + * Contains the function that tell the user what went wrong when an error is encountered + * Contains the function that print a line for readability + */ public class Ui { private static final String MESSAGE_HI = "Hello! I'm Duke\n" + "What can I do for you?\n" + "!help for Command List\n"; private static final String MESSAGE_BYE = "Bye. Hope to see you again soon!\n"; + /** + * Called right at the start of the program + * Greet the user with a message + * Handles the message that is printed to the user + */ public void Greetings(){ - System.out.println(Logo.logo +Logo.divider + MESSAGE_HI + Logo.dividerWithoutNewLine); + System.out.println(Logo.logo + Logo.divider + MESSAGE_HI + Logo.dividerWithoutNewLine); } + /** + * Called when the program exit + * Print a farewell message to the user + * Handles the message to be printed to the user + */ public void Farewell(){ System.out.println(MESSAGE_BYE + Logo.bye); } + /** + * Called before the input is process and after + * Draw a line before and after the response to an input + * Improve readability when using the program + */ public void showLine(){ System.out.println(Logo.dividerWithoutNewLine); } - + /** + * A function to read in input from user + * + * @return input from user in String + */ public String readCommand(){ Scanner in = new Scanner(System.in); return in.nextLine().toLowerCase().trim(); } + /** + * Called when an error is encountered + * Print error message to the user + * + * @param error Error Message in String to print to user + */ public void showError(String error){ System.out.println(error); } diff --git a/src/main/java/duke/task/Deadline.java b/src/main/java/duke/task/Deadline.java index cfe7b3045..d70558799 100644 --- a/src/main/java/duke/task/Deadline.java +++ b/src/main/java/duke/task/Deadline.java @@ -1,7 +1,6 @@ package duke.task; import duke.ErrorHandling.ErrorStaticString; - import java.time.LocalDate; import java.time.LocalTime; import java.time.format.DateTimeFormatter; @@ -9,16 +8,31 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +/** + * Represent a DeadLine Task + */ public class Deadline extends Task{ private static final String TASK_SYMBOL = "[D]"; private final String deadlineDateTime; + /** + * Constructor for DeadLine Task + * Set description of DeadLine + * Set Date and Time of DeadLine + */ public Deadline(String description, String deadlineDateTime){ super(description); this.deadlineDateTime = deadlineDateTime; } + /** + * Find first instance of a date by finding a string in a pattern + * Pattern:4int-2int-2int + * + * @param stringToSearch String that contain date + * @return Null if no date is found or return a matcher object that found date + */ private Matcher findDate(String stringToSearch){ Pattern pattern = Pattern.compile(DATE_PATTERN); Matcher matcher = pattern.matcher(stringToSearch); @@ -28,6 +42,13 @@ private Matcher findDate(String stringToSearch){ return null; } + /** + * Find first instance of time by finding a fixed pattern of string + * Pattern:2int:2int + * + * @param stringToSearch String that contain time + * @return null if no time found or return matcher object that found time + */ private Matcher findTime(String stringToSearch){ Pattern pattern = Pattern.compile(TIME_PATTERN); Matcher matcher = pattern.matcher(stringToSearch); @@ -37,6 +58,11 @@ private Matcher findTime(String stringToSearch){ return null; } + /** + * Extract string containing date + * + * @return string containing date or Empty String if no date found + */ @Override public String convertStringToDate(){ Matcher dateMatcher = findDate(deadlineDateTime); @@ -48,6 +74,11 @@ public String convertStringToDate(){ return EMPTY_STRING; } + /** + * Extract string containing Time + * + * @return string containing time or Empty String if no time found + */ private String convertStringToTime(){ Matcher timeMatcher = findTime(deadlineDateTime); if(timeMatcher != null){ @@ -58,6 +89,13 @@ private String convertStringToTime(){ return EMPTY_STRING; } + /** + * Process date in string form and reformat it + * + * @param date String containing date of task + * @param isForFile Boolean variable to decide format of date return + * @return String of reformatted date depending on whether it being printed or save into text file + */ @Override public String getDate(String date, boolean isForFile) { if(!date.isEmpty()) { @@ -74,6 +112,13 @@ public String getDate(String date, boolean isForFile) { return EMPTY_STRING; } + /** + * Process Time in string form and reformat it + * + * @param time String containing time of task + * @param isForFile Boolean variable to decide format of date return + * @return String of reformatted time depending on whether it being printed or save into text file + */ private String getTime(String time, boolean isForFile) { if(!time.isEmpty()) { try { @@ -92,11 +137,21 @@ private String getTime(String time, boolean isForFile) { return EMPTY_STRING; } + /** + * Format string to print to user + * + * @return Formatted String containing date and time if present + */ @Override public String toString(){ return TASK_SYMBOL + super.toString() + "(by: " + getTime(convertStringToTime(),false) + " " + getDate(convertStringToDate(),false) + ")"; } + /** + * Format string to write to text file + * + * @return Formatted String containing date and time if present + */ @Override public String toFile(){ return TASK_SYMBOL + SEPARATOR + super.toFile() + SEPARATOR + getTime(convertStringToTime(),true) + " " + getDate(convertStringToDate(),true); diff --git a/src/main/java/duke/task/Event.java b/src/main/java/duke/task/Event.java index 40778a844..edc2f5f69 100644 --- a/src/main/java/duke/task/Event.java +++ b/src/main/java/duke/task/Event.java @@ -1,7 +1,6 @@ package duke.task; import duke.ErrorHandling.ErrorStaticString; - import java.time.LocalDate; import java.time.LocalTime; import java.time.format.DateTimeFormatter; @@ -9,16 +8,31 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +/** + * Represent a Event Task + */ public class Event extends Task{ private static final String TASK_SYMBOL = "[E]"; private final String eventDateTime; + /** + * Constructor for Event Task + * Set description of event + * Set Date and Time of Event + */ public Event(String description, String eventDateTime){ super(description); this.eventDateTime = eventDateTime; } + /** + * Find first instance of a date by finding a string in a pattern + * Pattern:4int-2int-2int + * + * @param stringToSearch String that contain date + * @return Null if no date is found or return a matcher object that found date + */ private Matcher findDate(String stringToSearch){ Pattern pattern = Pattern.compile(DATE_PATTERN); Matcher matcher = pattern.matcher(stringToSearch); @@ -28,6 +42,13 @@ private Matcher findDate(String stringToSearch){ return null; } + /** + * Find first instance of time by finding a fixed pattern of string + * Pattern:2int:2int + * + * @param stringToSearch String that contain time + * @return null if no time found or return matcher object that found time + */ private Matcher findTime(String stringToSearch){ Pattern pattern = Pattern.compile(TIME_PATTERN); Matcher matcher = pattern.matcher(stringToSearch); @@ -37,6 +58,12 @@ private Matcher findTime(String stringToSearch){ return null; } + /** + * Extract string containing date + * + * @return string containing date or Empty String if no date found + */ + @Override public String convertStringToDate(){ Matcher dateMatcher = findDate(eventDateTime); if(dateMatcher != null){ @@ -47,6 +74,11 @@ public String convertStringToDate(){ return EMPTY_STRING; } + /** + * Extract string containing Time + * + * @return string containing time or Empty String if no time found + */ private String convertStringToTime(){ Matcher timeMatcher = findTime(eventDateTime); if(timeMatcher != null){ @@ -57,6 +89,13 @@ private String convertStringToTime(){ return EMPTY_STRING; } + /** + * Process date in string form and reformat it + * + * @param date String containing date of task + * @param isForFile Boolean variable to decide format of date return + * @return String of reformatted date depending on whether it being printed or save into text file + */ @Override public String getDate(String date, boolean isForFile) { if(!date.isEmpty()) { @@ -73,6 +112,13 @@ public String getDate(String date, boolean isForFile) { return EMPTY_STRING; } + /** + * Process Time in string form and reformat it + * + * @param time String containing time of task + * @param isForFile Boolean variable to decide format of date return + * @return String of reformatted time depending on whether it being printed or save into text file + */ private String getTime(String time, boolean isForFile) { if(!time.isEmpty()) { try { @@ -91,11 +137,21 @@ private String getTime(String time, boolean isForFile) { return EMPTY_STRING; } + /** + * Format string to print to user + * + * @return Formatted String containing date and time if present + */ @Override public String toString(){ return TASK_SYMBOL + super.toString() + "(at: " + getTime(convertStringToTime(),false) + " " + getDate(convertStringToDate(), false) + ")"; } + /** + * Format string to write to text file + * + * @return Formatted String containing date and time if present + */ @Override public String toFile(){ return TASK_SYMBOL + SEPARATOR + super.toFile() + SEPARATOR + getTime(convertStringToTime(),true) + " " + getDate(convertStringToDate(),true); diff --git a/src/main/java/duke/task/Task.java b/src/main/java/duke/task/Task.java index 4e1401a1a..bf9cca16d 100644 --- a/src/main/java/duke/task/Task.java +++ b/src/main/java/duke/task/Task.java @@ -1,41 +1,87 @@ package duke.task; +/** + * Represent a task to be done with a description of task + */ public class Task implements TaskInterface { + private static final String COMPLETE_STATUS_ICON = "[X]"; private static final String INCOMPLETE_STATUS_ICON = "[ ]"; protected static final String DATE_PATTERN = "\\d{4}-\\d{1,2}-\\d{1,2}"; protected static final String TIME_PATTERN = "\\d{2}:\\d{2}"; protected static final String EMPTY_STRING = ""; + protected static final String SEPARATOR = ";"; private final String description; private boolean isDone; - protected static final String SEPARATOR = ";"; + /** + * Constructor for Task + * Set description of task + * Set tasks to be incomplete by default + * + * @param description description of task + */ public Task(String description){ this.description = description; this.isDone = false; } + /** + * Set task as complete + */ public void setDone(){ isDone = true; } + /** + * Get date of task, Empty String by default + * + * @param date String containing date of task + * @param isForFile Boolean variable to decide format of date return + * @return Empty String by default representing no date in task + */ public String getDate(String date, boolean isForFile){return EMPTY_STRING;} + /** + * Convert String into LocalDate + * + * @return Empty String by default representing no date in task + */ public String convertStringToDate(){return EMPTY_STRING;} + /** + * Get description of task + * + * @return String description of task + */ public String getDescription(){ return description; } + /** + * Convert completion status of task into string form + * + * @return String representing if task is done + */ public String getStatusIcon(){ return(isDone ? COMPLETE_STATUS_ICON : INCOMPLETE_STATUS_ICON); } + /** + * Set Task to print completion status and its description when printed + * + * @return String format of when task is printed + */ public String toString(){ return getStatusIcon() + description; } + /** + * Set format of task to be saved into text file + * + * @return String format of when task is saved into text file + */ public String toFile(){ return getStatusIcon() + SEPARATOR + description; } diff --git a/src/main/java/duke/task/TaskInterface.java b/src/main/java/duke/task/TaskInterface.java index 2ab7cfc4c..0875f7d8f 100644 --- a/src/main/java/duke/task/TaskInterface.java +++ b/src/main/java/duke/task/TaskInterface.java @@ -2,6 +2,10 @@ public interface TaskInterface { void setDone(); + String getDate(String date, boolean isForFile); + String convertStringToDate(); String getDescription(); String getStatusIcon(); + String toString(); + String toFile(); } diff --git a/src/main/java/duke/task/ToDo.java b/src/main/java/duke/task/ToDo.java index d9904e98c..0f48fb4a8 100644 --- a/src/main/java/duke/task/ToDo.java +++ b/src/main/java/duke/task/ToDo.java @@ -1,18 +1,36 @@ package duke.task; +/** + * Represent one of the task object + */ public class ToDo extends Task{ private static final String TASK_SYMBOL = "[T]"; + /** + * Constructor for ToDo task + * + * @param description Description of task + */ public ToDo(String description){ super(description); } + /** + * Format string to print task to user + * + * @return Formatted String + */ @Override public String toString() { return TASK_SYMBOL + super.toString(); } + /** + * Format string to save in text file + * + * @return Formatted String + */ @Override public String toFile(){ return TASK_SYMBOL + SEPARATOR + super.toFile(); From 9a88e1b9b936bff54c9ed02dbd7763db87c9cd6b Mon Sep 17 00:00:00 2001 From: wingho2 Date: Tue, 28 Sep 2021 15:25:27 +0800 Subject: [PATCH 25/62] Level-8 --- src/main/java/duke/Duke.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 2a855b98a..3f7ba679d 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -5,7 +5,7 @@ import duke.Storage.Storage; import duke.TaskList.TaskList; import duke.Ui.Ui; - +//Level 8 /** * Main Class of the Duke program * Handle the integration of classes to provide the necessary functions to the user From 668659beb25f93f3be1f67d4b3ea7b0d964ae7b9 Mon Sep 17 00:00:00 2001 From: wingho2 Date: Tue, 28 Sep 2021 15:27:17 +0800 Subject: [PATCH 26/62] Level-9 --- src/main/java/duke/Duke.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 2a855b98a..51e347331 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -5,7 +5,7 @@ import duke.Storage.Storage; import duke.TaskList.TaskList; import duke.Ui.Ui; - +//Level-9 /** * Main Class of the Duke program * Handle the integration of classes to provide the necessary functions to the user From 8c59d4dcb9a92a60d245c7244ee97fcd3ca294b3 Mon Sep 17 00:00:00 2001 From: wingho2 Date: Tue, 28 Sep 2021 15:28:18 +0800 Subject: [PATCH 27/62] JavaDoc --- src/main/java/duke/Duke.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 2a855b98a..aa729e17c 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -5,7 +5,7 @@ import duke.Storage.Storage; import duke.TaskList.TaskList; import duke.Ui.Ui; - +//JavaDoc /** * Main Class of the Duke program * Handle the integration of classes to provide the necessary functions to the user From 9060af4295f2f2ed00e6111b24ff8a2970840626 Mon Sep 17 00:00:00 2001 From: wingho2 Date: Tue, 28 Sep 2021 15:41:04 +0800 Subject: [PATCH 28/62] no message --- text-ui-test/EXPECTED.TXT | 7 + text-ui-test/EXPECTED.txt | 194 +--------------------- text-ui-test/EXPECTED.txt~merged | 273 +++++++++++++++++++++++++++++++ 3 files changed, 283 insertions(+), 191 deletions(-) create mode 100644 text-ui-test/EXPECTED.TXT create mode 100644 text-ui-test/EXPECTED.txt~merged diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT new file mode 100644 index 000000000..657e74f6e --- /dev/null +++ b/text-ui-test/EXPECTED.TXT @@ -0,0 +1,7 @@ +Hello from + ____ _ +| _ \ _ _| | _____ +| | | | | | | |/ / _ \ +| |_| | |_| | < __/ +|____/ \__,_|_|\_\___| + diff --git a/text-ui-test/EXPECTED.txt b/text-ui-test/EXPECTED.txt index d04327598..657e74f6e 100644 --- a/text-ui-test/EXPECTED.txt +++ b/text-ui-test/EXPECTED.txt @@ -1,195 +1,7 @@ - ____ _ -| _ \ _ _| | _____ +Hello from + ____ _ +| _ \ _ _| | _____ | | | | | | | |/ / _ \ | |_| | |_| | < __/ |____/ \__,_|_|\_\___| -____________________________________________________________ -Hello! I'm Duke -What can I do for you? -!help for Command List -____________________________________________________________ -____________________________________________________________ -hi -____________________________________________________________ -____________________________________________________________ -HI - ___ ___ .___ - / | \ | | -/ ~ \| | -\ Y /| | - \___|___/ |___| -____________________________________________________________ -____________________________________________________________ - ☹ OOPS!!! List is empty. Add tasks to the list. -____________________________________________________________ -____________________________________________________________ -Got it. I've added this task: -[T][ ]watch et1231 livestream -Now you have 1 tasks in the list. -Got it. I've added this task: -[E][ ]watch hankyuu livestream(at: midnight ) -Now you have 2 tasks in the list. -____________________________________________________________ -____________________________________________________________ -Got it. I've added this task: -[T][ ]watch haxxnini livestream -Now you have 3 tasks in the list. -____________________________________________________________ -____________________________________________________________ -☹ OOPS!!! The due date of a deadline not detected, use [by] to indicated the date. -____________________________________________________________ -____________________________________________________________ -Got it. I've added this task: -[D][ ]reach legend(by: this season ) -Now you have 4 tasks in the list. -____________________________________________________________ -____________________________________________________________ -Got it. I've added this task: -[D][ ]reach gold(by: 08:00 PM ) -Now you have 5 tasks in the list. -____________________________________________________________ -____________________________________________________________ -Got it. I've added this task: -[D][ ]reach silver(by: Oct 10 2020) -Now you have 6 tasks in the list. -____________________________________________________________ -____________________________________________________________ -Got it. I've added this task: -[D][ ]reach bronze(by: 08:00 PM Oct 10 2020) -Now you have 7 tasks in the list. -____________________________________________________________ -____________________________________________________________ -Here are the tasks in your list: -1. [D][ ]reach silver(by: Oct 10 2020) -2. [D][ ]reach bronze(by: 08:00 AM Oct 10 2020) -____________________________________________________________ -____________________________________________________________ -☹ OOPS!!! The timing of the event not detected, use [at] to indicated the time. -____________________________________________________________ -____________________________________________________________ -Here are the tasks in your list: -1. [E][ ]g2 vs sentinel(at: 12am) -____________________________________________________________ -____________________________________________________________ -Got it. I've added this task: -[E][ ]g2 vs sentinel(at: 10pm ) -Now you have 8 tasks in the list. -____________________________________________________________ -____________________________________________________________ -Got it. I've added this task: -[E][ ]g2 vs sentinel(at: 10:00 PM ) -Now you have 9 tasks in the list. -____________________________________________________________ -____________________________________________________________ -Got it. I've added this task: -[E][ ]g2 vs sentinel(at: 10:00 PM Oct 10 2020) -Now you have 10 tasks in the list. -____________________________________________________________ -____________________________________________________________ -Here are the tasks in your list: -1. [T][ ]watch et1231 livestream -2. [E][ ]watch hankyuu livestream(at: midnight ) -3. [T][ ]watch haxxnini livestream -4. [D][ ]reach legend(by: this season ) -5. [D][ ]reach gold(by: 08:00 AM ) -6. [D][ ]reach silver(by: Oct 10 2020) -7. [D][ ]reach bronze(by: 08:00 AM Oct 10 2020) -8. [E][ ]g2 vs sentinel(at: 10pm ) -9. [E][ ]g2 vs sentinel(at: 10:00 PM ) -10. [E][ ]g2 vs sentinel(at: 10:00 PM Oct 10 2020) -____________________________________________________________ -____________________________________________________________ -Here are the tasks in your list: -1. [T][ ]watch et1231 livestream -2. [T][ ]watch haxxnini livestream -____________________________________________________________ -____________________________________________________________ -Here are the tasks in your list: -1. [D][ ]reach legend(by: this season ) -2. [D][ ]reach gold(by: 08:00 AM ) -3. [D][ ]reach silver(by: Oct 10 2020) -4. [D][ ]reach bronze(by: 08:00 AM Oct 10 2020) -____________________________________________________________ -____________________________________________________________ -Here are the tasks in your list: -1. [E][ ]watch hankyuu livestream(at: midnight ) -2. [E][ ]g2 vs sentinel(at: 10pm ) -3. [E][ ]g2 vs sentinel(at: 10:00 PM ) -4. [E][ ]g2 vs sentinel(at: 10:00 PM Oct 10 2020) -____________________________________________________________ -____________________________________________________________ -____________________________________________________________ -Nice! I've marked this task as done: -[T][X]watch et1231 livestream -[E][X]watch hankyuu livestream(at: midnight ) -[T][X]watch haxxnini livestream -Here are the tasks in your list: -1. [T][X]watch et1231 livestream -2. [E][X]watch hankyuu livestream(at: midnight ) -3. [T][X]watch haxxnini livestream -4. [D][ ]reach legend(by: this season ) -5. [D][ ]reach gold(by: 08:00 AM ) -6. [D][ ]reach silver(by: Oct 10 2020) -7. [D][ ]reach bronze(by: 08:00 AM Oct 10 2020) -8. [E][ ]g2 vs sentinel(at: 10pm ) -9. [E][ ]g2 vs sentinel(at: 10:00 PM ) -10. [E][ ]g2 vs sentinel(at: 10:00 PM Oct 10 2020) -____________________________________________________________ -____________________________________________________________ -Noted. I've removed this task: -[E][X]watch hankyuu livestream(at: midnight ) -Now you have 9 tasks in the list. -Noted. I've removed this task: -[T][X]watch et1231 livestream -Now you have 8 tasks in the list. -____________________________________________________________ -____________________________________________________________ -Here are the tasks in your list: -1. [T][X]watch haxxnini livestream -2. [D][ ]reach legend(by: this season ) -3. [D][ ]reach gold(by: 08:00 AM ) -4. [D][ ]reach silver(by: Oct 10 2020) -5. [D][ ]reach bronze(by: 08:00 AM Oct 10 2020) -6. [E][ ]g2 vs sentinel(at: 10pm ) -7. [E][ ]g2 vs sentinel(at: 10:00 AM ) -8. [E][ ]g2 vs sentinel(at: 10:00 AM Oct 10 2020) -____________________________________________________________ -____________________________________________________________ -☹ OOPS!!! I'm sorry, but I don't know what that means :-( -Defaulting to Echo. Type !help to see the list of Commands -random command -____________________________________________________________ -____________________________________________________________ -List of Commands: - echo - Repeat whatever was typed - !echo to repeat in art form - list - Display List - !list for details - todo - Add ToDo Task - event - Add Event Task - !event for details - deadline - Add Deadline Task - !deadline for details - bye - Shut Down - -____________________________________________________________ -____________________________________________________________ -list displays all tasks -list todo displays all todo tasks -list event displays all event tasks -list deadline displays all deadline tasks - -____________________________________________________________ -____________________________________________________________ -event command requires a timing indicated using "at" [timing] - -____________________________________________________________ -____________________________________________________________ -deadline command requires a end time indicated using "by"[end time] - -____________________________________________________________ -____________________________________________________________ -____________________________________________________________ -Bye. Hope to see you again soon! -_______________.___.___________ -\______ \__ | |\_ _____/ - | | _// | | | __)_ - | | \\____ | | \ - |________// ______|/_________/ \ No newline at end of file diff --git a/text-ui-test/EXPECTED.txt~merged b/text-ui-test/EXPECTED.txt~merged new file mode 100644 index 000000000..b7ba62331 --- /dev/null +++ b/text-ui-test/EXPECTED.txt~merged @@ -0,0 +1,273 @@ + ____ _ +| _ \ _ _| | _____ +| | | | | | | |/ / _ \ +| |_| | |_| | < __/ +|____/ \__,_|_|\_\___| +____________________________________________________________ +Hello! I'm Duke +What can I do for you? +!help for Command List +____________________________________________________________ +____________________________________________________________ +hi +____________________________________________________________ +<<<<<<< HEAD +____________________________________________________________ +======= +>>>>>>> parent of 6845eab (no message) +HI + ___ ___ .___ + / | \ | | +/ ~ \| | +\ Y /| | + \___|___/ |___| +<<<<<<< HEAD +____________________________________________________________ +____________________________________________________________ + ☹ OOPS!!! List is empty. Add tasks to the list. +____________________________________________________________ +____________________________________________________________ +Got it. I've added this task: +[T][ ]watch et1231 livestream +Now you have 1 tasks in the list. +Got it. I've added this task: +[E][ ]watch hankyuu livestream(at: midnight ) +Now you have 2 tasks in the list. +____________________________________________________________ +======= + ____________________________________________________________ + Got it. I've added this task: + [T][ ]watch et1231 livestream + Now you have 1 tasks in the list. + ____________________________________________________________ + ____________________________________________________________ + Got it. I've added this task: + [T][ ]watch hankyuu livestream + Now you have 2 tasks in the list. + ____________________________________________________________ +>>>>>>> parent of 6845eab (no message) +____________________________________________________________ +Got it. I've added this task: +[T][ ]watch haxxnini livestream +Now you have 3 tasks in the list. +____________________________________________________________ +____________________________________________________________ +<<<<<<< HEAD +☹ OOPS!!! The due date of a deadline not detected, use [by] to indicated the date. +____________________________________________________________ +____________________________________________________________ +Got it. I've added this task: +[D][ ]reach legend(by: this season ) +======= +Got it. I've added this task: +[D][ ]reach radiant(by: this season) +>>>>>>> parent of 6845eab (no message) +Now you have 4 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Got it. I've added this task: +<<<<<<< HEAD +[D][ ]reach gold(by: 08:00 PM ) +Now you have 5 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Got it. I've added this task: +[D][ ]reach silver(by: Oct 10 2020) +Now you have 6 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Got it. I've added this task: +[D][ ]reach bronze(by: 08:00 PM Oct 10 2020) +Now you have 7 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Here are the tasks in your list: +1. [D][ ]reach silver(by: Oct 10 2020) +2. [D][ ]reach bronze(by: 08:00 AM Oct 10 2020) +____________________________________________________________ +____________________________________________________________ +☹ OOPS!!! The timing of the event not detected, use [at] to indicated the time. +____________________________________________________________ +____________________________________________________________ +Here are the tasks in your list: +1. [E][ ]g2 vs sentinel(at: 12am) +____________________________________________________________ +____________________________________________________________ +Got it. I've added this task: +[E][ ]g2 vs sentinel(at: 10pm ) +Now you have 8 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Got it. I've added this task: +[E][ ]g2 vs sentinel(at: 10:00 PM ) +Now you have 9 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Got it. I've added this task: +[E][ ]g2 vs sentinel(at: 10:00 PM Oct 10 2020) +Now you have 10 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Here are the tasks in your list: +1. [T][ ]watch et1231 livestream +2. [E][ ]watch hankyuu livestream(at: midnight ) +3. [T][ ]watch haxxnini livestream +4. [D][ ]reach legend(by: this season ) +5. [D][ ]reach gold(by: 08:00 AM ) +6. [D][ ]reach silver(by: Oct 10 2020) +7. [D][ ]reach bronze(by: 08:00 AM Oct 10 2020) +8. [E][ ]g2 vs sentinel(at: 10pm ) +9. [E][ ]g2 vs sentinel(at: 10:00 PM ) +10. [E][ ]g2 vs sentinel(at: 10:00 PM Oct 10 2020) +____________________________________________________________ +____________________________________________________________ +Here are the tasks in your list: +1. [T][ ]watch et1231 livestream +2. [T][ ]watch haxxnini livestream +____________________________________________________________ +____________________________________________________________ +Here are the tasks in your list: +1. [D][ ]reach legend(by: this season ) +2. [D][ ]reach gold(by: 08:00 AM ) +3. [D][ ]reach silver(by: Oct 10 2020) +4. [D][ ]reach bronze(by: 08:00 AM Oct 10 2020) +____________________________________________________________ +____________________________________________________________ +Here are the tasks in your list: +1. [E][ ]watch hankyuu livestream(at: midnight ) +2. [E][ ]g2 vs sentinel(at: 10pm ) +3. [E][ ]g2 vs sentinel(at: 10:00 PM ) +4. [E][ ]g2 vs sentinel(at: 10:00 PM Oct 10 2020) +____________________________________________________________ +======= +[E][ ]g2 vs sentinel(at:12am) +Now you have 5 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Here are the tasks in your list: +1. [T][ ]watch et1231 livestream +2. [T][ ]watch hankyuu livestream +3. [T][ ]watch haxxnini livestream +4. [D][ ]reach radiant(by: this season) +5. [E][ ]g2 vs sentinel(at:12am) +>>>>>>> parent of 6845eab (no message) +____________________________________________________________ +____________________________________________________________ +Nice! I've marked this task as done: +[T][X]watch et1231 livestream +<<<<<<< HEAD +[E][X]watch hankyuu livestream(at: midnight ) +[T][X]watch haxxnini livestream +Here are the tasks in your list: +1. [T][X]watch et1231 livestream +2. [E][X]watch hankyuu livestream(at: midnight ) +3. [T][X]watch haxxnini livestream +4. [D][ ]reach legend(by: this season ) +5. [D][ ]reach gold(by: 08:00 AM ) +6. [D][ ]reach silver(by: Oct 10 2020) +7. [D][ ]reach bronze(by: 08:00 AM Oct 10 2020) +8. [E][ ]g2 vs sentinel(at: 10pm ) +9. [E][ ]g2 vs sentinel(at: 10:00 PM ) +10. [E][ ]g2 vs sentinel(at: 10:00 PM Oct 10 2020) +____________________________________________________________ +____________________________________________________________ +Noted. I've removed this task: +[E][X]watch hankyuu livestream(at: midnight ) +Now you have 9 tasks in the list. +Noted. I've removed this task: +[T][X]watch et1231 livestream +Now you have 8 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Here are the tasks in your list: +1. [T][X]watch haxxnini livestream +2. [D][ ]reach legend(by: this season ) +3. [D][ ]reach gold(by: 08:00 AM ) +4. [D][ ]reach silver(by: Oct 10 2020) +5. [D][ ]reach bronze(by: 08:00 AM Oct 10 2020) +6. [E][ ]g2 vs sentinel(at: 10pm ) +7. [E][ ]g2 vs sentinel(at: 10:00 AM ) +8. [E][ ]g2 vs sentinel(at: 10:00 AM Oct 10 2020) +____________________________________________________________ +____________________________________________________________ +☹ OOPS!!! I'm sorry, but I don't know what that means :-( +Defaulting to Echo. Type !help to see the list of Commands + +======= +[T][X]watch hankyuu livestream +[D][X]reach radiant(by: this season) +____________________________________________________________ +Here are the tasks in your list: +1. [T][X]watch et1231 livestream +2. [T][X]watch hankyuu livestream +3. [T][ ]watch haxxnini livestream +4. [D][X]reach radiant(by: this season) +5. [E][ ]g2 vs sentinel(at:12am) +____________________________________________________________ +____________________________________________________________ +Noted. I've removed this task: +[T][X]watch et1231 livestream +Now you have 4 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Here are the tasks in your list: +1. [T][X]watch hankyuu livestream +2. [T][ ]watch haxxnini livestream +3. [D][X]reach radiant(by: this season) +4. [E][ ]g2 vs sentinel(at:12am) +____________________________________________________________ +☹ OOPS!!! I'm sorry, but I don't know what that means :-( +Defaulting to Echo. Type !help to see the list of Commands +____________________________________________________________ +>>>>>>> parent of 6845eab (no message) +random command +____________________________________________________________ +____________________________________________________________ +List of Commands: + echo - Repeat whatever was typed - !echo to repeat in art form + list - Display List - !list for details + todo - Add ToDo Task + event - Add Event Task - !event for details + deadline - Add Deadline Task - !deadline for details + bye - Shut Down +<<<<<<< HEAD + +======= +>>>>>>> parent of 6845eab (no message) +____________________________________________________________ +____________________________________________________________ +list displays all tasks +list todo displays all todo tasks +list event displays all event tasks +list deadline displays all deadline tasks +<<<<<<< HEAD + +____________________________________________________________ +____________________________________________________________ +event command requires a timing indicated using "at" [timing] + +____________________________________________________________ +____________________________________________________________ +deadline command requires a end time indicated using "by"[end time] + +____________________________________________________________ +____________________________________________________________ +____________________________________________________________ +Bye. Hope to see you again soon! +======= +____________________________________________________________ +____________________________________________________________ +event command requires a timing indicated using "at" [timing] +____________________________________________________________ +____________________________________________________________ +deadline command requires a end time indicated using "by"[end time] +____________________________________________________________ +____________________________________________________________ +Bye. Hope to see you again soon! +____________________________________________________________ +>>>>>>> parent of 6845eab (no message) +_______________.___.___________ +\______ \__ | |\_ _____/ + | | _// | | | __)_ + | | \\____ | | \ + |________// ______|/_________/ \ No newline at end of file From 1c84ea05284a0abbc0f109c8db7952d89e5d22b2 Mon Sep 17 00:00:00 2001 From: wingho2 Date: Tue, 28 Sep 2021 15:51:28 +0800 Subject: [PATCH 29/62] Levvel-7 fix --- src/main/java/duke/Duke.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 3f7ba679d..5cd01fc1e 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -5,7 +5,7 @@ import duke.Storage.Storage; import duke.TaskList.TaskList; import duke.Ui.Ui; -//Level 8 +//Level 7 /** * Main Class of the Duke program * Handle the integration of classes to provide the necessary functions to the user From 19157414595ec1e63affc41a599b7d2d2cbe6e12 Mon Sep 17 00:00:00 2001 From: wingho2 Date: Tue, 28 Sep 2021 15:52:40 +0800 Subject: [PATCH 30/62] Level-8-fix --- src/main/java/duke/Duke.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 5cd01fc1e..3f7ba679d 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -5,7 +5,7 @@ import duke.Storage.Storage; import duke.TaskList.TaskList; import duke.Ui.Ui; -//Level 7 +//Level 8 /** * Main Class of the Duke program * Handle the integration of classes to provide the necessary functions to the user From 2bb73ddf7ff66012e4f541520af2e212f272cdf6 Mon Sep 17 00:00:00 2001 From: wingho2 Date: Tue, 28 Sep 2021 15:53:28 +0800 Subject: [PATCH 31/62] Level9 fix --- src/main/java/duke/Duke.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 5cd01fc1e..55d56fabd 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -5,7 +5,7 @@ import duke.Storage.Storage; import duke.TaskList.TaskList; import duke.Ui.Ui; -//Level 7 +//Level 9 /** * Main Class of the Duke program * Handle the integration of classes to provide the necessary functions to the user From 88be32eb433de7fb667b104519089d2ec7e3b3f5 Mon Sep 17 00:00:00 2001 From: wingho2 Date: Tue, 28 Sep 2021 15:54:15 +0800 Subject: [PATCH 32/62] A-JavaDoc --- src/main/java/duke/Duke.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 5cd01fc1e..b664ae3a4 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -5,7 +5,7 @@ import duke.Storage.Storage; import duke.TaskList.TaskList; import duke.Ui.Ui; -//Level 7 +//Level A-JavaDoc /** * Main Class of the Duke program * Handle the integration of classes to provide the necessary functions to the user From 1bbc6f59581c5eb1a7c161c34f099f4147e99cc0 Mon Sep 17 00:00:00 2001 From: wingho2 Date: Tue, 28 Sep 2021 16:45:45 +0800 Subject: [PATCH 33/62] Level8 --- src/main/java/duke/Duke.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 2a855b98a..974068a7b 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -5,7 +5,7 @@ import duke.Storage.Storage; import duke.TaskList.TaskList; import duke.Ui.Ui; - +//level-8 /** * Main Class of the Duke program * Handle the integration of classes to provide the necessary functions to the user From 7022461522c49ab7b94270c6f9830fc6f96d1439 Mon Sep 17 00:00:00 2001 From: wingho2 Date: Tue, 28 Sep 2021 16:46:38 +0800 Subject: [PATCH 34/62] Level9 --- src/main/java/duke/Duke.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 974068a7b..5d1605e25 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -5,7 +5,7 @@ import duke.Storage.Storage; import duke.TaskList.TaskList; import duke.Ui.Ui; -//level-8 +//level-9 /** * Main Class of the Duke program * Handle the integration of classes to provide the necessary functions to the user From 78d2e29117a61bfbc1d5df788d28499efdf9121b Mon Sep 17 00:00:00 2001 From: wingho2 Date: Tue, 28 Sep 2021 16:49:01 +0800 Subject: [PATCH 35/62] JavaDoc --- src/main/java/duke/Duke.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 5d1605e25..5cd801c2b 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -5,7 +5,7 @@ import duke.Storage.Storage; import duke.TaskList.TaskList; import duke.Ui.Ui; -//level-9 +//A-JavaDoc /** * Main Class of the Duke program * Handle the integration of classes to provide the necessary functions to the user From 15cfa134399e89cb026e1b6a45edc6cdca0ec24f Mon Sep 17 00:00:00 2001 From: wingho2 Date: Tue, 28 Sep 2021 16:50:56 +0800 Subject: [PATCH 36/62] Branch level8 --- src/main/java/duke/Duke.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 5cd801c2b..3f7ba679d 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -5,7 +5,7 @@ import duke.Storage.Storage; import duke.TaskList.TaskList; import duke.Ui.Ui; -//A-JavaDoc +//Level 8 /** * Main Class of the Duke program * Handle the integration of classes to provide the necessary functions to the user From b349f2ed6715f54a96ed627e803ec1d2f82dae59 Mon Sep 17 00:00:00 2001 From: wingho2 Date: Tue, 28 Sep 2021 16:52:16 +0800 Subject: [PATCH 37/62] Branch Level9 --- src/main/java/duke/Duke.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 5cd801c2b..51e347331 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -5,7 +5,7 @@ import duke.Storage.Storage; import duke.TaskList.TaskList; import duke.Ui.Ui; -//A-JavaDoc +//Level-9 /** * Main Class of the Duke program * Handle the integration of classes to provide the necessary functions to the user From 6a5eff9a7a0a575bc9ce90a720123aad540dc095 Mon Sep 17 00:00:00 2001 From: wingho2 Date: Tue, 28 Sep 2021 16:53:02 +0800 Subject: [PATCH 38/62] A-JavaDoc --- src/main/java/duke/Duke.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 5cd801c2b..5e08b0412 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -5,7 +5,7 @@ import duke.Storage.Storage; import duke.TaskList.TaskList; import duke.Ui.Ui; -//A-JavaDoc +//A-Javadoc /** * Main Class of the Duke program * Handle the integration of classes to provide the necessary functions to the user From ecceb769560e5e781238e9230218573a8404c245 Mon Sep 17 00:00:00 2001 From: wingho2 Date: Tue, 28 Sep 2021 17:04:31 +0800 Subject: [PATCH 39/62] Level:8 --- src/main/java/duke/Duke.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 2a855b98a..65cb465c9 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -5,7 +5,7 @@ import duke.Storage.Storage; import duke.TaskList.TaskList; import duke.Ui.Ui; - +//level8 /** * Main Class of the Duke program * Handle the integration of classes to provide the necessary functions to the user From 8e593894ea68f7ecbd3fafe262fec8ea4420af03 Mon Sep 17 00:00:00 2001 From: wingho2 Date: Tue, 28 Sep 2021 17:05:19 +0800 Subject: [PATCH 40/62] Level:9 --- src/main/java/duke/Duke.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 2a855b98a..bb8b07dfb 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -5,7 +5,7 @@ import duke.Storage.Storage; import duke.TaskList.TaskList; import duke.Ui.Ui; - +//level 9 /** * Main Class of the Duke program * Handle the integration of classes to provide the necessary functions to the user From 887ddf132437fc410753ed5285f80f65cf71f6a5 Mon Sep 17 00:00:00 2001 From: wingho2 Date: Tue, 28 Sep 2021 17:05:53 +0800 Subject: [PATCH 41/62] A-JavaDoc --- src/main/java/duke/Duke.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 2a855b98a..5cd801c2b 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -5,7 +5,7 @@ import duke.Storage.Storage; import duke.TaskList.TaskList; import duke.Ui.Ui; - +//A-JavaDoc /** * Main Class of the Duke program * Handle the integration of classes to provide the necessary functions to the user From d07b2aa9bf713966ed5cc1a487532c55fba08393 Mon Sep 17 00:00:00 2001 From: wingho2 Date: Tue, 28 Sep 2021 17:09:02 +0800 Subject: [PATCH 42/62] Solving merge conflict --- src/main/java/duke/Duke.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 9b0efbf7b..2a855b98a 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -5,11 +5,7 @@ import duke.Storage.Storage; import duke.TaskList.TaskList; import duke.Ui.Ui; -<<<<<<< HEAD -//level8 -======= -//A-JavaDoc ->>>>>>> branch-A-JavaDoc + /** * Main Class of the Duke program * Handle the integration of classes to provide the necessary functions to the user From f3317e19e45f05e39da281f91aa98d537edff918 Mon Sep 17 00:00:00 2001 From: wingho2 Date: Tue, 28 Sep 2021 17:10:26 +0800 Subject: [PATCH 43/62] Merging PRS --- src/main/java/duke/Duke.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index bb8b07dfb..2a855b98a 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -5,7 +5,7 @@ import duke.Storage.Storage; import duke.TaskList.TaskList; import duke.Ui.Ui; -//level 9 + /** * Main Class of the Duke program * Handle the integration of classes to provide the necessary functions to the user From 264344eedd4e75f547b4385754987bc50b8473e9 Mon Sep 17 00:00:00 2001 From: wingho2 Date: Wed, 29 Sep 2021 17:47:23 +0800 Subject: [PATCH 44/62] Fix Exception Messages and add more comments to functions --- duke.txt | 5 +- src/main/java/duke/ArtBot/ArtBot.java | 13 +- .../java/duke/Command/AddDeadlineCommand.java | 15 + .../java/duke/Command/AddEventCommand.java | 15 + .../java/duke/Command/AddToDoCommand.java | 13 + src/main/java/duke/Command/ClearCommand.java | 2 +- src/main/java/duke/Command/Command.java | 14 +- src/main/java/duke/Command/DeleteCommand.java | 14 +- src/main/java/duke/Command/DoneCommand.java | 12 +- .../java/duke/Command/FindDateCommand.java | 7 +- .../java/duke/Command/FindKeywordCommand.java | 2 +- src/main/java/duke/Command/ListCommand.java | 5 +- src/main/java/duke/Duke.java | 6 +- .../duke/ErrorHandling/CommandException.java | 4 +- .../duke/ErrorHandling/ErrorStaticString.java | 17 +- src/main/java/duke/Parser/Parser.java | 10 +- src/main/java/duke/Storage/FileRead.java | 4 +- src/main/java/duke/Storage/Storage.java | 8 +- src/main/java/duke/TaskList/TaskList.java | 42 +-- src/main/java/duke/Ui/Ui.java | 37 +-- src/main/java/duke/task/Deadline.java | 6 +- src/main/java/duke/task/Event.java | 6 +- text-ui-test/EXPECTED.TXT | 216 +++++++++++++- text-ui-test/EXPECTED.txt | 7 - text-ui-test/EXPECTED.txt~merged | 273 ------------------ text-ui-test/input.txt | 11 +- 26 files changed, 381 insertions(+), 383 deletions(-) delete mode 100644 text-ui-test/EXPECTED.txt delete mode 100644 text-ui-test/EXPECTED.txt~merged diff --git a/duke.txt b/duke.txt index 5e2b38870..1ccf53062 100644 --- a/duke.txt +++ b/duke.txt @@ -1,8 +1,7 @@ -[T];[X];watch haxxnini livestream -[D];[ ];reach legend;this season +[D];[ ];reach legend;this season [D];[ ];reach gold;08:00 [D];[ ];reach silver; 2020-10-10 [D];[ ];reach bronze;08:00 2020-10-10 -[E];[ ];g2 vs sentinel;10pm +[E];[ ];g2 vs sentinel;10pm [E];[ ];g2 vs sentinel;10:00 [E];[ ];g2 vs sentinel;10:00 2020-10-10 diff --git a/src/main/java/duke/ArtBot/ArtBot.java b/src/main/java/duke/ArtBot/ArtBot.java index a2f7df19e..3b1be8242 100644 --- a/src/main/java/duke/ArtBot/ArtBot.java +++ b/src/main/java/duke/ArtBot/ArtBot.java @@ -5,15 +5,16 @@ import java.util.ArrayList; /** - * Convert a string into graffiti form and print it out + * Convert string into graffiti form and print it */ public class ArtBot implements ArtInterface { + private static final int SIZE_OF_ARRAY = 5; private final String userInput; /** * Constructor for ArtBot - * Assign string to be drawn + * Assign string to draw * * @param userInput String to be drawn */ @@ -23,7 +24,8 @@ public ArtBot(String userInput){ /** * Each Drawn version of a letter take up 5 line - * Convert letter into drawn version of string + * Convert letter into drawn version of string stored in Logo Class + * Split each drawn version into array of 5 string separated by each line * * @param letter Letter to convert into array of string * @return Array of string representing a letter @@ -158,7 +160,7 @@ private ArrayList getLetterInArtForm(String[] inputArrayOfLetter) thro for(String s:inputArrayOfLetter){ String[] letterInArtForm = getLogo(s); if(letterInArtForm == null){ - throw new CommandException(ErrorStaticString.ERROR_LETTER_NOT_FOUND); + throw new CommandException(ErrorStaticString.ERROR_ARTBOT_LETTER_NOT_FOUND); } listToStoreLetterInArtForm.add(letterInArtForm); } @@ -168,6 +170,7 @@ private ArrayList getLetterInArtForm(String[] inputArrayOfLetter) thro /** * Merge same index of string in each string array * First String in First String Array with First String in Second String Array and so on... + * * @param arrayToMerge list of String Array to merge * @return String Array of 5 String after all have been merged */ @@ -190,7 +193,7 @@ private String[] mergeArray(ArrayList arrayToMerge){ * @param array Array to print */ private void printArray(String[] array){ - for(int i = 0; i < 5; i++){ + for(int i = 0; i < SIZE_OF_ARRAY; i++){ System.out.println(array[i]); } } diff --git a/src/main/java/duke/Command/AddDeadlineCommand.java b/src/main/java/duke/Command/AddDeadlineCommand.java index 9c312cd8a..26c3d7172 100644 --- a/src/main/java/duke/Command/AddDeadlineCommand.java +++ b/src/main/java/duke/Command/AddDeadlineCommand.java @@ -4,15 +4,30 @@ import duke.ErrorHandling.ErrorStaticString; import duke.TaskList.TaskList; +/** + * Represent a command to add deadline task + */ public class AddDeadlineCommand extends Command{ private final TaskList listManager; + /** + * Constructor for Add Deadline Command + * + * @param taskInput Command input by user to process + * @param listManager Tasklist to interact with list of task + */ public AddDeadlineCommand(String taskInput, TaskList listManager){ super(taskInput); this.listManager = listManager; } + /** + * Filter out deadline command, description and date and time of deadline + * Add deadline task to list via TaskList + * + * @throws CommandException if date and time of deadline is empty or if description is empty + */ @Override public void executeCommand() throws CommandException { String taskDescription = taskInput.replaceFirst(COMMAND_ADD_DEADLINE, EMPTY_STRING).trim(); diff --git a/src/main/java/duke/Command/AddEventCommand.java b/src/main/java/duke/Command/AddEventCommand.java index 0d321695e..6efc7a729 100644 --- a/src/main/java/duke/Command/AddEventCommand.java +++ b/src/main/java/duke/Command/AddEventCommand.java @@ -4,15 +4,30 @@ import duke.ErrorHandling.ErrorStaticString; import duke.TaskList.TaskList; +/** + * Represent a command to add Event task + */ public class AddEventCommand extends Command{ private final TaskList listManager; + /** + * Constructor for Add Deadline Command + * + * @param taskInput Command input by user to process + * @param listManager Tasklist to interact with list of task + */ public AddEventCommand(String taskInput, TaskList listManager){ super(taskInput); this.listManager = listManager; } + /** + * Filter out event command, description and date and time of event + * Add event task to list via TaskList + * + * @throws CommandException if date and time of event is empty or if description is empty + */ @Override public void executeCommand() throws CommandException { String taskDescription = taskInput.replaceFirst(COMMAND_ADD_EVENT, EMPTY_STRING).trim(); diff --git a/src/main/java/duke/Command/AddToDoCommand.java b/src/main/java/duke/Command/AddToDoCommand.java index a6d9f0e52..5edf6d23f 100644 --- a/src/main/java/duke/Command/AddToDoCommand.java +++ b/src/main/java/duke/Command/AddToDoCommand.java @@ -4,15 +4,28 @@ import duke.ErrorHandling.ErrorStaticString; import duke.TaskList.TaskList; +/** + * Represent a command to add ToDo task + */ public class AddToDoCommand extends Command{ private final TaskList listManager; + /** + * Constructor for Add ToDo Command + * + * @param taskInput Command input by user to process + * @param listManager Tasklist to interact with list of task + */ public AddToDoCommand(String taskInput, TaskList listManager){ super(taskInput); this.listManager = listManager; } + /** + * Filter out ToDo command and description + * @throws CommandException if description is empty + */ @Override public void executeCommand() throws CommandException{ String removeCommand = taskInput.replaceFirst(COMMAND_ADD_TODO, EMPTY_STRING).trim(); diff --git a/src/main/java/duke/Command/ClearCommand.java b/src/main/java/duke/Command/ClearCommand.java index f61bf7e92..f46b707dd 100644 --- a/src/main/java/duke/Command/ClearCommand.java +++ b/src/main/java/duke/Command/ClearCommand.java @@ -20,7 +20,7 @@ public ClearCommand(String taskInput, TaskList taskList){ } /** - * Clear the list in Tasklist + * Clear list in Tasklist */ @Override public void executeCommand(){ diff --git a/src/main/java/duke/Command/Command.java b/src/main/java/duke/Command/Command.java index 96733477c..5dd1b8815 100644 --- a/src/main/java/duke/Command/Command.java +++ b/src/main/java/duke/Command/Command.java @@ -20,7 +20,6 @@ public abstract class Command { protected static final String COMMAND_ADD_DEADLINE = "deadline"; protected static final String COMMAND_DELETE = "delete"; protected static final String COMMAND_FIND_WORD = "find"; - protected static final String COMMAND_CLEAR_WORD = "clear"; protected static final String EVENT_TIME = "at "; protected static final String DEADLINE_DATE = "by "; protected static final String MESSAGE_TASK_COMPLETE = "Nice! I've marked this task as done: "; @@ -36,13 +35,18 @@ public abstract class Command { " todo - Add ToDo Task\n" + " event - Add Event Task - !event for details\n" + " deadline - Add Deadline Task - !deadline for details\n" + - " bye - Shut Down\n"; + " clear - Clear list\n" + + " find - Find Task With a specific word\n" + + " date - Find Task with a specific date\n" + + " bye - Shut Down"; protected static final String MESSAGE_LIST_HELP = "list displays all tasks\n" + "list todo displays all todo tasks\n" + "list event displays all event tasks\n" + - "list deadline displays all deadline tasks\n"; - protected static final String MESSAGE_EVENT_HELP = "event command requires a timing indicated using \"at\" [timing]\n"; - protected static final String MESSAGE_DEADLINE_HELP = "deadline command requires a end time indicated using \"by\"[end time]\n"; + "list deadline displays all deadline tasks"; + protected static final String MESSAGE_EVENT_HELP = "event command requires a timing indicated using \"at\" [timing]\n" + + "[timing]: HH:MM YYYY-MM-DD"; + protected static final String MESSAGE_DEADLINE_HELP = "deadline command requires a end time indicated using \"by\"[end time]\n" + + "[timing]: HH:MM YYYY-MM-DD"; protected String taskInput; diff --git a/src/main/java/duke/Command/DeleteCommand.java b/src/main/java/duke/Command/DeleteCommand.java index aa1869ebe..752d6636b 100644 --- a/src/main/java/duke/Command/DeleteCommand.java +++ b/src/main/java/duke/Command/DeleteCommand.java @@ -7,7 +7,7 @@ import java.util.Collections; /** - * Represent a command that remove a task from list + * Represent a command that remove task from list */ public class DeleteCommand extends Command{ @@ -42,10 +42,14 @@ public void executeCommand()throws CommandException { String[] taskDoneArray = removeCommand.split(SEPARATOR); ArrayList intArray = new ArrayList<>(); for (String s: taskDoneArray){ - int taskDoneIndex = Integer.parseInt(s) - 1; - intArray.add(taskDoneIndex); - if(taskDoneIndex > listManager.getListSize() || taskDoneIndex < 0){ - throw new CommandException(ErrorStaticString.ERROR_DELETE_TASK); + try { + int taskDoneIndex = Integer.parseInt(s) - 1; + intArray.add(taskDoneIndex); + if (taskDoneIndex > listManager.getListSize() || taskDoneIndex < 0) { + throw new CommandException(ErrorStaticString.ERROR_DELETE_TASK); + } + }catch (NumberFormatException e){ + System.out.println(ErrorStaticString.ERROR_DELETE_INPUT_FORMAT); } } Collections.sort(intArray, Collections.reverseOrder()); diff --git a/src/main/java/duke/Command/DoneCommand.java b/src/main/java/duke/Command/DoneCommand.java index 4767e6432..b19139f75 100644 --- a/src/main/java/duke/Command/DoneCommand.java +++ b/src/main/java/duke/Command/DoneCommand.java @@ -41,10 +41,14 @@ public void executeCommand() throws CommandException{ System.out.println(MESSAGE_TASK_COMPLETE); ArrayList intArray = new ArrayList<>(); for (String s: taskDoneArray) { - int taskDoneIndex = Integer.parseInt(s) - 1; - intArray.add(taskDoneIndex); - if(taskDoneIndex > listManager.getListSize() || taskDoneIndex < 0){ - throw new CommandException(ErrorStaticString.ERROR_DONE_TASK_NOT_IN_LIST); + try { + int taskDoneIndex = Integer.parseInt(s) - 1; + intArray.add(taskDoneIndex); + if (taskDoneIndex > listManager.getListSize() || taskDoneIndex < 0) { + throw new CommandException(ErrorStaticString.ERROR_DONE_TASK_NOT_IN_LIST); + } + }catch (NumberFormatException e){ + System.out.println(ErrorStaticString.ERROR_DONE_INPUT_FORMAT); } } for(Integer i: intArray){ diff --git a/src/main/java/duke/Command/FindDateCommand.java b/src/main/java/duke/Command/FindDateCommand.java index f7af509e6..a7c79d6a4 100644 --- a/src/main/java/duke/Command/FindDateCommand.java +++ b/src/main/java/duke/Command/FindDateCommand.java @@ -39,19 +39,18 @@ public void executeCommand() throws CommandException { } taskInput = taskInput.replaceFirst(COMMAND_DATE_TASK,EMPTY_STRING).trim(); if(taskInput.isEmpty()){ - throw new CommandException(ErrorStaticString.ERROR_EMPTY_DATE_SEARCH_TASK); + throw new CommandException(ErrorStaticString.ERROR_EMPTY_DATE_INPUT); } try { LocalDate localDate = LocalDate.parse(convertStringToDate()); taskList.printDate(localDate); }catch (DateTimeParseException e ){ - System.out.println(ErrorStaticString.ERROR_DATE_SEARCH); + System.out.println(ErrorStaticString.ERROR_DATE_TIME_PARSE); } } /** - * Find first instance of a date by finding a string in a pattern - * Pattern:4int-2int-2int + * Find first instance of a date by finding a string in a pattern:4int-2int-2int * * @param stringToSearch String that contain date * @return Null if no date is found or return a matcher object that found date diff --git a/src/main/java/duke/Command/FindKeywordCommand.java b/src/main/java/duke/Command/FindKeywordCommand.java index 98dbaf972..d82dd9e2d 100644 --- a/src/main/java/duke/Command/FindKeywordCommand.java +++ b/src/main/java/duke/Command/FindKeywordCommand.java @@ -34,7 +34,7 @@ public void executeCommand() throws CommandException{ } taskInput = taskInput.replaceFirst(COMMAND_FIND_WORD,EMPTY_STRING).trim(); if(taskInput.isEmpty()){ - throw new CommandException(ErrorStaticString.ERROR_EMPTY_LIST); + throw new CommandException(ErrorStaticString.ERROR_EMPTY_WORD_INPUT); } taskList.printWord(taskInput); } diff --git a/src/main/java/duke/Command/ListCommand.java b/src/main/java/duke/Command/ListCommand.java index ec563607e..6e45fcc90 100644 --- a/src/main/java/duke/Command/ListCommand.java +++ b/src/main/java/duke/Command/ListCommand.java @@ -13,6 +13,7 @@ public class ListCommand extends Command{ /** * Constructor for ListCommand + * * @param userInput Command Input by user to process * @param listManager Tasklist to interact with list of task */ @@ -23,8 +24,8 @@ public ListCommand(String userInput, TaskList listManager){ /** * Process list input to print whole list or list of a certain type - * Remove the command by replacing command with empty string - * Remove the need for using separators + * Remove command by replacing command with empty string + * Remove need for using separators * * @throws CommandException if list is empty */ diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 2a855b98a..c66b6072c 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -27,9 +27,9 @@ public Duke(){ /** * Main function of Duke - * Integrate the Ui class that handles taking in input of the user with - * the Parser class that handles the response to the input - * Keep running until the system is terminated by a string bye + * Integrate Ui class that handles taking in input of user with + * Parser class that handles response of input + * Loop until system is terminated */ public void run(){ ui.Greetings(); diff --git a/src/main/java/duke/ErrorHandling/CommandException.java b/src/main/java/duke/ErrorHandling/CommandException.java index f2ee2f719..f7c9b65be 100644 --- a/src/main/java/duke/ErrorHandling/CommandException.java +++ b/src/main/java/duke/ErrorHandling/CommandException.java @@ -1,7 +1,7 @@ package duke.ErrorHandling; /** - * Represent a error resulting from input of user + * Represent error resulting from input of user */ public class CommandException extends Exception{ @@ -9,7 +9,7 @@ public class CommandException extends Exception{ /** * Constructor for CommandException - * Create error message of this instance of exception + * Assign error message of this instance of exception * * @param errorMessage Error message to print */ diff --git a/src/main/java/duke/ErrorHandling/ErrorStaticString.java b/src/main/java/duke/ErrorHandling/ErrorStaticString.java index 2bb6e2ac9..d51528df6 100644 --- a/src/main/java/duke/ErrorHandling/ErrorStaticString.java +++ b/src/main/java/duke/ErrorHandling/ErrorStaticString.java @@ -4,7 +4,7 @@ * Contain Error Messages */ public class ErrorStaticString { - public static final String ERROR_NULL = "☹ OOPS!!! Input cannot be empty."; + public static final String ERROR_EMPTY_INPUT = "☹ OOPS!!! Input cannot be empty."; public static final String ERROR_UNKNOWN_COMMAND = "☹ OOPS!!! I'm sorry, but I don't know what that means :-(\n" + "" + "Defaulting to Echo. Type !help to see the list of Commands\n"; @@ -12,30 +12,35 @@ public class ErrorStaticString { public static final String ERROR_EMPTY_TODO_LIST = "☹ OOPS!!! There is no To Do task in list. Add To Do tasks to the list."; public static final String ERROR_EMPTY_EVENT_LIST = "☹ OOPS!!! There is no Event task in list. Add Events to the list."; public static final String ERROR_EMPTY_DEADLINE_LIST = "☹ OOPS!!! There is no Deadline task in list. Add Deadlines to the list."; + public static final String ERROR_EMPTY_DATE_SEARCH_LIST = "☹ OOPS!!! No tasks with date found."; + public static final String ERROR_EMPTY_WORD_SEARCH_LIST = "☹ OOPS!!! No tasks with input word found."; public static final String ERROR_EMPTY_TODO_INPUT = "☹ OOPS!!! The description of a todo cannot be empty."; public static final String ERROR_EMPTY_EVENT_INPUT = "☹ OOPS!!! The description of a event cannot be empty."; public static final String ERROR_EMPTY_DEADLINE_INPUT = "☹ OOPS!!! The description of a deadline cannot be empty."; public static final String ERROR_EMPTY_ECHO_INPUT = "☹ OOPS!!! The description of a echo cannot be empty."; - public static final String ERROR_EMPTY_EVENT_TIME = "☹ OOPS!!! The timing of the event not detected, use [at] to indicated the time."; - public static final String ERROR_EMPTY_DEADLINE_TIME = "☹ OOPS!!! The due date of a deadline not detected, use [by] to indicated the date."; + public static final String ERROR_EMPTY_EVENT_TIME = "☹ OOPS!!! The timing of the event not detected, use [at] to indicated date and time."; + public static final String ERROR_EMPTY_DEADLINE_TIME = "☹ OOPS!!! The due date of a deadline not detected, use [by] to indicated date and time."; public static final String ERROR_DONE_TASK_NOT_IN_LIST ="☹ OOPS!!! Task done not found in list"; public static final String ERROR_DONE_TASK_EMPTY ="☹ OOPS!!! Cannot set task as complete without index."; + public static final String ERROR_DONE_INPUT_FORMAT = "☹ OOPS!!! Use only , and numbers to separate task to set as done."; public static final String ERROR_DELETE_TASK ="☹ OOPS!!! Cannot remove task that does not exist."; public static final String ERROR_DELETE_TASK_EMPTY ="☹ OOPS!!! Cannot remove task without index."; + public static final String ERROR_DELETE_INPUT_FORMAT = "☹ OOPS!!! Use only , and numbers to separate task to delete."; - public static final String ERROR_LETTER_NOT_FOUND = "☹ OOPS!!! Something went wrong. Do not input space or symbols."; + public static final String ERROR_ARTBOT_LETTER_NOT_FOUND = "☹ OOPS!!! Something went wrong, character input cannot be drawn.\n" + + "Do not input space or symbols."; public static final String ERROR_FILE_MESSAGE_CREATION = "☹ OOPS!!! Something went wrong with creating files"; public static final String ERROR_FILE_MESSAGE_READING = "☹ OOPS!!! Something went wrong with reading the files"; public static final String ERROR_FILE_MESSAGE_WRITING = "☹ OOPS!!! Something went wrong with writing to the files"; + public static final String ERROR_FILE_MESSAGE_CLEARING = "☹ OOPS!!! Something went wrong with clearing contents of the files"; public static final String ERROR_DATE_TIME_PARSE = "☹ OOPS!!! Something went wrong with reading date or time\n" + "Format of Date: YYYY-MM-DD\n" + "Format of Time: HH:MM"; - public static final String ERROR_DATE_SEARCH = "☹ OOPS!!! Date searched is invalid. Please enter date in format of YYYY-MM-DD"; - public static final String ERROR_EMPTY_DATE_SEARCH_TASK = "☹ OOPS!!! No tasks with date found."; public static final String ERROR_EMPTY_DATE_INPUT = "☹ OOPS!!! Date Searched cannot be Empty."; + public static final String ERROR_EMPTY_WORD_INPUT = "☹ OOPS!!! Word Searched cannot be Empty."; } diff --git a/src/main/java/duke/Parser/Parser.java b/src/main/java/duke/Parser/Parser.java index 9a68fe485..f81336d68 100644 --- a/src/main/java/duke/Parser/Parser.java +++ b/src/main/java/duke/Parser/Parser.java @@ -7,7 +7,7 @@ import java.util.Objects; /** - * Main Class handling the processing of input by user + * Main Class handling processing of input by user */ public class Parser{ @@ -146,7 +146,7 @@ public boolean isExit(){ */ public void handleInput() throws CommandException{ if(userInput.isEmpty()){ - throw new CommandException(ErrorStaticString.ERROR_NULL); + throw new CommandException(ErrorStaticString.ERROR_EMPTY_INPUT); } if(userInput.startsWith(COMMAND_GUIDE_INDICATOR)){ CommandGuide commandGuide = new CommandGuide(userInput); @@ -182,10 +182,10 @@ private void splitInputIfThereMoreThanOneCommand() { } /** - * Handle One Command by Creating an instance of the Command - * Hand execution of Command to the individual instance of Command + * Handle One Command by Creating an instance of Command + * Hand execution of Command to instance of Command * - * @param inputCommand String representing one Command, and it's input for the command + * @param inputCommand String representing one Command, and it's relevant input */ private void handleCommand(String inputCommand){ String commandCategory = taskCategory(inputCommand); diff --git a/src/main/java/duke/Storage/FileRead.java b/src/main/java/duke/Storage/FileRead.java index 716475bea..b3bc9db1d 100644 --- a/src/main/java/duke/Storage/FileRead.java +++ b/src/main/java/duke/Storage/FileRead.java @@ -20,8 +20,8 @@ public class FileRead extends Storage{ /** * Constructor for FileRead - * Creates new arraylist to store task from text file in - * Create Tasklist interact with arraylist after processing string in text file + * Creates new arraylist to store task from text file + * Create Tasklist to interact with arraylist after processing string in text file * * @param file file to read from */ diff --git a/src/main/java/duke/Storage/Storage.java b/src/main/java/duke/Storage/Storage.java index ce0b3bd50..b67636afb 100644 --- a/src/main/java/duke/Storage/Storage.java +++ b/src/main/java/duke/Storage/Storage.java @@ -9,7 +9,7 @@ /** * Handle interaction between Duke and text file - * Create the file if file is not found + * Create file if file is not found * Contain function to write to file * Contain function to read from file */ @@ -35,7 +35,6 @@ public class Storage { * Constructor for Storage * Create duke.txt file if not found * Print file name and location if created - * @throws IOException if file cannot be created */ public Storage(){ try{ @@ -50,6 +49,7 @@ public Storage(){ /** * Load task from text file into list + * * @return list of task from text file */ public ArrayList load(){ @@ -89,8 +89,6 @@ public void writeTask(ArrayList list){ /** * Write empty string to text file to clear its content - * - * @throws IOException if file is not found */ public void writeClearTask(){ try { @@ -98,7 +96,7 @@ public void writeClearTask(){ fileWriter.write(EMPTY_STRING); fileWriter.close(); } catch (IOException e) { - e.printStackTrace(); + System.out.println(ErrorStaticString.ERROR_FILE_MESSAGE_CLEARING); } } } diff --git a/src/main/java/duke/TaskList/TaskList.java b/src/main/java/duke/TaskList/TaskList.java index e3a3c3469..a7d2364fc 100644 --- a/src/main/java/duke/TaskList/TaskList.java +++ b/src/main/java/duke/TaskList/TaskList.java @@ -11,8 +11,8 @@ import java.util.ArrayList; /** - * Serve as an interface for Arraylist storing the tasks - * Responsible for manipulation and interaction of the Arraylist + * Serve as an interface for Arraylist storing tasks + * Responsible for manipulation and interaction of Arraylist */ public class TaskList implements TaskListInterface { @@ -24,6 +24,7 @@ public class TaskList implements TaskListInterface { private static final String MESSAGE_LIST_DEADLINE = "Here are the Deadline tasks in your list:"; private static final String MESSAGE_LIST_FIND = "Here are the matching tasks in your list:"; private static final String MESSAGE_LIST_FIND_DATE = "Here are the tasks with matching dates in your list:"; + private static final String MESSAGE_LIST_CLEAR = "List Cleared. All tasks removed."; private static final String MESSAGE_TASK_NOW = "Now you have "; private static final String MESSAGE_DELETE = "Noted. I've removed this task: "; private static final String MESSAGE_SPACER = ". "; @@ -32,16 +33,16 @@ public class TaskList implements TaskListInterface { private final ArrayList list; /** - * Constructor for the class to assign the arraylist to be manipulated + * Constructor for list class to assign arraylist to be manipulated * - * @param list Arraylist that store the tasks + * @param list Arraylist that store tasks */ public TaskList(ArrayList list){ this.list = list; } /** - * Loops through a list of task and print each task + * Loops through list of task and print each task * * @param listToPrint Arraylist containing tasks to print */ @@ -53,7 +54,7 @@ private void printer(ArrayList listToPrint){ } /** - * Print all the task in the list + * Print all task in list */ public void printList(){ System.out.println(MESSAGE_LIST_TASK); @@ -61,12 +62,12 @@ public void printList(){ } /** - * Print all the task with a specific date - * Sort out the task with the same date into a new list - * Print the new list + * Print all task with a specific date + * Sort out task with same date into new list + * Print new list * * @param dateSearched Date being search as LocalDate object - * @throws CommandException if no task with the date searched was found + * @throws CommandException if no task with date searched was found */ public void printDate(LocalDate dateSearched) throws CommandException{ boolean haveDate = false; @@ -82,7 +83,7 @@ public void printDate(LocalDate dateSearched) throws CommandException{ } } if(!haveDate){ - throw new CommandException(ErrorStaticString.ERROR_EMPTY_DATE_INPUT); + throw new CommandException(ErrorStaticString.ERROR_EMPTY_DATE_SEARCH_LIST); } System.out.println(MESSAGE_LIST_FIND_DATE); printer(listOfTaskWithDate); @@ -106,16 +107,16 @@ public void printWord(String wordSearch) throws CommandException{ } } if(!haveWord){ - throw new CommandException(ErrorStaticString.ERROR_EMPTY_LIST); + throw new CommandException(ErrorStaticString.ERROR_EMPTY_WORD_SEARCH_LIST); } System.out.println(MESSAGE_LIST_FIND); printer(listOfTaskWithWord); } /** - * Print all the Todo task in the list - * Sort out all the Todo task into a new list - * Print the new list + * Print all Todo task in list + * Sort out all Todo task into new list + * Print new list * * @throws CommandException if no Todo task is found in list */ @@ -136,9 +137,9 @@ public void printToDo() throws CommandException { } /** - * Print all the Event Task in list - * Sort out the Event Task into a new list - * Print the new list + * Print all Event Task in list + * Sort out Event Task into a new list + * Print new list * * @throws CommandException if Event task is not found in list */ @@ -182,7 +183,7 @@ public void printDeadline() throws CommandException{ } /** - * Print message when a task is added + * Print message when task is added * * @param t Task added to the list */ @@ -192,7 +193,7 @@ private void printAddItem(Task t){ } /** - * Adds ToDo task to list + * Add ToDo task to list * Print task added * Write task to text file * @@ -295,6 +296,7 @@ private void printDeleteTask(Task t){ * Write empty string to text file to clear text file */ public void clearTask(){ + System.out.println(MESSAGE_LIST_CLEAR); list.clear(); Storage storage = new Storage(); storage.writeClearTask(); diff --git a/src/main/java/duke/Ui/Ui.java b/src/main/java/duke/Ui/Ui.java index 8ed7f08d3..7cbde14bd 100644 --- a/src/main/java/duke/Ui/Ui.java +++ b/src/main/java/duke/Ui/Ui.java @@ -4,11 +4,11 @@ import java.util.Scanner; /** - * Handles the Interaction between the user and the program - * Contains the function that greets the user when program is started - * Contains the function that bid farewell to the user when the program ends - * Contains the function that tell the user what went wrong when an error is encountered - * Contains the function that print a line for readability + * Handles Interaction between user and program + * Contains function that greets user when program start + * Contains function that bid farewell to user when program ends + * Contains function that tell user what went wrong when an error is encountered + * Contains function that print a line for readability */ public class Ui { @@ -16,34 +16,35 @@ public class Ui { private static final String MESSAGE_BYE = "Bye. Hope to see you again soon!\n"; /** - * Called right at the start of the program - * Greet the user with a message - * Handles the message that is printed to the user + * Called at start of program + * Greet user with message + * Handles message that is printed to user */ public void Greetings(){ System.out.println(Logo.logo + Logo.divider + MESSAGE_HI + Logo.dividerWithoutNewLine); } /** - * Called when the program exit - * Print a farewell message to the user - * Handles the message to be printed to the user + * Called when program exit + * Print a farewell message to user + * Handles message to be printed to user */ public void Farewell(){ System.out.println(MESSAGE_BYE + Logo.bye); } /** - * Called before the input is process and after - * Draw a line before and after the response to an input - * Improve readability when using the program + * Called before input is process and after + * Draw a line before and after response of input + * Improve readability of program */ public void showLine(){ System.out.println(Logo.dividerWithoutNewLine); } /** - * A function to read in input from user + * Read in input from user + * Remove Spaces and convert to lower case * * @return input from user in String */ @@ -53,10 +54,10 @@ public String readCommand(){ } /** - * Called when an error is encountered - * Print error message to the user + * Called when error encountered + * Print error message to user * - * @param error Error Message in String to print to user + * @param error Error Message to print */ public void showError(String error){ System.out.println(error); diff --git a/src/main/java/duke/task/Deadline.java b/src/main/java/duke/task/Deadline.java index d70558799..59ee52560 100644 --- a/src/main/java/duke/task/Deadline.java +++ b/src/main/java/duke/task/Deadline.java @@ -27,8 +27,7 @@ public Deadline(String description, String deadlineDateTime){ } /** - * Find first instance of a date by finding a string in a pattern - * Pattern:4int-2int-2int + * Find first instance of a date by finding a string in a pattern:4int-2int-2int * * @param stringToSearch String that contain date * @return Null if no date is found or return a matcher object that found date @@ -43,8 +42,7 @@ private Matcher findDate(String stringToSearch){ } /** - * Find first instance of time by finding a fixed pattern of string - * Pattern:2int:2int + * Find first instance of time by finding a fixed pattern:2int:2int * * @param stringToSearch String that contain time * @return null if no time found or return matcher object that found time diff --git a/src/main/java/duke/task/Event.java b/src/main/java/duke/task/Event.java index edc2f5f69..73a1958dc 100644 --- a/src/main/java/duke/task/Event.java +++ b/src/main/java/duke/task/Event.java @@ -27,8 +27,7 @@ public Event(String description, String eventDateTime){ } /** - * Find first instance of a date by finding a string in a pattern - * Pattern:4int-2int-2int + * Find first instance of a date by finding a string in a pattern:4int-2int-2int * * @param stringToSearch String that contain date * @return Null if no date is found or return a matcher object that found date @@ -43,8 +42,7 @@ private Matcher findDate(String stringToSearch){ } /** - * Find first instance of time by finding a fixed pattern of string - * Pattern:2int:2int + * Find first instance of time by finding a fixed pattern:2int:2int * * @param stringToSearch String that contain time * @return null if no time found or return matcher object that found time diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 657e74f6e..204938f76 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,7 +1,217 @@ -Hello from - ____ _ -| _ \ _ _| | _____ + ____ _ +| _ \ _ _| | _____ | | | | | | | |/ / _ \ | |_| | |_| | < __/ |____/ \__,_|_|\_\___| +____________________________________________________________ +Hello! I'm Duke +What can I do for you? +!help for Command List +____________________________________________________________ +____________________________________________________________ +hi +____________________________________________________________ +____________________________________________________________ +HI + ___ ___ .___ + / | \ | | +/ ~ \| | +\ Y /| | + \___|___/ |___| +____________________________________________________________ +____________________________________________________________ + ☹ OOPS!!! List is empty. Add tasks to the list. +____________________________________________________________ +____________________________________________________________ +List Cleared. All tasks removed. +____________________________________________________________ +____________________________________________________________ +☹ OOPS!!! List is empty. Add tasks to the list. +____________________________________________________________ +____________________________________________________________ +☹ OOPS!!! List is empty. Add tasks to the list. +____________________________________________________________ +____________________________________________________________ +Got it. I've added this task: +[T][ ]watch et livestream +Now you have 1 tasks in the list. +Got it. I've added this task: +[E][ ]watch hankyuu livestream(at: midnight ) +Now you have 2 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Got it. I've added this task: +[T][ ]watch haxxnini livestream +Now you have 3 tasks in the list. +____________________________________________________________ +____________________________________________________________ +☹ OOPS!!! The due date of a deadline not detected, use [by] to indicated date and time. +____________________________________________________________ +____________________________________________________________ +Got it. I've added this task: +[D][ ]reach legend(by: this season ) +Now you have 4 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Got it. I've added this task: +[D][ ]reach gold(by: 08:00 PM ) +Now you have 5 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Got it. I've added this task: +[D][ ]reach silver(by: Oct 10 2020) +Now you have 6 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Got it. I've added this task: +[D][ ]reach bronze(by: 08:00 PM Oct 10 2020) +Now you have 7 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Here are the tasks in your list: +1. [D][ ]reach silver(by: Oct 10 2020) +2. [D][ ]reach bronze(by: 08:00 PM Oct 10 2020) +____________________________________________________________ +____________________________________________________________ +☹ OOPS!!! Something went wrong with reading date or time +Format of Date: YYYY-MM-DD +Format of Time: HH:MM +____________________________________________________________ +____________________________________________________________ +☹ OOPS!!! The timing of the event not detected, use [at] to indicated date and time. +____________________________________________________________ +____________________________________________________________ +Got it. I've added this task: +[E][ ]g2 vs sentinel(at: 10pm ) +Now you have 8 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Got it. I've added this task: +[E][ ]g2 vs sentinel(at: 10:00 PM ) +Now you have 9 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Got it. I've added this task: +[E][ ]g2 vs sentinel(at: 10:00 PM Oct 10 2020) +Now you have 10 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Here are the matching tasks in your list: +1. [E][ ]g2 vs sentinel(at: 10pm ) +2. [E][ ]g2 vs sentinel(at: 10:00 PM ) +3. [E][ ]g2 vs sentinel(at: 10:00 PM Oct 10 2020) +____________________________________________________________ +____________________________________________________________ +☹ OOPS!!! No tasks with input word found. +____________________________________________________________ +____________________________________________________________ +Here are the tasks in your list: +1. [T][ ]watch et livestream +2. [E][ ]watch hankyuu livestream(at: midnight ) +3. [T][ ]watch haxxnini livestream +4. [D][ ]reach legend(by: this season ) +5. [D][ ]reach gold(by: 08:00 PM ) +6. [D][ ]reach silver(by: Oct 10 2020) +7. [D][ ]reach bronze(by: 08:00 PM Oct 10 2020) +8. [E][ ]g2 vs sentinel(at: 10pm ) +9. [E][ ]g2 vs sentinel(at: 10:00 PM ) +10. [E][ ]g2 vs sentinel(at: 10:00 PM Oct 10 2020) +____________________________________________________________ +____________________________________________________________ +Here are the tasks in your list: +1. [T][ ]watch et livestream +2. [T][ ]watch haxxnini livestream +____________________________________________________________ +____________________________________________________________ +Here are the tasks in your list: +1. [D][ ]reach legend(by: this season ) +2. [D][ ]reach gold(by: 08:00 PM ) +3. [D][ ]reach silver(by: Oct 10 2020) +4. [D][ ]reach bronze(by: 08:00 PM Oct 10 2020) +____________________________________________________________ +____________________________________________________________ +Here are the tasks in your list: +1. [E][ ]watch hankyuu livestream(at: midnight ) +2. [E][ ]g2 vs sentinel(at: 10pm ) +3. [E][ ]g2 vs sentinel(at: 10:00 PM ) +4. [E][ ]g2 vs sentinel(at: 10:00 PM Oct 10 2020) +____________________________________________________________ +____________________________________________________________ +Nice! I've marked this task as done: +[T][X]watch et livestream +[E][X]watch hankyuu livestream(at: midnight ) +[T][X]watch haxxnini livestream +Here are the tasks in your list: +1. [T][X]watch et livestream +2. [E][X]watch hankyuu livestream(at: midnight ) +3. [T][X]watch haxxnini livestream +4. [D][ ]reach legend(by: this season ) +5. [D][ ]reach gold(by: 08:00 PM ) +6. [D][ ]reach silver(by: Oct 10 2020) +7. [D][ ]reach bronze(by: 08:00 PM Oct 10 2020) +8. [E][ ]g2 vs sentinel(at: 10pm ) +9. [E][ ]g2 vs sentinel(at: 10:00 PM ) +10. [E][ ]g2 vs sentinel(at: 10:00 PM Oct 10 2020) +____________________________________________________________ +____________________________________________________________ +Noted. I've removed this task: +[E][X]watch hankyuu livestream(at: midnight ) +Now you have 9 tasks in the list. +Noted. I've removed this task: +[T][X]watch et1231 livestream +Now you have 8 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Here are the tasks in your list: +1. [T][X]watch haxxnini livestream +2. [D][ ]reach legend(by: this season ) +3. [D][ ]reach gold(by: 08:00 PM ) +4. [D][ ]reach silver(by: Oct 10 2020) +5. [D][ ]reach bronze(by: 08:00 PM Oct 10 2020) +6. [E][ ]g2 vs sentinel(at: 10pm ) +7. [E][ ]g2 vs sentinel(at: 10:00 PM ) +8. [E][ ]g2 vs sentinel(at: 10:00 PM Oct 10 2020) +____________________________________________________________ +____________________________________________________________ +☹ OOPS!!! Input cannot be empty. +____________________________________________________________ +____________________________________________________________ +☹ OOPS!!! I'm sorry, but I don't know what that means :-( +Defaulting to Echo. Type !help to see the list of Commands +random command +____________________________________________________________ +____________________________________________________________ +List of Commands: + echo - Repeat whatever was typed - !echo to repeat in art form + list - Display List - !list for details + todo - Add ToDo Task + event - Add Event Task - !event for details + deadline - Add Deadline Task - !deadline for details + clear - Clear list + find - Find Task With a specific word + date - Find Task with a specific date + bye - Shut Down +____________________________________________________________ +____________________________________________________________ +list displays all tasks +list todo displays all todo tasks +list event displays all event tasks +list deadline displays all deadline tasks +____________________________________________________________ +____________________________________________________________ +event command requires a timing indicated using "at" [timing] +[timing]: HH:MM YYYY-MM-DD +____________________________________________________________ +____________________________________________________________ +deadline command requires a end time indicated using "by"[end time] +[timing]: HH:MM YYYY-MM-DD +____________________________________________________________ +____________________________________________________________ +____________________________________________________________ +Bye. Hope to see you again soon! +_______________.___.___________ +\______ \__ | |\_ _____/ + | | _// | | | __)_ + | | \\____ | | \ + |________// ______|/_________/ \ No newline at end of file diff --git a/text-ui-test/EXPECTED.txt b/text-ui-test/EXPECTED.txt deleted file mode 100644 index 657e74f6e..000000000 --- a/text-ui-test/EXPECTED.txt +++ /dev/null @@ -1,7 +0,0 @@ -Hello from - ____ _ -| _ \ _ _| | _____ -| | | | | | | |/ / _ \ -| |_| | |_| | < __/ -|____/ \__,_|_|\_\___| - diff --git a/text-ui-test/EXPECTED.txt~merged b/text-ui-test/EXPECTED.txt~merged deleted file mode 100644 index b7ba62331..000000000 --- a/text-ui-test/EXPECTED.txt~merged +++ /dev/null @@ -1,273 +0,0 @@ - ____ _ -| _ \ _ _| | _____ -| | | | | | | |/ / _ \ -| |_| | |_| | < __/ -|____/ \__,_|_|\_\___| -____________________________________________________________ -Hello! I'm Duke -What can I do for you? -!help for Command List -____________________________________________________________ -____________________________________________________________ -hi -____________________________________________________________ -<<<<<<< HEAD -____________________________________________________________ -======= ->>>>>>> parent of 6845eab (no message) -HI - ___ ___ .___ - / | \ | | -/ ~ \| | -\ Y /| | - \___|___/ |___| -<<<<<<< HEAD -____________________________________________________________ -____________________________________________________________ - ☹ OOPS!!! List is empty. Add tasks to the list. -____________________________________________________________ -____________________________________________________________ -Got it. I've added this task: -[T][ ]watch et1231 livestream -Now you have 1 tasks in the list. -Got it. I've added this task: -[E][ ]watch hankyuu livestream(at: midnight ) -Now you have 2 tasks in the list. -____________________________________________________________ -======= - ____________________________________________________________ - Got it. I've added this task: - [T][ ]watch et1231 livestream - Now you have 1 tasks in the list. - ____________________________________________________________ - ____________________________________________________________ - Got it. I've added this task: - [T][ ]watch hankyuu livestream - Now you have 2 tasks in the list. - ____________________________________________________________ ->>>>>>> parent of 6845eab (no message) -____________________________________________________________ -Got it. I've added this task: -[T][ ]watch haxxnini livestream -Now you have 3 tasks in the list. -____________________________________________________________ -____________________________________________________________ -<<<<<<< HEAD -☹ OOPS!!! The due date of a deadline not detected, use [by] to indicated the date. -____________________________________________________________ -____________________________________________________________ -Got it. I've added this task: -[D][ ]reach legend(by: this season ) -======= -Got it. I've added this task: -[D][ ]reach radiant(by: this season) ->>>>>>> parent of 6845eab (no message) -Now you have 4 tasks in the list. -____________________________________________________________ -____________________________________________________________ -Got it. I've added this task: -<<<<<<< HEAD -[D][ ]reach gold(by: 08:00 PM ) -Now you have 5 tasks in the list. -____________________________________________________________ -____________________________________________________________ -Got it. I've added this task: -[D][ ]reach silver(by: Oct 10 2020) -Now you have 6 tasks in the list. -____________________________________________________________ -____________________________________________________________ -Got it. I've added this task: -[D][ ]reach bronze(by: 08:00 PM Oct 10 2020) -Now you have 7 tasks in the list. -____________________________________________________________ -____________________________________________________________ -Here are the tasks in your list: -1. [D][ ]reach silver(by: Oct 10 2020) -2. [D][ ]reach bronze(by: 08:00 AM Oct 10 2020) -____________________________________________________________ -____________________________________________________________ -☹ OOPS!!! The timing of the event not detected, use [at] to indicated the time. -____________________________________________________________ -____________________________________________________________ -Here are the tasks in your list: -1. [E][ ]g2 vs sentinel(at: 12am) -____________________________________________________________ -____________________________________________________________ -Got it. I've added this task: -[E][ ]g2 vs sentinel(at: 10pm ) -Now you have 8 tasks in the list. -____________________________________________________________ -____________________________________________________________ -Got it. I've added this task: -[E][ ]g2 vs sentinel(at: 10:00 PM ) -Now you have 9 tasks in the list. -____________________________________________________________ -____________________________________________________________ -Got it. I've added this task: -[E][ ]g2 vs sentinel(at: 10:00 PM Oct 10 2020) -Now you have 10 tasks in the list. -____________________________________________________________ -____________________________________________________________ -Here are the tasks in your list: -1. [T][ ]watch et1231 livestream -2. [E][ ]watch hankyuu livestream(at: midnight ) -3. [T][ ]watch haxxnini livestream -4. [D][ ]reach legend(by: this season ) -5. [D][ ]reach gold(by: 08:00 AM ) -6. [D][ ]reach silver(by: Oct 10 2020) -7. [D][ ]reach bronze(by: 08:00 AM Oct 10 2020) -8. [E][ ]g2 vs sentinel(at: 10pm ) -9. [E][ ]g2 vs sentinel(at: 10:00 PM ) -10. [E][ ]g2 vs sentinel(at: 10:00 PM Oct 10 2020) -____________________________________________________________ -____________________________________________________________ -Here are the tasks in your list: -1. [T][ ]watch et1231 livestream -2. [T][ ]watch haxxnini livestream -____________________________________________________________ -____________________________________________________________ -Here are the tasks in your list: -1. [D][ ]reach legend(by: this season ) -2. [D][ ]reach gold(by: 08:00 AM ) -3. [D][ ]reach silver(by: Oct 10 2020) -4. [D][ ]reach bronze(by: 08:00 AM Oct 10 2020) -____________________________________________________________ -____________________________________________________________ -Here are the tasks in your list: -1. [E][ ]watch hankyuu livestream(at: midnight ) -2. [E][ ]g2 vs sentinel(at: 10pm ) -3. [E][ ]g2 vs sentinel(at: 10:00 PM ) -4. [E][ ]g2 vs sentinel(at: 10:00 PM Oct 10 2020) -____________________________________________________________ -======= -[E][ ]g2 vs sentinel(at:12am) -Now you have 5 tasks in the list. -____________________________________________________________ -____________________________________________________________ -Here are the tasks in your list: -1. [T][ ]watch et1231 livestream -2. [T][ ]watch hankyuu livestream -3. [T][ ]watch haxxnini livestream -4. [D][ ]reach radiant(by: this season) -5. [E][ ]g2 vs sentinel(at:12am) ->>>>>>> parent of 6845eab (no message) -____________________________________________________________ -____________________________________________________________ -Nice! I've marked this task as done: -[T][X]watch et1231 livestream -<<<<<<< HEAD -[E][X]watch hankyuu livestream(at: midnight ) -[T][X]watch haxxnini livestream -Here are the tasks in your list: -1. [T][X]watch et1231 livestream -2. [E][X]watch hankyuu livestream(at: midnight ) -3. [T][X]watch haxxnini livestream -4. [D][ ]reach legend(by: this season ) -5. [D][ ]reach gold(by: 08:00 AM ) -6. [D][ ]reach silver(by: Oct 10 2020) -7. [D][ ]reach bronze(by: 08:00 AM Oct 10 2020) -8. [E][ ]g2 vs sentinel(at: 10pm ) -9. [E][ ]g2 vs sentinel(at: 10:00 PM ) -10. [E][ ]g2 vs sentinel(at: 10:00 PM Oct 10 2020) -____________________________________________________________ -____________________________________________________________ -Noted. I've removed this task: -[E][X]watch hankyuu livestream(at: midnight ) -Now you have 9 tasks in the list. -Noted. I've removed this task: -[T][X]watch et1231 livestream -Now you have 8 tasks in the list. -____________________________________________________________ -____________________________________________________________ -Here are the tasks in your list: -1. [T][X]watch haxxnini livestream -2. [D][ ]reach legend(by: this season ) -3. [D][ ]reach gold(by: 08:00 AM ) -4. [D][ ]reach silver(by: Oct 10 2020) -5. [D][ ]reach bronze(by: 08:00 AM Oct 10 2020) -6. [E][ ]g2 vs sentinel(at: 10pm ) -7. [E][ ]g2 vs sentinel(at: 10:00 AM ) -8. [E][ ]g2 vs sentinel(at: 10:00 AM Oct 10 2020) -____________________________________________________________ -____________________________________________________________ -☹ OOPS!!! I'm sorry, but I don't know what that means :-( -Defaulting to Echo. Type !help to see the list of Commands - -======= -[T][X]watch hankyuu livestream -[D][X]reach radiant(by: this season) -____________________________________________________________ -Here are the tasks in your list: -1. [T][X]watch et1231 livestream -2. [T][X]watch hankyuu livestream -3. [T][ ]watch haxxnini livestream -4. [D][X]reach radiant(by: this season) -5. [E][ ]g2 vs sentinel(at:12am) -____________________________________________________________ -____________________________________________________________ -Noted. I've removed this task: -[T][X]watch et1231 livestream -Now you have 4 tasks in the list. -____________________________________________________________ -____________________________________________________________ -Here are the tasks in your list: -1. [T][X]watch hankyuu livestream -2. [T][ ]watch haxxnini livestream -3. [D][X]reach radiant(by: this season) -4. [E][ ]g2 vs sentinel(at:12am) -____________________________________________________________ -☹ OOPS!!! I'm sorry, but I don't know what that means :-( -Defaulting to Echo. Type !help to see the list of Commands -____________________________________________________________ ->>>>>>> parent of 6845eab (no message) -random command -____________________________________________________________ -____________________________________________________________ -List of Commands: - echo - Repeat whatever was typed - !echo to repeat in art form - list - Display List - !list for details - todo - Add ToDo Task - event - Add Event Task - !event for details - deadline - Add Deadline Task - !deadline for details - bye - Shut Down -<<<<<<< HEAD - -======= ->>>>>>> parent of 6845eab (no message) -____________________________________________________________ -____________________________________________________________ -list displays all tasks -list todo displays all todo tasks -list event displays all event tasks -list deadline displays all deadline tasks -<<<<<<< HEAD - -____________________________________________________________ -____________________________________________________________ -event command requires a timing indicated using "at" [timing] - -____________________________________________________________ -____________________________________________________________ -deadline command requires a end time indicated using "by"[end time] - -____________________________________________________________ -____________________________________________________________ -____________________________________________________________ -Bye. Hope to see you again soon! -======= -____________________________________________________________ -____________________________________________________________ -event command requires a timing indicated using "at" [timing] -____________________________________________________________ -____________________________________________________________ -deadline command requires a end time indicated using "by"[end time] -____________________________________________________________ -____________________________________________________________ -Bye. Hope to see you again soon! -____________________________________________________________ ->>>>>>> parent of 6845eab (no message) -_______________.___.___________ -\______ \__ | |\_ _____/ - | | _// | | | __)_ - | | \\____ | | \ - |________// ______|/_________/ \ No newline at end of file diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index 3d85b04d7..1e1ed6d4a 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -1,7 +1,10 @@ echo Hi !echo hi list -todo watch et1231 livestream event watch hankyuu livestream at midnight +clear +find hi +date 2020-10-10 +todo watch et livestream event watch hankyuu livestream at midnight todo watch haxxnini livestream deadline reach radiant deadline reach legend by this season @@ -9,10 +12,13 @@ deadline reach gold by 20:00 deadline reach silver by 2020-10-10 deadline reach bronze by 20:00 2020-10-10 date 2020-10-10 +date 2020\10\10 event G2 vs Sentinel event G2 vs Sentinel at 10pm event G2 vs Sentinel at 22:00 event G2 vs Sentinel at 22:00 2020-10-10 +find G2 +find hi list list todo list deadline @@ -20,7 +26,10 @@ list event done 1,2,3 delete 1,2 list + random command +clear +list !help !list !event From 21ea13810ec89b21b573d0ee4235d0daa2a26a8d Mon Sep 17 00:00:00 2001 From: wingho2 Date: Wed, 29 Sep 2021 18:30:17 +0800 Subject: [PATCH 45/62] Fix a bug that invalid date keep throwing parsing error --- data/duke.txt | 0 duke.txt | 4 ++-- src/main/java/duke/Duke.java | 2 +- src/main/java/duke/ErrorHandling/ErrorStaticString.java | 2 +- src/main/java/duke/task/Deadline.java | 8 +++++++- src/main/java/duke/task/Event.java | 8 +++++++- 6 files changed, 18 insertions(+), 6 deletions(-) delete mode 100644 data/duke.txt diff --git a/data/duke.txt b/data/duke.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/duke.txt b/duke.txt index 1ccf53062..e34584291 100644 --- a/duke.txt +++ b/duke.txt @@ -1,7 +1,7 @@ -[D];[ ];reach legend;this season +[D];[ ];reach legend;this season [D];[ ];reach gold;08:00 [D];[ ];reach silver; 2020-10-10 [D];[ ];reach bronze;08:00 2020-10-10 -[E];[ ];g2 vs sentinel;10pm +[E];[ ];g2 vs sentinel;10pm [E];[ ];g2 vs sentinel;10:00 [E];[ ];g2 vs sentinel;10:00 2020-10-10 diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index c66b6072c..3949b76ff 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -29,7 +29,7 @@ public Duke(){ * Main function of Duke * Integrate Ui class that handles taking in input of user with * Parser class that handles response of input - * Loop until system is terminated + * Loop\ until system is terminated */ public void run(){ ui.Greetings(); diff --git a/src/main/java/duke/ErrorHandling/ErrorStaticString.java b/src/main/java/duke/ErrorHandling/ErrorStaticString.java index d51528df6..6c408eddb 100644 --- a/src/main/java/duke/ErrorHandling/ErrorStaticString.java +++ b/src/main/java/duke/ErrorHandling/ErrorStaticString.java @@ -40,7 +40,7 @@ public class ErrorStaticString { public static final String ERROR_FILE_MESSAGE_CLEARING = "☹ OOPS!!! Something went wrong with clearing contents of the files"; public static final String ERROR_DATE_TIME_PARSE = "☹ OOPS!!! Something went wrong with reading date or time\n" + - "Format of Date: YYYY-MM-DD\n" + "Format of Time: HH:MM"; + "Input will be read in as String\n" + "Format of Date: YYYY-MM-DD\n" + "Format of Time: HH:MM"; public static final String ERROR_EMPTY_DATE_INPUT = "☹ OOPS!!! Date Searched cannot be Empty."; public static final String ERROR_EMPTY_WORD_INPUT = "☹ OOPS!!! Word Searched cannot be Empty."; } diff --git a/src/main/java/duke/task/Deadline.java b/src/main/java/duke/task/Deadline.java index 59ee52560..db1b1baa2 100644 --- a/src/main/java/duke/task/Deadline.java +++ b/src/main/java/duke/task/Deadline.java @@ -13,8 +13,12 @@ */ public class Deadline extends Task{ + private static final String DATE_SEPARATOR = "-"; + private static final String DATE_SEPARATOR_NEW = "/"; + private static final String TIME_SEPARATOR = ":"; + private static final String TIME_SEPARATOR_NEW = "."; private static final String TASK_SYMBOL = "[D]"; - private final String deadlineDateTime; + private String deadlineDateTime; /** * Constructor for DeadLine Task @@ -105,6 +109,7 @@ public String getDate(String date, boolean isForFile) { return parseDate.format(DateTimeFormatter.ofPattern("MMM dd yyyy")); }catch (DateTimeParseException e){ System.out.println(ErrorStaticString.ERROR_DATE_TIME_PARSE); + deadlineDateTime = deadlineDateTime.replaceAll(DATE_SEPARATOR,DATE_SEPARATOR_NEW); } } return EMPTY_STRING; @@ -127,6 +132,7 @@ private String getTime(String time, boolean isForFile) { return parseTime.format(DateTimeFormatter.ofPattern("hh:mm a")); }catch (DateTimeParseException e){ System.out.println(ErrorStaticString.ERROR_DATE_TIME_PARSE); + deadlineDateTime = deadlineDateTime.replaceAll(TIME_SEPARATOR,TIME_SEPARATOR_NEW); } } if(getDate(convertStringToDate(),false).equals(EMPTY_STRING)) { diff --git a/src/main/java/duke/task/Event.java b/src/main/java/duke/task/Event.java index 73a1958dc..2926ac4ba 100644 --- a/src/main/java/duke/task/Event.java +++ b/src/main/java/duke/task/Event.java @@ -13,8 +13,12 @@ */ public class Event extends Task{ + private static final String DATE_SEPARATOR = "-"; + private static final String DATE_SEPARATOR_NEW = "/"; + private static final String TIME_SEPARATOR = ":"; + private static final String TIME_SEPARATOR_NEW = "."; private static final String TASK_SYMBOL = "[E]"; - private final String eventDateTime; + private String eventDateTime; /** * Constructor for Event Task @@ -105,6 +109,7 @@ public String getDate(String date, boolean isForFile) { return parseDate.format(DateTimeFormatter.ofPattern("MMM dd yyyy")); }catch (DateTimeParseException e){ System.out.println(ErrorStaticString.ERROR_DATE_TIME_PARSE); + eventDateTime = eventDateTime.replaceAll(DATE_SEPARATOR,DATE_SEPARATOR_NEW); } } return EMPTY_STRING; @@ -127,6 +132,7 @@ private String getTime(String time, boolean isForFile) { return parseTime.format(DateTimeFormatter.ofPattern("hh:mm a")); }catch (DateTimeParseException e){ System.out.println(ErrorStaticString.ERROR_DATE_TIME_PARSE); + eventDateTime = eventDateTime.replaceAll(TIME_SEPARATOR,TIME_SEPARATOR_NEW); } } if(getDate(convertStringToDate(),false).equals(EMPTY_STRING)) { From 19b892c1d6aecf97b06ddd7bbc864f9c45541f30 Mon Sep 17 00:00:00 2001 From: kum-wh <69519728+kum-wh@users.noreply.github.com> Date: Thu, 30 Sep 2021 03:11:35 +0800 Subject: [PATCH 46/62] Update README.md --- docs/README.md | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/docs/README.md b/docs/README.md index 8077118eb..4bd135a8d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,29 +1,33 @@ -# User Guide +# Duke User Guide -## Features +## Quick Start -### Feature-ABC +## Command List -Description of the feature. +## Notes -### Feature-XYZ +## Features -Description of the feature. +### Adding a ToDo Task -## Usage +### Adding a DeadLine Task -### `Keyword` - Describe action +### Adding a Event Task -Describe the action and its outcome. +### Delete a Task -Example of usage: +### Delete all Task -`keyword (optional arguments)` +### View Tasks -Expected outcome: +#### Viewing Todo Tasks -Description of the outcome. +#### Viewing DeadLine Tasks -``` -expected output -``` +#### Viewing Event Tasks + +### Finding Task By KeyWords + +### Finding Task By Date + +### Exit Program From 8e97fa8c316625e5c13a6d25dee33ba11951e671 Mon Sep 17 00:00:00 2001 From: kum-wh <69519728+kum-wh@users.noreply.github.com> Date: Thu, 30 Sep 2021 03:13:15 +0800 Subject: [PATCH 47/62] Set theme jekyll-theme-cayman --- docs/_config.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/_config.yml diff --git a/docs/_config.yml b/docs/_config.yml new file mode 100644 index 000000000..c4192631f --- /dev/null +++ b/docs/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-cayman \ No newline at end of file From 41d7353a4b65c2a8530f80659f33956c1b9d70d4 Mon Sep 17 00:00:00 2001 From: kum-wh <69519728+kum-wh@users.noreply.github.com> Date: Thu, 30 Sep 2021 03:26:31 +0800 Subject: [PATCH 48/62] Update README.md --- docs/README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 4bd135a8d..7a463e263 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,7 +1,11 @@ # Duke User Guide +Duke is a Command Line Interface program that let users keep track of their tasks. ## Quick Start - +1.Ensure Java '''11''' is installed. +2.Download [IP.jar](https://github.com/kum-wh/ip/releases). +3.Go to file path in terminal. +4.Enter java -jar IP.jar to run Duke. ## Command List ## Notes From 5d3bffc34c05704f4a2f4a7af39bbb6af2a2cc23 Mon Sep 17 00:00:00 2001 From: kum-wh <69519728+kum-wh@users.noreply.github.com> Date: Thu, 30 Sep 2021 03:27:00 +0800 Subject: [PATCH 49/62] Create README.md From 43397455b861675a8d216b31e7989eb0b65327d5 Mon Sep 17 00:00:00 2001 From: kum-wh <69519728+kum-wh@users.noreply.github.com> Date: Thu, 30 Sep 2021 03:30:16 +0800 Subject: [PATCH 50/62] Update README.md --- docs/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/README.md b/docs/README.md index 7a463e263..11619afce 100644 --- a/docs/README.md +++ b/docs/README.md @@ -3,9 +3,13 @@ Duke is a Command Line Interface program that let users keep track of their task ## Quick Start 1.Ensure Java '''11''' is installed. + 2.Download [IP.jar](https://github.com/kum-wh/ip/releases). + 3.Go to file path in terminal. + 4.Enter java -jar IP.jar to run Duke. + ## Command List ## Notes From 7576a856d64222c6928e3841327b5a11fffe1f78 Mon Sep 17 00:00:00 2001 From: kum-wh <69519728+kum-wh@users.noreply.github.com> Date: Thu, 30 Sep 2021 03:42:49 +0800 Subject: [PATCH 51/62] Update README.md --- docs/README.md | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/docs/README.md b/docs/README.md index 11619afce..52f19e84e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2,16 +2,25 @@ Duke is a Command Line Interface program that let users keep track of their tasks. ## Quick Start -1.Ensure Java '''11''' is installed. - -2.Download [IP.jar](https://github.com/kum-wh/ip/releases). - -3.Go to file path in terminal. - -4.Enter java -jar IP.jar to run Duke. - +1. Ensure Java `11` is installed. +2. Download [IP.jar](https://github.com/kum-wh/ip/releases). +3. Navigate to file path in terminal. +4. To launch **Duke**, enter `java -jar IP.jar`. ## Command List +Command | Use +------- | --- +ToDo | Add **ToDo** Task +Deadline | Add **Deadline** Task +Event | Add **Event** Task +Done | Set a Task as completed +Delete | Remove a Task +List | View Task +Find | Find a Task with **Keyword** +Date | Find a Task with a specific **Date** +Echo | Repeat Input +Bye | Exit Program + ## Notes ## Features From 3f424fcbf534e4a7e086a17486230ce27594d30f Mon Sep 17 00:00:00 2001 From: kum-wh <69519728+kum-wh@users.noreply.github.com> Date: Thu, 30 Sep 2021 03:53:59 +0800 Subject: [PATCH 52/62] Update README.md --- docs/README.md | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/docs/README.md b/docs/README.md index 52f19e84e..1947bb5c2 100644 --- a/docs/README.md +++ b/docs/README.md @@ -10,23 +10,29 @@ Duke is a Command Line Interface program that let users keep track of their task Command | Use ------- | --- -ToDo | Add **ToDo** Task -Deadline | Add **Deadline** Task -Event | Add **Event** Task -Done | Set a Task as completed -Delete | Remove a Task -List | View Task -Find | Find a Task with **Keyword** -Date | Find a Task with a specific **Date** -Echo | Repeat Input -Bye | Exit Program +`ToDo` | Add **ToDo** Task +`Deadline` | Add **Deadline** Task +`Event` | Add **Event** Task +`Done` | Set a Task as completed +`Delete` | Remove a Task +`List` | View Task +`Find` | Find a Task with **Keyword** +`Date` | Find a Task with a specific **Date** +`Echo` | Repeat Input +`Bye` | Exit Program ## Notes ## Features ### Adding a ToDo Task +Add a ToDo Task to your list of tasks. +ToDo Task are tasks without specific dates and times +For tasks that can be completed anytime. +Command: `todo TASK_DESCRIPTION` + +Examples: ### Adding a DeadLine Task ### Adding a Event Task From 5cbdada075d383d76587124ba271979c1369c29b Mon Sep 17 00:00:00 2001 From: kum-wh <69519728+kum-wh@users.noreply.github.com> Date: Thu, 30 Sep 2021 09:39:38 +0800 Subject: [PATCH 53/62] Update README.md --- docs/README.md | 57 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 9 deletions(-) diff --git a/docs/README.md b/docs/README.md index 1947bb5c2..4e507eea7 100644 --- a/docs/README.md +++ b/docs/README.md @@ -18,39 +18,78 @@ Command | Use `List` | View Task `Find` | Find a Task with **Keyword** `Date` | Find a Task with a specific **Date** -`Echo` | Repeat Input `Bye` | Exit Program +`Echo` | Repeat Input +`!Echo` | Repeat Input in Grafiti ASCII Art +`!help` | View commands functions +`!list` | View list commands description +`!event` | View event commands description +`!deadline` | View deadline commands description ## Notes ## Features -### Adding a ToDo Task -Add a ToDo Task to your list of tasks. -ToDo Task are tasks without specific dates and times -For tasks that can be completed anytime. +### Adding a Task + +#### Adding a ToDo Task + +Command Format: `todo TASK_DESCRIPTION` -Command: `todo TASK_DESCRIPTION` +#### Adding a DeadLine Task -Examples: -### Adding a DeadLine Task +Command Format | Command +-------------- | ------- +Without Date and Time | `deadline TASK_DESCRIPTION at duedate` +Without Date | `deadline TASK_DESCRIPTION at HH:MM +Without Time | `deadline TASK_DESCRIPTION at yyyy-mm-dd +With Date and Time | `deadline TASK_DESCCRIPTION at HH:MM yyyy-mm-dd -### Adding a Event Task +#### Adding a Event Task + +Command Format | Command +-------------- | ------- +Without Date and Time | `event TASK_DESCRIPTION at event timing` +Without Date | `event TASK_DESCRIPTION at HH:MM +Without Time | `event TASK_DESCRIPTION at yyyy-mm-dd +With Date and Time | `event TASK_DESCCRIPTION at HH:MM yyyy-mm-dd + +### Setting a task as complete + +Command Format: `done TASK_INDEX` ### Delete a Task +Command Format: `delete TASK_INDEX` + ### Delete all Task +Command Format: `clear` + ### View Tasks +Command Format: `list` + #### Viewing Todo Tasks +Command Format: `list todo` + #### Viewing DeadLine Tasks +Command Format: `list deadline` + #### Viewing Event Tasks +Command Format: `list event` + ### Finding Task By KeyWords +Command Format: `find KEYWORD` + ### Finding Task By Date +Command Format: `date yyyy-mm-dd` + ### Exit Program + +Command Format: `bye` From 0ec1b611f9de042c3041f6da162d6d46dff1a00e Mon Sep 17 00:00:00 2001 From: kum-wh <69519728+kum-wh@users.noreply.github.com> Date: Thu, 30 Sep 2021 10:06:45 +0800 Subject: [PATCH 54/62] Update README.md --- docs/README.md | 176 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 164 insertions(+), 12 deletions(-) diff --git a/docs/README.md b/docs/README.md index 4e507eea7..d7b1cdcb0 100644 --- a/docs/README.md +++ b/docs/README.md @@ -13,7 +13,7 @@ Command | Use `ToDo` | Add **ToDo** Task `Deadline` | Add **Deadline** Task `Event` | Add **Event** Task -`Done` | Set a Task as completed +`Done` | Set a Task as **completed** `Delete` | Remove a Task `List` | View Task `Find` | Find a Task with **Keyword** @@ -22,74 +22,226 @@ Command | Use `Echo` | Repeat Input `!Echo` | Repeat Input in Grafiti ASCII Art `!help` | View commands functions -`!list` | View list commands description -`!event` | View event commands description -`!deadline` | View deadline commands description +`!list` | View **list** commands description +`!event` | View **event** commands description +`!deadline` | View **deadline** commands description ## Notes +TASK_DESCRIPTION TASK_DEADLINE TASK_TIMING TASK_INDEX KEYWORD HH:MM yyyy-mm-dd + ## Features ### Adding a Task #### Adding a ToDo Task +Add a task without any specific dates to list. + Command Format: `todo TASK_DESCRIPTION` +Demo: + +``` +todo +``` + #### Adding a DeadLine Task +Add a task with a deadline to list. + Command Format | Command -------------- | ------- -Without Date and Time | `deadline TASK_DESCRIPTION at duedate` -Without Date | `deadline TASK_DESCRIPTION at HH:MM -Without Time | `deadline TASK_DESCRIPTION at yyyy-mm-dd -With Date and Time | `deadline TASK_DESCCRIPTION at HH:MM yyyy-mm-dd +Without Date and Time | `deadline TASK_DESCRIPTION at TASK_DEADLINE` +Without Date | `deadline TASK_DESCRIPTION at HH:MM` +Without Time | `deadline TASK_DESCRIPTION at yyyy-mm-dd` +With Date and Time | `deadline TASK_DESCCRIPTION at HH:MM yyyy-mm-dd` + +Demo: + +``` +deadline +``` #### Adding a Event Task +Add a task occuring at a specific date and time to list. + Command Format | Command -------------- | ------- -Without Date and Time | `event TASK_DESCRIPTION at event timing` -Without Date | `event TASK_DESCRIPTION at HH:MM -Without Time | `event TASK_DESCRIPTION at yyyy-mm-dd -With Date and Time | `event TASK_DESCCRIPTION at HH:MM yyyy-mm-dd +Without Date and Time | `event TASK_DESCRIPTION at TASK_TIMING` +Without Date | `event TASK_DESCRIPTION at HH:MM` +Without Time | `event TASK_DESCRIPTION at yyyy-mm-dd` +With Date and Time | `event TASK_DESCCRIPTION at HH:MM yyyy-mm-dd` + +Demo: + +``` +event +``` ### Setting a task as complete Command Format: `done TASK_INDEX` +Demo: + +``` +done +``` + ### Delete a Task +Delete a task from list + Command Format: `delete TASK_INDEX` +Demo: + +``` +delete +``` + ### Delete all Task +Delete all tasks from list. + Command Format: `clear` +Demo: + +``` +clear + +____________________________________________________________ +List Cleared. All tasks removed. +____________________________________________________________ +``` + ### View Tasks +List all task in list. + Command Format: `list` +Demo: + +``` +list +``` + #### Viewing Todo Tasks +List all ToDo task in list + Command Format: `list todo` +Demo: + +``` +list todo +``` + #### Viewing DeadLine Tasks +List all Deadline task in list. + Command Format: `list deadline` +Demo: + +``` +list deadline +``` + #### Viewing Event Tasks +List all Event task in list. + Command Format: `list event` +Demo: + +``` +list event +``` + ### Finding Task By KeyWords +List all tasks with a specific keyword in its description in list. + Command Format: `find KEYWORD` +Demo: + +``` +find +``` + ### Finding Task By Date +List all tasks with a specific date in list. + Command Format: `date yyyy-mm-dd` +Demo: + +``` +date +``` + +### Echo User Input + +Print user input on terminal + +Command Format: `echo INPUT` + +Demo: + +``` +echo +``` + +### Command Guide + +Command Format: `!help` + +Demo: + +``` +!help + +____________________________________________________________ +List of Commands: + echo - Repeat whatever was typed - !echo to repeat in art form + list - Display List - !list for details + todo - Add ToDo Task + event - Add Event Task - !event for details + deadline - Add Deadline Task - !deadline for details + clear - Clear list + find - Find Task With a specific word + date - Find Task with a specific date + bye - Shut Down +____________________________________________________________ +``` + ### Exit Program +Exits program. + Command Format: `bye` + +Demo: + +``` +bye + +____________________________________________________________ +____________________________________________________________ +Bye. Hope to see you again soon! +_______________.___.___________ +\______ \__ | |\_ _____/ + | | _// | | | __)_ + | | \\____ | | \ + |________// ______|/_________/ +``` From 28c7be49d66346bf0af3566da69418e0d4d1df5f Mon Sep 17 00:00:00 2001 From: kum-wh <69519728+kum-wh@users.noreply.github.com> Date: Thu, 30 Sep 2021 10:53:56 +0800 Subject: [PATCH 55/62] Update README.md --- docs/README.md | 137 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 113 insertions(+), 24 deletions(-) diff --git a/docs/README.md b/docs/README.md index d7b1cdcb0..5744a1d93 100644 --- a/docs/README.md +++ b/docs/README.md @@ -28,62 +28,132 @@ Command | Use ## Notes -TASK_DESCRIPTION TASK_DEADLINE TASK_TIMING TASK_INDEX KEYWORD HH:MM yyyy-mm-dd +* Words in `UPPER_CASE` are parameters to be entered by user +* Program is **not** case sensitive. +* TASK_DESCRIPTION represent description of a task. +* TASK_DEADLINE represent date of a task either in words or DATE and TIME format. +* TASK_TIMING represent timing of a task either in words or DATE and TIME format. +* TASK_INDEX represent index number of a task. Index number can be viewed by viewing the whole list. +* KEYWORD represent word input by user. +* TIME represents date input by user in `HH:MM` format. + * HH represents hours. + * MM represents minutes. +* DATE represents date input by user in `yyyy-mm-dd` fomat. + * yyyy represents year. + * mm represents months. + * dd represents days. +* Tasks are represented as `TASK_TYPE`,`STATUS`,`TASK_DESCRIPTION`,`TASK_DATE`. + * `TASK_TYPE` is `T` for ToDo, `D` for Deadline and `E` for Event. + * `STATUS` is `X` if completed. + * `TASK_DATE` is TASK_DEADLINE for Deadline and TASK_TIMING for Event. ## Features ### Adding a Task +Multiple tasks can be added in one line. + #### Adding a ToDo Task -Add a task without any specific dates to list. +Adds a task without any specific dates to list. Command Format: `todo TASK_DESCRIPTION` +* TASK_DESCRIPTION cannot be empty. + +Examples: +* todo watch twitch videos +* todo watch youtube videos + Demo: ``` -todo +todo watch twitch videos todo watch youtube videos + +____________________________________________________________ +Got it. I've added this task: +[T][ ]watch twitch videos +Now you have 1 tasks in the list. +Got it. I've added this task: +[T][ ]watch youtube videos +Now you have 2 tasks in the list. +____________________________________________________________ ``` #### Adding a DeadLine Task -Add a task with a deadline to list. +Adds a task with a duedate as deadline to list. Command Format | Command -------------- | ------- -Without Date and Time | `deadline TASK_DESCRIPTION at TASK_DEADLINE` -Without Date | `deadline TASK_DESCRIPTION at HH:MM` -Without Time | `deadline TASK_DESCRIPTION at yyyy-mm-dd` -With Date and Time | `deadline TASK_DESCCRIPTION at HH:MM yyyy-mm-dd` +Without Date and Time | `deadline TASK_DESCRIPTION by TASK_DEADLINE` +Without Date | `deadline TASK_DESCRIPTION by TIME` +Without Time | `deadline TASK_DESCRIPTION by DATE` +With Date and Time | `deadline TASK_DESCCRIPTION by TIME DATE` + +* TASK_DESCRIPTION and TASK_DEADLINE cannot be empty. +* Word "by " is required in input to indicated TASK_DEADLINE. +* No specific ordering of time and date as long as input pattern is followed. Demo: ``` -deadline +deadline homework1 by 23:59 deadline homework2 by 2020-10-10 deadline homework3 by 20:00 2021-10-20 + +____________________________________________________________ +Got it. I've added this task: +[D][ ]homework1(by: 11:59 PM ) +Now you have 3 tasks in the list. +Got it. I've added this task: +[D][ ]homework2(by: Oct 10 2020) +Now you have 4 tasks in the list. +Got it. I've added this task: +[D][ ]homework3(by: 08:00 PM Oct 20 2021) +Now you have 5 tasks in the list. +____________________________________________________________ ``` #### Adding a Event Task -Add a task occuring at a specific date and time to list. +Adds a task occuring at a specific date and time as event to list. Command Format | Command -------------- | ------- Without Date and Time | `event TASK_DESCRIPTION at TASK_TIMING` -Without Date | `event TASK_DESCRIPTION at HH:MM` -Without Time | `event TASK_DESCRIPTION at yyyy-mm-dd` -With Date and Time | `event TASK_DESCCRIPTION at HH:MM yyyy-mm-dd` +Without Date | `event TASK_DESCRIPTION at TIME` +Without Time | `event TASK_DESCRIPTION at DATE` +With Date and Time | `event TASK_DESCCRIPTION at TIME DATE` + +* TASK_DESCRIPTION and TASK_TIMING cannot be empty. +* Word "at " is required in input to indicated TASK_DEADLINE. +* No specific ordering of time and date as long as input pattern is followed. Demo: ``` -event +event g2 vs SEN at 21:00 event 100T vs Gambit at 2021-08-01 event paperex vs Bren at 2021-08-01 08:00 + +____________________________________________________________ +Got it. I've added this task: +[E][ ]g2 vs en(at: 09:00 PM ) +Now you have 6 tasks in the list. +Got it. I've added this task: +[E][ ]100t vs gambit(at: Aug 01 2021) +Now you have 7 tasks in the list. +Got it. I've added this task: +[E][ ]paperex vs bren(at: 08:00 AM Aug 01 2021) +Now you have 8 tasks in the list. +____________________________________________________________ ``` ### Setting a task as complete +Sets a task in list as done. + Command Format: `done TASK_INDEX` +* INDEX + Demo: ``` @@ -92,7 +162,7 @@ done ### Delete a Task -Delete a task from list +Deletes a task from list Command Format: `delete TASK_INDEX` @@ -104,7 +174,7 @@ delete ### Delete all Task -Delete all tasks from list. +Deletes all tasks from list. Command Format: `clear` @@ -120,7 +190,7 @@ ____________________________________________________________ ### View Tasks -List all task in list. +Lists all task in list. Command Format: `list` @@ -132,7 +202,7 @@ list #### Viewing Todo Tasks -List all ToDo task in list +Lists all ToDo task in list Command Format: `list todo` @@ -144,7 +214,7 @@ list todo #### Viewing DeadLine Tasks -List all Deadline task in list. +Lists all Deadline task in list. Command Format: `list deadline` @@ -156,7 +226,7 @@ list deadline #### Viewing Event Tasks -List all Event task in list. +Lists all Event task in list. Command Format: `list event` @@ -168,7 +238,7 @@ list event ### Finding Task By KeyWords -List all tasks with a specific keyword in its description in list. +Lists all tasks with a specific keyword in its description in list. Command Format: `find KEYWORD` @@ -180,7 +250,7 @@ find ### Finding Task By Date -List all tasks with a specific date in list. +Lists all tasks with a specific date in list. Command Format: `date yyyy-mm-dd` @@ -192,14 +262,33 @@ date ### Echo User Input -Print user input on terminal +Prints user input on terminal Command Format: `echo INPUT` +Draws user input on terminial. + +Command Format: `!echo INPUT` + Demo: ``` -echo +echo hi + +____________________________________________________________ +hi +____________________________________________________________ + +!echo hi + +____________________________________________________________ +HI + ___ ___ .___ + / | \ | | +/ ~ \| | +\ Y /| | + \___|___/ |___| +____________________________________________________________ ``` ### Command Guide From e4d14a7a84c509db0bba20322045da3b66679899 Mon Sep 17 00:00:00 2001 From: kum-wh <69519728+kum-wh@users.noreply.github.com> Date: Thu, 30 Sep 2021 11:19:38 +0800 Subject: [PATCH 56/62] Update README.md --- docs/README.md | 147 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 135 insertions(+), 12 deletions(-) diff --git a/docs/README.md b/docs/README.md index 5744a1d93..55b37a911 100644 --- a/docs/README.md +++ b/docs/README.md @@ -113,6 +113,19 @@ Now you have 5 tasks in the list. ____________________________________________________________ ``` +View details on adding Deadline task in program. + +Command Format: `!deadline` + +Demo: + +``` +____________________________________________________________ +deadline command requires a end time indicated using "by"[end time] +[timing]: HH:MM YYYY-MM-DD +____________________________________________________________ +``` + #### Adding a Event Task Adds a task occuring at a specific date and time as event to list. @@ -145,31 +158,77 @@ Got it. I've added this task: Now you have 8 tasks in the list. ____________________________________________________________ ``` +View details on adding Event task in program. + +Command Format: `!event` + +Demo: + +``` +____________________________________________________________ +event command requires a timing indicated using "at" [timing] +[timing]: HH:MM YYYY-MM-DD +____________________________________________________________ +``` ### Setting a task as complete -Sets a task in list as done. +Sets tasks in list as done. Command Format: `done TASK_INDEX` -* INDEX +* TASK_INDEX cannot be empty. +* TASK_INDEX must be a integer. +* Use "," to seperate multiple tasks. Demo: ``` -done +done 1,2,3 + +____________________________________________________________ +Nice! I've marked this task as done: +[T][X]watch twitch videos +[T][X]watch youtube videos +[D][X]homework1(by: 11:59 PM ) +Here are the tasks in your list: +1. [T][X]watch twitch videos +2. [T][X]watch youtube videos +3. [D][X]homework1(by: 11:59 PM ) +4. [D][ ]homework2(by: Oct 10 2020) +5. [D][ ]homework3(by: 08:00 PM Oct 20 2021) +6. [E][ ]g2 vs en(at: 09:00 PM ) +7. [E][ ]100t vs gambit(at: Aug 01 2021) +8. [E][ ]paperex vs bren(at: 08:00 AM Aug 01 2021) +____________________________________________________________ ``` ### Delete a Task -Deletes a task from list +Deletes tasks from list Command Format: `delete TASK_INDEX` +* TASK_INDEX cannot be empty. +* TASK_INDEX must be a integer. +* Use "," to seperate multiple tasks. + Demo: ``` -delete +delete 2,4,5 + +____________________________________________________________ +Noted. I've removed this task: +[D][ ]homework3(by: 08:00 PM Oct 20 2021) +Now you have 7 tasks in the list. +Noted. I've removed this task: +[D][ ]homework2(by: Oct 10 2020) +Now you have 6 tasks in the list. +Noted. I've removed this task: +[T][X]watch youtube videos +Now you have 5 tasks in the list. +____________________________________________________________ ``` ### Delete all Task @@ -198,6 +257,31 @@ Demo: ``` list + +____________________________________________________________ +Here are the tasks in your list: +1. [T][X]watch twitch videos +2. [D][X]homework1(by: 11:59 PM ) +3. [E][ ]g2 vs en(at: 09:00 PM ) +4. [E][ ]100t vs gambit(at: Aug 01 2021) +5. [E][ ]paperex vs bren(at: 08:00 AM Aug 01 2021) +____________________________________________________________ +``` +View all list commands in program. + +Demo: + +``` +Command Format: `!list` + +!list + +____________________________________________________________ +list displays all tasks +list todo displays all todo tasks +list event displays all event tasks +list deadline displays all deadline tasks +____________________________________________________________ ``` #### Viewing Todo Tasks @@ -210,6 +294,11 @@ Demo: ``` list todo + +____________________________________________________________ +Here are the ToDo tasks in your list: +1. [T][X]watch twitch videos +____________________________________________________________ ``` #### Viewing DeadLine Tasks @@ -222,6 +311,11 @@ Demo: ``` list deadline + +____________________________________________________________ +Here are the Deadline tasks in your list: +1. [D][X]homework1(by: 11:59 PM ) +____________________________________________________________ ``` #### Viewing Event Tasks @@ -234,6 +328,13 @@ Demo: ``` list event + +____________________________________________________________ +Here are the Event tasks in your list: +1. [E][ ]g2 vs en(at: 09:00 PM ) +2. [E][ ]100t vs gambit(at: Aug 01 2021) +3. [E][ ]paperex vs bren(at: 08:00 AM Aug 01 2021) +____________________________________________________________ ``` ### Finding Task By KeyWords @@ -242,22 +343,38 @@ Lists all tasks with a specific keyword in its description in list. Command Format: `find KEYWORD` +* kEYWORD must not be empty. + Demo: ``` -find +find g2 + +____________________________________________________________ +Here are the matching tasks in your list: +1. [E][ ]g2 vs en(at: 09:00 PM ) +____________________________________________________________ ``` ### Finding Task By Date Lists all tasks with a specific date in list. -Command Format: `date yyyy-mm-dd` +Command Format: `date DATE` + +* DATE must not be empty. +* DATE must be in the format of yyyy-mm-dd. Demo: ``` -date +date 2021-08-01 + +____________________________________________________________ +Here are the tasks with matching dates in your list: +1. [E][ ]100t vs gambit(at: Aug 01 2021) +2. [E][ ]paperex vs bren(at: 08:00 AM Aug 01 2021) +____________________________________________________________ ``` ### Echo User Input @@ -266,10 +383,6 @@ Prints user input on terminal Command Format: `echo INPUT` -Draws user input on terminial. - -Command Format: `!echo INPUT` - Demo: ``` @@ -278,7 +391,17 @@ echo hi ____________________________________________________________ hi ____________________________________________________________ +``` +Draws user input on terminial. + +Command Format: `!echo INPUT` + +!echo hi + +Demo: + +``` !echo hi ____________________________________________________________ From 4054b00d56190abe8fc106e5310ace4894acef32 Mon Sep 17 00:00:00 2001 From: kum-wh <69519728+kum-wh@users.noreply.github.com> Date: Thu, 30 Sep 2021 11:30:55 +0800 Subject: [PATCH 57/62] Update README.md --- docs/README.md | 72 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 22 deletions(-) diff --git a/docs/README.md b/docs/README.md index 55b37a911..1d55ffd83 100644 --- a/docs/README.md +++ b/docs/README.md @@ -16,8 +16,8 @@ Command | Use `Done` | Set a Task as **completed** `Delete` | Remove a Task `List` | View Task -`Find` | Find a Task with **Keyword** -`Date` | Find a Task with a specific **Date** +`Find` | Find Tasks with a specific **Keyword** +`Date` | Find Tasks with a specific **Date** `Bye` | Exit Program `Echo` | Repeat Input `!Echo` | Repeat Input in Grafiti ASCII Art @@ -28,20 +28,21 @@ Command | Use ## Notes -* Words in `UPPER_CASE` are parameters to be entered by user +* Words in `UPPER_CASE` are parameters to be entered by user. * Program is **not** case sensitive. -* TASK_DESCRIPTION represent description of a task. -* TASK_DEADLINE represent date of a task either in words or DATE and TIME format. -* TASK_TIMING represent timing of a task either in words or DATE and TIME format. -* TASK_INDEX represent index number of a task. Index number can be viewed by viewing the whole list. -* KEYWORD represent word input by user. -* TIME represents date input by user in `HH:MM` format. - * HH represents hours. - * MM represents minutes. -* DATE represents date input by user in `yyyy-mm-dd` fomat. - * yyyy represents year. - * mm represents months. - * dd represents days. +* `INPUT` represent input by user. +* `TASK_DESCRIPTION` represent description of a task. +* `TASK_DEADLINE` represent date of a task either in words or `DATE` and `TIME` format. +* `TASK_TIMING` represent timing of a task either in words or `DATE` and `TIME` format. +* `TASK_INDEX` represent index number of a task. Index number can be viewed by viewing list. +* `KEYWORD` represent word input by user. +* `TIME` represents date input by user in `HH:MM` format. + * `HH` represents hours. + * `MM` represents minutes. +* `DATE` represents date input by user in `yyyy-mm-dd` fomat. + * `yyyy` represents year. + * `mm` represents months. + * `dd` represents days. * Tasks are represented as `TASK_TYPE`,`STATUS`,`TASK_DESCRIPTION`,`TASK_DATE`. * `TASK_TYPE` is `T` for ToDo, `D` for Deadline and `E` for Event. * `STATUS` is `X` if completed. @@ -62,8 +63,8 @@ Command Format: `todo TASK_DESCRIPTION` * TASK_DESCRIPTION cannot be empty. Examples: -* todo watch twitch videos -* todo watch youtube videos +* `todo watch twitch videos` +* `todo watch youtube videos` Demo: @@ -91,10 +92,16 @@ Without Date | `deadline TASK_DESCRIPTION by TIME` Without Time | `deadline TASK_DESCRIPTION by DATE` With Date and Time | `deadline TASK_DESCCRIPTION by TIME DATE` + * TASK_DESCRIPTION and TASK_DEADLINE cannot be empty. -* Word "by " is required in input to indicated TASK_DEADLINE. +* Word `by` is required in input to indicated TASK_DEADLINE. * No specific ordering of time and date as long as input pattern is followed. +Examples: +* `deadline homework1 by 23:59` +* `deadline homework2 by 2020-10-10` +* `deadline homework3 by 20:00 2021-10-20 + Demo: ``` @@ -113,6 +120,7 @@ Now you have 5 tasks in the list. ____________________________________________________________ ``` + View details on adding Deadline task in program. Command Format: `!deadline` @@ -137,10 +145,16 @@ Without Date | `event TASK_DESCRIPTION at TIME` Without Time | `event TASK_DESCRIPTION at DATE` With Date and Time | `event TASK_DESCCRIPTION at TIME DATE` + * TASK_DESCRIPTION and TASK_TIMING cannot be empty. -* Word "at " is required in input to indicated TASK_DEADLINE. +* Word `at` is required in input to indicated TASK_DEADLINE. * No specific ordering of time and date as long as input pattern is followed. +Examples: +* `event g2 vs SEN at 21:00` +* `event 100T vs Gambit at 2021-08-01` +* `event paperex vs Bren at 2021-08-01 08:00` + Demo: ``` @@ -158,6 +172,8 @@ Got it. I've added this task: Now you have 8 tasks in the list. ____________________________________________________________ ``` + + View details on adding Event task in program. Command Format: `!event` @@ -179,7 +195,10 @@ Command Format: `done TASK_INDEX` * TASK_INDEX cannot be empty. * TASK_INDEX must be a integer. -* Use "," to seperate multiple tasks. +* Use `,` to seperate multiple tasks. + +Examples: +* `done 1,2,3` Demo: @@ -211,7 +230,10 @@ Command Format: `delete TASK_INDEX` * TASK_INDEX cannot be empty. * TASK_INDEX must be a integer. -* Use "," to seperate multiple tasks. +* Use `,` to seperate multiple tasks. + +Examples: +* `delete 2,4,5` Demo: @@ -343,7 +365,10 @@ Lists all tasks with a specific keyword in its description in list. Command Format: `find KEYWORD` -* kEYWORD must not be empty. +* KEYWORD must not be empty. + +Examples: +* `find g2` Demo: @@ -365,6 +390,9 @@ Command Format: `date DATE` * DATE must not be empty. * DATE must be in the format of yyyy-mm-dd. +Examples: +* `date 2021-08-01` + Demo: ``` From bc4554c606d3bacac8c2753620db43d2a2ae96f6 Mon Sep 17 00:00:00 2001 From: kum-wh <69519728+kum-wh@users.noreply.github.com> Date: Thu, 30 Sep 2021 11:35:15 +0800 Subject: [PATCH 58/62] Update README.md --- docs/README.md | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/docs/README.md b/docs/README.md index 1d55ffd83..2c3a0c8a3 100644 --- a/docs/README.md +++ b/docs/README.md @@ -60,7 +60,7 @@ Adds a task without any specific dates to list. Command Format: `todo TASK_DESCRIPTION` -* TASK_DESCRIPTION cannot be empty. +* `TASK_DESCRIPTION` cannot be empty. Examples: * `todo watch twitch videos` @@ -92,9 +92,8 @@ Without Date | `deadline TASK_DESCRIPTION by TIME` Without Time | `deadline TASK_DESCRIPTION by DATE` With Date and Time | `deadline TASK_DESCCRIPTION by TIME DATE` - -* TASK_DESCRIPTION and TASK_DEADLINE cannot be empty. -* Word `by` is required in input to indicated TASK_DEADLINE. +* `TASK_DESCRIPTION` and `TASK_DEADLINE` cannot be empty. +* Word `by` is required in input to indicated `TASK_DEADLINE`. * No specific ordering of time and date as long as input pattern is followed. Examples: @@ -120,7 +119,6 @@ Now you have 5 tasks in the list. ____________________________________________________________ ``` - View details on adding Deadline task in program. Command Format: `!deadline` @@ -146,9 +144,9 @@ Without Time | `event TASK_DESCRIPTION at DATE` With Date and Time | `event TASK_DESCCRIPTION at TIME DATE` -* TASK_DESCRIPTION and TASK_TIMING cannot be empty. -* Word `at` is required in input to indicated TASK_DEADLINE. -* No specific ordering of time and date as long as input pattern is followed. +* `TASK_DESCRIPTION` and `TASK_TIMING` cannot be empty. +* Word `at` is required in input to indicated `TASK_DEADLINE`. +* No specific ordering of `TIME` and `DATE` as long as input pattern is followed. Examples: * `event g2 vs SEN at 21:00` @@ -173,7 +171,6 @@ Now you have 8 tasks in the list. ____________________________________________________________ ``` - View details on adding Event task in program. Command Format: `!event` @@ -193,8 +190,8 @@ Sets tasks in list as done. Command Format: `done TASK_INDEX` -* TASK_INDEX cannot be empty. -* TASK_INDEX must be a integer. +* `TASK_INDEX` cannot be empty. +* `TASK_INDEX` must be a integer. * Use `,` to seperate multiple tasks. Examples: @@ -228,8 +225,8 @@ Deletes tasks from list Command Format: `delete TASK_INDEX` -* TASK_INDEX cannot be empty. -* TASK_INDEX must be a integer. +* `TASK_INDEX` cannot be empty. +* `TASK_INDEX` must be an integer. * Use `,` to seperate multiple tasks. Examples: @@ -365,7 +362,7 @@ Lists all tasks with a specific keyword in its description in list. Command Format: `find KEYWORD` -* KEYWORD must not be empty. +* `KEYWORD` must not be empty. Examples: * `find g2` @@ -387,8 +384,8 @@ Lists all tasks with a specific date in list. Command Format: `date DATE` -* DATE must not be empty. -* DATE must be in the format of yyyy-mm-dd. +* `DATE` must not be empty. +* `DATE` must be in the format of `yyyy-mm-dd`. Examples: * `date 2021-08-01` From 1816abe518cbd5f814510f9a8919da43eff7395a Mon Sep 17 00:00:00 2001 From: kum-wh <69519728+kum-wh@users.noreply.github.com> Date: Thu, 30 Sep 2021 11:42:51 +0800 Subject: [PATCH 59/62] Update README.md --- docs/README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 2c3a0c8a3..cf0af61b2 100644 --- a/docs/README.md +++ b/docs/README.md @@ -99,7 +99,7 @@ With Date and Time | `deadline TASK_DESCCRIPTION by TIME DATE` Examples: * `deadline homework1 by 23:59` * `deadline homework2 by 2020-10-10` -* `deadline homework3 by 20:00 2021-10-20 +* `deadline homework3 by 20:00 2021-10-20` Demo: @@ -286,8 +286,11 @@ Here are the tasks in your list: 5. [E][ ]paperex vs bren(at: 08:00 AM Aug 01 2021) ____________________________________________________________ ``` + View all list commands in program. +Command Format: `!list` + Demo: ``` @@ -482,3 +485,7 @@ _______________.___.___________ | | \\____ | | \ |________// ______|/_________/ ``` +## Storage +Duke saves all tasks into a text file `duke.txt` automatically. + +** Do Not manually edit the text file as that might corrupt the data and crash the program.** From e29bcf78985ba4632412ed847b5e57b0289b6be9 Mon Sep 17 00:00:00 2001 From: kum-wh <69519728+kum-wh@users.noreply.github.com> Date: Thu, 30 Sep 2021 11:44:39 +0800 Subject: [PATCH 60/62] Update README.md --- docs/README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index cf0af61b2..7475c9f0a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,11 +1,14 @@ # Duke User Guide + Duke is a Command Line Interface program that let users keep track of their tasks. ## Quick Start + 1. Ensure Java `11` is installed. 2. Download [IP.jar](https://github.com/kum-wh/ip/releases). 3. Navigate to file path in terminal. 4. To launch **Duke**, enter `java -jar IP.jar`. + ## Command List Command | Use @@ -486,6 +489,7 @@ _______________.___.___________ |________// ______|/_________/ ``` ## Storage + Duke saves all tasks into a text file `duke.txt` automatically. -** Do Not manually edit the text file as that might corrupt the data and crash the program.** +**Do Not manually edit the text file as that might corrupt the data and crash the program.** From cee51f8740b9c173ef97029ce7998bd8f54eeb9c Mon Sep 17 00:00:00 2001 From: kum-wh <69519728+kum-wh@users.noreply.github.com> Date: Thu, 30 Sep 2021 11:49:40 +0800 Subject: [PATCH 61/62] Update README.md --- docs/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 7475c9f0a..45d134c89 100644 --- a/docs/README.md +++ b/docs/README.md @@ -428,7 +428,8 @@ Draws user input on terminial. Command Format: `!echo INPUT` -!echo hi +Examples: +* `!echo hi` Demo: From bba48ca9cf12211d5d9b6f21e1ab9b66c551881a Mon Sep 17 00:00:00 2001 From: wingho2 Date: Thu, 30 Sep 2021 12:04:50 +0800 Subject: [PATCH 62/62] Fix ArtBot null pointer --- duke.txt | 12 +++++------- src/main/java/duke/Command/ArtCommand.java | 9 ++++++++- src/main/java/duke/Command/CommandGuide.java | 8 +++++++- .../java/duke/ErrorHandling/ErrorStaticString.java | 1 + 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/duke.txt b/duke.txt index e34584291..016b62a8a 100644 --- a/duke.txt +++ b/duke.txt @@ -1,7 +1,5 @@ -[D];[ ];reach legend;this season -[D];[ ];reach gold;08:00 -[D];[ ];reach silver; 2020-10-10 -[D];[ ];reach bronze;08:00 2020-10-10 -[E];[ ];g2 vs sentinel;10pm -[E];[ ];g2 vs sentinel;10:00 -[E];[ ];g2 vs sentinel;10:00 2020-10-10 +[T];[X];watch twitch videos +[D];[X];homework1;11:59 +[E];[ ];g2 vs en;09:00 +[E];[ ];100t vs gambit; 2021-08-01 +[E];[ ];paperex vs bren;08:00 2021-08-01 diff --git a/src/main/java/duke/Command/ArtCommand.java b/src/main/java/duke/Command/ArtCommand.java index ca9d58cff..0760bc9d1 100644 --- a/src/main/java/duke/Command/ArtCommand.java +++ b/src/main/java/duke/Command/ArtCommand.java @@ -1,6 +1,8 @@ package duke.Command; import duke.ArtBot.ArtBot; +import duke.ErrorHandling.CommandException; +import duke.ErrorHandling.ErrorStaticString; /** * Represent a command that echo string in graffiti form @@ -18,9 +20,14 @@ public ArtCommand(String userInput){ /** * Filter out string to echo in graffiti and hand over drawing to artbot class + * + * @throws CommandException if input is empty */ - public void handleArtCommand(){ + public void handleArtCommand() throws CommandException{ String removeCommand = taskInput.replaceFirst(COMMAND_ECHO_ART,EMPTY_STRING).trim().toUpperCase(); + if(removeCommand.isEmpty()){ + throw new CommandException(ErrorStaticString.ERROR_ARTBOT_INPUT_EMPTY); + } System.out.println(removeCommand); ArtBot artBot = new ArtBot(removeCommand); artBot.drawArt(); diff --git a/src/main/java/duke/Command/CommandGuide.java b/src/main/java/duke/Command/CommandGuide.java index 0889dcbe0..b2bb220eb 100644 --- a/src/main/java/duke/Command/CommandGuide.java +++ b/src/main/java/duke/Command/CommandGuide.java @@ -1,5 +1,7 @@ package duke.Command; +import duke.ErrorHandling.CommandException; + /** * Represent multiple simple one word commands that mainly just print out messages */ @@ -21,7 +23,11 @@ public CommandGuide(String taskInput){ public void executeCommand(){ if(taskInput.startsWith(COMMAND_ECHO_ART)){ ArtCommand artCommand = new ArtCommand(taskInput); - artCommand.handleArtCommand(); + try { + artCommand.handleArtCommand(); + } catch (CommandException e) { + e.handleException(); + } return; } switch(taskInput) { diff --git a/src/main/java/duke/ErrorHandling/ErrorStaticString.java b/src/main/java/duke/ErrorHandling/ErrorStaticString.java index 6c408eddb..b19d32eb0 100644 --- a/src/main/java/duke/ErrorHandling/ErrorStaticString.java +++ b/src/main/java/duke/ErrorHandling/ErrorStaticString.java @@ -33,6 +33,7 @@ public class ErrorStaticString { public static final String ERROR_ARTBOT_LETTER_NOT_FOUND = "☹ OOPS!!! Something went wrong, character input cannot be drawn.\n" + "Do not input space or symbols."; + public static final String ERROR_ARTBOT_INPUT_EMPTY = "☹ OOPS!!! Input cannot be empty."; public static final String ERROR_FILE_MESSAGE_CREATION = "☹ OOPS!!! Something went wrong with creating files"; public static final String ERROR_FILE_MESSAGE_READING = "☹ OOPS!!! Something went wrong with reading the files";