From 3741eff0b2a4c86774b336a35c3b12e8de0ccf55 Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Fri, 28 Jan 2022 16:24:06 +0800 Subject: [PATCH 01/45] Level 1 - add echo features --- src/main/java/Chatbox.java | 15 ++++++++++++++ src/main/java/Controller.java | 39 +++++++++++++++++++++++++++++++++++ src/main/java/Duke.java | 12 +++++------ 3 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 src/main/java/Chatbox.java create mode 100644 src/main/java/Controller.java diff --git a/src/main/java/Chatbox.java b/src/main/java/Chatbox.java new file mode 100644 index 000000000..57ad61920 --- /dev/null +++ b/src/main/java/Chatbox.java @@ -0,0 +1,15 @@ +public class Chatbox { + private String content = ""; + private String horizontalLine = "-------------------------------------"; + + public void chatboxPrinter(){ + System.out.println(content); + System.out.println(horizontalLine); + } + + public void setContent(String input){ + this.content = input; + } + + +} diff --git a/src/main/java/Controller.java b/src/main/java/Controller.java new file mode 100644 index 000000000..0fa2ef474 --- /dev/null +++ b/src/main/java/Controller.java @@ -0,0 +1,39 @@ +import java.util.Locale; +import java.util.Scanner; + +public class Controller { + public String hello = " Hello! I'm Duke\n What can I do for you?"; + public String goodbye = " Bye. Hope to see you again soon!"; + public String recvMsg = ""; + public String replyMsg = ""; + Chatbox chatbox = new Chatbox(); + + public void echo(String input) { + chatbox.setContent(input); + this.replyMsg = input; + chatbox.chatboxPrinter(); + } + + public void greet() { + chatbox.setContent(hello); + chatbox.chatboxPrinter(); + } + + public void bye() { + chatbox.setContent(goodbye); + chatbox.chatboxPrinter(); + System.exit(0); + } + + public void listen() { + Scanner msg = new Scanner(System.in); + this.recvMsg = msg.nextLine(); + String res = this.recvMsg.toLowerCase(Locale.ROOT); + if(res.contains("bye")){ + this.bye(); + }else{ + this.echo(this.recvMsg); + } + } + +} \ No newline at end of file diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5d313334c..3956b41a6 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,10 +1,10 @@ +import java.util.Scanner; public class Duke { public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); + Controller bot = new Controller(); + bot.greet(); + while(true){ + bot.listen(); + } } } From 4420957b64e9141ad1e8cecb2f53229350036143 Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Fri, 28 Jan 2022 23:50:38 +0800 Subject: [PATCH 02/45] Level - 2 Add/list function added --- src/main/java/Chatbox.java | 4 ++++ src/main/java/Controller.java | 25 +++++++++++++-------- src/main/java/Task.java | 41 ++++++++++++++++++++++++++++++++++ src/main/java/TaskManager.java | 33 +++++++++++++++++++++++++++ 4 files changed, 94 insertions(+), 9 deletions(-) create mode 100644 src/main/java/Task.java create mode 100644 src/main/java/TaskManager.java diff --git a/src/main/java/Chatbox.java b/src/main/java/Chatbox.java index 57ad61920..baf24b463 100644 --- a/src/main/java/Chatbox.java +++ b/src/main/java/Chatbox.java @@ -7,6 +7,10 @@ public void chatboxPrinter(){ System.out.println(horizontalLine); } + public void linePrinter(){ + System.out.println(horizontalLine); + } + public void setContent(String input){ this.content = input; } diff --git a/src/main/java/Controller.java b/src/main/java/Controller.java index 0fa2ef474..650bbdf24 100644 --- a/src/main/java/Controller.java +++ b/src/main/java/Controller.java @@ -2,16 +2,19 @@ import java.util.Scanner; public class Controller { - public String hello = " Hello! I'm Duke\n What can I do for you?"; - public String goodbye = " Bye. Hope to see you again soon!"; + public String hello = "Hello! I'm Duke :P\nWhat can I do for you?"; + public String goodbye = "Bye. Hope to see you again soon! ;)"; public String recvMsg = ""; public String replyMsg = ""; Chatbox chatbox = new Chatbox(); + TaskManager manager = new TaskManager(); - public void echo(String input) { - chatbox.setContent(input); - this.replyMsg = input; - chatbox.chatboxPrinter(); + public void addTask(String input) { + manager.addTask(input); + } + + public void listTask(){ + manager.listTask(); } public void greet() { @@ -25,14 +28,18 @@ public void bye() { System.exit(0); } + + public void listen() { Scanner msg = new Scanner(System.in); this.recvMsg = msg.nextLine(); String res = this.recvMsg.toLowerCase(Locale.ROOT); - if(res.contains("bye")){ + if(res.equals("bye")){ this.bye(); - }else{ - this.echo(this.recvMsg); + }else if(res.equals("list")) { + this.listTask(); + }else { + this.addTask(this.recvMsg); } } diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 000000000..f4c636a7b --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,41 @@ +public class Task { + //public String unmarkedStatus = "[]"; + //public String markedStatus = "[X]"; + public String taskName = ""; + //public int status = 0; + public String listName = ""; + + public void setName(String name){ + this.taskName = name; + //setListName(); + } + + public String getTaskName(){ + return this.taskName; + } + + /* + public void setListName(){ + if(status == 0){ + this.listName = this.unmarkedStatus + this.taskName; + }else{ + this.listName = this.markedStatus + this.taskName; + } + } + + + public void mark(){ + this.status = 1; + } + + public void unmark(){ + this.status = 0; + } + */ + + public void taskPrinter(){ + System.out.println(listName); + } + + +} diff --git a/src/main/java/TaskManager.java b/src/main/java/TaskManager.java new file mode 100644 index 000000000..fb39e5f6a --- /dev/null +++ b/src/main/java/TaskManager.java @@ -0,0 +1,33 @@ +import java.util.ArrayList; +public class TaskManager { + private static ArrayList Tasks = new ArrayList(); + Chatbox chatbox = new Chatbox(); + + public void addTask(String name){ + Task newTask = new Task(); + newTask.setName(name); + Tasks.add(newTask); + chatbox.setContent("added: " + name); + chatbox.chatboxPrinter(); + } + + public void listTask(){ + String content = ""; + if(Tasks.size() == 0){ + content = "Sorry, there's no task in the list :("; + }else { + for (int i = 0; i < Tasks.size(); i++) { + String index = String.valueOf(i + 1); + String name = index + ". " + Tasks.get(i).getTaskName(); + content += name; + if(i < Tasks.size() - 1){ + content += "\n"; + } + } + } + chatbox.setContent(content); + chatbox.chatboxPrinter(); + } + + +} From 5072522c30ff7d644eea7daafa56e8c3d234ae91 Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Sat, 29 Jan 2022 02:18:31 +0800 Subject: [PATCH 03/45] Level 3 add mark/unmark feature --- src/main/java/Controller.java | 34 ++++++++++++++++++++++++++++++---- src/main/java/Task.java | 15 +++++++++------ src/main/java/TaskManager.java | 30 ++++++++++++++++++++++++++++-- 3 files changed, 67 insertions(+), 12 deletions(-) diff --git a/src/main/java/Controller.java b/src/main/java/Controller.java index 650bbdf24..4edb5fd7a 100644 --- a/src/main/java/Controller.java +++ b/src/main/java/Controller.java @@ -28,17 +28,43 @@ public void bye() { System.exit(0); } + public void unmarkTask(String input){ + String[] keywords = input.split(" "); + int index= Integer.parseInt(keywords[1]); + manager.unmarkTask(index); + } + + public void markTask(String input){ + String[] keywords = input.split(" "); + int index= Integer.parseInt(keywords[1]); + manager.markTask(index); + } + + public void replyMsgPrinter(){ + chatbox.setContent(this.replyMsg); + chatbox.chatboxPrinter(); + } + public void listen() { Scanner msg = new Scanner(System.in); this.recvMsg = msg.nextLine(); - String res = this.recvMsg.toLowerCase(Locale.ROOT); - if(res.equals("bye")){ + String[] keyword = this.recvMsg.toLowerCase(Locale.ROOT).split(" "); + switch (keyword[0]) { + case "bye": this.bye(); - }else if(res.equals("list")) { + break; + case "list": this.listTask(); - }else { + break; + case "mark": + this.markTask(this.recvMsg); + break; + case "unmark": + this.unmarkTask(this.recvMsg); + break; + default: this.addTask(this.recvMsg); } } diff --git a/src/main/java/Task.java b/src/main/java/Task.java index f4c636a7b..e2149d6f8 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -1,20 +1,19 @@ public class Task { - //public String unmarkedStatus = "[]"; - //public String markedStatus = "[X]"; + public String unmarkedStatus = "[ ]"; + public String markedStatus = "[X]"; public String taskName = ""; - //public int status = 0; + public int status = 0; public String listName = ""; public void setName(String name){ this.taskName = name; - //setListName(); + setListName(); } public String getTaskName(){ return this.taskName; } - /* public void setListName(){ if(status == 0){ this.listName = this.unmarkedStatus + this.taskName; @@ -23,15 +22,19 @@ public void setListName(){ } } + public String getListName(){ + return this.listName; + } public void mark(){ this.status = 1; + this.setListName(); } public void unmark(){ this.status = 0; + this.setListName(); } - */ public void taskPrinter(){ System.out.println(listName); diff --git a/src/main/java/TaskManager.java b/src/main/java/TaskManager.java index fb39e5f6a..fcd1626c4 100644 --- a/src/main/java/TaskManager.java +++ b/src/main/java/TaskManager.java @@ -12,13 +12,13 @@ public void addTask(String name){ } public void listTask(){ - String content = ""; + String content = "Here are the tasks in your list:\n"; if(Tasks.size() == 0){ content = "Sorry, there's no task in the list :("; }else { for (int i = 0; i < Tasks.size(); i++) { String index = String.valueOf(i + 1); - String name = index + ". " + Tasks.get(i).getTaskName(); + String name = index + ". " + Tasks.get(i).getListName(); content += name; if(i < Tasks.size() - 1){ content += "\n"; @@ -29,5 +29,31 @@ public void listTask(){ chatbox.chatboxPrinter(); } + public void markTask(int n){ + System.out.println(n); + String content = ""; + if(n < 1 || n > Tasks.size()){ + content = "Sorry, I could not find the task :/"; + }else { + //System.out.println(n); + Tasks.get(n - 1).mark(); + content = "Nice! I've marked this task as done:\n" + Tasks.get(n - 1).listName; + } + chatbox.setContent(content); + chatbox.chatboxPrinter(); + } + + public void unmarkTask(int n){ + String content = ""; + if(n < 1 || n > Tasks.size()){ + content = "Sorry, I could not find the task :/"; + }else { + Tasks.get(n - 1).unmark(); + content = "OK, I've marked this task as not done yet:\n" + Tasks.get(n - 1).listName; + } + chatbox.setContent(content); + chatbox.chatboxPrinter(); + } + } From 9bec8de1339c7ddafae915363c6c00c1849047b2 Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Sun, 30 Jan 2022 23:53:32 +0800 Subject: [PATCH 04/45] A-coding standard --- src/main/java/Chatbox.java | 2 +- src/main/java/Controller.java | 2 -- src/main/java/Task.java | 2 -- src/main/java/TaskManager.java | 2 +- 4 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/main/java/Chatbox.java b/src/main/java/Chatbox.java index baf24b463..9ab9b7036 100644 --- a/src/main/java/Chatbox.java +++ b/src/main/java/Chatbox.java @@ -1,6 +1,6 @@ public class Chatbox { private String content = ""; - private String horizontalLine = "-------------------------------------"; + private final String horizontalLine = "-------------------------------------"; public void chatboxPrinter(){ System.out.println(content); diff --git a/src/main/java/Controller.java b/src/main/java/Controller.java index 4edb5fd7a..25de93218 100644 --- a/src/main/java/Controller.java +++ b/src/main/java/Controller.java @@ -45,8 +45,6 @@ public void replyMsgPrinter(){ chatbox.chatboxPrinter(); } - - public void listen() { Scanner msg = new Scanner(System.in); this.recvMsg = msg.nextLine(); diff --git a/src/main/java/Task.java b/src/main/java/Task.java index e2149d6f8..a7960a32f 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -39,6 +39,4 @@ public void unmark(){ public void taskPrinter(){ System.out.println(listName); } - - } diff --git a/src/main/java/TaskManager.java b/src/main/java/TaskManager.java index fcd1626c4..67cbecc74 100644 --- a/src/main/java/TaskManager.java +++ b/src/main/java/TaskManager.java @@ -1,6 +1,6 @@ import java.util.ArrayList; public class TaskManager { - private static ArrayList Tasks = new ArrayList(); + private static final ArrayList Tasks = new ArrayList(); Chatbox chatbox = new Chatbox(); public void addTask(String name){ From 4d45c740012a72a0acea230cea2080a789707e0b Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Thu, 3 Feb 2022 02:10:03 +0800 Subject: [PATCH 05/45] Level-4 --- src/main/java/Controller.java | 28 ++++++++++++++++++++++++++++ src/main/java/Deadline.java | 13 +++++++++++++ src/main/java/Event.java | 13 +++++++++++++ src/main/java/Task.java | 10 +++++----- src/main/java/TaskManager.java | 31 +++++++++++++++++++++++++++++-- src/main/java/ToDo.java | 11 +++++++++++ 6 files changed, 99 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/Controller.java b/src/main/java/Controller.java index 25de93218..fc07c4db7 100644 --- a/src/main/java/Controller.java +++ b/src/main/java/Controller.java @@ -13,6 +13,25 @@ public void addTask(String input) { manager.addTask(input); } + public void addToDo(String input) { + String name = input.replace("todo", ""); + manager.addToDo(name); + } + + public void addDeadline(String input) { + String[] keywords = input.split("/by "); + String by = keywords[1]; + String name = keywords[0].replace("deadline ", ""); + manager.addDeadline(name, by); + } + + public void addEvent(String input) { + String[] keywords = input.split("/at "); + String by = keywords[1]; + String name = keywords[0].replace("event ", ""); + manager.addEvent(name, by); + } + public void listTask(){ manager.listTask(); } @@ -62,6 +81,15 @@ public void listen() { case "unmark": this.unmarkTask(this.recvMsg); break; + case "deadline": + this.addDeadline(this.recvMsg); + break; + case "event": + this.addEvent(this.recvMsg); + break; + case "todo": + this.addToDo(this.recvMsg); + break; default: this.addTask(this.recvMsg); } diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java new file mode 100644 index 000000000..b5e5a100a --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,13 @@ +public class Deadline extends Task{ + public String by; + + public Deadline(String name, String by){ + super(name); + this.by = by; + } + + @Override + public String getListName(){ + return "[D]" + super.getListName() + "(by: " + by + ")"; + } +} diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 000000000..130e05108 --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,13 @@ +public class Event extends Task{ + public String by; + + public Event(String name, String by){ + super(name); + this.by = by; + } + + @Override + public String getListName(){ + return "[E]" + super.getListName() + "(at: " + by + ")"; + } +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java index a7960a32f..90ae84f94 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -2,10 +2,10 @@ public class Task { public String unmarkedStatus = "[ ]"; public String markedStatus = "[X]"; public String taskName = ""; - public int status = 0; + public boolean isDone = false; public String listName = ""; - public void setName(String name){ + public Task(String name){ this.taskName = name; setListName(); } @@ -15,7 +15,7 @@ public String getTaskName(){ } public void setListName(){ - if(status == 0){ + if(isDone == false){ this.listName = this.unmarkedStatus + this.taskName; }else{ this.listName = this.markedStatus + this.taskName; @@ -27,12 +27,12 @@ public String getListName(){ } public void mark(){ - this.status = 1; + this.isDone = true; this.setListName(); } public void unmark(){ - this.status = 0; + this.isDone = false; this.setListName(); } diff --git a/src/main/java/TaskManager.java b/src/main/java/TaskManager.java index 67cbecc74..5857bc60b 100644 --- a/src/main/java/TaskManager.java +++ b/src/main/java/TaskManager.java @@ -1,16 +1,43 @@ import java.util.ArrayList; public class TaskManager { private static final ArrayList Tasks = new ArrayList(); + private String addResponse = "Got it. I've added this task:\n"; Chatbox chatbox = new Chatbox(); public void addTask(String name){ - Task newTask = new Task(); - newTask.setName(name); + Task newTask = new Task(name); Tasks.add(newTask); chatbox.setContent("added: " + name); chatbox.chatboxPrinter(); } + public void addDeadline(String name, String by){ + Deadline newDeadline = new Deadline(name, by); + Tasks.add(newDeadline); + int s = Tasks.size(); + String response = addResponse + newDeadline.getListName() + "\n" + "Now you have " + String.valueOf(s) + " tasks in your list."; + chatbox.setContent(response); + chatbox.chatboxPrinter(); + } + + public void addEvent(String name, String by){ + Event newEvent = new Event(name, by); + Tasks.add(newEvent); + int s = Tasks.size(); + String response = addResponse + newEvent.getListName() + "\n" + "Now you have " + String.valueOf(s) + " tasks in your list."; + chatbox.setContent(response); + chatbox.chatboxPrinter(); + } + + public void addToDo(String name){ + ToDo newToDo = new ToDo(name); + Tasks.add(newToDo); + int s = Tasks.size(); + String response = addResponse + newToDo.getListName() + "\n" + "Now you have " + String.valueOf(s) + " tasks in your list."; + chatbox.setContent(response); + chatbox.chatboxPrinter(); + } + public void listTask(){ String content = "Here are the tasks in your list:\n"; if(Tasks.size() == 0){ diff --git a/src/main/java/ToDo.java b/src/main/java/ToDo.java new file mode 100644 index 000000000..1956e993a --- /dev/null +++ b/src/main/java/ToDo.java @@ -0,0 +1,11 @@ +public class ToDo extends Task{ + + public ToDo(String name){ + super(name); + } + + @Override + public String getListName(){ + return "[T]" + super.getListName(); + } +} From d54b512eadfdc277ffb033dfe1f72ff5ac71b6e3 Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Thu, 3 Feb 2022 12:59:57 +0800 Subject: [PATCH 06/45] Fixed some bugs in Level-4 --- src/main/java/Deadline.java | 9 +++++++-- src/main/java/Event.java | 9 +++++++-- src/main/java/ToDo.java | 8 ++++++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index b5e5a100a..26b78cb8c 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -4,10 +4,15 @@ public class Deadline extends Task{ public Deadline(String name, String by){ super(name); this.by = by; + setListName(); } @Override - public String getListName(){ - return "[D]" + super.getListName() + "(by: " + by + ")"; + public void setListName(){ + if(isDone == false){ + this.listName = "[D]" + this.unmarkedStatus + this.taskName + "(by: " + by + ")"; + }else{ + this.listName = "[D]" + this.markedStatus + this.taskName + "(by: " + by + ")"; + } } } diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 130e05108..a6e7ea8c3 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -4,10 +4,15 @@ public class Event extends Task{ public Event(String name, String by){ super(name); this.by = by; + setListName(); } @Override - public String getListName(){ - return "[E]" + super.getListName() + "(at: " + by + ")"; + public void setListName(){ + if(isDone == false){ + this.listName = "[E]" + this.unmarkedStatus + this.taskName + "(at: " + by + ")"; + }else{ + this.listName = "[E]" + this.markedStatus + this.taskName + "(at: " + by + ")"; + } } } diff --git a/src/main/java/ToDo.java b/src/main/java/ToDo.java index 1956e993a..7226943ea 100644 --- a/src/main/java/ToDo.java +++ b/src/main/java/ToDo.java @@ -5,7 +5,11 @@ public ToDo(String name){ } @Override - public String getListName(){ - return "[T]" + super.getListName(); + public void setListName(){ + if(isDone == false){ + this.listName = "[T]" + this.unmarkedStatus + this.taskName; + }else{ + this.listName = "[T]" + this.markedStatus + this.taskName; + } } } From beece18a6f80438b98109904f4d13b8c8d76f024 Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Fri, 4 Feb 2022 18:23:15 +0800 Subject: [PATCH 07/45] Optimise instruction analysis --- src/main/java/Controller.java | 79 +++++++++++++++++------------ src/main/java/Deadline.java | 4 +- src/main/java/Event.java | 16 +++--- src/main/java/OperationAnalyst.java | 64 +++++++++++++++++++++++ src/main/java/Task.java | 10 ++-- src/main/java/TaskManager.java | 58 ++++++++++++++++----- src/main/java/ToDo.java | 2 +- 7 files changed, 171 insertions(+), 62 deletions(-) create mode 100644 src/main/java/OperationAnalyst.java diff --git a/src/main/java/Controller.java b/src/main/java/Controller.java index fc07c4db7..9bfad022b 100644 --- a/src/main/java/Controller.java +++ b/src/main/java/Controller.java @@ -2,13 +2,37 @@ import java.util.Scanner; public class Controller { - public String hello = "Hello! I'm Duke :P\nWhat can I do for you?"; - public String goodbye = "Bye. Hope to see you again soon! ;)"; - public String recvMsg = ""; - public String replyMsg = ""; + protected String HELLO_WORDS = "Hello! I'm Duke :P\nWhat can I do for you?"; + protected String GOODBYE_WORDS = "Bye. Hope to see you again soon! ;)"; + protected String recvMsg = ""; + protected String replyMsg = ""; Chatbox chatbox = new Chatbox(); TaskManager manager = new TaskManager(); + OperationAnalyst analyst; + public void greet() { + chatbox.setContent(HELLO_WORDS); + chatbox.chatboxPrinter(); + } + + public void bye() { + chatbox.setContent(GOODBYE_WORDS); + chatbox.chatboxPrinter(); + System.exit(0); + } + + public void unmarkTask(){ + //String[] keywords = input.split(" "); + int index= Integer.parseInt(analyst.taskName); + manager.unmarkTask(index); + } + + public void markTask(){ + //String[] keywords = input.split(" "); + int index= Integer.parseInt(analyst.taskName); + manager.markTask(index); + } + /* public void addTask(String input) { manager.addTask(input); } @@ -22,77 +46,68 @@ public void addDeadline(String input) { String[] keywords = input.split("/by "); String by = keywords[1]; String name = keywords[0].replace("deadline ", ""); - manager.addDeadline(name, by); + manager.addDeadline(analyst.taskName, analyst.time); } public void addEvent(String input) { - String[] keywords = input.split("/at "); - String by = keywords[1]; - String name = keywords[0].replace("event ", ""); - manager.addEvent(name, by); + manager.addEvent(analyst.taskName, analyst.time); } public void listTask(){ manager.listTask(); } + public void greet() { - chatbox.setContent(hello); + chatbox.setContent(HELLO_WORDS); chatbox.chatboxPrinter(); } public void bye() { - chatbox.setContent(goodbye); + chatbox.setContent(GOODBYE_WORDS); chatbox.chatboxPrinter(); System.exit(0); } - public void unmarkTask(String input){ - String[] keywords = input.split(" "); - int index= Integer.parseInt(keywords[1]); - manager.unmarkTask(index); - } - - public void markTask(String input){ - String[] keywords = input.split(" "); - int index= Integer.parseInt(keywords[1]); - manager.markTask(index); - } - public void replyMsgPrinter(){ chatbox.setContent(this.replyMsg); chatbox.chatboxPrinter(); } + */ + public void listen() { Scanner msg = new Scanner(System.in); this.recvMsg = msg.nextLine(); - String[] keyword = this.recvMsg.toLowerCase(Locale.ROOT).split(" "); - switch (keyword[0]) { + analyst = new OperationAnalyst(this.recvMsg); + String command = analyst.getCommand(); + //String[] keyword = this.recvMsg.toLowerCase(Locale.ROOT).split(" "); + switch (command) { case "bye": this.bye(); break; case "list": - this.listTask(); + manager.listTask(); break; case "mark": - this.markTask(this.recvMsg); + this.markTask(); break; case "unmark": - this.unmarkTask(this.recvMsg); + this.unmarkTask(); break; case "deadline": - this.addDeadline(this.recvMsg); + manager.addDeadline(analyst.taskName, analyst.time); break; case "event": - this.addEvent(this.recvMsg); + manager.addEvent(analyst.taskName, analyst.time); break; case "todo": - this.addToDo(this.recvMsg); + manager.addToDo(analyst.taskName); break; default: - this.addTask(this.recvMsg); + manager.addTask(analyst.taskName); } } + } \ No newline at end of file diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index 26b78cb8c..0a7557cc9 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -1,5 +1,5 @@ public class Deadline extends Task{ - public String by; + protected String by; public Deadline(String name, String by){ super(name); @@ -9,7 +9,7 @@ public Deadline(String name, String by){ @Override public void setListName(){ - if(isDone == false){ + if(!isDone){ this.listName = "[D]" + this.unmarkedStatus + this.taskName + "(by: " + by + ")"; }else{ this.listName = "[D]" + this.markedStatus + this.taskName + "(by: " + by + ")"; diff --git a/src/main/java/Event.java b/src/main/java/Event.java index a6e7ea8c3..29f6dab07 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -1,18 +1,18 @@ -public class Event extends Task{ - public String by; +public class Event extends Task { + public String at; - public Event(String name, String by){ + public Event(String name, String at) { super(name); - this.by = by; + this.at = at; setListName(); } @Override - public void setListName(){ - if(isDone == false){ - this.listName = "[E]" + this.unmarkedStatus + this.taskName + "(at: " + by + ")"; + public void setListName() { + if(!isDone){ + this.listName = "[E]" + this.unmarkedStatus + this.taskName + "(at: " + at + ")"; }else{ - this.listName = "[E]" + this.markedStatus + this.taskName + "(at: " + by + ")"; + this.listName = "[E]" + this.markedStatus + this.taskName + "(at: " + at + ")"; } } } diff --git a/src/main/java/OperationAnalyst.java b/src/main/java/OperationAnalyst.java new file mode 100644 index 000000000..5a0ac587f --- /dev/null +++ b/src/main/java/OperationAnalyst.java @@ -0,0 +1,64 @@ +import java.util.Locale; + +public class OperationAnalyst { + protected String[] keywords; + protected String rawInput; + protected String time; + protected String taskName; + protected String instruction; + + public OperationAnalyst(String input){ + this.keywords = input.split(" "); + this.rawInput = input; + this.instruction = keywords[0].toLowerCase(Locale.ROOT); + parseInstruction(); + } + + /** + * Computes the command for further operation, which is the first element in the keywords array + * @return the command, whether it is deadline, todo, event, list, mark or unmark + */ + public String getCommand() { + return this.instruction; + } + + /** + * Analyses raw input to determine the task name and time + */ + public void parseInstruction() { + //String name; + String[] command; + switch (this.instruction) { + case "deadline": + command = rawInput.split("/by "); + this.taskName = command[0].replace("deadline ", ""); + this.time = command[1]; + //System.out.println(this.time); + break; + case "event": + command = rawInput.split("/at "); + this.taskName = command[0].replace("event ", ""); + this.time = command[1]; + break; + case "todo": + this.taskName = rawInput.replace("todo ", ""); + break; + case "mark": + this.taskName = this.keywords[1]; + break; + case "unmark": + this.taskName = this.keywords[1]; + break; + default: + this.taskName = rawInput; + } + } + + public String getTaskName() { + return this.taskName; + } + + public String getTime() { + return this.time; + } +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 90ae84f94..93c72df00 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -1,9 +1,9 @@ public class Task { - public String unmarkedStatus = "[ ]"; - public String markedStatus = "[X]"; - public String taskName = ""; - public boolean isDone = false; - public String listName = ""; + protected String unmarkedStatus = "[ ]"; + protected String markedStatus = "[X]"; + protected String taskName = ""; + protected boolean isDone = false; + protected String listName = ""; public Task(String name){ this.taskName = name; diff --git a/src/main/java/TaskManager.java b/src/main/java/TaskManager.java index 5857bc60b..ae8d9e6e6 100644 --- a/src/main/java/TaskManager.java +++ b/src/main/java/TaskManager.java @@ -1,44 +1,65 @@ import java.util.ArrayList; public class TaskManager { private static final ArrayList Tasks = new ArrayList(); - private String addResponse = "Got it. I've added this task:\n"; + protected String ADD_RES = "Got it. I've added this task:\n"; Chatbox chatbox = new Chatbox(); - public void addTask(String name){ + /** + * Adds a general task in the list + * @param name refers to the name of the task + */ + public void addTask(String name) { Task newTask = new Task(name); Tasks.add(newTask); chatbox.setContent("added: " + name); chatbox.chatboxPrinter(); } - public void addDeadline(String name, String by){ + /** + * Adds a deadline task to the list + * @param name refers to the name of the task + * @param by refers to the deadline of the task + */ + public void addDeadline(String name, String by) { Deadline newDeadline = new Deadline(name, by); Tasks.add(newDeadline); int s = Tasks.size(); - String response = addResponse + newDeadline.getListName() + "\n" + "Now you have " + String.valueOf(s) + " tasks in your list."; + String response = ADD_RES + newDeadline.getListName() + "\n" + "Now you have " + String.valueOf(s) + " tasks in your list."; chatbox.setContent(response); chatbox.chatboxPrinter(); } - public void addEvent(String name, String by){ - Event newEvent = new Event(name, by); + /** + * Adds an event task to the list + * @param name refers to the name of the task + * @param at refers to the happening time of the event + */ + public void addEvent(String name, String at) { + Event newEvent = new Event(name, at); Tasks.add(newEvent); int s = Tasks.size(); - String response = addResponse + newEvent.getListName() + "\n" + "Now you have " + String.valueOf(s) + " tasks in your list."; + String response = ADD_RES + newEvent.getListName() + "\n" + "Now you have " + String.valueOf(s) + " tasks in your list."; chatbox.setContent(response); chatbox.chatboxPrinter(); } - public void addToDo(String name){ + /** + * Adds a todo task to the list + * @param name refers to the name of the todo task + */ + public void addToDo(String name) { ToDo newToDo = new ToDo(name); Tasks.add(newToDo); int s = Tasks.size(); - String response = addResponse + newToDo.getListName() + "\n" + "Now you have " + String.valueOf(s) + " tasks in your list."; + String response = ADD_RES + newToDo.getListName() + "\n" + "Now you have " + String.valueOf(s) + " tasks in your list."; chatbox.setContent(response); chatbox.chatboxPrinter(); } - public void listTask(){ + /** + * Lists all tasks in the list with adding time order + */ + public void listTask() { String content = "Here are the tasks in your list:\n"; if(Tasks.size() == 0){ content = "Sorry, there's no task in the list :("; @@ -56,13 +77,17 @@ public void listTask(){ chatbox.chatboxPrinter(); } - public void markTask(int n){ + /** + * Marks specific task in the list as done + * @param n refers to the index of the task in adding time order + */ + public void markTask(int n) { System.out.println(n); String content = ""; - if(n < 1 || n > Tasks.size()){ + if(n < 1 || n > Tasks.size()) { + //Beyonds boundaries content = "Sorry, I could not find the task :/"; }else { - //System.out.println(n); Tasks.get(n - 1).mark(); content = "Nice! I've marked this task as done:\n" + Tasks.get(n - 1).listName; } @@ -70,9 +95,14 @@ public void markTask(int n){ chatbox.chatboxPrinter(); } - public void unmarkTask(int n){ + /** + * Unmarks specific task in the list as undone + * @param n refers to the index of the task in adding time order + */ + public void unmarkTask(int n) { String content = ""; if(n < 1 || n > Tasks.size()){ + // Beyonds boundaries content = "Sorry, I could not find the task :/"; }else { Tasks.get(n - 1).unmark(); diff --git a/src/main/java/ToDo.java b/src/main/java/ToDo.java index 7226943ea..89d56671c 100644 --- a/src/main/java/ToDo.java +++ b/src/main/java/ToDo.java @@ -6,7 +6,7 @@ public ToDo(String name){ @Override public void setListName(){ - if(isDone == false){ + if(!isDone){ this.listName = "[T]" + this.unmarkedStatus + this.taskName; }else{ this.listName = "[T]" + this.markedStatus + this.taskName; From 53fb133ba39901f003ad634465dd7fa9a17ba718 Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Mon, 7 Feb 2022 16:17:47 +0800 Subject: [PATCH 08/45] Fix coding quality --- src/main/java/Chatbox.java | 7 ++-- src/main/java/Controller.java | 60 +++++++++-------------------------- src/main/java/Duke.java | 2 +- src/main/java/Event.java | 2 +- src/main/java/Task.java | 4 +-- 5 files changed, 23 insertions(+), 52 deletions(-) diff --git a/src/main/java/Chatbox.java b/src/main/java/Chatbox.java index 9ab9b7036..22a88423c 100644 --- a/src/main/java/Chatbox.java +++ b/src/main/java/Chatbox.java @@ -1,14 +1,15 @@ public class Chatbox { private String content = ""; - private final String horizontalLine = "-------------------------------------"; + //border of the chatbox + private final String HORIZON_LINE = "-------------------------------------"; public void chatboxPrinter(){ System.out.println(content); - System.out.println(horizontalLine); + System.out.println(HORIZON_LINE); } public void linePrinter(){ - System.out.println(horizontalLine); + System.out.println(HORIZON_LINE); } public void setContent(String input){ diff --git a/src/main/java/Controller.java b/src/main/java/Controller.java index 9bfad022b..6f85d2342 100644 --- a/src/main/java/Controller.java +++ b/src/main/java/Controller.java @@ -2,6 +2,7 @@ import java.util.Scanner; public class Controller { + //greeting msg and exit msg protected String HELLO_WORDS = "Hello! I'm Duke :P\nWhat can I do for you?"; protected String GOODBYE_WORDS = "Bye. Hope to see you again soon! ;)"; protected String recvMsg = ""; @@ -10,78 +11,47 @@ public class Controller { TaskManager manager = new TaskManager(); OperationAnalyst analyst; + /** + * Prints greeting msg + */ public void greet() { chatbox.setContent(HELLO_WORDS); chatbox.chatboxPrinter(); } + /** + * Prints goodbye msg and exits + */ public void bye() { chatbox.setContent(GOODBYE_WORDS); chatbox.chatboxPrinter(); System.exit(0); } + /** + * Unmarks task in the list + */ public void unmarkTask(){ - //String[] keywords = input.split(" "); int index= Integer.parseInt(analyst.taskName); manager.unmarkTask(index); } + /** + * Marks task in the list + */ public void markTask(){ - //String[] keywords = input.split(" "); int index= Integer.parseInt(analyst.taskName); manager.markTask(index); } - /* - public void addTask(String input) { - manager.addTask(input); - } - - public void addToDo(String input) { - String name = input.replace("todo", ""); - manager.addToDo(name); - } - - public void addDeadline(String input) { - String[] keywords = input.split("/by "); - String by = keywords[1]; - String name = keywords[0].replace("deadline ", ""); - manager.addDeadline(analyst.taskName, analyst.time); - } - - public void addEvent(String input) { - manager.addEvent(analyst.taskName, analyst.time); - } - - public void listTask(){ - manager.listTask(); - } - - - public void greet() { - chatbox.setContent(HELLO_WORDS); - chatbox.chatboxPrinter(); - } - - public void bye() { - chatbox.setContent(GOODBYE_WORDS); - chatbox.chatboxPrinter(); - System.exit(0); - } - - public void replyMsgPrinter(){ - chatbox.setContent(this.replyMsg); - chatbox.chatboxPrinter(); - } + /** + * Listen the instruction and operate during the session */ - public void listen() { Scanner msg = new Scanner(System.in); this.recvMsg = msg.nextLine(); analyst = new OperationAnalyst(this.recvMsg); String command = analyst.getCommand(); - //String[] keyword = this.recvMsg.toLowerCase(Locale.ROOT).split(" "); switch (command) { case "bye": this.bye(); diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 3956b41a6..99328315c 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -3,7 +3,7 @@ public class Duke { public static void main(String[] args) { Controller bot = new Controller(); bot.greet(); - while(true){ + while(true){ //opens a new session for receiving instructions bot.listen(); } } diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 29f6dab07..1a288bae3 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -1,5 +1,5 @@ public class Event extends Task { - public String at; + public String at; public Event(String name, String at) { super(name); diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 93c72df00..043932a10 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -1,9 +1,9 @@ public class Task { protected String unmarkedStatus = "[ ]"; protected String markedStatus = "[X]"; - protected String taskName = ""; + protected String taskName = ""; //the name of the task protected boolean isDone = false; - protected String listName = ""; + protected String listName = ""; //the name of the task that appears when listing public Task(String name){ this.taskName = name; From 83488fe2275bacc1190bb551d359f6a841a874c6 Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Mon, 7 Feb 2022 16:21:00 +0800 Subject: [PATCH 09/45] Improve coding quality --- src/main/java/Event.java | 2 +- src/main/java/OperationAnalyst.java | 2 -- src/main/java/TaskManager.java | 10 +++++++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 1a288bae3..8849e72e5 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -1,5 +1,5 @@ public class Event extends Task { - public String at; + protected String at; public Event(String name, String at) { super(name); diff --git a/src/main/java/OperationAnalyst.java b/src/main/java/OperationAnalyst.java index 5a0ac587f..e8eb630b6 100644 --- a/src/main/java/OperationAnalyst.java +++ b/src/main/java/OperationAnalyst.java @@ -44,8 +44,6 @@ public void parseInstruction() { this.taskName = rawInput.replace("todo ", ""); break; case "mark": - this.taskName = this.keywords[1]; - break; case "unmark": this.taskName = this.keywords[1]; break; diff --git a/src/main/java/TaskManager.java b/src/main/java/TaskManager.java index ae8d9e6e6..07d4029c9 100644 --- a/src/main/java/TaskManager.java +++ b/src/main/java/TaskManager.java @@ -1,6 +1,7 @@ import java.util.ArrayList; public class TaskManager { private static final ArrayList Tasks = new ArrayList(); + //response of adding protected String ADD_RES = "Got it. I've added this task:\n"; Chatbox chatbox = new Chatbox(); @@ -24,7 +25,8 @@ public void addDeadline(String name, String by) { Deadline newDeadline = new Deadline(name, by); Tasks.add(newDeadline); int s = Tasks.size(); - String response = ADD_RES + newDeadline.getListName() + "\n" + "Now you have " + String.valueOf(s) + " tasks in your list."; + String response = ADD_RES + newDeadline.getListName() + + "\n" + "Now you have " + String.valueOf(s) + " tasks in your list."; chatbox.setContent(response); chatbox.chatboxPrinter(); } @@ -38,7 +40,8 @@ public void addEvent(String name, String at) { Event newEvent = new Event(name, at); Tasks.add(newEvent); int s = Tasks.size(); - String response = ADD_RES + newEvent.getListName() + "\n" + "Now you have " + String.valueOf(s) + " tasks in your list."; + String response = ADD_RES + newEvent.getListName() + + "\n" + "Now you have " + String.valueOf(s) + " tasks in your list."; chatbox.setContent(response); chatbox.chatboxPrinter(); } @@ -51,7 +54,8 @@ public void addToDo(String name) { ToDo newToDo = new ToDo(name); Tasks.add(newToDo); int s = Tasks.size(); - String response = ADD_RES + newToDo.getListName() + "\n" + "Now you have " + String.valueOf(s) + " tasks in your list."; + String response = ADD_RES + newToDo.getListName() + "\n" + + "Now you have " + String.valueOf(s) + " tasks in your list."; chatbox.setContent(response); chatbox.chatboxPrinter(); } From 3966c3568c0ebcfed5bfcdc084e9a42ab7a16abf Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Mon, 7 Feb 2022 17:04:22 +0800 Subject: [PATCH 10/45] TextUiTesting --- src/main/java/Chatbox.class | Bin 0 -> 702 bytes src/main/java/Controller.class | Bin 0 -> 2331 bytes src/main/java/Deadline.class | Bin 0 -> 1074 bytes src/main/java/Duke.class | Bin 0 -> 367 bytes src/main/java/Event.class | Bin 0 -> 1068 bytes src/main/java/OperationAnalyst.class | Bin 0 -> 1597 bytes src/main/java/Task.class | Bin 0 -> 1528 bytes src/main/java/TaskManager.class | Bin 0 -> 3224 bytes src/main/java/ToDo.class | Bin 0 -> 941 bytes text-ui-test/EXPECTED.TXT | 50 +++++++++++++++++++++++---- text-ui-test/input.txt | 11 ++++++ text-ui-test/runtest.sh | 6 +--- 12 files changed, 55 insertions(+), 12 deletions(-) create mode 100644 src/main/java/Chatbox.class create mode 100644 src/main/java/Controller.class create mode 100644 src/main/java/Deadline.class create mode 100644 src/main/java/Duke.class create mode 100644 src/main/java/Event.class create mode 100644 src/main/java/OperationAnalyst.class create mode 100644 src/main/java/Task.class create mode 100644 src/main/java/TaskManager.class create mode 100644 src/main/java/ToDo.class diff --git a/src/main/java/Chatbox.class b/src/main/java/Chatbox.class new file mode 100644 index 0000000000000000000000000000000000000000..989ddf4cf8ddd921b85744569379983d599b0b36 GIT binary patch literal 702 zcma)3T~8B16g|_{Zg-h}ZACy)1g(}e+87>7cxf<_G_A3u54@0Vo#2w~tZAo4f0hI^ z@qr(}k20LyZAyR_cal4IZ_YXQ+&fqQ{$2uTq2VBdtc9G!1LOrNr~Y@p8T$I9*&Cj! zkrBx620Ac%0@=p)pn!q^Y&cl5ASH?@30Uo~z8OY8n2jQBlqSpV+$iJhHGNv5K`@cKbi4Mvdt*nz8+I+CGSypV-^b zf%3;K2T!nW;i<$kYzWj6i?=bH;akiIHANcthu9tn6x)%W8ef}%AI_9Ot{r{hRqg~@ zb!X$DnjHGWkd@LXT}F>Y%)?Gf|w}h8+{i$#3r|q;d5np zxNv4}yc!5RPpW0)nDhM@H(7a49A61l?+=9MS{JZAw|s%>FBS#17)!_|d5%ygp}$zr zcjolk86JA)uz%w*Gq=q9u7E{yfo^QdzFY{@=K}V9S~`d%sYps48;r5#EmGnU^WGb} Sy=jx;D;%y$KQ5dIDbpU2IVHJ%OyZSGzkvu2#d=M?#?2ZXzq7& zzf>iu$}6elB}vI*#i~5!Ayxi?{D4%R@}8F@U+poxiIs5D1Km80K ziq8!cp;$w}LkZITNAcx#jJ#9UGUP@f|qSAg@H91OcQIdPQhsRTtDrlQchZ7O?PKJ z-ZwVVH_$Pt5Q?ux9`w^mcQUG@Org4M!P#$hd$W$^dsfDA1lO`B?WAjEJkQ-_Me8I= z$ixN-vG!zNUq{<$X8~8oMg_=vm5EKVuBDxcxt`3V*tVG1DmFds%%&D-)Ucf%?L5l3 zH*a7Yip9+`u?xGoFi}`gD2=c9L^bT;Nrvpq#U9(WC!Mr`>cXxX6Sb)0u9?CDQ;Xl@ z7Zvz=6Ag%vmyF{JHI7TZH`YE(McuHtH=1}%inMMek$%$TOUMIg(s0nkAvE7t!oh`% z@60F!ocSb?1GTZbVL8zgCXV1Jb7N{L`Uw4fvrgLflb(B`V2hTb1;;czX`)p~Dtpj@ zy!kwLuRY@!IDs||?It?VsZhRJ$`}(QEA*YU(;0{Ae;hC-#GN$JEk`i2?u?zjD0GSW zl!?<~*6$cK^xTP(^^>W_K{lT2q)SOepNW1vrBIY~8L7Zz(rb*lvss^g<=8W1K8``@ z_aTK%D`Y?5B7Da&Y+?jw7}s^?{dm%K6e?=#9;T9Uk`;*wk@}aT1Q5Nbx8-2vp+CvE_7R>F#?8&tPv{HsK&Bv@e*r zBJHLNW}y}aUXWUF*}yd^R#3X+B@-`8iv;|n^g=aWHSro==f$uSiH?t?1#w| z>Z|dliMIqnCqkzrDaLn9yerp5qjAXVV7k?K&&2z8ZR{6jQJ`_X6s$KpGw!5^?C})& zESXF@4*M@C=W*B`YX^OMf){so#laZ#vgrw@D=FUVSKq4r($9PYgOW>AtNwbgiNkQmH1&9wxJwd)ayaj}Uthp`Hj0 zM2K+j$9E8l)-uNu(s=n6;-f#JcNqimaD5I>3-`CsGRlN1mod78!;)nV=Xx4?i<$$G z9G?4*xqri<-TuS+ozjK6_9x{D9Qgig%6>EjZ&Qw;d8&)@tCC;RUs7J*5%}#4<<&?i zk;8>AU>7$B7I7{Tn$D{O0a4?TP%5vsmxy{S5_0qE!Jw%7Bca*6x>pl*XC#!)tChN_ zWs#7dSG6*FZw!3PXyC0W`~@lMISz2NaI|xr;uz<+63$_65z|tK9Of5so`&ZaF-mcD z5d&fuB3Q11crk}p7IE}Z_BR%>`yP7^Z!fZ~R{?UkE=4NJx9~7Fa^A!u9b}OX@#Zum zjKfOD5oPjMYCT$1C61}hXjR*BTv=#Sd(f_G_*2t@F4c-|HH4TN!D;0nuBOnd=2(JH rh+2#Cf8e7;gP|d=VT}L00_*aBW<#(v7_6!)`-}Hk;Zyn-;j@1Mdt2lc literal 0 HcmV?d00001 diff --git a/src/main/java/Deadline.class b/src/main/java/Deadline.class new file mode 100644 index 0000000000000000000000000000000000000000..ac483692a3de232b22e609a6229b6461413dca8c GIT binary patch literal 1074 zcma)5-A)rh6#k}^ZdtZJR1guRs72a>R7L!u#tYjJH3cu)U?TBix}CtX+udeoO42tm zzJS*zq6rs1fDdIn)7DTeFTdgrJkdP&87B^lma(9$^IaZO=drBN(fxYbAD4O`O6 zI~HZ{1w>fb;Jek2P6J(o5#Xd<2zs<`$Ythjy(qxcPpFa3~J`erB)6hNB?69$r$kT^$rn7}4GBaf}( zSIm6EVv+7SI@jnJXIKPIk^M{}$+!R2>oO6Xm$9fo0$ED`2s6l&HHt`fmJk;Do<*$D UtpTjlc}QL$Pz+mmf@fIx4Tx$6i2wiq literal 0 HcmV?d00001 diff --git a/src/main/java/Duke.class b/src/main/java/Duke.class new file mode 100644 index 0000000000000000000000000000000000000000..12b408fc0d2e1eb1c1b86408283f69e626aa15f3 GIT binary patch literal 367 zcmYLE%Sr=55Uk0**UdwtQ4b!xB?{&PB7#Ibt$K(A#M5LQ!X%qnS!ewv&t42D_yK-X zP`iWRz*Kd0SNHUMeZPMK7+^m}4Nd?zfd^lpHIvV>pG!0C-%MsIvjYC9Hrk#EINjbj zKqwFo3uDV7&s7;CfWxqnAmIVtv{cG+rjek@89&!gR+#{s0`5gMS46|&fvA~kqpqvP zM3uL4l5=4pwGrra@6-Q9Mz+*uI_QlB>LV+&`IUV9^T(s2Dl>JdxjEwDC)|fawCG=a zYM`Cq6K;_@AQr^l(Gud70)aLmm)RO&8#@%U^_(=1Xn!EMTOvx2-w@NSzx=G$W^Qc2 YA#@Sa8wvfnLn?$=Aqhwc?5>@Azg${CA^-pY literal 0 HcmV?d00001 diff --git a/src/main/java/Event.class b/src/main/java/Event.class new file mode 100644 index 0000000000000000000000000000000000000000..2a619b9bd1c88491baa80b5c5832c4844c302370 GIT binary patch literal 1068 zcma)5-ELAr5dM||hn^k^#nxJ@r7E>RYf)?cDaH%2jT%}nAT_b^Vu4M2%3%*VyO8uv zj4$A|iPfYRK7bEpoCT7i5YvnOnVD~9zM0wm_51uMfFibSgfL+t>>z?DL%7OSlOg)t zm9BolFqbW#@GdWSTpkrFI&kGtF?TSD7$z;)4yNERM0UDDYK9P}Ej8+36MWi10!fA` zC3M+UdY`uh!$h_pEal(|W+|_$Uip#??1Ra1)xo?;Fx`9W1n%t<$uvm6*tH;6{lw_25 z9Au2r8RpEeda2a80~$ifZ%_{sWmk&*POBz@DzAB@iBtXc<{obkWV_;bg1XpsjnVE+ zVZ)4zA^FnxwbB7^?+JbEH&h~udp0&uuyEgW=>bFLVzRF6`b{wyaKCZ8ysrJ=l;P7b z?*XtM^fi|aPpC}U_nVz|akNE4n!g;Yr)@C?emI1GS341PT^#QFAVi6KUd7d-7{ewt z`EchWV_B}ZmsyU)H&TkAkze}(mR~=EmH&?T*PhEN?J05uInbYj4GYs0kOq$AAV8h$j1XJ- zZY}j6g@Bgnv5rjJE_}Jnl@=d6OY}xNoWZ;O(|(Y15N@>2&GxQ*rRwFdu+zz zMnPiDZ-6yYB#;nP#7L;>2B{0AN~~G11N9$(SX7)hPJ)}dmge1e-@E62oO_>tefIMs z06DDd=t3xluz?7o0*QO_zRZ@TyO~|yxMvr9f#|g3I{u76Xe_m+K@$*zI&{QiFbwpd z_c_#x?>X+KK%`zPJ4BC;<^Olty3D24Up(tZ0>@%74fNwUJucU5Px?;Pz2VC8PMw~# zEqiCX>J{q({V#EF!oW$KqNyjh7u;HdD6>w92|_{8c{7K`|>1jsZrUmy;ZrPMnK=R z{n=`zBHg0E@v#oM3G}S^vaq!%Yx|fuF{}GYk_x3UJNjCwHoSs8?5DA{d9=xzA> zLwGbeJi(Q-%azH9&*>~onNX&ST{D>`Qr{BcEBKSAgMU#vn2bK5T*uYYJmq5KvG*0_ z^|RsM?@*3s%!^HAzr?lB%r2%f=47B{!_=&dc_q+>BGk@g%r^q9KT54PW4;+^k=V?@ zH+00`7cHT3!U#VVuf*>&^)bh!nIm0!D;=6JubJ1IxUq*hD;=KL!>wK91B>?$Ef!y} zuoS~dbNS$67pDTwm4mrm#Di;Y73p08=`$o3IESy<`0sEY4@vni{8xBP+J7UHe;|cF zVc{t<_!}4TFD{EP#zhR1q7PTFM)XM-&oGS`bkW0~J~A|P%=m}8z{efCHg~jZQ#8HP Q(e&0)(`lN15~P3kKL!R(W&i*H literal 0 HcmV?d00001 diff --git a/src/main/java/Task.class b/src/main/java/Task.class new file mode 100644 index 0000000000000000000000000000000000000000..065dbde04143d7796107fa429a8f5aee701c5e7c GIT binary patch literal 1528 zcmaJ=+j0^?5IsW(%VkX>xfvrdYND`F@qWW=(0C(i6)Ck$`7j|?g5)lkph}sxNOknJ-d?)iY>22ko zZoE|$EfBlzdak}HFqF+bk0Z{@`uytzl1N#wZS2E{Ky*z8Re_O~SC`GI+AM3STY*5j zw41Q3o36K2h-1v8cp0Wh+ZZ=^yB8M6qyS8XX&VR3-*L_KPh?#g=Rq5@I7DJ@aM$;g zfOuuxb2bi#u{Af)CN@du5gSKMU#URpQrDkm=L@!E~~2Odlji)xcUumftH>o z^DEhY>iwQvzbk<(auysLOE|el(eienRh`ZIE$TYifx3SF8FkTAN6C62iPOkiIAh~1 z&Iyc%^6iZguo?zY^O$4+%iMF$qv&r^nbDH#sVA-ahH9?KjT$|vEv3z@j6ebt*#Qj* z?Bn<<)m7Q(0sU2vxy`I7e`nTAX@(Q_pqc{7vfpY})QW4WB}}Q)rUweK?E5;+jTdvlk|b~Hft(a zDEWT1)hP5&r^mAgxVGI;1H#vP;yVjb=vAznq9|*%va1!}_KHA62tMeCo~N3{nhXLJ zSa>L~*w@=2$`&3A%>6%<+IRZH5kBz9%wjr~q~qKzqMsEwKMnsJuQ_czRcX1Krwp2xYOK%6Bbq%njs z-lmv*7BLb_@c$$nq!@h>m%0TrwA^hBJ6|#NX(v@IbdK=kw(>OG)|t|To?__C2TVJ( z2?P6qV?Z03kC-sN{k=ZJE)ud!lMRq&!{cN$iIbSdWqQbVc8rOy4CIvgm(xLpUftp3 zFuCEBbfQL?J#vhYFEB>|4zu}r#$6kL3l$xJJ4W0Baf`$ic5o-U^-^DOf^BBL;nc4F jozZ8ha*n01vv>qIaFaI9B)9mxhx>*sZx8SYCCvN*M@B!( literal 0 HcmV?d00001 diff --git a/src/main/java/TaskManager.class b/src/main/java/TaskManager.class new file mode 100644 index 0000000000000000000000000000000000000000..dcd4b044fcbbef1aee529112381c3faba079b0d9 GIT binary patch literal 3224 zcmb7FX>;4w6+KU+1QLcfBvv9zcHr32Zm~^L*&=17iX_{zDakQiyN;XM5D81LC_n)~ zB}$icN%t+?({xRyGydE(kvq~%r=L6hMXjgpxd5%Dq%-aZJ`nF++K+-S&} z?pbv#yHar~R5CKl~z-hW-kex$_LV+J0_As&>I1BGm{Zo@C0P)JJz9qs6lEDkFi>TUGh zcU63K890KY3a#=0sjj6Dpys z(D$-Qa=Q)mpjY9EWqZk)@V&AfU2~&F{tF}9ix|AS8O%oHLPWoT0m)1coroSH$BSh9 zq=6wR+rBzAmq=se1R6e}kePJsO4aoo9XUKJ%si*i(u@ZG+YoZ`IEkmX>`aklEJLPvGYzqo%0th z@+Zo%T+dqbYk^fI19?4zOA61F{2*8x6r;fD2`$f$ZN*f+6H6=KE6iRtP{I{bN(vh? zuZu|ZJYuptuSxo!RXF`f={HH%L<-kTq|u$l=kSV#&l|XjTf6JA7Dmo85&1Pil#uB9 zxmZvvmSZooE9OzwP%+?u1xvbOw+#!rA`+~6WReBtyjWB~26q&W*XfzI%6_d{Aw7|G z+x290B&1sToFrW}uq>KRFWbRVmK(l-6&WNMVNld&Qp??98XAbiw5{fev57X>w~*q9 zD7g!s9n}JA^GK4;?gkz$$_OZoQOW5Eze2P9MK;T9ZF$}auGsTc?r3arv7*@d??FEi z3EyJz)J-UvI=sYsZz;0NoOvsCKN&%n9O((v>td=9b0u56Lz&)awDgZ z!4DH|ol4$P8NAJ&Qc9ooUz1+57H!@(s!9J1W$+VLQ4PsQKT~K?eEve7Y|M8!XJ_5A zb1b>7q!K%?E6Wb8itjmjo!`8xFgSN{@ZpxCS+Ta(9Cp1@Fs41v2_~v`7&@Vb-x6^{ z5t?zU;rF~pKi-tOP6~lzyt!I+9zHos=O@KEpX+#jI8DDpTbiZ<8V;;QZoQkF@SRq191NT0nkeTeFV@?00RUtNB}1ZV2A*61n}i8 zc2~%)@HD!KX<_%`7P|=nW0F7FE*{xRUnns<(hpC6n4F&?)2HzyMyQ=UF%0>{pjbCgSKfzCRlLltw_4QQ|7;4}f!%0ZV$}^(9l!)JOv2y=Y~mctbe<}iCguw~ zxrjLw8Rs1DtxKrjB`o1GzQV6~o!y72;mmy~^)HP7lPoHH6}P#H@_$XQqT132xIrP= z=E6*8`aSIJOp^K|({yLB@tomUg~=2yX+g0yB~TOR!VoNdny@8cbeewmNQ5 zcdt-mH(BOe1V2ysWx}n*fOVwqql183j}zk8wt&7}2U>hIgh2zs+Q%VG`eBJNs-(=L zAXa!)yh#d;{O) obC7g=izh#b*B`~}kK^^H@%r<4{bjuVigg01Q}_*jhd-d>zo8$llJr+X2_YLN&m$7 z13sH*O#0vl_)*3^a1v=CKFppyD{HTPnVH{zE`I@N;zbrQ#2qADB#~lBbh-8!Qm;Je znb!>K)%F=b=Z%2NlSapco;+#Rjx$Ij;~?u|1+EQJ`-*}*y|1KTU>_|Z=OT{+LvA8R zJoLq|W4M`UhT@{67dKF1D2=!;T1pPM`QVvT^0eX7klM>7 z6)q;IEkZWuhKpO%oPno}&1u2gF78;+y;^pnrH0g8zU@hIG#T|p*ya6zkQFUVJBnwB zS8K-%tJLhkKjhdRVhO!B z$A8~H69dznA8;hm;z7{yjA*8@%aH7KKQTsAeJ7;|TLITvXa`Riwieo3R<(m?44eO_ z(i@z$i2HPpF?v5BOSzFEyGf@9bhdb^zWo#I8+ig 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 +diff ACTUAL.TXT EXPECTED.TXT if [ $? -eq 0 ] then echo "Test result: PASSED" From fd7236a32d66c6d5a303dcd8a33ca1d627eb6ad6 Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Thu, 17 Feb 2022 13:10:32 +0800 Subject: [PATCH 11/45] Save/Delete/Exception --- data/Duke.txt | 1 + src/main/java/Chatbox.class | Bin 702 -> 0 bytes src/main/java/Controller.class | Bin 2331 -> 0 bytes src/main/java/Controller.java | 106 ++++++++++++------ src/main/java/Deadline.class | Bin 1074 -> 0 bytes src/main/java/Duke.class | Bin 367 -> 0 bytes src/main/java/Duke.java | 6 +- src/main/java/DukeException.java | 2 + src/main/java/Event.class | Bin 1068 -> 0 bytes src/main/java/IllegalFormatException.java | 2 + .../java/IllegalInstructionException.java | 3 + src/main/java/IllegalSavingAction.java | 2 + src/main/java/IllegalTaskIndexException.java | 2 + src/main/java/IllegalTaskNameException.java | 2 + src/main/java/META-INF/MANIFEST.MF | 3 + src/main/java/OperationAnalyst.class | Bin 1597 -> 0 bytes src/main/java/OperationAnalyst.java | 33 +++++- src/main/java/Task.class | Bin 1528 -> 0 bytes src/main/java/TaskManager.class | Bin 3224 -> 0 bytes src/main/java/TaskManager.java | 46 +++++++- src/main/java/ToDo.class | Bin 941 -> 0 bytes 21 files changed, 165 insertions(+), 43 deletions(-) create mode 100644 data/Duke.txt delete mode 100644 src/main/java/Chatbox.class delete mode 100644 src/main/java/Controller.class delete mode 100644 src/main/java/Deadline.class delete mode 100644 src/main/java/Duke.class create mode 100644 src/main/java/DukeException.java delete mode 100644 src/main/java/Event.class create mode 100644 src/main/java/IllegalFormatException.java create mode 100644 src/main/java/IllegalInstructionException.java create mode 100644 src/main/java/IllegalSavingAction.java create mode 100644 src/main/java/IllegalTaskIndexException.java create mode 100644 src/main/java/IllegalTaskNameException.java create mode 100644 src/main/java/META-INF/MANIFEST.MF delete mode 100644 src/main/java/OperationAnalyst.class delete mode 100644 src/main/java/Task.class delete mode 100644 src/main/java/TaskManager.class delete mode 100644 src/main/java/ToDo.class diff --git a/data/Duke.txt b/data/Duke.txt new file mode 100644 index 000000000..b255a5e1f --- /dev/null +++ b/data/Duke.txt @@ -0,0 +1 @@ +[T][ ]ddd diff --git a/src/main/java/Chatbox.class b/src/main/java/Chatbox.class deleted file mode 100644 index 989ddf4cf8ddd921b85744569379983d599b0b36..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 702 zcma)3T~8B16g|_{Zg-h}ZACy)1g(}e+87>7cxf<_G_A3u54@0Vo#2w~tZAo4f0hI^ z@qr(}k20LyZAyR_cal4IZ_YXQ+&fqQ{$2uTq2VBdtc9G!1LOrNr~Y@p8T$I9*&Cj! zkrBx620Ac%0@=p)pn!q^Y&cl5ASH?@30Uo~z8OY8n2jQBlqSpV+$iJhHGNv5K`@cKbi4Mvdt*nz8+I+CGSypV-^b zf%3;K2T!nW;i<$kYzWj6i?=bH;akiIHANcthu9tn6x)%W8ef}%AI_9Ot{r{hRqg~@ zb!X$DnjHGWkd@LXT}F>Y%)?Gf|w}h8+{i$#3r|q;d5np zxNv4}yc!5RPpW0)nDhM@H(7a49A61l?+=9MS{JZAw|s%>FBS#17)!_|d5%ygp}$zr zcjolk86JA)uz%w*Gq=q9u7E{yfo^QdzFY{@=K}V9S~`d%sYps48;r5#EmGnU^WGb} Sy=jx;D;%y$KQ5dIDbpU2IVHJ%OyZSGzkvu2#d=M?#?2ZXzq7& zzf>iu$}6elB}vI*#i~5!Ayxi?{D4%R@}8F@U+poxiIs5D1Km80K ziq8!cp;$w}LkZITNAcx#jJ#9UGUP@f|qSAg@H91OcQIdPQhsRTtDrlQchZ7O?PKJ z-ZwVVH_$Pt5Q?ux9`w^mcQUG@Org4M!P#$hd$W$^dsfDA1lO`B?WAjEJkQ-_Me8I= z$ixN-vG!zNUq{<$X8~8oMg_=vm5EKVuBDxcxt`3V*tVG1DmFds%%&D-)Ucf%?L5l3 zH*a7Yip9+`u?xGoFi}`gD2=c9L^bT;Nrvpq#U9(WC!Mr`>cXxX6Sb)0u9?CDQ;Xl@ z7Zvz=6Ag%vmyF{JHI7TZH`YE(McuHtH=1}%inMMek$%$TOUMIg(s0nkAvE7t!oh`% z@60F!ocSb?1GTZbVL8zgCXV1Jb7N{L`Uw4fvrgLflb(B`V2hTb1;;czX`)p~Dtpj@ zy!kwLuRY@!IDs||?It?VsZhRJ$`}(QEA*YU(;0{Ae;hC-#GN$JEk`i2?u?zjD0GSW zl!?<~*6$cK^xTP(^^>W_K{lT2q)SOepNW1vrBIY~8L7Zz(rb*lvss^g<=8W1K8``@ z_aTK%D`Y?5B7Da&Y+?jw7}s^?{dm%K6e?=#9;T9Uk`;*wk@}aT1Q5Nbx8-2vp+CvE_7R>F#?8&tPv{HsK&Bv@e*r zBJHLNW}y}aUXWUF*}yd^R#3X+B@-`8iv;|n^g=aWHSro==f$uSiH?t?1#w| z>Z|dliMIqnCqkzrDaLn9yerp5qjAXVV7k?K&&2z8ZR{6jQJ`_X6s$KpGw!5^?C})& zESXF@4*M@C=W*B`YX^OMf){so#laZ#vgrw@D=FUVSKq4r($9PYgOW>AtNwbgiNkQmH1&9wxJwd)ayaj}Uthp`Hj0 zM2K+j$9E8l)-uNu(s=n6;-f#JcNqimaD5I>3-`CsGRlN1mod78!;)nV=Xx4?i<$$G z9G?4*xqri<-TuS+ozjK6_9x{D9Qgig%6>EjZ&Qw;d8&)@tCC;RUs7J*5%}#4<<&?i zk;8>AU>7$B7I7{Tn$D{O0a4?TP%5vsmxy{S5_0qE!Jw%7Bca*6x>pl*XC#!)tChN_ zWs#7dSG6*FZw!3PXyC0W`~@lMISz2NaI|xr;uz<+63$_65z|tK9Of5so`&ZaF-mcD z5d&fuB3Q11crk}p7IE}Z_BR%>`yP7^Z!fZ~R{?UkE=4NJx9~7Fa^A!u9b}OX@#Zum zjKfOD5oPjMYCT$1C61}hXjR*BTv=#Sd(f_G_*2t@F4c-|HH4TN!D;0nuBOnd=2(JH rh+2#Cf8e7;gP|d=VT}L00_*aBW<#(v7_6!)`-}Hk;Zyn-;j@1Mdt2lc diff --git a/src/main/java/Controller.java b/src/main/java/Controller.java index 6f85d2342..a8bdb12de 100644 --- a/src/main/java/Controller.java +++ b/src/main/java/Controller.java @@ -1,6 +1,8 @@ +import java.io.File; import java.util.Locale; import java.util.Scanner; - +import java.io.FileWriter; +import java.io.IOException; public class Controller { //greeting msg and exit msg protected String HELLO_WORDS = "Hello! I'm Duke :P\nWhat can I do for you?"; @@ -31,53 +33,87 @@ public void bye() { /** * Unmarks task in the list */ - public void unmarkTask(){ - int index= Integer.parseInt(analyst.taskName); - manager.unmarkTask(index); + public void unmarkTask() throws DukeException{ + try { + int index = Integer.parseInt(analyst.taskName); + manager.unmarkTask(index); + } catch (NumberFormatException e) { + throw new IllegalTaskIndexException(); + } } /** * Marks task in the list */ - public void markTask(){ - int index= Integer.parseInt(analyst.taskName); - manager.markTask(index); + public void markTask() throws DukeException{ + try { + int index = Integer.parseInt(analyst.taskName); + manager.markTask(index); + } catch (NumberFormatException e) { + throw new IllegalTaskIndexException(); + } + } + + public void deleteTask() throws DukeException{ + try { + int index = Integer.parseInt(analyst.taskName); + manager.deleteTask(index); + } catch (NumberFormatException e) { + throw new IllegalTaskIndexException(); + } } /** * Listen the instruction and operate during the session */ - public void listen() { + public void listen() throws DukeException { Scanner msg = new Scanner(System.in); this.recvMsg = msg.nextLine(); - analyst = new OperationAnalyst(this.recvMsg); - String command = analyst.getCommand(); - switch (command) { - case "bye": - this.bye(); - break; - case "list": - manager.listTask(); - break; - case "mark": - this.markTask(); - break; - case "unmark": - this.unmarkTask(); - break; - case "deadline": - manager.addDeadline(analyst.taskName, analyst.time); - break; - case "event": - manager.addEvent(analyst.taskName, analyst.time); - break; - case "todo": - manager.addToDo(analyst.taskName); - break; - default: - manager.addTask(analyst.taskName); + try { + analyst = new OperationAnalyst(this.recvMsg); + String command = analyst.getCommand(); + switch (command) { + case "bye": + this.bye(); + break; + case "list": + manager.listTask(); + break; + case "mark": + this.markTask(); + break; + case "unmark": + this.unmarkTask(); + break; + case "deadline": + manager.addDeadline(analyst.taskName, analyst.time); + break; + case "event": + manager.addEvent(analyst.taskName, analyst.time); + break; + case "todo": + manager.addToDo(analyst.taskName); + break; + case "delete": + this.deleteTask(); + } + manager.saveTask(); + } catch (IllegalInstructionException e){ + chatbox.setContent("Sorry, I don't understand your instruction :("); + chatbox.chatboxPrinter(); + } catch (IllegalFormatException e) { + chatbox.setContent("Please check your format again :("); + chatbox.chatboxPrinter(); + } catch (IllegalTaskNameException e) { + chatbox.setContent("Did you specify your task name?"); + chatbox.chatboxPrinter(); + } catch (IllegalSavingAction e) { + chatbox.setContent("Cannot save to file :("); + chatbox.chatboxPrinter(); + } catch (IllegalTaskIndexException e) { + chatbox.setContent("Please specify the index of the task :("); + chatbox.chatboxPrinter(); } } - } \ No newline at end of file diff --git a/src/main/java/Deadline.class b/src/main/java/Deadline.class deleted file mode 100644 index ac483692a3de232b22e609a6229b6461413dca8c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1074 zcma)5-A)rh6#k}^ZdtZJR1guRs72a>R7L!u#tYjJH3cu)U?TBix}CtX+udeoO42tm zzJS*zq6rs1fDdIn)7DTeFTdgrJkdP&87B^lma(9$^IaZO=drBN(fxYbAD4O`O6 zI~HZ{1w>fb;Jek2P6J(o5#Xd<2zs<`$Ythjy(qxcPpFa3~J`erB)6hNB?69$r$kT^$rn7}4GBaf}( zSIm6EVv+7SI@jnJXIKPIk^M{}$+!R2>oO6Xm$9fo0$ED`2s6l&HHt`fmJk;Do<*$D UtpTjlc}QL$Pz+mmf@fIx4Tx$6i2wiq diff --git a/src/main/java/Duke.class b/src/main/java/Duke.class deleted file mode 100644 index 12b408fc0d2e1eb1c1b86408283f69e626aa15f3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 367 zcmYLE%Sr=55Uk0**UdwtQ4b!xB?{&PB7#Ibt$K(A#M5LQ!X%qnS!ewv&t42D_yK-X zP`iWRz*Kd0SNHUMeZPMK7+^m}4Nd?zfd^lpHIvV>pG!0C-%MsIvjYC9Hrk#EINjbj zKqwFo3uDV7&s7;CfWxqnAmIVtv{cG+rjek@89&!gR+#{s0`5gMS46|&fvA~kqpqvP zM3uL4l5=4pwGrra@6-Q9Mz+*uI_QlB>LV+&`IUV9^T(s2Dl>JdxjEwDC)|fawCG=a zYM`Cq6K;_@AQr^l(Gud70)aLmm)RO&8#@%U^_(=1Xn!EMTOvx2-w@NSzx=G$W^Qc2 YA#@Sa8wvfnLn?$=Aqhwc?5>@Azg${CA^-pY diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 99328315c..7f3b3bbac 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,6 +1,10 @@ +import java.io.File; import java.util.Scanner; +import java.io.FileWriter; +import java.io.IOException; + public class Duke { - public static void main(String[] args) { + public static void main(String[] args) throws DukeException{ Controller bot = new Controller(); bot.greet(); while(true){ //opens a new session for receiving instructions diff --git a/src/main/java/DukeException.java b/src/main/java/DukeException.java new file mode 100644 index 000000000..9b807163e --- /dev/null +++ b/src/main/java/DukeException.java @@ -0,0 +1,2 @@ +public abstract class DukeException extends Exception{ +} diff --git a/src/main/java/Event.class b/src/main/java/Event.class deleted file mode 100644 index 2a619b9bd1c88491baa80b5c5832c4844c302370..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1068 zcma)5-ELAr5dM||hn^k^#nxJ@r7E>RYf)?cDaH%2jT%}nAT_b^Vu4M2%3%*VyO8uv zj4$A|iPfYRK7bEpoCT7i5YvnOnVD~9zM0wm_51uMfFibSgfL+t>>z?DL%7OSlOg)t zm9BolFqbW#@GdWSTpkrFI&kGtF?TSD7$z;)4yNERM0UDDYK9P}Ej8+36MWi10!fA` zC3M+UdY`uh!$h_pEal(|W+|_$Uip#??1Ra1)xo?;Fx`9W1n%t<$uvm6*tH;6{lw_25 z9Au2r8RpEeda2a80~$ifZ%_{sWmk&*POBz@DzAB@iBtXc<{obkWV_;bg1XpsjnVE+ zVZ)4zA^FnxwbB7^?+JbEH&h~udp0&uuyEgW=>bFLVzRF6`b{wyaKCZ8ysrJ=l;P7b z?*XtM^fi|aPpC}U_nVz|akNE4n!g;Yr)@C?emI1GS341PT^#QFAVi6KUd7d-7{ewt z`EchWV_B}ZmsyU)H&TkAkze}(mR~=EmH&?T*PhEN?J05uInbYj4GYs0kOq$AAV8h$j1XJ- zZY}j6g@Bgnv5rjJE_}Jnl@=d6OY}xNoWZ;O(|(Y15N@>2&GxQ*rRwFdu+zz zMnPiDZ-6yYB#;nP#7L;>2B{0AN~~G11N9$(SX7)hPJ)}dmge1e-@E62oO_>tefIMs z06DDd=t3xluz?7o0*QO_zRZ@TyO~|yxMvr9f#|g3I{u76Xe_m+K@$*zI&{QiFbwpd z_c_#x?>X+KK%`zPJ4BC;<^Olty3D24Up(tZ0>@%74fNwUJucU5Px?;Pz2VC8PMw~# zEqiCX>J{q({V#EF!oW$KqNyjh7u;HdD6>w92|_{8c{7K`|>1jsZrUmy;ZrPMnK=R z{n=`zBHg0E@v#oM3G}S^vaq!%Yx|fuF{}GYk_x3UJNjCwHoSs8?5DA{d9=xzA> zLwGbeJi(Q-%azH9&*>~onNX&ST{D>`Qr{BcEBKSAgMU#vn2bK5T*uYYJmq5KvG*0_ z^|RsM?@*3s%!^HAzr?lB%r2%f=47B{!_=&dc_q+>BGk@g%r^q9KT54PW4;+^k=V?@ zH+00`7cHT3!U#VVuf*>&^)bh!nIm0!D;=6JubJ1IxUq*hD;=KL!>wK91B>?$Ef!y} zuoS~dbNS$67pDTwm4mrm#Di;Y73p08=`$o3IESy<`0sEY4@vni{8xBP+J7UHe;|cF zVc{t<_!}4TFD{EP#zhR1q7PTFM)XM-&oGS`bkW0~J~A|P%=m}8z{efCHg~jZQ#8HP Q(e&0)(`lN15~P3kKL!R(W&i*H diff --git a/src/main/java/OperationAnalyst.java b/src/main/java/OperationAnalyst.java index e8eb630b6..6315bcdd7 100644 --- a/src/main/java/OperationAnalyst.java +++ b/src/main/java/OperationAnalyst.java @@ -7,11 +7,14 @@ public class OperationAnalyst { protected String taskName; protected String instruction; - public OperationAnalyst(String input){ + public OperationAnalyst(String input) throws DukeException { this.keywords = input.split(" "); this.rawInput = input; this.instruction = keywords[0].toLowerCase(Locale.ROOT); + //System.out.println(this.instruction); parseInstruction(); + //System.out.println(this.instruction); + //System.out.println(this.taskName); } /** @@ -25,30 +28,48 @@ public String getCommand() { /** * Analyses raw input to determine the task name and time */ - public void parseInstruction() { + public void parseInstruction() throws DukeException{ //String name; String[] command; switch (this.instruction) { case "deadline": command = rawInput.split("/by "); this.taskName = command[0].replace("deadline ", ""); - this.time = command[1]; + try { + this.time = command[1]; + } catch (IndexOutOfBoundsException e){ + throw new IllegalFormatException(); + } //System.out.println(this.time); break; case "event": command = rawInput.split("/at "); this.taskName = command[0].replace("event ", ""); - this.time = command[1]; + try { + this.time = command[1]; + } catch (IndexOutOfBoundsException e){ + throw new IllegalFormatException(); + } break; case "todo": this.taskName = rawInput.replace("todo ", ""); break; case "mark": case "unmark": - this.taskName = this.keywords[1]; + case "delete": + try { + this.taskName = this.keywords[1]; + } catch (IndexOutOfBoundsException e){ + throw new IllegalFormatException(); + } + break; + case "list" : + break; + case "bye" : break; default: - this.taskName = rawInput; + this.instruction = "unknown"; + throw new IllegalInstructionException(); } } diff --git a/src/main/java/Task.class b/src/main/java/Task.class deleted file mode 100644 index 065dbde04143d7796107fa429a8f5aee701c5e7c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1528 zcmaJ=+j0^?5IsW(%VkX>xfvrdYND`F@qWW=(0C(i6)Ck$`7j|?g5)lkph}sxNOknJ-d?)iY>22ko zZoE|$EfBlzdak}HFqF+bk0Z{@`uytzl1N#wZS2E{Ky*z8Re_O~SC`GI+AM3STY*5j zw41Q3o36K2h-1v8cp0Wh+ZZ=^yB8M6qyS8XX&VR3-*L_KPh?#g=Rq5@I7DJ@aM$;g zfOuuxb2bi#u{Af)CN@du5gSKMU#URpQrDkm=L@!E~~2Odlji)xcUumftH>o z^DEhY>iwQvzbk<(auysLOE|el(eienRh`ZIE$TYifx3SF8FkTAN6C62iPOkiIAh~1 z&Iyc%^6iZguo?zY^O$4+%iMF$qv&r^nbDH#sVA-ahH9?KjT$|vEv3z@j6ebt*#Qj* z?Bn<<)m7Q(0sU2vxy`I7e`nTAX@(Q_pqc{7vfpY})QW4WB}}Q)rUweK?E5;+jTdvlk|b~Hft(a zDEWT1)hP5&r^mAgxVGI;1H#vP;yVjb=vAznq9|*%va1!}_KHA62tMeCo~N3{nhXLJ zSa>L~*w@=2$`&3A%>6%<+IRZH5kBz9%wjr~q~qKzqMsEwKMnsJuQ_czRcX1Krwp2xYOK%6Bbq%njs z-lmv*7BLb_@c$$nq!@h>m%0TrwA^hBJ6|#NX(v@IbdK=kw(>OG)|t|To?__C2TVJ( z2?P6qV?Z03kC-sN{k=ZJE)ud!lMRq&!{cN$iIbSdWqQbVc8rOy4CIvgm(xLpUftp3 zFuCEBbfQL?J#vhYFEB>|4zu}r#$6kL3l$xJJ4W0Baf`$ic5o-U^-^DOf^BBL;nc4F jozZ8ha*n01vv>qIaFaI9B)9mxhx>*sZx8SYCCvN*M@B!( diff --git a/src/main/java/TaskManager.class b/src/main/java/TaskManager.class deleted file mode 100644 index dcd4b044fcbbef1aee529112381c3faba079b0d9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3224 zcmb7FX>;4w6+KU+1QLcfBvv9zcHr32Zm~^L*&=17iX_{zDakQiyN;XM5D81LC_n)~ zB}$icN%t+?({xRyGydE(kvq~%r=L6hMXjgpxd5%Dq%-aZJ`nF++K+-S&} z?pbv#yHar~R5CKl~z-hW-kex$_LV+J0_As&>I1BGm{Zo@C0P)JJz9qs6lEDkFi>TUGh zcU63K890KY3a#=0sjj6Dpys z(D$-Qa=Q)mpjY9EWqZk)@V&AfU2~&F{tF}9ix|AS8O%oHLPWoT0m)1coroSH$BSh9 zq=6wR+rBzAmq=se1R6e}kePJsO4aoo9XUKJ%si*i(u@ZG+YoZ`IEkmX>`aklEJLPvGYzqo%0th z@+Zo%T+dqbYk^fI19?4zOA61F{2*8x6r;fD2`$f$ZN*f+6H6=KE6iRtP{I{bN(vh? zuZu|ZJYuptuSxo!RXF`f={HH%L<-kTq|u$l=kSV#&l|XjTf6JA7Dmo85&1Pil#uB9 zxmZvvmSZooE9OzwP%+?u1xvbOw+#!rA`+~6WReBtyjWB~26q&W*XfzI%6_d{Aw7|G z+x290B&1sToFrW}uq>KRFWbRVmK(l-6&WNMVNld&Qp??98XAbiw5{fev57X>w~*q9 zD7g!s9n}JA^GK4;?gkz$$_OZoQOW5Eze2P9MK;T9ZF$}auGsTc?r3arv7*@d??FEi z3EyJz)J-UvI=sYsZz;0NoOvsCKN&%n9O((v>td=9b0u56Lz&)awDgZ z!4DH|ol4$P8NAJ&Qc9ooUz1+57H!@(s!9J1W$+VLQ4PsQKT~K?eEve7Y|M8!XJ_5A zb1b>7q!K%?E6Wb8itjmjo!`8xFgSN{@ZpxCS+Ta(9Cp1@Fs41v2_~v`7&@Vb-x6^{ z5t?zU;rF~pKi-tOP6~lzyt!I+9zHos=O@KEpX+#jI8DDpTbiZ<8V;;QZoQkF@SRq191NT0nkeTeFV@?00RUtNB}1ZV2A*61n}i8 zc2~%)@HD!KX<_%`7P|=nW0F7FE*{xRUnns<(hpC6n4F&?)2HzyMyQ=UF%0>{pjbCgSKfzCRlLltw_4QQ|7;4}f!%0ZV$}^(9l!)JOv2y=Y~mctbe<}iCguw~ zxrjLw8Rs1DtxKrjB`o1GzQV6~o!y72;mmy~^)HP7lPoHH6}P#H@_$XQqT132xIrP= z=E6*8`aSIJOp^K|({yLB@tomUg~=2yX+g0yB~TOR!VoNdny@8cbeewmNQ5 zcdt-mH(BOe1V2ysWx}n*fOVwqql183j}zk8wt&7}2U>hIgh2zs+Q%VG`eBJNs-(=L zAXa!)yh#d;{O) obC7g=izh#b*B`~}kK^^H@%r<4{bjuVigg01Q}_*jhd-d>zo Tasks = new ArrayList(); //response of adding protected String ADD_RES = "Got it. I've added this task:\n"; Chatbox chatbox = new Chatbox(); + public void saveTask() throws DukeException{ + String content = ""; + for(int i = 0;i < Tasks.size();i++){ + content += Tasks.get(i).getListName(); + content += "\n"; + } + if(null != content){ + try{ + File file = new File("data/Duke.txt"); + if(!file.exists()){ + File dir = new File(file.getParent()); + dir.mkdirs(); + file.createNewFile(); + } + FileWriter outStream = new FileWriter(file); + outStream.write(content); + outStream.close(); + } catch (Exception e){ + throw new IllegalSavingAction(); + } + } + + } + /** * Adds a general task in the list * @param name refers to the name of the task @@ -86,7 +115,7 @@ public void listTask() { * @param n refers to the index of the task in adding time order */ public void markTask(int n) { - System.out.println(n); + //System.out.println(n); String content = ""; if(n < 1 || n > Tasks.size()) { //Beyonds boundaries @@ -116,5 +145,20 @@ public void unmarkTask(int n) { chatbox.chatboxPrinter(); } + public void deleteTask(int n) { + String content = ""; + if(n < 1 || n > Tasks.size()) { + //Beyonds boundaries + content = "Sorry, I could not find the task :/"; + }else { + content = "Okay! I've deleted this task:\n" + Tasks.get(n - 1).listName; + Tasks.remove(n-1); + int s = Tasks.size(); + content += "\nNow you have " + String.valueOf(s) + " tasks in your list"; + } + chatbox.setContent(content); + chatbox.chatboxPrinter(); + } + } diff --git a/src/main/java/ToDo.class b/src/main/java/ToDo.class deleted file mode 100644 index 0e226117f6ebea5abbc37be5657e3a9205af0317..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 941 zcmaJ=+ip@p6kWsZ06hi7R;*~fQ3ZOz+k*+l2Wc8jXnlaxMB>8$llJr+X2_YLN&m$7 z13sH*O#0vl_)*3^a1v=CKFppyD{HTPnVH{zE`I@N;zbrQ#2qADB#~lBbh-8!Qm;Je znb!>K)%F=b=Z%2NlSapco;+#Rjx$Ij;~?u|1+EQJ`-*}*y|1KTU>_|Z=OT{+LvA8R zJoLq|W4M`UhT@{67dKF1D2=!;T1pPM`QVvT^0eX7klM>7 z6)q;IEkZWuhKpO%oPno}&1u2gF78;+y;^pnrH0g8zU@hIG#T|p*ya6zkQFUVJBnwB zS8K-%tJLhkKjhdRVhO!B z$A8~H69dznA8;hm;z7{yjA*8@%aH7KKQTsAeJ7;|TLITvXa`Riwieo3R<(m?44eO_ z(i@z$i2HPpF?v5BOSzFEyGf@9bhdb^zWo#I8+ig Date: Thu, 17 Feb 2022 13:41:47 +0800 Subject: [PATCH 12/45] Level-5 --- src/main/java/Controller.java | 8 +++++--- src/main/java/TaskManager.java | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/Controller.java b/src/main/java/Controller.java index a8bdb12de..f9c7e49b4 100644 --- a/src/main/java/Controller.java +++ b/src/main/java/Controller.java @@ -54,6 +54,7 @@ public void markTask() throws DukeException{ } } + /** public void deleteTask() throws DukeException{ try { int index = Integer.parseInt(analyst.taskName); @@ -62,6 +63,7 @@ public void deleteTask() throws DukeException{ throw new IllegalTaskIndexException(); } } + */ /** * Listen the instruction and operate during the session @@ -94,10 +96,10 @@ public void listen() throws DukeException { case "todo": manager.addToDo(analyst.taskName); break; - case "delete": - this.deleteTask(); + //case "delete": + //this.deleteTask(); } - manager.saveTask(); + //manager.saveTask(); } catch (IllegalInstructionException e){ chatbox.setContent("Sorry, I don't understand your instruction :("); chatbox.chatboxPrinter(); diff --git a/src/main/java/TaskManager.java b/src/main/java/TaskManager.java index fea9b618a..15b4d6d57 100644 --- a/src/main/java/TaskManager.java +++ b/src/main/java/TaskManager.java @@ -10,6 +10,7 @@ public class TaskManager { protected String ADD_RES = "Got it. I've added this task:\n"; Chatbox chatbox = new Chatbox(); + /** public void saveTask() throws DukeException{ String content = ""; for(int i = 0;i < Tasks.size();i++){ @@ -33,6 +34,7 @@ public void saveTask() throws DukeException{ } } + */ /** * Adds a general task in the list From a463ffebcf4cc0d2337929d1f24e75a8a135d81d Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Thu, 17 Feb 2022 14:01:32 +0800 Subject: [PATCH 13/45] Revert --- data/Duke.txt | 1 - src/main/java/Controller.java | 57 ++++++++++++++----- src/main/java/Duke.java | 6 +- src/main/java/DukeException.java | 2 - src/main/java/IllegalFormatException.java | 2 - .../java/IllegalInstructionException.java | 3 - src/main/java/IllegalSavingAction.java | 2 - src/main/java/IllegalTaskIndexException.java | 2 - src/main/java/IllegalTaskNameException.java | 2 - src/main/java/META-INF/MANIFEST.MF | 3 - src/main/java/OperationAnalyst.java | 33 ++--------- src/main/java/TaskManager.java | 23 +------- 12 files changed, 51 insertions(+), 85 deletions(-) delete mode 100644 data/Duke.txt delete mode 100644 src/main/java/DukeException.java delete mode 100644 src/main/java/IllegalFormatException.java delete mode 100644 src/main/java/IllegalInstructionException.java delete mode 100644 src/main/java/IllegalSavingAction.java delete mode 100644 src/main/java/IllegalTaskIndexException.java delete mode 100644 src/main/java/IllegalTaskNameException.java delete mode 100644 src/main/java/META-INF/MANIFEST.MF diff --git a/data/Duke.txt b/data/Duke.txt deleted file mode 100644 index b255a5e1f..000000000 --- a/data/Duke.txt +++ /dev/null @@ -1 +0,0 @@ -[T][ ]ddd diff --git a/src/main/java/Controller.java b/src/main/java/Controller.java index f9c7e49b4..3df1eace7 100644 --- a/src/main/java/Controller.java +++ b/src/main/java/Controller.java @@ -1,8 +1,6 @@ -import java.io.File; import java.util.Locale; import java.util.Scanner; -import java.io.FileWriter; -import java.io.IOException; + public class Controller { //greeting msg and exit msg protected String HELLO_WORDS = "Hello! I'm Duke :P\nWhat can I do for you?"; @@ -33,18 +31,14 @@ public void bye() { /** * Unmarks task in the list */ - public void unmarkTask() throws DukeException{ - try { - int index = Integer.parseInt(analyst.taskName); - manager.unmarkTask(index); - } catch (NumberFormatException e) { - throw new IllegalTaskIndexException(); - } + public void unmarkTask(){ + int index= Integer.parseInt(analyst.taskName); + manager.unmarkTask(index); } /** * Marks task in the list - */ + public void markTask() throws DukeException{ try { int index = Integer.parseInt(analyst.taskName); @@ -53,7 +47,7 @@ public void markTask() throws DukeException{ throw new IllegalTaskIndexException(); } } - + */ /** public void deleteTask() throws DukeException{ try { @@ -62,15 +56,21 @@ public void deleteTask() throws DukeException{ } catch (NumberFormatException e) { throw new IllegalTaskIndexException(); } - } */ + public void markTask(){ + int index= Integer.parseInt(analyst.taskName); + manager.markTask(index); + } + /** * Listen the instruction and operate during the session */ - public void listen() throws DukeException { + public void listen() { Scanner msg = new Scanner(System.in); this.recvMsg = msg.nextLine(); + /** +<<<<<<< HEAD try { analyst = new OperationAnalyst(this.recvMsg); String command = analyst.getCommand(); @@ -115,7 +115,36 @@ public void listen() throws DukeException { } catch (IllegalTaskIndexException e) { chatbox.setContent("Please specify the index of the task :("); chatbox.chatboxPrinter(); +======= + **/ + analyst = new OperationAnalyst(this.recvMsg); + String command = analyst.getCommand(); + switch (command) { + case "bye": + this.bye(); + break; + case "list": + manager.listTask(); + break; + case "mark": + this.markTask(); + break; + case "unmark": + this.unmarkTask(); + break; + case "deadline": + manager.addDeadline(analyst.taskName, analyst.time); + break; + case "event": + manager.addEvent(analyst.taskName, analyst.time); + break; + case "todo": + manager.addToDo(analyst.taskName); + break; + default: + manager.addTask(analyst.taskName); } } + } \ No newline at end of file diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 7f3b3bbac..99328315c 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,10 +1,6 @@ -import java.io.File; import java.util.Scanner; -import java.io.FileWriter; -import java.io.IOException; - public class Duke { - public static void main(String[] args) throws DukeException{ + public static void main(String[] args) { Controller bot = new Controller(); bot.greet(); while(true){ //opens a new session for receiving instructions diff --git a/src/main/java/DukeException.java b/src/main/java/DukeException.java deleted file mode 100644 index 9b807163e..000000000 --- a/src/main/java/DukeException.java +++ /dev/null @@ -1,2 +0,0 @@ -public abstract class DukeException extends Exception{ -} diff --git a/src/main/java/IllegalFormatException.java b/src/main/java/IllegalFormatException.java deleted file mode 100644 index 9b185aef7..000000000 --- a/src/main/java/IllegalFormatException.java +++ /dev/null @@ -1,2 +0,0 @@ -public class IllegalFormatException extends DukeException{ -} diff --git a/src/main/java/IllegalInstructionException.java b/src/main/java/IllegalInstructionException.java deleted file mode 100644 index 95df328d7..000000000 --- a/src/main/java/IllegalInstructionException.java +++ /dev/null @@ -1,3 +0,0 @@ -public class IllegalInstructionException extends DukeException{ - -} diff --git a/src/main/java/IllegalSavingAction.java b/src/main/java/IllegalSavingAction.java deleted file mode 100644 index 9d9fef743..000000000 --- a/src/main/java/IllegalSavingAction.java +++ /dev/null @@ -1,2 +0,0 @@ -public class IllegalSavingAction extends DukeException{ -} diff --git a/src/main/java/IllegalTaskIndexException.java b/src/main/java/IllegalTaskIndexException.java deleted file mode 100644 index 87174ec9c..000000000 --- a/src/main/java/IllegalTaskIndexException.java +++ /dev/null @@ -1,2 +0,0 @@ -public class IllegalTaskIndexException extends DukeException{ -} diff --git a/src/main/java/IllegalTaskNameException.java b/src/main/java/IllegalTaskNameException.java deleted file mode 100644 index bc891ea84..000000000 --- a/src/main/java/IllegalTaskNameException.java +++ /dev/null @@ -1,2 +0,0 @@ -public class IllegalTaskNameException extends DukeException{ -} diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF deleted file mode 100644 index d2ffd5b4d..000000000 --- a/src/main/java/META-INF/MANIFEST.MF +++ /dev/null @@ -1,3 +0,0 @@ -Manifest-Version: 1.0 -Main-Class: Duke - diff --git a/src/main/java/OperationAnalyst.java b/src/main/java/OperationAnalyst.java index 6315bcdd7..e8eb630b6 100644 --- a/src/main/java/OperationAnalyst.java +++ b/src/main/java/OperationAnalyst.java @@ -7,14 +7,11 @@ public class OperationAnalyst { protected String taskName; protected String instruction; - public OperationAnalyst(String input) throws DukeException { + public OperationAnalyst(String input){ this.keywords = input.split(" "); this.rawInput = input; this.instruction = keywords[0].toLowerCase(Locale.ROOT); - //System.out.println(this.instruction); parseInstruction(); - //System.out.println(this.instruction); - //System.out.println(this.taskName); } /** @@ -28,48 +25,30 @@ public String getCommand() { /** * Analyses raw input to determine the task name and time */ - public void parseInstruction() throws DukeException{ + public void parseInstruction() { //String name; String[] command; switch (this.instruction) { case "deadline": command = rawInput.split("/by "); this.taskName = command[0].replace("deadline ", ""); - try { - this.time = command[1]; - } catch (IndexOutOfBoundsException e){ - throw new IllegalFormatException(); - } + this.time = command[1]; //System.out.println(this.time); break; case "event": command = rawInput.split("/at "); this.taskName = command[0].replace("event ", ""); - try { - this.time = command[1]; - } catch (IndexOutOfBoundsException e){ - throw new IllegalFormatException(); - } + this.time = command[1]; break; case "todo": this.taskName = rawInput.replace("todo ", ""); break; case "mark": case "unmark": - case "delete": - try { - this.taskName = this.keywords[1]; - } catch (IndexOutOfBoundsException e){ - throw new IllegalFormatException(); - } - break; - case "list" : - break; - case "bye" : + this.taskName = this.keywords[1]; break; default: - this.instruction = "unknown"; - throw new IllegalInstructionException(); + this.taskName = rawInput; } } diff --git a/src/main/java/TaskManager.java b/src/main/java/TaskManager.java index 15b4d6d57..c72d7e579 100644 --- a/src/main/java/TaskManager.java +++ b/src/main/java/TaskManager.java @@ -1,9 +1,4 @@ -import java.io.File; import java.util.ArrayList; -import java.io.FileWriter; -import java.io.IOException; -import java.io.FileWriter; -import java.io.FileOutputStream; public class TaskManager { private static final ArrayList Tasks = new ArrayList(); //response of adding @@ -35,7 +30,6 @@ public void saveTask() throws DukeException{ } */ - /** * Adds a general task in the list * @param name refers to the name of the task @@ -117,7 +111,7 @@ public void listTask() { * @param n refers to the index of the task in adding time order */ public void markTask(int n) { - //System.out.println(n); + System.out.println(n); String content = ""; if(n < 1 || n > Tasks.size()) { //Beyonds boundaries @@ -147,20 +141,5 @@ public void unmarkTask(int n) { chatbox.chatboxPrinter(); } - public void deleteTask(int n) { - String content = ""; - if(n < 1 || n > Tasks.size()) { - //Beyonds boundaries - content = "Sorry, I could not find the task :/"; - }else { - content = "Okay! I've deleted this task:\n" + Tasks.get(n - 1).listName; - Tasks.remove(n-1); - int s = Tasks.size(); - content += "\nNow you have " + String.valueOf(s) + " tasks in your list"; - } - chatbox.setContent(content); - chatbox.chatboxPrinter(); - } - } From 7cbe1f53503743c49a02dfac9793fb2358a29a7f Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Thu, 17 Feb 2022 14:05:58 +0800 Subject: [PATCH 14/45] Revert --- src/main/java/Controller.java | 6 ++++++ src/main/java/OperationAnalyst.java | 1 + 2 files changed, 7 insertions(+) diff --git a/src/main/java/Controller.java b/src/main/java/Controller.java index 3df1eace7..b80cc2b74 100644 --- a/src/main/java/Controller.java +++ b/src/main/java/Controller.java @@ -38,6 +38,7 @@ public void unmarkTask(){ /** * Marks task in the list +<<<<<<< HEAD public void markTask() throws DukeException{ try { @@ -56,6 +57,8 @@ public void deleteTask() throws DukeException{ } catch (NumberFormatException e) { throw new IllegalTaskIndexException(); } +======= +>>>>>>> parent of fd7236a (Save/Delete/Exception) */ public void markTask(){ int index= Integer.parseInt(analyst.taskName); @@ -70,6 +73,7 @@ public void listen() { Scanner msg = new Scanner(System.in); this.recvMsg = msg.nextLine(); /** +<<<<<<< HEAD <<<<<<< HEAD try { analyst = new OperationAnalyst(this.recvMsg); @@ -116,6 +120,8 @@ public void listen() { chatbox.setContent("Please specify the index of the task :("); chatbox.chatboxPrinter(); ======= +======= +>>>>>>> parent of fd7236a (Save/Delete/Exception) **/ analyst = new OperationAnalyst(this.recvMsg); String command = analyst.getCommand(); diff --git a/src/main/java/OperationAnalyst.java b/src/main/java/OperationAnalyst.java index e8eb630b6..86dca520f 100644 --- a/src/main/java/OperationAnalyst.java +++ b/src/main/java/OperationAnalyst.java @@ -19,6 +19,7 @@ public OperationAnalyst(String input){ * @return the command, whether it is deadline, todo, event, list, mark or unmark */ public String getCommand() { + return this.instruction; } From df02cad4447a38350e7660919c297e1e5559cc48 Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Thu, 17 Feb 2022 14:10:11 +0800 Subject: [PATCH 15/45] Revert --- src/main/java/TaskManager.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/TaskManager.java b/src/main/java/TaskManager.java index c72d7e579..915e71e5e 100644 --- a/src/main/java/TaskManager.java +++ b/src/main/java/TaskManager.java @@ -5,6 +5,7 @@ public class TaskManager { protected String ADD_RES = "Got it. I've added this task:\n"; Chatbox chatbox = new Chatbox(); +<<<<<<< HEAD /** public void saveTask() throws DukeException{ String content = ""; @@ -30,6 +31,8 @@ public void saveTask() throws DukeException{ } */ +======= +>>>>>>> parent of fd7236a (Save/Delete/Exception) /** * Adds a general task in the list * @param name refers to the name of the task From 7dfb5b5c283e72c81c7e7f9d835678c09b3cc1bb Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Thu, 17 Feb 2022 20:43:40 +0800 Subject: [PATCH 16/45] Exception Handling --- src/main/java/Controller.java | 65 ++++--------------- src/main/java/Duke.java | 2 +- src/main/java/DukeExceptions.java | 2 + src/main/java/IllegalFormatException.java | 2 + .../java/IllegalInstructionException.java | 2 + src/main/java/IllegalSavingAction.java | 2 + src/main/java/IllegalTaskIndexException.java | 2 + src/main/java/IllegalTaskNameException.java | 2 + src/main/java/TaskManager.java | 3 - 9 files changed, 24 insertions(+), 58 deletions(-) create mode 100644 src/main/java/DukeExceptions.java create mode 100644 src/main/java/IllegalFormatException.java create mode 100644 src/main/java/IllegalInstructionException.java create mode 100644 src/main/java/IllegalSavingAction.java create mode 100644 src/main/java/IllegalTaskIndexException.java create mode 100644 src/main/java/IllegalTaskNameException.java diff --git a/src/main/java/Controller.java b/src/main/java/Controller.java index b80cc2b74..cb8c778c2 100644 --- a/src/main/java/Controller.java +++ b/src/main/java/Controller.java @@ -31,16 +31,16 @@ public void bye() { /** * Unmarks task in the list */ - public void unmarkTask(){ - int index= Integer.parseInt(analyst.taskName); - manager.unmarkTask(index); + public void unmarkTask() throws DukeExceptions{ + try { + int index= Integer.parseInt(analyst.taskName); + manager.unmarkTask(index); + } catch (NumberFormatException e) { + throw new IllegalTaskIndexException(); + } } - /** - * Marks task in the list -<<<<<<< HEAD - - public void markTask() throws DukeException{ + public void markTask() throws DukeExceptions{ try { int index = Integer.parseInt(analyst.taskName); manager.markTask(index); @@ -48,7 +48,6 @@ public void markTask() throws DukeException{ throw new IllegalTaskIndexException(); } } - */ /** public void deleteTask() throws DukeException{ try { @@ -56,25 +55,14 @@ public void deleteTask() throws DukeException{ manager.deleteTask(index); } catch (NumberFormatException e) { throw new IllegalTaskIndexException(); - } -======= ->>>>>>> parent of fd7236a (Save/Delete/Exception) - */ - public void markTask(){ - int index= Integer.parseInt(analyst.taskName); - manager.markTask(index); - } - +*/ /** * Listen the instruction and operate during the session */ - public void listen() { + public void listen() throws DukeExceptions{ Scanner msg = new Scanner(System.in); this.recvMsg = msg.nextLine(); - /** -<<<<<<< HEAD -<<<<<<< HEAD try { analyst = new OperationAnalyst(this.recvMsg); String command = analyst.getCommand(); @@ -119,38 +107,7 @@ public void listen() { } catch (IllegalTaskIndexException e) { chatbox.setContent("Please specify the index of the task :("); chatbox.chatboxPrinter(); -======= -======= ->>>>>>> parent of fd7236a (Save/Delete/Exception) - **/ - analyst = new OperationAnalyst(this.recvMsg); - String command = analyst.getCommand(); - switch (command) { - case "bye": - this.bye(); - break; - case "list": - manager.listTask(); - break; - case "mark": - this.markTask(); - break; - case "unmark": - this.unmarkTask(); - break; - case "deadline": - manager.addDeadline(analyst.taskName, analyst.time); - break; - case "event": - manager.addEvent(analyst.taskName, analyst.time); - break; - case "todo": - manager.addToDo(analyst.taskName); - break; - default: - manager.addTask(analyst.taskName); - } - } + } } \ No newline at end of file diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 99328315c..ad1216221 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,6 +1,6 @@ import java.util.Scanner; public class Duke { - public static void main(String[] args) { + public static void main(String[] args) throws DukeExceptions{ Controller bot = new Controller(); bot.greet(); while(true){ //opens a new session for receiving instructions diff --git a/src/main/java/DukeExceptions.java b/src/main/java/DukeExceptions.java new file mode 100644 index 000000000..ce1cb7989 --- /dev/null +++ b/src/main/java/DukeExceptions.java @@ -0,0 +1,2 @@ +public class DukeExceptions extends Exception{ +} diff --git a/src/main/java/IllegalFormatException.java b/src/main/java/IllegalFormatException.java new file mode 100644 index 000000000..f0b03a086 --- /dev/null +++ b/src/main/java/IllegalFormatException.java @@ -0,0 +1,2 @@ +public class IllegalFormatException extends DukeExceptions{ +} diff --git a/src/main/java/IllegalInstructionException.java b/src/main/java/IllegalInstructionException.java new file mode 100644 index 000000000..ed21af383 --- /dev/null +++ b/src/main/java/IllegalInstructionException.java @@ -0,0 +1,2 @@ +public class IllegalInstructionException extends DukeExceptions{ +} diff --git a/src/main/java/IllegalSavingAction.java b/src/main/java/IllegalSavingAction.java new file mode 100644 index 000000000..04b8203e4 --- /dev/null +++ b/src/main/java/IllegalSavingAction.java @@ -0,0 +1,2 @@ +public class IllegalSavingAction extends DukeExceptions{ +} diff --git a/src/main/java/IllegalTaskIndexException.java b/src/main/java/IllegalTaskIndexException.java new file mode 100644 index 000000000..b9c4aa7bf --- /dev/null +++ b/src/main/java/IllegalTaskIndexException.java @@ -0,0 +1,2 @@ +public class IllegalTaskIndexException extends DukeExceptions{ +} diff --git a/src/main/java/IllegalTaskNameException.java b/src/main/java/IllegalTaskNameException.java new file mode 100644 index 000000000..206aa4bd2 --- /dev/null +++ b/src/main/java/IllegalTaskNameException.java @@ -0,0 +1,2 @@ +public class IllegalTaskNameException extends DukeExceptions{ +} diff --git a/src/main/java/TaskManager.java b/src/main/java/TaskManager.java index 915e71e5e..c72d7e579 100644 --- a/src/main/java/TaskManager.java +++ b/src/main/java/TaskManager.java @@ -5,7 +5,6 @@ public class TaskManager { protected String ADD_RES = "Got it. I've added this task:\n"; Chatbox chatbox = new Chatbox(); -<<<<<<< HEAD /** public void saveTask() throws DukeException{ String content = ""; @@ -31,8 +30,6 @@ public void saveTask() throws DukeException{ } */ -======= ->>>>>>> parent of fd7236a (Save/Delete/Exception) /** * Adds a general task in the list * @param name refers to the name of the task From 69e8e2a4440071cad0f903179ae1afa4ae2a0791 Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Thu, 17 Feb 2022 20:56:15 +0800 Subject: [PATCH 17/45] Delete --- src/main/java/Controller.java | 8 ++++---- src/main/java/TaskManager.java | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/main/java/Controller.java b/src/main/java/Controller.java index cb8c778c2..e0c6af6ca 100644 --- a/src/main/java/Controller.java +++ b/src/main/java/Controller.java @@ -48,8 +48,8 @@ public void markTask() throws DukeExceptions{ throw new IllegalTaskIndexException(); } } - /** - public void deleteTask() throws DukeException{ + + public void deleteTask() throws DukeExceptions{ try { int index = Integer.parseInt(analyst.taskName); manager.deleteTask(index); @@ -88,8 +88,8 @@ public void listen() throws DukeExceptions{ case "todo": manager.addToDo(analyst.taskName); break; - //case "delete": - //this.deleteTask(); + case "delete": + this.deleteTask(); } //manager.saveTask(); } catch (IllegalInstructionException e){ diff --git a/src/main/java/TaskManager.java b/src/main/java/TaskManager.java index c72d7e579..6670165a7 100644 --- a/src/main/java/TaskManager.java +++ b/src/main/java/TaskManager.java @@ -141,5 +141,20 @@ public void unmarkTask(int n) { chatbox.chatboxPrinter(); } + public void deleteTask(int n) { + String content = ""; + if(n < 1 || n > Tasks.size()) { + //Beyonds boundaries + content = "Sorry, I could not find the task :/"; + }else { + content = "Okay! I've deleted this task:\n" + Tasks.get(n - 1).listName; + Tasks.remove(n-1); + int s = Tasks.size(); + content += "\nNow you have " + String.valueOf(s) + " tasks in your list"; + } + chatbox.setContent(content); + chatbox.chatboxPrinter(); + } + } From 89b1c013bc49857ed25f9c5d7691f45cfb904ac0 Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Thu, 17 Feb 2022 20:59:52 +0800 Subject: [PATCH 18/45] Fix some bugs --- src/main/java/Controller.java | 101 +++++++++++++++++----------------- 1 file changed, 51 insertions(+), 50 deletions(-) diff --git a/src/main/java/Controller.java b/src/main/java/Controller.java index e0c6af6ca..a2251f81a 100644 --- a/src/main/java/Controller.java +++ b/src/main/java/Controller.java @@ -49,65 +49,66 @@ public void markTask() throws DukeExceptions{ } } - public void deleteTask() throws DukeExceptions{ + public void deleteTask() throws DukeExceptions { try { int index = Integer.parseInt(analyst.taskName); manager.deleteTask(index); } catch (NumberFormatException e) { throw new IllegalTaskIndexException(); -*/ - + } + } /** * Listen the instruction and operate during the session */ - public void listen() throws DukeExceptions{ - Scanner msg = new Scanner(System.in); - this.recvMsg = msg.nextLine(); - try { - analyst = new OperationAnalyst(this.recvMsg); - String command = analyst.getCommand(); - switch (command) { - case "bye": - this.bye(); - break; - case "list": - manager.listTask(); - break; - case "mark": - this.markTask(); - break; - case "unmark": - this.unmarkTask(); - break; - case "deadline": - manager.addDeadline(analyst.taskName, analyst.time); - break; - case "event": - manager.addEvent(analyst.taskName, analyst.time); - break; - case "todo": - manager.addToDo(analyst.taskName); - break; - case "delete": - this.deleteTask(); + public void listen() throws DukeExceptions { + Scanner msg = new Scanner(System.in); + this.recvMsg = msg.nextLine(); + try { + analyst = new OperationAnalyst(this.recvMsg); + String command = analyst.getCommand(); + switch (command) { + case "bye": + this.bye(); + break; + case "list": + manager.listTask(); + break; + case "mark": + this.markTask(); + break; + case "unmark": + this.unmarkTask(); + break; + case "deadline": + manager.addDeadline(analyst.taskName, analyst.time); + break; + case "event": + manager.addEvent(analyst.taskName, analyst.time); + break; + case "todo": + manager.addToDo(analyst.taskName); + break; + case "delete": + this.deleteTask(); + } + //manager.saveTask(); + } catch (IllegalInstructionException e) { + chatbox.setContent("Sorry, I don't understand your instruction :("); + chatbox.chatboxPrinter(); + } catch (IllegalFormatException e) { + chatbox.setContent("Please check your format again :("); + chatbox.chatboxPrinter(); + } catch (IllegalTaskNameException e) { + chatbox.setContent("Did you specify your task name?"); + chatbox.chatboxPrinter(); + } catch (IllegalSavingAction e) { + chatbox.setContent("Cannot save to file :("); + chatbox.chatboxPrinter(); + } catch (IllegalTaskIndexException e) { + chatbox.setContent("Please specify the index of the task :("); + chatbox.chatboxPrinter(); + } } - //manager.saveTask(); - } catch (IllegalInstructionException e){ - chatbox.setContent("Sorry, I don't understand your instruction :("); - chatbox.chatboxPrinter(); - } catch (IllegalFormatException e) { - chatbox.setContent("Please check your format again :("); - chatbox.chatboxPrinter(); - } catch (IllegalTaskNameException e) { - chatbox.setContent("Did you specify your task name?"); - chatbox.chatboxPrinter(); - } catch (IllegalSavingAction e) { - chatbox.setContent("Cannot save to file :("); - chatbox.chatboxPrinter(); - } catch (IllegalTaskIndexException e) { - chatbox.setContent("Please specify the index of the task :("); - chatbox.chatboxPrinter(); - } } \ No newline at end of file From 928901701a11ceac524629e6c0605bdafc2ba56d Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Thu, 17 Feb 2022 21:02:05 +0800 Subject: [PATCH 19/45] Save --- src/main/java/Controller.java | 11 ++++++----- src/main/java/TaskManager.java | 8 +++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/Controller.java b/src/main/java/Controller.java index cb8c778c2..987a35d47 100644 --- a/src/main/java/Controller.java +++ b/src/main/java/Controller.java @@ -60,7 +60,7 @@ public void deleteTask() throws DukeException{ /** * Listen the instruction and operate during the session */ - public void listen() throws DukeExceptions{ + public void listen() throws DukeExceptions { Scanner msg = new Scanner(System.in); this.recvMsg = msg.nextLine(); try { @@ -89,10 +89,10 @@ public void listen() throws DukeExceptions{ manager.addToDo(analyst.taskName); break; //case "delete": - //this.deleteTask(); + //this.deleteTask(); } - //manager.saveTask(); - } catch (IllegalInstructionException e){ + manager.saveTask(); + } catch (IllegalInstructionException e) { chatbox.setContent("Sorry, I don't understand your instruction :("); chatbox.chatboxPrinter(); } catch (IllegalFormatException e) { @@ -107,7 +107,8 @@ public void listen() throws DukeExceptions{ } catch (IllegalTaskIndexException e) { chatbox.setContent("Please specify the index of the task :("); chatbox.chatboxPrinter(); - } + } + } } \ No newline at end of file diff --git a/src/main/java/TaskManager.java b/src/main/java/TaskManager.java index c72d7e579..66b110e98 100644 --- a/src/main/java/TaskManager.java +++ b/src/main/java/TaskManager.java @@ -1,12 +1,15 @@ import java.util.ArrayList; +import java.io.FileWriter; +import java.io.File; +import java.io.IOException; public class TaskManager { private static final ArrayList Tasks = new ArrayList(); //response of adding protected String ADD_RES = "Got it. I've added this task:\n"; Chatbox chatbox = new Chatbox(); - /** - public void saveTask() throws DukeException{ + + public void saveTask() throws DukeExceptions{ String content = ""; for(int i = 0;i < Tasks.size();i++){ content += Tasks.get(i).getListName(); @@ -29,7 +32,6 @@ public void saveTask() throws DukeException{ } } - */ /** * Adds a general task in the list * @param name refers to the name of the task From 83f053b4017faa1d7b5369c6282e8db61c2d95b5 Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Thu, 17 Feb 2022 22:26:03 +0800 Subject: [PATCH 20/45] Fix some bugs --- src/main/java/OperationAnalyst.java | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/main/java/OperationAnalyst.java b/src/main/java/OperationAnalyst.java index 86dca520f..931592c76 100644 --- a/src/main/java/OperationAnalyst.java +++ b/src/main/java/OperationAnalyst.java @@ -7,7 +7,7 @@ public class OperationAnalyst { protected String taskName; protected String instruction; - public OperationAnalyst(String input){ + public OperationAnalyst(String input) throws DukeExceptions{ this.keywords = input.split(" "); this.rawInput = input; this.instruction = keywords[0].toLowerCase(Locale.ROOT); @@ -26,27 +26,43 @@ public String getCommand() { /** * Analyses raw input to determine the task name and time */ - public void parseInstruction() { + public void parseInstruction() throws DukeExceptions{ //String name; String[] command; switch (this.instruction) { case "deadline": command = rawInput.split("/by "); this.taskName = command[0].replace("deadline ", ""); - this.time = command[1]; + try { + this.time = command[1]; + } catch (IndexOutOfBoundsException e){ + throw new IllegalFormatException(); + } //System.out.println(this.time); break; case "event": command = rawInput.split("/at "); this.taskName = command[0].replace("event ", ""); - this.time = command[1]; + try { + this.time = command[1]; + } catch (IndexOutOfBoundsException e){ + throw new IllegalFormatException(); + } break; case "todo": this.taskName = rawInput.replace("todo ", ""); break; case "mark": case "unmark": - this.taskName = this.keywords[1]; + case "delete": + try { + this.taskName = this.keywords[1]; + } catch (IndexOutOfBoundsException e){ + throw new IllegalFormatException(); + } + break; + case "list" : + case "bye" : break; default: this.taskName = rawInput; From b6d7646a20f63daf19fd76229e59c514faf98576 Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Fri, 25 Feb 2022 16:50:44 +0800 Subject: [PATCH 21/45] Divide classes into packages --- src/main/java/Duke.java | 6 ++++-- src/main/java/IllegalFormatException.java | 2 -- src/main/java/IllegalInstructionException.java | 2 -- src/main/java/IllegalSavingAction.java | 2 -- src/main/java/IllegalTaskIndexException.java | 2 -- src/main/java/IllegalTaskNameException.java | 2 -- src/main/java/{ => chatbox}/Chatbox.java | 2 ++ src/main/java/{ => controller}/Controller.java | 9 +++++++-- src/main/java/{ => controller}/OperationAnalyst.java | 6 +++++- src/main/java/{ => exceptions}/DukeExceptions.java | 2 ++ src/main/java/exceptions/IllegalFormatException.java | 4 ++++ .../java/exceptions/IllegalInstructionException.java | 4 ++++ src/main/java/exceptions/IllegalSavingAction.java | 4 ++++ src/main/java/exceptions/IllegalTaskIndexException.java | 4 ++++ src/main/java/exceptions/IllegalTaskNameException.java | 4 ++++ src/main/java/{ => tasks}/Deadline.java | 4 +++- src/main/java/{ => tasks}/Event.java | 2 ++ src/main/java/{ => tasks}/Task.java | 2 ++ src/main/java/{ => tasks}/TaskManager.java | 8 ++++++-- src/main/java/{ => tasks}/ToDo.java | 4 +++- 20 files changed, 56 insertions(+), 19 deletions(-) delete mode 100644 src/main/java/IllegalFormatException.java delete mode 100644 src/main/java/IllegalInstructionException.java delete mode 100644 src/main/java/IllegalSavingAction.java delete mode 100644 src/main/java/IllegalTaskIndexException.java delete mode 100644 src/main/java/IllegalTaskNameException.java rename src/main/java/{ => chatbox}/Chatbox.java (96%) rename src/main/java/{ => controller}/Controller.java (96%) rename src/main/java/{ => controller}/OperationAnalyst.java (95%) rename src/main/java/{ => exceptions}/DukeExceptions.java (70%) create mode 100644 src/main/java/exceptions/IllegalFormatException.java create mode 100644 src/main/java/exceptions/IllegalInstructionException.java create mode 100644 src/main/java/exceptions/IllegalSavingAction.java create mode 100644 src/main/java/exceptions/IllegalTaskIndexException.java create mode 100644 src/main/java/exceptions/IllegalTaskNameException.java rename src/main/java/{ => tasks}/Deadline.java (89%) rename src/main/java/{ => tasks}/Event.java (96%) rename src/main/java/{ => tasks}/Task.java (98%) rename src/main/java/{ => tasks}/TaskManager.java (98%) rename src/main/java/{ => tasks}/ToDo.java (86%) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index ad1216221..cbe10cd6a 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,6 +1,8 @@ -import java.util.Scanner; +import controller.*; +import exceptions.*; + public class Duke { - public static void main(String[] args) throws DukeExceptions{ + public static void main(String[] args) throws DukeExceptions { Controller bot = new Controller(); bot.greet(); while(true){ //opens a new session for receiving instructions diff --git a/src/main/java/IllegalFormatException.java b/src/main/java/IllegalFormatException.java deleted file mode 100644 index f0b03a086..000000000 --- a/src/main/java/IllegalFormatException.java +++ /dev/null @@ -1,2 +0,0 @@ -public class IllegalFormatException extends DukeExceptions{ -} diff --git a/src/main/java/IllegalInstructionException.java b/src/main/java/IllegalInstructionException.java deleted file mode 100644 index ed21af383..000000000 --- a/src/main/java/IllegalInstructionException.java +++ /dev/null @@ -1,2 +0,0 @@ -public class IllegalInstructionException extends DukeExceptions{ -} diff --git a/src/main/java/IllegalSavingAction.java b/src/main/java/IllegalSavingAction.java deleted file mode 100644 index 04b8203e4..000000000 --- a/src/main/java/IllegalSavingAction.java +++ /dev/null @@ -1,2 +0,0 @@ -public class IllegalSavingAction extends DukeExceptions{ -} diff --git a/src/main/java/IllegalTaskIndexException.java b/src/main/java/IllegalTaskIndexException.java deleted file mode 100644 index b9c4aa7bf..000000000 --- a/src/main/java/IllegalTaskIndexException.java +++ /dev/null @@ -1,2 +0,0 @@ -public class IllegalTaskIndexException extends DukeExceptions{ -} diff --git a/src/main/java/IllegalTaskNameException.java b/src/main/java/IllegalTaskNameException.java deleted file mode 100644 index 206aa4bd2..000000000 --- a/src/main/java/IllegalTaskNameException.java +++ /dev/null @@ -1,2 +0,0 @@ -public class IllegalTaskNameException extends DukeExceptions{ -} diff --git a/src/main/java/Chatbox.java b/src/main/java/chatbox/Chatbox.java similarity index 96% rename from src/main/java/Chatbox.java rename to src/main/java/chatbox/Chatbox.java index 22a88423c..169deded3 100644 --- a/src/main/java/Chatbox.java +++ b/src/main/java/chatbox/Chatbox.java @@ -1,3 +1,5 @@ +package chatbox; + public class Chatbox { private String content = ""; //border of the chatbox diff --git a/src/main/java/Controller.java b/src/main/java/controller/Controller.java similarity index 96% rename from src/main/java/Controller.java rename to src/main/java/controller/Controller.java index 749ebd2f1..57594c138 100644 --- a/src/main/java/Controller.java +++ b/src/main/java/controller/Controller.java @@ -1,4 +1,9 @@ -import java.util.Locale; +package controller; + +import chatbox.Chatbox; +import exceptions.*; +import tasks.TaskManager; + import java.util.Scanner; public class Controller { @@ -31,7 +36,7 @@ public void bye() { /** * Unmarks task in the list */ - public void unmarkTask() throws DukeExceptions{ + public void unmarkTask() throws DukeExceptions { try { int index= Integer.parseInt(analyst.taskName); manager.unmarkTask(index); diff --git a/src/main/java/OperationAnalyst.java b/src/main/java/controller/OperationAnalyst.java similarity index 95% rename from src/main/java/OperationAnalyst.java rename to src/main/java/controller/OperationAnalyst.java index 931592c76..9fe5df850 100644 --- a/src/main/java/OperationAnalyst.java +++ b/src/main/java/controller/OperationAnalyst.java @@ -1,3 +1,7 @@ +package controller; + +import exceptions.*; + import java.util.Locale; public class OperationAnalyst { @@ -7,7 +11,7 @@ public class OperationAnalyst { protected String taskName; protected String instruction; - public OperationAnalyst(String input) throws DukeExceptions{ + public OperationAnalyst(String input) throws DukeExceptions { this.keywords = input.split(" "); this.rawInput = input; this.instruction = keywords[0].toLowerCase(Locale.ROOT); diff --git a/src/main/java/DukeExceptions.java b/src/main/java/exceptions/DukeExceptions.java similarity index 70% rename from src/main/java/DukeExceptions.java rename to src/main/java/exceptions/DukeExceptions.java index ce1cb7989..c65525c08 100644 --- a/src/main/java/DukeExceptions.java +++ b/src/main/java/exceptions/DukeExceptions.java @@ -1,2 +1,4 @@ +package exceptions; + public class DukeExceptions extends Exception{ } diff --git a/src/main/java/exceptions/IllegalFormatException.java b/src/main/java/exceptions/IllegalFormatException.java new file mode 100644 index 000000000..75e783542 --- /dev/null +++ b/src/main/java/exceptions/IllegalFormatException.java @@ -0,0 +1,4 @@ +package exceptions; + +public class IllegalFormatException extends DukeExceptions { +} diff --git a/src/main/java/exceptions/IllegalInstructionException.java b/src/main/java/exceptions/IllegalInstructionException.java new file mode 100644 index 000000000..9a6bddc1e --- /dev/null +++ b/src/main/java/exceptions/IllegalInstructionException.java @@ -0,0 +1,4 @@ +package exceptions; + +public class IllegalInstructionException extends DukeExceptions { +} diff --git a/src/main/java/exceptions/IllegalSavingAction.java b/src/main/java/exceptions/IllegalSavingAction.java new file mode 100644 index 000000000..0f73f5fa7 --- /dev/null +++ b/src/main/java/exceptions/IllegalSavingAction.java @@ -0,0 +1,4 @@ +package exceptions; + +public class IllegalSavingAction extends DukeExceptions { +} diff --git a/src/main/java/exceptions/IllegalTaskIndexException.java b/src/main/java/exceptions/IllegalTaskIndexException.java new file mode 100644 index 000000000..baaa873e4 --- /dev/null +++ b/src/main/java/exceptions/IllegalTaskIndexException.java @@ -0,0 +1,4 @@ +package exceptions; + +public class IllegalTaskIndexException extends DukeExceptions { +} diff --git a/src/main/java/exceptions/IllegalTaskNameException.java b/src/main/java/exceptions/IllegalTaskNameException.java new file mode 100644 index 000000000..f57cfe40f --- /dev/null +++ b/src/main/java/exceptions/IllegalTaskNameException.java @@ -0,0 +1,4 @@ +package exceptions; + +public class IllegalTaskNameException extends DukeExceptions { +} diff --git a/src/main/java/Deadline.java b/src/main/java/tasks/Deadline.java similarity index 89% rename from src/main/java/Deadline.java rename to src/main/java/tasks/Deadline.java index 0a7557cc9..d74daccbc 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/tasks/Deadline.java @@ -1,4 +1,6 @@ -public class Deadline extends Task{ +package tasks; + +public class Deadline extends Task { protected String by; public Deadline(String name, String by){ diff --git a/src/main/java/Event.java b/src/main/java/tasks/Event.java similarity index 96% rename from src/main/java/Event.java rename to src/main/java/tasks/Event.java index 8849e72e5..d1f594f57 100644 --- a/src/main/java/Event.java +++ b/src/main/java/tasks/Event.java @@ -1,3 +1,5 @@ +package tasks; + public class Event extends Task { protected String at; diff --git a/src/main/java/Task.java b/src/main/java/tasks/Task.java similarity index 98% rename from src/main/java/Task.java rename to src/main/java/tasks/Task.java index 043932a10..7594a19fc 100644 --- a/src/main/java/Task.java +++ b/src/main/java/tasks/Task.java @@ -1,3 +1,5 @@ +package tasks; + public class Task { protected String unmarkedStatus = "[ ]"; protected String markedStatus = "[X]"; diff --git a/src/main/java/TaskManager.java b/src/main/java/tasks/TaskManager.java similarity index 98% rename from src/main/java/TaskManager.java rename to src/main/java/tasks/TaskManager.java index b7b04f795..5f600891a 100644 --- a/src/main/java/TaskManager.java +++ b/src/main/java/tasks/TaskManager.java @@ -1,7 +1,11 @@ +package tasks; + import java.util.ArrayList; import java.io.FileWriter; import java.io.File; -import java.io.IOException; +import chatbox.*; +import exceptions.*; + public class TaskManager { private static final ArrayList Tasks = new ArrayList(); //response of adding @@ -9,7 +13,7 @@ public class TaskManager { Chatbox chatbox = new Chatbox(); - public void saveTask() throws DukeExceptions{ + public void saveTask() throws DukeExceptions { String content = ""; for(int i = 0;i < Tasks.size();i++){ content += Tasks.get(i).getListName(); diff --git a/src/main/java/ToDo.java b/src/main/java/tasks/ToDo.java similarity index 86% rename from src/main/java/ToDo.java rename to src/main/java/tasks/ToDo.java index 89d56671c..1936d96bd 100644 --- a/src/main/java/ToDo.java +++ b/src/main/java/tasks/ToDo.java @@ -1,4 +1,6 @@ -public class ToDo extends Task{ +package tasks; + +public class ToDo extends Task { public ToDo(String name){ super(name); From 9102ec1acae64007d5ddaf480a24815cc777cddc Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Sat, 26 Feb 2022 21:04:08 +0800 Subject: [PATCH 22/45] fix loading task feature --- data/duke.txt | 1 + src/main/java/Duke.java | 4 +- src/main/java/controller/Controller.java | 9 ++ .../exceptions/CreatingFileException.java | 4 + .../java/exceptions/IllegalReadingAction.java | 4 + src/main/java/tasks/Storage.java | 117 ++++++++++++++++++ src/main/java/tasks/Task.java | 5 +- src/main/java/tasks/TaskManager.java | 32 ++--- 8 files changed, 152 insertions(+), 24 deletions(-) create mode 100644 data/duke.txt create mode 100644 src/main/java/exceptions/CreatingFileException.java create mode 100644 src/main/java/exceptions/IllegalReadingAction.java create mode 100644 src/main/java/tasks/Storage.java diff --git a/data/duke.txt b/data/duke.txt new file mode 100644 index 000000000..dd722d12f --- /dev/null +++ b/data/duke.txt @@ -0,0 +1 @@ +[T][ ]e diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index cbe10cd6a..7c54e55ac 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -5,7 +5,9 @@ public class Duke { public static void main(String[] args) throws DukeExceptions { Controller bot = new Controller(); bot.greet(); - while(true){ //opens a new session for receiving instructions + bot.createFile(); + bot.loadTask(); + while(true){//opens a new session for receiving instruction bot.listen(); } } diff --git a/src/main/java/controller/Controller.java b/src/main/java/controller/Controller.java index 57594c138..1a6cf7142 100644 --- a/src/main/java/controller/Controller.java +++ b/src/main/java/controller/Controller.java @@ -62,6 +62,15 @@ public void deleteTask() throws DukeExceptions { throw new IllegalTaskIndexException(); } } + + public void createFile() throws DukeExceptions{ + manager.createFile(); + } + + public void loadTask() throws DukeExceptions{ + manager.loadTask(); + } + /** * Listen the instruction and operate during the session */ diff --git a/src/main/java/exceptions/CreatingFileException.java b/src/main/java/exceptions/CreatingFileException.java new file mode 100644 index 000000000..a2701091e --- /dev/null +++ b/src/main/java/exceptions/CreatingFileException.java @@ -0,0 +1,4 @@ +package exceptions; + +public class CreatingFileException extends DukeExceptions{ +} diff --git a/src/main/java/exceptions/IllegalReadingAction.java b/src/main/java/exceptions/IllegalReadingAction.java new file mode 100644 index 000000000..8b052bf7b --- /dev/null +++ b/src/main/java/exceptions/IllegalReadingAction.java @@ -0,0 +1,4 @@ +package exceptions; + +public class IllegalReadingAction extends DukeExceptions{ +} diff --git a/src/main/java/tasks/Storage.java b/src/main/java/tasks/Storage.java new file mode 100644 index 000000000..448ae8822 --- /dev/null +++ b/src/main/java/tasks/Storage.java @@ -0,0 +1,117 @@ +package tasks; + +import exceptions.*; + +import java.io.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.regex.*; + +public class Storage { + private static final ArrayList Tasks = new ArrayList(); + private static final String FILE_NAME = "data/duke.txt"; + + public int size() { + return Tasks.size(); + } + public void add(Task newTask) { + Tasks.add(newTask); + } + public Task get(int i) { + return Tasks.get(i); + } + public void remove(int i) { + Tasks.remove(i); + } + public void saveTask() throws DukeExceptions { + String content = ""; + for(int i = 0;i < Tasks.size();i++){ + content += Tasks.get(i).getListName(); + content += "\n"; + } + if(content != null){ + try{ + File file = new File(FILE_NAME); + if(!file.exists()){ + File dir = new File(file.getParent()); + dir.mkdirs(); + file.createNewFile(); + } + FileWriter writeStream = new FileWriter(file); + writeStream.write(content); + writeStream.close(); + } catch (Exception e){ + throw new IllegalSavingAction(); + } + } + + } + + public String[] parseInput(String listName) { + String info = listName.replaceAll("\\]", "\\|"); + info = info.replaceAll("\\[", ""); + info = info.replaceAll("\\(", "\\|"); + info = info.replaceAll("\\)", ""); + System.out.println(info); + String[] data = info.split("\\|"); + return data; + } + + public void mark(Task task, String status){ + if(status.equals("X")){ + task.isDone = true; + } + } + + public void loadTask() throws DukeExceptions{ + try (BufferedReader loadData = new BufferedReader(new FileReader(FILE_NAME))){ + String listName; + String time; + while ((listName = loadData.readLine()) != null) { + String[] data = this.parseInput(listName); + System.out.println(listName); + System.out.println(Arrays.toString(data)); + switch (data[0]) { + case "T": + ToDo newToDo = new ToDo(data[2]); + mark(newToDo, data[2]); + Tasks.add(newToDo); + break; + case "E": + time = data[3].replace("at: ", ""); + Event newEvent = new Event(data[2], time); + mark(newEvent, data[2]); + Tasks.add(newEvent); + break; + case "D": + time = data[3].replace("by: ", ""); + Deadline newDeadline = new Deadline(data[2], time); + mark(newDeadline, data[2]); + Tasks.add(newDeadline); + break; + default: + throw new IllegalReadingAction(); + } + } + } catch (Exception e){ + throw new IllegalReadingAction(); + } + + } + + public void createFile() throws DukeExceptions { + try { + File file = new File(FILE_NAME); + if (!file.exists()) { + File dir = new File(file.getParent()); + dir.mkdirs(); + file.createNewFile(); + } + } catch (Exception e){ + throw new CreatingFileException(); + } + } + +} + + diff --git a/src/main/java/tasks/Task.java b/src/main/java/tasks/Task.java index 7594a19fc..c1594ff82 100644 --- a/src/main/java/tasks/Task.java +++ b/src/main/java/tasks/Task.java @@ -3,12 +3,13 @@ public class Task { protected String unmarkedStatus = "[ ]"; protected String markedStatus = "[X]"; - protected String taskName = ""; //the name of the task + protected String taskName; //the name of the task protected boolean isDone = false; - protected String listName = ""; //the name of the task that appears when listing + protected String listName; //the name of the task that appears when listing public Task(String name){ this.taskName = name; + this.isDone = false; setListName(); } diff --git a/src/main/java/tasks/TaskManager.java b/src/main/java/tasks/TaskManager.java index 5f600891a..4dd345c7f 100644 --- a/src/main/java/tasks/TaskManager.java +++ b/src/main/java/tasks/TaskManager.java @@ -7,34 +7,22 @@ import exceptions.*; public class TaskManager { - private static final ArrayList Tasks = new ArrayList(); + Storage Tasks = new Storage(); //response of adding protected String ADD_RES = "Got it. I've added this task:\n"; Chatbox chatbox = new Chatbox(); public void saveTask() throws DukeExceptions { - String content = ""; - for(int i = 0;i < Tasks.size();i++){ - content += Tasks.get(i).getListName(); - content += "\n"; - } - if(null != content){ - try{ - File file = new File("data/Duke.txt"); - if(!file.exists()){ - File dir = new File(file.getParent()); - dir.mkdirs(); - file.createNewFile(); - } - FileWriter outStream = new FileWriter(file); - outStream.write(content); - outStream.close(); - } catch (Exception e){ - throw new IllegalSavingAction(); - } - } + Tasks.saveTask(); + } + + public void loadTask() throws DukeExceptions { + Tasks.loadTask(); + } + public void createFile() throws DukeExceptions { + Tasks.createFile(); } /** * Adds a general task in the list @@ -163,4 +151,6 @@ public void deleteTask(int n) { } + + } From c69a2639540af0898a88086e8e189e7e3b275aea Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Sun, 27 Feb 2022 15:47:41 +0800 Subject: [PATCH 23/45] Optimize OOP --- data/duke.txt | 1 - src/main/java/{chatbox => UI}/Chatbox.java | 2 +- src/main/java/UI/UI.java | 24 +++++ src/main/java/controller/Controller.java | 93 +++++++++---------- .../java/controller/OperationAnalyst.java | 58 ++++++++---- .../exceptions/CreatingFileException.java | 7 ++ src/main/java/exceptions/DukeExceptions.java | 2 +- .../java/exceptions/EmptyListException.java | 11 +++ .../exceptions/IllegalFormatException.java | 7 ++ .../exceptions/IllegalIndexException.java | 11 +++ .../IllegalInstructionException.java | 7 ++ .../java/exceptions/IllegalReadingAction.java | 7 ++ .../java/exceptions/IllegalSavingAction.java | 7 ++ .../exceptions/IllegalTaskIndexException.java | 4 - .../exceptions/IllegalTaskNameException.java | 4 - .../IllegalTimeFormatException.java | 11 +++ .../exceptions/TaskIndexLossException.java | 11 +++ .../exceptions/TaskNameLossException.java | 11 +++ src/main/java/tasks/Deadline.java | 16 +++- src/main/java/tasks/Event.java | 18 +++- src/main/java/tasks/Storage.java | 27 +++--- src/main/java/tasks/TaskManager.java | 83 ++++++++--------- 22 files changed, 281 insertions(+), 141 deletions(-) rename src/main/java/{chatbox => UI}/Chatbox.java (96%) create mode 100644 src/main/java/UI/UI.java create mode 100644 src/main/java/exceptions/EmptyListException.java create mode 100644 src/main/java/exceptions/IllegalIndexException.java delete mode 100644 src/main/java/exceptions/IllegalTaskIndexException.java delete mode 100644 src/main/java/exceptions/IllegalTaskNameException.java create mode 100644 src/main/java/exceptions/IllegalTimeFormatException.java create mode 100644 src/main/java/exceptions/TaskIndexLossException.java create mode 100644 src/main/java/exceptions/TaskNameLossException.java diff --git a/data/duke.txt b/data/duke.txt index dd722d12f..e69de29bb 100644 --- a/data/duke.txt +++ b/data/duke.txt @@ -1 +0,0 @@ -[T][ ]e diff --git a/src/main/java/chatbox/Chatbox.java b/src/main/java/UI/Chatbox.java similarity index 96% rename from src/main/java/chatbox/Chatbox.java rename to src/main/java/UI/Chatbox.java index 169deded3..c6d12b9ec 100644 --- a/src/main/java/chatbox/Chatbox.java +++ b/src/main/java/UI/Chatbox.java @@ -1,4 +1,4 @@ -package chatbox; +package UI; public class Chatbox { private String content = ""; diff --git a/src/main/java/UI/UI.java b/src/main/java/UI/UI.java new file mode 100644 index 000000000..e556fa51d --- /dev/null +++ b/src/main/java/UI/UI.java @@ -0,0 +1,24 @@ +package UI; + +import exceptions.DukeExceptions; + +public class UI { + protected static final String HELLO_WORDS = "Hello! I'm Duke :P\nWhat can I do for you?"; + protected static final String GOODBYE_WORDS = "Bye. Hope to see you again soon! ;)"; + Chatbox chatbox = new Chatbox(); + + public void greet() { + chatbox.setContent(HELLO_WORDS); + chatbox.chatboxPrinter(); + } + + public void goodbye() { + chatbox.setContent(GOODBYE_WORDS); + chatbox.chatboxPrinter(); + } + + public void printMsg(String message) { + chatbox.setContent(message); + chatbox.chatboxPrinter(); + } +} diff --git a/src/main/java/controller/Controller.java b/src/main/java/controller/Controller.java index 1a6cf7142..94e4b00b7 100644 --- a/src/main/java/controller/Controller.java +++ b/src/main/java/controller/Controller.java @@ -1,6 +1,6 @@ package controller; -import chatbox.Chatbox; +import UI.*; import exceptions.*; import tasks.TaskManager; @@ -8,58 +8,62 @@ public class Controller { //greeting msg and exit msg - protected String HELLO_WORDS = "Hello! I'm Duke :P\nWhat can I do for you?"; - protected String GOODBYE_WORDS = "Bye. Hope to see you again soon! ;)"; - protected String recvMsg = ""; - protected String replyMsg = ""; - Chatbox chatbox = new Chatbox(); + protected String recvMsg; + protected String replyMsg; + protected static final String MARK_TASK_COMMAND = "mark"; + protected static final String UNMARK_TASK_COMMAND = "unmark"; + protected static final String DELETE_TASK_COMMAND = "delete"; + protected static final String ADD_TODO_TASK_COMMAND = "todo"; + protected static final String ADD_EVENT_TASK_COMMAND = "event"; + protected static final String ADD_DEADLINE_TASK_COMMAND = "deadline"; + protected static final String LIST_TASKS_COMMAND = "list"; + protected static final String EXIT_COMMAND = "bye"; TaskManager manager = new TaskManager(); OperationAnalyst analyst; + UI userInterface = new UI(); /** * Prints greeting msg */ public void greet() { - chatbox.setContent(HELLO_WORDS); - chatbox.chatboxPrinter(); + userInterface.greet(); } /** * Prints goodbye msg and exits */ public void bye() { - chatbox.setContent(GOODBYE_WORDS); - chatbox.chatboxPrinter(); + userInterface.goodbye(); System.exit(0); } /** * Unmarks task in the list */ - public void unmarkTask() throws DukeExceptions { + public String unmarkTask() throws DukeExceptions { try { int index= Integer.parseInt(analyst.taskName); - manager.unmarkTask(index); + return manager.unmarkTask(index); } catch (NumberFormatException e) { - throw new IllegalTaskIndexException(); + throw new TaskIndexLossException(); } } - public void markTask() throws DukeExceptions{ + public String markTask() throws DukeExceptions{ try { int index = Integer.parseInt(analyst.taskName); - manager.markTask(index); + return manager.markTask(index); } catch (NumberFormatException e) { - throw new IllegalTaskIndexException(); + throw new TaskIndexLossException(); } } - public void deleteTask() throws DukeExceptions { + public String deleteTask() throws DukeExceptions { try { int index = Integer.parseInt(analyst.taskName); - manager.deleteTask(index); + return manager.deleteTask(index); } catch (NumberFormatException e) { - throw new IllegalTaskIndexException(); + throw new TaskIndexLossException(); } } @@ -81,46 +85,37 @@ public void listen() throws DukeExceptions { analyst = new OperationAnalyst(this.recvMsg); String command = analyst.getCommand(); switch (command) { - case "bye": + case EXIT_COMMAND: this.bye(); break; - case "list": - manager.listTask(); + case LIST_TASKS_COMMAND: + this.replyMsg = manager.listTask(); break; - case "mark": - this.markTask(); + case MARK_TASK_COMMAND: + this.replyMsg = this.markTask(); break; - case "unmark": - this.unmarkTask(); + case UNMARK_TASK_COMMAND: + this.replyMsg = this.unmarkTask(); break; - case "deadline": - manager.addDeadline(analyst.taskName, analyst.time); + case ADD_DEADLINE_TASK_COMMAND: + this.replyMsg = manager.addDeadline(analyst.taskName, analyst.time); break; - case "event": - manager.addEvent(analyst.taskName, analyst.time); + case ADD_EVENT_TASK_COMMAND: + this.replyMsg = manager.addEvent(analyst.taskName, analyst.time); break; - case "todo": - manager.addToDo(analyst.taskName); + case ADD_TODO_TASK_COMMAND: + this.replyMsg = manager.addToDo(analyst.taskName); break; - case "delete": - this.deleteTask(); + case DELETE_TASK_COMMAND: + this.replyMsg = this.deleteTask(); + break; + default: + throw new IllegalInstructionException(); } + userInterface.printMsg(replyMsg); manager.saveTask(); - } catch (IllegalInstructionException e) { - chatbox.setContent("Sorry, I don't understand your instruction :("); - chatbox.chatboxPrinter(); - } catch (IllegalFormatException e) { - chatbox.setContent("Please check your format again :("); - chatbox.chatboxPrinter(); - } catch (IllegalTaskNameException e) { - chatbox.setContent("Did you specify your task name?"); - chatbox.chatboxPrinter(); - } catch (IllegalSavingAction e) { - chatbox.setContent("Cannot save to file :("); - chatbox.chatboxPrinter(); - } catch (IllegalTaskIndexException e) { - chatbox.setContent("Please specify the index of the task :("); - chatbox.chatboxPrinter(); + } catch (DukeExceptions e) { + userInterface.printMsg(e.toString()); } } diff --git a/src/main/java/controller/OperationAnalyst.java b/src/main/java/controller/OperationAnalyst.java index 9fe5df850..813d62187 100644 --- a/src/main/java/controller/OperationAnalyst.java +++ b/src/main/java/controller/OperationAnalyst.java @@ -2,14 +2,24 @@ import exceptions.*; +import java.time.DateTimeException; +import java.time.LocalDate; import java.util.Locale; public class OperationAnalyst { protected String[] keywords; protected String rawInput; - protected String time; + protected LocalDate time; protected String taskName; protected String instruction; + protected static final String MARK_TASK_COMMAND = "mark"; + protected static final String UNMARK_TASK_COMMAND = "unmark"; + protected static final String DELETE_TASK_COMMAND = "delete"; + protected static final String ADD_TODO_TASK_COMMAND = "todo"; + protected static final String ADD_EVENT_TASK_COMMAND = "event"; + protected static final String ADD_DEADLINE_TASK_COMMAND = "deadline"; + protected static final String LIST_TASKS_COMMAND = "list"; + protected static final String EXIT_COMMAND = "bye"; public OperationAnalyst(String input) throws DukeExceptions { this.keywords = input.split(" "); @@ -23,7 +33,6 @@ public OperationAnalyst(String input) throws DukeExceptions { * @return the command, whether it is deadline, todo, event, list, mark or unmark */ public String getCommand() { - return this.instruction; } @@ -34,39 +43,56 @@ public void parseInstruction() throws DukeExceptions{ //String name; String[] command; switch (this.instruction) { - case "deadline": + case ADD_DEADLINE_TASK_COMMAND: command = rawInput.split("/by "); - this.taskName = command[0].replace("deadline ", ""); try { - this.time = command[1]; + this.taskName = keywords[1]; + } catch (Exception e){ + throw new TaskNameLossException(); + } + try { + this.time = LocalDate.parse(command[1].toString()); } catch (IndexOutOfBoundsException e){ throw new IllegalFormatException(); + } catch (DateTimeException e){ + throw new IllegalTimeFormatException(); } //System.out.println(this.time); break; - case "event": + case ADD_EVENT_TASK_COMMAND: command = rawInput.split("/at "); - this.taskName = command[0].replace("event ", ""); try { - this.time = command[1]; + this.taskName = keywords[1]; + } catch (Exception e){ + throw new TaskNameLossException(); + } + try { + String date = command[1]; + this.time = LocalDate.parse(date); } catch (IndexOutOfBoundsException e){ throw new IllegalFormatException(); + } catch (DateTimeException e){ + throw new IllegalTimeFormatException(); } break; - case "todo": - this.taskName = rawInput.replace("todo ", ""); + case ADD_TODO_TASK_COMMAND: + try { + this.taskName = this.keywords[1]; + } catch (Exception e){ + throw new TaskNameLossException(); + } break; - case "mark": - case "unmark": - case "delete": + case MARK_TASK_COMMAND: + case UNMARK_TASK_COMMAND: + case DELETE_TASK_COMMAND: try { this.taskName = this.keywords[1]; } catch (IndexOutOfBoundsException e){ throw new IllegalFormatException(); } break; - case "list" : - case "bye" : + case LIST_TASKS_COMMAND: + case EXIT_COMMAND: break; default: this.taskName = rawInput; @@ -77,7 +103,7 @@ public String getTaskName() { return this.taskName; } - public String getTime() { + public LocalDate getTime() { return this.time; } } diff --git a/src/main/java/exceptions/CreatingFileException.java b/src/main/java/exceptions/CreatingFileException.java index a2701091e..32bad827d 100644 --- a/src/main/java/exceptions/CreatingFileException.java +++ b/src/main/java/exceptions/CreatingFileException.java @@ -1,4 +1,11 @@ package exceptions; public class CreatingFileException extends DukeExceptions{ + protected static final String CREATING_FILE_ERROR_MSG = + "Sorry, there's something wrong when creating file, please try again later QnQ"; + + @Override + public String toString() { + return CREATING_FILE_ERROR_MSG; + } } diff --git a/src/main/java/exceptions/DukeExceptions.java b/src/main/java/exceptions/DukeExceptions.java index c65525c08..7eaeabdcc 100644 --- a/src/main/java/exceptions/DukeExceptions.java +++ b/src/main/java/exceptions/DukeExceptions.java @@ -1,4 +1,4 @@ package exceptions; -public class DukeExceptions extends Exception{ +public abstract class DukeExceptions extends Exception{ } diff --git a/src/main/java/exceptions/EmptyListException.java b/src/main/java/exceptions/EmptyListException.java new file mode 100644 index 000000000..e6830a598 --- /dev/null +++ b/src/main/java/exceptions/EmptyListException.java @@ -0,0 +1,11 @@ +package exceptions; + +public class EmptyListException extends DukeExceptions{ + protected static final String EMPTY_LIST_ERROR_MSG = "The list is empty currently ( ̄3 ̄)a"; + + @Override + public String toString(){ + return EMPTY_LIST_ERROR_MSG; + } + +} diff --git a/src/main/java/exceptions/IllegalFormatException.java b/src/main/java/exceptions/IllegalFormatException.java index 75e783542..cd57ac25d 100644 --- a/src/main/java/exceptions/IllegalFormatException.java +++ b/src/main/java/exceptions/IllegalFormatException.java @@ -1,4 +1,11 @@ package exceptions; public class IllegalFormatException extends DukeExceptions { + protected static final String FORMAT_ERROR_MSG = + "The format is incorrect! Can you please check your input again? ●ω●"; + + @Override + public String toString() { + return FORMAT_ERROR_MSG; + } } diff --git a/src/main/java/exceptions/IllegalIndexException.java b/src/main/java/exceptions/IllegalIndexException.java new file mode 100644 index 000000000..07bbcd9e4 --- /dev/null +++ b/src/main/java/exceptions/IllegalIndexException.java @@ -0,0 +1,11 @@ +package exceptions; + +public class IllegalIndexException extends DukeExceptions{ + protected static final String ILLEGAL_INDEX_ERROR_MSG = "I can't find the task from the list (°ー°〃) Please check your index again"; + + @Override + public String toString(){ + return ILLEGAL_INDEX_ERROR_MSG; + } + +} diff --git a/src/main/java/exceptions/IllegalInstructionException.java b/src/main/java/exceptions/IllegalInstructionException.java index 9a6bddc1e..67d687970 100644 --- a/src/main/java/exceptions/IllegalInstructionException.java +++ b/src/main/java/exceptions/IllegalInstructionException.java @@ -1,4 +1,11 @@ package exceptions; public class IllegalInstructionException extends DukeExceptions { + protected static final String INSTRUCTION_ERROR_MSG = + "…(⊙_⊙;)… Sorry I can't understand. Please check the manual for acceptable instructions"; + + @Override + public String toString() { + return INSTRUCTION_ERROR_MSG; + } } diff --git a/src/main/java/exceptions/IllegalReadingAction.java b/src/main/java/exceptions/IllegalReadingAction.java index 8b052bf7b..12ed588fd 100644 --- a/src/main/java/exceptions/IllegalReadingAction.java +++ b/src/main/java/exceptions/IllegalReadingAction.java @@ -1,4 +1,11 @@ package exceptions; public class IllegalReadingAction extends DukeExceptions{ + protected static final String READING_FILE_ERROR_MSG = + "Sorry, there's something wrong when loading task, please try again later QnQ"; + + @Override + public String toString() { + return READING_FILE_ERROR_MSG; + } } diff --git a/src/main/java/exceptions/IllegalSavingAction.java b/src/main/java/exceptions/IllegalSavingAction.java index 0f73f5fa7..e83f96bbd 100644 --- a/src/main/java/exceptions/IllegalSavingAction.java +++ b/src/main/java/exceptions/IllegalSavingAction.java @@ -1,4 +1,11 @@ package exceptions; public class IllegalSavingAction extends DukeExceptions { + protected static final String SAVING_FILE_ERROR_MSG = + "Sorry, there's something wrong when saving task, please try again later QnQ"; + + @Override + public String toString() { + return SAVING_FILE_ERROR_MSG; + } } diff --git a/src/main/java/exceptions/IllegalTaskIndexException.java b/src/main/java/exceptions/IllegalTaskIndexException.java deleted file mode 100644 index baaa873e4..000000000 --- a/src/main/java/exceptions/IllegalTaskIndexException.java +++ /dev/null @@ -1,4 +0,0 @@ -package exceptions; - -public class IllegalTaskIndexException extends DukeExceptions { -} diff --git a/src/main/java/exceptions/IllegalTaskNameException.java b/src/main/java/exceptions/IllegalTaskNameException.java deleted file mode 100644 index f57cfe40f..000000000 --- a/src/main/java/exceptions/IllegalTaskNameException.java +++ /dev/null @@ -1,4 +0,0 @@ -package exceptions; - -public class IllegalTaskNameException extends DukeExceptions { -} diff --git a/src/main/java/exceptions/IllegalTimeFormatException.java b/src/main/java/exceptions/IllegalTimeFormatException.java new file mode 100644 index 000000000..07c0bb4cc --- /dev/null +++ b/src/main/java/exceptions/IllegalTimeFormatException.java @@ -0,0 +1,11 @@ +package exceptions; + +public class IllegalTimeFormatException extends DukeExceptions{ + protected static final String FORMAT_ERROR_MSG = + "The time format is incorrect! Can you please check your input again? ●ω●"; + + @Override + public String toString() { + return FORMAT_ERROR_MSG; + } +} diff --git a/src/main/java/exceptions/TaskIndexLossException.java b/src/main/java/exceptions/TaskIndexLossException.java new file mode 100644 index 000000000..cb9c52f4b --- /dev/null +++ b/src/main/java/exceptions/TaskIndexLossException.java @@ -0,0 +1,11 @@ +package exceptions; + +public class TaskIndexLossException extends DukeExceptions { + protected static final String INDEX_LOSS_ERROR_MSG = + "Did you specify the index?∑(っ °Д °;)っ"; + + @Override + public String toString() { + return INDEX_LOSS_ERROR_MSG; + } +} diff --git a/src/main/java/exceptions/TaskNameLossException.java b/src/main/java/exceptions/TaskNameLossException.java new file mode 100644 index 000000000..0254d272e --- /dev/null +++ b/src/main/java/exceptions/TaskNameLossException.java @@ -0,0 +1,11 @@ +package exceptions; + +public class TaskNameLossException extends DukeExceptions { + protected static final String INDEX_LOSS_ERROR_MSG = + "Did you specify the name of the task?∑(っ °Д °;)っ"; + + @Override + public String toString() { + return INDEX_LOSS_ERROR_MSG; + } +} diff --git a/src/main/java/tasks/Deadline.java b/src/main/java/tasks/Deadline.java index d74daccbc..ac68e5290 100644 --- a/src/main/java/tasks/Deadline.java +++ b/src/main/java/tasks/Deadline.java @@ -1,20 +1,28 @@ package tasks; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + public class Deadline extends Task { - protected String by; + LocalDate by; - public Deadline(String name, String by){ + public Deadline(String name, LocalDate by){ super(name); this.by = by; setListName(); } + public String getTime() { + return by.format(DateTimeFormatter.ofPattern("MMM d yyyy")); + } + @Override public void setListName(){ if(!isDone){ - this.listName = "[D]" + this.unmarkedStatus + this.taskName + "(by: " + by + ")"; + this.listName = "[D]" + this.unmarkedStatus + this.taskName + "(by: " + this.getTime() + ")"; }else{ - this.listName = "[D]" + this.markedStatus + this.taskName + "(by: " + by + ")"; + this.listName = "[D]" + this.markedStatus + this.taskName + "(by: " + this.getTime() + ")"; } } + } diff --git a/src/main/java/tasks/Event.java b/src/main/java/tasks/Event.java index d1f594f57..3b4eec260 100644 --- a/src/main/java/tasks/Event.java +++ b/src/main/java/tasks/Event.java @@ -1,20 +1,30 @@ package tasks; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; public class Event extends Task { - protected String at; + LocalDate at; - public Event(String name, String at) { + public Event(String name, LocalDate at) { super(name); this.at = at; setListName(); } + public String getTime() { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM d yyyy"); + String time = this.at.format(formatter); + System.out.println(time); + return time; + } + @Override public void setListName() { if(!isDone){ - this.listName = "[E]" + this.unmarkedStatus + this.taskName + "(at: " + at + ")"; + this.listName = "[E]" + this.unmarkedStatus + this.taskName + "(at: " + getTime() + ")"; }else{ - this.listName = "[E]" + this.markedStatus + this.taskName + "(at: " + at + ")"; + this.listName = "[E]" + this.markedStatus + this.taskName + "(at: " + getTime() + ")"; } } } diff --git a/src/main/java/tasks/Storage.java b/src/main/java/tasks/Storage.java index 448ae8822..8de5c095d 100644 --- a/src/main/java/tasks/Storage.java +++ b/src/main/java/tasks/Storage.java @@ -3,13 +3,18 @@ import exceptions.*; import java.io.*; +import java.time.LocalDate; import java.util.ArrayList; import java.util.Arrays; import java.util.regex.*; public class Storage { private static final ArrayList Tasks = new ArrayList(); - private static final String FILE_NAME = "data/duke.txt"; + protected static final String FILE_NAME = "data/duke.txt"; + protected static final String DONE = "X"; + protected static final String TODO = "T"; + protected static final String EVENT = "E"; + protected static final String DEADLINE = "d"; public int size() { return Tasks.size(); @@ -52,13 +57,13 @@ public String[] parseInput(String listName) { info = info.replaceAll("\\[", ""); info = info.replaceAll("\\(", "\\|"); info = info.replaceAll("\\)", ""); - System.out.println(info); + //System.out.println(info); String[] data = info.split("\\|"); return data; } public void mark(Task task, String status){ - if(status.equals("X")){ + if(status.equals(DONE)){ task.isDone = true; } } @@ -66,25 +71,25 @@ public void mark(Task task, String status){ public void loadTask() throws DukeExceptions{ try (BufferedReader loadData = new BufferedReader(new FileReader(FILE_NAME))){ String listName; - String time; + LocalDate time; while ((listName = loadData.readLine()) != null) { String[] data = this.parseInput(listName); - System.out.println(listName); - System.out.println(Arrays.toString(data)); + //System.out.println(listName); + //System.out.println(Arrays.toString(data)); switch (data[0]) { - case "T": + case TODO: ToDo newToDo = new ToDo(data[2]); mark(newToDo, data[2]); Tasks.add(newToDo); break; - case "E": - time = data[3].replace("at: ", ""); + case EVENT: + time = LocalDate.parse(data[3].replace("at: ", "")); Event newEvent = new Event(data[2], time); mark(newEvent, data[2]); Tasks.add(newEvent); break; - case "D": - time = data[3].replace("by: ", ""); + case DEADLINE: + time = LocalDate.parse(data[3].replace("by ", "")); Deadline newDeadline = new Deadline(data[2], time); mark(newDeadline, data[2]); Tasks.add(newDeadline); diff --git a/src/main/java/tasks/TaskManager.java b/src/main/java/tasks/TaskManager.java index 4dd345c7f..e146b8a75 100644 --- a/src/main/java/tasks/TaskManager.java +++ b/src/main/java/tasks/TaskManager.java @@ -1,18 +1,23 @@ package tasks; -import java.util.ArrayList; -import java.io.FileWriter; -import java.io.File; -import chatbox.*; +import UI.*; import exceptions.*; +import java.time.LocalDate; + public class TaskManager { Storage Tasks = new Storage(); //response of adding - protected String ADD_RES = "Got it. I've added this task:\n"; + protected static final String ADD_RESPONSE = "ψ(._. )> Got it. I've added this task:\n"; + protected static final String MARK_RESPONSE = "ψ(._. )> Nice! I've marked this task as done:\n"; + protected static final String UNMARK_RESPONSE = "ψ(._. )> OK, I've marked this task as not done yet:\n"; + protected static final String LIST_RESPONSE = "o(≧v≦)o Here are the tasks in your list:\n"; + protected static final String DELETE_RESPONSE = "ψ(._. )> Okay! I've deleted this task:\n"; Chatbox chatbox = new Chatbox(); - + public String taskNumberMsg(int taskNumber){ + return "Now you have " + taskNumber + " tasks in your list."; + } public void saveTask() throws DukeExceptions { Tasks.saveTask(); } @@ -40,14 +45,12 @@ public void addTask(String name) { * @param name refers to the name of the task * @param by refers to the deadline of the task */ - public void addDeadline(String name, String by) { + public String addDeadline(String name, LocalDate by) { Deadline newDeadline = new Deadline(name, by); Tasks.add(newDeadline); int s = Tasks.size(); - String response = ADD_RES + newDeadline.getListName() + - "\n" + "Now you have " + String.valueOf(s) + " tasks in your list."; - chatbox.setContent(response); - chatbox.chatboxPrinter(); + return ADD_RESPONSE + newDeadline.getListName() + + "\n" + this.taskNumberMsg(s); } /** @@ -55,38 +58,34 @@ public void addDeadline(String name, String by) { * @param name refers to the name of the task * @param at refers to the happening time of the event */ - public void addEvent(String name, String at) { + public String addEvent(String name, LocalDate at) { Event newEvent = new Event(name, at); Tasks.add(newEvent); int s = Tasks.size(); - String response = ADD_RES + newEvent.getListName() + - "\n" + "Now you have " + String.valueOf(s) + " tasks in your list."; - chatbox.setContent(response); - chatbox.chatboxPrinter(); + return ADD_RESPONSE + newEvent.getListName() + + "\n" + this.taskNumberMsg(s); } /** * Adds a todo task to the list * @param name refers to the name of the todo task */ - public void addToDo(String name) { + public String addToDo(String name) { ToDo newToDo = new ToDo(name); Tasks.add(newToDo); int s = Tasks.size(); - String response = ADD_RES + newToDo.getListName() + "\n" + - "Now you have " + String.valueOf(s) + " tasks in your list."; - chatbox.setContent(response); - chatbox.chatboxPrinter(); + return ADD_RESPONSE + newToDo.getListName() + "\n" + + this.taskNumberMsg(s); } /** * Lists all tasks in the list with adding time order */ - public void listTask() { - String content = "Here are the tasks in your list:\n"; + public String listTask() throws DukeExceptions{ if(Tasks.size() == 0){ - content = "Sorry, there's no task in the list :("; + throw new EmptyListException(); }else { + String content = LIST_RESPONSE; for (int i = 0; i < Tasks.size(); i++) { String index = String.valueOf(i + 1); String name = index + ". " + Tasks.get(i).getListName(); @@ -95,59 +94,51 @@ public void listTask() { content += "\n"; } } + return content; } - chatbox.setContent(content); - chatbox.chatboxPrinter(); + } /** * Marks specific task in the list as done * @param n refers to the index of the task in adding time order */ - public void markTask(int n) { + public String markTask(int n) throws DukeExceptions{ System.out.println(n); - String content = ""; if(n < 1 || n > Tasks.size()) { //Beyonds boundaries - content = "Sorry, I could not find the task :/"; + throw new IllegalIndexException(); }else { Tasks.get(n - 1).mark(); - content = "Nice! I've marked this task as done:\n" + Tasks.get(n - 1).listName; + return MARK_RESPONSE + Tasks.get(n - 1).listName; } - chatbox.setContent(content); - chatbox.chatboxPrinter(); } /** * Unmarks specific task in the list as undone * @param n refers to the index of the task in adding time order */ - public void unmarkTask(int n) { - String content = ""; + public String unmarkTask(int n) throws DukeExceptions{ if(n < 1 || n > Tasks.size()){ - // Beyonds boundaries - content = "Sorry, I could not find the task :/"; + throw new IllegalIndexException(); }else { Tasks.get(n - 1).unmark(); - content = "OK, I've marked this task as not done yet:\n" + Tasks.get(n - 1).listName; + return UNMARK_RESPONSE + Tasks.get(n - 1).listName; + } - chatbox.setContent(content); - chatbox.chatboxPrinter(); } - public void deleteTask(int n) { - String content = ""; + public String deleteTask(int n) throws DukeExceptions{ if(n < 1 || n > Tasks.size()) { //Beyonds boundaries - content = "Sorry, I could not find the task :/"; + throw new IllegalIndexException(); }else { - content = "Okay! I've deleted this task:\n" + Tasks.get(n - 1).listName; + String content = DELETE_RESPONSE + Tasks.get(n - 1).listName; Tasks.remove(n-1); int s = Tasks.size(); - content += "\nNow you have " + String.valueOf(s) + " tasks in your list"; + content += "\n" + this.taskNumberMsg(s); + return content; } - chatbox.setContent(content); - chatbox.chatboxPrinter(); } From 7dab026c3d29021b216d9db5a7d3f04ff1b345eb Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Sun, 27 Feb 2022 21:36:50 +0800 Subject: [PATCH 24/45] Add Date and Time --- data/duke.txt | 5 ++ src/main/java/Duke.java | 2 +- src/main/java/controller/Controller.java | 2 +- .../java/controller/OperationAnalyst.java | 20 +++++--- .../IllegalTimeFormatException.java | 3 +- src/main/java/tasks/Deadline.java | 22 +++++---- src/main/java/tasks/Event.java | 31 +++++++----- src/main/java/tasks/Storage.java | 20 ++++++-- src/main/java/tasks/TaskManager.java | 5 +- src/main/java/time/DateFormatChecker.java | 35 ++++++++++++++ src/main/java/time/DateTimeFormatChecker.java | 37 ++++++++++++++ src/main/java/time/Time.java | 48 +++++++++++++++++++ src/main/java/time/TimeToStringConverter.java | 35 ++++++++++++++ 13 files changed, 227 insertions(+), 38 deletions(-) create mode 100644 src/main/java/time/DateFormatChecker.java create mode 100644 src/main/java/time/DateTimeFormatChecker.java create mode 100644 src/main/java/time/Time.java create mode 100644 src/main/java/time/TimeToStringConverter.java diff --git a/data/duke.txt b/data/duke.txt index e69de29bb..f8d138d88 100644 --- a/data/duke.txt +++ b/data/duke.txt @@ -0,0 +1,5 @@ +[E][ ]j(at: Feb. 22 2019) +[E][ ]j(at: Sep. 12 2001) +[E][ ]j(at: Mar. 20 2001 13:00) +[E][ ]k(at: Feb. 02 2001) +[D][ ]kk(by: Mar. 03 2019 07:10) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 7c54e55ac..aed2f70fa 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -2,7 +2,7 @@ import exceptions.*; public class Duke { - public static void main(String[] args) throws DukeExceptions { + public static void main(String[] args) throws Exception { Controller bot = new Controller(); bot.greet(); bot.createFile(); diff --git a/src/main/java/controller/Controller.java b/src/main/java/controller/Controller.java index 94e4b00b7..6c35a4f0b 100644 --- a/src/main/java/controller/Controller.java +++ b/src/main/java/controller/Controller.java @@ -78,7 +78,7 @@ public void loadTask() throws DukeExceptions{ /** * Listen the instruction and operate during the session */ - public void listen() throws DukeExceptions { + public void listen() throws Exception { Scanner msg = new Scanner(System.in); this.recvMsg = msg.nextLine(); try { diff --git a/src/main/java/controller/OperationAnalyst.java b/src/main/java/controller/OperationAnalyst.java index 813d62187..1d320aeac 100644 --- a/src/main/java/controller/OperationAnalyst.java +++ b/src/main/java/controller/OperationAnalyst.java @@ -1,15 +1,17 @@ package controller; import exceptions.*; +import time.*; import java.time.DateTimeException; import java.time.LocalDate; import java.util.Locale; +import java.util.Date; public class OperationAnalyst { protected String[] keywords; protected String rawInput; - protected LocalDate time; + protected String time; protected String taskName; protected String instruction; protected static final String MARK_TASK_COMMAND = "mark"; @@ -20,6 +22,7 @@ public class OperationAnalyst { protected static final String ADD_DEADLINE_TASK_COMMAND = "deadline"; protected static final String LIST_TASKS_COMMAND = "list"; protected static final String EXIT_COMMAND = "bye"; + Time timeChecker; public OperationAnalyst(String input) throws DukeExceptions { this.keywords = input.split(" "); @@ -51,10 +54,12 @@ public void parseInstruction() throws DukeExceptions{ throw new TaskNameLossException(); } try { - this.time = LocalDate.parse(command[1].toString()); + timeChecker = new Time(command[1]); + timeChecker.check(); + this.time = timeChecker.getDateString(); } catch (IndexOutOfBoundsException e){ throw new IllegalFormatException(); - } catch (DateTimeException e){ + } catch (Exception e){ throw new IllegalTimeFormatException(); } //System.out.println(this.time); @@ -67,11 +72,12 @@ public void parseInstruction() throws DukeExceptions{ throw new TaskNameLossException(); } try { - String date = command[1]; - this.time = LocalDate.parse(date); + timeChecker = new Time(command[1]); + timeChecker.check(); + this.time = timeChecker.getDateString(); } catch (IndexOutOfBoundsException e){ throw new IllegalFormatException(); - } catch (DateTimeException e){ + } catch (Exception e){ throw new IllegalTimeFormatException(); } break; @@ -103,7 +109,7 @@ public String getTaskName() { return this.taskName; } - public LocalDate getTime() { + public String getTime() { return this.time; } } diff --git a/src/main/java/exceptions/IllegalTimeFormatException.java b/src/main/java/exceptions/IllegalTimeFormatException.java index 07c0bb4cc..e09de3e25 100644 --- a/src/main/java/exceptions/IllegalTimeFormatException.java +++ b/src/main/java/exceptions/IllegalTimeFormatException.java @@ -2,7 +2,8 @@ public class IllegalTimeFormatException extends DukeExceptions{ protected static final String FORMAT_ERROR_MSG = - "The time format is incorrect! Can you please check your input again? ●ω●"; + "The time format is incorrect! Can you please check your input again? ( ̄~ ̄;) " + + "You can check the manual to find out acceptable time format!"; @Override public String toString() { diff --git a/src/main/java/tasks/Deadline.java b/src/main/java/tasks/Deadline.java index ac68e5290..2216ea01c 100644 --- a/src/main/java/tasks/Deadline.java +++ b/src/main/java/tasks/Deadline.java @@ -1,27 +1,31 @@ package tasks; +import time.TimeToStringConverter; + import java.time.LocalDate; import java.time.format.DateTimeFormatter; +import java.util.Date; +import time.*; public class Deadline extends Task { - LocalDate by; + protected Date by; + protected String byString; + Time timeConverter; - public Deadline(String name, LocalDate by){ + public Deadline(String name, String byString) throws Exception{ super(name); - this.by = by; + this.byString = byString; + timeConverter = new Time(byString); + by = timeConverter.getNewDate(); setListName(); } - public String getTime() { - return by.format(DateTimeFormatter.ofPattern("MMM d yyyy")); - } - @Override public void setListName(){ if(!isDone){ - this.listName = "[D]" + this.unmarkedStatus + this.taskName + "(by: " + this.getTime() + ")"; + this.listName = "[D]" + this.unmarkedStatus + this.taskName + "(by: " + byString + ")"; }else{ - this.listName = "[D]" + this.markedStatus + this.taskName + "(by: " + this.getTime() + ")"; + this.listName = "[D]" + this.markedStatus + this.taskName + "(by: " + byString + ")"; } } diff --git a/src/main/java/tasks/Event.java b/src/main/java/tasks/Event.java index 3b4eec260..12709c95d 100644 --- a/src/main/java/tasks/Event.java +++ b/src/main/java/tasks/Event.java @@ -1,30 +1,37 @@ package tasks; +import time.TimeToStringConverter; + import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; +import java.util.Date; +import time.*; + public class Event extends Task { - LocalDate at; + protected Date at; + protected String atString; + Time timeConverter; - public Event(String name, LocalDate at) { + public Event(String name, String atString) throws Exception{ super(name); - this.at = at; + this.atString = atString; + timeConverter = new Time(atString); + at = timeConverter.getNewDate(); + //System.out.println(this.at.toString()); setListName(); } - public String getTime() { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM d yyyy"); - String time = this.at.format(formatter); - System.out.println(time); - return time; - } - @Override + + public void setListName() { if(!isDone){ - this.listName = "[E]" + this.unmarkedStatus + this.taskName + "(at: " + getTime() + ")"; + this.listName = "[E]" + this.unmarkedStatus + this.taskName + "(at: " + atString + ")"; }else{ - this.listName = "[E]" + this.markedStatus + this.taskName + "(at: " + getTime() + ")"; + this.listName = "[E]" + this.markedStatus + this.taskName + "(at: " + atString + ")"; } } + + } diff --git a/src/main/java/tasks/Storage.java b/src/main/java/tasks/Storage.java index 8de5c095d..a3d0b4442 100644 --- a/src/main/java/tasks/Storage.java +++ b/src/main/java/tasks/Storage.java @@ -1,10 +1,12 @@ package tasks; import exceptions.*; +import time.Time; import java.io.*; import java.time.LocalDate; import java.util.ArrayList; +import java.util.Date; import java.util.Arrays; import java.util.regex.*; @@ -15,6 +17,7 @@ public class Storage { protected static final String TODO = "T"; protected static final String EVENT = "E"; protected static final String DEADLINE = "d"; + Time timeChecker; public int size() { return Tasks.size(); @@ -71,7 +74,8 @@ public void mark(Task task, String status){ public void loadTask() throws DukeExceptions{ try (BufferedReader loadData = new BufferedReader(new FileReader(FILE_NAME))){ String listName; - LocalDate time; + String oldTime; + String newTime; while ((listName = loadData.readLine()) != null) { String[] data = this.parseInput(listName); //System.out.println(listName); @@ -83,14 +87,20 @@ public void loadTask() throws DukeExceptions{ Tasks.add(newToDo); break; case EVENT: - time = LocalDate.parse(data[3].replace("at: ", "")); - Event newEvent = new Event(data[2], time); + oldTime = data[3].replace("at: ", ""); + timeChecker = new Time(oldTime); + timeChecker.check(); + newTime = timeChecker.getDateString(); + Event newEvent = new Event(data[2], newTime); mark(newEvent, data[2]); Tasks.add(newEvent); break; case DEADLINE: - time = LocalDate.parse(data[3].replace("by ", "")); - Deadline newDeadline = new Deadline(data[2], time); + oldTime = data[3].replace("by: ", ""); + timeChecker = new Time(oldTime); + timeChecker.check(); + newTime = timeChecker.getDateString(); + Deadline newDeadline = new Deadline(data[2], newTime); mark(newDeadline, data[2]); Tasks.add(newDeadline); break; diff --git a/src/main/java/tasks/TaskManager.java b/src/main/java/tasks/TaskManager.java index e146b8a75..32b04b46c 100644 --- a/src/main/java/tasks/TaskManager.java +++ b/src/main/java/tasks/TaskManager.java @@ -4,6 +4,7 @@ import exceptions.*; import java.time.LocalDate; +import java.util.Date; public class TaskManager { Storage Tasks = new Storage(); @@ -45,7 +46,7 @@ public void addTask(String name) { * @param name refers to the name of the task * @param by refers to the deadline of the task */ - public String addDeadline(String name, LocalDate by) { + public String addDeadline(String name, String by) throws Exception{ Deadline newDeadline = new Deadline(name, by); Tasks.add(newDeadline); int s = Tasks.size(); @@ -58,7 +59,7 @@ public String addDeadline(String name, LocalDate by) { * @param name refers to the name of the task * @param at refers to the happening time of the event */ - public String addEvent(String name, LocalDate at) { + public String addEvent(String name, String at) throws Exception{ Event newEvent = new Event(name, at); Tasks.add(newEvent); int s = Tasks.size(); diff --git a/src/main/java/time/DateFormatChecker.java b/src/main/java/time/DateFormatChecker.java new file mode 100644 index 000000000..42c31a4db --- /dev/null +++ b/src/main/java/time/DateFormatChecker.java @@ -0,0 +1,35 @@ +package time; + +import exceptions.DukeExceptions; +import exceptions.IllegalTimeFormatException; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.util.*; +import java.util.concurrent.ScheduledExecutorService; + +public class DateFormatChecker extends Time { + private static final List formatStrings = + Arrays.asList("M/d/y", "M-d-y", "y-M-d", "y/M/d", "MMM dd yyyy", "M/d", "M-d", "d/M", "d-M"); + protected static final SimpleDateFormat stdFormatter = new SimpleDateFormat("MMM dd yyyy"); + + public DateFormatChecker(String date) throws DukeExceptions { + super(date); + for(String formatString : formatStrings) { + try { + SimpleDateFormat formatter = new SimpleDateFormat(formatString); + formatter.setLenient(false); + newDate = formatter.parse(date); + dateString = stdFormatter.format(newDate); + //System.out.println(dateString); + isValidDate = true; + break; + } catch (ParseException e) { + //throw new IllegalTimeFormatException(); + } + } + } + +} + diff --git a/src/main/java/time/DateTimeFormatChecker.java b/src/main/java/time/DateTimeFormatChecker.java new file mode 100644 index 000000000..89bbb651b --- /dev/null +++ b/src/main/java/time/DateTimeFormatChecker.java @@ -0,0 +1,37 @@ +package time; + +import exceptions.DukeExceptions; +import exceptions.IllegalTimeFormatException; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.List; + +public class DateTimeFormatChecker extends Time{ + private static final List formatStrings = + Arrays.asList("M/d/y H:m", "M/d/y H", "M-d-y H:m", + "M-d-y H", "y-M-d H:m", "y-M-d H", + "y/M/d H:m", "y/M/d H", "MMM dd yyyy H:m","M/d H:m", "M/d H", + "M-d H:m", "d/M H:m", "d/M H", "d-M H:m", "d/M H"); + + protected static final SimpleDateFormat stdFormatter = new SimpleDateFormat("MMM dd yyyy HH:mm"); + + public DateTimeFormatChecker(String date) throws DukeExceptions { + super(date); + for(String formatString: formatStrings) { + try { + SimpleDateFormat formatter = new SimpleDateFormat(formatString); + formatter.setLenient(false); + newDate = formatter.parse(date); + dateString = stdFormatter.format(newDate); + //System.out.println(dateString); + isValidTime = true; + break; + } catch (ParseException e) { + //throw new IllegalTimeFormatException(); + } + } + } +} + diff --git a/src/main/java/time/Time.java b/src/main/java/time/Time.java new file mode 100644 index 000000000..de4328b7d --- /dev/null +++ b/src/main/java/time/Time.java @@ -0,0 +1,48 @@ +package time; + +import exceptions.DukeExceptions; +import exceptions.IllegalTimeFormatException; + +import java.time.LocalDate; +import java.util.Date; + +public class Time { + protected boolean isValid; + protected static boolean isValidDate; + protected static boolean isValidTime; + protected static Date newDate; + protected static String dateString; + protected String oldDate; + DateTimeFormatChecker checkTime; + DateFormatChecker checkDate; + + public Time(String date) { + oldDate = date; + isValidDate = false; + isValidTime = false; + isValid = false; + } + + public void check() throws DukeExceptions { + if(oldDate.contains(":")) { + checkTime = new DateTimeFormatChecker(oldDate); + } else { + checkDate = new DateFormatChecker(oldDate); + } + + if (!isValidTime && !isValidDate) { + throw new IllegalTimeFormatException(); + } + } + + public boolean validation() { + return isValid; + } + + public Date getNewDate() { + return newDate; + } + public String getDateString() { + return dateString; + } +} diff --git a/src/main/java/time/TimeToStringConverter.java b/src/main/java/time/TimeToStringConverter.java new file mode 100644 index 000000000..7282e1c23 --- /dev/null +++ b/src/main/java/time/TimeToStringConverter.java @@ -0,0 +1,35 @@ +package time; + +import java.text.SimpleDateFormat; +import java.util.Date; + +public class TimeToStringConverter { + protected static final SimpleDateFormat stdDateTimeFormatter = new SimpleDateFormat("MMM dd yyyy HH:mm"); + protected static final SimpleDateFormat stdDateFormatter = new SimpleDateFormat("MMM dd yyyy"); + protected boolean isDateTime; + protected boolean isDate; + protected String timeString; + + public TimeToStringConverter (Date date) throws Exception { + try{ + timeString = stdDateFormatter.format(date); + //System.out.println(timeString); + isDate = true; + } catch (Exception e) { + isDate = false; + } + if (!isDate) { + try { + timeString = stdDateTimeFormatter.format(date); + //System.out.println(timeString); + isDateTime = true; + } catch (Exception e) { + } + isDateTime = false; + } + } + + public String getTimeString() { + return timeString; + } +} From c24a49e4d86b4d518a38570fddc564bf2e1a8016 Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Sun, 27 Feb 2022 23:42:57 +0800 Subject: [PATCH 25/45] Add Find --- data/duke.txt | 1 + src/main/java/controller/Controller.java | 4 +++ .../java/controller/OperationAnalyst.java | 20 +++++++++---- .../java/exceptions/KeywordLossException.java | 11 ++++++++ src/main/java/tasks/Deadline.java | 12 +++----- src/main/java/tasks/Event.java | 15 +++------- src/main/java/tasks/Storage.java | 6 ++-- src/main/java/tasks/TaskManager.java | 28 +++++++++++++++++-- 8 files changed, 67 insertions(+), 30 deletions(-) create mode 100644 src/main/java/exceptions/KeywordLossException.java diff --git a/data/duke.txt b/data/duke.txt index e69de29bb..c365df117 100644 --- a/data/duke.txt +++ b/data/duke.txt @@ -0,0 +1 @@ +[E][ ]1(at: jjj) diff --git a/src/main/java/controller/Controller.java b/src/main/java/controller/Controller.java index 94e4b00b7..49ff8f5a5 100644 --- a/src/main/java/controller/Controller.java +++ b/src/main/java/controller/Controller.java @@ -18,6 +18,7 @@ public class Controller { protected static final String ADD_DEADLINE_TASK_COMMAND = "deadline"; protected static final String LIST_TASKS_COMMAND = "list"; protected static final String EXIT_COMMAND = "bye"; + protected static final String SEARCH_COMMAND = "find"; TaskManager manager = new TaskManager(); OperationAnalyst analyst; UI userInterface = new UI(); @@ -109,6 +110,9 @@ public void listen() throws DukeExceptions { case DELETE_TASK_COMMAND: this.replyMsg = this.deleteTask(); break; + case SEARCH_COMMAND: + this.replyMsg = manager.searchTask(analyst.taskName); + break; default: throw new IllegalInstructionException(); } diff --git a/src/main/java/controller/OperationAnalyst.java b/src/main/java/controller/OperationAnalyst.java index 813d62187..bbd7707fc 100644 --- a/src/main/java/controller/OperationAnalyst.java +++ b/src/main/java/controller/OperationAnalyst.java @@ -9,7 +9,7 @@ public class OperationAnalyst { protected String[] keywords; protected String rawInput; - protected LocalDate time; + protected String time; protected String taskName; protected String instruction; protected static final String MARK_TASK_COMMAND = "mark"; @@ -20,6 +20,7 @@ public class OperationAnalyst { protected static final String ADD_DEADLINE_TASK_COMMAND = "deadline"; protected static final String LIST_TASKS_COMMAND = "list"; protected static final String EXIT_COMMAND = "bye"; + protected static final String SEARCH_COMMAND = "find"; public OperationAnalyst(String input) throws DukeExceptions { this.keywords = input.split(" "); @@ -51,7 +52,7 @@ public void parseInstruction() throws DukeExceptions{ throw new TaskNameLossException(); } try { - this.time = LocalDate.parse(command[1].toString()); + this.time = command[1]; } catch (IndexOutOfBoundsException e){ throw new IllegalFormatException(); } catch (DateTimeException e){ @@ -66,9 +67,8 @@ public void parseInstruction() throws DukeExceptions{ } catch (Exception e){ throw new TaskNameLossException(); } - try { - String date = command[1]; - this.time = LocalDate.parse(date); + try {; + this.time = command[1]; } catch (IndexOutOfBoundsException e){ throw new IllegalFormatException(); } catch (DateTimeException e){ @@ -91,6 +91,14 @@ public void parseInstruction() throws DukeExceptions{ throw new IllegalFormatException(); } break; + case SEARCH_COMMAND: + command = rawInput.split(" ",2); + try { + System.out.println(command.length); + this.taskName = command[1]; + } catch (IndexOutOfBoundsException e) { + throw new KeywordLossException(); + } case LIST_TASKS_COMMAND: case EXIT_COMMAND: break; @@ -103,7 +111,7 @@ public String getTaskName() { return this.taskName; } - public LocalDate getTime() { + public String getTime() { return this.time; } } diff --git a/src/main/java/exceptions/KeywordLossException.java b/src/main/java/exceptions/KeywordLossException.java new file mode 100644 index 000000000..bd84f232a --- /dev/null +++ b/src/main/java/exceptions/KeywordLossException.java @@ -0,0 +1,11 @@ +package exceptions; + +public class KeywordLossException extends DukeExceptions{ + protected static final String KEYWORD_LOSS_ERROR_MSG = + "Did you specify the keyword?∑(っ °Д °;)っ"; + + @Override + public String toString() { + return KEYWORD_LOSS_ERROR_MSG; + } +} diff --git a/src/main/java/tasks/Deadline.java b/src/main/java/tasks/Deadline.java index ac68e5290..cd7575290 100644 --- a/src/main/java/tasks/Deadline.java +++ b/src/main/java/tasks/Deadline.java @@ -4,24 +4,20 @@ import java.time.format.DateTimeFormatter; public class Deadline extends Task { - LocalDate by; + String by; - public Deadline(String name, LocalDate by){ + public Deadline(String name, String by){ super(name); this.by = by; setListName(); } - public String getTime() { - return by.format(DateTimeFormatter.ofPattern("MMM d yyyy")); - } - @Override public void setListName(){ if(!isDone){ - this.listName = "[D]" + this.unmarkedStatus + this.taskName + "(by: " + this.getTime() + ")"; + this.listName = "[D]" + this.unmarkedStatus + this.taskName + "(by: " + by + ")"; }else{ - this.listName = "[D]" + this.markedStatus + this.taskName + "(by: " + this.getTime() + ")"; + this.listName = "[D]" + this.markedStatus + this.taskName + "(by: " + by + ")"; } } diff --git a/src/main/java/tasks/Event.java b/src/main/java/tasks/Event.java index 3b4eec260..0948f7141 100644 --- a/src/main/java/tasks/Event.java +++ b/src/main/java/tasks/Event.java @@ -4,27 +4,20 @@ import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; public class Event extends Task { - LocalDate at; + String at; - public Event(String name, LocalDate at) { + public Event(String name, String at) { super(name); this.at = at; setListName(); } - public String getTime() { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM d yyyy"); - String time = this.at.format(formatter); - System.out.println(time); - return time; - } - @Override public void setListName() { if(!isDone){ - this.listName = "[E]" + this.unmarkedStatus + this.taskName + "(at: " + getTime() + ")"; + this.listName = "[E]" + this.unmarkedStatus + this.taskName + "(at: " + at + ")"; }else{ - this.listName = "[E]" + this.markedStatus + this.taskName + "(at: " + getTime() + ")"; + this.listName = "[E]" + this.markedStatus + this.taskName + "(at: " + at + ")"; } } } diff --git a/src/main/java/tasks/Storage.java b/src/main/java/tasks/Storage.java index 8de5c095d..184b620a4 100644 --- a/src/main/java/tasks/Storage.java +++ b/src/main/java/tasks/Storage.java @@ -71,7 +71,7 @@ public void mark(Task task, String status){ public void loadTask() throws DukeExceptions{ try (BufferedReader loadData = new BufferedReader(new FileReader(FILE_NAME))){ String listName; - LocalDate time; + String time; while ((listName = loadData.readLine()) != null) { String[] data = this.parseInput(listName); //System.out.println(listName); @@ -83,13 +83,13 @@ public void loadTask() throws DukeExceptions{ Tasks.add(newToDo); break; case EVENT: - time = LocalDate.parse(data[3].replace("at: ", "")); + time = data[3].replace("at: ", ""); Event newEvent = new Event(data[2], time); mark(newEvent, data[2]); Tasks.add(newEvent); break; case DEADLINE: - time = LocalDate.parse(data[3].replace("by ", "")); + time = data[3].replace("by: ", ""); Deadline newDeadline = new Deadline(data[2], time); mark(newDeadline, data[2]); Tasks.add(newDeadline); diff --git a/src/main/java/tasks/TaskManager.java b/src/main/java/tasks/TaskManager.java index e146b8a75..e96982d49 100644 --- a/src/main/java/tasks/TaskManager.java +++ b/src/main/java/tasks/TaskManager.java @@ -13,6 +13,8 @@ public class TaskManager { protected static final String UNMARK_RESPONSE = "ψ(._. )> OK, I've marked this task as not done yet:\n"; protected static final String LIST_RESPONSE = "o(≧v≦)o Here are the tasks in your list:\n"; protected static final String DELETE_RESPONSE = "ψ(._. )> Okay! I've deleted this task:\n"; + protected static final String NOT_FOUND_RESPONSE = "( ̄ε ̄;) Sorry, I can't find any result from the list."; + protected static final String FOUND_RESPONSE = "o(≧v≦)o Here are the matching tasks in your list:"; Chatbox chatbox = new Chatbox(); public String taskNumberMsg(int taskNumber){ @@ -45,7 +47,7 @@ public void addTask(String name) { * @param name refers to the name of the task * @param by refers to the deadline of the task */ - public String addDeadline(String name, LocalDate by) { + public String addDeadline(String name, String by) { Deadline newDeadline = new Deadline(name, by); Tasks.add(newDeadline); int s = Tasks.size(); @@ -58,7 +60,7 @@ public String addDeadline(String name, LocalDate by) { * @param name refers to the name of the task * @param at refers to the happening time of the event */ - public String addEvent(String name, LocalDate at) { + public String addEvent(String name, String at) { Event newEvent = new Event(name, at); Tasks.add(newEvent); int s = Tasks.size(); @@ -141,6 +143,28 @@ public String deleteTask(int n) throws DukeExceptions{ } } + public String searchTask(String keywords) throws DukeExceptions{ + if(Tasks.size() == 0){ + throw new EmptyListException(); + }else { + String content = ""; + int count = 0; + for (int i = 0; i < Tasks.size(); i++) { + if (Tasks.get(i).getListName().contains(keywords)) { + content += "\n"; + String index = String.valueOf(count + 1); + String name = index + ". " + Tasks.get(i).getListName(); + content += name; + count ++; + } + } + if(count == 0){ + return NOT_FOUND_RESPONSE; + } + return FOUND_RESPONSE + content; + } + } + From 1293634907a6939d7180c8e7011a75ae845dfa94 Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Tue, 1 Mar 2022 19:43:18 +0800 Subject: [PATCH 26/45] Improve code quality --- src/main/java/UI/UI.java | 2 - src/main/java/commands/AddCommand.java | 42 ++++++++ src/main/java/commands/Command.java | 57 ++++++++++ src/main/java/commands/SearchCommand.java | 21 ++++ .../java/commands/UpdateDeleteCommand.java | 18 ++++ src/main/java/controller/Controller.java | 2 +- .../java/controller/OperationAnalyst.java | 73 ++++--------- src/main/java/tasks/Deadline.java | 6 +- src/main/java/tasks/Event.java | 7 +- src/main/java/tasks/Storage.java | 94 ++++++++-------- src/main/java/tasks/Task.java | 2 +- src/main/java/tasks/TaskManager.java | 102 ++++++++---------- src/main/java/time/DateFormatChecker.java | 6 +- src/main/java/time/DateTimeFormatChecker.java | 1 - src/main/java/time/Time.java | 1 - src/main/java/time/TimeToStringConverter.java | 35 ------ 16 files changed, 257 insertions(+), 212 deletions(-) create mode 100644 src/main/java/commands/AddCommand.java create mode 100644 src/main/java/commands/Command.java create mode 100644 src/main/java/commands/SearchCommand.java create mode 100644 src/main/java/commands/UpdateDeleteCommand.java delete mode 100644 src/main/java/time/TimeToStringConverter.java diff --git a/src/main/java/UI/UI.java b/src/main/java/UI/UI.java index e556fa51d..4837c23fb 100644 --- a/src/main/java/UI/UI.java +++ b/src/main/java/UI/UI.java @@ -1,7 +1,5 @@ package UI; -import exceptions.DukeExceptions; - public class UI { protected static final String HELLO_WORDS = "Hello! I'm Duke :P\nWhat can I do for you?"; protected static final String GOODBYE_WORDS = "Bye. Hope to see you again soon! ;)"; diff --git a/src/main/java/commands/AddCommand.java b/src/main/java/commands/AddCommand.java new file mode 100644 index 000000000..54a3a293f --- /dev/null +++ b/src/main/java/commands/AddCommand.java @@ -0,0 +1,42 @@ +package commands; + +import exceptions.DukeExceptions; +import exceptions.IllegalFormatException; +import exceptions.IllegalTimeFormatException; +import exceptions.TaskNameLossException; +import time.Time; + +public class AddCommand extends Command{ + public AddCommand(String[] keywords, String rawInput) { + super(keywords, rawInput); + } + + public void addTaskWithTime (String regex) throws DukeExceptions { + String parsedInput[]; + parsedInput = rawInput.split(regex); + try { + this.taskName = keywords[1]; + } catch (Exception e){ + throw new TaskNameLossException(); + } + try { + timeChecker = new Time(parsedInput[1]); + timeChecker.check(); + this.dateString = timeChecker.getDateString(); + } catch (IndexOutOfBoundsException e){ + throw new IllegalFormatException(); + } catch (Exception e){ + throw new IllegalTimeFormatException(); + } + } + + public void addTaskWithoutTime() throws DukeExceptions{ + try { + this.taskName = this.keywords[1]; + } catch (Exception e){ + throw new TaskNameLossException(); + } + } + + +} diff --git a/src/main/java/commands/Command.java b/src/main/java/commands/Command.java new file mode 100644 index 000000000..2c551cda6 --- /dev/null +++ b/src/main/java/commands/Command.java @@ -0,0 +1,57 @@ +package commands; + +import exceptions.DukeExceptions; +import time.Time; + +public class Command { + protected String taskName; + protected String dateString; + protected String rawInput; + protected String[] keywords; + protected static final String ADD_EVENT = "event"; + protected static final String ADD_DEADLINE = "deadline"; + protected static final String ADD_TODO = "todo"; + protected static final String UPDATE = "update"; + protected static final String SEARCH = "find"; + Time timeChecker; + AddCommand add; + SearchCommand search; + UpdateDeleteCommand update; + + public Command(String[] keywords, String rawInput) { + this.rawInput = rawInput; + this.keywords = keywords; + add = new AddCommand(keywords, rawInput); + search = new SearchCommand(keywords, rawInput); + update = new UpdateDeleteCommand(keywords, rawInput); + } + + public void execute(String Instruction) throws DukeExceptions { + switch (Instruction) { + case ADD_EVENT: + add.addTaskWithTime("/at "); + break; + case ADD_DEADLINE: + add.addTaskWithTime("/by "); + break; + case ADD_TODO: + add.addTaskWithoutTime(); + break; + case SEARCH: + search.searchByDescription(); + break; + case UPDATE: + update.updateDeleteTask(); + default: + break; + } + } + + public String getDateString() { + return dateString; + } + + public String getTaskName() { + return taskName; + } +} diff --git a/src/main/java/commands/SearchCommand.java b/src/main/java/commands/SearchCommand.java new file mode 100644 index 000000000..1ad7a9bad --- /dev/null +++ b/src/main/java/commands/SearchCommand.java @@ -0,0 +1,21 @@ +package commands; + +import exceptions.DukeExceptions; +import exceptions.KeywordLossException; + +public class SearchCommand extends Command{ + + public SearchCommand(String[] keywords, String rawInput) { + super(keywords, rawInput); + } + + public void searchByDescription() throws DukeExceptions { + String[] command; + command = rawInput.split(" ",2); + try { + this.taskName = command[1]; + } catch (IndexOutOfBoundsException e) { + throw new KeywordLossException(); + } + } +} diff --git a/src/main/java/commands/UpdateDeleteCommand.java b/src/main/java/commands/UpdateDeleteCommand.java new file mode 100644 index 000000000..dfb068adb --- /dev/null +++ b/src/main/java/commands/UpdateDeleteCommand.java @@ -0,0 +1,18 @@ +package commands; + +import exceptions.DukeExceptions; +import exceptions.IllegalFormatException; + +public class UpdateDeleteCommand extends Command{ + + public UpdateDeleteCommand(String[] keywords, String rawInput){ + super(keywords, rawInput); + } + public void updateDeleteTask() throws DukeExceptions { + try { + this.taskName = this.keywords[1]; + } catch (IndexOutOfBoundsException e){ + throw new IllegalFormatException(); + } + } +} diff --git a/src/main/java/controller/Controller.java b/src/main/java/controller/Controller.java index 1fbff6fa6..49ff8f5a5 100644 --- a/src/main/java/controller/Controller.java +++ b/src/main/java/controller/Controller.java @@ -79,7 +79,7 @@ public void loadTask() throws DukeExceptions{ /** * Listen the instruction and operate during the session */ - public void listen() throws Exception { + public void listen() throws DukeExceptions { Scanner msg = new Scanner(System.in); this.recvMsg = msg.nextLine(); try { diff --git a/src/main/java/controller/OperationAnalyst.java b/src/main/java/controller/OperationAnalyst.java index 2f67cd076..195fc0a7f 100644 --- a/src/main/java/controller/OperationAnalyst.java +++ b/src/main/java/controller/OperationAnalyst.java @@ -1,12 +1,9 @@ package controller; +import commands.Command; import exceptions.*; -import time.*; -import java.time.DateTimeException; -import java.time.LocalDate; import java.util.Locale; -import java.util.Date; public class OperationAnalyst { protected String[] keywords; @@ -23,13 +20,15 @@ public class OperationAnalyst { protected static final String LIST_TASKS_COMMAND = "list"; protected static final String EXIT_COMMAND = "bye"; protected static final String SEARCH_COMMAND = "find"; - Time timeChecker; + protected static final String UPDATE = "update"; + Command command; public OperationAnalyst(String input) throws DukeExceptions { this.keywords = input.split(" "); this.rawInput = input; this.instruction = keywords[0].toLowerCase(Locale.ROOT); parseInstruction(); + command = new Command(keywords, rawInput); } /** @@ -44,74 +43,38 @@ public String getCommand() { * Analyses raw input to determine the task name and time */ public void parseInstruction() throws DukeExceptions{ - //String name; - String[] command; switch (this.instruction) { case ADD_DEADLINE_TASK_COMMAND: - command = rawInput.split("/by "); - try { - this.taskName = keywords[1]; - } catch (Exception e){ - throw new TaskNameLossException(); - } - try { - timeChecker = new Time(command[1]); - timeChecker.check(); - this.time = timeChecker.getDateString(); - } catch (IndexOutOfBoundsException e){ - throw new IllegalFormatException(); - } catch (Exception e){ - throw new IllegalTimeFormatException(); - } - //System.out.println(this.time); + command.execute(ADD_DEADLINE_TASK_COMMAND); + this.time = command.getDateString(); + this.taskName = command.getTaskName(); break; case ADD_EVENT_TASK_COMMAND: - command = rawInput.split("/at "); - try { - this.taskName = keywords[1]; - } catch (Exception e){ - throw new TaskNameLossException(); - } - try { - timeChecker = new Time(command[1]); - timeChecker.check(); - this.time = timeChecker.getDateString(); - } catch (IndexOutOfBoundsException e){ - throw new IllegalFormatException(); - } catch (Exception e){ - throw new IllegalTimeFormatException(); - } + command.execute(ADD_EVENT_TASK_COMMAND); + this.time = command.getDateString(); + this.taskName = command.getTaskName(); break; case ADD_TODO_TASK_COMMAND: - try { - this.taskName = this.keywords[1]; - } catch (Exception e){ - throw new TaskNameLossException(); - } + command.execute(ADD_TODO_TASK_COMMAND); + this.taskName = command.getTaskName(); break; case MARK_TASK_COMMAND: case UNMARK_TASK_COMMAND: case DELETE_TASK_COMMAND: - try { - this.taskName = this.keywords[1]; - } catch (IndexOutOfBoundsException e){ - throw new IllegalFormatException(); - } + command.execute(UPDATE); + this.taskName = command.getTaskName(); break; case SEARCH_COMMAND: - command = rawInput.split(" ",2); - try { - System.out.println(command.length); - this.taskName = command[1]; - } catch (IndexOutOfBoundsException e) { - throw new KeywordLossException(); - } + command.execute(SEARCH_COMMAND); + this.taskName = command.getTaskName(); + break; case LIST_TASKS_COMMAND: case EXIT_COMMAND: break; default: this.taskName = rawInput; } + } public String getTaskName() { diff --git a/src/main/java/tasks/Deadline.java b/src/main/java/tasks/Deadline.java index 2216ea01c..5957fa389 100644 --- a/src/main/java/tasks/Deadline.java +++ b/src/main/java/tasks/Deadline.java @@ -1,9 +1,5 @@ package tasks; -import time.TimeToStringConverter; - -import java.time.LocalDate; -import java.time.format.DateTimeFormatter; import java.util.Date; import time.*; @@ -12,7 +8,7 @@ public class Deadline extends Task { protected String byString; Time timeConverter; - public Deadline(String name, String byString) throws Exception{ + public Deadline(String name, String byString){ super(name); this.byString = byString; timeConverter = new Time(byString); diff --git a/src/main/java/tasks/Event.java b/src/main/java/tasks/Event.java index 36b19bb09..962c5ac94 100644 --- a/src/main/java/tasks/Event.java +++ b/src/main/java/tasks/Event.java @@ -1,10 +1,5 @@ package tasks; -import time.TimeToStringConverter; - -import java.time.LocalDate; -import java.time.format.DateTimeFormatter; -import java.time.temporal.ChronoUnit; import java.util.Date; import time.*; @@ -13,7 +8,7 @@ public class Event extends Task { protected String atString; Time timeConverter; - public Event(String name, String atString) throws Exception{ + public Event(String name, String atString) { super(name); this.atString = atString; timeConverter = new Time(atString); diff --git a/src/main/java/tasks/Storage.java b/src/main/java/tasks/Storage.java index a3d0b4442..9b598ad8f 100644 --- a/src/main/java/tasks/Storage.java +++ b/src/main/java/tasks/Storage.java @@ -4,14 +4,10 @@ import time.Time; import java.io.*; -import java.time.LocalDate; import java.util.ArrayList; -import java.util.Date; -import java.util.Arrays; -import java.util.regex.*; public class Storage { - private static final ArrayList Tasks = new ArrayList(); + private static final ArrayList Tasks = new ArrayList<>(); protected static final String FILE_NAME = "data/duke.txt"; protected static final String DONE = "X"; protected static final String TODO = "T"; @@ -19,50 +15,42 @@ public class Storage { protected static final String DEADLINE = "d"; Time timeChecker; - public int size() { + public int getSize() { return Tasks.size(); } public void add(Task newTask) { Tasks.add(newTask); } - public Task get(int i) { - return Tasks.get(i); + public Task get(int ndexOfTask) { + return Tasks.get(ndexOfTask); } - public void remove(int i) { - Tasks.remove(i); + public void remove(int indexOfTask) { + Tasks.remove(indexOfTask); } public void saveTask() throws DukeExceptions { - String content = ""; - for(int i = 0;i < Tasks.size();i++){ - content += Tasks.get(i).getListName(); - content += "\n"; + StringBuilder content = new StringBuilder(); + for (Task task : Tasks) { + content.append(task.getListName()); + content.append("\n"); } - if(content != null){ try{ File file = new File(FILE_NAME); - if(!file.exists()){ - File dir = new File(file.getParent()); - dir.mkdirs(); - file.createNewFile(); - } FileWriter writeStream = new FileWriter(file); - writeStream.write(content); + writeStream.write(content.toString()); writeStream.close(); } catch (Exception e){ throw new IllegalSavingAction(); } - } } public String[] parseInput(String listName) { - String info = listName.replaceAll("\\]", "\\|"); + String info = listName.replaceAll("]", "\\|"); info = info.replaceAll("\\[", ""); info = info.replaceAll("\\(", "\\|"); info = info.replaceAll("\\)", ""); - //System.out.println(info); - String[] data = info.split("\\|"); - return data; + String[] parsedInput = info.split("\\|"); + return parsedInput; } public void mark(Task task, String status){ @@ -74,35 +62,17 @@ public void mark(Task task, String status){ public void loadTask() throws DukeExceptions{ try (BufferedReader loadData = new BufferedReader(new FileReader(FILE_NAME))){ String listName; - String oldTime; - String newTime; while ((listName = loadData.readLine()) != null) { String[] data = this.parseInput(listName); - //System.out.println(listName); - //System.out.println(Arrays.toString(data)); switch (data[0]) { case TODO: - ToDo newToDo = new ToDo(data[2]); - mark(newToDo, data[2]); - Tasks.add(newToDo); + importTodoTask(data); break; case EVENT: - oldTime = data[3].replace("at: ", ""); - timeChecker = new Time(oldTime); - timeChecker.check(); - newTime = timeChecker.getDateString(); - Event newEvent = new Event(data[2], newTime); - mark(newEvent, data[2]); - Tasks.add(newEvent); + importEvent(data); break; case DEADLINE: - oldTime = data[3].replace("by: ", ""); - timeChecker = new Time(oldTime); - timeChecker.check(); - newTime = timeChecker.getDateString(); - Deadline newDeadline = new Deadline(data[2], newTime); - mark(newDeadline, data[2]); - Tasks.add(newDeadline); + importDeadline(data); break; default: throw new IllegalReadingAction(); @@ -114,6 +84,36 @@ public void loadTask() throws DukeExceptions{ } + private void importDeadline(String[] parsedInput) throws DukeExceptions { + String oldTimeString; + String newTimeString; + oldTimeString = parsedInput[3].replace("by: ", ""); + timeChecker = new Time(oldTimeString); + timeChecker.check(); + newTimeString = timeChecker.getDateString(); + Deadline newDeadline = new Deadline(parsedInput[2], newTimeString); + mark(newDeadline, parsedInput[2]); + Tasks.add(newDeadline); + } + + private void importEvent(String[] parsedInput) throws DukeExceptions { + String newTimeString; + String oldTimeString; + oldTimeString = parsedInput[3].replace("at: ", ""); + timeChecker = new Time(oldTimeString); + timeChecker.check(); + newTimeString = timeChecker.getDateString(); + Event newEvent = new Event(parsedInput[2], newTimeString); + mark(newEvent, parsedInput[2]); + Tasks.add(newEvent); + } + + private void importTodoTask(String[] data) { + ToDo newToDo = new ToDo(data[2]); + mark(newToDo, data[2]); + Tasks.add(newToDo); + } + public void createFile() throws DukeExceptions { try { File file = new File(FILE_NAME); diff --git a/src/main/java/tasks/Task.java b/src/main/java/tasks/Task.java index c1594ff82..999cb8f04 100644 --- a/src/main/java/tasks/Task.java +++ b/src/main/java/tasks/Task.java @@ -18,7 +18,7 @@ public String getTaskName(){ } public void setListName(){ - if(isDone == false){ + if(!isDone){ this.listName = this.unmarkedStatus + this.taskName; }else{ this.listName = this.markedStatus + this.taskName; diff --git a/src/main/java/tasks/TaskManager.java b/src/main/java/tasks/TaskManager.java index 6826e2d68..71862ffb8 100644 --- a/src/main/java/tasks/TaskManager.java +++ b/src/main/java/tasks/TaskManager.java @@ -1,11 +1,7 @@ package tasks; -import UI.*; import exceptions.*; -import java.time.LocalDate; -import java.util.Date; - public class TaskManager { Storage Tasks = new Storage(); //response of adding @@ -16,10 +12,11 @@ public class TaskManager { protected static final String DELETE_RESPONSE = "ψ(._. )> Okay! I've deleted this task:\n"; protected static final String NOT_FOUND_RESPONSE = "( ̄ε ̄;) Sorry, I can't find any result from the list."; protected static final String FOUND_RESPONSE = "o(≧v≦)o Here are the matching tasks in your list:"; - Chatbox chatbox = new Chatbox(); public String taskNumberMsg(int taskNumber){ - return "Now you have " + taskNumber + " tasks in your list."; + StringBuilder content = new StringBuilder(); + content.append("Now you have ").append(taskNumber).append(" tasks in your list."); + return content.toString(); } public void saveTask() throws DukeExceptions { Tasks.saveTask(); @@ -32,26 +29,15 @@ public void loadTask() throws DukeExceptions { public void createFile() throws DukeExceptions { Tasks.createFile(); } - /** - * Adds a general task in the list - * @param name refers to the name of the task - */ - public void addTask(String name) { - Task newTask = new Task(name); - Tasks.add(newTask); - chatbox.setContent("added: " + name); - chatbox.chatboxPrinter(); - } - /** * Adds a deadline task to the list * @param name refers to the name of the task * @param by refers to the deadline of the task */ - public String addDeadline(String name, String by) throws Exception{ + public String addDeadline(String name, String by) { Deadline newDeadline = new Deadline(name, by); Tasks.add(newDeadline); - int s = Tasks.size(); + int s = Tasks.getSize(); return ADD_RESPONSE + newDeadline.getListName() + "\n" + this.taskNumberMsg(s); } @@ -61,12 +47,13 @@ public String addDeadline(String name, String by) throws Exception{ * @param name refers to the name of the task * @param at refers to the happening time of the event */ - public String addEvent(String name, String at) throws Exception{ + public String addEvent(String name, String at) { + StringBuilder content = new StringBuilder(ADD_RESPONSE); Event newEvent = new Event(name, at); Tasks.add(newEvent); - int s = Tasks.size(); - return ADD_RESPONSE + newEvent.getListName() + - "\n" + this.taskNumberMsg(s); + int s = Tasks.getSize(); + content.append(newEvent.getListName()).append("\n").append(this.taskNumberMsg(s)); + return content.toString(); } /** @@ -74,88 +61,93 @@ public String addEvent(String name, String at) throws Exception{ * @param name refers to the name of the todo task */ public String addToDo(String name) { + StringBuilder content = new StringBuilder(ADD_RESPONSE); ToDo newToDo = new ToDo(name); Tasks.add(newToDo); - int s = Tasks.size(); - return ADD_RESPONSE + newToDo.getListName() + "\n" + - this.taskNumberMsg(s); + int s = Tasks.getSize(); + content.append(newToDo.getListName()).append("\n").append(this.taskNumberMsg(s)); + return content.toString(); } /** * Lists all tasks in the list with adding time order */ public String listTask() throws DukeExceptions{ - if(Tasks.size() == 0){ + if(Tasks.getSize() == 0){ throw new EmptyListException(); }else { - String content = LIST_RESPONSE; - for (int i = 0; i < Tasks.size(); i++) { + StringBuilder content = new StringBuilder(LIST_RESPONSE); + for (int i = 0; i < Tasks.getSize(); i++) { String index = String.valueOf(i + 1); String name = index + ". " + Tasks.get(i).getListName(); - content += name; - if(i < Tasks.size() - 1){ - content += "\n"; + content.append(name); + if(i < Tasks.getSize() - 1){ + content.append("\n"); } } - return content; + return content.toString(); } } /** * Marks specific task in the list as done - * @param n refers to the index of the task in adding time order + * @param indexOfTask refers to the indexOfTask of the task in adding time order */ - public String markTask(int n) throws DukeExceptions{ - System.out.println(n); - if(n < 1 || n > Tasks.size()) { + public String markTask(int indexOfTask) throws DukeExceptions{ + if(isOutOfBoundary(indexOfTask)) { //Beyonds boundaries throw new IllegalIndexException(); }else { - Tasks.get(n - 1).mark(); - return MARK_RESPONSE + Tasks.get(n - 1).listName; + Tasks.get(indexOfTask - 1).mark(); + return MARK_RESPONSE + Tasks.get(indexOfTask - 1).listName; } } /** * Unmarks specific task in the list as undone - * @param n refers to the index of the task in adding time order + * @param indexOfTask refers to the indexOfTask of the task in adding time order */ - public String unmarkTask(int n) throws DukeExceptions{ - if(n < 1 || n > Tasks.size()){ + public String unmarkTask(int indexOfTask) throws DukeExceptions{ + if(isOutOfBoundary(indexOfTask)){ throw new IllegalIndexException(); }else { - Tasks.get(n - 1).unmark(); - return UNMARK_RESPONSE + Tasks.get(n - 1).listName; + Tasks.get(indexOfTask - 1).unmark(); + return UNMARK_RESPONSE + Tasks.get(indexOfTask - 1).listName; } } - public String deleteTask(int n) throws DukeExceptions{ - if(n < 1 || n > Tasks.size()) { + private boolean isOutOfBoundary(int indexOfTask) { + return indexOfTask < 1 || indexOfTask > Tasks.getSize(); + } + + + public String deleteTask(int indexOfTask) throws DukeExceptions{ + if(isOutOfBoundary(indexOfTask)) { //Beyonds boundaries throw new IllegalIndexException(); }else { - String content = DELETE_RESPONSE + Tasks.get(n - 1).listName; - Tasks.remove(n-1); - int s = Tasks.size(); + String content = DELETE_RESPONSE + Tasks.get(indexOfTask - 1).listName; + Tasks.remove(indexOfTask-1); + int s = Tasks.getSize(); content += "\n" + this.taskNumberMsg(s); return content; } } public String searchTask(String keywords) throws DukeExceptions{ - if(Tasks.size() == 0){ + if(Tasks.getSize() == 0){ throw new EmptyListException(); }else { - String content = ""; + StringBuilder content = new StringBuilder(); int count = 0; - for (int i = 0; i < Tasks.size(); i++) { - if (Tasks.get(i).getListName().contains(keywords)) { - content += "\n"; + for (int i = 0; i < Tasks.getSize(); i++) { + if (Tasks.get(i).getTaskName().contains(keywords)) { + content.append("\n"); String index = String.valueOf(count + 1); String name = index + ". " + Tasks.get(i).getListName(); - content += name; + content.append(name); count ++; } } diff --git a/src/main/java/time/DateFormatChecker.java b/src/main/java/time/DateFormatChecker.java index 42c31a4db..3d421a617 100644 --- a/src/main/java/time/DateFormatChecker.java +++ b/src/main/java/time/DateFormatChecker.java @@ -5,9 +5,9 @@ import java.text.ParseException; import java.text.SimpleDateFormat; -import java.time.LocalDate; -import java.util.*; -import java.util.concurrent.ScheduledExecutorService; +import java.util.Arrays; +import java.util.List; + public class DateFormatChecker extends Time { private static final List formatStrings = diff --git a/src/main/java/time/DateTimeFormatChecker.java b/src/main/java/time/DateTimeFormatChecker.java index 89bbb651b..4dba6917c 100644 --- a/src/main/java/time/DateTimeFormatChecker.java +++ b/src/main/java/time/DateTimeFormatChecker.java @@ -1,7 +1,6 @@ package time; import exceptions.DukeExceptions; -import exceptions.IllegalTimeFormatException; import java.text.ParseException; import java.text.SimpleDateFormat; diff --git a/src/main/java/time/Time.java b/src/main/java/time/Time.java index de4328b7d..1a607331b 100644 --- a/src/main/java/time/Time.java +++ b/src/main/java/time/Time.java @@ -3,7 +3,6 @@ import exceptions.DukeExceptions; import exceptions.IllegalTimeFormatException; -import java.time.LocalDate; import java.util.Date; public class Time { diff --git a/src/main/java/time/TimeToStringConverter.java b/src/main/java/time/TimeToStringConverter.java deleted file mode 100644 index 7282e1c23..000000000 --- a/src/main/java/time/TimeToStringConverter.java +++ /dev/null @@ -1,35 +0,0 @@ -package time; - -import java.text.SimpleDateFormat; -import java.util.Date; - -public class TimeToStringConverter { - protected static final SimpleDateFormat stdDateTimeFormatter = new SimpleDateFormat("MMM dd yyyy HH:mm"); - protected static final SimpleDateFormat stdDateFormatter = new SimpleDateFormat("MMM dd yyyy"); - protected boolean isDateTime; - protected boolean isDate; - protected String timeString; - - public TimeToStringConverter (Date date) throws Exception { - try{ - timeString = stdDateFormatter.format(date); - //System.out.println(timeString); - isDate = true; - } catch (Exception e) { - isDate = false; - } - if (!isDate) { - try { - timeString = stdDateTimeFormatter.format(date); - //System.out.println(timeString); - isDateTime = true; - } catch (Exception e) { - } - isDateTime = false; - } - } - - public String getTimeString() { - return timeString; - } -} From 5242dddb54c663c407d9709644c9c2a9848b5b52 Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Wed, 2 Mar 2022 16:46:36 +0800 Subject: [PATCH 27/45] Update javadoc and user guide --- README.md | 50 ++++++- data/duke.txt | 5 - src/main/java/Duke.java | 3 +- src/main/java/commands/AddCommand.java | 42 ------ src/main/java/commands/Command.java | 57 -------- src/main/java/commands/SearchCommand.java | 21 --- .../java/commands/UpdateDeleteCommand.java | 18 --- src/main/java/commandsParser/Command.java | 137 ++++++++++++++++++ .../Controller.java | 65 ++++----- .../OperationAnalyst.java | 41 ++++-- src/main/java/exceptions/DukeExceptions.java | 3 + .../IllegalInstructionException.java | 2 +- text-ui-test/runtest.bat | 2 +- 13 files changed, 247 insertions(+), 199 deletions(-) delete mode 100644 src/main/java/commands/AddCommand.java delete mode 100644 src/main/java/commands/Command.java delete mode 100644 src/main/java/commands/SearchCommand.java delete mode 100644 src/main/java/commands/UpdateDeleteCommand.java create mode 100644 src/main/java/commandsParser/Command.java rename src/main/java/{controller => commandsParser}/Controller.java (66%) rename src/main/java/{controller => commandsParser}/OperationAnalyst.java (67%) diff --git a/README.md b/README.md index 8715d4d91..6e2979171 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,52 @@ -# Duke project template +# User Guide of Duke -This is a project template for a greenfield Java project. It's named after the Java mascot _Duke_. Given below are instructions on how to use it. +## Outline +* [Outline](#outline) +* [Setup Guide](#setup) +* [Features](#features) + * [Task Type](#feature-type) + * [Event](#feature-type-event) + * [Deadline](#feature-type-deadline) + * [Todo](#feature-type-todo) + * [Add](#feature-add) + * [Delete](#feature-delete) + * [Mark/Unmark](#feature-mark-unmark) + * [Search](#feature-search) + * [List](#feature-list) +* [Tutorial](#tutorial) + * [Add Event](#tutorial-add-event) + * [Add Deadline](#tutorial-add-deadline) + * [Add Todo](#tutorial-add-todo) + * [Delete Task](#tutorial-delete-task) + * [Mark/Unmark Task](#tutorial-update-task) + * [Find Task](#tutorial-find-task) + * [List Task](#tutorial-list-task) +* [Command Summary](#command) -## Setting up in Intellij +##Introduction +##Setup Guide +Prerequisite: JDK 11 +1. Please ensure that JDK 11 is installed before running Duke. You can check it in terminal by typing + ````shell + java -v + ```` + and you should see something similar as following: + ````shell + openjdk version "11.0.13" 2021-10-19 LTS + OpenJDK Runtime Environment Corretto-11.0.13.8.1 (build 11.0.13+8-LTS) + OpenJDK 64-Bit Server VM Corretto-11.0.13.8.1 (build 11.0.13+8-LTS, mixed mode) + ```` +2. Download the latest release. You can use command to download it or simply download it from the website: + ```` + https://github.com/hlwang56/ip/releases + ```` +3. Open a terminal in the folder when the jar file is placed and run following command + ````shell + java -jar ip.jar + ```` +##Features +##Tutorial +##Command Summary Prerequisites: JDK 11, update Intellij to the most recent version. diff --git a/data/duke.txt b/data/duke.txt index f8d138d88..e69de29bb 100644 --- a/data/duke.txt +++ b/data/duke.txt @@ -1,5 +0,0 @@ -[E][ ]j(at: Feb. 22 2019) -[E][ ]j(at: Sep. 12 2001) -[E][ ]j(at: Mar. 20 2001 13:00) -[E][ ]k(at: Feb. 02 2001) -[D][ ]kk(by: Mar. 03 2019 07:10) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index aed2f70fa..c3cf76b8f 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,5 +1,4 @@ -import controller.*; -import exceptions.*; +import commandsParser.Controller; public class Duke { public static void main(String[] args) throws Exception { diff --git a/src/main/java/commands/AddCommand.java b/src/main/java/commands/AddCommand.java deleted file mode 100644 index 54a3a293f..000000000 --- a/src/main/java/commands/AddCommand.java +++ /dev/null @@ -1,42 +0,0 @@ -package commands; - -import exceptions.DukeExceptions; -import exceptions.IllegalFormatException; -import exceptions.IllegalTimeFormatException; -import exceptions.TaskNameLossException; -import time.Time; - -public class AddCommand extends Command{ - public AddCommand(String[] keywords, String rawInput) { - super(keywords, rawInput); - } - - public void addTaskWithTime (String regex) throws DukeExceptions { - String parsedInput[]; - parsedInput = rawInput.split(regex); - try { - this.taskName = keywords[1]; - } catch (Exception e){ - throw new TaskNameLossException(); - } - try { - timeChecker = new Time(parsedInput[1]); - timeChecker.check(); - this.dateString = timeChecker.getDateString(); - } catch (IndexOutOfBoundsException e){ - throw new IllegalFormatException(); - } catch (Exception e){ - throw new IllegalTimeFormatException(); - } - } - - public void addTaskWithoutTime() throws DukeExceptions{ - try { - this.taskName = this.keywords[1]; - } catch (Exception e){ - throw new TaskNameLossException(); - } - } - - -} diff --git a/src/main/java/commands/Command.java b/src/main/java/commands/Command.java deleted file mode 100644 index 2c551cda6..000000000 --- a/src/main/java/commands/Command.java +++ /dev/null @@ -1,57 +0,0 @@ -package commands; - -import exceptions.DukeExceptions; -import time.Time; - -public class Command { - protected String taskName; - protected String dateString; - protected String rawInput; - protected String[] keywords; - protected static final String ADD_EVENT = "event"; - protected static final String ADD_DEADLINE = "deadline"; - protected static final String ADD_TODO = "todo"; - protected static final String UPDATE = "update"; - protected static final String SEARCH = "find"; - Time timeChecker; - AddCommand add; - SearchCommand search; - UpdateDeleteCommand update; - - public Command(String[] keywords, String rawInput) { - this.rawInput = rawInput; - this.keywords = keywords; - add = new AddCommand(keywords, rawInput); - search = new SearchCommand(keywords, rawInput); - update = new UpdateDeleteCommand(keywords, rawInput); - } - - public void execute(String Instruction) throws DukeExceptions { - switch (Instruction) { - case ADD_EVENT: - add.addTaskWithTime("/at "); - break; - case ADD_DEADLINE: - add.addTaskWithTime("/by "); - break; - case ADD_TODO: - add.addTaskWithoutTime(); - break; - case SEARCH: - search.searchByDescription(); - break; - case UPDATE: - update.updateDeleteTask(); - default: - break; - } - } - - public String getDateString() { - return dateString; - } - - public String getTaskName() { - return taskName; - } -} diff --git a/src/main/java/commands/SearchCommand.java b/src/main/java/commands/SearchCommand.java deleted file mode 100644 index 1ad7a9bad..000000000 --- a/src/main/java/commands/SearchCommand.java +++ /dev/null @@ -1,21 +0,0 @@ -package commands; - -import exceptions.DukeExceptions; -import exceptions.KeywordLossException; - -public class SearchCommand extends Command{ - - public SearchCommand(String[] keywords, String rawInput) { - super(keywords, rawInput); - } - - public void searchByDescription() throws DukeExceptions { - String[] command; - command = rawInput.split(" ",2); - try { - this.taskName = command[1]; - } catch (IndexOutOfBoundsException e) { - throw new KeywordLossException(); - } - } -} diff --git a/src/main/java/commands/UpdateDeleteCommand.java b/src/main/java/commands/UpdateDeleteCommand.java deleted file mode 100644 index dfb068adb..000000000 --- a/src/main/java/commands/UpdateDeleteCommand.java +++ /dev/null @@ -1,18 +0,0 @@ -package commands; - -import exceptions.DukeExceptions; -import exceptions.IllegalFormatException; - -public class UpdateDeleteCommand extends Command{ - - public UpdateDeleteCommand(String[] keywords, String rawInput){ - super(keywords, rawInput); - } - public void updateDeleteTask() throws DukeExceptions { - try { - this.taskName = this.keywords[1]; - } catch (IndexOutOfBoundsException e){ - throw new IllegalFormatException(); - } - } -} diff --git a/src/main/java/commandsParser/Command.java b/src/main/java/commandsParser/Command.java new file mode 100644 index 000000000..36731eec0 --- /dev/null +++ b/src/main/java/commandsParser/Command.java @@ -0,0 +1,137 @@ +package commandsParser; + +import exceptions.*; +import time.Time; + +public class Command { + protected String taskName; + protected String dateString; + protected String rawInput; + protected String[] parsedInput; + protected static final String ADD_EVENT = "event"; + protected static final String ADD_DEADLINE = "deadline"; + protected static final String ADD_TODO = "todo"; + protected static final String UPDATE = "update"; + protected static final String SEARCH = "find"; + Time timeChecker; + + /** + * Create a new instruction executor + * @param parsedInput the array of the instruction after splitting by space; + * @param rawInput the instruction that user given from the command line. + */ + public Command(String[] parsedInput, String rawInput) { + this.rawInput = rawInput; + this.parsedInput = parsedInput; + } + + /** + * decomposes the instruction from user and store the information separately + * @param Instruction the instruction from user after analysed by Operation Analyst + * @throws DukeExceptions + */ + public void decomposeInstruction(String Instruction) throws DukeExceptions { + switch (Instruction) { + case ADD_EVENT: + decomposeAddWithTime("/at "); + break; + case ADD_DEADLINE: + decomposeAddWithTime("/by "); + break; + case ADD_TODO: + decomposeAddWithoutTime(); + break; + case SEARCH: + decomposeSearchByDescription(); + break; + case UPDATE: + decomposeUpdateDelete(); + default: + break; + } + } + + /** + * Decompose the instruction of adding task with time, and store the + * task name and date in taskName and dateString for further access + * @param regex the keyword for decomposition. For adding event, + * the regex is "/at ", and for adding deadline, the + * regex is "/by" + * @throws DukeExceptions if the task name is loss, wrong instruction + * formatting or wrong time formatting + */ + public void decomposeAddWithTime(String regex) throws DukeExceptions { + String[] parsedInputByTime; + parsedInputByTime = rawInput.split(regex); + try { + this.taskName = this.parsedInput[1]; + } catch (Exception e){ + throw new TaskNameLossException(); + } + try { + timeChecker = new Time(parsedInputByTime[1]); + timeChecker.check(); + this.dateString = timeChecker.getDateString(); + } catch (IndexOutOfBoundsException e){ + throw new IllegalFormatException(); + } catch (Exception e){ + throw new IllegalTimeFormatException(); + } + } + + /** + * Decompose the instruction of searching task by task description, + * and store the key information in taskName for further access + * @throws DukeExceptions if the keyword is loss + */ + public void decomposeSearchByDescription() throws DukeExceptions { + String[] parseInputByKeywords; + parseInputByKeywords = rawInput.split(" ",2); + try { + this.taskName = parseInputByKeywords[1]; + } catch (IndexOutOfBoundsException e) { + throw new KeywordLossException(); + } + } + + /** + * Decomposes decompose the instruction of adding task without time + * @throws DukeExceptions if the task name is loss + */ + public void decomposeAddWithoutTime() throws DukeExceptions{ + try { + this.taskName = this.parsedInput[1]; + } catch (Exception e){ + throw new TaskNameLossException(); + } + } + + /** + * Decomposes the instruction for marking/unmarking and deleting task + * @throws DukeExceptions if the format of instruction is wrong + */ + public void decomposeUpdateDelete() throws DukeExceptions { + try { + this.taskName = this.parsedInput[1]; + } catch (IndexOutOfBoundsException e){ + throw new IllegalFormatException(); + } + } + + /** + * Access and return the date stored in dateString in string format + * @return the date in string format + */ + public String getDateString() { + return dateString; + } + + /** + * Access and return the information in taskName + * @return the information stored in taskName in String format + */ + public String getTaskName() { + return taskName; + } + +} diff --git a/src/main/java/controller/Controller.java b/src/main/java/commandsParser/Controller.java similarity index 66% rename from src/main/java/controller/Controller.java rename to src/main/java/commandsParser/Controller.java index 49ff8f5a5..bde0e2733 100644 --- a/src/main/java/controller/Controller.java +++ b/src/main/java/commandsParser/Controller.java @@ -1,13 +1,14 @@ -package controller; +package commandsParser; -import UI.*; -import exceptions.*; +import UI.UI; +import exceptions.DukeExceptions; +import exceptions.TaskIndexLossException; +import exceptions.IllegalInstructionException; import tasks.TaskManager; import java.util.Scanner; public class Controller { - //greeting msg and exit msg protected String recvMsg; protected String replyMsg; protected static final String MARK_TASK_COMMAND = "mark"; @@ -24,14 +25,14 @@ public class Controller { UI userInterface = new UI(); /** - * Prints greeting msg + * Prints greeting msg on the interface */ public void greet() { userInterface.greet(); } /** - * Prints goodbye msg and exits + * Prints goodbye msg on the interface and exits */ public void bye() { userInterface.goodbye(); @@ -39,49 +40,44 @@ public void bye() { } /** - * Unmarks task in the list + * Checks if the input to indicate the index of the task for operation is a number + * @param indexOfTask is the index of the task in String format + * @return the index of the task in Integer format + * @throws DukeExceptions if the input is not a number */ - public String unmarkTask() throws DukeExceptions { + private int parseInt(String indexOfTask) throws DukeExceptions { try { - int index= Integer.parseInt(analyst.taskName); - return manager.unmarkTask(index); - } catch (NumberFormatException e) { - throw new TaskIndexLossException(); - } - } - - public String markTask() throws DukeExceptions{ - try { - int index = Integer.parseInt(analyst.taskName); - return manager.markTask(index); - } catch (NumberFormatException e) { - throw new TaskIndexLossException(); - } - } - - public String deleteTask() throws DukeExceptions { - try { - int index = Integer.parseInt(analyst.taskName); - return manager.deleteTask(index); + int index = Integer.parseInt(indexOfTask); + return index; } catch (NumberFormatException e) { throw new TaskIndexLossException(); } } + /** + * Calls task manager to create a new file for saving task + * @throws DukeExceptions if the creation is failed + */ public void createFile() throws DukeExceptions{ manager.createFile(); } + /** + * Calls task manager to load tasks from the file + * @throws DukeExceptions if the loading action is failed + */ public void loadTask() throws DukeExceptions{ manager.loadTask(); } /** - * Listen the instruction and operate during the session + * listen to the instruction from user and do operation after user open a session + * @throws DukeExceptions if it is failed to operate the instruction user given */ public void listen() throws DukeExceptions { Scanner msg = new Scanner(System.in); this.recvMsg = msg.nextLine(); + int indexOfTask; try { analyst = new OperationAnalyst(this.recvMsg); String command = analyst.getCommand(); @@ -93,10 +89,12 @@ public void listen() throws DukeExceptions { this.replyMsg = manager.listTask(); break; case MARK_TASK_COMMAND: - this.replyMsg = this.markTask(); + indexOfTask = parseInt(analyst.taskName); + this.replyMsg = manager.markTask(indexOfTask); break; case UNMARK_TASK_COMMAND: - this.replyMsg = this.unmarkTask(); + indexOfTask = parseInt(analyst.taskName); + this.replyMsg = manager.unmarkTask(indexOfTask); break; case ADD_DEADLINE_TASK_COMMAND: this.replyMsg = manager.addDeadline(analyst.taskName, analyst.time); @@ -108,7 +106,8 @@ public void listen() throws DukeExceptions { this.replyMsg = manager.addToDo(analyst.taskName); break; case DELETE_TASK_COMMAND: - this.replyMsg = this.deleteTask(); + indexOfTask = parseInt(analyst.taskName); + this.replyMsg = manager.deleteTask(indexOfTask); break; case SEARCH_COMMAND: this.replyMsg = manager.searchTask(analyst.taskName); @@ -122,6 +121,4 @@ public void listen() throws DukeExceptions { userInterface.printMsg(e.toString()); } } - - } \ No newline at end of file diff --git a/src/main/java/controller/OperationAnalyst.java b/src/main/java/commandsParser/OperationAnalyst.java similarity index 67% rename from src/main/java/controller/OperationAnalyst.java rename to src/main/java/commandsParser/OperationAnalyst.java index 195fc0a7f..e5f58664f 100644 --- a/src/main/java/controller/OperationAnalyst.java +++ b/src/main/java/commandsParser/OperationAnalyst.java @@ -1,6 +1,5 @@ -package controller; +package commandsParser; -import commands.Command; import exceptions.*; import java.util.Locale; @@ -23,49 +22,61 @@ public class OperationAnalyst { protected static final String UPDATE = "update"; Command command; + /** + * Compute and parse the instruction into several parts and store them in different + * format into different parameters. + * @param input the raw input that user type in the command line + * @throws DukeExceptions if there's any uuacceptable condition exist while + * parsing the instruction + */ public OperationAnalyst(String input) throws DukeExceptions { + //split the raw input into several keywords this.keywords = input.split(" "); this.rawInput = input; + //Standardize the instruction this.instruction = keywords[0].toLowerCase(Locale.ROOT); - parseInstruction(); + //Create a command for further parsing command = new Command(keywords, rawInput); + parseInstruction(); } /** - * Computes the command for further operation, which is the first element in the keywords array - * @return the command, whether it is deadline, todo, event, list, mark or unmark + * @return the command, whether it is deadline, todo, event, + * list, mark, unmark, delete or find */ public String getCommand() { return this.instruction; } /** - * Analyses raw input to determine the task name and time + * Parses the command and store the task name, index of task and time + * in different parameters. + * @throws DukeExceptions if there's unacceptable condition exist */ public void parseInstruction() throws DukeExceptions{ switch (this.instruction) { case ADD_DEADLINE_TASK_COMMAND: - command.execute(ADD_DEADLINE_TASK_COMMAND); + command.decomposeInstruction(ADD_DEADLINE_TASK_COMMAND); this.time = command.getDateString(); this.taskName = command.getTaskName(); break; case ADD_EVENT_TASK_COMMAND: - command.execute(ADD_EVENT_TASK_COMMAND); + command.decomposeInstruction(ADD_EVENT_TASK_COMMAND); this.time = command.getDateString(); this.taskName = command.getTaskName(); break; case ADD_TODO_TASK_COMMAND: - command.execute(ADD_TODO_TASK_COMMAND); + command.decomposeInstruction(ADD_TODO_TASK_COMMAND); this.taskName = command.getTaskName(); break; case MARK_TASK_COMMAND: case UNMARK_TASK_COMMAND: case DELETE_TASK_COMMAND: - command.execute(UPDATE); + command.decomposeInstruction(UPDATE); this.taskName = command.getTaskName(); break; case SEARCH_COMMAND: - command.execute(SEARCH_COMMAND); + command.decomposeInstruction(SEARCH_COMMAND); this.taskName = command.getTaskName(); break; case LIST_TASKS_COMMAND: @@ -77,10 +88,10 @@ public void parseInstruction() throws DukeExceptions{ } - public String getTaskName() { - return this.taskName; - } - + /** + * Returns the information stored in time + * @return the date in string format + */ public String getTime() { return this.time; } diff --git a/src/main/java/exceptions/DukeExceptions.java b/src/main/java/exceptions/DukeExceptions.java index 7eaeabdcc..a18f39cbd 100644 --- a/src/main/java/exceptions/DukeExceptions.java +++ b/src/main/java/exceptions/DukeExceptions.java @@ -1,4 +1,7 @@ package exceptions; +/** + * DukeException is the super class of all possible exceptions in Duke + */ public abstract class DukeExceptions extends Exception{ } diff --git a/src/main/java/exceptions/IllegalInstructionException.java b/src/main/java/exceptions/IllegalInstructionException.java index 67d687970..1428b057c 100644 --- a/src/main/java/exceptions/IllegalInstructionException.java +++ b/src/main/java/exceptions/IllegalInstructionException.java @@ -2,7 +2,7 @@ public class IllegalInstructionException extends DukeExceptions { protected static final String INSTRUCTION_ERROR_MSG = - "…(⊙_⊙;)… Sorry I can't understand. Please check the manual for acceptable instructions"; + "…(⊙_⊙;)… Sorry I can't understand. Please check the user guide for acceptable instructions"; @Override public String toString() { diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 087374464..aacb5e44d 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -14,7 +14,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 +REM run the program, feed commandsParser from input.txt file and redirect the output to the ACTUAL.TXT java -classpath ..\bin Duke < input.txt > ACTUAL.TXT REM compare the output to the expected output From a450dc2a07a679df572e2f12b2dbc7dd186d54d3 Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Wed, 2 Mar 2022 20:52:58 +0800 Subject: [PATCH 28/45] Update Javadoc --- README.md | 19 --- data/duke.txt | 1 + src/main/java/UI/Chatbox.java | 7 +- src/main/java/UI/UI.java | 19 ++- .../java/commandsParser/OperationAnalyst.java | 16 ++- src/main/java/tasks/Deadline.java | 5 + src/main/java/tasks/Event.java | 6 +- src/main/java/tasks/Storage.java | 115 +++++++++++++----- src/main/java/tasks/Task.java | 15 ++- src/main/java/tasks/TaskManager.java | 75 +++++++++--- src/main/java/tasks/ToDo.java | 4 + src/main/java/time/DateFormatChecker.java | 13 +- src/main/java/time/DateTimeFormatChecker.java | 18 +-- src/main/java/time/Time.java | 18 +-- 14 files changed, 236 insertions(+), 95 deletions(-) diff --git a/README.md b/README.md index 6e2979171..828d0f6cb 100644 --- a/README.md +++ b/README.md @@ -47,22 +47,3 @@ Prerequisite: JDK 11 ##Features ##Tutorial ##Command Summary - -Prerequisites: JDK 11, update Intellij to the most recent version. - -1. Open Intellij (if you are not in the welcome screen, click `File` > `Close Project` to close the existing project first) -1. Open the project into Intellij as follows: - 1. Click `Open`. - 1. Select the project directory, and click `OK`. - 1. If there are any further prompts, accept the defaults. -1. Configure the project to use **JDK 11** (not other versions) as explained in [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk).
- In the same dialog, set the **Project language level** field to the `SDK default` option. -3. After that, locate the `src/main/java/Duke.java` file, right-click it, and choose `Run Duke.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output: - ``` - Hello from - ____ _ - | _ \ _ _| | _____ - | | | | | | | |/ / _ \ - | |_| | |_| | < __/ - |____/ \__,_|_|\_\___| - ``` diff --git a/data/duke.txt b/data/duke.txt index e69de29bb..d17200146 100644 --- a/data/duke.txt +++ b/data/duke.txt @@ -0,0 +1 @@ +[E][ ]j(at: Mar. 04 2019) diff --git a/src/main/java/UI/Chatbox.java b/src/main/java/UI/Chatbox.java index c6d12b9ec..10ec70ef0 100644 --- a/src/main/java/UI/Chatbox.java +++ b/src/main/java/UI/Chatbox.java @@ -5,15 +5,14 @@ public class Chatbox { //border of the chatbox private final String HORIZON_LINE = "-------------------------------------"; + /** + * Initialize a chatbox + */ public void chatboxPrinter(){ System.out.println(content); System.out.println(HORIZON_LINE); } - public void linePrinter(){ - System.out.println(HORIZON_LINE); - } - public void setContent(String input){ this.content = input; } diff --git a/src/main/java/UI/UI.java b/src/main/java/UI/UI.java index 4837c23fb..80da9d66f 100644 --- a/src/main/java/UI/UI.java +++ b/src/main/java/UI/UI.java @@ -3,18 +3,35 @@ public class UI { protected static final String HELLO_WORDS = "Hello! I'm Duke :P\nWhat can I do for you?"; protected static final String GOODBYE_WORDS = "Bye. Hope to see you again soon! ;)"; - Chatbox chatbox = new Chatbox(); + Chatbox chatbox; + /** + * Initialize a UI + */ + public UI(){ + chatbox = new Chatbox(); + } + + /** + * Print greeting message + */ public void greet() { chatbox.setContent(HELLO_WORDS); chatbox.chatboxPrinter(); } + /** + * Print goodbye message + */ public void goodbye() { chatbox.setContent(GOODBYE_WORDS); chatbox.chatboxPrinter(); } + /** + * Prints message from other classes + * @param message the message that is returned from other function or classes + */ public void printMsg(String message) { chatbox.setContent(message); chatbox.chatboxPrinter(); diff --git a/src/main/java/commandsParser/OperationAnalyst.java b/src/main/java/commandsParser/OperationAnalyst.java index e5f58664f..0408b974b 100644 --- a/src/main/java/commandsParser/OperationAnalyst.java +++ b/src/main/java/commandsParser/OperationAnalyst.java @@ -5,11 +5,17 @@ import java.util.Locale; public class OperationAnalyst { - protected String[] keywords; + //the key information array after splitting raw input + protected String[] keyInfo; + //the raw input from user protected String rawInput; + //the information of task time protected String time; + //the information of task description protected String taskName; + //the instruction after standardizing protected String instruction; + protected static final String MARK_TASK_COMMAND = "mark"; protected static final String UNMARK_TASK_COMMAND = "unmark"; protected static final String DELETE_TASK_COMMAND = "delete"; @@ -26,17 +32,17 @@ public class OperationAnalyst { * Compute and parse the instruction into several parts and store them in different * format into different parameters. * @param input the raw input that user type in the command line - * @throws DukeExceptions if there's any uuacceptable condition exist while + * @throws DukeExceptions if there's any unacceptable condition exist while * parsing the instruction */ public OperationAnalyst(String input) throws DukeExceptions { //split the raw input into several keywords - this.keywords = input.split(" "); + this.keyInfo = input.split(" "); this.rawInput = input; //Standardize the instruction - this.instruction = keywords[0].toLowerCase(Locale.ROOT); + this.instruction = keyInfo[0].toLowerCase(Locale.ROOT); //Create a command for further parsing - command = new Command(keywords, rawInput); + command = new Command(keyInfo, rawInput); parseInstruction(); } diff --git a/src/main/java/tasks/Deadline.java b/src/main/java/tasks/Deadline.java index 5957fa389..cba7c302b 100644 --- a/src/main/java/tasks/Deadline.java +++ b/src/main/java/tasks/Deadline.java @@ -8,6 +8,11 @@ public class Deadline extends Task { protected String byString; Time timeConverter; + /** + * Initializes a deadline task by given task name and deadline + * @param name the name of the task + * @param byString the deadline of the task in String format + */ public Deadline(String name, String byString){ super(name); this.byString = byString; diff --git a/src/main/java/tasks/Event.java b/src/main/java/tasks/Event.java index 962c5ac94..d69376a8b 100644 --- a/src/main/java/tasks/Event.java +++ b/src/main/java/tasks/Event.java @@ -8,12 +8,16 @@ public class Event extends Task { protected String atString; Time timeConverter; + /** + * Initializes an event task by given task name and event time + * @param name the name of the event task + * @param atString the time of the task in String format + */ public Event(String name, String atString) { super(name); this.atString = atString; timeConverter = new Time(atString); at = timeConverter.getNewDate(); - //System.out.println(this.at.toString()); setListName(); } diff --git a/src/main/java/tasks/Storage.java b/src/main/java/tasks/Storage.java index 9b598ad8f..c36fda761 100644 --- a/src/main/java/tasks/Storage.java +++ b/src/main/java/tasks/Storage.java @@ -18,15 +18,30 @@ public class Storage { public int getSize() { return Tasks.size(); } + + /** + * Adds a new task to the array list + * @param newTask a task object + */ public void add(Task newTask) { Tasks.add(newTask); } - public Task get(int ndexOfTask) { - return Tasks.get(ndexOfTask); + public Task get(int indexOfTask) { + return Tasks.get(indexOfTask); } + + /** + * Deletes a task from the list + * @param indexOfTask the index of the task that needs to be deleted + */ public void remove(int indexOfTask) { Tasks.remove(indexOfTask); } + + /** + * Writes and saves the tasks to an external file + * @throws DukeExceptions if the action fails + */ public void saveTask() throws DukeExceptions { StringBuilder content = new StringBuilder(); for (Task task : Tasks) { @@ -44,6 +59,11 @@ public void saveTask() throws DukeExceptions { } + /** + * Parses the input from loading task and rejects redundant characters for further loading action + * @param listName the raw input of task from the external file + * @return the array of key information of task + */ public String[] parseInput(String listName) { String info = listName.replaceAll("]", "\\|"); info = info.replaceAll("\\[", ""); @@ -53,67 +73,106 @@ public String[] parseInput(String listName) { return parsedInput; } + /** + * Checks the status of the task and mark when loading + * @param task The task that is going to be added to the list + * @param status the status of task from the external file + */ public void mark(Task task, String status){ if(status.equals(DONE)){ task.isDone = true; } } + /** + * Loads tasks from external file + * @throws DukeExceptions if the action fails + */ public void loadTask() throws DukeExceptions{ + //Reads input from external file line by line (task by task) try (BufferedReader loadData = new BufferedReader(new FileReader(FILE_NAME))){ String listName; while ((listName = loadData.readLine()) != null) { - String[] data = this.parseInput(listName); - switch (data[0]) { - case TODO: - importTodoTask(data); - break; - case EVENT: - importEvent(data); - break; - case DEADLINE: - importDeadline(data); - break; - default: - throw new IllegalReadingAction(); - } - } + //parses input into key information array + String[] keyInfo = this.parseInput(listName); + //imports task according to the information + importTask(keyInfo); + } } catch (Exception e){ throw new IllegalReadingAction(); } } - private void importDeadline(String[] parsedInput) throws DukeExceptions { + /** + * Imports tasks according to the key information array + * @param keyInfo the key information array from parsing input from external file + * @throws DukeExceptions if the action fails + */ + private void importTask(String[] keyInfo) throws DukeExceptions { + switch (keyInfo[0]) { + case TODO: + importTodoTask(keyInfo); + break; + case EVENT: + importEvent(keyInfo); + break; + case DEADLINE: + importDeadline(keyInfo); + break; + default: + throw new IllegalReadingAction(); + } + } + + /** + * Imports deadline task according to the key information array + * @param keyInfo the key information array from parsing input from external file + * @throws DukeExceptions if time converting fails + */ + private void importDeadline(String[] keyInfo) throws DukeExceptions { String oldTimeString; String newTimeString; - oldTimeString = parsedInput[3].replace("by: ", ""); + oldTimeString = keyInfo[3].replace("by: ", ""); timeChecker = new Time(oldTimeString); timeChecker.check(); newTimeString = timeChecker.getDateString(); - Deadline newDeadline = new Deadline(parsedInput[2], newTimeString); - mark(newDeadline, parsedInput[2]); + Deadline newDeadline = new Deadline(keyInfo[2], newTimeString); + mark(newDeadline, keyInfo[2]); Tasks.add(newDeadline); } - private void importEvent(String[] parsedInput) throws DukeExceptions { + /** + * Imports event task according to the key information array + * @param keyInfo the key information array from parsing input from external file + * @throws DukeExceptions if time converting fails + */ + private void importEvent(String[] keyInfo) throws DukeExceptions { String newTimeString; String oldTimeString; - oldTimeString = parsedInput[3].replace("at: ", ""); + oldTimeString = keyInfo[3].replace("at: ", ""); timeChecker = new Time(oldTimeString); timeChecker.check(); newTimeString = timeChecker.getDateString(); - Event newEvent = new Event(parsedInput[2], newTimeString); - mark(newEvent, parsedInput[2]); + Event newEvent = new Event(keyInfo[2], newTimeString); + mark(newEvent, keyInfo[2]); Tasks.add(newEvent); } - private void importTodoTask(String[] data) { - ToDo newToDo = new ToDo(data[2]); - mark(newToDo, data[2]); + /** + * Imports todo task according to the key information array + * @param keyInfo the key information array from parsing input from external file + */ + private void importTodoTask(String[] keyInfo) { + ToDo newToDo = new ToDo(keyInfo[2]); + mark(newToDo, keyInfo[2]); Tasks.add(newToDo); } + /** + * Creates a external file for saving and loading task + * @throws DukeExceptions if the action fails + */ public void createFile() throws DukeExceptions { try { File file = new File(FILE_NAME); diff --git a/src/main/java/tasks/Task.java b/src/main/java/tasks/Task.java index 999cb8f04..9608311c2 100644 --- a/src/main/java/tasks/Task.java +++ b/src/main/java/tasks/Task.java @@ -5,8 +5,12 @@ public class Task { protected String markedStatus = "[X]"; protected String taskName; //the name of the task protected boolean isDone = false; - protected String listName; //the name of the task that appears when listing + protected String listName; //the name of the task that appears when listing and searching + /** + * Initialize a task object + * @param name the name of the task + */ public Task(String name){ this.taskName = name; this.isDone = false; @@ -29,17 +33,20 @@ public String getListName(){ return this.listName; } + /** + * Marks task as done and change list name + */ public void mark(){ this.isDone = true; this.setListName(); } + /** + * Marks tasks as undone and change list name + */ public void unmark(){ this.isDone = false; this.setListName(); } - public void taskPrinter(){ - System.out.println(listName); - } } diff --git a/src/main/java/tasks/TaskManager.java b/src/main/java/tasks/TaskManager.java index 71862ffb8..6ef8ee9de 100644 --- a/src/main/java/tasks/TaskManager.java +++ b/src/main/java/tasks/TaskManager.java @@ -4,7 +4,7 @@ public class TaskManager { Storage Tasks = new Storage(); - //response of adding + //response messages of different action protected static final String ADD_RESPONSE = "ψ(._. )> Got it. I've added this task:\n"; protected static final String MARK_RESPONSE = "ψ(._. )> Nice! I've marked this task as done:\n"; protected static final String UNMARK_RESPONSE = "ψ(._. )> OK, I've marked this task as not done yet:\n"; @@ -13,19 +13,37 @@ public class TaskManager { protected static final String NOT_FOUND_RESPONSE = "( ̄ε ̄;) Sorry, I can't find any result from the list."; protected static final String FOUND_RESPONSE = "o(≧v≦)o Here are the matching tasks in your list:"; - public String taskNumberMsg(int taskNumber){ + /** + * Generates a message that contains the number of tasks in the list currently + * @return the message that contains the number of tasks in the list + */ + public String taskNumberMsg(){ + int taskNumber = Tasks.getSize(); StringBuilder content = new StringBuilder(); content.append("Now you have ").append(taskNumber).append(" tasks in your list."); return content.toString(); } + + /** + * Saves the tasks in the list to the external file + * @throws DukeExceptions if the action fails + */ public void saveTask() throws DukeExceptions { Tasks.saveTask(); } + /** + * Loads the tasks to the arraylist from external file + * @throws DukeExceptions if the action fails + */ public void loadTask() throws DukeExceptions { Tasks.loadTask(); } + /** + * Creates an external file for saving and loading task if there's no such file in to correspond folder + * @throws DukeExceptions if the action fails + */ public void createFile() throws DukeExceptions { Tasks.createFile(); } @@ -33,46 +51,56 @@ public void createFile() throws DukeExceptions { * Adds a deadline task to the list * @param name refers to the name of the task * @param by refers to the deadline of the task + * @return content.toString() the message that is going to display on the user interface, contains the + * response of successful action, information of the new task and the number of task in the list after + * adding. */ public String addDeadline(String name, String by) { Deadline newDeadline = new Deadline(name, by); Tasks.add(newDeadline); - int s = Tasks.getSize(); return ADD_RESPONSE + newDeadline.getListName() + - "\n" + this.taskNumberMsg(s); + "\n" + this.taskNumberMsg(); } /** * Adds an event task to the list * @param name refers to the name of the task * @param at refers to the happening time of the event + * @return content.toString() the message that is going to display on the user interface, contains the + * response of successful action, information of the new task and the number of task in the list after + * adding. */ public String addEvent(String name, String at) { StringBuilder content = new StringBuilder(ADD_RESPONSE); Event newEvent = new Event(name, at); Tasks.add(newEvent); - int s = Tasks.getSize(); - content.append(newEvent.getListName()).append("\n").append(this.taskNumberMsg(s)); + content.append(newEvent.getListName()).append("\n").append(this.taskNumberMsg()); return content.toString(); } /** * Adds a todo task to the list * @param name refers to the name of the todo task + * @return content.toString() the message that is going to display on the user interface, contains the + * response of successful action, information of the new task and the number of task in the list after + * adding. */ public String addToDo(String name) { StringBuilder content = new StringBuilder(ADD_RESPONSE); ToDo newToDo = new ToDo(name); Tasks.add(newToDo); - int s = Tasks.getSize(); - content.append(newToDo.getListName()).append("\n").append(this.taskNumberMsg(s)); + content.append(newToDo.getListName()).append("\n").append(this.taskNumberMsg()); return content.toString(); } /** * Lists all tasks in the list with adding time order + * @return content.toString() the message that is going to display on the user interface, contains the + * response of successful action and the information of the all the task in the list. + * @throws DukeExceptions if there's no task in the list currently */ public String listTask() throws DukeExceptions{ + //checks if there's any task in the list, otherwise throws an exception if(Tasks.getSize() == 0){ throw new EmptyListException(); }else { @@ -96,7 +124,6 @@ public String listTask() throws DukeExceptions{ */ public String markTask(int indexOfTask) throws DukeExceptions{ if(isOutOfBoundary(indexOfTask)) { - //Beyonds boundaries throw new IllegalIndexException(); }else { Tasks.get(indexOfTask - 1).mark(); @@ -109,6 +136,7 @@ public String markTask(int indexOfTask) throws DukeExceptions{ * @param indexOfTask refers to the indexOfTask of the task in adding time order */ public String unmarkTask(int indexOfTask) throws DukeExceptions{ + //Checks whether the given task index is out of the range if(isOutOfBoundary(indexOfTask)){ throw new IllegalIndexException(); }else { @@ -118,30 +146,49 @@ public String unmarkTask(int indexOfTask) throws DukeExceptions{ } } + /** + * Checks whether the given task index is out of the range + * @param indexOfTask the index of the task that need to be checked + * @return True if the index is out of boundaries + */ private boolean isOutOfBoundary(int indexOfTask) { return indexOfTask < 1 || indexOfTask > Tasks.getSize(); } - + /** + * Delete the specific task by given index + * @param indexOfTask the index of the task that need to be deleted + * @return content.toString() the message that is going to display on the user interface, contains the + * response of successful action, information of the deleted task and the number of task in the list after + * deleting. + * @throws DukeExceptions if the task is not appeared in the list + */ public String deleteTask(int indexOfTask) throws DukeExceptions{ + //Checks whether the given task index is out of the range if(isOutOfBoundary(indexOfTask)) { - //Beyonds boundaries throw new IllegalIndexException(); }else { String content = DELETE_RESPONSE + Tasks.get(indexOfTask - 1).listName; Tasks.remove(indexOfTask-1); - int s = Tasks.getSize(); - content += "\n" + this.taskNumberMsg(s); + content += "\n" + this.taskNumberMsg(); return content; } } + /** + * Searches the matching tasks and lists them by the keyword given by user + * @param keywords the keyword given by user + * @return content.toString() the message that is going to display on the user interface, contains the + * response of successful action and the information of the matching tasks. + * @throws DukeExceptions if the list is empty + */ public String searchTask(String keywords) throws DukeExceptions{ + //checks if there's any task in the list, otherwise throws an exception if(Tasks.getSize() == 0){ throw new EmptyListException(); }else { StringBuilder content = new StringBuilder(); - int count = 0; + int count = 0; //count if there's any matching task for (int i = 0; i < Tasks.getSize(); i++) { if (Tasks.get(i).getTaskName().contains(keywords)) { content.append("\n"); diff --git a/src/main/java/tasks/ToDo.java b/src/main/java/tasks/ToDo.java index 1936d96bd..3748135a6 100644 --- a/src/main/java/tasks/ToDo.java +++ b/src/main/java/tasks/ToDo.java @@ -2,6 +2,10 @@ public class ToDo extends Task { + /** + * Initializes a todo task by given task name + * @param name the name of the todo task + */ public ToDo(String name){ super(name); } diff --git a/src/main/java/time/DateFormatChecker.java b/src/main/java/time/DateFormatChecker.java index 3d421a617..1a37e7a0c 100644 --- a/src/main/java/time/DateFormatChecker.java +++ b/src/main/java/time/DateFormatChecker.java @@ -10,23 +10,30 @@ public class DateFormatChecker extends Time { + //Acceptable format for time converting private static final List formatStrings = Arrays.asList("M/d/y", "M-d-y", "y-M-d", "y/M/d", "MMM dd yyyy", "M/d", "M-d", "d/M", "d-M"); + //Standard format for printing task information protected static final SimpleDateFormat stdFormatter = new SimpleDateFormat("MMM dd yyyy"); - public DateFormatChecker(String date) throws DukeExceptions { + /** + * Initializes a checker to check whether the date string is in acceptable format + * @param date the string of date + */ + public DateFormatChecker(String date) { super(date); + //Try to convert the date to check if the time is in any of the acceptable formats for(String formatString : formatStrings) { try { SimpleDateFormat formatter = new SimpleDateFormat(formatString); formatter.setLenient(false); newDate = formatter.parse(date); dateString = stdFormatter.format(newDate); - //System.out.println(dateString); isValidDate = true; break; } catch (ParseException e) { - //throw new IllegalTimeFormatException(); + //Time is not in this format if the exception is caught. Try next one to see if it is in + //acceptable format } } } diff --git a/src/main/java/time/DateTimeFormatChecker.java b/src/main/java/time/DateTimeFormatChecker.java index 4dba6917c..c99aaeeb0 100644 --- a/src/main/java/time/DateTimeFormatChecker.java +++ b/src/main/java/time/DateTimeFormatChecker.java @@ -1,7 +1,5 @@ package time; -import exceptions.DukeExceptions; - import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Arrays; @@ -9,14 +7,16 @@ public class DateTimeFormatChecker extends Time{ private static final List formatStrings = - Arrays.asList("M/d/y H:m", "M/d/y H", "M-d-y H:m", - "M-d-y H", "y-M-d H:m", "y-M-d H", - "y/M/d H:m", "y/M/d H", "MMM dd yyyy H:m","M/d H:m", "M/d H", - "M-d H:m", "d/M H:m", "d/M H", "d-M H:m", "d/M H"); + Arrays.asList("M/d/y H:m", "M/d/y H", "M-d-y H:m", "y-M-d H:m", "y/M/d H:m", "MMM dd yyyy H:m","M/d H:m", + "M-d H:m", "d/M H:m", "d-M H:m"); protected static final SimpleDateFormat stdFormatter = new SimpleDateFormat("MMM dd yyyy HH:mm"); - public DateTimeFormatChecker(String date) throws DukeExceptions { + /** + * Initializes a checker to check whether the date with time string is in acceptable format + * @param date the string of date with time + */ + public DateTimeFormatChecker(String date) { super(date); for(String formatString: formatStrings) { try { @@ -24,11 +24,11 @@ public DateTimeFormatChecker(String date) throws DukeExceptions { formatter.setLenient(false); newDate = formatter.parse(date); dateString = stdFormatter.format(newDate); - //System.out.println(dateString); isValidTime = true; break; } catch (ParseException e) { - //throw new IllegalTimeFormatException(); + //Time is not in this format if the exception is caught. Try next one to see if it is in + //acceptable format } } } diff --git a/src/main/java/time/Time.java b/src/main/java/time/Time.java index 1a607331b..674d01270 100644 --- a/src/main/java/time/Time.java +++ b/src/main/java/time/Time.java @@ -15,6 +15,10 @@ public class Time { DateTimeFormatChecker checkTime; DateFormatChecker checkDate; + /** + * Initializes a time object for time format checking and converting + * @param date the date for checking and converting in String format + */ public Time(String date) { oldDate = date; isValidDate = false; @@ -22,22 +26,22 @@ public Time(String date) { isValid = false; } + /** + * Checks whether the string is a date without time or a date with time + * @throws DukeExceptions if the string fails in checking + */ public void check() throws DukeExceptions { - if(oldDate.contains(":")) { + if(oldDate.contains(":")) { //the string contains time, may be a date with time checkTime = new DateTimeFormatChecker(oldDate); - } else { + } else { //the string does not contain time, may be a date without time checkDate = new DateFormatChecker(oldDate); } - + //throws exceptions if the string is neither date with time nor date without time if (!isValidTime && !isValidDate) { throw new IllegalTimeFormatException(); } } - public boolean validation() { - return isValid; - } - public Date getNewDate() { return newDate; } From 2529aa3dda15461311fadd5442225bed1c73fd9c Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Wed, 2 Mar 2022 22:47:33 +0800 Subject: [PATCH 29/45] Improve code quality --- config/checkstyle/checkstyle.xml | 398 ++++++++++++++++++ src/main/java/Duke.java | 2 +- src/main/java/UI/Chatbox.java | 8 +- src/main/java/UI/UI.java | 4 +- src/main/java/commandsParser/Controller.java | 124 ------ .../Command.java | 41 +- src/main/java/controller/Controller.java | 124 ++++++ .../OperationAnalyst.java | 31 +- .../exceptions/CreatingFileException.java | 2 +- src/main/java/exceptions/DukeExceptions.java | 2 +- .../java/exceptions/EmptyListException.java | 2 +- .../exceptions/IllegalIndexException.java | 2 +- .../java/exceptions/IllegalReadingAction.java | 2 +- .../IllegalTimeFormatException.java | 2 +- .../java/exceptions/KeywordLossException.java | 2 +- src/main/java/tasks/Deadline.java | 13 +- src/main/java/tasks/Event.java | 9 +- src/main/java/tasks/Storage.java | 47 ++- src/main/java/tasks/Task.java | 16 +- src/main/java/tasks/TaskManager.java | 91 ++-- src/main/java/tasks/ToDo.java | 8 +- src/main/java/time/DateFormatChecker.java | 10 +- src/main/java/time/DateTimeFormatChecker.java | 10 +- src/main/java/time/Time.java | 12 +- text-ui-test/runtest.bat | 2 +- 25 files changed, 685 insertions(+), 279 deletions(-) create mode 100644 config/checkstyle/checkstyle.xml delete mode 100644 src/main/java/commandsParser/Controller.java rename src/main/java/{commandsParser => controller}/Command.java (82%) create mode 100644 src/main/java/controller/Controller.java rename src/main/java/{commandsParser => controller}/OperationAnalyst.java (96%) diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml new file mode 100644 index 000000000..502fbd3a5 --- /dev/null +++ b/config/checkstyle/checkstyle.xml @@ -0,0 +1,398 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index c3cf76b8f..1b7a8ffd4 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,4 +1,4 @@ -import commandsParser.Controller; +import controller.Controller; public class Duke { public static void main(String[] args) throws Exception { diff --git a/src/main/java/UI/Chatbox.java b/src/main/java/UI/Chatbox.java index 10ec70ef0..30fcd6a65 100644 --- a/src/main/java/UI/Chatbox.java +++ b/src/main/java/UI/Chatbox.java @@ -1,19 +1,19 @@ package UI; public class Chatbox { - private String content = ""; //border of the chatbox - private final String HORIZON_LINE = "-------------------------------------"; + protected static final String HORIZON_LINE = "-------------------------------------"; + private String content = ""; /** * Initialize a chatbox */ - public void chatboxPrinter(){ + public void chatboxPrinter() { System.out.println(content); System.out.println(HORIZON_LINE); } - public void setContent(String input){ + public void setContent(String input) { this.content = input; } diff --git a/src/main/java/UI/UI.java b/src/main/java/UI/UI.java index 80da9d66f..f9449e9c7 100644 --- a/src/main/java/UI/UI.java +++ b/src/main/java/UI/UI.java @@ -3,12 +3,12 @@ public class UI { protected static final String HELLO_WORDS = "Hello! I'm Duke :P\nWhat can I do for you?"; protected static final String GOODBYE_WORDS = "Bye. Hope to see you again soon! ;)"; - Chatbox chatbox; + private Chatbox chatbox; /** * Initialize a UI */ - public UI(){ + public UI() { chatbox = new Chatbox(); } diff --git a/src/main/java/commandsParser/Controller.java b/src/main/java/commandsParser/Controller.java deleted file mode 100644 index bde0e2733..000000000 --- a/src/main/java/commandsParser/Controller.java +++ /dev/null @@ -1,124 +0,0 @@ -package commandsParser; - -import UI.UI; -import exceptions.DukeExceptions; -import exceptions.TaskIndexLossException; -import exceptions.IllegalInstructionException; -import tasks.TaskManager; - -import java.util.Scanner; - -public class Controller { - protected String recvMsg; - protected String replyMsg; - protected static final String MARK_TASK_COMMAND = "mark"; - protected static final String UNMARK_TASK_COMMAND = "unmark"; - protected static final String DELETE_TASK_COMMAND = "delete"; - protected static final String ADD_TODO_TASK_COMMAND = "todo"; - protected static final String ADD_EVENT_TASK_COMMAND = "event"; - protected static final String ADD_DEADLINE_TASK_COMMAND = "deadline"; - protected static final String LIST_TASKS_COMMAND = "list"; - protected static final String EXIT_COMMAND = "bye"; - protected static final String SEARCH_COMMAND = "find"; - TaskManager manager = new TaskManager(); - OperationAnalyst analyst; - UI userInterface = new UI(); - - /** - * Prints greeting msg on the interface - */ - public void greet() { - userInterface.greet(); - } - - /** - * Prints goodbye msg on the interface and exits - */ - public void bye() { - userInterface.goodbye(); - System.exit(0); - } - - /** - * Checks if the input to indicate the index of the task for operation is a number - * @param indexOfTask is the index of the task in String format - * @return the index of the task in Integer format - * @throws DukeExceptions if the input is not a number - */ - private int parseInt(String indexOfTask) throws DukeExceptions { - try { - int index = Integer.parseInt(indexOfTask); - return index; - } catch (NumberFormatException e) { - throw new TaskIndexLossException(); - } - } - - /** - * Calls task manager to create a new file for saving task - * @throws DukeExceptions if the creation is failed - */ - public void createFile() throws DukeExceptions{ - manager.createFile(); - } - - /** - * Calls task manager to load tasks from the file - * @throws DukeExceptions if the loading action is failed - */ - public void loadTask() throws DukeExceptions{ - manager.loadTask(); - } - - /** - * listen to the instruction from user and do operation after user open a session - * @throws DukeExceptions if it is failed to operate the instruction user given - */ - public void listen() throws DukeExceptions { - Scanner msg = new Scanner(System.in); - this.recvMsg = msg.nextLine(); - int indexOfTask; - try { - analyst = new OperationAnalyst(this.recvMsg); - String command = analyst.getCommand(); - switch (command) { - case EXIT_COMMAND: - this.bye(); - break; - case LIST_TASKS_COMMAND: - this.replyMsg = manager.listTask(); - break; - case MARK_TASK_COMMAND: - indexOfTask = parseInt(analyst.taskName); - this.replyMsg = manager.markTask(indexOfTask); - break; - case UNMARK_TASK_COMMAND: - indexOfTask = parseInt(analyst.taskName); - this.replyMsg = manager.unmarkTask(indexOfTask); - break; - case ADD_DEADLINE_TASK_COMMAND: - this.replyMsg = manager.addDeadline(analyst.taskName, analyst.time); - break; - case ADD_EVENT_TASK_COMMAND: - this.replyMsg = manager.addEvent(analyst.taskName, analyst.time); - break; - case ADD_TODO_TASK_COMMAND: - this.replyMsg = manager.addToDo(analyst.taskName); - break; - case DELETE_TASK_COMMAND: - indexOfTask = parseInt(analyst.taskName); - this.replyMsg = manager.deleteTask(indexOfTask); - break; - case SEARCH_COMMAND: - this.replyMsg = manager.searchTask(analyst.taskName); - break; - default: - throw new IllegalInstructionException(); - } - userInterface.printMsg(replyMsg); - manager.saveTask(); - } catch (DukeExceptions e) { - userInterface.printMsg(e.toString()); - } - } -} \ No newline at end of file diff --git a/src/main/java/commandsParser/Command.java b/src/main/java/controller/Command.java similarity index 82% rename from src/main/java/commandsParser/Command.java rename to src/main/java/controller/Command.java index 36731eec0..341aeb5a0 100644 --- a/src/main/java/commandsParser/Command.java +++ b/src/main/java/controller/Command.java @@ -1,19 +1,23 @@ -package commandsParser; +package controller; -import exceptions.*; +import exceptions.DukeExceptions; +import exceptions.IllegalFormatException; +import exceptions.IllegalTimeFormatException; +import exceptions.KeywordLossException; +import exceptions.TaskNameLossException; import time.Time; public class Command { - protected String taskName; - protected String dateString; - protected String rawInput; - protected String[] parsedInput; protected static final String ADD_EVENT = "event"; protected static final String ADD_DEADLINE = "deadline"; protected static final String ADD_TODO = "todo"; protected static final String UPDATE = "update"; protected static final String SEARCH = "find"; - Time timeChecker; + protected String taskName; + protected String dateString; + protected String rawInput; + protected String[] parsedInput; + private Time timeChecker; /** * Create a new instruction executor @@ -27,11 +31,11 @@ public Command(String[] parsedInput, String rawInput) { /** * decomposes the instruction from user and store the information separately - * @param Instruction the instruction from user after analysed by Operation Analyst - * @throws DukeExceptions + * @param instruction the instruction from user after analysed by Operation Analyst + * @throws DukeExceptions if the instruction has incorrect format */ - public void decomposeInstruction(String Instruction) throws DukeExceptions { - switch (Instruction) { + public void decomposeInstruction(String instruction) throws DukeExceptions { + switch (instruction) { case ADD_EVENT: decomposeAddWithTime("/at "); break; @@ -46,6 +50,7 @@ public void decomposeInstruction(String Instruction) throws DukeExceptions { break; case UPDATE: decomposeUpdateDelete(); + break; default: break; } @@ -65,16 +70,16 @@ public void decomposeAddWithTime(String regex) throws DukeExceptions { parsedInputByTime = rawInput.split(regex); try { this.taskName = this.parsedInput[1]; - } catch (Exception e){ + } catch (Exception e) { throw new TaskNameLossException(); } try { timeChecker = new Time(parsedInputByTime[1]); timeChecker.check(); this.dateString = timeChecker.getDateString(); - } catch (IndexOutOfBoundsException e){ + } catch (IndexOutOfBoundsException e) { throw new IllegalFormatException(); - } catch (Exception e){ + } catch (Exception e) { throw new IllegalTimeFormatException(); } } @@ -86,7 +91,7 @@ public void decomposeAddWithTime(String regex) throws DukeExceptions { */ public void decomposeSearchByDescription() throws DukeExceptions { String[] parseInputByKeywords; - parseInputByKeywords = rawInput.split(" ",2); + parseInputByKeywords = rawInput.split(" ", 2); try { this.taskName = parseInputByKeywords[1]; } catch (IndexOutOfBoundsException e) { @@ -98,10 +103,10 @@ public void decomposeSearchByDescription() throws DukeExceptions { * Decomposes decompose the instruction of adding task without time * @throws DukeExceptions if the task name is loss */ - public void decomposeAddWithoutTime() throws DukeExceptions{ + public void decomposeAddWithoutTime() throws DukeExceptions { try { this.taskName = this.parsedInput[1]; - } catch (Exception e){ + } catch (Exception e) { throw new TaskNameLossException(); } } @@ -113,7 +118,7 @@ public void decomposeAddWithoutTime() throws DukeExceptions{ public void decomposeUpdateDelete() throws DukeExceptions { try { this.taskName = this.parsedInput[1]; - } catch (IndexOutOfBoundsException e){ + } catch (IndexOutOfBoundsException e) { throw new IllegalFormatException(); } } diff --git a/src/main/java/controller/Controller.java b/src/main/java/controller/Controller.java new file mode 100644 index 000000000..05d616eaa --- /dev/null +++ b/src/main/java/controller/Controller.java @@ -0,0 +1,124 @@ +package controller; + +import java.util.Scanner; + +import UI.UI; +import exceptions.DukeExceptions; +import exceptions.IllegalInstructionException; +import exceptions.TaskIndexLossException; +import tasks.TaskManager; + +public class Controller { + protected static final String MARK_TASK_COMMAND = "mark"; + protected static final String UNMARK_TASK_COMMAND = "unmark"; + protected static final String DELETE_TASK_COMMAND = "delete"; + protected static final String ADD_TODO_TASK_COMMAND = "todo"; + protected static final String ADD_EVENT_TASK_COMMAND = "event"; + protected static final String ADD_DEADLINE_TASK_COMMAND = "deadline"; + protected static final String LIST_TASKS_COMMAND = "list"; + protected static final String EXIT_COMMAND = "bye"; + protected static final String SEARCH_COMMAND = "find"; + protected String recvMsg; + protected String replyMsg; + private TaskManager manager = new TaskManager(); + private OperationAnalyst analyst; + private UI userInterface = new UI(); + + /** + * Prints greeting msg on the interface + */ + public void greet() { + userInterface.greet(); + } + + /** + * Prints goodbye msg on the interface and exits + */ + public void bye() { + userInterface.goodbye(); + System.exit(0); + } + + /** + * Checks if the input to indicate the index of the task for operation is a number + * @param indexOfTask is the index of the task in String format + * @return the index of the task in Integer format + * @throws DukeExceptions if the input is not a number + */ + private int parseInt(String indexOfTask) throws DukeExceptions { + try { + int index = Integer.parseInt(indexOfTask); + return index; + } catch (NumberFormatException e) { + throw new TaskIndexLossException(); + } + } + + /** + * Calls task manager to create a new file for saving task + * @throws DukeExceptions if the creation is failed + */ + public void createFile() throws DukeExceptions { + manager.createFile(); + } + + /** + * Calls task manager to load tasks from the file + * @throws DukeExceptions if the loading action is failed + */ + public void loadTask() throws DukeExceptions { + manager.loadTask(); + } + + /** + * listen to the instruction from user and do operation after user open a session + * @throws DukeExceptions if it is failed to operate the instruction user given + */ + public void listen() throws DukeExceptions { + Scanner msg = new Scanner(System.in); + this.recvMsg = msg.nextLine(); + int indexOfTask; + try { + analyst = new OperationAnalyst(this.recvMsg); + String command = analyst.getCommand(); + switch (command) { + case EXIT_COMMAND: + this.bye(); + break; + case LIST_TASKS_COMMAND: + this.replyMsg = manager.listTask(); + break; + case MARK_TASK_COMMAND: + indexOfTask = parseInt(analyst.taskName); + this.replyMsg = manager.markTask(indexOfTask); + break; + case UNMARK_TASK_COMMAND: + indexOfTask = parseInt(analyst.taskName); + this.replyMsg = manager.unmarkTask(indexOfTask); + break; + case ADD_DEADLINE_TASK_COMMAND: + this.replyMsg = manager.addDeadline(analyst.taskName, analyst.time); + break; + case ADD_EVENT_TASK_COMMAND: + this.replyMsg = manager.addEvent(analyst.taskName, analyst.time); + break; + case ADD_TODO_TASK_COMMAND: + this.replyMsg = manager.addToDo(analyst.taskName); + break; + case DELETE_TASK_COMMAND: + indexOfTask = parseInt(analyst.taskName); + this.replyMsg = manager.deleteTask(indexOfTask); + break; + case SEARCH_COMMAND: + this.replyMsg = manager.searchTask(analyst.taskName); + break; + default: + throw new IllegalInstructionException(); + } + userInterface.printMsg(replyMsg); + manager.saveTask(); + } catch (DukeExceptions e) { + userInterface.printMsg(e.toString()); + } + } +} \ No newline at end of file diff --git a/src/main/java/commandsParser/OperationAnalyst.java b/src/main/java/controller/OperationAnalyst.java similarity index 96% rename from src/main/java/commandsParser/OperationAnalyst.java rename to src/main/java/controller/OperationAnalyst.java index 0408b974b..879a033d7 100644 --- a/src/main/java/commandsParser/OperationAnalyst.java +++ b/src/main/java/controller/OperationAnalyst.java @@ -1,21 +1,10 @@ -package commandsParser; - -import exceptions.*; +package controller; import java.util.Locale; -public class OperationAnalyst { - //the key information array after splitting raw input - protected String[] keyInfo; - //the raw input from user - protected String rawInput; - //the information of task time - protected String time; - //the information of task description - protected String taskName; - //the instruction after standardizing - protected String instruction; +import exceptions.DukeExceptions; +public class OperationAnalyst { protected static final String MARK_TASK_COMMAND = "mark"; protected static final String UNMARK_TASK_COMMAND = "unmark"; protected static final String DELETE_TASK_COMMAND = "delete"; @@ -26,7 +15,17 @@ public class OperationAnalyst { protected static final String EXIT_COMMAND = "bye"; protected static final String SEARCH_COMMAND = "find"; protected static final String UPDATE = "update"; - Command command; + //the key information array after splitting raw input + protected String[] keyInfo; + //the raw input from user + protected String rawInput; + //the information of task time + protected String time; + //the information of task description + protected String taskName; + //the instruction after standardizing + protected String instruction; + private Command command; /** * Compute and parse the instruction into several parts and store them in different @@ -59,7 +58,7 @@ public String getCommand() { * in different parameters. * @throws DukeExceptions if there's unacceptable condition exist */ - public void parseInstruction() throws DukeExceptions{ + public void parseInstruction() throws DukeExceptions { switch (this.instruction) { case ADD_DEADLINE_TASK_COMMAND: command.decomposeInstruction(ADD_DEADLINE_TASK_COMMAND); diff --git a/src/main/java/exceptions/CreatingFileException.java b/src/main/java/exceptions/CreatingFileException.java index 32bad827d..ddc76150b 100644 --- a/src/main/java/exceptions/CreatingFileException.java +++ b/src/main/java/exceptions/CreatingFileException.java @@ -1,6 +1,6 @@ package exceptions; -public class CreatingFileException extends DukeExceptions{ +public class CreatingFileException extends DukeExceptions { protected static final String CREATING_FILE_ERROR_MSG = "Sorry, there's something wrong when creating file, please try again later QnQ"; diff --git a/src/main/java/exceptions/DukeExceptions.java b/src/main/java/exceptions/DukeExceptions.java index a18f39cbd..d8de7361a 100644 --- a/src/main/java/exceptions/DukeExceptions.java +++ b/src/main/java/exceptions/DukeExceptions.java @@ -3,5 +3,5 @@ /** * DukeException is the super class of all possible exceptions in Duke */ -public abstract class DukeExceptions extends Exception{ +public abstract class DukeExceptions extends Exception { } diff --git a/src/main/java/exceptions/EmptyListException.java b/src/main/java/exceptions/EmptyListException.java index e6830a598..a68d96a08 100644 --- a/src/main/java/exceptions/EmptyListException.java +++ b/src/main/java/exceptions/EmptyListException.java @@ -1,6 +1,6 @@ package exceptions; -public class EmptyListException extends DukeExceptions{ +public class EmptyListException extends DukeExceptions { protected static final String EMPTY_LIST_ERROR_MSG = "The list is empty currently ( ̄3 ̄)a"; @Override diff --git a/src/main/java/exceptions/IllegalIndexException.java b/src/main/java/exceptions/IllegalIndexException.java index 07bbcd9e4..48ab30903 100644 --- a/src/main/java/exceptions/IllegalIndexException.java +++ b/src/main/java/exceptions/IllegalIndexException.java @@ -1,6 +1,6 @@ package exceptions; -public class IllegalIndexException extends DukeExceptions{ +public class IllegalIndexException extends DukeExceptions { protected static final String ILLEGAL_INDEX_ERROR_MSG = "I can't find the task from the list (°ー°〃) Please check your index again"; @Override diff --git a/src/main/java/exceptions/IllegalReadingAction.java b/src/main/java/exceptions/IllegalReadingAction.java index 12ed588fd..18ba951cc 100644 --- a/src/main/java/exceptions/IllegalReadingAction.java +++ b/src/main/java/exceptions/IllegalReadingAction.java @@ -1,6 +1,6 @@ package exceptions; -public class IllegalReadingAction extends DukeExceptions{ +public class IllegalReadingAction extends DukeExceptions { protected static final String READING_FILE_ERROR_MSG = "Sorry, there's something wrong when loading task, please try again later QnQ"; diff --git a/src/main/java/exceptions/IllegalTimeFormatException.java b/src/main/java/exceptions/IllegalTimeFormatException.java index e09de3e25..b573525a5 100644 --- a/src/main/java/exceptions/IllegalTimeFormatException.java +++ b/src/main/java/exceptions/IllegalTimeFormatException.java @@ -1,6 +1,6 @@ package exceptions; -public class IllegalTimeFormatException extends DukeExceptions{ +public class IllegalTimeFormatException extends DukeExceptions { protected static final String FORMAT_ERROR_MSG = "The time format is incorrect! Can you please check your input again? ( ̄~ ̄;) " + "You can check the manual to find out acceptable time format!"; diff --git a/src/main/java/exceptions/KeywordLossException.java b/src/main/java/exceptions/KeywordLossException.java index bd84f232a..505587370 100644 --- a/src/main/java/exceptions/KeywordLossException.java +++ b/src/main/java/exceptions/KeywordLossException.java @@ -1,6 +1,6 @@ package exceptions; -public class KeywordLossException extends DukeExceptions{ +public class KeywordLossException extends DukeExceptions { protected static final String KEYWORD_LOSS_ERROR_MSG = "Did you specify the keyword?∑(っ °Д °;)っ"; diff --git a/src/main/java/tasks/Deadline.java b/src/main/java/tasks/Deadline.java index cba7c302b..b753cb3ef 100644 --- a/src/main/java/tasks/Deadline.java +++ b/src/main/java/tasks/Deadline.java @@ -1,19 +1,20 @@ package tasks; import java.util.Date; -import time.*; + +import time.Time; public class Deadline extends Task { protected Date by; protected String byString; - Time timeConverter; + private Time timeConverter; /** * Initializes a deadline task by given task name and deadline * @param name the name of the task * @param byString the deadline of the task in String format */ - public Deadline(String name, String byString){ + public Deadline(String name, String byString) { super(name); this.byString = byString; timeConverter = new Time(byString); @@ -22,10 +23,10 @@ public Deadline(String name, String byString){ } @Override - public void setListName(){ - if(!isDone){ + public void setListName() { + if (!isDone) { this.listName = "[D]" + this.unmarkedStatus + this.taskName + "(by: " + byString + ")"; - }else{ + } else { this.listName = "[D]" + this.markedStatus + this.taskName + "(by: " + byString + ")"; } } diff --git a/src/main/java/tasks/Event.java b/src/main/java/tasks/Event.java index d69376a8b..ee656c4a8 100644 --- a/src/main/java/tasks/Event.java +++ b/src/main/java/tasks/Event.java @@ -1,12 +1,13 @@ package tasks; import java.util.Date; -import time.*; + +import time.Time; public class Event extends Task { protected Date at; protected String atString; - Time timeConverter; + private Time timeConverter; /** * Initializes an event task by given task name and event time @@ -23,9 +24,9 @@ public Event(String name, String atString) { @Override public void setListName() { - if(!isDone){ + if (!isDone) { this.listName = "[E]" + this.unmarkedStatus + this.taskName + "(at: " + atString + ")"; - }else{ + } else { this.listName = "[E]" + this.markedStatus + this.taskName + "(at: " + atString + ")"; } } diff --git a/src/main/java/tasks/Storage.java b/src/main/java/tasks/Storage.java index c36fda761..6e1972b27 100644 --- a/src/main/java/tasks/Storage.java +++ b/src/main/java/tasks/Storage.java @@ -1,19 +1,25 @@ package tasks; -import exceptions.*; -import time.Time; - -import java.io.*; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; import java.util.ArrayList; +import exceptions.CreatingFileException; +import exceptions.DukeExceptions; +import exceptions.IllegalReadingAction; +import exceptions.IllegalSavingAction; +import time.Time; + public class Storage { - private static final ArrayList Tasks = new ArrayList<>(); protected static final String FILE_NAME = "data/duke.txt"; protected static final String DONE = "X"; protected static final String TODO = "T"; protected static final String EVENT = "E"; protected static final String DEADLINE = "d"; - Time timeChecker; + private static final ArrayList Tasks = new ArrayList<>(); + private Time timeChecker; public int getSize() { return Tasks.size(); @@ -48,15 +54,14 @@ public void saveTask() throws DukeExceptions { content.append(task.getListName()); content.append("\n"); } - try{ - File file = new File(FILE_NAME); - FileWriter writeStream = new FileWriter(file); - writeStream.write(content.toString()); - writeStream.close(); - } catch (Exception e){ - throw new IllegalSavingAction(); - } - + try { + File file = new File(FILE_NAME); + FileWriter writeStream = new FileWriter(file); + writeStream.write(content.toString()); + writeStream.close(); + } catch (Exception e) { + throw new IllegalSavingAction(); + } } /** @@ -78,8 +83,8 @@ public String[] parseInput(String listName) { * @param task The task that is going to be added to the list * @param status the status of task from the external file */ - public void mark(Task task, String status){ - if(status.equals(DONE)){ + public void mark(Task task, String status) { + if (status.equals(DONE)) { task.isDone = true; } } @@ -88,9 +93,9 @@ public void mark(Task task, String status){ * Loads tasks from external file * @throws DukeExceptions if the action fails */ - public void loadTask() throws DukeExceptions{ + public void loadTask() throws DukeExceptions { //Reads input from external file line by line (task by task) - try (BufferedReader loadData = new BufferedReader(new FileReader(FILE_NAME))){ + try (BufferedReader loadData = new BufferedReader(new FileReader(FILE_NAME))) { String listName; while ((listName = loadData.readLine()) != null) { //parses input into key information array @@ -98,7 +103,7 @@ public void loadTask() throws DukeExceptions{ //imports task according to the information importTask(keyInfo); } - } catch (Exception e){ + } catch (Exception e) { throw new IllegalReadingAction(); } @@ -181,7 +186,7 @@ public void createFile() throws DukeExceptions { dir.mkdirs(); file.createNewFile(); } - } catch (Exception e){ + } catch (Exception e) { throw new CreatingFileException(); } } diff --git a/src/main/java/tasks/Task.java b/src/main/java/tasks/Task.java index 9608311c2..fe0d4582d 100644 --- a/src/main/java/tasks/Task.java +++ b/src/main/java/tasks/Task.java @@ -11,32 +11,32 @@ public class Task { * Initialize a task object * @param name the name of the task */ - public Task(String name){ + public Task(String name) { this.taskName = name; this.isDone = false; setListName(); } - public String getTaskName(){ + public String getTaskName() { return this.taskName; } - public void setListName(){ - if(!isDone){ + public void setListName() { + if (!isDone) { this.listName = this.unmarkedStatus + this.taskName; - }else{ + } else { this.listName = this.markedStatus + this.taskName; } } - public String getListName(){ + public String getListName() { return this.listName; } /** * Marks task as done and change list name */ - public void mark(){ + public void mark() { this.isDone = true; this.setListName(); } @@ -44,7 +44,7 @@ public void mark(){ /** * Marks tasks as undone and change list name */ - public void unmark(){ + public void unmark() { this.isDone = false; this.setListName(); } diff --git a/src/main/java/tasks/TaskManager.java b/src/main/java/tasks/TaskManager.java index 6ef8ee9de..416696bf8 100644 --- a/src/main/java/tasks/TaskManager.java +++ b/src/main/java/tasks/TaskManager.java @@ -1,9 +1,10 @@ package tasks; -import exceptions.*; +import exceptions.DukeExceptions; +import exceptions.EmptyListException; +import exceptions.IllegalIndexException; public class TaskManager { - Storage Tasks = new Storage(); //response messages of different action protected static final String ADD_RESPONSE = "ψ(._. )> Got it. I've added this task:\n"; protected static final String MARK_RESPONSE = "ψ(._. )> Nice! I've marked this task as done:\n"; @@ -12,13 +13,13 @@ public class TaskManager { protected static final String DELETE_RESPONSE = "ψ(._. )> Okay! I've deleted this task:\n"; protected static final String NOT_FOUND_RESPONSE = "( ̄ε ̄;) Sorry, I can't find any result from the list."; protected static final String FOUND_RESPONSE = "o(≧v≦)o Here are the matching tasks in your list:"; - + private Storage tasks = new Storage(); /** * Generates a message that contains the number of tasks in the list currently * @return the message that contains the number of tasks in the list */ - public String taskNumberMsg(){ - int taskNumber = Tasks.getSize(); + public String taskNumberMsg() { + int taskNumber = tasks.getSize(); StringBuilder content = new StringBuilder(); content.append("Now you have ").append(taskNumber).append(" tasks in your list."); return content.toString(); @@ -29,7 +30,7 @@ public String taskNumberMsg(){ * @throws DukeExceptions if the action fails */ public void saveTask() throws DukeExceptions { - Tasks.saveTask(); + tasks.saveTask(); } /** @@ -37,7 +38,7 @@ public void saveTask() throws DukeExceptions { * @throws DukeExceptions if the action fails */ public void loadTask() throws DukeExceptions { - Tasks.loadTask(); + tasks.loadTask(); } /** @@ -45,7 +46,7 @@ public void loadTask() throws DukeExceptions { * @throws DukeExceptions if the action fails */ public void createFile() throws DukeExceptions { - Tasks.createFile(); + tasks.createFile(); } /** * Adds a deadline task to the list @@ -57,9 +58,9 @@ public void createFile() throws DukeExceptions { */ public String addDeadline(String name, String by) { Deadline newDeadline = new Deadline(name, by); - Tasks.add(newDeadline); - return ADD_RESPONSE + newDeadline.getListName() + - "\n" + this.taskNumberMsg(); + tasks.add(newDeadline); + return ADD_RESPONSE + newDeadline.getListName() + + "\n" + this.taskNumberMsg(); } /** @@ -73,7 +74,7 @@ public String addDeadline(String name, String by) { public String addEvent(String name, String at) { StringBuilder content = new StringBuilder(ADD_RESPONSE); Event newEvent = new Event(name, at); - Tasks.add(newEvent); + tasks.add(newEvent); content.append(newEvent.getListName()).append("\n").append(this.taskNumberMsg()); return content.toString(); } @@ -88,9 +89,9 @@ public String addEvent(String name, String at) { public String addToDo(String name) { StringBuilder content = new StringBuilder(ADD_RESPONSE); ToDo newToDo = new ToDo(name); - Tasks.add(newToDo); + tasks.add(newToDo); content.append(newToDo.getListName()).append("\n").append(this.taskNumberMsg()); - return content.toString(); + return content.toString(); } /** @@ -99,17 +100,17 @@ public String addToDo(String name) { * response of successful action and the information of the all the task in the list. * @throws DukeExceptions if there's no task in the list currently */ - public String listTask() throws DukeExceptions{ + public String listTask() throws DukeExceptions { //checks if there's any task in the list, otherwise throws an exception - if(Tasks.getSize() == 0){ + if (tasks.getSize() == 0) { throw new EmptyListException(); - }else { + } else { StringBuilder content = new StringBuilder(LIST_RESPONSE); - for (int i = 0; i < Tasks.getSize(); i++) { + for (int i = 0; i < tasks.getSize(); i++) { String index = String.valueOf(i + 1); - String name = index + ". " + Tasks.get(i).getListName(); + String name = index + ". " + tasks.get(i).getListName(); content.append(name); - if(i < Tasks.getSize() - 1){ + if (i < tasks.getSize() - 1) { content.append("\n"); } } @@ -122,12 +123,12 @@ public String listTask() throws DukeExceptions{ * Marks specific task in the list as done * @param indexOfTask refers to the indexOfTask of the task in adding time order */ - public String markTask(int indexOfTask) throws DukeExceptions{ - if(isOutOfBoundary(indexOfTask)) { + public String markTask(int indexOfTask) throws DukeExceptions { + if (isOutOfBoundary(indexOfTask)) { throw new IllegalIndexException(); - }else { - Tasks.get(indexOfTask - 1).mark(); - return MARK_RESPONSE + Tasks.get(indexOfTask - 1).listName; + } else { + tasks.get(indexOfTask - 1).mark(); + return MARK_RESPONSE + tasks.get(indexOfTask - 1).listName; } } @@ -135,13 +136,13 @@ public String markTask(int indexOfTask) throws DukeExceptions{ * Unmarks specific task in the list as undone * @param indexOfTask refers to the indexOfTask of the task in adding time order */ - public String unmarkTask(int indexOfTask) throws DukeExceptions{ + public String unmarkTask(int indexOfTask) throws DukeExceptions { //Checks whether the given task index is out of the range - if(isOutOfBoundary(indexOfTask)){ + if (isOutOfBoundary(indexOfTask)) { throw new IllegalIndexException(); - }else { - Tasks.get(indexOfTask - 1).unmark(); - return UNMARK_RESPONSE + Tasks.get(indexOfTask - 1).listName; + } else { + tasks.get(indexOfTask - 1).unmark(); + return UNMARK_RESPONSE + tasks.get(indexOfTask - 1).listName; } } @@ -152,7 +153,7 @@ public String unmarkTask(int indexOfTask) throws DukeExceptions{ * @return True if the index is out of boundaries */ private boolean isOutOfBoundary(int indexOfTask) { - return indexOfTask < 1 || indexOfTask > Tasks.getSize(); + return indexOfTask < 1 || indexOfTask > tasks.getSize(); } /** @@ -163,13 +164,13 @@ private boolean isOutOfBoundary(int indexOfTask) { * deleting. * @throws DukeExceptions if the task is not appeared in the list */ - public String deleteTask(int indexOfTask) throws DukeExceptions{ + public String deleteTask(int indexOfTask) throws DukeExceptions { //Checks whether the given task index is out of the range - if(isOutOfBoundary(indexOfTask)) { + if (isOutOfBoundary(indexOfTask)) { throw new IllegalIndexException(); - }else { - String content = DELETE_RESPONSE + Tasks.get(indexOfTask - 1).listName; - Tasks.remove(indexOfTask-1); + } else { + String content = DELETE_RESPONSE + tasks.get(indexOfTask - 1).listName; + tasks.remove(indexOfTask - 1); content += "\n" + this.taskNumberMsg(); return content; } @@ -182,23 +183,23 @@ public String deleteTask(int indexOfTask) throws DukeExceptions{ * response of successful action and the information of the matching tasks. * @throws DukeExceptions if the list is empty */ - public String searchTask(String keywords) throws DukeExceptions{ + public String searchTask(String keywords) throws DukeExceptions { //checks if there's any task in the list, otherwise throws an exception - if(Tasks.getSize() == 0){ + if (tasks.getSize() == 0) { throw new EmptyListException(); - }else { + } else { StringBuilder content = new StringBuilder(); - int count = 0; //count if there's any matching task - for (int i = 0; i < Tasks.getSize(); i++) { - if (Tasks.get(i).getTaskName().contains(keywords)) { + int count = 0; //count if there's any matching task + for (int i = 0; i < tasks.getSize(); i++) { + if (tasks.get(i).getTaskName().contains(keywords)) { content.append("\n"); String index = String.valueOf(count + 1); - String name = index + ". " + Tasks.get(i).getListName(); + String name = index + ". " + tasks.get(i).getListName(); content.append(name); - count ++; + count++; } } - if(count == 0){ + if (count == 0) { return NOT_FOUND_RESPONSE; } return FOUND_RESPONSE + content; diff --git a/src/main/java/tasks/ToDo.java b/src/main/java/tasks/ToDo.java index 3748135a6..591a09fcf 100644 --- a/src/main/java/tasks/ToDo.java +++ b/src/main/java/tasks/ToDo.java @@ -6,15 +6,15 @@ public class ToDo extends Task { * Initializes a todo task by given task name * @param name the name of the todo task */ - public ToDo(String name){ + public ToDo(String name) { super(name); } @Override - public void setListName(){ - if(!isDone){ + public void setListName() { + if (!isDone) { this.listName = "[T]" + this.unmarkedStatus + this.taskName; - }else{ + } else { this.listName = "[T]" + this.markedStatus + this.taskName; } } diff --git a/src/main/java/time/DateFormatChecker.java b/src/main/java/time/DateFormatChecker.java index 1a37e7a0c..ae563c227 100644 --- a/src/main/java/time/DateFormatChecker.java +++ b/src/main/java/time/DateFormatChecker.java @@ -1,8 +1,5 @@ package time; -import exceptions.DukeExceptions; -import exceptions.IllegalTimeFormatException; - import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Arrays; @@ -10,12 +7,11 @@ public class DateFormatChecker extends Time { + //Standard format for printing task information + private static final SimpleDateFormat stdFormatter = new SimpleDateFormat("MMM dd yyyy"); //Acceptable format for time converting private static final List formatStrings = Arrays.asList("M/d/y", "M-d-y", "y-M-d", "y/M/d", "MMM dd yyyy", "M/d", "M-d", "d/M", "d-M"); - //Standard format for printing task information - protected static final SimpleDateFormat stdFormatter = new SimpleDateFormat("MMM dd yyyy"); - /** * Initializes a checker to check whether the date string is in acceptable format * @param date the string of date @@ -23,7 +19,7 @@ public class DateFormatChecker extends Time { public DateFormatChecker(String date) { super(date); //Try to convert the date to check if the time is in any of the acceptable formats - for(String formatString : formatStrings) { + for (String formatString : formatStrings) { try { SimpleDateFormat formatter = new SimpleDateFormat(formatString); formatter.setLenient(false); diff --git a/src/main/java/time/DateTimeFormatChecker.java b/src/main/java/time/DateTimeFormatChecker.java index c99aaeeb0..aa76ef742 100644 --- a/src/main/java/time/DateTimeFormatChecker.java +++ b/src/main/java/time/DateTimeFormatChecker.java @@ -5,12 +5,12 @@ import java.util.Arrays; import java.util.List; -public class DateTimeFormatChecker extends Time{ +public class DateTimeFormatChecker extends Time { private static final List formatStrings = - Arrays.asList("M/d/y H:m", "M/d/y H", "M-d-y H:m", "y-M-d H:m", "y/M/d H:m", "MMM dd yyyy H:m","M/d H:m", - "M-d H:m", "d/M H:m", "d-M H:m"); + Arrays.asList("M/d/y H:m", "M/d/y H", "M-d-y H:m", "y-M-d H:m", "y/M/d H:m", "MMM dd yyyy H:m", + "M/d H:m", "M-d H:m", "d/M H:m", "d-M H:m"); - protected static final SimpleDateFormat stdFormatter = new SimpleDateFormat("MMM dd yyyy HH:mm"); + private static final SimpleDateFormat stdFormatter = new SimpleDateFormat("MMM dd yyyy HH:mm"); /** * Initializes a checker to check whether the date with time string is in acceptable format @@ -18,7 +18,7 @@ public class DateTimeFormatChecker extends Time{ */ public DateTimeFormatChecker(String date) { super(date); - for(String formatString: formatStrings) { + for (String formatString: formatStrings) { try { SimpleDateFormat formatter = new SimpleDateFormat(formatString); formatter.setLenient(false); diff --git a/src/main/java/time/Time.java b/src/main/java/time/Time.java index 674d01270..148e6d656 100644 --- a/src/main/java/time/Time.java +++ b/src/main/java/time/Time.java @@ -1,19 +1,19 @@ package time; +import java.util.Date; + import exceptions.DukeExceptions; import exceptions.IllegalTimeFormatException; -import java.util.Date; - public class Time { - protected boolean isValid; protected static boolean isValidDate; protected static boolean isValidTime; protected static Date newDate; protected static String dateString; + protected boolean isValid; protected String oldDate; - DateTimeFormatChecker checkTime; - DateFormatChecker checkDate; + private DateTimeFormatChecker checkTime; + private DateFormatChecker checkDate; /** * Initializes a time object for time format checking and converting @@ -31,7 +31,7 @@ public Time(String date) { * @throws DukeExceptions if the string fails in checking */ public void check() throws DukeExceptions { - if(oldDate.contains(":")) { //the string contains time, may be a date with time + if (oldDate.contains(":")) { //the string contains time, may be a date with time checkTime = new DateTimeFormatChecker(oldDate); } else { //the string does not contain time, may be a date without time checkDate = new DateFormatChecker(oldDate); diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index aacb5e44d..843446f1a 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -14,7 +14,7 @@ IF ERRORLEVEL 1 ( ) REM no error here, errorlevel == 0 -REM run the program, feed commandsParser from input.txt file and redirect the output to the ACTUAL.TXT +REM run the program, feed controller from input.txt file and redirect the output to the ACTUAL.TXT java -classpath ..\bin Duke < input.txt > ACTUAL.TXT REM compare the output to the expected output From 6f309d2cc4413084f40dee1f7c8b6de4e0d1ba28 Mon Sep 17 00:00:00 2001 From: hlwang56 <69446689+hlwang56@users.noreply.github.com> Date: Thu, 3 Mar 2022 10:31:35 +0800 Subject: [PATCH 30/45] Set theme jekyll-theme-architect --- 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..3397c9a49 --- /dev/null +++ b/docs/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-architect \ No newline at end of file From b2fe41702efc6411636200520ad382a728855acc Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Thu, 3 Mar 2022 16:47:55 +0800 Subject: [PATCH 31/45] Update README.md --- docs/README.md | 81 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 52 insertions(+), 29 deletions(-) diff --git a/docs/README.md b/docs/README.md index 8077118eb..c65b333f7 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,29 +1,52 @@ -# User Guide - -## Features - -### Feature-ABC - -Description of the feature. - -### Feature-XYZ - -Description of the feature. - -## Usage - -### `Keyword` - Describe action - -Describe the action and its outcome. - -Example of usage: - -`keyword (optional arguments)` - -Expected outcome: - -Description of the outcome. - -``` -expected output -``` +# User Guide of Duke + +## Outline +* [Outline](#outline) +* [Introduction](#introduction) +* [Setup Guide](#setup-guide) +* [Features](#features) + * [Task Type](#feature-type) + * [Event](#feature-type-event) + * [Deadline](#feature-type-deadline) + * [Todo](#feature-type-todo) + * [Add](#feature-add) + * [Delete](#feature-delete) + * [Mark/Unmark](#feature-mark-unmark) + * [Search](#feature-search) + * [List](#feature-list) +* [Tutorial](#tutorial) + * [Add Event](#tutorial-add-event) + * [Add Deadline](#tutorial-add-deadline) + * [Add Todo](#tutorial-add-todo) + * [Delete Task](#tutorial-delete-task) + * [Mark/Unmark Task](#tutorial-update-task) + * [Find Task](#tutorial-find-task) + * [List Task](#tutorial-list-task) +* [Command Summary](#command-summary) +* [Common Questions](#common-questions) + +##Introduction +##Setup Guide +Prerequisite: JDK 11 +1. Please ensure that JDK 11 is installed before running Duke. You can check it in terminal by typing + ````shell + java -v + ```` + and you should see something similar as following: + ````shell + openjdk version "11.0.13" 2021-10-19 LTS + OpenJDK Runtime Environment Corretto-11.0.13.8.1 (build 11.0.13+8-LTS) + OpenJDK 64-Bit Server VM Corretto-11.0.13.8.1 (build 11.0.13+8-LTS, mixed mode) + ```` +2. Download the latest release. You can use command to download it or simply download it from the website: + ```` + https://github.com/hlwang56/ip/releases + ```` +3. Open a terminal in the folder when the jar file is placed and run following command + ````shell + java -jar ip.jar + ```` +##Features +##Tutorial +##Command Summary +##Common Questions From d158db8ce256822590fd76f8bb1bcc26880c7726 Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Fri, 4 Mar 2022 12:32:24 +0800 Subject: [PATCH 32/45] Update UG --- README.md | 301 +++++++++++++++++++++++++++++++++++++++++++++---- data/duke.txt | 1 - docs/README.md | 285 ++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 555 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 828d0f6cb..6e24146fb 100644 --- a/README.md +++ b/README.md @@ -2,31 +2,40 @@ ## Outline * [Outline](#outline) -* [Setup Guide](#setup) +* [Introduction](#introduction) +* [Setup Guide](#setup-guide) * [Features](#features) - * [Task Type](#feature-type) - * [Event](#feature-type-event) - * [Deadline](#feature-type-deadline) - * [Todo](#feature-type-todo) - * [Add](#feature-add) - * [Delete](#feature-delete) - * [Mark/Unmark](#feature-mark-unmark) - * [Search](#feature-search) - * [List](#feature-list) + * [Task Type](#task-type) + * [Event](#event) + * [Deadline](#deadline) + * [Todo](#todo) + * [Add](#features-add) + * [Delete](#features-delete) + * [Mark/Unmark](#features-markunmark) + * [Search](#features-search) + * [List](#features-list) * [Tutorial](#tutorial) - * [Add Event](#tutorial-add-event) - * [Add Deadline](#tutorial-add-deadline) - * [Add Todo](#tutorial-add-todo) - * [Delete Task](#tutorial-delete-task) - * [Mark/Unmark Task](#tutorial-update-task) - * [Find Task](#tutorial-find-task) - * [List Task](#tutorial-list-task) -* [Command Summary](#command) + * [Exit](#tutorial-exit) + * [Add Event](#tutorial-add-event) + * [Add Deadline](#tutorial-add-deadline) + * [Add Todo](#tutorial-add-todo) + * [Delete Task](#tutorial-delete-task) + * [Mark/Unmark Task](#tutorial-markunmark-task) + * [Find Task](#tutorial-find-task) + * [List Task](#tutorial-list-task) +* [Command Summary](#command-summary) +* [Trouble Shooting](#trouble-shooting) + +--- ##Introduction +Duke is a flexible command line based task manager that helps you to manage your todo task, event task and deadline task. You can follow this guide to explore more features about duke. + +--- + ##Setup Guide Prerequisite: JDK 11 -1. Please ensure that JDK 11 is installed before running Duke. You can check it in terminal by typing +1. Please ensure that JDK 11 is installed before running Duke. You can check it in terminal by typing ````shell java -v ```` @@ -44,6 +53,260 @@ Prerequisite: JDK 11 ````shell java -jar ip.jar ```` + +--- + ##Features + +###Task Type +There are three types of task that are acceptable by duke: +* ####Event + *Event* is a task type that contains task name and event time. It has marked with *E* when displaying on the interface. + ````text + [E][ ](at: ) + ```` +* ####Deadline + *Deadline* is also a task type that contains task name and deadline time. It has marked with *D* when displaying on the interface + ````text + [D][ ](by: ) + ```` +* ####Todo + *Todo* is another task type that only contains task name. It has marked with *T* when displaying on the interface. + ````text + [T][ ] + ```` + +--- + +###Features: Add +You can add any todo task, event task and deadline task without limit in numbers. All the tasks are marked as undone initially like following: +````text +[Task Type][Task Status] +```` +Check [Tutorial](#tutorial) or [Command Summary](#command-summary) for adding command usage. + +--- + +###Features: Delete +You can delete any task from the list by giving the index of the task you want to delete. + +Check [Tutorial](#tutorial-delete-task) or [Command Summary](#command-summary) for delete command usage. + +--- + +###Features: Mark/Unmark +You can mark any task in the list as done or undone by giving the index of the task you want to mark/unmark. The marked task will display *X* on the second column when displaying on the interface, like following example: + +````text +[Task Type][X] //this is a marked task +```` +Check [Tutorial](#tutorial-markunmark-task) or [Command Summary](#command-summary) for marking/unmarking command usage. + +--- + +###Features: Search +You can use keywords to find all the task that have relevant task name to the given keyword. + +Check [Tutorial](#tutorial-find-task) or [Command Summary](#command-summary) for searching command usage. + +--- + +###Features: List +You can list all the task that duke has stored. Check [Tutorial](#tutorial-list-task) or [Command Summary](#command-summary) for searching command usage. + +--- + +###Features: Save +All the tasks that duke has will be saved to an external file. Don't worry if you exit the program without saving file! Duke will save it after every operation. Next time when you start the program again, you could see the tasks from the last use. + +--- ##Tutorial +####Tutorial: Exit +Use following command to exit the program: +````text +Bye +```` + +--- + +###Tutorial: Add Event +Type following command in the console by replacing and with your own task information: +````shell +Event /at +```` +You will get following message if the action is success. +````shell +ψ(._. )> Got it. I've added this task: +[E][ ](at: ) +Now you have tasks in your list. +```` + +--- + +###Tutorial: Add Deadline +Type following command in the console by replacing and with your own task information: +````shell +Deadline /by +```` +You will get following message if the action is success. +````shell +ψ(._. )> Got it. I've added this task: +[D][ ](by: ) +Now you have tasks in your list. +```` + +--- + +###Tutorial: Add Todo +Type following command in the console by replacing and with your own task information: +````shell +Todo +```` +You will get following message if the action is success. +````shell +ψ(._. )> Got it. I've added this task: +[T][ ] +Now you have tasks in your list. +```` +***IMPORTANT NOTE*** + +Please use acceptable time format when entering time. Acceptable time formats are following: +````text +y-M-d H:m +y/M/d H:m +d-M-y H:m +d/M/y H:m +(y -> year, M -> month, d -> day, H -> hour, m -> minute) +Year, Hour and Minute fields are optional +There's no requirement for the number of digit but please ensure that the date and the time is valid. +```` + +--- + +###Tutorial: List Task +Use following command to list all the task: +````shell +list +```` +You should see following message if there's any task in the list: +````text +o(≧v≦)o Here are the tasks in your list: +1. [Task Type][Status]() +2. [Task Type][Status]() +3. ... +```` +Otherwise +````text +The list is empty currently ( ̄3 ̄)a +```` +***IMPORTANT NOTE*** + +Please use the index from listing task for deleting and marking/unmarking task! + +--- + +###Tutorial: Delete Task +Type following command by replacing to the index of the task that you would like to delete: +````text +delete +```` +You will get following message if the action is success. +````text +ψ(._. )> Okay! I've deleted this task: +[Type of Task][Status of Task]() +Now you have tasks in your list. +```` +***IMPORTANT NOTE*** + +For the index of the task, please refer to the index when listing all the tasks. The index may change after adding task or deleting task. **Be aware that this action cannot be retrieved!** + +--- + +###Tutorial: Mark/Unmark Task +To mark a task in the list, type following command by replacing to the index of the task that you would like to delete: +````text +mark +```` +You will get following message if the action is success. +````shell +ψ(._. )> Okay! I've deleted this task: +[Type of Task][X]() +```` +Use following command to unmark a task in the list: +````shell +unmark +```` +You will get following message if the action is success. +````shell +ψ(._. )> Okay! I've deleted this task: +[Type of Task][ ]() +```` +***IMPORTANT NOTE*** + +For the index of the task, please refer to the index when listing all the tasks. The index may change after adding task or deleting task. + +--- + +###Tutorial: Find Task +Use following command to find a task that match the keyword from the list: +````shell +find +```` +Duke will list all the tasks that match the keyword (if there's any!) +````TEXT +o(≧v≦)o Here are the matching tasks in your list: +1. [Task Type][Status]() +2. [Task Type][Status]() +3. ... +... +```` +If there's no task which matches to the keyword, duke will print following message on the interface: +````TEXT +( ̄ε ̄;) Sorry, I can't find any result from the list. +```` +***IMPORTANT NOTE*** + +**Please do not refer to this index when deleting or marking/unmarking task.** This index is only for your reference about how many matching task in the list. + +Duke only supports to find matching task according to the keyword and task name. **Searching by time is not supported currently.** + +--- + ##Command Summary +| **Command Type** | Command Format | +|:-----------------|:---------------------------------------| +| **add todo** | `todo ` | +| **add event** | `event /at ` | +| **add deadline** | `deadline /by ` | +| **mark** | `mark ` | +| **unmark** | `unmark ` | +| **find** | `find ` | +| **delete** | `delete ` | +| **list** | `list` | +| **exit** | `bye` | + +--- + +##Trouble Shooting +**Q**: What should I do if the program reports loading error? + +**A**: The external file for saving and loading is broken. In this case you need to reinstall the programme. + +**Q**: What is acceptable time format? + +**A**: The acceptable time formats are following: +````text +y-M-d H:m +y/M/d H:m +d-M-y H:m +d/M/y H:m +(y -> year, M -> month, d -> day, H -> hour, m -> minute) +Year, Hour and Minute fields are optional +```` +There's no requirement for the number of digit but please ensure that the date and the time is valid. + +**Q**: What if I accidentally delete a task that I want to keep? + +**A**: Delete action cannot be retrieved. You can add it again, but the tasks will have different index. + +**TIPS**: Always list all the task before deleting and marking/unmarking. diff --git a/data/duke.txt b/data/duke.txt index d17200146..e69de29bb 100644 --- a/data/duke.txt +++ b/data/duke.txt @@ -1 +0,0 @@ -[E][ ]j(at: Mar. 04 2019) diff --git a/docs/README.md b/docs/README.md index c65b333f7..b94758be6 100644 --- a/docs/README.md +++ b/docs/README.md @@ -5,27 +5,34 @@ * [Introduction](#introduction) * [Setup Guide](#setup-guide) * [Features](#features) - * [Task Type](#feature-type) - * [Event](#feature-type-event) - * [Deadline](#feature-type-deadline) - * [Todo](#feature-type-todo) - * [Add](#feature-add) - * [Delete](#feature-delete) - * [Mark/Unmark](#feature-mark-unmark) - * [Search](#feature-search) - * [List](#feature-list) + * [Task Type](#task-type) + * [Event](#event) + * [Deadline](#deadline) + * [Todo](#todo) + * [Add](#features-add) + * [Delete](#features-delete) + * [Mark/Unmark](#features-markunmark) + * [Search](#features-search) + * [List](#features-list) * [Tutorial](#tutorial) + * [Exit](#tutorial-exit) * [Add Event](#tutorial-add-event) * [Add Deadline](#tutorial-add-deadline) * [Add Todo](#tutorial-add-todo) * [Delete Task](#tutorial-delete-task) - * [Mark/Unmark Task](#tutorial-update-task) + * [Mark/Unmark Task](#tutorial-markunmark-task) * [Find Task](#tutorial-find-task) * [List Task](#tutorial-list-task) * [Command Summary](#command-summary) -* [Common Questions](#common-questions) +* [Trouble Shooting](#trouble-shooting) + +--- ##Introduction +Duke is a flexible command line based task manager that helps you to manage your todo task, event task and deadline task. You can follow this guide to explore more features about duke. + +--- + ##Setup Guide Prerequisite: JDK 11 1. Please ensure that JDK 11 is installed before running Duke. You can check it in terminal by typing @@ -46,7 +53,261 @@ Prerequisite: JDK 11 ````shell java -jar ip.jar ```` + +--- + ##Features + +###Task Type +There are three types of task that are acceptable by duke: +* ####Event + *Event* is a task type that contains task name and event time. It has marked with *E* when displaying on the interface. + ````text + [E][ ](at: ) + ```` +* ####Deadline + *Deadline* is also a task type that contains task name and deadline time. It has marked with *D* when displaying on the interface + ````text + [D][ ](by: ) + ```` +* ####Todo + *Todo* is another task type that only contains task name. It has marked with *T* when displaying on the interface. + ````text + [T][ ] + ```` + +--- + +###Features: Add +You can add any todo task, event task and deadline task without limit in numbers. All the tasks are marked as undone initially like following: +````text +[Task Type][Task Status] +```` +Check [Tutorial](#tutorial) or [Command Summary](#command-summary) for adding command usage. + +--- + +###Features: Delete +You can delete any task from the list by giving the index of the task you want to delete. + +Check [Tutorial](#tutorial-delete-task) or [Command Summary](#command-summary) for delete command usage. + +--- + +###Features: Mark/Unmark +You can mark any task in the list as done or undone by giving the index of the task you want to mark/unmark. The marked task will display *X* on the second column when displaying on the interface, like following example: + +````text +[Task Type][X] //this is a marked task +```` +Check [Tutorial](#tutorial-markunmark-task) or [Command Summary](#command-summary) for marking/unmarking command usage. + +--- + +###Features: Search +You can use keywords to find all the task that have relevant task name to the given keyword. + +Check [Tutorial](#tutorial-find-task) or [Command Summary](#command-summary) for searching command usage. + +--- + +###Features: List +You can list all the task that duke has stored. Check [Tutorial](#tutorial-list-task) or [Command Summary](#command-summary) for searching command usage. + +--- + +###Features: Save +All the tasks that duke has will be saved to an external file. Don't worry if you exit the program without saving file! Duke will save it after every operation. Next time when you start the program again, you could see the tasks from the last use. + +--- ##Tutorial +####Tutorial: Exit +Use following command to exit the program: +````text +Bye +```` + +--- + +###Tutorial: Add Event +Type following command in the console by replacing and with your own task information: +````shell +Event /at +```` +You will get following message if the action is success. +````shell +ψ(._. )> Got it. I've added this task: +[E][ ](at: ) +Now you have tasks in your list. +```` + +--- + +###Tutorial: Add Deadline +Type following command in the console by replacing and with your own task information: +````shell +Deadline /by +```` +You will get following message if the action is success. +````shell +ψ(._. )> Got it. I've added this task: +[D][ ](by: ) +Now you have tasks in your list. +```` + +--- + +###Tutorial: Add Todo +Type following command in the console by replacing and with your own task information: +````shell +Todo +```` +You will get following message if the action is success. +````shell +ψ(._. )> Got it. I've added this task: +[T][ ] +Now you have tasks in your list. +```` +***IMPORTANT NOTE*** + +Please use acceptable time format when entering time. Acceptable time formats are following: +````text +y-M-d H:m +y/M/d H:m +d-M-y H:m +d/M/y H:m +(y -> year, M -> month, d -> day, H -> hour, m -> minute) +Year, Hour and Minute fields are optional +There's no requirement for the number of digit but please ensure that the date and the time is valid. +```` + +--- + +###Tutorial: List Task +Use following command to list all the task: +````shell +list +```` +You should see following message if there's any task in the list: +````text +o(≧v≦)o Here are the tasks in your list: +1. [Task Type][Status]() +2. [Task Type][Status]() +3. ... +```` +Otherwise +````text +The list is empty currently ( ̄3 ̄)a +```` +***IMPORTANT NOTE*** + +Please use the index from listing task for deleting and marking/unmarking task! + +--- + +###Tutorial: Delete Task +Type following command by replacing to the index of the task that you would like to delete: +````text +delete +```` +You will get following message if the action is success. +````text +ψ(._. )> Okay! I've deleted this task: +[Type of Task][Status of Task]() +Now you have tasks in your list. +```` +***IMPORTANT NOTE*** + +For the index of the task, please refer to the index when listing all the tasks. The index may change after adding task or deleting task. **Be aware that this action cannot be retrieved!** + +--- + +###Tutorial: Mark/Unmark Task +To mark a task in the list, type following command by replacing to the index of the task that you would like to delete: +````text +mark +```` +You will get following message if the action is success. +````shell +ψ(._. )> Okay! I've deleted this task: +[Type of Task][X]() +```` +Use following command to unmark a task in the list: +````shell +unmark +```` +You will get following message if the action is success. +````shell +ψ(._. )> Okay! I've deleted this task: +[Type of Task][ ]() +```` +***IMPORTANT NOTE*** + +For the index of the task, please refer to the index when listing all the tasks. The index may change after adding task or deleting task. + +--- + +###Tutorial: Find Task +Use following command to find a task that match the keyword from the list: +````shell +find +```` +Duke will list all the tasks that match the keyword (if there's any!) +````TEXT +o(≧v≦)o Here are the matching tasks in your list: +1. [Task Type][Status]() +2. [Task Type][Status]() +3. ... +... +```` +If there's no task which matches to the keyword, duke will print following message on the interface: +````TEXT +( ̄ε ̄;) Sorry, I can't find any result from the list. +```` +***IMPORTANT NOTE*** + +**Please do not refer to this index when deleting or marking/unmarking task.** This index is only for your reference about how many matching task in the list. + +Duke only supports to find matching task according to the keyword and task name. **Searching by time is not supported currently.** + +--- + ##Command Summary -##Common Questions +| **Command Type** | Command Format | +|:-----------------|:---------------------------------------| +| **add todo** | `todo ` | +| **add event** | `event /at ` | +| **add deadline** | `deadline /by ` | +| **mark** | `mark ` | +| **unmark** | `unmark ` | +| **find** | `find ` | +| **delete** | `delete ` | +| **list** | `list` | +| **exit** | `bye` | + +--- + +##Trouble Shooting +**Q**: What should I do if the program reports loading error? + +**A**: The external file for saving and loading is broken. In this case you need to reinstall the programme. + +**Q**: What is acceptable time format? + +**A**: The acceptable time formats are following: +````text +y-M-d H:m +y/M/d H:m +d-M-y H:m +d/M/y H:m +(y -> year, M -> month, d -> day, H -> hour, m -> minute) +Year, Hour and Minute fields are optional +```` +There's no requirement for the number of digit but please ensure that the date and the time is valid. + +**Q**: What if I accidentally delete a task that I want to keep? + +**A**: Delete action cannot be retrieved. You can add it again, but the tasks will have different index. + +**TIPS**: Always list all the task before deleting and marking/unmarking. + From a731ae76e84c8967dde9a79f2bb2b80a6ad0e8e0 Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Fri, 4 Mar 2022 12:36:42 +0800 Subject: [PATCH 33/45] fix error in ug --- README.md | 48 ++++++++++++++++++++++++------------------------ docs/README.md | 48 ++++++++++++++++++++++++------------------------ 2 files changed, 48 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 6e24146fb..58ecc1418 100644 --- a/README.md +++ b/README.md @@ -28,12 +28,12 @@ --- -##Introduction +## Introduction Duke is a flexible command line based task manager that helps you to manage your todo task, event task and deadline task. You can follow this guide to explore more features about duke. --- -##Setup Guide +## Setup Guide Prerequisite: JDK 11 1. Please ensure that JDK 11 is installed before running Duke. You can check it in terminal by typing ````shell @@ -56,21 +56,21 @@ Prerequisite: JDK 11 --- -##Features +## Features -###Task Type +### Task Type There are three types of task that are acceptable by duke: -* ####Event +* #### Event *Event* is a task type that contains task name and event time. It has marked with *E* when displaying on the interface. ````text [E][ ](at: ) ```` -* ####Deadline +* #### Deadline *Deadline* is also a task type that contains task name and deadline time. It has marked with *D* when displaying on the interface ````text [D][ ](by: ) ```` -* ####Todo +* #### Todo *Todo* is another task type that only contains task name. It has marked with *T* when displaying on the interface. ````text [T][ ] @@ -78,7 +78,7 @@ There are three types of task that are acceptable by duke: --- -###Features: Add +### Features: Add You can add any todo task, event task and deadline task without limit in numbers. All the tasks are marked as undone initially like following: ````text [Task Type][Task Status] @@ -87,14 +87,14 @@ Check [Tutorial](#tutorial) or [Command Summary](#command-summary) for adding co --- -###Features: Delete +### Features: Delete You can delete any task from the list by giving the index of the task you want to delete. Check [Tutorial](#tutorial-delete-task) or [Command Summary](#command-summary) for delete command usage. --- -###Features: Mark/Unmark +### Features: Mark/Unmark You can mark any task in the list as done or undone by giving the index of the task you want to mark/unmark. The marked task will display *X* on the second column when displaying on the interface, like following example: ````text @@ -104,24 +104,24 @@ Check [Tutorial](#tutorial-markunmark-task) or [Command Summary](#command-summar --- -###Features: Search +### Features: Search You can use keywords to find all the task that have relevant task name to the given keyword. Check [Tutorial](#tutorial-find-task) or [Command Summary](#command-summary) for searching command usage. --- -###Features: List +### Features: List You can list all the task that duke has stored. Check [Tutorial](#tutorial-list-task) or [Command Summary](#command-summary) for searching command usage. --- -###Features: Save +### Features: Save All the tasks that duke has will be saved to an external file. Don't worry if you exit the program without saving file! Duke will save it after every operation. Next time when you start the program again, you could see the tasks from the last use. --- -##Tutorial -####Tutorial: Exit +## Tutorial +#### Tutorial: Exit Use following command to exit the program: ````text Bye @@ -129,7 +129,7 @@ Bye --- -###Tutorial: Add Event +### Tutorial: Add Event Type following command in the console by replacing and with your own task information: ````shell Event /at @@ -143,7 +143,7 @@ Now you have tasks in your list. --- -###Tutorial: Add Deadline +### Tutorial: Add Deadline Type following command in the console by replacing and with your own task information: ````shell Deadline /by @@ -157,7 +157,7 @@ Now you have tasks in your list. --- -###Tutorial: Add Todo +### Tutorial: Add Todo Type following command in the console by replacing and with your own task information: ````shell Todo @@ -183,7 +183,7 @@ There's no requirement for the number of digit but please ensure that the date a --- -###Tutorial: List Task +### Tutorial: List Task Use following command to list all the task: ````shell list @@ -205,7 +205,7 @@ Please use the index from listing task for deleting and marking/unmarking task! --- -###Tutorial: Delete Task +### Tutorial: Delete Task Type following command by replacing to the index of the task that you would like to delete: ````text delete @@ -222,7 +222,7 @@ For the index of the task, please refer to the index when listing all the tasks. --- -###Tutorial: Mark/Unmark Task +### Tutorial: Mark/Unmark Task To mark a task in the list, type following command by replacing to the index of the task that you would like to delete: ````text mark @@ -247,7 +247,7 @@ For the index of the task, please refer to the index when listing all the tasks. --- -###Tutorial: Find Task +### Tutorial: Find Task Use following command to find a task that match the keyword from the list: ````shell find @@ -272,7 +272,7 @@ Duke only supports to find matching task according to the keyword and task name. --- -##Command Summary +## Command Summary | **Command Type** | Command Format | |:-----------------|:---------------------------------------| | **add todo** | `todo ` | @@ -287,7 +287,7 @@ Duke only supports to find matching task according to the keyword and task name. --- -##Trouble Shooting +## Trouble Shooting **Q**: What should I do if the program reports loading error? **A**: The external file for saving and loading is broken. In this case you need to reinstall the programme. diff --git a/docs/README.md b/docs/README.md index b94758be6..db0dc2f59 100644 --- a/docs/README.md +++ b/docs/README.md @@ -28,12 +28,12 @@ --- -##Introduction +## Introduction Duke is a flexible command line based task manager that helps you to manage your todo task, event task and deadline task. You can follow this guide to explore more features about duke. --- -##Setup Guide +## Setup Guide Prerequisite: JDK 11 1. Please ensure that JDK 11 is installed before running Duke. You can check it in terminal by typing ````shell @@ -56,21 +56,21 @@ Prerequisite: JDK 11 --- -##Features +## Features -###Task Type +### Task Type There are three types of task that are acceptable by duke: -* ####Event +* #### Event *Event* is a task type that contains task name and event time. It has marked with *E* when displaying on the interface. ````text [E][ ](at: ) ```` -* ####Deadline +* #### Deadline *Deadline* is also a task type that contains task name and deadline time. It has marked with *D* when displaying on the interface ````text [D][ ](by: ) ```` -* ####Todo +* #### Todo *Todo* is another task type that only contains task name. It has marked with *T* when displaying on the interface. ````text [T][ ] @@ -78,7 +78,7 @@ There are three types of task that are acceptable by duke: --- -###Features: Add +### Features: Add You can add any todo task, event task and deadline task without limit in numbers. All the tasks are marked as undone initially like following: ````text [Task Type][Task Status] @@ -87,14 +87,14 @@ Check [Tutorial](#tutorial) or [Command Summary](#command-summary) for adding co --- -###Features: Delete +### Features: Delete You can delete any task from the list by giving the index of the task you want to delete. Check [Tutorial](#tutorial-delete-task) or [Command Summary](#command-summary) for delete command usage. --- -###Features: Mark/Unmark +### Features: Mark/Unmark You can mark any task in the list as done or undone by giving the index of the task you want to mark/unmark. The marked task will display *X* on the second column when displaying on the interface, like following example: ````text @@ -104,24 +104,24 @@ Check [Tutorial](#tutorial-markunmark-task) or [Command Summary](#command-summar --- -###Features: Search +### Features: Search You can use keywords to find all the task that have relevant task name to the given keyword. Check [Tutorial](#tutorial-find-task) or [Command Summary](#command-summary) for searching command usage. --- -###Features: List +### Features: List You can list all the task that duke has stored. Check [Tutorial](#tutorial-list-task) or [Command Summary](#command-summary) for searching command usage. --- -###Features: Save +### Features: Save All the tasks that duke has will be saved to an external file. Don't worry if you exit the program without saving file! Duke will save it after every operation. Next time when you start the program again, you could see the tasks from the last use. --- -##Tutorial -####Tutorial: Exit +## Tutorial +#### Tutorial: Exit Use following command to exit the program: ````text Bye @@ -129,7 +129,7 @@ Bye --- -###Tutorial: Add Event +### Tutorial: Add Event Type following command in the console by replacing and with your own task information: ````shell Event /at @@ -143,7 +143,7 @@ Now you have tasks in your list. --- -###Tutorial: Add Deadline +### Tutorial: Add Deadline Type following command in the console by replacing and with your own task information: ````shell Deadline /by @@ -157,7 +157,7 @@ Now you have tasks in your list. --- -###Tutorial: Add Todo +### Tutorial: Add Todo Type following command in the console by replacing and with your own task information: ````shell Todo @@ -183,7 +183,7 @@ There's no requirement for the number of digit but please ensure that the date a --- -###Tutorial: List Task +### Tutorial: List Task Use following command to list all the task: ````shell list @@ -205,7 +205,7 @@ Please use the index from listing task for deleting and marking/unmarking task! --- -###Tutorial: Delete Task +### Tutorial: Delete Task Type following command by replacing to the index of the task that you would like to delete: ````text delete @@ -222,7 +222,7 @@ For the index of the task, please refer to the index when listing all the tasks. --- -###Tutorial: Mark/Unmark Task +### Tutorial: Mark/Unmark Task To mark a task in the list, type following command by replacing to the index of the task that you would like to delete: ````text mark @@ -247,7 +247,7 @@ For the index of the task, please refer to the index when listing all the tasks. --- -###Tutorial: Find Task +### Tutorial: Find Task Use following command to find a task that match the keyword from the list: ````shell find @@ -272,7 +272,7 @@ Duke only supports to find matching task according to the keyword and task name. --- -##Command Summary +## Command Summary | **Command Type** | Command Format | |:-----------------|:---------------------------------------| | **add todo** | `todo ` | @@ -287,7 +287,7 @@ Duke only supports to find matching task according to the keyword and task name. --- -##Trouble Shooting +## Trouble Shooting **Q**: What should I do if the program reports loading error? **A**: The external file for saving and loading is broken. In this case you need to reinstall the programme. From ced626053b2dfa5c239ee0b87d195f26c9960ffa Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Fri, 4 Mar 2022 12:38:59 +0800 Subject: [PATCH 34/45] fix error in ug --- README.md | 25 +++++++++++++------------ docs/README.md | 20 ++++++++++---------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 58ecc1418..964156cd5 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ Prerequisite: JDK 11 ````shell java -jar ip.jar ```` - + --- ## Features @@ -75,7 +75,7 @@ There are three types of task that are acceptable by duke: ````text [T][ ] ```` - + --- ### Features: Add @@ -131,11 +131,11 @@ Bye ### Tutorial: Add Event Type following command in the console by replacing and with your own task information: -````shell +````text Event /at ```` You will get following message if the action is success. -````shell +````text ψ(._. )> Got it. I've added this task: [E][ ](at: ) Now you have tasks in your list. @@ -145,11 +145,11 @@ Now you have tasks in your list. ### Tutorial: Add Deadline Type following command in the console by replacing and with your own task information: -````shell +````text Deadline /by ```` You will get following message if the action is success. -````shell +````text ψ(._. )> Got it. I've added this task: [D][ ](by: ) Now you have tasks in your list. @@ -163,7 +163,7 @@ Type following command in the console by replacing and Todo ```` You will get following message if the action is success. -````shell +````text ψ(._. )> Got it. I've added this task: [T][ ] Now you have tasks in your list. @@ -185,7 +185,7 @@ There's no requirement for the number of digit but please ensure that the date a ### Tutorial: List Task Use following command to list all the task: -````shell +````text list ```` You should see following message if there's any task in the list: @@ -228,16 +228,16 @@ To mark a task in the list, type following command by replacing mark ```` You will get following message if the action is success. -````shell +````text ψ(._. )> Okay! I've deleted this task: [Type of Task][X]() ```` Use following command to unmark a task in the list: -````shell +````text unmark ```` You will get following message if the action is success. -````shell +````text ψ(._. )> Okay! I've deleted this task: [Type of Task][ ]() ```` @@ -249,7 +249,7 @@ For the index of the task, please refer to the index when listing all the tasks. ### Tutorial: Find Task Use following command to find a task that match the keyword from the list: -````shell +````text find ```` Duke will list all the tasks that match the keyword (if there's any!) @@ -310,3 +310,4 @@ There's no requirement for the number of digit but please ensure that the date a **A**: Delete action cannot be retrieved. You can add it again, but the tasks will have different index. **TIPS**: Always list all the task before deleting and marking/unmarking. + diff --git a/docs/README.md b/docs/README.md index db0dc2f59..964156cd5 100644 --- a/docs/README.md +++ b/docs/README.md @@ -131,11 +131,11 @@ Bye ### Tutorial: Add Event Type following command in the console by replacing and with your own task information: -````shell +````text Event /at ```` You will get following message if the action is success. -````shell +````text ψ(._. )> Got it. I've added this task: [E][ ](at: ) Now you have tasks in your list. @@ -145,11 +145,11 @@ Now you have tasks in your list. ### Tutorial: Add Deadline Type following command in the console by replacing and with your own task information: -````shell +````text Deadline /by ```` You will get following message if the action is success. -````shell +````text ψ(._. )> Got it. I've added this task: [D][ ](by: ) Now you have tasks in your list. @@ -163,7 +163,7 @@ Type following command in the console by replacing and Todo ```` You will get following message if the action is success. -````shell +````text ψ(._. )> Got it. I've added this task: [T][ ] Now you have tasks in your list. @@ -185,7 +185,7 @@ There's no requirement for the number of digit but please ensure that the date a ### Tutorial: List Task Use following command to list all the task: -````shell +````text list ```` You should see following message if there's any task in the list: @@ -228,16 +228,16 @@ To mark a task in the list, type following command by replacing mark ```` You will get following message if the action is success. -````shell +````text ψ(._. )> Okay! I've deleted this task: [Type of Task][X]() ```` Use following command to unmark a task in the list: -````shell +````text unmark ```` You will get following message if the action is success. -````shell +````text ψ(._. )> Okay! I've deleted this task: [Type of Task][ ]() ```` @@ -249,7 +249,7 @@ For the index of the task, please refer to the index when listing all the tasks. ### Tutorial: Find Task Use following command to find a task that match the keyword from the list: -````shell +````text find ```` Duke will list all the tasks that match the keyword (if there's any!) From d2c0e1057346aea4dcac627c5155f7faeae06da9 Mon Sep 17 00:00:00 2001 From: hlwang56 <69446689+hlwang56@users.noreply.github.com> Date: Fri, 4 Mar 2022 12:41:36 +0800 Subject: [PATCH 35/45] Set theme jekyll-theme-leap-day --- docs/_config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/_config.yml b/docs/_config.yml index 3397c9a49..b84971359 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -1 +1 @@ -theme: jekyll-theme-architect \ No newline at end of file +theme: jekyll-theme-leap-day \ No newline at end of file From 90869a9a91889c104ba4eea6528dec51b829536a Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Fri, 4 Mar 2022 12:43:24 +0800 Subject: [PATCH 36/45] fix error in ug --- README.md | 2 +- docs/README.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 964156cd5..e27fc5eaf 100644 --- a/README.md +++ b/README.md @@ -303,7 +303,7 @@ d/M/y H:m (y -> year, M -> month, d -> day, H -> hour, m -> minute) Year, Hour and Minute fields are optional ```` -There's no requirement for the number of digit but please ensure that the date and the time is valid. +There's no requirement for the number of digit but please ensure that the date and the time are valid. **Q**: What if I accidentally delete a task that I want to keep? diff --git a/docs/README.md b/docs/README.md index 964156cd5..321036aeb 100644 --- a/docs/README.md +++ b/docs/README.md @@ -46,7 +46,7 @@ Prerequisite: JDK 11 OpenJDK 64-Bit Server VM Corretto-11.0.13.8.1 (build 11.0.13+8-LTS, mixed mode) ```` 2. Download the latest release. You can use command to download it or simply download it from the website: - ```` + ````shell https://github.com/hlwang56/ip/releases ```` 3. Open a terminal in the folder when the jar file is placed and run following command @@ -303,7 +303,7 @@ d/M/y H:m (y -> year, M -> month, d -> day, H -> hour, m -> minute) Year, Hour and Minute fields are optional ```` -There's no requirement for the number of digit but please ensure that the date and the time is valid. +There's no requirement for the number of digit but please ensure that the date and the time are valid. **Q**: What if I accidentally delete a task that I want to keep? From 886077c60a79986456b439ff38f3da674a3f4793 Mon Sep 17 00:00:00 2001 From: hlwang56 <69446689+hlwang56@users.noreply.github.com> Date: Fri, 4 Mar 2022 12:45:19 +0800 Subject: [PATCH 37/45] Set theme jekyll-theme-hacker --- docs/_config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/_config.yml b/docs/_config.yml index b84971359..fc24e7a62 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -1 +1 @@ -theme: jekyll-theme-leap-day \ No newline at end of file +theme: jekyll-theme-hacker \ No newline at end of file From d8c74505b26068fe5fd7080ccc8c1e5f94442b15 Mon Sep 17 00:00:00 2001 From: hlwang56 <69446689+hlwang56@users.noreply.github.com> Date: Fri, 4 Mar 2022 12:48:05 +0800 Subject: [PATCH 38/45] Set theme jekyll-theme-slate --- docs/_config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/_config.yml b/docs/_config.yml index fc24e7a62..c74188174 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -1 +1 @@ -theme: jekyll-theme-hacker \ No newline at end of file +theme: jekyll-theme-slate \ No newline at end of file From ce7c7ea2e12c3037ed88c61260c5f99b2864bbd2 Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Fri, 4 Mar 2022 17:01:20 +0800 Subject: [PATCH 39/45] fixed some bugs and update demo session --- README.md | 99 ++++++++++++++++++++++++++- docs/README.md | 99 ++++++++++++++++++++++++++- src/main/java/controller/Command.java | 19 +++-- src/main/java/tasks/Storage.java | 3 +- text-ui-test/EXPECTED.TXT | 66 ++++++++++++------ text-ui-test/input.txt | 9 ++- 6 files changed, 259 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index e27fc5eaf..0f82f781d 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ * [List Task](#tutorial-list-task) * [Command Summary](#command-summary) * [Trouble Shooting](#trouble-shooting) - +* [Demo](#demo) --- ## Introduction @@ -176,8 +176,11 @@ y-M-d H:m y/M/d H:m d-M-y H:m d/M/y H:m +y-M-d +y/M/d +d-M-y +d/M/y (y -> year, M -> month, d -> day, H -> hour, m -> minute) -Year, Hour and Minute fields are optional There's no requirement for the number of digit but please ensure that the date and the time is valid. ```` @@ -300,8 +303,11 @@ y-M-d H:m y/M/d H:m d-M-y H:m d/M/y H:m +y-M-d +y/M/d +d-M-y +d/M/y (y -> year, M -> month, d -> day, H -> hour, m -> minute) -Year, Hour and Minute fields are optional ```` There's no requirement for the number of digit but please ensure that the date and the time are valid. @@ -311,3 +317,90 @@ There's no requirement for the number of digit but please ensure that the date a **TIPS**: Always list all the task before deleting and marking/unmarking. +##Demo +````text +Hello! I'm Duke :P +What can I do for you? +------------------------------------- +list +The list is empty currently ( ̄3 ̄)a +------------------------------------- +deadline CS2113 Quiz /by 2019/06/20 23:59 +ψ(._. )> Got it. I've added this task: +[D][ ]CS2113 Quiz (by: Jun. 20 2019 23:59) +Now you have 1 tasks in your list. +------------------------------------- +event MA2101 Quiz /at 2019-6-30 +ψ(._. )> Got it. I've added this task: +[E][ ]MA2101 Quiz (at: Jun. 30 2019) +Now you have 2 tasks in your list. +------------------------------------- +todo Homework +ψ(._. )> Got it. I've added this task: +[T][ ]Homework +Now you have 3 tasks in your list. +------------------------------------- +list +o(≧v≦)o Here are the tasks in your list: +1. [D][ ]CS2113 Quiz (by: Jun. 20 2019 23:59) +2. [E][ ]MA2101 Quiz (at: Jun. 30 2019) +3. [T][ ]Homework +------------------------------------- +mark 1 +ψ(._. )> Nice! I've marked this task as done: +[D][X]CS2113 Quiz (by: Jun. 20 2019 23:59) +------------------------------------- +mark 2 +ψ(._. )> Nice! I've marked this task as done: +[E][X]MA2101 Quiz (at: Jun. 30 2019) +------------------------------------- +list +o(≧v≦)o Here are the tasks in your list: +1. [D][X]CS2113 Quiz (by: Jun. 20 2019 23:59) +2. [E][X]MA2101 Quiz (at: Jun. 30 2019) +3. [T][ ]Homework +------------------------------------- +unmark 2 +ψ(._. )> OK, I've marked this task as not done yet: +[E][ ]MA2101 Quiz (at: Jun. 30 2019) +------------------------------------- +list +o(≧v≦)o Here are the tasks in your list: +1. [D][X]CS2113 Quiz (by: Jun. 20 2019 23:59) +2. [E][ ]MA2101 Quiz (at: Jun. 30 2019) +3. [T][ ]Homework +------------------------------------- +find Quiz +o(≧v≦)o Here are the matching tasks in your list: +1. [D][X]CS2113 Quiz (by: Jun. 20 2019 23:59) +2. [E][ ]MA2101 Quiz (at: Jun. 30 2019) +------------------------------------- +deadline CS2106 midterm /at 2019-4-31 +The format is incorrect! Can you please check your input again? ●ω● +------------------------------------- +deadline CS2106 midterm /by 2019-4-31 +The time format is incorrect! Can you please check your input again? ( ̄~ ̄;) You can check the manual to find out acceptable time format! +------------------------------------- +deadline CS2106 midterm /by 2019-4-30 25:61 +The time format is incorrect! Can you please check your input again? ( ̄~ ̄;) You can check the manual to find out acceptable time format! +------------------------------------- +deadline CS2106 midterm /by 2019-4-30 2:3 +ψ(._. )> Got it. I've added this task: +[D][ ]CS2106 midterm (by: Apr. 30 2019 02:03) +Now you have 4 tasks in your list. +------------------------------------- +list +o(≧v≦)o Here are the tasks in your list: +1. [D][ ]CS2113 Quiz (by: Jun. 20 2019 23:59) +2. [E][ ]MA2101 Quiz (at: Jun. 30 2019) +3. [T][ ]Homework +4. [D][ ]CS2106 midterm (by: Apr. 30 2019 02:03) +------------------------------------- +delete 4 +ψ(._. )> Okay! I've deleted this task: +[D][ ]CS2106 midterm (by: Apr. 30 2019 02:03) +Now you have 3 tasks in your list. +------------------------------------- +Bye. Hope to see you again soon! ;) +------------------------------------- +```` \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index 321036aeb..a84f0e70f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -25,6 +25,7 @@ * [List Task](#tutorial-list-task) * [Command Summary](#command-summary) * [Trouble Shooting](#trouble-shooting) +* [Demo](#demo) --- @@ -176,8 +177,11 @@ y-M-d H:m y/M/d H:m d-M-y H:m d/M/y H:m +y-M-d +y/M/d +d-M-y +d/M/y (y -> year, M -> month, d -> day, H -> hour, m -> minute) -Year, Hour and Minute fields are optional There's no requirement for the number of digit but please ensure that the date and the time is valid. ```` @@ -300,8 +304,11 @@ y-M-d H:m y/M/d H:m d-M-y H:m d/M/y H:m +y-M-d +y/M/d +d-M-y +d/M/y (y -> year, M -> month, d -> day, H -> hour, m -> minute) -Year, Hour and Minute fields are optional ```` There's no requirement for the number of digit but please ensure that the date and the time are valid. @@ -311,3 +318,91 @@ There's no requirement for the number of digit but please ensure that the date a **TIPS**: Always list all the task before deleting and marking/unmarking. +--- +##Demo +````text +Hello! I'm Duke :P +What can I do for you? +------------------------------------- +list +The list is empty currently ( ̄3 ̄)a +------------------------------------- +deadline CS2113 Quiz /by 2019/06/20 23:59 +ψ(._. )> Got it. I've added this task: +[D][ ]CS2113 Quiz (by: Jun. 20 2019 23:59) +Now you have 1 tasks in your list. +------------------------------------- +event MA2101 Quiz /at 2019-6-30 +ψ(._. )> Got it. I've added this task: +[E][ ]MA2101 Quiz (at: Jun. 30 2019) +Now you have 2 tasks in your list. +------------------------------------- +todo Homework +ψ(._. )> Got it. I've added this task: +[T][ ]Homework +Now you have 3 tasks in your list. +------------------------------------- +list +o(≧v≦)o Here are the tasks in your list: +1. [D][ ]CS2113 Quiz (by: Jun. 20 2019 23:59) +2. [E][ ]MA2101 Quiz (at: Jun. 30 2019) +3. [T][ ]Homework +------------------------------------- +mark 1 +ψ(._. )> Nice! I've marked this task as done: +[D][X]CS2113 Quiz (by: Jun. 20 2019 23:59) +------------------------------------- +mark 2 +ψ(._. )> Nice! I've marked this task as done: +[E][X]MA2101 Quiz (at: Jun. 30 2019) +------------------------------------- +list +o(≧v≦)o Here are the tasks in your list: +1. [D][X]CS2113 Quiz (by: Jun. 20 2019 23:59) +2. [E][X]MA2101 Quiz (at: Jun. 30 2019) +3. [T][ ]Homework +------------------------------------- +unmark 2 +ψ(._. )> OK, I've marked this task as not done yet: +[E][ ]MA2101 Quiz (at: Jun. 30 2019) +------------------------------------- +list +o(≧v≦)o Here are the tasks in your list: +1. [D][X]CS2113 Quiz (by: Jun. 20 2019 23:59) +2. [E][ ]MA2101 Quiz (at: Jun. 30 2019) +3. [T][ ]Homework +------------------------------------- +find Quiz +o(≧v≦)o Here are the matching tasks in your list: +1. [D][X]CS2113 Quiz (by: Jun. 20 2019 23:59) +2. [E][ ]MA2101 Quiz (at: Jun. 30 2019) +------------------------------------- +deadline CS2106 midterm /at 2019-4-31 +The format is incorrect! Can you please check your input again? ●ω● +------------------------------------- +deadline CS2106 midterm /by 2019-4-31 +The time format is incorrect! Can you please check your input again? ( ̄~ ̄;) You can check the manual to find out acceptable time format! +------------------------------------- +deadline CS2106 midterm /by 2019-4-30 25:61 +The time format is incorrect! Can you please check your input again? ( ̄~ ̄;) You can check the manual to find out acceptable time format! +------------------------------------- +deadline CS2106 midterm /by 2019-4-30 2:3 +ψ(._. )> Got it. I've added this task: +[D][ ]CS2106 midterm (by: Apr. 30 2019 02:03) +Now you have 4 tasks in your list. +------------------------------------- +list +o(≧v≦)o Here are the tasks in your list: +1. [D][ ]CS2113 Quiz (by: Jun. 20 2019 23:59) +2. [E][ ]MA2101 Quiz (at: Jun. 30 2019) +3. [T][ ]Homework +4. [D][ ]CS2106 midterm (by: Apr. 30 2019 02:03) +------------------------------------- +delete 4 +ψ(._. )> Okay! I've deleted this task: +[D][ ]CS2106 midterm (by: Apr. 30 2019 02:03) +Now you have 3 tasks in your list. +------------------------------------- +Bye. Hope to see you again soon! ;) +------------------------------------- +```` \ No newline at end of file diff --git a/src/main/java/controller/Command.java b/src/main/java/controller/Command.java index 341aeb5a0..399c60266 100644 --- a/src/main/java/controller/Command.java +++ b/src/main/java/controller/Command.java @@ -13,6 +13,9 @@ public class Command { protected static final String ADD_TODO = "todo"; protected static final String UPDATE = "update"; protected static final String SEARCH = "find"; + protected static final String EVENT = "event "; + protected static final String TODO = "todo "; + protected static final String DEADLINE = "deadline "; protected String taskName; protected String dateString; protected String rawInput; @@ -37,13 +40,13 @@ public Command(String[] parsedInput, String rawInput) { public void decomposeInstruction(String instruction) throws DukeExceptions { switch (instruction) { case ADD_EVENT: - decomposeAddWithTime("/at "); + decomposeAddWithTime("/at ", EVENT); break; case ADD_DEADLINE: - decomposeAddWithTime("/by "); + decomposeAddWithTime("/by ", DEADLINE); break; case ADD_TODO: - decomposeAddWithoutTime(); + decomposeAddWithoutTime(TODO); break; case SEARCH: decomposeSearchByDescription(); @@ -62,14 +65,15 @@ public void decomposeInstruction(String instruction) throws DukeExceptions { * @param regex the keyword for decomposition. For adding event, * the regex is "/at ", and for adding deadline, the * regex is "/by" + * @param taskType the type of task that need to be added * @throws DukeExceptions if the task name is loss, wrong instruction * formatting or wrong time formatting */ - public void decomposeAddWithTime(String regex) throws DukeExceptions { + public void decomposeAddWithTime(String regex, String taskType) throws DukeExceptions { String[] parsedInputByTime; parsedInputByTime = rawInput.split(regex); try { - this.taskName = this.parsedInput[1]; + this.taskName = parsedInputByTime[0].replace(taskType, ""); } catch (Exception e) { throw new TaskNameLossException(); } @@ -101,11 +105,12 @@ public void decomposeSearchByDescription() throws DukeExceptions { /** * Decomposes decompose the instruction of adding task without time + * @param taskType the type of task that is going to be added * @throws DukeExceptions if the task name is loss */ - public void decomposeAddWithoutTime() throws DukeExceptions { + public void decomposeAddWithoutTime(String taskType) throws DukeExceptions { try { - this.taskName = this.parsedInput[1]; + this.taskName = this.rawInput.replace(taskType, ""); } catch (Exception e) { throw new TaskNameLossException(); } diff --git a/src/main/java/tasks/Storage.java b/src/main/java/tasks/Storage.java index 6e1972b27..20a737aa5 100644 --- a/src/main/java/tasks/Storage.java +++ b/src/main/java/tasks/Storage.java @@ -17,7 +17,7 @@ public class Storage { protected static final String DONE = "X"; protected static final String TODO = "T"; protected static final String EVENT = "E"; - protected static final String DEADLINE = "d"; + protected static final String DEADLINE = "D"; private static final ArrayList Tasks = new ArrayList<>(); private Time timeChecker; @@ -104,6 +104,7 @@ public void loadTask() throws DukeExceptions { importTask(keyInfo); } } catch (Exception e) { + e.printStackTrace(); throw new IllegalReadingAction(); } diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 0d49ec714..8113a1947 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,43 +1,67 @@ Hello! I'm Duke :P What can I do for you? ------------------------------------- -Sorry, there's no task in the list :( +The list is empty currently ( ̄3 ̄)a ------------------------------------- -Got it. I've added this task: -[D][ ]CS2113 Quiz (by: Friday 4pm) +ψ(._. )> Got it. I've added this task: +[D][ ]CS2113 Quiz (by: Jun. 20 2019 23:59) Now you have 1 tasks in your list. ------------------------------------- -Got it. I've added this task: -[E][ ]MA2101 Quiz (at: Feb 15th) +ψ(._. )> Got it. I've added this task: +[E][ ]MA2101 Quiz (at: Jun. 30 2019) Now you have 2 tasks in your list. ------------------------------------- -Got it. I've added this task: +ψ(._. )> Got it. I've added this task: [T][ ]Homework Now you have 3 tasks in your list. ------------------------------------- -Here are the tasks in your list: -1. [D][ ]CS2113 Quiz (by: Friday 4pm) -2. [E][ ]MA2101 Quiz (at: Feb 15th) +o(≧v≦)o Here are the tasks in your list: +1. [D][ ]CS2113 Quiz (by: Jun. 20 2019 23:59) +2. [E][ ]MA2101 Quiz (at: Jun. 30 2019) 3. [T][ ]Homework ------------------------------------- -Nice! I've marked this task as done: -[D][X]CS2113 Quiz (by: Friday 4pm) +ψ(._. )> Nice! I've marked this task as done: +[D][X]CS2113 Quiz (by: Jun. 20 2019 23:59) ------------------------------------- -Nice! I've marked this task as done: -[E][X]MA2101 Quiz (at: Feb 15th) +ψ(._. )> Nice! I've marked this task as done: +[E][X]MA2101 Quiz (at: Jun. 30 2019) ------------------------------------- -Here are the tasks in your list: -1. [D][X]CS2113 Quiz (by: Friday 4pm) -2. [E][X]MA2101 Quiz (at: Feb 15th) +o(≧v≦)o Here are the tasks in your list: +1. [D][X]CS2113 Quiz (by: Jun. 20 2019 23:59) +2. [E][X]MA2101 Quiz (at: Jun. 30 2019) 3. [T][ ]Homework ------------------------------------- -OK, I've marked this task as not done yet: -[E][ ]MA2101 Quiz (at: Feb 15th) +ψ(._. )> OK, I've marked this task as not done yet: +[E][ ]MA2101 Quiz (at: Jun. 30 2019) ------------------------------------- -Here are the tasks in your list: -1. [D][ ]CS2113 Quiz (by: Friday 4pm) -2. [E][ ]MA2101 Quiz (at: Feb 15th) +o(≧v≦)o Here are the tasks in your list: +1. [D][X]CS2113 Quiz (by: Jun. 20 2019 23:59) +2. [E][ ]MA2101 Quiz (at: Jun. 30 2019) 3. [T][ ]Homework ------------------------------------- +o(≧v≦)o Here are the matching tasks in your list: +1. [D][X]CS2113 Quiz (by: Jun. 20 2019 23:59) +2. [E][ ]MA2101 Quiz (at: Jun. 30 2019) +------------------------------------- +The format is incorrect! Can you please check your input again? ●ω● +------------------------------------- +The time format is incorrect! Can you please check your input again? ( ̄~ ̄;) You can check the manual to find out acceptable time format! +------------------------------------- +The time format is incorrect! Can you please check your input again? ( ̄~ ̄;) You can check the manual to find out acceptable time format! +------------------------------------- +ψ(._. )> Got it. I've added this task: +[D][ ]CS2106 midterm (by: Apr. 30 2019 02:03) +Now you have 4 tasks in your list. +------------------------------------- +o(≧v≦)o Here are the tasks in your list: +1. [D][ ]CS2113 Quiz (by: Jun. 20 2019 23:59) +2. [E][ ]MA2101 Quiz (at: Jun. 30 2019) +3. [T][ ]Homework +4. [D][ ]CS2106 midterm (by: Apr. 30 2019 02:03) +------------------------------------- +ψ(._. )> Okay! I've deleted this task: +[D][ ]CS2106 midterm (by: Apr. 30 2019 02:03) +Now you have 3 tasks in your list. +------------------------------------- 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 73b522e51..e7f29b2f3 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -1,6 +1,6 @@ list -deadline CS2113 Quiz /by Friday 4pm -event MA2101 Quiz /at Feb 15th +deadline CS2113 Quiz /by 2019/06/20 23:59 +event MA2101 Quiz /at 2019-6-30 todo Homework list mark 1 @@ -8,4 +8,9 @@ mark 2 list unmark 2 list +find Quiz +deadline CS2106 midterm /at 2019-4-31 +deadline CS2106 midterm /by 2019-4-31 +deadline CS2106 midterm /by 2019-4-30 25:61 +deadline CS2106 midterm /by 2019-4-30 2:3 bye \ No newline at end of file From 8b6fa7b5d22e3712cedfbe0c8311f761c34d49a8 Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Fri, 4 Mar 2022 17:08:56 +0800 Subject: [PATCH 40/45] fix error in ug --- README.md | 1 + docs/README.md | 1 + 2 files changed, 2 insertions(+) diff --git a/README.md b/README.md index 0f82f781d..ca36ba26c 100644 --- a/README.md +++ b/README.md @@ -401,6 +401,7 @@ delete 4 [D][ ]CS2106 midterm (by: Apr. 30 2019 02:03) Now you have 3 tasks in your list. ------------------------------------- +bye Bye. Hope to see you again soon! ;) ------------------------------------- ```` \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index a84f0e70f..964208b0a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -403,6 +403,7 @@ delete 4 [D][ ]CS2106 midterm (by: Apr. 30 2019 02:03) Now you have 3 tasks in your list. ------------------------------------- +bye Bye. Hope to see you again soon! ;) ------------------------------------- ```` \ No newline at end of file From c24141d051590ac27f8fa343850145db13a04ea7 Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Fri, 4 Mar 2022 17:28:14 +0800 Subject: [PATCH 41/45] fix error in ug --- README.md | 48 ++++++++++++++++++++++++++++++++++++------------ docs/README.md | 48 ++++++++++++++++++++++++++++++++++++------------ 2 files changed, 72 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index ca36ba26c..7a3d811cf 100644 --- a/README.md +++ b/README.md @@ -276,17 +276,41 @@ Duke only supports to find matching task according to the keyword and task name. --- ## Command Summary -| **Command Type** | Command Format | -|:-----------------|:---------------------------------------| -| **add todo** | `todo ` | -| **add event** | `event /at ` | -| **add deadline** | `deadline /by ` | -| **mark** | `mark ` | -| **unmark** | `unmark ` | -| **find** | `find ` | -| **delete** | `delete ` | -| **list** | `list` | -| **exit** | `bye` | +**add todo** + +`todo ` + +**add event** + +`event /at ` + +**add deadline** + +`deadline /by ` + +**mark** + +`mark ` + +**unmark** + +`unmark ` + +**find** + +`find ` + +**delete** + +`delete ` + +**list** + +`list` + +**exit** + +`bye` --- @@ -317,7 +341,7 @@ There's no requirement for the number of digit but please ensure that the date a **TIPS**: Always list all the task before deleting and marking/unmarking. -##Demo +## Demo ````text Hello! I'm Duke :P What can I do for you? diff --git a/docs/README.md b/docs/README.md index 964208b0a..ef0d941d3 100644 --- a/docs/README.md +++ b/docs/README.md @@ -277,17 +277,41 @@ Duke only supports to find matching task according to the keyword and task name. --- ## Command Summary -| **Command Type** | Command Format | -|:-----------------|:---------------------------------------| -| **add todo** | `todo ` | -| **add event** | `event /at ` | -| **add deadline** | `deadline /by ` | -| **mark** | `mark ` | -| **unmark** | `unmark ` | -| **find** | `find ` | -| **delete** | `delete ` | -| **list** | `list` | -| **exit** | `bye` | +**add todo** + +`todo ` + +**add event** + +`event /at ` + +**add deadline** + +`deadline /by ` + +**mark** + +`mark ` + +**unmark** + +`unmark ` + +**find** + +`find ` + +**delete** + +`delete ` + +**list** + +`list` + +**exit** + +`bye` --- @@ -319,7 +343,7 @@ There's no requirement for the number of digit but please ensure that the date a **TIPS**: Always list all the task before deleting and marking/unmarking. --- -##Demo +## Demo ````text Hello! I'm Duke :P What can I do for you? From 0887a113108f1e3610cd789e1d78e5d9ed8e177c Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Fri, 4 Mar 2022 20:41:52 +0800 Subject: [PATCH 42/45] Update Javadoc --- src/main/java/Duke.java | 8 +++++++- src/main/java/META-INF/MANIFEST.MF | 3 +++ src/main/java/UI/Chatbox.java | 3 +++ src/main/java/UI/UI.java | 3 +++ src/main/java/time/DateFormatChecker.java | 4 +++- src/main/java/time/DateTimeFormatChecker.java | 3 +++ 6 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 src/main/java/META-INF/MANIFEST.MF diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 1b7a8ffd4..8b678f98e 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,12 +1,18 @@ import controller.Controller; public class Duke { + /** + * Run program + * @param args input from user + * @throws Exception if there's any unacceptable condition + */ public static void main(String[] args) throws Exception { Controller bot = new Controller(); bot.greet(); bot.createFile(); bot.loadTask(); - while(true){//opens a new session for receiving instruction + while (true) { + //opens a new session for receiving instruction bot.listen(); } } diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 000000000..d2ffd5b4d --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: Duke + diff --git a/src/main/java/UI/Chatbox.java b/src/main/java/UI/Chatbox.java index 30fcd6a65..5cc92230d 100644 --- a/src/main/java/UI/Chatbox.java +++ b/src/main/java/UI/Chatbox.java @@ -1,5 +1,8 @@ package UI; +/** + * Create a chatbox for each message + */ public class Chatbox { //border of the chatbox protected static final String HORIZON_LINE = "-------------------------------------"; diff --git a/src/main/java/UI/UI.java b/src/main/java/UI/UI.java index f9449e9c7..6594c61c5 100644 --- a/src/main/java/UI/UI.java +++ b/src/main/java/UI/UI.java @@ -1,5 +1,8 @@ package UI; +/** + * Create a UI for displaying message + */ public class UI { protected static final String HELLO_WORDS = "Hello! I'm Duke :P\nWhat can I do for you?"; protected static final String GOODBYE_WORDS = "Bye. Hope to see you again soon! ;)"; diff --git a/src/main/java/time/DateFormatChecker.java b/src/main/java/time/DateFormatChecker.java index ae563c227..f4fab5b46 100644 --- a/src/main/java/time/DateFormatChecker.java +++ b/src/main/java/time/DateFormatChecker.java @@ -5,7 +5,9 @@ import java.util.Arrays; import java.util.List; - +/** + * Check the format of the input date and convert to standart format date string + */ public class DateFormatChecker extends Time { //Standard format for printing task information private static final SimpleDateFormat stdFormatter = new SimpleDateFormat("MMM dd yyyy"); diff --git a/src/main/java/time/DateTimeFormatChecker.java b/src/main/java/time/DateTimeFormatChecker.java index aa76ef742..64195c513 100644 --- a/src/main/java/time/DateTimeFormatChecker.java +++ b/src/main/java/time/DateTimeFormatChecker.java @@ -5,6 +5,9 @@ import java.util.Arrays; import java.util.List; +/** + * Check the format of the input date and time and convert to standart format date string + */ public class DateTimeFormatChecker extends Time { private static final List formatStrings = Arrays.asList("M/d/y H:m", "M/d/y H", "M-d-y H:m", "y-M-d H:m", "y/M/d H:m", "MMM dd yyyy H:m", From f85d95d132b3e8458827c2bc76b179c34be34efc Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Fri, 4 Mar 2022 22:03:43 +0800 Subject: [PATCH 43/45] update ug --- README.md | 4 ++-- docs/README.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7a3d811cf..1dc652b1d 100644 --- a/README.md +++ b/README.md @@ -46,8 +46,8 @@ Prerequisite: JDK 11 OpenJDK 64-Bit Server VM Corretto-11.0.13.8.1 (build 11.0.13+8-LTS, mixed mode) ```` 2. Download the latest release. You can use command to download it or simply download it from the website: - ```` - https://github.com/hlwang56/ip/releases + ````shell + https://github.com/hlwang56/ip/releases/download/v2.0/ip.jar ```` 3. Open a terminal in the folder when the jar file is placed and run following command ````shell diff --git a/docs/README.md b/docs/README.md index ef0d941d3..9b998b694 100644 --- a/docs/README.md +++ b/docs/README.md @@ -48,7 +48,7 @@ Prerequisite: JDK 11 ```` 2. Download the latest release. You can use command to download it or simply download it from the website: ````shell - https://github.com/hlwang56/ip/releases + https://github.com/hlwang56/ip/releases/download/v2.0/ip.jar ```` 3. Open a terminal in the folder when the jar file is placed and run following command ````shell From 8ba4df2367d89509c47f0c39baa9438ea03be746 Mon Sep 17 00:00:00 2001 From: hlwang56 Date: Fri, 4 Mar 2022 23:58:42 +0800 Subject: [PATCH 44/45] fix bugs --- data/duke.txt | 1 + src/main/java/tasks/Storage.java | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/data/duke.txt b/data/duke.txt index e69de29bb..d116fb41e 100644 --- a/data/duke.txt +++ b/data/duke.txt @@ -0,0 +1 @@ +[T][X]j diff --git a/src/main/java/tasks/Storage.java b/src/main/java/tasks/Storage.java index 20a737aa5..9dfffd1a7 100644 --- a/src/main/java/tasks/Storage.java +++ b/src/main/java/tasks/Storage.java @@ -20,6 +20,7 @@ public class Storage { protected static final String DEADLINE = "D"; private static final ArrayList Tasks = new ArrayList<>(); private Time timeChecker; + private TaskManager manager; public int getSize() { return Tasks.size(); @@ -85,7 +86,7 @@ public String[] parseInput(String listName) { */ public void mark(Task task, String status) { if (status.equals(DONE)) { - task.isDone = true; + task.mark(); } } @@ -144,8 +145,8 @@ private void importDeadline(String[] keyInfo) throws DukeExceptions { timeChecker.check(); newTimeString = timeChecker.getDateString(); Deadline newDeadline = new Deadline(keyInfo[2], newTimeString); - mark(newDeadline, keyInfo[2]); Tasks.add(newDeadline); + mark(newDeadline, keyInfo[1]); } /** @@ -161,8 +162,8 @@ private void importEvent(String[] keyInfo) throws DukeExceptions { timeChecker.check(); newTimeString = timeChecker.getDateString(); Event newEvent = new Event(keyInfo[2], newTimeString); - mark(newEvent, keyInfo[2]); Tasks.add(newEvent); + mark(newEvent, keyInfo[1]); } /** @@ -171,8 +172,8 @@ private void importEvent(String[] keyInfo) throws DukeExceptions { */ private void importTodoTask(String[] keyInfo) { ToDo newToDo = new ToDo(keyInfo[2]); - mark(newToDo, keyInfo[2]); Tasks.add(newToDo); + mark(newToDo, keyInfo[1]); } /** From d15930f4e41b4054a36d0ab04f8c97270d603f54 Mon Sep 17 00:00:00 2001 From: hlwang56 <69446689+hlwang56@users.noreply.github.com> Date: Sun, 6 Mar 2022 21:06:53 +0800 Subject: [PATCH 45/45] Update README.md --- docs/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/README.md b/docs/README.md index 9b998b694..b8dd57ea7 100644 --- a/docs/README.md +++ b/docs/README.md @@ -38,7 +38,7 @@ Duke is a flexible command line based task manager that helps you to manage your Prerequisite: JDK 11 1. Please ensure that JDK 11 is installed before running Duke. You can check it in terminal by typing ````shell - java -v + java -version ```` and you should see something similar as following: ````shell @@ -50,7 +50,7 @@ Prerequisite: JDK 11 ````shell https://github.com/hlwang56/ip/releases/download/v2.0/ip.jar ```` -3. Open a terminal in the folder when the jar file is placed and run following command +3. Open a terminal in the folder where the jar file is placed and run following command ````shell java -jar ip.jar ```` @@ -430,4 +430,4 @@ Now you have 3 tasks in your list. bye Bye. Hope to see you again soon! ;) ------------------------------------- -```` \ No newline at end of file +````