From a4564e4f57e952f108d309d08b125152f9243679 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Mon, 4 Sep 2023 18:57:08 +0800 Subject: [PATCH 01/77] rename "Duke" to "Luke", and added greetings --- src/main/java/Duke.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5d313334c..608e9e96f 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,10 +1,17 @@ public class Duke { public static void main(String[] args) { - String logo = " ____ _ \n" + /* String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" + "| | | | | | | |/ / _ \\\n" + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); + + "|____/ \\__,_|_|\\_\\___|\n"; */ + String logo = " _ _ \n" + + "| | _ _| | _____ \n" + + "| | | | | | |/ / _ \\\n" + + "| |___| |_| | < __/\n" + + "|_____|\\__,_|_|\\_\\___|\n"; + System.out.println("Hello! I'm\n" + logo); + System.out.println("What can I do for you?"); + System.out.println("Bye. Hope to see you again soon!"); } } From 860d8788728b2d3dabc1f8e7636e765eaccda6c3 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Mon, 4 Sep 2023 21:58:48 +0800 Subject: [PATCH 02/77] add echo feature --- src/main/java/Duke.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 608e9e96f..456c1b080 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,10 +1,7 @@ +import java.util.Scanner; + public class Duke { public static void main(String[] args) { - /* String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; */ String logo = " _ _ \n" + "| | _ _| | _____ \n" + "| | | | | | |/ / _ \\\n" @@ -12,6 +9,17 @@ public static void main(String[] args) { + "|_____|\\__,_|_|\\_\\___|\n"; System.out.println("Hello! I'm\n" + logo); System.out.println("What can I do for you?"); + + Scanner in = new Scanner(System.in); + + String echo = in.nextLine(); + while (!echo.equals("bye")) { + System.out.println(echo); + echo = in.nextLine(); + } + System.out.println("Bye. Hope to see you again soon!"); + + in.close(); } } From 35b72fcb51bd055676b7de8755d68a1fd6f86246 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Tue, 5 Sep 2023 22:15:53 +0800 Subject: [PATCH 03/77] add features (add, list but reverse) --- src/main/java/Duke.java | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 456c1b080..7d3f90613 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -10,12 +10,30 @@ public static void main(String[] args) { System.out.println("Hello! I'm\n" + logo); System.out.println("What can I do for you?"); + String[] theList = new String[100]; Scanner in = new Scanner(System.in); + int i = 0; String echo = in.nextLine(); while (!echo.equals("bye")) { - System.out.println(echo); + if (echo.equals("list")) { + //theList[i] is the oldest String, start printing from theList[i - 1] + int k = i - 1; + for (int j = 1; theList[k] != null && j <= 100; j += 1) { + System.out.println(j + ". " + theList[k]); + k -= 1; + if (k < 0) { + k += 100; + } + } + } + theList[i] = echo; + System.out.println("added: " + echo); echo = in.nextLine(); + i += 1; + if (i >= 100) { + i = 0; + } } System.out.println("Bye. Hope to see you again soon!"); From 5fc8ba6f5f76778df0cb83d3efeb1684a31d027d Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Tue, 5 Sep 2023 22:31:39 +0800 Subject: [PATCH 04/77] amend features (add, list) --- src/main/java/Duke.java | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 7d3f90613..1b53706be 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -17,23 +17,15 @@ public static void main(String[] args) { String echo = in.nextLine(); while (!echo.equals("bye")) { if (echo.equals("list")) { - //theList[i] is the oldest String, start printing from theList[i - 1] - int k = i - 1; - for (int j = 1; theList[k] != null && j <= 100; j += 1) { - System.out.println(j + ". " + theList[k]); - k -= 1; - if (k < 0) { - k += 100; - } + for (int j = 0; j < i; j += 1) { + System.out.println((j + 1) + ". " + theList[j]); } + } else { + theList[i] = echo; + System.out.println("added: " + echo); + i += 1; } - theList[i] = echo; - System.out.println("added: " + echo); echo = in.nextLine(); - i += 1; - if (i >= 100) { - i = 0; - } } System.out.println("Bye. Hope to see you again soon!"); From 8e0282308b1369693157aed36676b840eaf6547f Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Tue, 5 Sep 2023 23:32:47 +0800 Subject: [PATCH 05/77] add feature (mark as done) --- src/main/java/Duke.java | 20 +++++++++++++++++--- src/main/java/Task.java | 27 +++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 src/main/java/Task.java diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 1b53706be..cbfd2072c 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -10,18 +10,32 @@ public static void main(String[] args) { System.out.println("Hello! I'm\n" + logo); System.out.println("What can I do for you?"); - String[] theList = new String[100]; + Task[] theList = new Task[100]; Scanner in = new Scanner(System.in); int i = 0; String echo = in.nextLine(); + while (!echo.equals("bye")) { + String[] words = echo.split(" "); //to identify usage of features "mark" & "unmark" if (echo.equals("list")) { + System.out.println("Here are the tasks in your list:"); for (int j = 0; j < i; j += 1) { - System.out.println((j + 1) + ". " + theList[j]); + System.out.print((j + 1) + "."); + theList[j].printTask(); } + } else if (words[0].equals("mark")) { + int taskNumber = Integer.parseInt(words[1]) - 1; + System.out.println("Woohoo! You have accomplished:"); + theList[taskNumber].markAsDone(); + theList[taskNumber].printTask(); + } else if (words[0].equals("unmark")) { + int taskNumber = Integer.parseInt(words[1]) - 1; + System.out.println("HA! You still have to complete:"); + theList[taskNumber].markAsIncomplete(); + theList[taskNumber].printTask(); } else { - theList[i] = echo; + theList[i] = new Task(echo); System.out.println("added: " + echo); i += 1; } diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 000000000..f6f7248d1 --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,27 @@ +public class Task { + protected String taskName; + protected boolean isDone; + + public Task(String taskName) { + this.taskName = taskName; + this.isDone = false; + } + + public void printTask() { + System.out.println("[" + getStatusIcon() + "] " + taskName); + } + + public String getStatusIcon() { + return (isDone ? "X" : " "); // mark done task with X + } + + public void markAsDone() { + isDone = true; + } + + public void markAsIncomplete() { + isDone = false; + } + + //... +} From 6b19f57edf777d2730d2613e88f25968f06b3efe Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Tue, 5 Sep 2023 23:44:29 +0800 Subject: [PATCH 06/77] tweaks to follow naming conventions --- src/main/java/Duke.java | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index cbfd2072c..5b5a99e20 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -11,39 +11,44 @@ public static void main(String[] args) { System.out.println("What can I do for you?"); Task[] theList = new Task[100]; - Scanner in = new Scanner(System.in); - int i = 0; + Scanner userInput = new Scanner(System.in); + int counter = 0; - String echo = in.nextLine(); + String echo = userInput.nextLine(); while (!echo.equals("bye")) { String[] words = echo.split(" "); //to identify usage of features "mark" & "unmark" + if (echo.equals("list")) { System.out.println("Here are the tasks in your list:"); - for (int j = 0; j < i; j += 1) { - System.out.print((j + 1) + "."); - theList[j].printTask(); + for (int i = 0; i < counter; i += 1) { + System.out.print((i + 1) + "."); + theList[i].printTask(); } + } else if (words[0].equals("mark")) { int taskNumber = Integer.parseInt(words[1]) - 1; System.out.println("Woohoo! You have accomplished:"); theList[taskNumber].markAsDone(); theList[taskNumber].printTask(); + } else if (words[0].equals("unmark")) { int taskNumber = Integer.parseInt(words[1]) - 1; System.out.println("HA! You still have to complete:"); theList[taskNumber].markAsIncomplete(); theList[taskNumber].printTask(); + } else { - theList[i] = new Task(echo); + theList[counter] = new Task(echo); System.out.println("added: " + echo); - i += 1; + counter += 1; } - echo = in.nextLine(); + + echo = userInput.nextLine(); } System.out.println("Bye. Hope to see you again soon!"); - - in.close(); + + userInput.close(); } } From aebc096bf7c74560045d22ad57b75ebb80ec02d9 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Fri, 8 Sep 2023 00:39:29 +0800 Subject: [PATCH 07/77] Added three different task types (ToDos, Events, Deadlines) --- src/main/java/Deadline.java | 31 ++++++++++++++ src/main/java/Duke.java | 84 ++++++++++++++++++++++++++----------- src/main/java/Event.java | 46 ++++++++++++++++++++ src/main/java/Task.java | 29 ++++++------- src/main/java/Todo.java | 31 ++++++++++++++ 5 files changed, 183 insertions(+), 38 deletions(-) create mode 100644 src/main/java/Deadline.java create mode 100644 src/main/java/Event.java create mode 100644 src/main/java/Todo.java diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java new file mode 100644 index 000000000..eb19cbab4 --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,31 @@ +public class Deadline extends Todo { + protected String byDate; + + public Deadline(String description, String date) { + super(description); + int spaceCut = date.indexOf(" "); + byDate = date.substring(spaceCut + 1); + } + + public String getByDate() { + return byDate; + } + + public void setByDate(String byDate) { + this.byDate = byDate; + } + + @Override + public String toString() { + super.toString(); + String isDoneString; + + if (isDone()) { + isDoneString = "[X]"; + } else { + isDoneString = "[ ]"; + } + + return "[D]" + isDoneString + description + "(do by: " + byDate + ")"; + } +} diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5b5a99e20..e92a43e29 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -15,35 +15,71 @@ public static void main(String[] args) { int counter = 0; String echo = userInput.nextLine(); + int taskNumber; while (!echo.equals("bye")) { String[] words = echo.split(" "); //to identify usage of features "mark" & "unmark" - if (echo.equals("list")) { - System.out.println("Here are the tasks in your list:"); - for (int i = 0; i < counter; i += 1) { - System.out.print((i + 1) + "."); - theList[i].printTask(); - } - - } else if (words[0].equals("mark")) { - int taskNumber = Integer.parseInt(words[1]) - 1; - System.out.println("Woohoo! You have accomplished:"); - theList[taskNumber].markAsDone(); - theList[taskNumber].printTask(); - - } else if (words[0].equals("unmark")) { - int taskNumber = Integer.parseInt(words[1]) - 1; - System.out.println("HA! You still have to complete:"); - theList[taskNumber].markAsIncomplete(); - theList[taskNumber].printTask(); - - } else { - theList[counter] = new Task(echo); - System.out.println("added: " + echo); - counter += 1; - } + switch (words[0]) { + case "list": + System.out.println("Here are the tasks in your list:"); + for (int i = 0; i < counter; i += 1) { + System.out.print((i + 1) + "."); + System.out.println(theList[i]); + } + break; + case "mark": + taskNumber = Integer.parseInt(words[1]) - 1; + System.out.println("Woohoo! You have accomplished:"); + theList[taskNumber].setDone(true); + System.out.println(theList[taskNumber]); + break; + case "unmark": + taskNumber = Integer.parseInt(words[1]) - 1; + System.out.println("HA! You still have to complete:"); + theList[taskNumber].setDone(false); + System.out.println(theList[taskNumber]); + break; + default: + int spaceCut = echo.indexOf(" "); + String taskType = echo.substring(0, spaceCut); + String taskDescription = echo.substring(spaceCut); + int slashCut = taskDescription.indexOf("/"); + + //TaskType type = TaskType.words[0]; + + switch (taskType) { + case "todo": + theList[counter] = new Todo(taskDescription); + System.out.println("Got it. I've added this task:"); + System.out.println(theList[counter]); + counter += 1; + System.out.println("Now you have " + counter + " tasks in the list."); + break; + case "deadline": + String taskDeadline = taskDescription.substring(slashCut); + taskDescription = taskDescription.substring(0, slashCut); + theList[counter] = new Deadline(taskDescription, taskDeadline); + System.out.println("Got it. I've added this task:"); + System.out.println(theList[counter]); + counter += 1; + System.out.println("Now you have " + counter + " tasks in the list."); + break; + case "event": + String taskDuration = taskDescription.substring(slashCut); + taskDescription = taskDescription.substring(0, slashCut); + + theList[counter] = new Event(taskDescription, taskDuration); + System.out.println("Got it. I've added this task:"); + System.out.println(theList[counter]); + counter += 1; + System.out.println("Now you have " + counter + " tasks in the list."); + break; + default: + break; + } + } echo = userInput.nextLine(); } diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 000000000..dd014f189 --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,46 @@ +public class Event extends Deadline { + protected String startDate; + protected String endDate; +//event project meeting /from Mon 2pm /to 4pm + public Event(String description, String dates) { + super(description, dates); + + int spaceCut = dates.indexOf(" "); + dates = dates.substring(spaceCut + 1); + + int slashCut = dates.indexOf("/"); + startDate = dates.substring(0, slashCut); + dates = dates.substring(slashCut + 1); + + spaceCut = dates.indexOf(" "); + endDate = dates.substring(spaceCut + 1); +/* + int spaceCut = taskDeadline.indexOf(" "); + taskDeadline = taskDeadline.substring(spaceCut + 1); + //this.dates = dates; + + */ + } + + public String getBy() { + return startDate; + } + + public void setBy(String by) { + this.startDate = by; + } + + @Override + public String toString() { + super.toString(); + String isDoneString; + + if (isDone()) { + isDoneString = "[X]"; + } else { + isDoneString = "[ ]"; + } + + return "[E]" + isDoneString + description + "(from: " + startDate + "to: " + endDate + ")"; + } +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java index f6f7248d1..c35540eb1 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -1,27 +1,28 @@ public class Task { - protected String taskName; + protected String description; protected boolean isDone; - public Task(String taskName) { - this.taskName = taskName; - this.isDone = false; + public Task(String description) { + this.description = description; + isDone = false; } - public void printTask() { - System.out.println("[" + getStatusIcon() + "] " + taskName); + public String getDescription() { + return description; } - public String getStatusIcon() { - return (isDone ? "X" : " "); // mark done task with X + + public boolean isDone() { + return isDone; } - public void markAsDone() { - isDone = true; + public void setDone(boolean done) { + isDone = done; } - public void markAsIncomplete() { - isDone = false; + @Override + public String toString() { + return ""; } - //... -} +} \ No newline at end of file diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java new file mode 100644 index 000000000..00103ab42 --- /dev/null +++ b/src/main/java/Todo.java @@ -0,0 +1,31 @@ +public class Todo extends Task { + //protected boolean isDone; + + public Todo(String description) { + super(description); + //isDone = false; + } +/* + public boolean isDone() { + return isDone; + } + + public void setDone(boolean done) { + isDone = done; + } +*/ + + @Override + public String toString() { + super.toString(); + String isDoneString; + + if (isDone()) { + isDoneString = "[X]"; + } else { + isDoneString = "[ ]"; + } + + return "[T]" + isDoneString + description; + } +} From 17570b2ac876d00293a5ad4848fa7f688e8629b0 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Fri, 8 Sep 2023 00:46:47 +0800 Subject: [PATCH 08/77] Added three different task types (ToDos, Events, Deadlines) --- src/main/java/Deadline.java | 12 ++++++------ src/main/java/Event.java | 29 +++++++++++++---------------- src/main/java/TaskType.java | 3 +++ src/main/java/Todo.java | 11 +---------- 4 files changed, 23 insertions(+), 32 deletions(-) create mode 100644 src/main/java/TaskType.java diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index eb19cbab4..640e39a2a 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -3,21 +3,21 @@ public class Deadline extends Todo { public Deadline(String description, String date) { super(description); - int spaceCut = date.indexOf(" "); - byDate = date.substring(spaceCut + 1); + setByDate(date); } public String getByDate() { return byDate; } - public void setByDate(String byDate) { - this.byDate = byDate; + public void setByDate(String date) { + int spaceCut = date.indexOf(" "); + byDate = date.substring(spaceCut + 1); } @Override public String toString() { - super.toString(); + //super.toString(); String isDoneString; if (isDone()) { @@ -26,6 +26,6 @@ public String toString() { isDoneString = "[ ]"; } - return "[D]" + isDoneString + description + "(do by: " + byDate + ")"; + return "[D]" + isDoneString + description + "(do by: " + getByDate() + ")"; } } diff --git a/src/main/java/Event.java b/src/main/java/Event.java index dd014f189..4a2d32e9b 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -4,7 +4,18 @@ public class Event extends Deadline { //event project meeting /from Mon 2pm /to 4pm public Event(String description, String dates) { super(description, dates); + setDates(dates); + } + + public String getStartDate() { + return startDate; + } + + public String getEndDate() { + return endDate; + } + public void setDates(String dates) { int spaceCut = dates.indexOf(" "); dates = dates.substring(spaceCut + 1); @@ -14,25 +25,11 @@ public Event(String description, String dates) { spaceCut = dates.indexOf(" "); endDate = dates.substring(spaceCut + 1); -/* - int spaceCut = taskDeadline.indexOf(" "); - taskDeadline = taskDeadline.substring(spaceCut + 1); - //this.dates = dates; - - */ - } - - public String getBy() { - return startDate; - } - - public void setBy(String by) { - this.startDate = by; } @Override public String toString() { - super.toString(); + //super.toString(); String isDoneString; if (isDone()) { @@ -41,6 +38,6 @@ public String toString() { isDoneString = "[ ]"; } - return "[E]" + isDoneString + description + "(from: " + startDate + "to: " + endDate + ")"; + return "[E]" + isDoneString + description + "(from: " + getStartDate() + "to: " + getEndDate() + ")"; } } diff --git a/src/main/java/TaskType.java b/src/main/java/TaskType.java new file mode 100644 index 000000000..75ec79542 --- /dev/null +++ b/src/main/java/TaskType.java @@ -0,0 +1,3 @@ +public enum TaskType { + LIST, TODO, DEADLINE, EVENT +} diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java index 00103ab42..508706da2 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/Todo.java @@ -5,19 +5,10 @@ public Todo(String description) { super(description); //isDone = false; } -/* - public boolean isDone() { - return isDone; - } - - public void setDone(boolean done) { - isDone = done; - } -*/ @Override public String toString() { - super.toString(); + //super.toString(); String isDoneString; if (isDone()) { From 10bcaaeb989798a2ee94d303127e38d447498b38 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Fri, 8 Sep 2023 00:47:57 +0800 Subject: [PATCH 09/77] Added three different task types (ToDos, Events, Deadlines) --- src/main/java/TaskType.java | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 src/main/java/TaskType.java diff --git a/src/main/java/TaskType.java b/src/main/java/TaskType.java deleted file mode 100644 index 75ec79542..000000000 --- a/src/main/java/TaskType.java +++ /dev/null @@ -1,3 +0,0 @@ -public enum TaskType { - LIST, TODO, DEADLINE, EVENT -} From b503333370692582e75ee2d1edd098f67ffe89af Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Fri, 8 Sep 2023 00:48:59 +0800 Subject: [PATCH 10/77] Added three different task types (ToDos, Events, Deadlines) --- src/main/java/Deadline.java | 2 +- src/main/java/Event.java | 2 +- src/main/java/Todo.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index 640e39a2a..ffd3f6c6f 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -26,6 +26,6 @@ public String toString() { isDoneString = "[ ]"; } - return "[D]" + isDoneString + description + "(do by: " + getByDate() + ")"; + return "[D]" + isDoneString + getDescription() + "(do by: " + getByDate() + ")"; } } diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 4a2d32e9b..9262e8b43 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -38,6 +38,6 @@ public String toString() { isDoneString = "[ ]"; } - return "[E]" + isDoneString + description + "(from: " + getStartDate() + "to: " + getEndDate() + ")"; + return "[E]" + isDoneString + getDescription() + "(from: " + getStartDate() + "to: " + getEndDate() + ")"; } } diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java index 508706da2..56c816c35 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/Todo.java @@ -17,6 +17,6 @@ public String toString() { isDoneString = "[ ]"; } - return "[T]" + isDoneString + description; + return "[T]" + isDoneString + getDescription(); } } From 5bae0159a025e1b8784d4b31fa41b205c5225df7 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Fri, 8 Sep 2023 01:36:47 +0800 Subject: [PATCH 11/77] Added Text-UI-Testing --- src/main/java/Duke.java | 4 ++-- src/main/java/Event.java | 2 +- text-ui-test/EXPECTED.TXT | 32 ++++++++++++++++++++++++++------ text-ui-test/input.txt | 7 +++++++ text-ui-test/runtest.sh | 9 +++++---- 5 files changed, 41 insertions(+), 13 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index e92a43e29..271df21d8 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -2,8 +2,8 @@ public class Duke { public static void main(String[] args) { - String logo = " _ _ \n" - + "| | _ _| | _____ \n" + String logo = " _ _\n" + + "| | _ _| | _____\n" + "| | | | | | |/ / _ \\\n" + "| |___| |_| | < __/\n" + "|_____|\\__,_|_|\\_\\___|\n"; diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 9262e8b43..b508fb36e 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -1,7 +1,7 @@ public class Event extends Deadline { protected String startDate; protected String endDate; -//event project meeting /from Mon 2pm /to 4pm + public Event(String description, String dates) { super(description, dates); setDates(dates); diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 657e74f6e..4c260316b 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,7 +1,27 @@ -Hello from - ____ _ -| _ \ _ _| | _____ -| | | | | | | |/ / _ \ -| |_| | |_| | < __/ -|____/ \__,_|_|\_\___| +Hello! I'm + _ _ +| | _ _| | _____ +| | | | | | |/ / _ \ +| |___| |_| | < __/ +|_____|\__,_|_|\_\___| +What can I do for you? +Got it. I've added this task: +[T][ ] Liow Enqi Janelle Answer CS2113 tutorial questions +Now you have 1 tasks in the list. +Got it. I've added this task: +[D][ ] weekly CS2113 quiz (do by: Monday 9pm) +Now you have 2 tasks in the list. +Here are the tasks in your list: +1.[T][ ] Liow Enqi Janelle Answer CS2113 tutorial questions +2.[D][ ] weekly CS2113 quiz (do by: Monday 9pm) +Got it. I've added this task: +[E][ ] CS2113 lecture (from: Friday 4 to: 6pm) +Now you have 3 tasks in the list. +Woohoo! You have accomplished: +[T][X] Liow Enqi Janelle Answer CS2113 tutorial questions +Here are the tasks in your list: +1.[T][X] Liow Enqi Janelle Answer CS2113 tutorial questions +2.[D][ ] weekly CS2113 quiz (do by: Monday 9pm) +3.[E][ ] CS2113 lecture (from: Friday 4 to: 6pm) +Bye. Hope to see you again soon! diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index e69de29bb..07daf1c7e 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -0,0 +1,7 @@ +todo Liow Enqi Janelle Answer CS2113 tutorial questions +deadline weekly CS2113 quiz /by Monday 9pm +list +event CS2113 lecture /from Friday 4 /to 6pm +mark 1 +list +bye \ No newline at end of file diff --git a/text-ui-test/runtest.sh b/text-ui-test/runtest.sh index c9ec87003..3844ed30b 100644 --- a/text-ui-test/runtest.sh +++ b/text-ui-test/runtest.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash + # create bin directory if it doesn't exist if [ ! -d "../bin" ] then @@ -13,7 +14,7 @@ then fi # compile the code into the bin folder, terminates if error occurred -if ! javac -cp ../src/main/java -Xlint:none -d ../bin ../src/main/java/*.java +if ! javac -cp /Users/janelle/cs2113repo/ip/src/main/java -Xlint:none -d ../bin /Users/janelle/cs2113repo/ip/src/main/java/*.java then echo "********** BUILD FAILURE **********" exit 1 @@ -23,11 +24,11 @@ fi java -classpath ../bin Duke < input.txt > ACTUAL.TXT # convert to UNIX format -cp EXPECTED.TXT EXPECTED-UNIX.TXT -dos2unix ACTUAL.TXT EXPECTED-UNIX.TXT +#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 2702b6eb13a2965bdcabb6ee3851fa9bbc40fc5e Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Sun, 10 Sep 2023 13:16:56 +0800 Subject: [PATCH 12/77] Revise formatting, Implement enum & switch --- src/main/java/ActionType.java | 3 + src/main/java/Deadline.java | 2 +- src/main/java/Duke.java | 128 ++++++++++++++++++---------------- src/main/java/Event.java | 2 +- src/main/java/Todo.java | 2 +- 5 files changed, 72 insertions(+), 65 deletions(-) create mode 100644 src/main/java/ActionType.java diff --git a/src/main/java/ActionType.java b/src/main/java/ActionType.java new file mode 100644 index 000000000..7047c5fea --- /dev/null +++ b/src/main/java/ActionType.java @@ -0,0 +1,3 @@ +public enum ActionType { + LIST, MARK, UNMARK, TODO, DEADLINE, EVENT +} diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index ffd3f6c6f..5975aa495 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -26,6 +26,6 @@ public String toString() { isDoneString = "[ ]"; } - return "[D]" + isDoneString + getDescription() + "(do by: " + getByDate() + ")"; + return "\t[D]" + isDoneString + getDescription() + "(do by: " + getByDate() + ")"; } } diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 271df21d8..0bafde698 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,89 +1,93 @@ import java.util.Scanner; public class Duke { + private static final String BYE_COMMAND = "bye"; public static void main(String[] args) { - String logo = " _ _\n" - + "| | _ _| | _____\n" - + "| | | | | | |/ / _ \\\n" - + "| |___| |_| | < __/\n" - + "|_____|\\__,_|_|\\_\\___|\n"; - System.out.println("Hello! I'm\n" + logo); - System.out.println("What can I do for you?"); - - Task[] theList = new Task[100]; + String logo = "\t _ _\n" + + "\t| | _ _| | _____\n" + + "\t| | | | | | |/ / _ \\\n" + + "\t| |___| |_| | < __/\n" + + "\t|_____|\\__,_|_|\\_\\___|\n"; + System.out.println("\t" + "Hello! I'm\n" + logo); + System.out.println("\t" + "What can I do for you?"); + + Task[] taskList = new Task[100]; Scanner userInput = new Scanner(System.in); int counter = 0; String echo = userInput.nextLine(); int taskNumber; + String taskDescription; + int slashCut; - while (!echo.equals("bye")) { + while (!echo.equals(BYE_COMMAND)) { String[] words = echo.split(" "); //to identify usage of features "mark" & "unmark" + ActionType action = ActionType.valueOf(words[0].toUpperCase()); - switch (words[0]) { - case "list": - System.out.println("Here are the tasks in your list:"); + switch (action) { + case LIST: + System.out.println("\tHere are the tasks in your list:"); for (int i = 0; i < counter; i += 1) { - System.out.print((i + 1) + "."); - System.out.println(theList[i]); + System.out.println("\t" + (i + 1) + "." + taskList[i]); } break; - case "mark": + case MARK: taskNumber = Integer.parseInt(words[1]) - 1; - System.out.println("Woohoo! You have accomplished:"); - theList[taskNumber].setDone(true); - System.out.println(theList[taskNumber]); + System.out.println("\tWoohoo! You have accomplished:"); + taskList[taskNumber].setDone(true); + System.out.println(taskList[taskNumber]); break; - case "unmark": + case UNMARK: taskNumber = Integer.parseInt(words[1]) - 1; - System.out.println("HA! You still have to complete:"); - theList[taskNumber].setDone(false); - System.out.println(theList[taskNumber]); + System.out.println("\tHA! You still have to complete:"); + taskList[taskNumber].setDone(false); + System.out.println(taskList[taskNumber]); + break; + + case TODO: + //int spaceCut = echo.indexOf(" "); + taskDescription = echo.substring(4); + taskList[counter] = new Todo(taskDescription); + System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); + counter += 1; + System.out.println("\tNow you have " + counter + " tasks in the list."); + break; + + + case DEADLINE: + taskDescription = echo.substring(8); + slashCut = taskDescription.indexOf("/"); + + String taskDeadline = taskDescription.substring(slashCut + 1); + taskDescription = taskDescription.substring(0, slashCut); + + taskList[counter] = new Deadline(taskDescription, taskDeadline); + System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); + counter += 1; + System.out.println("\tNow you have " + counter + " tasks in the list."); break; + + + case EVENT: + taskDescription = echo.substring(5); + slashCut = taskDescription.indexOf("/"); + + String taskDuration = taskDescription.substring(slashCut); + taskDescription = taskDescription.substring(0, slashCut); + + taskList[counter] = new Event(taskDescription, taskDuration); + System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); + counter += 1; + System.out.println("\tNow you have " + counter + " tasks in the list."); + break; + default: - int spaceCut = echo.indexOf(" "); - String taskType = echo.substring(0, spaceCut); - String taskDescription = echo.substring(spaceCut); - int slashCut = taskDescription.indexOf("/"); - - //TaskType type = TaskType.words[0]; - - switch (taskType) { - case "todo": - theList[counter] = new Todo(taskDescription); - System.out.println("Got it. I've added this task:"); - System.out.println(theList[counter]); - counter += 1; - System.out.println("Now you have " + counter + " tasks in the list."); - break; - case "deadline": - String taskDeadline = taskDescription.substring(slashCut); - taskDescription = taskDescription.substring(0, slashCut); - - theList[counter] = new Deadline(taskDescription, taskDeadline); - System.out.println("Got it. I've added this task:"); - System.out.println(theList[counter]); - counter += 1; - System.out.println("Now you have " + counter + " tasks in the list."); - break; - case "event": - String taskDuration = taskDescription.substring(slashCut); - taskDescription = taskDescription.substring(0, slashCut); - - theList[counter] = new Event(taskDescription, taskDuration); - System.out.println("Got it. I've added this task:"); - System.out.println(theList[counter]); - counter += 1; - System.out.println("Now you have " + counter + " tasks in the list."); - break; - default: - break; - } + break; } echo = userInput.nextLine(); } - System.out.println("Bye. Hope to see you again soon!"); + System.out.println("\tBye. Hope to see you again soon!"); userInput.close(); } diff --git a/src/main/java/Event.java b/src/main/java/Event.java index b508fb36e..eb6dc8252 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -38,6 +38,6 @@ public String toString() { isDoneString = "[ ]"; } - return "[E]" + isDoneString + getDescription() + "(from: " + getStartDate() + "to: " + getEndDate() + ")"; + return "\t[E]" + isDoneString + getDescription() + "(from: " + getStartDate() + "to: " + getEndDate() + ")"; } } diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java index 56c816c35..68b5a74aa 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/Todo.java @@ -17,6 +17,6 @@ public String toString() { isDoneString = "[ ]"; } - return "[T]" + isDoneString + getDescription(); + return "\t[T]" + isDoneString + getDescription(); } } From 77966913f184f3c4f092e56a37038ac4d2b287ab Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Mon, 18 Sep 2023 01:04:02 +0800 Subject: [PATCH 13/77] make Task an abstract task --- src/main/java/Task.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Task.java b/src/main/java/Task.java index c35540eb1..ed0dc0617 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -1,4 +1,4 @@ -public class Task { +public abstract class Task { protected String description; protected boolean isDone; From 39b457ca27a98279c0505755cd508591986154b9 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Mon, 18 Sep 2023 01:12:16 +0800 Subject: [PATCH 14/77] fix lines spaced part 2 --- src/main/java/Duke.java | 2 -- src/main/java/Task.java | 5 ++--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 0bafde698..96210fca5 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -53,7 +53,6 @@ public static void main(String[] args) { System.out.println("\tNow you have " + counter + " tasks in the list."); break; - case DEADLINE: taskDescription = echo.substring(8); slashCut = taskDescription.indexOf("/"); @@ -67,7 +66,6 @@ public static void main(String[] args) { System.out.println("\tNow you have " + counter + " tasks in the list."); break; - case EVENT: taskDescription = echo.substring(5); slashCut = taskDescription.indexOf("/"); diff --git a/src/main/java/Task.java b/src/main/java/Task.java index ed0dc0617..ec8c89e3b 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -11,7 +11,6 @@ public String getDescription() { return description; } - public boolean isDone() { return isDone; } @@ -20,9 +19,9 @@ public void setDone(boolean done) { isDone = done; } - @Override + /*@Override public String toString() { return ""; } - + */ } \ No newline at end of file From 573e246ef08459ce7c86d20f1b984907d63f4075 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Mon, 18 Sep 2023 01:13:10 +0800 Subject: [PATCH 15/77] fix lines spaced part 2 --- src/main/java/Duke.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 96210fca5..491ba15c3 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -43,7 +43,6 @@ public static void main(String[] args) { taskList[taskNumber].setDone(false); System.out.println(taskList[taskNumber]); break; - case TODO: //int spaceCut = echo.indexOf(" "); taskDescription = echo.substring(4); @@ -52,7 +51,6 @@ public static void main(String[] args) { counter += 1; System.out.println("\tNow you have " + counter + " tasks in the list."); break; - case DEADLINE: taskDescription = echo.substring(8); slashCut = taskDescription.indexOf("/"); @@ -65,7 +63,6 @@ public static void main(String[] args) { counter += 1; System.out.println("\tNow you have " + counter + " tasks in the list."); break; - case EVENT: taskDescription = echo.substring(5); slashCut = taskDescription.indexOf("/"); @@ -78,7 +75,6 @@ public static void main(String[] args) { counter += 1; System.out.println("\tNow you have " + counter + " tasks in the list."); break; - default: break; } From bf1f72bf9b390154d1848a6435d310156dee98b3 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Tue, 19 Sep 2023 17:22:26 +0800 Subject: [PATCH 16/77] remove unnecessary line --- src/main/java/Duke.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 491ba15c3..f0132dbfc 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -44,7 +44,6 @@ public static void main(String[] args) { System.out.println(taskList[taskNumber]); break; case TODO: - //int spaceCut = echo.indexOf(" "); taskDescription = echo.substring(4); taskList[counter] = new Todo(taskDescription); System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); From 7087e36f3109d1f4bed4ce38e7282eb624d6340c Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Tue, 19 Sep 2023 17:23:36 +0800 Subject: [PATCH 17/77] IntelliJ recommendations --- src/main/java/Duke.java | 44 ++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index f0132dbfc..9d086dd3d 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -3,11 +3,13 @@ public class Duke { private static final String BYE_COMMAND = "bye"; public static void main(String[] args) { - String logo = "\t _ _\n" - + "\t| | _ _| | _____\n" - + "\t| | | | | | |/ / _ \\\n" - + "\t| |___| |_| | < __/\n" - + "\t|_____|\\__,_|_|\\_\\___|\n"; + String logo = """ + \t _ _ + \t| | _ _| | _____ + \t| | | | | | |/ / _ \\ + \t| |___| |_| | < __/ + \t|_____|\\__,_|_|\\_\\___| + """; System.out.println("\t" + "Hello! I'm\n" + logo); System.out.println("\t" + "What can I do for you?"); @@ -25,57 +27,53 @@ public static void main(String[] args) { ActionType action = ActionType.valueOf(words[0].toUpperCase()); switch (action) { - case LIST: + case LIST -> { System.out.println("\tHere are the tasks in your list:"); for (int i = 0; i < counter; i += 1) { System.out.println("\t" + (i + 1) + "." + taskList[i]); } - break; - case MARK: + } + case MARK -> { taskNumber = Integer.parseInt(words[1]) - 1; System.out.println("\tWoohoo! You have accomplished:"); taskList[taskNumber].setDone(true); System.out.println(taskList[taskNumber]); - break; - case UNMARK: + } + case UNMARK -> { taskNumber = Integer.parseInt(words[1]) - 1; System.out.println("\tHA! You still have to complete:"); taskList[taskNumber].setDone(false); System.out.println(taskList[taskNumber]); - break; - case TODO: + } + case TODO -> { taskDescription = echo.substring(4); taskList[counter] = new Todo(taskDescription); System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); counter += 1; System.out.println("\tNow you have " + counter + " tasks in the list."); - break; - case DEADLINE: + } + case DEADLINE -> { taskDescription = echo.substring(8); slashCut = taskDescription.indexOf("/"); - String taskDeadline = taskDescription.substring(slashCut + 1); taskDescription = taskDescription.substring(0, slashCut); - taskList[counter] = new Deadline(taskDescription, taskDeadline); System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); counter += 1; System.out.println("\tNow you have " + counter + " tasks in the list."); - break; - case EVENT: + } + case EVENT -> { taskDescription = echo.substring(5); slashCut = taskDescription.indexOf("/"); - String taskDuration = taskDescription.substring(slashCut); taskDescription = taskDescription.substring(0, slashCut); - taskList[counter] = new Event(taskDescription, taskDuration); System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); counter += 1; System.out.println("\tNow you have " + counter + " tasks in the list."); - break; - default: - break; + } + default -> { + } } echo = userInput.nextLine(); } From 0609792bfa807a8896ed12ee8da39e1c4dff442f Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Wed, 20 Sep 2023 01:51:29 +0800 Subject: [PATCH 18/77] add some try-catch blocks --- src/main/java/Deadline.java | 13 +++-- src/main/java/Duke.java | 85 -------------------------------- src/main/java/Event.java | 11 +++-- src/main/java/Luke.java | 96 +++++++++++++++++++++++++++++++++++++ src/main/java/Todo.java | 8 +++- 5 files changed, 120 insertions(+), 93 deletions(-) delete mode 100644 src/main/java/Duke.java create mode 100644 src/main/java/Luke.java diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index 5975aa495..8591159a6 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -1,9 +1,16 @@ public class Deadline extends Todo { protected String byDate; - public Deadline(String description, String date) { - super(description); - setByDate(date); + public Deadline(String echo) { + super(echo); + //setByDate(date); + String taskDescription = echo.substring(8); + int slashCut = taskDescription.indexOf("/"); + byDate = taskDescription.substring(slashCut + 1); + description = taskDescription.substring(0, slashCut); + if (description.length() <= 0) { + throw new IndexOutOfBoundsException(); + } } public String getByDate() { diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java deleted file mode 100644 index 9d086dd3d..000000000 --- a/src/main/java/Duke.java +++ /dev/null @@ -1,85 +0,0 @@ -import java.util.Scanner; - -public class Duke { - private static final String BYE_COMMAND = "bye"; - public static void main(String[] args) { - String logo = """ - \t _ _ - \t| | _ _| | _____ - \t| | | | | | |/ / _ \\ - \t| |___| |_| | < __/ - \t|_____|\\__,_|_|\\_\\___| - """; - System.out.println("\t" + "Hello! I'm\n" + logo); - System.out.println("\t" + "What can I do for you?"); - - Task[] taskList = new Task[100]; - Scanner userInput = new Scanner(System.in); - int counter = 0; - - String echo = userInput.nextLine(); - int taskNumber; - String taskDescription; - int slashCut; - - while (!echo.equals(BYE_COMMAND)) { - String[] words = echo.split(" "); //to identify usage of features "mark" & "unmark" - ActionType action = ActionType.valueOf(words[0].toUpperCase()); - - switch (action) { - case LIST -> { - System.out.println("\tHere are the tasks in your list:"); - for (int i = 0; i < counter; i += 1) { - System.out.println("\t" + (i + 1) + "." + taskList[i]); - } - } - case MARK -> { - taskNumber = Integer.parseInt(words[1]) - 1; - System.out.println("\tWoohoo! You have accomplished:"); - taskList[taskNumber].setDone(true); - System.out.println(taskList[taskNumber]); - } - case UNMARK -> { - taskNumber = Integer.parseInt(words[1]) - 1; - System.out.println("\tHA! You still have to complete:"); - taskList[taskNumber].setDone(false); - System.out.println(taskList[taskNumber]); - } - case TODO -> { - taskDescription = echo.substring(4); - taskList[counter] = new Todo(taskDescription); - System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); - counter += 1; - System.out.println("\tNow you have " + counter + " tasks in the list."); - } - case DEADLINE -> { - taskDescription = echo.substring(8); - slashCut = taskDescription.indexOf("/"); - String taskDeadline = taskDescription.substring(slashCut + 1); - taskDescription = taskDescription.substring(0, slashCut); - taskList[counter] = new Deadline(taskDescription, taskDeadline); - System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); - counter += 1; - System.out.println("\tNow you have " + counter + " tasks in the list."); - } - case EVENT -> { - taskDescription = echo.substring(5); - slashCut = taskDescription.indexOf("/"); - String taskDuration = taskDescription.substring(slashCut); - taskDescription = taskDescription.substring(0, slashCut); - taskList[counter] = new Event(taskDescription, taskDuration); - System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); - counter += 1; - System.out.println("\tNow you have " + counter + " tasks in the list."); - } - default -> { - } - } - echo = userInput.nextLine(); - } - - System.out.println("\tBye. Hope to see you again soon!"); - - userInput.close(); - } -} diff --git a/src/main/java/Event.java b/src/main/java/Event.java index eb6dc8252..7fe41c462 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -2,9 +2,14 @@ public class Event extends Deadline { protected String startDate; protected String endDate; - public Event(String description, String dates) { - super(description, dates); - setDates(dates); + public Event(String echo) { + super(echo); + //setDates(dates); + String taskDescription = echo.substring(5); + int slashCut = taskDescription.indexOf("/"); + String taskDuration = taskDescription.substring(slashCut); + setDates(taskDuration); + description = taskDescription.substring(0, slashCut); } public String getStartDate() { diff --git a/src/main/java/Luke.java b/src/main/java/Luke.java new file mode 100644 index 000000000..bfa9158df --- /dev/null +++ b/src/main/java/Luke.java @@ -0,0 +1,96 @@ +import java.util.Scanner; + +public class Luke { + private static final String BYE_COMMAND = "bye"; + public static void main(String[] args) { + String logo = "\t _ _\n" + + "\t | |_ _| |_____\n" + + "\t | | | | | | |/ /_ \\\\\n" + + "\t | |___ | |_ | | <__ /\n" + + "\t | _____ |\\\\__, _ | _ |\\\\_\\\\___ |\n"; + System.out.println("\t" + "Hello! I'm\n" + logo); + System.out.println("\t" + "What can I do for you?"); + + Task[] taskList = new Task[100]; + Scanner userInput = new Scanner(System.in); + int counter = 0; + + String echo = userInput.nextLine(); + int taskNumber; + + + while (!echo.equals(BYE_COMMAND)) { + String[] words = echo.split(" "); //to identify usage of features "mark" & "unmark" + ActionType action = ActionType.valueOf(words[0].toUpperCase()); + + switch (action) { + case LIST: + System.out.println("\tHere are the tasks in your list:"); + for (int i = 0; i < counter; i += 1) { + System.out.println("\t" + (i + 1) + "." + taskList[i]); + } + break; + + case MARK: + taskNumber = Integer.parseInt(words[1]) - 1; + System.out.println("\tWoohoo! You have accomplished:"); + taskList[taskNumber].setDone(true); + System.out.println(taskList[taskNumber]); + break; + + case UNMARK: + taskNumber = Integer.parseInt(words[1]) - 1; + System.out.println("\tHA! You still have to complete:"); + taskList[taskNumber].setDone(false); + System.out.println(taskList[taskNumber]); + break; + + case TODO: + try { + taskList[counter] = new Todo(echo); + + System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); + counter += 1; + System.out.println("\tNow you have " + counter + " tasks in the list."); + } catch (IndexOutOfBoundsException e) { + //counter -= 1; + System.out.println("OOPS!!! The description of a todo cannot be empty."); + } + + break; + + case DEADLINE: + + try { + taskList[counter] = new Deadline(echo); + System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); + counter += 1; + System.out.println("\tNow you have " + counter + " tasks in the list."); + } catch (IndexOutOfBoundsException e) { + //counter -= 1; + System.out.println("OOPS!!! The description of a deadline cannot be empty."); + } + break; + + case EVENT: + taskList[counter] = new Event(echo); + System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); + counter += 1; + System.out.println("\tNow you have " + counter + " tasks in the list."); + break; + + default: + //System.out.println("OOPS"); + //throw new IndexOutOfBoundsException("OOPS"); + break; + } + + echo = userInput.nextLine(); + } + + System.out.println("\tBye. Hope to see you again soon!"); + + userInput.close(); + } +} + diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java index 68b5a74aa..e271313f3 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/Todo.java @@ -1,9 +1,13 @@ public class Todo extends Task { //protected boolean isDone; - public Todo(String description) { - super(description); + public Todo(String echo) { + super(echo); //isDone = false; + description = echo.substring(4); + if (description.length() <= 0) { + throw new IndexOutOfBoundsException(); + } } @Override From e41f732c124a65f229e025c620341fca93e9af0e Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Wed, 20 Sep 2023 10:21:35 +0800 Subject: [PATCH 19/77] add some try-catch blocks and throw-catch blocks --- src/main/java/Event.java | 4 ++++ src/main/java/Luke.java | 25 ++++++++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 7fe41c462..6c1a6defc 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -10,6 +10,10 @@ public Event(String echo) { String taskDuration = taskDescription.substring(slashCut); setDates(taskDuration); description = taskDescription.substring(0, slashCut); + + if (description.length() <= 0) { + throw new IndexOutOfBoundsException(); + } } public String getStartDate() { diff --git a/src/main/java/Luke.java b/src/main/java/Luke.java index bfa9158df..e123ffabe 100644 --- a/src/main/java/Luke.java +++ b/src/main/java/Luke.java @@ -3,11 +3,12 @@ public class Luke { private static final String BYE_COMMAND = "bye"; public static void main(String[] args) { - String logo = "\t _ _\n" + - "\t | |_ _| |_____\n" + - "\t | | | | | | |/ /_ \\\\\n" + - "\t | |___ | |_ | | <__ /\n" + - "\t | _____ |\\\\__, _ | _ |\\\\_\\\\___ |\n"; + String logo = "\t _ _ \n" + + "\t| | _ _| | _____ \n" + + "\t| | | | | | |/ / _ \\\n" + + "\t| |___| |_| | < __/\n" + + "\t|_____|\\__,_|_|\\_\\___|\n"; + System.out.println("\t" + "Hello! I'm\n" + logo); System.out.println("\t" + "What can I do for you?"); @@ -73,10 +74,16 @@ public static void main(String[] args) { break; case EVENT: - taskList[counter] = new Event(echo); - System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); - counter += 1; - System.out.println("\tNow you have " + counter + " tasks in the list."); + + try { + taskList[counter] = new Event(echo); + System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); + counter += 1; + System.out.println("\tNow you have " + counter + " tasks in the list."); + } catch (IndexOutOfBoundsException e) { + //counter -= 1; + System.out.println("OOPS!!! The description of a event cannot be empty."); + } break; default: From 6c7aeb7a987de7212c089b0b50ce78e393e00183 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Wed, 20 Sep 2023 10:34:38 +0800 Subject: [PATCH 20/77] add try-catch blocks and throw-catch blocks for random words --- src/main/java/Luke.java | 147 +++++++++++++++++++++------------------- 1 file changed, 78 insertions(+), 69 deletions(-) diff --git a/src/main/java/Luke.java b/src/main/java/Luke.java index e123ffabe..e4e341e05 100644 --- a/src/main/java/Luke.java +++ b/src/main/java/Luke.java @@ -2,6 +2,78 @@ public class Luke { private static final String BYE_COMMAND = "bye"; + + public static void callAction(Task[] taskList, String echo, ActionType action, String[] words, int counter) { + int taskNumber; + + switch (action) { + case LIST: + System.out.println("\tHere are the tasks in your list:"); + for (int i = 0; i < counter; i += 1) { + System.out.println("\t" + (i + 1) + "." + taskList[i]); + } + break; + + case MARK: + taskNumber = Integer.parseInt(words[1]) - 1; + System.out.println("\tWoohoo! You have accomplished:"); + taskList[taskNumber].setDone(true); + System.out.println(taskList[taskNumber]); + break; + + case UNMARK: + taskNumber = Integer.parseInt(words[1]) - 1; + System.out.println("\tHA! You still have to complete:"); + taskList[taskNumber].setDone(false); + System.out.println(taskList[taskNumber]); + break; + + case TODO: + try { + taskList[counter] = new Todo(echo); + + System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); + counter += 1; + System.out.println("\tNow you have " + counter + " tasks in the list."); + } catch (IndexOutOfBoundsException e) { + //counter -= 1; + System.out.println("OOPS!!! The description of a todo cannot be empty."); + } + + break; + + case DEADLINE: + + try { + taskList[counter] = new Deadline(echo); + System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); + counter += 1; + System.out.println("\tNow you have " + counter + " tasks in the list."); + } catch (IndexOutOfBoundsException e) { + //counter -= 1; + System.out.println("OOPS!!! The description of a deadline cannot be empty."); + } + break; + + case EVENT: + + try { + taskList[counter] = new Event(echo); + System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); + counter += 1; + System.out.println("\tNow you have " + counter + " tasks in the list."); + } catch (IndexOutOfBoundsException e) { + //counter -= 1; + System.out.println("OOPS!!! The description of a event cannot be empty."); + } + break; + + default: + //System.out.println("OOPS"); + //throw new IndexOutOfBoundsException("OOPS"); + break; + } + } public static void main(String[] args) { String logo = "\t _ _ \n" + "\t| | _ _| | _____ \n" @@ -17,79 +89,16 @@ public static void main(String[] args) { int counter = 0; String echo = userInput.nextLine(); - int taskNumber; while (!echo.equals(BYE_COMMAND)) { String[] words = echo.split(" "); //to identify usage of features "mark" & "unmark" - ActionType action = ActionType.valueOf(words[0].toUpperCase()); - - switch (action) { - case LIST: - System.out.println("\tHere are the tasks in your list:"); - for (int i = 0; i < counter; i += 1) { - System.out.println("\t" + (i + 1) + "." + taskList[i]); - } - break; - - case MARK: - taskNumber = Integer.parseInt(words[1]) - 1; - System.out.println("\tWoohoo! You have accomplished:"); - taskList[taskNumber].setDone(true); - System.out.println(taskList[taskNumber]); - break; - - case UNMARK: - taskNumber = Integer.parseInt(words[1]) - 1; - System.out.println("\tHA! You still have to complete:"); - taskList[taskNumber].setDone(false); - System.out.println(taskList[taskNumber]); - break; - - case TODO: - try { - taskList[counter] = new Todo(echo); - - System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); - counter += 1; - System.out.println("\tNow you have " + counter + " tasks in the list."); - } catch (IndexOutOfBoundsException e) { - //counter -= 1; - System.out.println("OOPS!!! The description of a todo cannot be empty."); - } - - break; - - case DEADLINE: - - try { - taskList[counter] = new Deadline(echo); - System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); - counter += 1; - System.out.println("\tNow you have " + counter + " tasks in the list."); - } catch (IndexOutOfBoundsException e) { - //counter -= 1; - System.out.println("OOPS!!! The description of a deadline cannot be empty."); - } - break; - - case EVENT: - - try { - taskList[counter] = new Event(echo); - System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); - counter += 1; - System.out.println("\tNow you have " + counter + " tasks in the list."); - } catch (IndexOutOfBoundsException e) { - //counter -= 1; - System.out.println("OOPS!!! The description of a event cannot be empty."); - } - break; - - default: - //System.out.println("OOPS"); - //throw new IndexOutOfBoundsException("OOPS"); - break; + + try { + ActionType action = ActionType.valueOf(words[0].toUpperCase()); + callAction(taskList, echo, action, words, counter); + } catch (IllegalArgumentException e) { + System.out.println("OOPS!!! The waht is this."); } echo = userInput.nextLine(); From 43207212b8e196ca2595bacccee7e76b19804d34 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Wed, 20 Sep 2023 11:21:19 +0800 Subject: [PATCH 21/77] change to more specific error message lines --- src/main/java/Deadline.java | 13 ++- src/main/java/Event.java | 10 ++- src/main/java/Luke.java | 134 +++++++++++++++---------------- src/main/java/LukeTimeError.java | 2 + src/main/java/Todo.java | 6 +- 5 files changed, 89 insertions(+), 76 deletions(-) create mode 100644 src/main/java/LukeTimeError.java diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index 8591159a6..80800d06c 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -1,14 +1,21 @@ public class Deadline extends Todo { protected String byDate; - public Deadline(String echo) { + public Deadline(String echo) throws LukeTimeError { super(echo); - //setByDate(date); + String taskDescription = echo.substring(8); + int slashCut = taskDescription.indexOf("/"); + if (slashCut <= 0) { + throw new LukeTimeError(); + } + byDate = taskDescription.substring(slashCut + 1); + description = taskDescription.substring(0, slashCut); - if (description.length() <= 0) { + + if (description.length() <= 1) { throw new IndexOutOfBoundsException(); } } diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 6c1a6defc..311ed2522 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -2,16 +2,22 @@ public class Event extends Deadline { protected String startDate; protected String endDate; - public Event(String echo) { + public Event(String echo) throws LukeTimeError { super(echo); //setDates(dates); String taskDescription = echo.substring(5); + int slashCut = taskDescription.indexOf("/"); + if (slashCut <= 0) { + throw new LukeTimeError(); + } + String taskDuration = taskDescription.substring(slashCut); setDates(taskDuration); + description = taskDescription.substring(0, slashCut); - if (description.length() <= 0) { + if (description.length() <= 1) { throw new IndexOutOfBoundsException(); } } diff --git a/src/main/java/Luke.java b/src/main/java/Luke.java index e4e341e05..084fc5d7a 100644 --- a/src/main/java/Luke.java +++ b/src/main/java/Luke.java @@ -6,72 +6,71 @@ public class Luke { public static void callAction(Task[] taskList, String echo, ActionType action, String[] words, int counter) { int taskNumber; - switch (action) { - case LIST: - System.out.println("\tHere are the tasks in your list:"); - for (int i = 0; i < counter; i += 1) { - System.out.println("\t" + (i + 1) + "." + taskList[i]); - } - break; - - case MARK: - taskNumber = Integer.parseInt(words[1]) - 1; - System.out.println("\tWoohoo! You have accomplished:"); - taskList[taskNumber].setDone(true); - System.out.println(taskList[taskNumber]); - break; - - case UNMARK: - taskNumber = Integer.parseInt(words[1]) - 1; - System.out.println("\tHA! You still have to complete:"); - taskList[taskNumber].setDone(false); - System.out.println(taskList[taskNumber]); - break; - - case TODO: - try { - taskList[counter] = new Todo(echo); - - System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); - counter += 1; - System.out.println("\tNow you have " + counter + " tasks in the list."); - } catch (IndexOutOfBoundsException e) { - //counter -= 1; - System.out.println("OOPS!!! The description of a todo cannot be empty."); - } - - break; - - case DEADLINE: - - try { - taskList[counter] = new Deadline(echo); - System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); - counter += 1; - System.out.println("\tNow you have " + counter + " tasks in the list."); - } catch (IndexOutOfBoundsException e) { - //counter -= 1; - System.out.println("OOPS!!! The description of a deadline cannot be empty."); - } - break; - - case EVENT: - - try { - taskList[counter] = new Event(echo); - System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); - counter += 1; - System.out.println("\tNow you have " + counter + " tasks in the list."); - } catch (IndexOutOfBoundsException e) { - //counter -= 1; - System.out.println("OOPS!!! The description of a event cannot be empty."); - } - break; - - default: - //System.out.println("OOPS"); - //throw new IndexOutOfBoundsException("OOPS"); - break; + try { + switch (action) { + case LIST: + System.out.println("\tHere are the tasks in your list:"); + for (int i = 0; i < counter; i += 1) { + System.out.println("\t" + (i + 1) + "." + taskList[i]); + } + break; + + case MARK: + taskNumber = Integer.parseInt(words[1]) - 1; + System.out.println("\tWoohoo! You have accomplished:"); + taskList[taskNumber].setDone(true); + System.out.println(taskList[taskNumber]); + break; + + case UNMARK: + taskNumber = Integer.parseInt(words[1]) - 1; + System.out.println("\tHA! You still have to complete:"); + taskList[taskNumber].setDone(false); + System.out.println(taskList[taskNumber]); + break; + + case TODO: + //try { + taskList[counter] = new Todo(echo); + + System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); + counter += 1; + System.out.println("\tNow you have " + counter + " tasks in the list."); + //} catch (IndexOutOfBoundsException e) { + //System.out.println("OOPS!!! The description of a todo cannot be empty."); + //} + break; + + case DEADLINE: + try { + taskList[counter] = new Deadline(echo); + + System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); + counter += 1; + System.out.println("\tNow you have " + counter + " tasks in the list."); + } catch (LukeTimeError e) { + System.out.println("OOPS!!! There's an error in how you write the deadline."); + } + break; + + case EVENT: + try { + taskList[counter] = new Event(echo); + + System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); + counter += 1; + System.out.println("\tNow you have " + counter + " tasks in the list."); + } catch (LukeTimeError e) { + System.out.println("OOPS!!! There's an error in how you specify the event schedule."); + } + break; + + default: + assert false: "This line should never be reached"; + break; + } + } catch (IndexOutOfBoundsException e) { //for empty MARK and empty UNMARK and empty TODO + System.out.println("OOPS!!! You have an error in " + words[0] + "."); } } public static void main(String[] args) { @@ -90,7 +89,6 @@ public static void main(String[] args) { String echo = userInput.nextLine(); - while (!echo.equals(BYE_COMMAND)) { String[] words = echo.split(" "); //to identify usage of features "mark" & "unmark" @@ -98,7 +96,7 @@ public static void main(String[] args) { ActionType action = ActionType.valueOf(words[0].toUpperCase()); callAction(taskList, echo, action, words, counter); } catch (IllegalArgumentException e) { - System.out.println("OOPS!!! The waht is this."); + System.out.println("OOPS!!! I'm sorry, but I don't know what that means :-("); } echo = userInput.nextLine(); diff --git a/src/main/java/LukeTimeError.java b/src/main/java/LukeTimeError.java new file mode 100644 index 000000000..0f1abc9f0 --- /dev/null +++ b/src/main/java/LukeTimeError.java @@ -0,0 +1,2 @@ +public class LukeTimeError extends Exception { +} \ No newline at end of file diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java index e271313f3..8cdc562fc 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/Todo.java @@ -2,10 +2,10 @@ public class Todo extends Task { //protected boolean isDone; public Todo(String echo) { - super(echo); - //isDone = false; + super(echo); //ensures superclass is properly initialised + description = echo.substring(4); - if (description.length() <= 0) { + if (description.isEmpty()) { throw new IndexOutOfBoundsException(); } } From f6e4a2db6e7ea57feaf03380822866216c16657e Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Wed, 20 Sep 2023 11:52:41 +0800 Subject: [PATCH 22/77] change to even more specific error message lines and fix list error --- src/main/java/Luke.java | 135 +++++++++++++++++++--------------------- 1 file changed, 64 insertions(+), 71 deletions(-) diff --git a/src/main/java/Luke.java b/src/main/java/Luke.java index 084fc5d7a..b744f0a12 100644 --- a/src/main/java/Luke.java +++ b/src/main/java/Luke.java @@ -3,76 +3,6 @@ public class Luke { private static final String BYE_COMMAND = "bye"; - public static void callAction(Task[] taskList, String echo, ActionType action, String[] words, int counter) { - int taskNumber; - - try { - switch (action) { - case LIST: - System.out.println("\tHere are the tasks in your list:"); - for (int i = 0; i < counter; i += 1) { - System.out.println("\t" + (i + 1) + "." + taskList[i]); - } - break; - - case MARK: - taskNumber = Integer.parseInt(words[1]) - 1; - System.out.println("\tWoohoo! You have accomplished:"); - taskList[taskNumber].setDone(true); - System.out.println(taskList[taskNumber]); - break; - - case UNMARK: - taskNumber = Integer.parseInt(words[1]) - 1; - System.out.println("\tHA! You still have to complete:"); - taskList[taskNumber].setDone(false); - System.out.println(taskList[taskNumber]); - break; - - case TODO: - //try { - taskList[counter] = new Todo(echo); - - System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); - counter += 1; - System.out.println("\tNow you have " + counter + " tasks in the list."); - //} catch (IndexOutOfBoundsException e) { - //System.out.println("OOPS!!! The description of a todo cannot be empty."); - //} - break; - - case DEADLINE: - try { - taskList[counter] = new Deadline(echo); - - System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); - counter += 1; - System.out.println("\tNow you have " + counter + " tasks in the list."); - } catch (LukeTimeError e) { - System.out.println("OOPS!!! There's an error in how you write the deadline."); - } - break; - - case EVENT: - try { - taskList[counter] = new Event(echo); - - System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); - counter += 1; - System.out.println("\tNow you have " + counter + " tasks in the list."); - } catch (LukeTimeError e) { - System.out.println("OOPS!!! There's an error in how you specify the event schedule."); - } - break; - - default: - assert false: "This line should never be reached"; - break; - } - } catch (IndexOutOfBoundsException e) { //for empty MARK and empty UNMARK and empty TODO - System.out.println("OOPS!!! You have an error in " + words[0] + "."); - } - } public static void main(String[] args) { String logo = "\t _ _ \n" + "\t| | _ _| | _____ \n" @@ -86,6 +16,7 @@ public static void main(String[] args) { Task[] taskList = new Task[100]; Scanner userInput = new Scanner(System.in); int counter = 0; + int taskNumber; String echo = userInput.nextLine(); @@ -94,7 +25,69 @@ public static void main(String[] args) { try { ActionType action = ActionType.valueOf(words[0].toUpperCase()); - callAction(taskList, echo, action, words, counter); + + try { + switch (action) { + case LIST: + System.out.println("\tHere are the tasks in your list:"); + for (int i = 0; i < counter; i += 1) { + System.out.println("\t" + (i + 1) + "." + taskList[i]); + } + break; + + case MARK: + taskNumber = Integer.parseInt(words[1]) - 1; + System.out.println("\tWoohoo! You have accomplished:"); + taskList[taskNumber].setDone(true); + System.out.println(taskList[taskNumber]); + break; + + case UNMARK: + taskNumber = Integer.parseInt(words[1]) - 1; + System.out.println("\tHA! You still have to complete:"); + taskList[taskNumber].setDone(false); + System.out.println(taskList[taskNumber]); + break; + + case TODO: + taskList[counter] = new Todo(echo); + + System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); + counter += 1; + System.out.println("\tNow you have " + counter + " tasks in the list."); + break; + + case DEADLINE: + try { + taskList[counter] = new Deadline(echo); + + System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); + counter += 1; + System.out.println("\tNow you have " + counter + " tasks in the list."); + } catch (LukeTimeError e) { + System.out.println("OOPS!!! There's an error in the deadline's 'do by' date."); + } + break; + + case EVENT: + try { + taskList[counter] = new Event(echo); + + System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); + counter += 1; + System.out.println("\tNow you have " + counter + " tasks in the list."); + } catch (LukeTimeError e) { + System.out.println("OOPS!!! There's an error in the event's start and end time."); + } + break; + + default: + assert false: "This line should never be reached"; + break; + } + } catch (IndexOutOfBoundsException e) { //empty for MARK, UNMARK, TO DO description, DEADLINE description, EVENT description + System.out.println("OOPS!!! You have missing arguments for " + words[0] + "."); + } } catch (IllegalArgumentException e) { System.out.println("OOPS!!! I'm sorry, but I don't know what that means :-("); } From 5dc30d9002e7f5654f72f574af227c06a1a8c711 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Thu, 21 Sep 2023 00:02:06 +0800 Subject: [PATCH 23/77] throw error if deadline format is wrong --- src/main/java/Deadline.java | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index 80800d06c..7eca4fcf7 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -1,5 +1,5 @@ public class Deadline extends Todo { - protected String byDate; + protected String date; public Deadline(String echo) throws LukeTimeError { super(echo); @@ -11,7 +11,7 @@ public Deadline(String echo) throws LukeTimeError { throw new LukeTimeError(); } - byDate = taskDescription.substring(slashCut + 1); + setDate(taskDescription.substring(slashCut + 1)); description = taskDescription.substring(0, slashCut); @@ -20,13 +20,17 @@ public Deadline(String echo) throws LukeTimeError { } } - public String getByDate() { - return byDate; + public String getDate() { + return date; } - public void setByDate(String date) { - int spaceCut = date.indexOf(" "); - byDate = date.substring(spaceCut + 1); + public void setDate(String dateString) throws LukeTimeError { + String[] words = dateString.split(" "); + if (!words[0].equals("by")) { + throw new LukeTimeError(); + } + int spaceCut = dateString.indexOf(" "); + date = dateString.substring(spaceCut + 1); } @Override @@ -40,6 +44,6 @@ public String toString() { isDoneString = "[ ]"; } - return "\t[D]" + isDoneString + getDescription() + "(do by: " + getByDate() + ")"; + return "\t[D]" + isDoneString + getDescription() + "(do by: " + getDate() + ")"; } } From e0a2e01bd7677a9b7df30e6549b89a9818a87a75 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Thu, 21 Sep 2023 00:17:31 +0800 Subject: [PATCH 24/77] throw error if event format is wrong --- src/main/java/Event.java | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 311ed2522..b912699c9 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -1,4 +1,4 @@ -public class Event extends Deadline { +public class Event extends Task { protected String startDate; protected String endDate; @@ -12,7 +12,7 @@ public Event(String echo) throws LukeTimeError { throw new LukeTimeError(); } - String taskDuration = taskDescription.substring(slashCut); + String taskDuration = taskDescription.substring(slashCut + 1); setDates(taskDuration); description = taskDescription.substring(0, slashCut); @@ -30,16 +30,28 @@ public String getEndDate() { return endDate; } - public void setDates(String dates) { - int spaceCut = dates.indexOf(" "); - dates = dates.substring(spaceCut + 1); + public void setDates(String dates) throws LukeTimeError { + String[] words = dates.split(" "); + if (!words[0].equals("from")) { + throw new LukeTimeError(); + } + + dates = dates.substring(5); int slashCut = dates.indexOf("/"); + if (slashCut <= 0) { + throw new LukeTimeError(); + } + startDate = dates.substring(0, slashCut); dates = dates.substring(slashCut + 1); - spaceCut = dates.indexOf(" "); - endDate = dates.substring(spaceCut + 1); + words = dates.split(" "); + if (!words[0].equals("to")) { + throw new LukeTimeError(); + } + + endDate = dates.substring(3); } @Override From 25200f018cf6f9d2198e677627d417b79410629c Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Thu, 21 Sep 2023 01:12:07 +0800 Subject: [PATCH 25/77] divide classes into packages --- src/main/java/Luke.java | 3 +++ src/main/java/{ => luke/constants}/ActionType.java | 2 ++ src/main/java/{ => luke/errors}/LukeTimeError.java | 1 + src/main/java/{ => luke/tasks}/Deadline.java | 4 ++++ src/main/java/{ => luke/tasks}/Event.java | 3 +++ src/main/java/{ => luke/tasks}/Task.java | 2 ++ src/main/java/{ => luke/tasks}/Todo.java | 2 ++ 7 files changed, 17 insertions(+) rename src/main/java/{ => luke/constants}/ActionType.java (74%) rename src/main/java/{ => luke/errors}/LukeTimeError.java (69%) rename src/main/java/{ => luke/tasks}/Deadline.java (95%) rename src/main/java/{ => luke/tasks}/Event.java (96%) rename src/main/java/{ => luke/tasks}/Task.java (95%) rename src/main/java/{ => luke/tasks}/Todo.java (96%) diff --git a/src/main/java/Luke.java b/src/main/java/Luke.java index b744f0a12..38a4b8214 100644 --- a/src/main/java/Luke.java +++ b/src/main/java/Luke.java @@ -1,3 +1,6 @@ +import luke.constants.*; +import luke.errors.LukeTimeError;; +import luke.tasks.*; import java.util.Scanner; public class Luke { diff --git a/src/main/java/ActionType.java b/src/main/java/luke/constants/ActionType.java similarity index 74% rename from src/main/java/ActionType.java rename to src/main/java/luke/constants/ActionType.java index 7047c5fea..89adc459e 100644 --- a/src/main/java/ActionType.java +++ b/src/main/java/luke/constants/ActionType.java @@ -1,3 +1,5 @@ +package luke.constants; + public enum ActionType { LIST, MARK, UNMARK, TODO, DEADLINE, EVENT } diff --git a/src/main/java/LukeTimeError.java b/src/main/java/luke/errors/LukeTimeError.java similarity index 69% rename from src/main/java/LukeTimeError.java rename to src/main/java/luke/errors/LukeTimeError.java index 0f1abc9f0..54538cc1d 100644 --- a/src/main/java/LukeTimeError.java +++ b/src/main/java/luke/errors/LukeTimeError.java @@ -1,2 +1,3 @@ +package luke.errors; public class LukeTimeError extends Exception { } \ No newline at end of file diff --git a/src/main/java/Deadline.java b/src/main/java/luke/tasks/Deadline.java similarity index 95% rename from src/main/java/Deadline.java rename to src/main/java/luke/tasks/Deadline.java index 7eca4fcf7..3fc1af2d0 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/luke/tasks/Deadline.java @@ -1,3 +1,7 @@ + +package luke.tasks; +import luke.errors.LukeTimeError; + public class Deadline extends Todo { protected String date; diff --git a/src/main/java/Event.java b/src/main/java/luke/tasks/Event.java similarity index 96% rename from src/main/java/Event.java rename to src/main/java/luke/tasks/Event.java index b912699c9..da04a5a09 100644 --- a/src/main/java/Event.java +++ b/src/main/java/luke/tasks/Event.java @@ -1,3 +1,6 @@ +package luke.tasks; +import luke.errors.LukeTimeError; + public class Event extends Task { protected String startDate; protected String endDate; diff --git a/src/main/java/Task.java b/src/main/java/luke/tasks/Task.java similarity index 95% rename from src/main/java/Task.java rename to src/main/java/luke/tasks/Task.java index ec8c89e3b..e845637be 100644 --- a/src/main/java/Task.java +++ b/src/main/java/luke/tasks/Task.java @@ -1,3 +1,5 @@ +package luke.tasks; + public abstract class Task { protected String description; protected boolean isDone; diff --git a/src/main/java/Todo.java b/src/main/java/luke/tasks/Todo.java similarity index 96% rename from src/main/java/Todo.java rename to src/main/java/luke/tasks/Todo.java index 8cdc562fc..0c5e56b6b 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/luke/tasks/Todo.java @@ -1,3 +1,5 @@ +package luke.tasks; + public class Todo extends Task { //protected boolean isDone; From 746312fad263e232ba7c600d54c1ed006e0f4e31 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Thu, 21 Sep 2023 01:13:32 +0800 Subject: [PATCH 26/77] fix lines --- src/main/java/Luke.java | 1 + src/main/java/luke/tasks/Deadline.java | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Luke.java b/src/main/java/Luke.java index 38a4b8214..f7cdfa00f 100644 --- a/src/main/java/Luke.java +++ b/src/main/java/Luke.java @@ -1,6 +1,7 @@ import luke.constants.*; import luke.errors.LukeTimeError;; import luke.tasks.*; + import java.util.Scanner; public class Luke { diff --git a/src/main/java/luke/tasks/Deadline.java b/src/main/java/luke/tasks/Deadline.java index 3fc1af2d0..c17d0a0a3 100644 --- a/src/main/java/luke/tasks/Deadline.java +++ b/src/main/java/luke/tasks/Deadline.java @@ -1,4 +1,3 @@ - package luke.tasks; import luke.errors.LukeTimeError; From ed9f860920ded57feedf8fee42a5337bbb9e6b9c Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Thu, 21 Sep 2023 16:01:10 +0800 Subject: [PATCH 27/77] use java collection classes, add "delete" action --- src/main/java/Luke.java | 48 +++++++++++++++----- src/main/java/luke/constants/ActionType.java | 2 +- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/main/java/Luke.java b/src/main/java/Luke.java index f7cdfa00f..d9fb645cb 100644 --- a/src/main/java/Luke.java +++ b/src/main/java/Luke.java @@ -3,10 +3,23 @@ import luke.tasks.*; import java.util.Scanner; +import java.util.ArrayList; public class Luke { private static final String BYE_COMMAND = "bye"; + private static final ArrayList taskList = new ArrayList<>(); + + private static void addTask(Task taskName) { + taskList.add(taskName); + //System.out.println(numbers); + } + + private static void removeTask(int taskNumber) { + taskList.remove(taskNumber); + //System.out.println(numbers); + } + public static void main(String[] args) { String logo = "\t _ _ \n" + "\t| | _ _| | _____ \n" @@ -17,7 +30,8 @@ public static void main(String[] args) { System.out.println("\t" + "Hello! I'm\n" + logo); System.out.println("\t" + "What can I do for you?"); - Task[] taskList = new Task[100]; + //Task[] taskList = new Task[100]; + Scanner userInput = new Scanner(System.in); int counter = 0; int taskNumber; @@ -35,37 +49,39 @@ public static void main(String[] args) { case LIST: System.out.println("\tHere are the tasks in your list:"); for (int i = 0; i < counter; i += 1) { - System.out.println("\t" + (i + 1) + "." + taskList[i]); + System.out.println("\t" + (i + 1) + "." + taskList.get(i)); } break; case MARK: taskNumber = Integer.parseInt(words[1]) - 1; System.out.println("\tWoohoo! You have accomplished:"); - taskList[taskNumber].setDone(true); - System.out.println(taskList[taskNumber]); + taskList.get(taskNumber).setDone(true); + System.out.println(taskList.get(taskNumber)); break; case UNMARK: taskNumber = Integer.parseInt(words[1]) - 1; System.out.println("\tHA! You still have to complete:"); - taskList[taskNumber].setDone(false); - System.out.println(taskList[taskNumber]); + taskList.get(taskNumber).setDone(false); + System.out.println(taskList.get(taskNumber)); break; case TODO: - taskList[counter] = new Todo(echo); + Task newTodo = new Todo(echo); + addTask(newTodo); - System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); + System.out.println("\tGot it. I've added this task:" + "\n" + taskList.get(counter)); counter += 1; System.out.println("\tNow you have " + counter + " tasks in the list."); break; case DEADLINE: try { - taskList[counter] = new Deadline(echo); + Task newDeadline = new Deadline(echo); + addTask(newDeadline); - System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); + System.out.println("\tGot it. I've added this task:" + "\n" + taskList.get(counter)); counter += 1; System.out.println("\tNow you have " + counter + " tasks in the list."); } catch (LukeTimeError e) { @@ -75,9 +91,10 @@ public static void main(String[] args) { case EVENT: try { - taskList[counter] = new Event(echo); + Task newEvent = new Event(echo); + addTask(newEvent); - System.out.println("\tGot it. I've added this task:" + "\n" + taskList[counter]); + System.out.println("\tGot it. I've added this task:" + "\n" + taskList.get(counter)); counter += 1; System.out.println("\tNow you have " + counter + " tasks in the list."); } catch (LukeTimeError e) { @@ -85,6 +102,13 @@ public static void main(String[] args) { } break; + case DELETE: + taskNumber = Integer.parseInt(words[1]) - 1; + System.out.println("\tNoted. I've removed this task:\n" + taskList.get(taskNumber)); + removeTask(taskNumber); + System.out.println("\tNow you have " + counter + " tasks in the list."); + counter -= 1; + break; default: assert false: "This line should never be reached"; break; diff --git a/src/main/java/luke/constants/ActionType.java b/src/main/java/luke/constants/ActionType.java index 89adc459e..ebb1867ad 100644 --- a/src/main/java/luke/constants/ActionType.java +++ b/src/main/java/luke/constants/ActionType.java @@ -1,5 +1,5 @@ package luke.constants; public enum ActionType { - LIST, MARK, UNMARK, TODO, DEADLINE, EVENT + LIST, MARK, UNMARK, TODO, DEADLINE, EVENT, DELETE } From 022d97d998248ebc123267e7b24b9be54ae939b0 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Thu, 21 Sep 2023 16:18:08 +0800 Subject: [PATCH 28/77] (notes: errors exist) adding memory storage using txt file --- src/main/java/Luke.java | 13 +++++++++++++ src/main/java/luke/files/RetrieveMemory.java | 16 ++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/main/java/luke/files/RetrieveMemory.java diff --git a/src/main/java/Luke.java b/src/main/java/Luke.java index f7cdfa00f..911f440fd 100644 --- a/src/main/java/Luke.java +++ b/src/main/java/Luke.java @@ -1,7 +1,9 @@ import luke.constants.*; import luke.errors.LukeTimeError;; import luke.tasks.*; +import luke.files.*; +import java.io.FileNotFoundException; import java.util.Scanner; public class Luke { @@ -15,6 +17,17 @@ public static void main(String[] args) { + "\t|_____|\\__,_|_|\\_\\___|\n"; System.out.println("\t" + "Hello! I'm\n" + logo); + + try { + RetrieveMemory.printFileContents("./luke/files/memory.txt"); + } catch (FileNotFoundException e) { + System.out.println("No existing memory."); + RetrieveMemory taskListFile = new RetrieveMemory ("./luke/files/memory.txt"); + if(taskListFile.exists() == false){ + taskListFile.createNewFile(); + } + } + System.out.println("\t" + "What can I do for you?"); Task[] taskList = new Task[100]; diff --git a/src/main/java/luke/files/RetrieveMemory.java b/src/main/java/luke/files/RetrieveMemory.java new file mode 100644 index 000000000..42a593ba3 --- /dev/null +++ b/src/main/java/luke/files/RetrieveMemory.java @@ -0,0 +1,16 @@ +package luke.files; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + +public class RetrieveMemory { + + public static void printFileContents(String filePath) throws FileNotFoundException { + File f = new File(filePath); // create a File for the given file path + Scanner s = new Scanner(f); // create a Scanner using the File as the source + while (s.hasNext()) { + System.out.println(s.nextLine()); + } + } +} \ No newline at end of file From e51e00074c5548447873e59c225b6f5f906f6be3 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Thu, 21 Sep 2023 17:49:39 +0800 Subject: [PATCH 29/77] ignore META-INF folder --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 2873e189e..242e2faef 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ bin/ /text-ui-test/ACTUAL.TXT text-ui-test/EXPECTED-UNIX.TXT + +/src/main/java/META-INF From 36fcba83e04a6810dde7f9c1d81f7873a1b685a0 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Thu, 21 Sep 2023 21:21:52 +0800 Subject: [PATCH 30/77] write new memory into memory.txt, ignore META-INF folder --- .gitignore | 2 + src/main/java/Luke.java | 30 +++++++++++---- src/main/java/luke/files/Memory.java | 39 ++++++++++++++++++++ src/main/java/luke/files/RetrieveMemory.java | 16 -------- 4 files changed, 63 insertions(+), 24 deletions(-) create mode 100644 src/main/java/luke/files/Memory.java delete mode 100644 src/main/java/luke/files/RetrieveMemory.java diff --git a/.gitignore b/.gitignore index 2873e189e..b8978a9b7 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ bin/ /text-ui-test/ACTUAL.TXT text-ui-test/EXPECTED-UNIX.TXT + +./src/main/java/META-INF \ No newline at end of file diff --git a/src/main/java/Luke.java b/src/main/java/Luke.java index 911f440fd..b4459c013 100644 --- a/src/main/java/Luke.java +++ b/src/main/java/Luke.java @@ -3,7 +3,9 @@ import luke.tasks.*; import luke.files.*; +import java.io.File; import java.io.FileNotFoundException; +import java.io.IOException; import java.util.Scanner; public class Luke { @@ -18,15 +20,20 @@ public static void main(String[] args) { System.out.println("\t" + "Hello! I'm\n" + logo); - try { - RetrieveMemory.printFileContents("./luke/files/memory.txt"); - } catch (FileNotFoundException e) { - System.out.println("No existing memory."); - RetrieveMemory taskListFile = new RetrieveMemory ("./luke/files/memory.txt"); - if(taskListFile.exists() == false){ - taskListFile.createNewFile(); - } + File taskListFile = new File("./luke/files/memory.txt"); + if (taskListFile.exists()) { + //Memory.readMemory("./memory.txt"); + } else { + //taskListFile.createNewFile(); } + //try { + + // } catch (FileNotFoundException e) { + System.out.println("No existing memory."); + File newMemory = new File("./luke/files/memory.txt"); + //Memory taskListFile = new Memory(); + //} + System.out.println("\t" + "What can I do for you?"); @@ -112,6 +119,13 @@ public static void main(String[] args) { echo = userInput.nextLine(); } + //store in memory.txt + try { + Memory.storeMemory("./src/main/java/luke/files/memory.txt", taskList, counter); + } catch (IOException e) { + System.out.println("IO Exception"); + } + System.out.println("\tBye. Hope to see you again soon!"); userInput.close(); diff --git a/src/main/java/luke/files/Memory.java b/src/main/java/luke/files/Memory.java new file mode 100644 index 000000000..41ffa556d --- /dev/null +++ b/src/main/java/luke/files/Memory.java @@ -0,0 +1,39 @@ +package luke.files; + +import luke.tasks.Task; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; +import java.io.FileWriter; + +import java.io.IOException; + +public class Memory { + + public static void readMemory(String filePath) throws FileNotFoundException { + File f = new File(filePath); // create a File for the given file path + Scanner s = new Scanner(f); // create a Scanner using the File as the source + while (s.hasNext()) { + System.out.println(s.nextLine()); + } + } + + public static void storeMemory(String filePath, Task[] taskList, int counter) throws IOException { + try { + FileWriter fw = new FileWriter(filePath); //overwrite file + + for (int i = 0; i < counter; i += 1) { + fw.write("\t" + (i + 1) + "." + taskList[i] + "\n"); + } + + fw.close(); + + } catch (IOException e) { + System.out.println("IO Exception, storeMemory fail"); + return; + } + + + } +} \ No newline at end of file diff --git a/src/main/java/luke/files/RetrieveMemory.java b/src/main/java/luke/files/RetrieveMemory.java deleted file mode 100644 index 42a593ba3..000000000 --- a/src/main/java/luke/files/RetrieveMemory.java +++ /dev/null @@ -1,16 +0,0 @@ -package luke.files; - -import java.io.File; -import java.io.FileNotFoundException; -import java.util.Scanner; - -public class RetrieveMemory { - - public static void printFileContents(String filePath) throws FileNotFoundException { - File f = new File(filePath); // create a File for the given file path - Scanner s = new Scanner(f); // create a Scanner using the File as the source - while (s.hasNext()) { - System.out.println(s.nextLine()); - } - } -} \ No newline at end of file From 0641727e09171dda5c46dbdc528fa89bd70eb723 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Thu, 21 Sep 2023 21:22:31 +0800 Subject: [PATCH 31/77] ignore META-INF folder --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b8978a9b7..41078d60a 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,4 @@ bin/ /text-ui-test/ACTUAL.TXT text-ui-test/EXPECTED-UNIX.TXT -./src/main/java/META-INF \ No newline at end of file +/src/main/java/META-INF \ No newline at end of file From af7f54cf567df193a38654d3fb868811aa05df87 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Thu, 21 Sep 2023 22:20:58 +0800 Subject: [PATCH 32/77] (still needs fixing) add read ability from existing file --- src/main/java/Luke.java | 27 +++++++++++---------- src/main/java/luke/files/Memory.java | 33 +++++++++++++++++++++++--- src/main/java/luke/tasks/Deadline.java | 15 +++++++++++- src/main/java/luke/tasks/Event.java | 13 ++++++++++ src/main/java/luke/tasks/Task.java | 12 ++++++++++ src/main/java/luke/tasks/Todo.java | 14 +++++++++++ 6 files changed, 98 insertions(+), 16 deletions(-) diff --git a/src/main/java/Luke.java b/src/main/java/Luke.java index b4459c013..4dc65be3e 100644 --- a/src/main/java/Luke.java +++ b/src/main/java/Luke.java @@ -20,20 +20,22 @@ public static void main(String[] args) { System.out.println("\t" + "Hello! I'm\n" + logo); - File taskListFile = new File("./luke/files/memory.txt"); - if (taskListFile.exists()) { - //Memory.readMemory("./memory.txt"); - } else { - //taskListFile.createNewFile(); - } - //try { - - // } catch (FileNotFoundException e) { + File taskListFile = new File("./src/main/java/luke/files/memory.txt"); + try { + if (taskListFile.exists()) { + Memory.readMemory("./src/main/java/luke/files/memory.txt"); + } else { + taskListFile.createNewFile(); + } + } catch (FileNotFoundException e) { System.out.println("No existing memory."); - File newMemory = new File("./luke/files/memory.txt"); + //File newMemory = new File("./luke/files/memory.txt"); //Memory taskListFile = new Memory(); - //} - + } catch (IOException e) { + System.out.println("IOException."); + } catch (SecurityException e) { + System.out.println("SecurityException."); + } System.out.println("\t" + "What can I do for you?"); @@ -122,6 +124,7 @@ public static void main(String[] args) { //store in memory.txt try { Memory.storeMemory("./src/main/java/luke/files/memory.txt", taskList, counter); + System.out.println("Memory Stored Safely!"); } catch (IOException e) { System.out.println("IO Exception"); } diff --git a/src/main/java/luke/files/Memory.java b/src/main/java/luke/files/Memory.java index 41ffa556d..2dbaf5ff5 100644 --- a/src/main/java/luke/files/Memory.java +++ b/src/main/java/luke/files/Memory.java @@ -1,10 +1,12 @@ package luke.files; -import luke.tasks.Task; +import luke.errors.LukeTimeError; +import luke.tasks.*; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; +import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; @@ -12,11 +14,36 @@ public class Memory { public static void readMemory(String filePath) throws FileNotFoundException { + File f = new File(filePath); // create a File for the given file path Scanner s = new Scanner(f); // create a Scanner using the File as the source while (s.hasNext()) { - System.out.println(s.nextLine()); + String currentLine = s.nextLine(); + + String taskDetails = currentLine.substring(0,5); + String taskDescription = currentLine.substring(4); + char[] characters = taskDetails.toCharArray(); + try { + switch (characters[4]) { + case 't': + Task newTodo = new Todo(taskDescription); + break; + case 'd': + Task newDeadline = new Deadline(taskDescription); + break; + case 'e': + Task newEvent = new Event(taskDescription); + break; + default: + break; + } + } catch (LukeTimeError e) { + System.out.println("somethings wrong"); + } + + System.out.println(currentLine); } + } public static void storeMemory(String filePath, Task[] taskList, int counter) throws IOException { @@ -24,7 +51,7 @@ public static void storeMemory(String filePath, Task[] taskList, int counter) th FileWriter fw = new FileWriter(filePath); //overwrite file for (int i = 0; i < counter; i += 1) { - fw.write("\t" + (i + 1) + "." + taskList[i] + "\n"); + fw.write(taskList[i].memoryString() + "\n"); } fw.close(); diff --git a/src/main/java/luke/tasks/Deadline.java b/src/main/java/luke/tasks/Deadline.java index c17d0a0a3..6dfbb3c8c 100644 --- a/src/main/java/luke/tasks/Deadline.java +++ b/src/main/java/luke/tasks/Deadline.java @@ -1,7 +1,7 @@ package luke.tasks; import luke.errors.LukeTimeError; -public class Deadline extends Todo { +public class Deadline extends Task { protected String date; public Deadline(String echo) throws LukeTimeError { @@ -49,4 +49,17 @@ public String toString() { return "\t[D]" + isDoneString + getDescription() + "(do by: " + getDate() + ")"; } + + @Override + public String memoryString() { + String isDoneString; + + if (isDone()) { + isDoneString = "[X]"; + } else { + isDoneString = "[ ]"; + } + + return isDoneString + " deadline " + getDescription() + "/by " + getDate(); + } } diff --git a/src/main/java/luke/tasks/Event.java b/src/main/java/luke/tasks/Event.java index da04a5a09..be2724c66 100644 --- a/src/main/java/luke/tasks/Event.java +++ b/src/main/java/luke/tasks/Event.java @@ -70,4 +70,17 @@ public String toString() { return "\t[E]" + isDoneString + getDescription() + "(from: " + getStartDate() + "to: " + getEndDate() + ")"; } + + @Override + public String memoryString() { + String isDoneString; + + if (isDone()) { + isDoneString = "[X]"; + } else { + isDoneString = "[ ]"; + } + + return isDoneString + " event " + getDescription() + "/from " + getStartDate() + "/to " + getEndDate(); + } } diff --git a/src/main/java/luke/tasks/Task.java b/src/main/java/luke/tasks/Task.java index e845637be..efd449ff8 100644 --- a/src/main/java/luke/tasks/Task.java +++ b/src/main/java/luke/tasks/Task.java @@ -26,4 +26,16 @@ public String toString() { return ""; } */ + public String memoryString() { + String isDoneString; + + if (isDone()) { + isDoneString = "[X]"; + } else { + isDoneString = "[ ]"; + } + + return isDoneString + " task " + getDescription(); + } + } \ No newline at end of file diff --git a/src/main/java/luke/tasks/Todo.java b/src/main/java/luke/tasks/Todo.java index 0c5e56b6b..90aab6f25 100644 --- a/src/main/java/luke/tasks/Todo.java +++ b/src/main/java/luke/tasks/Todo.java @@ -25,4 +25,18 @@ public String toString() { return "\t[T]" + isDoneString + getDescription(); } + + @Override + public String memoryString() { + String isDoneString; + + if (isDone()) { + isDoneString = "[X]"; + } else { + isDoneString = "[ ]"; + } + + return isDoneString + " todo " + getDescription(); + } + } From 0437cfba8f94df22e58c58a6f342ad1266ef1923 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Thu, 21 Sep 2023 22:38:29 +0800 Subject: [PATCH 33/77] (still needs fixing) able to read from file and write to file but unable to use file data --- .gitignore | 3 ++- src/main/java/luke/files/Memory.java | 17 +++++++++-------- src/main/java/luke/tasks/Deadline.java | 2 +- src/main/java/luke/tasks/Event.java | 2 +- src/main/java/luke/tasks/Task.java | 2 +- src/main/java/luke/tasks/Todo.java | 2 +- 6 files changed, 15 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 41078d60a..9807ceb61 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,5 @@ bin/ /text-ui-test/ACTUAL.TXT text-ui-test/EXPECTED-UNIX.TXT -/src/main/java/META-INF \ No newline at end of file +/src/main/java/META-INF +/out/production/ip/luke/files/memory.txt \ No newline at end of file diff --git a/src/main/java/luke/files/Memory.java b/src/main/java/luke/files/Memory.java index 2dbaf5ff5..547c3cbd2 100644 --- a/src/main/java/luke/files/Memory.java +++ b/src/main/java/luke/files/Memory.java @@ -19,19 +19,22 @@ public static void readMemory(String filePath) throws FileNotFoundException { Scanner s = new Scanner(f); // create a Scanner using the File as the source while (s.hasNext()) { String currentLine = s.nextLine(); + System.out.println(currentLine); - String taskDetails = currentLine.substring(0,5); - String taskDescription = currentLine.substring(4); + String taskDetails = currentLine.substring(0,6); + //System.out.println(taskDetails); + String taskDescription = currentLine.substring(7); + //System.out.println(taskDescription); char[] characters = taskDetails.toCharArray(); try { - switch (characters[4]) { - case 't': + switch (characters[1]) { + case 'T': Task newTodo = new Todo(taskDescription); break; - case 'd': + case 'D': Task newDeadline = new Deadline(taskDescription); break; - case 'e': + case 'E': Task newEvent = new Event(taskDescription); break; default: @@ -40,8 +43,6 @@ public static void readMemory(String filePath) throws FileNotFoundException { } catch (LukeTimeError e) { System.out.println("somethings wrong"); } - - System.out.println(currentLine); } } diff --git a/src/main/java/luke/tasks/Deadline.java b/src/main/java/luke/tasks/Deadline.java index 6dfbb3c8c..8531a7657 100644 --- a/src/main/java/luke/tasks/Deadline.java +++ b/src/main/java/luke/tasks/Deadline.java @@ -60,6 +60,6 @@ public String memoryString() { isDoneString = "[ ]"; } - return isDoneString + " deadline " + getDescription() + "/by " + getDate(); + return "[D]" + isDoneString + " deadline" + getDescription() + "/by " + getDate(); } } diff --git a/src/main/java/luke/tasks/Event.java b/src/main/java/luke/tasks/Event.java index be2724c66..245fe13e9 100644 --- a/src/main/java/luke/tasks/Event.java +++ b/src/main/java/luke/tasks/Event.java @@ -81,6 +81,6 @@ public String memoryString() { isDoneString = "[ ]"; } - return isDoneString + " event " + getDescription() + "/from " + getStartDate() + "/to " + getEndDate(); + return "[E]" + isDoneString + " event" + getDescription() + "/from " + getStartDate() + "/to " + getEndDate(); } } diff --git a/src/main/java/luke/tasks/Task.java b/src/main/java/luke/tasks/Task.java index efd449ff8..146b442f3 100644 --- a/src/main/java/luke/tasks/Task.java +++ b/src/main/java/luke/tasks/Task.java @@ -35,7 +35,7 @@ public String memoryString() { isDoneString = "[ ]"; } - return isDoneString + " task " + getDescription(); + return "[T]" + isDoneString + " task" + getDescription(); } } \ No newline at end of file diff --git a/src/main/java/luke/tasks/Todo.java b/src/main/java/luke/tasks/Todo.java index 90aab6f25..5462902ce 100644 --- a/src/main/java/luke/tasks/Todo.java +++ b/src/main/java/luke/tasks/Todo.java @@ -36,7 +36,7 @@ public String memoryString() { isDoneString = "[ ]"; } - return isDoneString + " todo " + getDescription(); + return "[T]" + isDoneString + " todo" + getDescription(); } } From 6494a32e8cb8cb73b9cd4097425cbdd8dbeb4140 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Thu, 21 Sep 2023 22:40:20 +0800 Subject: [PATCH 34/77] .gitignore for memory.txt --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9807ceb61..e4e8b982e 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,4 @@ bin/ text-ui-test/EXPECTED-UNIX.TXT /src/main/java/META-INF -/out/production/ip/luke/files/memory.txt \ No newline at end of file +/src/main/java/luke/files/memory.txt \ No newline at end of file From 652c9b29504a74b2ac3d4f84eb278bc96a873b8e Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Thu, 21 Sep 2023 23:15:07 +0800 Subject: [PATCH 35/77] can use file data --- src/main/java/Luke.java | 28 ++++++++++++---------------- src/main/java/luke/files/Memory.java | 9 ++++----- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/main/java/Luke.java b/src/main/java/Luke.java index a7555dbcf..d50a6f2c7 100644 --- a/src/main/java/Luke.java +++ b/src/main/java/Luke.java @@ -12,8 +12,8 @@ public class Luke { private static final String BYE_COMMAND = "bye"; - private static final ArrayList taskList = new ArrayList<>(); - private static int counter = 0; + private static ArrayList taskList = new ArrayList<>(); + private static void addTask(Task taskName) { taskList.add(taskName); @@ -37,7 +37,7 @@ public static void main(String[] args) { File taskListFile = new File("./src/main/java/luke/files/memory.txt"); try { if (taskListFile.exists()) { - Memory.readMemory("./src/main/java/luke/files/memory.txt", taskList, counter); + taskList = Memory.readMemory("./src/main/java/luke/files/memory.txt", taskList); } else { taskListFile.createNewFile(); } @@ -70,7 +70,7 @@ public static void main(String[] args) { switch (action) { case LIST: System.out.println("\tHere are the tasks in your list:"); - for (int i = 0; i < counter; i += 1) { + for (int i = 0; i < taskList.size(); i += 1) { System.out.println("\t" + (i + 1) + "." + taskList.get(i)); } break; @@ -93,9 +93,8 @@ public static void main(String[] args) { Task newTodo = new Todo(echo); addTask(newTodo); - System.out.println("\tGot it. I've added this task:" + "\n" + taskList.get(counter)); - counter += 1; - System.out.println("\tNow you have " + counter + " tasks in the list."); + System.out.println("\tGot it. I've added this task:" + "\n" + taskList.get(taskList.size() - 1)); + System.out.println("\tNow you have " + taskList.size() + " tasks in the list."); break; case DEADLINE: @@ -103,9 +102,8 @@ public static void main(String[] args) { Task newDeadline = new Deadline(echo); addTask(newDeadline); - System.out.println("\tGot it. I've added this task:" + "\n" + taskList.get(counter)); - counter += 1; - System.out.println("\tNow you have " + counter + " tasks in the list."); + System.out.println("\tGot it. I've added this task:" + "\n" + taskList.get(taskList.size() - 1)); + System.out.println("\tNow you have " + taskList.size() + " tasks in the list."); } catch (LukeTimeError e) { System.out.println("OOPS!!! There's an error in the deadline's 'do by' date."); } @@ -116,9 +114,8 @@ public static void main(String[] args) { Task newEvent = new Event(echo); addTask(newEvent); - System.out.println("\tGot it. I've added this task:" + "\n" + taskList.get(counter)); - counter += 1; - System.out.println("\tNow you have " + counter + " tasks in the list."); + System.out.println("\tGot it. I've added this task:" + "\n" + taskList.get(taskList.size() - 1)); + System.out.println("\tNow you have " + taskList.size() + " tasks in the list."); } catch (LukeTimeError e) { System.out.println("OOPS!!! There's an error in the event's start and end time."); } @@ -128,8 +125,7 @@ public static void main(String[] args) { taskNumber = Integer.parseInt(words[1]) - 1; System.out.println("\tNoted. I've removed this task:\n" + taskList.get(taskNumber)); removeTask(taskNumber); - System.out.println("\tNow you have " + counter + " tasks in the list."); - counter -= 1; + System.out.println("\tNow you have " + taskList.size() + " tasks in the list."); break; default: assert false: "This line should never be reached"; @@ -147,7 +143,7 @@ public static void main(String[] args) { //store in memory.txt try { - Memory.storeMemory("./src/main/java/luke/files/memory.txt", taskList, counter); + Memory.storeMemory("./src/main/java/luke/files/memory.txt", taskList); System.out.println("Memory Stored Safely!"); } catch (IOException e) { System.out.println("IO Exception"); diff --git a/src/main/java/luke/files/Memory.java b/src/main/java/luke/files/Memory.java index 37c39b8e7..4a046c14c 100644 --- a/src/main/java/luke/files/Memory.java +++ b/src/main/java/luke/files/Memory.java @@ -14,7 +14,7 @@ public class Memory { - public static void readMemory(String filePath, ArrayList taskList, int counter) throws FileNotFoundException { + public static ArrayList readMemory(String filePath, ArrayList taskList) throws FileNotFoundException { File f = new File(filePath); // create a File for the given file path Scanner s = new Scanner(f); // create a Scanner using the File as the source @@ -45,19 +45,18 @@ public static void readMemory(String filePath, ArrayList taskList, int cou } taskList.add(newTask); - counter += 1; } catch (LukeTimeError e) { System.out.println("somethings wrong"); } } - + return taskList; } - public static void storeMemory(String filePath, ArrayList taskList, int counter) throws IOException { + public static void storeMemory(String filePath, ArrayList taskList) throws IOException { try { FileWriter fw = new FileWriter(filePath); //overwrite file - for (int i = 0; i < counter; i += 1) { + for (int i = 0; i < taskList.size(); i += 1) { fw.write(taskList.get(i).memoryString() + "\n"); } From 51f7a9f5b4f71cdafd5da4241441f5ed241d6051 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Wed, 4 Oct 2023 20:14:58 +0800 Subject: [PATCH 36/77] fix indentation --- src/main/java/Luke.java | 44 +++++++++++++--------------- src/main/java/luke/files/Memory.java | 10 ++++--- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/main/java/Luke.java b/src/main/java/Luke.java index d50a6f2c7..4a1d5ce9f 100644 --- a/src/main/java/Luke.java +++ b/src/main/java/Luke.java @@ -35,23 +35,25 @@ public static void main(String[] args) { System.out.println("\t" + "Hello! I'm\n" + logo); File taskListFile = new File("./src/main/java/luke/files/memory.txt"); - try { if (taskListFile.exists()) { - taskList = Memory.readMemory("./src/main/java/luke/files/memory.txt", taskList); + try { + taskList = Memory.readMemory("./src/main/java/luke/files/memory.txt", taskList); + System.out.println("\n\tMemory retrieval successful!\n"); + } catch (FileNotFoundException e) { + System.out.println("\tNo existing memory. (1)"); + } } else { - taskListFile.createNewFile(); + try { + taskListFile.createNewFile(); + System.out.println("\tNo existing memory."); + } catch (IOException e) { + System.out.println("\tIOException."); + } catch (SecurityException e) { + System.out.println("\tSecurityException."); + } } - } catch (FileNotFoundException e) { - System.out.println("No existing memory."); - //File newMemory = new File("./luke/files/memory.txt"); - //Memory taskListFile = new Memory(); - } catch (IOException e) { - System.out.println("IOException."); - } catch (SecurityException e) { - System.out.println("SecurityException."); - } - System.out.println("\t" + "What can I do for you?"); + System.out.println("\tWhat can I do for you?"); //Task[] taskList = new Task[100]; @@ -105,7 +107,7 @@ public static void main(String[] args) { System.out.println("\tGot it. I've added this task:" + "\n" + taskList.get(taskList.size() - 1)); System.out.println("\tNow you have " + taskList.size() + " tasks in the list."); } catch (LukeTimeError e) { - System.out.println("OOPS!!! There's an error in the deadline's 'do by' date."); + System.out.println("\tOOPS!!! There's an error in the deadline's 'do by' date."); } break; @@ -117,7 +119,7 @@ public static void main(String[] args) { System.out.println("\tGot it. I've added this task:" + "\n" + taskList.get(taskList.size() - 1)); System.out.println("\tNow you have " + taskList.size() + " tasks in the list."); } catch (LukeTimeError e) { - System.out.println("OOPS!!! There's an error in the event's start and end time."); + System.out.println("\tOOPS!!! There's an error in the event's start and end time."); } break; @@ -132,22 +134,18 @@ public static void main(String[] args) { break; } } catch (IndexOutOfBoundsException e) { //empty for MARK, UNMARK, TO DO description, DEADLINE description, EVENT description - System.out.println("OOPS!!! You have missing arguments for " + words[0] + "."); + System.out.println("\tOOPS!!! You have missing arguments for " + words[0] + "."); } } catch (IllegalArgumentException e) { - System.out.println("OOPS!!! I'm sorry, but I don't know what that means :-("); + System.out.println("\tOOPS!!! I'm sorry, but I don't know what that means :-("); } echo = userInput.nextLine(); } //store in memory.txt - try { - Memory.storeMemory("./src/main/java/luke/files/memory.txt", taskList); - System.out.println("Memory Stored Safely!"); - } catch (IOException e) { - System.out.println("IO Exception"); - } + + Memory.storeMemory("./src/main/java/luke/files/memory.txt", taskList); System.out.println("\tBye. Hope to see you again soon!"); diff --git a/src/main/java/luke/files/Memory.java b/src/main/java/luke/files/Memory.java index 4a046c14c..0db4e1c94 100644 --- a/src/main/java/luke/files/Memory.java +++ b/src/main/java/luke/files/Memory.java @@ -20,7 +20,7 @@ public static ArrayList readMemory(String filePath, ArrayList taskLi Scanner s = new Scanner(f); // create a Scanner using the File as the source while (s.hasNext()) { String currentLine = s.nextLine(); - System.out.println(currentLine); + System.out.println("\t" + currentLine); String taskDetails = currentLine.substring(0,6); //System.out.println(taskDetails); @@ -46,13 +46,13 @@ public static ArrayList readMemory(String filePath, ArrayList taskLi taskList.add(newTask); } catch (LukeTimeError e) { - System.out.println("somethings wrong"); + System.out.println("\tsomethings wrong"); } } return taskList; } - public static void storeMemory(String filePath, ArrayList taskList) throws IOException { + public static void storeMemory(String filePath, ArrayList taskList){ try { FileWriter fw = new FileWriter(filePath); //overwrite file @@ -62,8 +62,10 @@ public static void storeMemory(String filePath, ArrayList taskList) throws fw.close(); + System.out.println("\tMemory Stored Safely!"); + } catch (IOException e) { - System.out.println("IO Exception, storeMemory fail"); + System.out.println("\tIO Exception: fail to store memory"); return; } From 4bcd01daed6d458b2eff46a3161e680dc6702215 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Wed, 4 Oct 2023 20:26:51 +0800 Subject: [PATCH 37/77] fix indentation --- src/main/java/Luke.java | 1 - src/main/java/luke/files/Memory.java | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/Luke.java b/src/main/java/Luke.java index 4a1d5ce9f..709e1fae5 100644 --- a/src/main/java/Luke.java +++ b/src/main/java/Luke.java @@ -14,7 +14,6 @@ public class Luke { private static ArrayList taskList = new ArrayList<>(); - private static void addTask(Task taskName) { taskList.add(taskName); //System.out.println(numbers); diff --git a/src/main/java/luke/files/Memory.java b/src/main/java/luke/files/Memory.java index 0db4e1c94..496bd296c 100644 --- a/src/main/java/luke/files/Memory.java +++ b/src/main/java/luke/files/Memory.java @@ -6,7 +6,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; -import java.io.FileReader; +//import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; @@ -66,9 +66,8 @@ public static void storeMemory(String filePath, ArrayList taskList){ } catch (IOException e) { System.out.println("\tIO Exception: fail to store memory"); - return; + //return; } - } } \ No newline at end of file From 801ed7899bed6b12a01344dda0b0f13431f86644 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Wed, 4 Oct 2023 20:38:54 +0800 Subject: [PATCH 38/77] Add "find" ActionType --- src/main/java/Luke.java | 12 ++++++++++++ src/main/java/luke/constants/ActionType.java | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/Luke.java b/src/main/java/Luke.java index 709e1fae5..cf5dffff2 100644 --- a/src/main/java/Luke.java +++ b/src/main/java/Luke.java @@ -76,6 +76,18 @@ public static void main(String[] args) { } break; + case FIND: + String findWord = echo.substring(4); + System.out.println("\tHere are the matching tasks in your list:"); + int j = 1; + for (int i = 0; i < taskList.size(); i += 1) { + if (taskList.get(i).getDescription().contains(findWord)) { + System.out.println("\t" + j + "." + taskList.get(i)); + j += 1; + } + } + break; + case MARK: taskNumber = Integer.parseInt(words[1]) - 1; System.out.println("\tWoohoo! You have accomplished:"); diff --git a/src/main/java/luke/constants/ActionType.java b/src/main/java/luke/constants/ActionType.java index ebb1867ad..f2ddf4a17 100644 --- a/src/main/java/luke/constants/ActionType.java +++ b/src/main/java/luke/constants/ActionType.java @@ -1,5 +1,5 @@ package luke.constants; public enum ActionType { - LIST, MARK, UNMARK, TODO, DEADLINE, EVENT, DELETE + LIST, FIND, MARK, UNMARK, TODO, DEADLINE, EVENT, DELETE } From 39eda3c7bd82b02262322c1e262a0d753d058780 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Thu, 5 Oct 2023 16:49:30 +0800 Subject: [PATCH 39/77] Add Objects (Ui & Parser) --- src/main/java/luke/actions/Parser.java | 63 ++++++++++++++++++++++++++ src/main/java/luke/user/Ui.java | 44 ++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 src/main/java/luke/actions/Parser.java create mode 100644 src/main/java/luke/user/Ui.java diff --git a/src/main/java/luke/actions/Parser.java b/src/main/java/luke/actions/Parser.java new file mode 100644 index 000000000..dc9d985b3 --- /dev/null +++ b/src/main/java/luke/actions/Parser.java @@ -0,0 +1,63 @@ +package luke.actions; + +import luke.tasks.Deadline; +import luke.tasks.Event; +import luke.tasks.Task; +import luke.tasks.Todo; +import luke.user.LukeTimeError; + +public class Parser { + //user input from Ui to luke command to Command + + public static Command parse(String fullCommand) { + ActionType theAction; + String parameters = ""; + + String[] words = fullCommand.split(" "); //to identify usage of features "mark" & "unmark" + + try { + ActionType action = ActionType.valueOf(words[0].toUpperCase()); + theAction = action; + + try { + switch (action) { + case LIST: + parameters = ""; + break; + + case FIND: + parameters = fullCommand.substring(4); + break; + + case MARK: case UNMARK: case DELETE: + parameters = words[1]; + break; + + case TODO: + parameters = fullCommand.substring(4); + break; + + case DEADLINE: + parameters = fullCommand.substring(8); + break; + + case EVENT: + parameters = fullCommand.substring(5); + break; + + default: + assert false: "This line should never be reached"; + break; + } + } catch (IndexOutOfBoundsException e) { //empty for MARK, UNMARK, TO DO description, DEADLINE description, EVENT description + System.out.println("\tOOPS!!! You have missing arguments for " + words[0] + "."); + } + Command c = new Command(theAction, parameters); + return c; + } catch (IllegalArgumentException e) { + System.out.println("\tOOPS!!! I'm sorry, but I don't know what that means :-("); + } + return null; + + } +} diff --git a/src/main/java/luke/user/Ui.java b/src/main/java/luke/user/Ui.java new file mode 100644 index 000000000..89f2a92a0 --- /dev/null +++ b/src/main/java/luke/user/Ui.java @@ -0,0 +1,44 @@ +package luke.user; + +import java.util.Scanner; + +public class Ui { + //directly interact with user (read in (to Parser)/print) + public String echo; + public Scanner userInput; + public Ui () { + userInput = new Scanner(System.in); + } + + //decompiler + //userInput.close(); + + public void showWelcome() { + String logo = "\t _ _ \n" + + "\t| | _ _| | _____ \n" + + "\t| | | | | | |/ / _ \\\n" + + "\t| |___| |_| | < __/\n" + + "\t|_____|\\__,_|_|\\_\\___|\n"; + + System.out.println("\t" + "Hello! I'm\n" + logo); + System.out.println("\tWhat can I do for you?"); + } + + public void showLine() { + // show the divider line ("_______") + System.out.println("__________________ (pls change)") + } + public void showLoadingError() { + System.out.println("Loading Error... (pls change)"); + } + + public void showError(String error) { + System.out.println(error); + } + + public String readCommand() { + echo = userInput.nextLine(); + return echo; + } + +} From 18a66435972120e4c088393dd6bb846fa3c60a83 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Thu, 5 Oct 2023 16:58:42 +0800 Subject: [PATCH 40/77] Add Objects (ExitCommand) --- src/main/java/luke/actions/ExitCommand.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/java/luke/actions/ExitCommand.java diff --git a/src/main/java/luke/actions/ExitCommand.java b/src/main/java/luke/actions/ExitCommand.java new file mode 100644 index 000000000..cb35e17cc --- /dev/null +++ b/src/main/java/luke/actions/ExitCommand.java @@ -0,0 +1,20 @@ +package luke.actions; + +import luke.files.Storage; +import luke.tasks.TaskList; +import luke.user.Ui; + +public class ExitCommand extends Command { + //bye input + public ExitCommand(ActionType theAction, String parameters) { + super(theAction, parameters); + } + + @Override + public void execute(TaskList tasks, Ui ui, Storage storage) { + //ui has String echo, storage has ArrayList tasks, tasks has ArrayList mainTaskList; + + storage.store(tasks); + ui.closeUi(); + } +} From bf62341bc9fcab2bd8c3cbacd01d346e8d009484 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Thu, 5 Oct 2023 17:34:18 +0800 Subject: [PATCH 41/77] Add Objects (DeleteCommand) --- src/main/java/luke/actions/DeleteCommand.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/main/java/luke/actions/DeleteCommand.java diff --git a/src/main/java/luke/actions/DeleteCommand.java b/src/main/java/luke/actions/DeleteCommand.java new file mode 100644 index 000000000..c188913f9 --- /dev/null +++ b/src/main/java/luke/actions/DeleteCommand.java @@ -0,0 +1,25 @@ +package luke.actions; + +import luke.files.Storage; +import luke.tasks.TaskList; +import luke.user.Ui; + +public class DeleteCommand extends Command { + public DeleteCommand(ActionType theAction, String parameters) { + super(theAction, parameters); + } + + @Override + public void execute(TaskList tasks, Ui ui, Storage storage) { + //ui has String echo, storage has ArrayList tasks, tasks has ArrayList mainTaskList; + + try { + int taskNumber = Integer.parseInt(parameters) - 1; + System.out.println("\tNoted. I've removed this task:\n" + tasks.get(taskNumber)); + tasks.removeTask(taskNumber); + System.out.println("\tNow you have " + tasks.size() + " tasks in the list."); + } catch (IndexOutOfBoundsException e) { //empty for MARK, UNMARK, TO DO description, DEADLINE description, EVENT description + System.out.println("\tOOPS!!! You have missing arguments for " + theAction + "."); + } + } +} From 56321ce34ddd464d62757fd60b9011eca9a942d2 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Thu, 5 Oct 2023 17:36:10 +0800 Subject: [PATCH 42/77] Add Objects (ListCommand) --- src/main/java/luke/actions/ListCommand.java | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/main/java/luke/actions/ListCommand.java diff --git a/src/main/java/luke/actions/ListCommand.java b/src/main/java/luke/actions/ListCommand.java new file mode 100644 index 000000000..cc79ad763 --- /dev/null +++ b/src/main/java/luke/actions/ListCommand.java @@ -0,0 +1,23 @@ +package luke.actions; + +import luke.files.Storage; +import luke.tasks.TaskList; +import luke.user.Ui; + +public class ListCommand extends Command { + public ListCommand(ActionType theAction, String parameters) { + super(theAction, parameters); + } + + @Override + public void execute(TaskList tasks, Ui ui, Storage storage) { + //ui has String echo, storage has ArrayList tasks, tasks has ArrayList mainTaskList; + + + System.out.println("\tHere are the tasks in your list:"); + for (int i = 0; i < tasks.size(); i += 1) { + System.out.println("\t" + (i + 1) + "." + tasks.get(i)); + } + + } +} From 48815a3ef80390ca64875188478f80d997c3d632 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Thu, 5 Oct 2023 17:39:11 +0800 Subject: [PATCH 43/77] Add Objects (FindCommand) --- src/main/java/luke/actions/FindCommand.java | 27 +++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/main/java/luke/actions/FindCommand.java diff --git a/src/main/java/luke/actions/FindCommand.java b/src/main/java/luke/actions/FindCommand.java new file mode 100644 index 000000000..2a8ebfa02 --- /dev/null +++ b/src/main/java/luke/actions/FindCommand.java @@ -0,0 +1,27 @@ +package luke.actions; + +import luke.files.Storage; +import luke.tasks.TaskList; +import luke.user.Ui; + +public class FindCommand extends Command { + public FindCommand(ActionType theAction, String parameters) { + super(theAction, parameters); + } + + @Override + public void execute(TaskList tasks, Ui ui, Storage storage) { + //ui has String echo, storage has ArrayList tasks, tasks has ArrayList mainTaskList; + //command has theActionWord and parameters + + //String findWord = ui.echo.substring(4); + System.out.println("\tHere are the matching tasks in your list:"); + int j = 1; + for (int i = 0; i < tasks.size(); i += 1) { + if (tasks.get(i).getDescription().contains(parameters)) { + System.out.println("\t" + j + "." + tasks.get(i)); + j += 1; + } + } + } +} From ef5a710f9fecf8a5b7e49b148d9b53e03a6b4ea1 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Thu, 5 Oct 2023 17:41:26 +0800 Subject: [PATCH 44/77] make more OOP but with errors --- src/main/java/Luke.java | 184 ++++-------------- .../{constants => actions}/ActionType.java | 2 +- src/main/java/luke/actions/AddCommand.java | 53 +++++ src/main/java/luke/actions/Command.java | 62 ++++++ src/main/java/luke/errors/LukeTimeError.java | 3 - src/main/java/luke/files/Memory.java | 10 +- src/main/java/luke/files/Storage.java | 51 +++++ src/main/java/luke/tasks/Deadline.java | 2 +- src/main/java/luke/tasks/Event.java | 2 +- src/main/java/luke/tasks/TaskList.java | 42 ++++ src/main/java/luke/user/LukeTimeError.java | 8 + src/main/java/luke/user/Ui.java | 6 +- 12 files changed, 269 insertions(+), 156 deletions(-) rename src/main/java/luke/{constants => actions}/ActionType.java (78%) create mode 100644 src/main/java/luke/actions/AddCommand.java create mode 100644 src/main/java/luke/actions/Command.java delete mode 100644 src/main/java/luke/errors/LukeTimeError.java create mode 100644 src/main/java/luke/files/Storage.java create mode 100644 src/main/java/luke/tasks/TaskList.java create mode 100644 src/main/java/luke/user/LukeTimeError.java diff --git a/src/main/java/Luke.java b/src/main/java/Luke.java index cf5dffff2..c5fa322ae 100644 --- a/src/main/java/Luke.java +++ b/src/main/java/Luke.java @@ -1,166 +1,62 @@ -import luke.constants.*; -import luke.errors.LukeTimeError;; + +import luke.actions.*; +import luke.user.LukeTimeError; +import luke.user.Ui; import luke.tasks.*; import luke.files.*; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.Scanner; import java.util.ArrayList; public class Luke { - private static final String BYE_COMMAND = "bye"; - - private static ArrayList taskList = new ArrayList<>(); - - private static void addTask(Task taskName) { - taskList.add(taskName); - //System.out.println(numbers); + private Storage storage; + private TaskList tasks; + private Ui ui; + + public Luke(String filePath) { + ui = new Ui(); + storage = new Storage(filePath); + try { + tasks = new TaskList(storage.load()); + } catch (LukeTimeError e) { + ui.showLoadingError(); + tasks = new TaskList(); + } } - private static void removeTask(int taskNumber) { - taskList.remove(taskNumber); - //System.out.println(numbers); - } - public static void main(String[] args) { - String logo = "\t _ _ \n" - + "\t| | _ _| | _____ \n" - + "\t| | | | | | |/ / _ \\\n" - + "\t| |___| |_| | < __/\n" - + "\t|_____|\\__,_|_|\\_\\___|\n"; + private static final String BYE_COMMAND = "bye"; - System.out.println("\t" + "Hello! I'm\n" + logo); + private static ArrayList taskList = new ArrayList<>(); - File taskListFile = new File("./src/main/java/luke/files/memory.txt"); - if (taskListFile.exists()) { - try { - taskList = Memory.readMemory("./src/main/java/luke/files/memory.txt", taskList); - System.out.println("\n\tMemory retrieval successful!\n"); - } catch (FileNotFoundException e) { - System.out.println("\tNo existing memory. (1)"); - } - } else { - try { - taskListFile.createNewFile(); - System.out.println("\tNo existing memory."); - } catch (IOException e) { - System.out.println("\tIOException."); - } catch (SecurityException e) { - System.out.println("\tSecurityException."); - } + public void run() { + ui.showWelcome(); + boolean isExit = false; + while (!isExit) { + try { + String fullCommand = ui.readCommand(); + ui.showLine(); // show the divider line ("_______") + Command c = Parser.parse(fullCommand); + c.execute(tasks, ui, storage); + isExit = c.isExit(); //for bye command + } catch (LukeTimeError e) { //from c.execute i think + ui.showError(e.getMessage()); + } finally { + ui.showLine(); } + } - System.out.println("\tWhat can I do for you?"); + } + public void run() { //Task[] taskList = new Task[100]; - Scanner userInput = new Scanner(System.in); int taskNumber; - String echo = userInput.nextLine(); - - while (!echo.equals(BYE_COMMAND)) { - String[] words = echo.split(" "); //to identify usage of features "mark" & "unmark" - - try { - ActionType action = ActionType.valueOf(words[0].toUpperCase()); - - try { - switch (action) { - case LIST: - System.out.println("\tHere are the tasks in your list:"); - for (int i = 0; i < taskList.size(); i += 1) { - System.out.println("\t" + (i + 1) + "." + taskList.get(i)); - } - break; - - case FIND: - String findWord = echo.substring(4); - System.out.println("\tHere are the matching tasks in your list:"); - int j = 1; - for (int i = 0; i < taskList.size(); i += 1) { - if (taskList.get(i).getDescription().contains(findWord)) { - System.out.println("\t" + j + "." + taskList.get(i)); - j += 1; - } - } - break; - - case MARK: - taskNumber = Integer.parseInt(words[1]) - 1; - System.out.println("\tWoohoo! You have accomplished:"); - taskList.get(taskNumber).setDone(true); - System.out.println(taskList.get(taskNumber)); - break; - - case UNMARK: - taskNumber = Integer.parseInt(words[1]) - 1; - System.out.println("\tHA! You still have to complete:"); - taskList.get(taskNumber).setDone(false); - System.out.println(taskList.get(taskNumber)); - break; - - case TODO: - Task newTodo = new Todo(echo); - addTask(newTodo); - - System.out.println("\tGot it. I've added this task:" + "\n" + taskList.get(taskList.size() - 1)); - System.out.println("\tNow you have " + taskList.size() + " tasks in the list."); - break; - - case DEADLINE: - try { - Task newDeadline = new Deadline(echo); - addTask(newDeadline); - - System.out.println("\tGot it. I've added this task:" + "\n" + taskList.get(taskList.size() - 1)); - System.out.println("\tNow you have " + taskList.size() + " tasks in the list."); - } catch (LukeTimeError e) { - System.out.println("\tOOPS!!! There's an error in the deadline's 'do by' date."); - } - break; - - case EVENT: - try { - Task newEvent = new Event(echo); - addTask(newEvent); - - System.out.println("\tGot it. I've added this task:" + "\n" + taskList.get(taskList.size() - 1)); - System.out.println("\tNow you have " + taskList.size() + " tasks in the list."); - } catch (LukeTimeError e) { - System.out.println("\tOOPS!!! There's an error in the event's start and end time."); - } - break; - - case DELETE: - taskNumber = Integer.parseInt(words[1]) - 1; - System.out.println("\tNoted. I've removed this task:\n" + taskList.get(taskNumber)); - removeTask(taskNumber); - System.out.println("\tNow you have " + taskList.size() + " tasks in the list."); - break; - default: - assert false: "This line should never be reached"; - break; - } - } catch (IndexOutOfBoundsException e) { //empty for MARK, UNMARK, TO DO description, DEADLINE description, EVENT description - System.out.println("\tOOPS!!! You have missing arguments for " + words[0] + "."); - } - } catch (IllegalArgumentException e) { - System.out.println("\tOOPS!!! I'm sorry, but I don't know what that means :-("); - } - - echo = userInput.nextLine(); - } - - //store in memory.txt - - Memory.storeMemory("./src/main/java/luke/files/memory.txt", taskList); - - System.out.println("\tBye. Hope to see you again soon!"); + } - userInput.close(); + public static void main(String[] args) { + new Luke("data/tasks.txt").run(); + //that was the only line } } diff --git a/src/main/java/luke/constants/ActionType.java b/src/main/java/luke/actions/ActionType.java similarity index 78% rename from src/main/java/luke/constants/ActionType.java rename to src/main/java/luke/actions/ActionType.java index f2ddf4a17..bd0e89bbc 100644 --- a/src/main/java/luke/constants/ActionType.java +++ b/src/main/java/luke/actions/ActionType.java @@ -1,4 +1,4 @@ -package luke.constants; +package luke.actions; public enum ActionType { LIST, FIND, MARK, UNMARK, TODO, DEADLINE, EVENT, DELETE diff --git a/src/main/java/luke/actions/AddCommand.java b/src/main/java/luke/actions/AddCommand.java new file mode 100644 index 000000000..ef630ccd1 --- /dev/null +++ b/src/main/java/luke/actions/AddCommand.java @@ -0,0 +1,53 @@ +package luke.actions; + +import luke.files.Storage; +import luke.tasks.*; +import luke.user.LukeTimeError; +import luke.user.Ui; + +public class AddCommand extends Command { + public AddCommand(ActionType theAction, String parameters) { + + super(theAction, parameters); + } + + @Override + public void execute(TaskList tasks, Ui ui, Storage storage) { + //ui has String echo, storage has ArrayList tasks, tasks has ArrayList mainTaskList; + + case TODO: + Task newTodo = new Todo(echo); + addTask(newTodo); + + System.out.println("\tGot it. I've added this task:" + "\n" + taskList.get(taskList.size() - 1)); + System.out.println("\tNow you have " + taskList.size() + " tasks in the list."); + break; + + case DEADLINE: + try { + Task newDeadline = new Deadline(echo); + addTask(newDeadline); + + System.out.println("\tGot it. I've added this task:" + "\n" + taskList.get(taskList.size() - 1)); + System.out.println("\tNow you have " + taskList.size() + " tasks in the list."); + } catch (LukeTimeError e) { + System.out.println("\tOOPS!!! There's an error in the deadline's 'do by' date."); + } + break; + + case EVENT: + try { + Task newEvent = new Event(echo); + addTask(newEvent); + + System.out.println("\tGot it. I've added this task:" + "\n" + taskList.get(taskList.size() - 1)); + System.out.println("\tNow you have " + taskList.size() + " tasks in the list."); + } catch (LukeTimeError e) { + System.out.println("\tOOPS!!! There's an error in the event's start and end time."); + } + break; + } catch (IndexOutOfBoundsException e) { //empty for MARK, UNMARK, TO DO description, DEADLINE description, EVENT description + System.out.println("\tOOPS!!! You have missing arguments for " + words[0] + "."); + } + } +} diff --git a/src/main/java/luke/actions/Command.java b/src/main/java/luke/actions/Command.java new file mode 100644 index 000000000..44a09fa23 --- /dev/null +++ b/src/main/java/luke/actions/Command.java @@ -0,0 +1,62 @@ +package luke.actions; + +import luke.files.Storage; +import luke.tasks.*; +import luke.user.LukeTimeError; +import luke.user.Ui; + +public abstract class Command { + protected ActionType theAction; + protected String parameters; //no. or description + public Command(ActionType theAction, String parameters) { + this.theAction = theAction; + this.parameters = parameters; + } + private boolean isExit; + public void execute(TaskList tasks, Ui ui, Storage storage) { + + //ui has String echo, storage has ArrayList tasks, tasks has ArrayList mainTaskList; + + String[] words = echo.split(" "); //to identify usage of features "mark" & "unmark" + + try { + ActionType action = ActionType.valueOf(words[0].toUpperCase()); + + try { + switch (action) { + + case MARK: + taskNumber = Integer.parseInt(words[1]) - 1; + System.out.println("\tWoohoo! You have accomplished:"); + taskList.get(taskNumber).setDone(true); + System.out.println(taskList.get(taskNumber)); + break; + + case UNMARK: + taskNumber = Integer.parseInt(words[1]) - 1; + System.out.println("\tHA! You still have to complete:"); + taskList.get(taskNumber).setDone(false); + System.out.println(taskList.get(taskNumber)); + break; + + default: + assert false: "This line should never be reached"; + break; + + + } + } catch (IndexOutOfBoundsException e) { //empty for MARK, UNMARK, TO DO description, DEADLINE description, EVENT description + System.out.println("\tOOPS!!! You have missing arguments for " + words[0] + "."); + } + } catch (IllegalArgumentException e) { + System.out.println("\tOOPS!!! I'm sorry, but I don't know what that means :-("); + } + + echo = userInput.nextLine(); + + } + + public boolean isExit() { + return isExit; + } +} diff --git a/src/main/java/luke/errors/LukeTimeError.java b/src/main/java/luke/errors/LukeTimeError.java deleted file mode 100644 index 54538cc1d..000000000 --- a/src/main/java/luke/errors/LukeTimeError.java +++ /dev/null @@ -1,3 +0,0 @@ -package luke.errors; -public class LukeTimeError extends Exception { -} \ No newline at end of file diff --git a/src/main/java/luke/files/Memory.java b/src/main/java/luke/files/Memory.java index 496bd296c..6c4618ebe 100644 --- a/src/main/java/luke/files/Memory.java +++ b/src/main/java/luke/files/Memory.java @@ -1,6 +1,6 @@ package luke.files; -import luke.errors.LukeTimeError; +import luke.user.LukeTimeError; import luke.tasks.*; import java.io.File; @@ -14,7 +14,9 @@ public class Memory { - public static ArrayList readMemory(String filePath, ArrayList taskList) throws FileNotFoundException { + public static ArrayList readMemory(String filePath) throws FileNotFoundException { + + ArrayList tasks = new ArrayList<>(); File f = new File(filePath); // create a File for the given file path Scanner s = new Scanner(f); // create a Scanner using the File as the source @@ -44,12 +46,12 @@ public static ArrayList readMemory(String filePath, ArrayList taskLi break; } - taskList.add(newTask); + tasks.add(newTask); } catch (LukeTimeError e) { System.out.println("\tsomethings wrong"); } } - return taskList; + return tasks; } public static void storeMemory(String filePath, ArrayList taskList){ diff --git a/src/main/java/luke/files/Storage.java b/src/main/java/luke/files/Storage.java new file mode 100644 index 000000000..d14526d08 --- /dev/null +++ b/src/main/java/luke/files/Storage.java @@ -0,0 +1,51 @@ +package luke.files; + +import luke.tasks.Task; +import luke.tasks.TaskList; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; + +public class Storage { + private ArrayList tasks; + + public Storage(String filePath) { + + + File taskListFile = new File("./src/main/java/luke/files/memory.txt"); + if (taskListFile.exists()) { + try { + tasks = Memory.readMemory("./src/main/java/luke/files/memory.txt"); + System.out.println("\n\tMemory retrieval successful!\n"); + //return tasks; + } catch (FileNotFoundException e) { + System.out.println("\tNo existing memory. (1)"); + } + } else { + try { + taskListFile.createNewFile(); + System.out.println("\tNo existing memory."); + } catch (IOException e) { + System.out.println("\tIOException."); + } catch (SecurityException e) { + System.out.println("\tSecurityException."); + } + } + //return null; + + } + + public ArrayList load() { + return tasks; + } + + public void store(TaskList tasksToStore) { + //store in memory.txt + + Memory.storeMemory("./src/main/java/luke/files/memory.txt", tasksToStore); + + System.out.println("\tBye. Hope to see you again soon!"); + } +} diff --git a/src/main/java/luke/tasks/Deadline.java b/src/main/java/luke/tasks/Deadline.java index 8531a7657..97f5b7624 100644 --- a/src/main/java/luke/tasks/Deadline.java +++ b/src/main/java/luke/tasks/Deadline.java @@ -1,5 +1,5 @@ package luke.tasks; -import luke.errors.LukeTimeError; +import luke.user.LukeTimeError; public class Deadline extends Task { protected String date; diff --git a/src/main/java/luke/tasks/Event.java b/src/main/java/luke/tasks/Event.java index 245fe13e9..bcd519e49 100644 --- a/src/main/java/luke/tasks/Event.java +++ b/src/main/java/luke/tasks/Event.java @@ -1,5 +1,5 @@ package luke.tasks; -import luke.errors.LukeTimeError; +import luke.user.LukeTimeError; public class Event extends Task { protected String startDate; diff --git a/src/main/java/luke/tasks/TaskList.java b/src/main/java/luke/tasks/TaskList.java new file mode 100644 index 000000000..5a107c054 --- /dev/null +++ b/src/main/java/luke/tasks/TaskList.java @@ -0,0 +1,42 @@ +package luke.tasks; + +import java.util.ArrayList; +import luke.user.LukeTimeError; + +public class TaskList{ + //contains the task list e.g., it has operations to add/delete tasks in the list + + private ArrayList mainTaskList; + public int numberOfTasks; + public TaskList(ArrayList thetasks) throws LukeTimeError { + mainTaskList = new ArrayList(); + numberOfTasks = 0; + for (Task item: thetasks) { + addTask(item); + } + } + + public TaskList() { + + } + + private void addTask(Task taskName) { + mainTaskList.add(taskName); + //System.out.println(numbers); + numberOfTasks += 1; + } + + public void removeTask(int taskNumber) { + mainTaskList.remove(taskNumber); + //System.out.println(numbers); + numberOfTasks -= 1; + } + + public int size() { + return numberOfTasks; + } + + public Task get(int TaskNumber) { + return mainTaskList.get(TaskNumber); + } +} diff --git a/src/main/java/luke/user/LukeTimeError.java b/src/main/java/luke/user/LukeTimeError.java new file mode 100644 index 000000000..630b57120 --- /dev/null +++ b/src/main/java/luke/user/LukeTimeError.java @@ -0,0 +1,8 @@ +package luke.user; +public class LukeTimeError extends Exception { + + @Override + public String getMessage() { + return "LukeTimeError"; + } +} \ No newline at end of file diff --git a/src/main/java/luke/user/Ui.java b/src/main/java/luke/user/Ui.java index 89f2a92a0..a0f11efea 100644 --- a/src/main/java/luke/user/Ui.java +++ b/src/main/java/luke/user/Ui.java @@ -10,8 +10,10 @@ public Ui () { userInput = new Scanner(System.in); } - //decompiler - //userInput.close(); + //decompiler??? + public void closeUi() { + userInput.close(); + } public void showWelcome() { String logo = "\t _ _ \n" From 2da6307e68460adf188b8ac49d33a595aa409e2e Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Thu, 5 Oct 2023 17:54:06 +0800 Subject: [PATCH 45/77] Add Objects (MarkCommand) --- src/main/java/luke/actions/Command.java | 12 ------- src/main/java/luke/actions/MarkCommand.java | 39 +++++++++++++++++++++ 2 files changed, 39 insertions(+), 12 deletions(-) create mode 100644 src/main/java/luke/actions/MarkCommand.java diff --git a/src/main/java/luke/actions/Command.java b/src/main/java/luke/actions/Command.java index 44a09fa23..e0256138e 100644 --- a/src/main/java/luke/actions/Command.java +++ b/src/main/java/luke/actions/Command.java @@ -25,19 +25,7 @@ public void execute(TaskList tasks, Ui ui, Storage storage) { try { switch (action) { - case MARK: - taskNumber = Integer.parseInt(words[1]) - 1; - System.out.println("\tWoohoo! You have accomplished:"); - taskList.get(taskNumber).setDone(true); - System.out.println(taskList.get(taskNumber)); - break; - case UNMARK: - taskNumber = Integer.parseInt(words[1]) - 1; - System.out.println("\tHA! You still have to complete:"); - taskList.get(taskNumber).setDone(false); - System.out.println(taskList.get(taskNumber)); - break; default: assert false: "This line should never be reached"; diff --git a/src/main/java/luke/actions/MarkCommand.java b/src/main/java/luke/actions/MarkCommand.java new file mode 100644 index 000000000..795ffcd6b --- /dev/null +++ b/src/main/java/luke/actions/MarkCommand.java @@ -0,0 +1,39 @@ +package luke.actions; + +import luke.files.Storage; +import luke.tasks.TaskList; +import luke.user.Ui; + +import static luke.actions.ActionType.MARK; +import static luke.actions.ActionType.UNMARK; + + +public class MarkCommand extends Command { + private boolean isDone; + public MarkCommand(ActionType theAction, String parameters) { + + super(theAction, parameters); + if (theAction == MARK) { + isDone = true; + } + if (theAction == UNMARK) { + isDone = false; + } + } + + @Override + public void execute(TaskList tasks, Ui ui, Storage storage) { + //ui has String echo, storage has ArrayList tasks, tasks has ArrayList mainTaskList; + //command has theActionWord and parameters + + int taskNumber = Integer.parseInt(parameters) - 1; + if (isDone) { + System.out.println("\tWoohoo! You have accomplished:"); + } else { + System.out.println("\tHA! You still have to complete:"); + } + tasks.get(taskNumber).setDone(isDone); + + System.out.println(tasks.get(taskNumber)); + } +} From 49d2924c3b085d2987fa24233c762dd60a441370 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Thu, 5 Oct 2023 18:56:49 +0800 Subject: [PATCH 46/77] Fix Objects (Parser), to include instantiating child classes of Command --- src/main/java/luke/actions/Parser.java | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/luke/actions/Parser.java b/src/main/java/luke/actions/Parser.java index dc9d985b3..9ad51a7b8 100644 --- a/src/main/java/luke/actions/Parser.java +++ b/src/main/java/luke/actions/Parser.java @@ -14,50 +14,63 @@ public static Command parse(String fullCommand) { String parameters = ""; String[] words = fullCommand.split(" "); //to identify usage of features "mark" & "unmark" - + Command c = null; try { ActionType action = ActionType.valueOf(words[0].toUpperCase()); theAction = action; + //Command c = null; try { switch (action) { case LIST: parameters = ""; + c = new ListCommand(theAction, parameters); break; case FIND: parameters = fullCommand.substring(4); + c = new FindCommand(theAction, parameters); break; - case MARK: case UNMARK: case DELETE: + case MARK: case UNMARK: parameters = words[1]; + c = new MarkCommand(theAction, parameters); break; case TODO: parameters = fullCommand.substring(4); + c = new AddCommand(theAction, parameters); break; case DEADLINE: parameters = fullCommand.substring(8); + c = new AddCommand(theAction, parameters); break; case EVENT: parameters = fullCommand.substring(5); + c = new AddCommand(theAction, parameters); + break; + + case DELETE: + parameters = words[1]; + c = new DeleteCommand(theAction, parameters); break; default: + c = new AddCommand(theAction, ""); assert false: "This line should never be reached"; break; } } catch (IndexOutOfBoundsException e) { //empty for MARK, UNMARK, TO DO description, DEADLINE description, EVENT description System.out.println("\tOOPS!!! You have missing arguments for " + words[0] + "."); } - Command c = new Command(theAction, parameters); - return c; + + //return c; } catch (IllegalArgumentException e) { System.out.println("\tOOPS!!! I'm sorry, but I don't know what that means :-("); } - return null; + return c; } } From 772d5cfe6cdda9dbb0a9555858d7f0a481b4071b Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Thu, 5 Oct 2023 20:41:02 +0800 Subject: [PATCH 47/77] Add Objects (AddCommand) --- src/main/java/luke/actions/AddCommand.java | 59 +++++++++------------- 1 file changed, 25 insertions(+), 34 deletions(-) diff --git a/src/main/java/luke/actions/AddCommand.java b/src/main/java/luke/actions/AddCommand.java index ef630ccd1..09f41280e 100644 --- a/src/main/java/luke/actions/AddCommand.java +++ b/src/main/java/luke/actions/AddCommand.java @@ -5,49 +5,40 @@ import luke.user.LukeTimeError; import luke.user.Ui; +import static luke.actions.ActionType.*; + public class AddCommand extends Command { - public AddCommand(ActionType theAction, String parameters) { + private Task latestTask; + public AddCommand(ActionType theAction, String parameters) throws LukeTimeError { super(theAction, parameters); + if (theAction == TODO) { + latestTask = new Todo(parameters); + } + if (theAction == DEADLINE) { + try { + latestTask = new Deadline(parameters); + } catch (LukeTimeError e) { + System.out.println("\tOOPS!!! There's an error in the deadline's 'do by' date."); + } + } + if (theAction == EVENT) { + try { + latestTask = new Event(parameters); + } catch (LukeTimeError e) { + System.out.println("\tOOPS!!! There's an error in the event's start and end time."); + } + } + } @Override public void execute(TaskList tasks, Ui ui, Storage storage) { //ui has String echo, storage has ArrayList tasks, tasks has ArrayList mainTaskList; - case TODO: - Task newTodo = new Todo(echo); - addTask(newTodo); - - System.out.println("\tGot it. I've added this task:" + "\n" + taskList.get(taskList.size() - 1)); - System.out.println("\tNow you have " + taskList.size() + " tasks in the list."); - break; + tasks.addTask(latestTask); - case DEADLINE: - try { - Task newDeadline = new Deadline(echo); - addTask(newDeadline); - - System.out.println("\tGot it. I've added this task:" + "\n" + taskList.get(taskList.size() - 1)); - System.out.println("\tNow you have " + taskList.size() + " tasks in the list."); - } catch (LukeTimeError e) { - System.out.println("\tOOPS!!! There's an error in the deadline's 'do by' date."); - } - break; - - case EVENT: - try { - Task newEvent = new Event(echo); - addTask(newEvent); - - System.out.println("\tGot it. I've added this task:" + "\n" + taskList.get(taskList.size() - 1)); - System.out.println("\tNow you have " + taskList.size() + " tasks in the list."); - } catch (LukeTimeError e) { - System.out.println("\tOOPS!!! There's an error in the event's start and end time."); - } - break; - } catch (IndexOutOfBoundsException e) { //empty for MARK, UNMARK, TO DO description, DEADLINE description, EVENT description - System.out.println("\tOOPS!!! You have missing arguments for " + words[0] + "."); - } + System.out.println("\tGot it. I've added this task:" + "\n" + tasks.get(tasks.size() - 1)); + System.out.println("\tNow you have " + tasks.size() + " tasks in the list."); } } From f1b66a6105e1053d5d51d783cf663a72457a2ec4 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Thu, 5 Oct 2023 20:41:25 +0800 Subject: [PATCH 48/77] Add Abstract Class (Command) --- src/main/java/luke/actions/Command.java | 31 ++++--------------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/src/main/java/luke/actions/Command.java b/src/main/java/luke/actions/Command.java index e0256138e..5c473b65a 100644 --- a/src/main/java/luke/actions/Command.java +++ b/src/main/java/luke/actions/Command.java @@ -8,40 +8,17 @@ public abstract class Command { protected ActionType theAction; protected String parameters; //no. or description + private boolean isExit; + public Command(ActionType theAction, String parameters) { this.theAction = theAction; this.parameters = parameters; } - private boolean isExit; - public void execute(TaskList tasks, Ui ui, Storage storage) { + public void execute(TaskList tasks, Ui ui, Storage storage) { //ui has String echo, storage has ArrayList tasks, tasks has ArrayList mainTaskList; - String[] words = echo.split(" "); //to identify usage of features "mark" & "unmark" - - try { - ActionType action = ActionType.valueOf(words[0].toUpperCase()); - - try { - switch (action) { - - - - default: - assert false: "This line should never be reached"; - break; - - - } - } catch (IndexOutOfBoundsException e) { //empty for MARK, UNMARK, TO DO description, DEADLINE description, EVENT description - System.out.println("\tOOPS!!! You have missing arguments for " + words[0] + "."); - } - } catch (IllegalArgumentException e) { - System.out.println("\tOOPS!!! I'm sorry, but I don't know what that means :-("); - } - - echo = userInput.nextLine(); - + //do nothing? should not be executed } public boolean isExit() { From 364d48db7dab3a0f30c74f6562987f6dbbf565bc Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Thu, 5 Oct 2023 20:42:00 +0800 Subject: [PATCH 49/77] Fix Objects (Parser) --- src/main/java/luke/actions/Parser.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/luke/actions/Parser.java b/src/main/java/luke/actions/Parser.java index 9ad51a7b8..4ca49058c 100644 --- a/src/main/java/luke/actions/Parser.java +++ b/src/main/java/luke/actions/Parser.java @@ -6,10 +6,10 @@ import luke.tasks.Todo; import luke.user.LukeTimeError; -public class Parser { +public class Parser{ //user input from Ui to luke command to Command - public static Command parse(String fullCommand) { + public static Command parse(String fullCommand) throws LukeTimeError { ActionType theAction; String parameters = ""; From ad80c66f0bbd637d382a522247c5f68ff4bf0771 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Thu, 5 Oct 2023 20:42:07 +0800 Subject: [PATCH 50/77] Add Objects (Storage) --- src/main/java/luke/files/Storage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/luke/files/Storage.java b/src/main/java/luke/files/Storage.java index d14526d08..b259d0b3a 100644 --- a/src/main/java/luke/files/Storage.java +++ b/src/main/java/luke/files/Storage.java @@ -44,7 +44,7 @@ public ArrayList load() { public void store(TaskList tasksToStore) { //store in memory.txt - Memory.storeMemory("./src/main/java/luke/files/memory.txt", tasksToStore); + Memory.storeMemory("./src/main/java/luke/files/memory.txt", tasksToStore.getMainTaskList()); System.out.println("\tBye. Hope to see you again soon!"); } From 1818f2f38f8fde83bd02ad3de54c3459bc46b147 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Thu, 5 Oct 2023 20:42:18 +0800 Subject: [PATCH 51/77] Add Objects (TaskList) --- src/main/java/luke/tasks/TaskList.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/luke/tasks/TaskList.java b/src/main/java/luke/tasks/TaskList.java index 5a107c054..34674b089 100644 --- a/src/main/java/luke/tasks/TaskList.java +++ b/src/main/java/luke/tasks/TaskList.java @@ -20,7 +20,7 @@ public TaskList() { } - private void addTask(Task taskName) { + public void addTask(Task taskName) { mainTaskList.add(taskName); //System.out.println(numbers); numberOfTasks += 1; @@ -39,4 +39,8 @@ public int size() { public Task get(int TaskNumber) { return mainTaskList.get(TaskNumber); } + + public ArrayList getMainTaskList() { + return mainTaskList; + } } From 3190778ff096a6abd3dde7b7b30ec3de8dbacbc0 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Thu, 5 Oct 2023 20:42:28 +0800 Subject: [PATCH 52/77] Fix Objects (Ui) --- src/main/java/luke/user/Ui.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/luke/user/Ui.java b/src/main/java/luke/user/Ui.java index a0f11efea..3048e73d5 100644 --- a/src/main/java/luke/user/Ui.java +++ b/src/main/java/luke/user/Ui.java @@ -28,7 +28,7 @@ public void showWelcome() { public void showLine() { // show the divider line ("_______") - System.out.println("__________________ (pls change)") + System.out.println("__________________ (pls change)"); } public void showLoadingError() { System.out.println("Loading Error... (pls change)"); From b99923f9bd88b45f23e831d0aa94f54edd20eb6c Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Thu, 5 Oct 2023 20:42:48 +0800 Subject: [PATCH 53/77] Fix Luke to get a code that can run --- src/main/java/Luke.java | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/main/java/Luke.java b/src/main/java/Luke.java index c5fa322ae..572a667e7 100644 --- a/src/main/java/Luke.java +++ b/src/main/java/Luke.java @@ -23,10 +23,8 @@ public Luke(String filePath) { } } - - private static final String BYE_COMMAND = "bye"; - - private static ArrayList taskList = new ArrayList<>(); + //private static final String BYE_COMMAND = "bye"; + //private static ArrayList taskList = new ArrayList<>(); public void run() { ui.showWelcome(); @@ -47,13 +45,6 @@ public void run() { } - public void run() { - //Task[] taskList = new Task[100]; - - int taskNumber; - - } - public static void main(String[] args) { new Luke("data/tasks.txt").run(); //that was the only line From 1109f0466dff2a68d335d5cddc34cec14cbddb1f Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Thu, 5 Oct 2023 20:54:22 +0800 Subject: [PATCH 54/77] Add "BYE" to ActionType, Add "BYE" case to Parser parse method, so that ExitCommand can be called --- src/main/java/luke/actions/ActionType.java | 2 +- src/main/java/luke/actions/Parser.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/luke/actions/ActionType.java b/src/main/java/luke/actions/ActionType.java index bd0e89bbc..4fe2d21ec 100644 --- a/src/main/java/luke/actions/ActionType.java +++ b/src/main/java/luke/actions/ActionType.java @@ -1,5 +1,5 @@ package luke.actions; public enum ActionType { - LIST, FIND, MARK, UNMARK, TODO, DEADLINE, EVENT, DELETE + LIST, FIND, MARK, UNMARK, TODO, DEADLINE, EVENT, DELETE, BYE } diff --git a/src/main/java/luke/actions/Parser.java b/src/main/java/luke/actions/Parser.java index 4ca49058c..2e1bc2282 100644 --- a/src/main/java/luke/actions/Parser.java +++ b/src/main/java/luke/actions/Parser.java @@ -57,6 +57,11 @@ public static Command parse(String fullCommand) throws LukeTimeError { c = new DeleteCommand(theAction, parameters); break; + case BYE: + parameters = ""; + c = new ExitCommand(theAction, parameters); + break; + default: c = new AddCommand(theAction, ""); assert false: "This line should never be reached"; From 3ad68bf2a5fe3161aa9fa8d95fa39bf8fcf869c8 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Thu, 5 Oct 2023 21:04:55 +0800 Subject: [PATCH 55/77] Fix small errors --- src/main/java/luke/files/Memory.java | 2 +- src/main/java/luke/tasks/Deadline.java | 11 +++++++---- src/main/java/luke/tasks/Event.java | 11 +++++++---- src/main/java/luke/tasks/Task.java | 4 ++++ src/main/java/luke/tasks/Todo.java | 10 +++++++--- 5 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/main/java/luke/files/Memory.java b/src/main/java/luke/files/Memory.java index 6c4618ebe..7279272c4 100644 --- a/src/main/java/luke/files/Memory.java +++ b/src/main/java/luke/files/Memory.java @@ -59,7 +59,7 @@ public static void storeMemory(String filePath, ArrayList taskList){ FileWriter fw = new FileWriter(filePath); //overwrite file for (int i = 0; i < taskList.size(); i += 1) { - fw.write(taskList.get(i).memoryString() + "\n"); + fw.write(taskList.get(i).getType() + taskList.get(i).memoryString() + "\n"); } fw.close(); diff --git a/src/main/java/luke/tasks/Deadline.java b/src/main/java/luke/tasks/Deadline.java index 97f5b7624..a3d13f62b 100644 --- a/src/main/java/luke/tasks/Deadline.java +++ b/src/main/java/luke/tasks/Deadline.java @@ -4,10 +4,8 @@ public class Deadline extends Task { protected String date; - public Deadline(String echo) throws LukeTimeError { - super(echo); - - String taskDescription = echo.substring(8); + public Deadline(String taskDescription) throws LukeTimeError { + super(taskDescription); int slashCut = taskDescription.indexOf("/"); if (slashCut <= 0) { @@ -36,6 +34,11 @@ public void setDate(String dateString) throws LukeTimeError { date = dateString.substring(spaceCut + 1); } + @Override + public String getType() { + return "deadline"; + } + @Override public String toString() { //super.toString(); diff --git a/src/main/java/luke/tasks/Event.java b/src/main/java/luke/tasks/Event.java index bcd519e49..829044d29 100644 --- a/src/main/java/luke/tasks/Event.java +++ b/src/main/java/luke/tasks/Event.java @@ -5,10 +5,8 @@ public class Event extends Task { protected String startDate; protected String endDate; - public Event(String echo) throws LukeTimeError { - super(echo); - //setDates(dates); - String taskDescription = echo.substring(5); + public Event(String taskDescription) throws LukeTimeError { + super(taskDescription); int slashCut = taskDescription.indexOf("/"); if (slashCut <= 0) { @@ -57,6 +55,11 @@ public void setDates(String dates) throws LukeTimeError { endDate = dates.substring(3); } + @Override + public String getType() { + return "event"; + } + @Override public String toString() { //super.toString(); diff --git a/src/main/java/luke/tasks/Task.java b/src/main/java/luke/tasks/Task.java index 146b442f3..0b53eb5dd 100644 --- a/src/main/java/luke/tasks/Task.java +++ b/src/main/java/luke/tasks/Task.java @@ -21,6 +21,10 @@ public void setDone(boolean done) { isDone = done; } + public String getType() { + return "task"; + } + /*@Override public String toString() { return ""; diff --git a/src/main/java/luke/tasks/Todo.java b/src/main/java/luke/tasks/Todo.java index 5462902ce..42c39dcd8 100644 --- a/src/main/java/luke/tasks/Todo.java +++ b/src/main/java/luke/tasks/Todo.java @@ -3,15 +3,19 @@ public class Todo extends Task { //protected boolean isDone; - public Todo(String echo) { - super(echo); //ensures superclass is properly initialised + public Todo(String description) { + super(description); //ensures superclass is properly initialised - description = echo.substring(4); if (description.isEmpty()) { throw new IndexOutOfBoundsException(); } } + @Override + public String getType() { + return "todo"; + } + @Override public String toString() { //super.toString(); From de661a45c28b022377ec91cb0bf3a14a7c08d9ad Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Thu, 5 Oct 2023 21:35:35 +0800 Subject: [PATCH 56/77] Fix - "bye" ends Luke without scanner errors --- src/main/java/luke/actions/Command.java | 4 ++++ src/main/java/luke/actions/ExitCommand.java | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/luke/actions/Command.java b/src/main/java/luke/actions/Command.java index 5c473b65a..a62ed0d9c 100644 --- a/src/main/java/luke/actions/Command.java +++ b/src/main/java/luke/actions/Command.java @@ -21,6 +21,10 @@ public void execute(TaskList tasks, Ui ui, Storage storage) { //do nothing? should not be executed } + public void setIsExit(boolean isExit) { + this.isExit = isExit; + } + public boolean isExit() { return isExit; } diff --git a/src/main/java/luke/actions/ExitCommand.java b/src/main/java/luke/actions/ExitCommand.java index cb35e17cc..a9c66c8fb 100644 --- a/src/main/java/luke/actions/ExitCommand.java +++ b/src/main/java/luke/actions/ExitCommand.java @@ -11,10 +11,11 @@ public ExitCommand(ActionType theAction, String parameters) { } @Override - public void execute(TaskList tasks, Ui ui, Storage storage) { + public void execute(TaskList tasks, Ui ui, Storage storage) throws IllegalArgumentException{ //ui has String echo, storage has ArrayList tasks, tasks has ArrayList mainTaskList; storage.store(tasks); + setIsExit(true); ui.closeUi(); } } From a4664668074bf5ea18d16b1cb3ec3863c5fbfbad Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Thu, 5 Oct 2023 21:52:08 +0800 Subject: [PATCH 57/77] Fix Retrieval of Memory (syntax) --- src/main/java/Luke.java | 9 +++++---- src/main/java/luke/actions/Parser.java | 6 +++--- src/main/java/luke/files/Memory.java | 6 +++--- src/main/java/luke/files/Storage.java | 8 +++----- src/main/java/luke/tasks/Deadline.java | 8 +++++--- src/main/java/luke/tasks/Event.java | 7 +++++-- src/main/java/luke/tasks/Task.java | 4 +++- src/main/java/luke/tasks/Todo.java | 8 +++++--- 8 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/main/java/Luke.java b/src/main/java/Luke.java index 572a667e7..fc4f90838 100644 --- a/src/main/java/Luke.java +++ b/src/main/java/Luke.java @@ -8,11 +8,12 @@ import java.util.ArrayList; public class Luke { + private Storage storage; private TaskList tasks; private Ui ui; - public Luke(String filePath) { + public Luke(String filePath) {//i dont get how this works ui = new Ui(); storage = new Storage(filePath); try { @@ -36,17 +37,17 @@ public void run() { Command c = Parser.parse(fullCommand); c.execute(tasks, ui, storage); isExit = c.isExit(); //for bye command - } catch (LukeTimeError e) { //from c.execute i think + } catch (LukeTimeError e) { //from Parser.parse i think ui.showError(e.getMessage()); } finally { ui.showLine(); } } - } public static void main(String[] args) { - new Luke("data/tasks.txt").run(); + new Luke("./out/artifacts/ip_jar/memory.txt").run(); + //new Luke("data/tasks.txt").run(); //that was the only line } } diff --git a/src/main/java/luke/actions/Parser.java b/src/main/java/luke/actions/Parser.java index 2e1bc2282..8829f34a7 100644 --- a/src/main/java/luke/actions/Parser.java +++ b/src/main/java/luke/actions/Parser.java @@ -38,17 +38,17 @@ public static Command parse(String fullCommand) throws LukeTimeError { break; case TODO: - parameters = fullCommand.substring(4); + parameters = fullCommand.substring(5); c = new AddCommand(theAction, parameters); break; case DEADLINE: - parameters = fullCommand.substring(8); + parameters = fullCommand.substring(9); c = new AddCommand(theAction, parameters); break; case EVENT: - parameters = fullCommand.substring(5); + parameters = fullCommand.substring(6); c = new AddCommand(theAction, parameters); break; diff --git a/src/main/java/luke/files/Memory.java b/src/main/java/luke/files/Memory.java index 7279272c4..622144036 100644 --- a/src/main/java/luke/files/Memory.java +++ b/src/main/java/luke/files/Memory.java @@ -24,9 +24,9 @@ public static ArrayList readMemory(String filePath) throws FileNotFoundExc String currentLine = s.nextLine(); System.out.println("\t" + currentLine); - String taskDetails = currentLine.substring(0,6); + String taskDetails = currentLine.substring(0,5); //System.out.println(taskDetails); - String taskDescription = currentLine.substring(7); + String taskDescription = currentLine.substring(6); //System.out.println(taskDescription); char[] characters = taskDetails.toCharArray(); try { @@ -59,7 +59,7 @@ public static void storeMemory(String filePath, ArrayList taskList){ FileWriter fw = new FileWriter(filePath); //overwrite file for (int i = 0; i < taskList.size(); i += 1) { - fw.write(taskList.get(i).getType() + taskList.get(i).memoryString() + "\n"); + fw.write(taskList.get(i).memoryString() + "\n"); } fw.close(); diff --git a/src/main/java/luke/files/Storage.java b/src/main/java/luke/files/Storage.java index b259d0b3a..d95b8154d 100644 --- a/src/main/java/luke/files/Storage.java +++ b/src/main/java/luke/files/Storage.java @@ -12,12 +12,10 @@ public class Storage { private ArrayList tasks; public Storage(String filePath) { - - - File taskListFile = new File("./src/main/java/luke/files/memory.txt"); + File taskListFile = new File(filePath); if (taskListFile.exists()) { try { - tasks = Memory.readMemory("./src/main/java/luke/files/memory.txt"); + tasks = Memory.readMemory(filePath); System.out.println("\n\tMemory retrieval successful!\n"); //return tasks; } catch (FileNotFoundException e) { @@ -44,7 +42,7 @@ public ArrayList load() { public void store(TaskList tasksToStore) { //store in memory.txt - Memory.storeMemory("./src/main/java/luke/files/memory.txt", tasksToStore.getMainTaskList()); + Memory.storeMemory("./out/artifacts/ip_jar/memory.txt", tasksToStore.getMainTaskList()); System.out.println("\tBye. Hope to see you again soon!"); } diff --git a/src/main/java/luke/tasks/Deadline.java b/src/main/java/luke/tasks/Deadline.java index a3d13f62b..a04d6ae7b 100644 --- a/src/main/java/luke/tasks/Deadline.java +++ b/src/main/java/luke/tasks/Deadline.java @@ -34,11 +34,13 @@ public void setDate(String dateString) throws LukeTimeError { date = dateString.substring(spaceCut + 1); } - @Override + /*@Override public String getType() { return "deadline"; } + */ + @Override public String toString() { //super.toString(); @@ -50,7 +52,7 @@ public String toString() { isDoneString = "[ ]"; } - return "\t[D]" + isDoneString + getDescription() + "(do by: " + getDate() + ")"; + return "\t[D]" + isDoneString + " " + getDescription() + "(do by: " + getDate() + ")"; } @Override @@ -63,6 +65,6 @@ public String memoryString() { isDoneString = "[ ]"; } - return "[D]" + isDoneString + " deadline" + getDescription() + "/by " + getDate(); + return "[D]" + isDoneString + " " + getDescription() + "/by " + getDate(); } } diff --git a/src/main/java/luke/tasks/Event.java b/src/main/java/luke/tasks/Event.java index 829044d29..8908b0a0e 100644 --- a/src/main/java/luke/tasks/Event.java +++ b/src/main/java/luke/tasks/Event.java @@ -55,11 +55,14 @@ public void setDates(String dates) throws LukeTimeError { endDate = dates.substring(3); } + /* @Override public String getType() { return "event"; } + */ + @Override public String toString() { //super.toString(); @@ -71,7 +74,7 @@ public String toString() { isDoneString = "[ ]"; } - return "\t[E]" + isDoneString + getDescription() + "(from: " + getStartDate() + "to: " + getEndDate() + ")"; + return "\t[E]" + isDoneString + " " + getDescription() + "(from: " + getStartDate() + "to: " + getEndDate() + ")"; } @Override @@ -84,6 +87,6 @@ public String memoryString() { isDoneString = "[ ]"; } - return "[E]" + isDoneString + " event" + getDescription() + "/from " + getStartDate() + "/to " + getEndDate(); + return "[E]" + isDoneString + " " + getDescription() + "/from " + getStartDate() + "/to " + getEndDate(); } } diff --git a/src/main/java/luke/tasks/Task.java b/src/main/java/luke/tasks/Task.java index 0b53eb5dd..d71df9b3b 100644 --- a/src/main/java/luke/tasks/Task.java +++ b/src/main/java/luke/tasks/Task.java @@ -20,11 +20,13 @@ public boolean isDone() { public void setDone(boolean done) { isDone = done; } - +/* public String getType() { return "task"; } + */ + /*@Override public String toString() { return ""; diff --git a/src/main/java/luke/tasks/Todo.java b/src/main/java/luke/tasks/Todo.java index 42c39dcd8..e725bc617 100644 --- a/src/main/java/luke/tasks/Todo.java +++ b/src/main/java/luke/tasks/Todo.java @@ -10,12 +10,14 @@ public Todo(String description) { throw new IndexOutOfBoundsException(); } } - +/* @Override public String getType() { return "todo"; } + */ + @Override public String toString() { //super.toString(); @@ -27,7 +29,7 @@ public String toString() { isDoneString = "[ ]"; } - return "\t[T]" + isDoneString + getDescription(); + return "\t[T]" + isDoneString + " " + getDescription(); } @Override @@ -40,7 +42,7 @@ public String memoryString() { isDoneString = "[ ]"; } - return "[T]" + isDoneString + " todo" + getDescription(); + return "[T]" + isDoneString + " " + getDescription(); } } From 4342a658cc786c01bd355e5d6ed52045b1464231 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Thu, 5 Oct 2023 23:53:43 +0800 Subject: [PATCH 58/77] Print correct and specific error messages for errors --- src/main/java/Luke.java | 4 ++-- src/main/java/luke/actions/AddCommand.java | 6 +++-- src/main/java/luke/actions/DeleteCommand.java | 4 ++-- .../java/luke/actions/DoNothingCommand.java | 18 +++++++++++++++ src/main/java/luke/actions/MarkCommand.java | 12 +++++----- src/main/java/luke/actions/Parser.java | 18 +++++++++++---- src/main/java/luke/files/Storage.java | 1 + src/main/java/luke/tasks/Deadline.java | 22 ++++++++++++++++--- src/main/java/luke/tasks/Event.java | 20 ++++++++++++++--- src/main/java/luke/tasks/Task.java | 9 ++++++++ src/main/java/luke/tasks/TaskList.java | 3 ++- src/main/java/luke/tasks/Todo.java | 11 +++++----- src/main/java/luke/user/Ui.java | 2 +- 13 files changed, 101 insertions(+), 29 deletions(-) create mode 100644 src/main/java/luke/actions/DoNothingCommand.java diff --git a/src/main/java/Luke.java b/src/main/java/Luke.java index fc4f90838..7825916d2 100644 --- a/src/main/java/Luke.java +++ b/src/main/java/Luke.java @@ -13,7 +13,7 @@ public class Luke { private TaskList tasks; private Ui ui; - public Luke(String filePath) {//i dont get how this works + public Luke(String filePath) {//i dont get how this filePath works ui = new Ui(); storage = new Storage(filePath); try { @@ -35,7 +35,7 @@ public void run() { String fullCommand = ui.readCommand(); ui.showLine(); // show the divider line ("_______") Command c = Parser.parse(fullCommand); - c.execute(tasks, ui, storage); + c.execute(tasks, ui, storage); //error because c is null isExit = c.isExit(); //for bye command } catch (LukeTimeError e) { //from Parser.parse i think ui.showError(e.getMessage()); diff --git a/src/main/java/luke/actions/AddCommand.java b/src/main/java/luke/actions/AddCommand.java index 09f41280e..370dcb290 100644 --- a/src/main/java/luke/actions/AddCommand.java +++ b/src/main/java/luke/actions/AddCommand.java @@ -19,14 +19,16 @@ public AddCommand(ActionType theAction, String parameters) throws LukeTimeError try { latestTask = new Deadline(parameters); } catch (LukeTimeError e) { - System.out.println("\tOOPS!!! There's an error in the deadline's 'do by' date."); + System.out.println("\tOOPS!!! You have missing/invalid arguments for deadline. No changes have been made."); + throw new LukeTimeError(); } } if (theAction == EVENT) { try { latestTask = new Event(parameters); } catch (LukeTimeError e) { - System.out.println("\tOOPS!!! There's an error in the event's start and end time."); + System.out.println("\tOOPS!!! You have missing/invalid arguments for event. No changes have been made."); + throw new LukeTimeError(); } } diff --git a/src/main/java/luke/actions/DeleteCommand.java b/src/main/java/luke/actions/DeleteCommand.java index c188913f9..705e8f44d 100644 --- a/src/main/java/luke/actions/DeleteCommand.java +++ b/src/main/java/luke/actions/DeleteCommand.java @@ -18,8 +18,8 @@ public void execute(TaskList tasks, Ui ui, Storage storage) { System.out.println("\tNoted. I've removed this task:\n" + tasks.get(taskNumber)); tasks.removeTask(taskNumber); System.out.println("\tNow you have " + tasks.size() + " tasks in the list."); - } catch (IndexOutOfBoundsException e) { //empty for MARK, UNMARK, TO DO description, DEADLINE description, EVENT description - System.out.println("\tOOPS!!! You have missing arguments for " + theAction + "."); + } catch (IndexOutOfBoundsException e) { + System.out.println("\tOOPS!!! Your arguments for " + theAction + " exceeds your task list."); } } } diff --git a/src/main/java/luke/actions/DoNothingCommand.java b/src/main/java/luke/actions/DoNothingCommand.java new file mode 100644 index 000000000..e66205b3b --- /dev/null +++ b/src/main/java/luke/actions/DoNothingCommand.java @@ -0,0 +1,18 @@ +package luke.actions; + +import luke.files.Storage; +import luke.tasks.TaskList; +import luke.user.Ui; + + +public class DoNothingCommand extends Command { + public DoNothingCommand(ActionType theAction, String parameters) { + super(theAction, parameters); + } + + @Override + public void execute(TaskList tasks, Ui ui, Storage storage) { + + } +} + diff --git a/src/main/java/luke/actions/MarkCommand.java b/src/main/java/luke/actions/MarkCommand.java index 795ffcd6b..9f87b1802 100644 --- a/src/main/java/luke/actions/MarkCommand.java +++ b/src/main/java/luke/actions/MarkCommand.java @@ -27,13 +27,13 @@ public void execute(TaskList tasks, Ui ui, Storage storage) { //command has theActionWord and parameters int taskNumber = Integer.parseInt(parameters) - 1; - if (isDone) { - System.out.println("\tWoohoo! You have accomplished:"); - } else { - System.out.println("\tHA! You still have to complete:"); + + try { + tasks.get(taskNumber).setDone(isDone); + System.out.println(tasks.get(taskNumber)); + } catch (IndexOutOfBoundsException e) { + System.out.println("\tOOPS!!! Your arguments for " + theAction + " exceeds your task list."); } - tasks.get(taskNumber).setDone(isDone); - System.out.println(tasks.get(taskNumber)); } } diff --git a/src/main/java/luke/actions/Parser.java b/src/main/java/luke/actions/Parser.java index 8829f34a7..face76873 100644 --- a/src/main/java/luke/actions/Parser.java +++ b/src/main/java/luke/actions/Parser.java @@ -44,12 +44,20 @@ public static Command parse(String fullCommand) throws LukeTimeError { case DEADLINE: parameters = fullCommand.substring(9); - c = new AddCommand(theAction, parameters); + try { + c = new AddCommand(theAction, parameters); + } catch (LukeTimeError e) { + c = new DoNothingCommand(ActionType.LIST, parameters); + } break; case EVENT: parameters = fullCommand.substring(6); - c = new AddCommand(theAction, parameters); + try { + c = new AddCommand(theAction, parameters); + } catch (LukeTimeError e) { + c = new DoNothingCommand(ActionType.LIST, parameters); + } break; case DELETE: @@ -63,17 +71,19 @@ public static Command parse(String fullCommand) throws LukeTimeError { break; default: - c = new AddCommand(theAction, ""); + c = new DoNothingCommand(theAction, ""); assert false: "This line should never be reached"; break; } } catch (IndexOutOfBoundsException e) { //empty for MARK, UNMARK, TO DO description, DEADLINE description, EVENT description - System.out.println("\tOOPS!!! You have missing arguments for " + words[0] + "."); + System.out.println("\tOOPS!!! You have missing arguments for " + words[0] + ". No changes have been made."); + c = new DoNothingCommand(ActionType.LIST, ""); } //return c; } catch (IllegalArgumentException e) { System.out.println("\tOOPS!!! I'm sorry, but I don't know what that means :-("); + c = new DoNothingCommand(ActionType.LIST, ""); } return c; diff --git a/src/main/java/luke/files/Storage.java b/src/main/java/luke/files/Storage.java index d95b8154d..2af38edcd 100644 --- a/src/main/java/luke/files/Storage.java +++ b/src/main/java/luke/files/Storage.java @@ -15,6 +15,7 @@ public Storage(String filePath) { File taskListFile = new File(filePath); if (taskListFile.exists()) { try { + System.out.println("\n\tRetrieving memory...\n"); tasks = Memory.readMemory(filePath); System.out.println("\n\tMemory retrieval successful!\n"); //return tasks; diff --git a/src/main/java/luke/tasks/Deadline.java b/src/main/java/luke/tasks/Deadline.java index a04d6ae7b..0cdf23131 100644 --- a/src/main/java/luke/tasks/Deadline.java +++ b/src/main/java/luke/tasks/Deadline.java @@ -3,22 +3,27 @@ public class Deadline extends Task { protected String date; + protected String deadlineGuide = "\tdeadline /by "; public Deadline(String taskDescription) throws LukeTimeError { super(taskDescription); int slashCut = taskDescription.indexOf("/"); if (slashCut <= 0) { + System.out.println("\tThere is a missing task description. Please follow this format:"); + printGuide(); throw new LukeTimeError(); } - setDate(taskDescription.substring(slashCut + 1)); - description = taskDescription.substring(0, slashCut); - +/* if (description.length() <= 1) { + System.out.println("length prob"); throw new IndexOutOfBoundsException(); } + */ + + setDate(taskDescription.substring(slashCut + 1)); } public String getDate() { @@ -28,9 +33,16 @@ public String getDate() { public void setDate(String dateString) throws LukeTimeError { String[] words = dateString.split(" "); if (!words[0].equals("by")) { + System.out.println("\tThere is a syntax problem. Please follow this format:"); + printGuide(); throw new LukeTimeError(); } int spaceCut = dateString.indexOf(" "); + if (spaceCut <= 0) { + System.out.println("\tThere is a missing date. Please follow this format:"); + printGuide(); + throw new LukeTimeError(); + } date = dateString.substring(spaceCut + 1); } @@ -40,6 +52,10 @@ public String getType() { } */ + @Override + public void printGuide() { + System.out.println(deadlineGuide); + } @Override public String toString() { diff --git a/src/main/java/luke/tasks/Event.java b/src/main/java/luke/tasks/Event.java index 8908b0a0e..4706e5f57 100644 --- a/src/main/java/luke/tasks/Event.java +++ b/src/main/java/luke/tasks/Event.java @@ -4,23 +4,26 @@ public class Event extends Task { protected String startDate; protected String endDate; + protected String eventGuide = "\tevent /from /to "; public Event(String taskDescription) throws LukeTimeError { super(taskDescription); int slashCut = taskDescription.indexOf("/"); if (slashCut <= 0) { + System.out.println("\tThere is a missing task description. Please follow this format:"); + printGuide(); throw new LukeTimeError(); } - String taskDuration = taskDescription.substring(slashCut + 1); - setDates(taskDuration); - description = taskDescription.substring(0, slashCut); if (description.length() <= 1) { throw new IndexOutOfBoundsException(); } + + String taskDuration = taskDescription.substring(slashCut + 1); + setDates(taskDuration); } public String getStartDate() { @@ -34,6 +37,8 @@ public String getEndDate() { public void setDates(String dates) throws LukeTimeError { String[] words = dates.split(" "); if (!words[0].equals("from")) { + System.out.println("\tThere is a syntax problem. Please follow this format:"); + printGuide(); throw new LukeTimeError(); } @@ -41,6 +46,8 @@ public void setDates(String dates) throws LukeTimeError { int slashCut = dates.indexOf("/"); if (slashCut <= 0) { + System.out.println("\tThere is a syntax problem. Please follow this format:"); + printGuide(); throw new LukeTimeError(); } @@ -49,6 +56,8 @@ public void setDates(String dates) throws LukeTimeError { words = dates.split(" "); if (!words[0].equals("to")) { + System.out.println("\tThere is a syntax problem. Please follow this format:"); + printGuide(); throw new LukeTimeError(); } @@ -63,6 +72,11 @@ public String getType() { */ + @Override + public void printGuide() { + System.out.println(eventGuide); + } + @Override public String toString() { //super.toString(); diff --git a/src/main/java/luke/tasks/Task.java b/src/main/java/luke/tasks/Task.java index d71df9b3b..292ace4b2 100644 --- a/src/main/java/luke/tasks/Task.java +++ b/src/main/java/luke/tasks/Task.java @@ -18,8 +18,17 @@ public boolean isDone() { } public void setDone(boolean done) { + if (done) { + System.out.println("\tWoohoo! You have accomplished:"); + } else { + System.out.println("\tHA! You still have to complete:"); + } isDone = done; } + + public void printGuide() { + //nothing + } /* public String getType() { return "task"; diff --git a/src/main/java/luke/tasks/TaskList.java b/src/main/java/luke/tasks/TaskList.java index 34674b089..612e98f17 100644 --- a/src/main/java/luke/tasks/TaskList.java +++ b/src/main/java/luke/tasks/TaskList.java @@ -36,8 +36,9 @@ public int size() { return numberOfTasks; } - public Task get(int TaskNumber) { + public Task get(int TaskNumber) throws IndexOutOfBoundsException { return mainTaskList.get(TaskNumber); + } public ArrayList getMainTaskList() { diff --git a/src/main/java/luke/tasks/Todo.java b/src/main/java/luke/tasks/Todo.java index e725bc617..d282a7362 100644 --- a/src/main/java/luke/tasks/Todo.java +++ b/src/main/java/luke/tasks/Todo.java @@ -2,22 +2,23 @@ public class Todo extends Task { //protected boolean isDone; + protected String todoGuide = "\ttodo "; public Todo(String description) { super(description); //ensures superclass is properly initialised if (description.isEmpty()) { + System.out.println("\tThere is a missing task description. Please follow this format:"); + printGuide(); throw new IndexOutOfBoundsException(); } } -/* + @Override - public String getType() { - return "todo"; + public void printGuide() { + System.out.println(todoGuide); } - */ - @Override public String toString() { //super.toString(); diff --git a/src/main/java/luke/user/Ui.java b/src/main/java/luke/user/Ui.java index 3048e73d5..0440bdb87 100644 --- a/src/main/java/luke/user/Ui.java +++ b/src/main/java/luke/user/Ui.java @@ -28,7 +28,7 @@ public void showWelcome() { public void showLine() { // show the divider line ("_______") - System.out.println("__________________ (pls change)"); + System.out.println("\t____________________________________________________________"); } public void showLoadingError() { System.out.println("Loading Error... (pls change)"); From 698d9640eb33217e162434b9b5ce7c9951d3b703 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Thu, 5 Oct 2023 23:56:55 +0800 Subject: [PATCH 59/77] Fix spacing in memory storage/retrieval --- src/main/java/luke/tasks/Deadline.java | 2 +- src/main/java/luke/tasks/Event.java | 2 +- src/main/java/luke/tasks/Todo.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/luke/tasks/Deadline.java b/src/main/java/luke/tasks/Deadline.java index 0cdf23131..3a099783d 100644 --- a/src/main/java/luke/tasks/Deadline.java +++ b/src/main/java/luke/tasks/Deadline.java @@ -81,6 +81,6 @@ public String memoryString() { isDoneString = "[ ]"; } - return "[D]" + isDoneString + " " + getDescription() + "/by " + getDate(); + return "[D]" + isDoneString + getDescription() + "/by " + getDate(); } } diff --git a/src/main/java/luke/tasks/Event.java b/src/main/java/luke/tasks/Event.java index 4706e5f57..4978a7806 100644 --- a/src/main/java/luke/tasks/Event.java +++ b/src/main/java/luke/tasks/Event.java @@ -101,6 +101,6 @@ public String memoryString() { isDoneString = "[ ]"; } - return "[E]" + isDoneString + " " + getDescription() + "/from " + getStartDate() + "/to " + getEndDate(); + return "[E]" + isDoneString + getDescription() + "/from " + getStartDate() + "/to " + getEndDate(); } } diff --git a/src/main/java/luke/tasks/Todo.java b/src/main/java/luke/tasks/Todo.java index d282a7362..a34a372d2 100644 --- a/src/main/java/luke/tasks/Todo.java +++ b/src/main/java/luke/tasks/Todo.java @@ -43,7 +43,7 @@ public String memoryString() { isDoneString = "[ ]"; } - return "[T]" + isDoneString + " " + getDescription(); + return "[T]" + isDoneString + getDescription(); } } From 41f428df4e05801bd23c974f8bad99b74db45136 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Fri, 6 Oct 2023 00:52:53 +0800 Subject: [PATCH 60/77] Code Organisation --- src/main/java/Luke.java | 10 +++------- src/main/java/luke/actions/Command.java | 3 --- src/main/java/luke/actions/DeleteCommand.java | 2 -- src/main/java/luke/actions/DoNothingCommand.java | 10 ---------- src/main/java/luke/actions/ExitCommand.java | 3 --- src/main/java/luke/actions/FindCommand.java | 4 ---- src/main/java/luke/actions/ListCommand.java | 4 ---- src/main/java/luke/actions/MarkCommand.java | 7 ++----- src/main/java/luke/actions/Parser.java | 15 ++++----------- src/main/java/luke/files/Memory.java | 9 ++------- src/main/java/luke/files/Storage.java | 4 ---- src/main/java/luke/tasks/Deadline.java | 13 ------------- src/main/java/luke/tasks/Event.java | 12 ------------ src/main/java/luke/tasks/Task.java | 13 +------------ src/main/java/luke/tasks/TaskList.java | 2 +- src/main/java/luke/user/LukeTimeError.java | 1 - src/main/java/luke/user/Ui.java | 1 - 17 files changed, 13 insertions(+), 100 deletions(-) diff --git a/src/main/java/Luke.java b/src/main/java/Luke.java index 7825916d2..00e0284d7 100644 --- a/src/main/java/Luke.java +++ b/src/main/java/Luke.java @@ -5,8 +5,6 @@ import luke.tasks.*; import luke.files.*; -import java.util.ArrayList; - public class Luke { private Storage storage; @@ -24,9 +22,6 @@ public Luke(String filePath) {//i dont get how this filePath works } } - //private static final String BYE_COMMAND = "bye"; - //private static ArrayList taskList = new ArrayList<>(); - public void run() { ui.showWelcome(); boolean isExit = false; @@ -35,7 +30,9 @@ public void run() { String fullCommand = ui.readCommand(); ui.showLine(); // show the divider line ("_______") Command c = Parser.parse(fullCommand); - c.execute(tasks, ui, storage); //error because c is null + //c has theActionWord and parameters + c.execute(tasks, ui, storage); + //tasks has ArrayList mainTaskList, ui has String echo, storage has ArrayList tasks isExit = c.isExit(); //for bye command } catch (LukeTimeError e) { //from Parser.parse i think ui.showError(e.getMessage()); @@ -48,7 +45,6 @@ public void run() { public static void main(String[] args) { new Luke("./out/artifacts/ip_jar/memory.txt").run(); //new Luke("data/tasks.txt").run(); - //that was the only line } } diff --git a/src/main/java/luke/actions/Command.java b/src/main/java/luke/actions/Command.java index a62ed0d9c..721dbcf6c 100644 --- a/src/main/java/luke/actions/Command.java +++ b/src/main/java/luke/actions/Command.java @@ -2,7 +2,6 @@ import luke.files.Storage; import luke.tasks.*; -import luke.user.LukeTimeError; import luke.user.Ui; public abstract class Command { @@ -16,8 +15,6 @@ public Command(ActionType theAction, String parameters) { } public void execute(TaskList tasks, Ui ui, Storage storage) { - //ui has String echo, storage has ArrayList tasks, tasks has ArrayList mainTaskList; - //do nothing? should not be executed } diff --git a/src/main/java/luke/actions/DeleteCommand.java b/src/main/java/luke/actions/DeleteCommand.java index 705e8f44d..c84e33d9b 100644 --- a/src/main/java/luke/actions/DeleteCommand.java +++ b/src/main/java/luke/actions/DeleteCommand.java @@ -11,8 +11,6 @@ public DeleteCommand(ActionType theAction, String parameters) { @Override public void execute(TaskList tasks, Ui ui, Storage storage) { - //ui has String echo, storage has ArrayList tasks, tasks has ArrayList mainTaskList; - try { int taskNumber = Integer.parseInt(parameters) - 1; System.out.println("\tNoted. I've removed this task:\n" + tasks.get(taskNumber)); diff --git a/src/main/java/luke/actions/DoNothingCommand.java b/src/main/java/luke/actions/DoNothingCommand.java index e66205b3b..82b5c11cd 100644 --- a/src/main/java/luke/actions/DoNothingCommand.java +++ b/src/main/java/luke/actions/DoNothingCommand.java @@ -1,18 +1,8 @@ package luke.actions; -import luke.files.Storage; -import luke.tasks.TaskList; -import luke.user.Ui; - - public class DoNothingCommand extends Command { public DoNothingCommand(ActionType theAction, String parameters) { super(theAction, parameters); } - - @Override - public void execute(TaskList tasks, Ui ui, Storage storage) { - - } } diff --git a/src/main/java/luke/actions/ExitCommand.java b/src/main/java/luke/actions/ExitCommand.java index a9c66c8fb..31020125b 100644 --- a/src/main/java/luke/actions/ExitCommand.java +++ b/src/main/java/luke/actions/ExitCommand.java @@ -5,15 +5,12 @@ import luke.user.Ui; public class ExitCommand extends Command { - //bye input public ExitCommand(ActionType theAction, String parameters) { super(theAction, parameters); } @Override public void execute(TaskList tasks, Ui ui, Storage storage) throws IllegalArgumentException{ - //ui has String echo, storage has ArrayList tasks, tasks has ArrayList mainTaskList; - storage.store(tasks); setIsExit(true); ui.closeUi(); diff --git a/src/main/java/luke/actions/FindCommand.java b/src/main/java/luke/actions/FindCommand.java index 2a8ebfa02..47a575f9d 100644 --- a/src/main/java/luke/actions/FindCommand.java +++ b/src/main/java/luke/actions/FindCommand.java @@ -11,10 +11,6 @@ public FindCommand(ActionType theAction, String parameters) { @Override public void execute(TaskList tasks, Ui ui, Storage storage) { - //ui has String echo, storage has ArrayList tasks, tasks has ArrayList mainTaskList; - //command has theActionWord and parameters - - //String findWord = ui.echo.substring(4); System.out.println("\tHere are the matching tasks in your list:"); int j = 1; for (int i = 0; i < tasks.size(); i += 1) { diff --git a/src/main/java/luke/actions/ListCommand.java b/src/main/java/luke/actions/ListCommand.java index cc79ad763..b18542cff 100644 --- a/src/main/java/luke/actions/ListCommand.java +++ b/src/main/java/luke/actions/ListCommand.java @@ -11,13 +11,9 @@ public ListCommand(ActionType theAction, String parameters) { @Override public void execute(TaskList tasks, Ui ui, Storage storage) { - //ui has String echo, storage has ArrayList tasks, tasks has ArrayList mainTaskList; - - System.out.println("\tHere are the tasks in your list:"); for (int i = 0; i < tasks.size(); i += 1) { System.out.println("\t" + (i + 1) + "." + tasks.get(i)); } - } } diff --git a/src/main/java/luke/actions/MarkCommand.java b/src/main/java/luke/actions/MarkCommand.java index 9f87b1802..445e3b140 100644 --- a/src/main/java/luke/actions/MarkCommand.java +++ b/src/main/java/luke/actions/MarkCommand.java @@ -7,12 +7,12 @@ import static luke.actions.ActionType.MARK; import static luke.actions.ActionType.UNMARK; - public class MarkCommand extends Command { private boolean isDone; - public MarkCommand(ActionType theAction, String parameters) { + public MarkCommand(ActionType theAction, String parameters) { super(theAction, parameters); + if (theAction == MARK) { isDone = true; } @@ -23,9 +23,6 @@ public MarkCommand(ActionType theAction, String parameters) { @Override public void execute(TaskList tasks, Ui ui, Storage storage) { - //ui has String echo, storage has ArrayList tasks, tasks has ArrayList mainTaskList; - //command has theActionWord and parameters - int taskNumber = Integer.parseInt(parameters) - 1; try { diff --git a/src/main/java/luke/actions/Parser.java b/src/main/java/luke/actions/Parser.java index face76873..ce3742624 100644 --- a/src/main/java/luke/actions/Parser.java +++ b/src/main/java/luke/actions/Parser.java @@ -1,9 +1,5 @@ package luke.actions; -import luke.tasks.Deadline; -import luke.tasks.Event; -import luke.tasks.Task; -import luke.tasks.Todo; import luke.user.LukeTimeError; public class Parser{ @@ -11,14 +7,14 @@ public class Parser{ public static Command parse(String fullCommand) throws LukeTimeError { ActionType theAction; - String parameters = ""; + String parameters; - String[] words = fullCommand.split(" "); //to identify usage of features "mark" & "unmark" - Command c = null; + String[] words = fullCommand.split(" "); + //to get parameters for actions "mark", "unmark" & "delete" + Command c; try { ActionType action = ActionType.valueOf(words[0].toUpperCase()); theAction = action; - //Command c = null; try { switch (action) { @@ -79,13 +75,10 @@ public static Command parse(String fullCommand) throws LukeTimeError { System.out.println("\tOOPS!!! You have missing arguments for " + words[0] + ". No changes have been made."); c = new DoNothingCommand(ActionType.LIST, ""); } - - //return c; } catch (IllegalArgumentException e) { System.out.println("\tOOPS!!! I'm sorry, but I don't know what that means :-("); c = new DoNothingCommand(ActionType.LIST, ""); } return c; - } } diff --git a/src/main/java/luke/files/Memory.java b/src/main/java/luke/files/Memory.java index 622144036..479ef00c2 100644 --- a/src/main/java/luke/files/Memory.java +++ b/src/main/java/luke/files/Memory.java @@ -6,7 +6,6 @@ import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; -//import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; @@ -25,9 +24,7 @@ public static ArrayList readMemory(String filePath) throws FileNotFoundExc System.out.println("\t" + currentLine); String taskDetails = currentLine.substring(0,5); - //System.out.println(taskDetails); String taskDescription = currentLine.substring(6); - //System.out.println(taskDescription); char[] characters = taskDetails.toCharArray(); try { Task newTask; @@ -45,7 +42,6 @@ public static ArrayList readMemory(String filePath) throws FileNotFoundExc newTask = new Todo("error"); break; } - tasks.add(newTask); } catch (LukeTimeError e) { System.out.println("\tsomethings wrong"); @@ -58,8 +54,8 @@ public static void storeMemory(String filePath, ArrayList taskList){ try { FileWriter fw = new FileWriter(filePath); //overwrite file - for (int i = 0; i < taskList.size(); i += 1) { - fw.write(taskList.get(i).memoryString() + "\n"); + for (Task currentTask : taskList) { + fw.write(currentTask.memoryString() + "\n"); } fw.close(); @@ -68,7 +64,6 @@ public static void storeMemory(String filePath, ArrayList taskList){ } catch (IOException e) { System.out.println("\tIO Exception: fail to store memory"); - //return; } } diff --git a/src/main/java/luke/files/Storage.java b/src/main/java/luke/files/Storage.java index 2af38edcd..9c1ab1e54 100644 --- a/src/main/java/luke/files/Storage.java +++ b/src/main/java/luke/files/Storage.java @@ -18,7 +18,6 @@ public Storage(String filePath) { System.out.println("\n\tRetrieving memory...\n"); tasks = Memory.readMemory(filePath); System.out.println("\n\tMemory retrieval successful!\n"); - //return tasks; } catch (FileNotFoundException e) { System.out.println("\tNo existing memory. (1)"); } @@ -32,8 +31,6 @@ public Storage(String filePath) { System.out.println("\tSecurityException."); } } - //return null; - } public ArrayList load() { @@ -42,7 +39,6 @@ public ArrayList load() { public void store(TaskList tasksToStore) { //store in memory.txt - Memory.storeMemory("./out/artifacts/ip_jar/memory.txt", tasksToStore.getMainTaskList()); System.out.println("\tBye. Hope to see you again soon!"); diff --git a/src/main/java/luke/tasks/Deadline.java b/src/main/java/luke/tasks/Deadline.java index 3a099783d..51bebc1c8 100644 --- a/src/main/java/luke/tasks/Deadline.java +++ b/src/main/java/luke/tasks/Deadline.java @@ -16,12 +16,6 @@ public Deadline(String taskDescription) throws LukeTimeError { } description = taskDescription.substring(0, slashCut); -/* - if (description.length() <= 1) { - System.out.println("length prob"); - throw new IndexOutOfBoundsException(); - } - */ setDate(taskDescription.substring(slashCut + 1)); } @@ -46,12 +40,6 @@ public void setDate(String dateString) throws LukeTimeError { date = dateString.substring(spaceCut + 1); } - /*@Override - public String getType() { - return "deadline"; - } - - */ @Override public void printGuide() { System.out.println(deadlineGuide); @@ -59,7 +47,6 @@ public void printGuide() { @Override public String toString() { - //super.toString(); String isDoneString; if (isDone()) { diff --git a/src/main/java/luke/tasks/Event.java b/src/main/java/luke/tasks/Event.java index 4978a7806..08e0d36f5 100644 --- a/src/main/java/luke/tasks/Event.java +++ b/src/main/java/luke/tasks/Event.java @@ -18,10 +18,6 @@ public Event(String taskDescription) throws LukeTimeError { description = taskDescription.substring(0, slashCut); - if (description.length() <= 1) { - throw new IndexOutOfBoundsException(); - } - String taskDuration = taskDescription.substring(slashCut + 1); setDates(taskDuration); } @@ -64,14 +60,6 @@ public void setDates(String dates) throws LukeTimeError { endDate = dates.substring(3); } - /* - @Override - public String getType() { - return "event"; - } - - */ - @Override public void printGuide() { System.out.println(eventGuide); diff --git a/src/main/java/luke/tasks/Task.java b/src/main/java/luke/tasks/Task.java index 292ace4b2..876a301b2 100644 --- a/src/main/java/luke/tasks/Task.java +++ b/src/main/java/luke/tasks/Task.java @@ -27,20 +27,9 @@ public void setDone(boolean done) { } public void printGuide() { - //nothing + //do nothing } -/* - public String getType() { - return "task"; - } - - */ - /*@Override - public String toString() { - return ""; - } - */ public String memoryString() { String isDoneString; diff --git a/src/main/java/luke/tasks/TaskList.java b/src/main/java/luke/tasks/TaskList.java index 612e98f17..e8ec8a33d 100644 --- a/src/main/java/luke/tasks/TaskList.java +++ b/src/main/java/luke/tasks/TaskList.java @@ -8,6 +8,7 @@ public class TaskList{ private ArrayList mainTaskList; public int numberOfTasks; + public TaskList(ArrayList thetasks) throws LukeTimeError { mainTaskList = new ArrayList(); numberOfTasks = 0; @@ -38,7 +39,6 @@ public int size() { public Task get(int TaskNumber) throws IndexOutOfBoundsException { return mainTaskList.get(TaskNumber); - } public ArrayList getMainTaskList() { diff --git a/src/main/java/luke/user/LukeTimeError.java b/src/main/java/luke/user/LukeTimeError.java index 630b57120..907a7c61c 100644 --- a/src/main/java/luke/user/LukeTimeError.java +++ b/src/main/java/luke/user/LukeTimeError.java @@ -1,6 +1,5 @@ package luke.user; public class LukeTimeError extends Exception { - @Override public String getMessage() { return "LukeTimeError"; diff --git a/src/main/java/luke/user/Ui.java b/src/main/java/luke/user/Ui.java index 0440bdb87..3071a46d7 100644 --- a/src/main/java/luke/user/Ui.java +++ b/src/main/java/luke/user/Ui.java @@ -42,5 +42,4 @@ public String readCommand() { echo = userInput.nextLine(); return echo; } - } From b8fe2519a8c5c7805ba56e40ccc3b640a5737a0e Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Fri, 6 Oct 2023 01:58:31 +0800 Subject: [PATCH 61/77] Add JavaDoc comments --- src/main/java/Luke.java | 22 ++++++++- src/main/java/luke/actions/ActionType.java | 4 ++ src/main/java/luke/actions/AddCommand.java | 22 +++++++++ src/main/java/luke/actions/Command.java | 41 ++++++++++++++++- src/main/java/luke/actions/DeleteCommand.java | 18 ++++++++ .../java/luke/actions/DoNothingCommand.java | 4 ++ src/main/java/luke/actions/ExitCommand.java | 19 ++++++++ src/main/java/luke/actions/FindCommand.java | 18 ++++++++ src/main/java/luke/actions/ListCommand.java | 11 +++++ src/main/java/luke/actions/MarkCommand.java | 17 +++++++ src/main/java/luke/actions/Parser.java | 10 ++++ src/main/java/luke/files/Memory.java | 16 +++++++ src/main/java/luke/files/Storage.java | 19 ++++++++ src/main/java/luke/tasks/Deadline.java | 34 ++++++++++++++ src/main/java/luke/tasks/Event.java | 39 ++++++++++++++++ src/main/java/luke/tasks/Task.java | 35 +++++++++++++- src/main/java/luke/tasks/TaskList.java | 46 +++++++++++++++++-- src/main/java/luke/tasks/Todo.java | 23 +++++++++- src/main/java/luke/user/LukeTimeError.java | 5 ++ src/main/java/luke/user/Ui.java | 31 ++++++++++++- 20 files changed, 424 insertions(+), 10 deletions(-) diff --git a/src/main/java/Luke.java b/src/main/java/Luke.java index 00e0284d7..cdebbba12 100644 --- a/src/main/java/Luke.java +++ b/src/main/java/Luke.java @@ -5,13 +5,23 @@ import luke.tasks.*; import luke.files.*; +/** + * The Luke Class represents the main application class for Luke, a task management application. + * It manages the user interface, task storage, and task list. + */ public class Luke { private Storage storage; private TaskList tasks; private Ui ui; - public Luke(String filePath) {//i dont get how this filePath works + /** + * Constructs a Luke object. + * + * @param filePath The file path to the storage file. + * The storage file contains task data that will be loaded into the application. + */ + public Luke(String filePath) { ui = new Ui(); storage = new Storage(filePath); try { @@ -22,6 +32,11 @@ public Luke(String filePath) {//i dont get how this filePath works } } + /** + * Runs the Luke application. + * It displays a welcome message, reads user commands, and executes corresponding actions. + * The application continues running until the user exits. + */ public void run() { ui.showWelcome(); boolean isExit = false; @@ -42,6 +57,11 @@ public void run() { } } + /** + * The main method that starts the Luke application. + * + * @param args The command-line arguments (not used in this application). + */ public static void main(String[] args) { new Luke("./out/artifacts/ip_jar/memory.txt").run(); //new Luke("data/tasks.txt").run(); diff --git a/src/main/java/luke/actions/ActionType.java b/src/main/java/luke/actions/ActionType.java index 4fe2d21ec..d763a25e7 100644 --- a/src/main/java/luke/actions/ActionType.java +++ b/src/main/java/luke/actions/ActionType.java @@ -1,5 +1,9 @@ package luke.actions; +/** + * The ActionType enum represents the various types of actions that can be performed in the LukeTime application. + * Each action corresponds to a specific user command. + */ public enum ActionType { LIST, FIND, MARK, UNMARK, TODO, DEADLINE, EVENT, DELETE, BYE } diff --git a/src/main/java/luke/actions/AddCommand.java b/src/main/java/luke/actions/AddCommand.java index 370dcb290..5d59e2932 100644 --- a/src/main/java/luke/actions/AddCommand.java +++ b/src/main/java/luke/actions/AddCommand.java @@ -7,8 +7,23 @@ import static luke.actions.ActionType.*; +/** + * The AddCommand Class represents a command for adding a task to the Luke application. + * It extends the Command class and includes specific behavior for adding different types of tasks. + */ public class AddCommand extends Command { + /** + * The latest task created as a result of the add command. + */ private Task latestTask; + + /** + * Constructs an AddCommand with the specified action type and parameters. + * + * @param theAction The action type (TODO, DEADLINE, EVENT). + * @param parameters The parameters provided with the command (task description or task details). + * @throws LukeTimeError If there are missing or invalid arguments for creating the task. + */ public AddCommand(ActionType theAction, String parameters) throws LukeTimeError { super(theAction, parameters); @@ -34,6 +49,13 @@ public AddCommand(ActionType theAction, String parameters) throws LukeTimeError } + /** + * Executes the AddCommand to add the latest task to the task list. + * + * @param tasks The task list to which the task will be added. + * @param ui The user interface for displaying messages. + * @param storage The storage for saving task changes (not used in this case). + */ @Override public void execute(TaskList tasks, Ui ui, Storage storage) { //ui has String echo, storage has ArrayList tasks, tasks has ArrayList mainTaskList; diff --git a/src/main/java/luke/actions/Command.java b/src/main/java/luke/actions/Command.java index 721dbcf6c..564cfc179 100644 --- a/src/main/java/luke/actions/Command.java +++ b/src/main/java/luke/actions/Command.java @@ -4,24 +4,63 @@ import luke.tasks.*; import luke.user.Ui; +/** + * The Command class represents a generic command in the LukeTime application. + * It serves as the base class for specific command types, such as AddCommand, ListCommand, etc. + */ public abstract class Command { + + /** + * The type of action associated with the command. + */ protected ActionType theAction; - protected String parameters; //no. or description + + /** + * Additional parameters provided with the command (e.g., task description or task number). + */ + protected String parameters; + + /** + * Flag indicating whether the command triggers an exit from the application. + */ private boolean isExit; + /** + * Constructs a Command with the specified action type and parameters. + * + * @param theAction The type of action associated with the command. + * @param parameters Additional parameters provided with the command. + */ public Command(ActionType theAction, String parameters) { this.theAction = theAction; this.parameters = parameters; } + /** + * Executes the command with the given task list, user interface, and storage. + * + * @param tasks The task list used for command execution. + * @param ui The user interface for displaying messages. + * @param storage The storage for saving task changes (not used in all commands). + */ public void execute(TaskList tasks, Ui ui, Storage storage) { //do nothing? should not be executed } + /** + * Sets the exit flag to indicate whether the command triggers an exit from the application. + * + * @param isExit True if the command triggers an exit, false otherwise. + */ public void setIsExit(boolean isExit) { this.isExit = isExit; } + /** + * Checks if the command triggers an exit from the application. + * + * @return True if the command triggers an exit, false otherwise. + */ public boolean isExit() { return isExit; } diff --git a/src/main/java/luke/actions/DeleteCommand.java b/src/main/java/luke/actions/DeleteCommand.java index c84e33d9b..dbb431ddf 100644 --- a/src/main/java/luke/actions/DeleteCommand.java +++ b/src/main/java/luke/actions/DeleteCommand.java @@ -4,11 +4,29 @@ import luke.tasks.TaskList; import luke.user.Ui; +/** + * The DeleteCommand Class represents a command for deleting a task in the Luke application. + * It extends the Command class and includes specific behavior for deleting a task. + */ public class DeleteCommand extends Command { + + /** + * Constructs a DeleteCommand with the specified action type and parameters. + * + * @param theAction The action type (DELETE). + * @param parameters The parameters provided with the command (task number to delete). + */ public DeleteCommand(ActionType theAction, String parameters) { super(theAction, parameters); } + /** + * Executes the DeleteCommand to remove a task from the task list. + * + * @param tasks The task list from which the task will be deleted. + * @param ui The user interface for displaying messages. + * @param storage The storage for saving task changes (not used in this case). + */ @Override public void execute(TaskList tasks, Ui ui, Storage storage) { try { diff --git a/src/main/java/luke/actions/DoNothingCommand.java b/src/main/java/luke/actions/DoNothingCommand.java index 82b5c11cd..b162de63c 100644 --- a/src/main/java/luke/actions/DoNothingCommand.java +++ b/src/main/java/luke/actions/DoNothingCommand.java @@ -1,5 +1,9 @@ package luke.actions; +/** + * The DoNothingCommand class represents a null command. + * It extends the Command class and is used when there are errors or invalid input in the user's command. + */ public class DoNothingCommand extends Command { public DoNothingCommand(ActionType theAction, String parameters) { super(theAction, parameters); diff --git a/src/main/java/luke/actions/ExitCommand.java b/src/main/java/luke/actions/ExitCommand.java index 31020125b..14105df50 100644 --- a/src/main/java/luke/actions/ExitCommand.java +++ b/src/main/java/luke/actions/ExitCommand.java @@ -4,11 +4,30 @@ import luke.tasks.TaskList; import luke.user.Ui; +/** + * The ExitCommand class represents a command for exiting the Luke application. + * It extends the Command class and includes specific behavior for exiting the application. + */ public class ExitCommand extends Command { + + /** + * Constructs an ExitCommand with the specified action type and parameters. + * + * @param theAction The action type (BYE). + * @param parameters The parameters provided with the command (not used in this case). + */ public ExitCommand(ActionType theAction, String parameters) { super(theAction, parameters); } + /** + * Executes the ExitCommand to store the task list and close the application. + * + * @param tasks The task list to be stored. + * @param ui The user interface for displaying messages. + * @param storage The storage for saving task changes. + * @throws IllegalArgumentException If there is an issue with storing the task list. + */ @Override public void execute(TaskList tasks, Ui ui, Storage storage) throws IllegalArgumentException{ storage.store(tasks); diff --git a/src/main/java/luke/actions/FindCommand.java b/src/main/java/luke/actions/FindCommand.java index 47a575f9d..1ffad5b30 100644 --- a/src/main/java/luke/actions/FindCommand.java +++ b/src/main/java/luke/actions/FindCommand.java @@ -4,11 +4,29 @@ import luke.tasks.TaskList; import luke.user.Ui; +/** + * The FindCommand Class represents a command for finding tasks in the Luke application based on a keyword. + * It extends the Command class and includes specific behavior for finding tasks. + */ public class FindCommand extends Command { + + /** + * Constructs a FindCommand with the specified action type and keyword parameters. + * + * @param theAction The action type (FIND). + * @param parameters The keyword parameters used for searching tasks. + */ public FindCommand(ActionType theAction, String parameters) { super(theAction, parameters); } + /** + * Executes the FindCommand to search for and display tasks that match the provided keyword. + * + * @param tasks The task list to search within. + * @param ui The user interface for displaying messages. + * @param storage The storage for saving task changes (not used in this case). + */ @Override public void execute(TaskList tasks, Ui ui, Storage storage) { System.out.println("\tHere are the matching tasks in your list:"); diff --git a/src/main/java/luke/actions/ListCommand.java b/src/main/java/luke/actions/ListCommand.java index b18542cff..c5aaa6b10 100644 --- a/src/main/java/luke/actions/ListCommand.java +++ b/src/main/java/luke/actions/ListCommand.java @@ -4,11 +4,22 @@ import luke.tasks.TaskList; import luke.user.Ui; +/** + * The ListCommand Class represents a command for listing tasks in the Luke application. + * It extends the Command class and includes specific behavior for listing tasks. + */ public class ListCommand extends Command { public ListCommand(ActionType theAction, String parameters) { super(theAction, parameters); } + /** + * Executes the ListCommand to display the list of tasks. + * + * @param tasks The task list to be displayed. + * @param ui The user interface for displaying messages. + * @param storage The storage for saving task changes (not used in this case). + */ @Override public void execute(TaskList tasks, Ui ui, Storage storage) { System.out.println("\tHere are the tasks in your list:"); diff --git a/src/main/java/luke/actions/MarkCommand.java b/src/main/java/luke/actions/MarkCommand.java index 445e3b140..f08a3e038 100644 --- a/src/main/java/luke/actions/MarkCommand.java +++ b/src/main/java/luke/actions/MarkCommand.java @@ -7,9 +7,19 @@ import static luke.actions.ActionType.MARK; import static luke.actions.ActionType.UNMARK; +/** + * The MarkCommand Class represents a command for marking or unmarking tasks as done in the Luke application. + * It extends the Command class and includes specific behavior for marking and unmarking tasks. + */ public class MarkCommand extends Command { private boolean isDone; + /** + * Constructs a MarkCommand with the specified action type and parameters. + * + * @param theAction The action type (MARK or UNMARK). + * @param parameters The parameters provided with the command. + */ public MarkCommand(ActionType theAction, String parameters) { super(theAction, parameters); @@ -21,6 +31,13 @@ public MarkCommand(ActionType theAction, String parameters) { } } + /** + * Executes the MarkCommand to mark or unmark a task as done in the task list. + * + * @param tasks The task list where the task should be marked or unmarked. + * @param ui The user interface for displaying messages. + * @param storage The storage for saving task changes. + */ @Override public void execute(TaskList tasks, Ui ui, Storage storage) { int taskNumber = Integer.parseInt(parameters) - 1; diff --git a/src/main/java/luke/actions/Parser.java b/src/main/java/luke/actions/Parser.java index ce3742624..8b33a3f5d 100644 --- a/src/main/java/luke/actions/Parser.java +++ b/src/main/java/luke/actions/Parser.java @@ -2,9 +2,19 @@ import luke.user.LukeTimeError; +/** + * The Parser Class handles the parsing of user input into valid commands. + */ public class Parser{ //user input from Ui to luke command to Command + /** + * Parses the user's full command and returns an appropriate Command object. + * + * @param fullCommand The full user input command. + * @return A Command object corresponding to the parsed command. + * @throws LukeTimeError If an error specific to the LukeTime application occurs during parsing. + */ public static Command parse(String fullCommand) throws LukeTimeError { ActionType theAction; String parameters; diff --git a/src/main/java/luke/files/Memory.java b/src/main/java/luke/files/Memory.java index 479ef00c2..7facf0d78 100644 --- a/src/main/java/luke/files/Memory.java +++ b/src/main/java/luke/files/Memory.java @@ -11,8 +11,18 @@ import java.io.IOException; import java.util.ArrayList; +/** + * The Memory Class provides methods for reading from and storing tasks to a file. + */ public class Memory { + /** + * Reads tasks from a specified file and returns them as an ArrayList of Task objects. + * + * @param filePath The path to the file to read tasks from. + * @return An ArrayList of Task objects read from the file. + * @throws FileNotFoundException If the specified file is not found. + */ public static ArrayList readMemory(String filePath) throws FileNotFoundException { ArrayList tasks = new ArrayList<>(); @@ -50,6 +60,12 @@ public static ArrayList readMemory(String filePath) throws FileNotFoundExc return tasks; } + /** + * Stores a list of Task objects to a specified file. + * + * @param filePath The path to the file to store tasks in. + * @param taskList The ArrayList of Task objects to be stored. + */ public static void storeMemory(String filePath, ArrayList taskList){ try { FileWriter fw = new FileWriter(filePath); //overwrite file diff --git a/src/main/java/luke/files/Storage.java b/src/main/java/luke/files/Storage.java index 9c1ab1e54..13eee8996 100644 --- a/src/main/java/luke/files/Storage.java +++ b/src/main/java/luke/files/Storage.java @@ -8,9 +8,18 @@ import java.io.IOException; import java.util.ArrayList; +/** + * The Storage Class handles the reading and writing of task data from/to a file. + */ public class Storage { private ArrayList tasks; + /** + * Constructs a Storage object with the specified file path. If the file exists, + * it retrieves tasks from the file. If the file doesn't exist, it creates a new file. + * + * @param filePath The path to the file where task data is stored. + */ public Storage(String filePath) { File taskListFile = new File(filePath); if (taskListFile.exists()) { @@ -33,10 +42,20 @@ public Storage(String filePath) { } } + /** + * Loads and returns the ArrayList of Task objects retrieved from the file. + * + * @return An ArrayList of Task objects loaded from the file. + */ public ArrayList load() { return tasks; } + /** + * Stores the main task list to a specified file path. + * + * @param tasksToStore The TaskList object containing the main task list. + */ public void store(TaskList tasksToStore) { //store in memory.txt Memory.storeMemory("./out/artifacts/ip_jar/memory.txt", tasksToStore.getMainTaskList()); diff --git a/src/main/java/luke/tasks/Deadline.java b/src/main/java/luke/tasks/Deadline.java index 51bebc1c8..c3d60115f 100644 --- a/src/main/java/luke/tasks/Deadline.java +++ b/src/main/java/luke/tasks/Deadline.java @@ -1,10 +1,20 @@ package luke.tasks; import luke.user.LukeTimeError; +/** + * The Deadline Class represents a task of type "Deadline" in the LukeTime application. + * It extends the Task class and includes specific behavior for deadline tasks. + */ public class Deadline extends Task { protected String date; protected String deadlineGuide = "\tdeadline /by "; + /** + * Constructs a Deadline task with the specified task description and deadline date. + * + * @param taskDescription The description of the deadline task including the deadline date. + * @throws LukeTimeError If there are syntax or formatting errors in the task description. + */ public Deadline(String taskDescription) throws LukeTimeError { super(taskDescription); @@ -20,10 +30,21 @@ public Deadline(String taskDescription) throws LukeTimeError { setDate(taskDescription.substring(slashCut + 1)); } + /** + * Gets the deadline date of the deadline task. + * + * @return The deadline date of the deadline task. + */ public String getDate() { return date; } + /** + * Parses and sets the deadline date of the deadline task from the provided date string. + * + * @param dateString The date string containing the deadline date information. + * @throws LukeTimeError If there are syntax or formatting errors in the date string. + */ public void setDate(String dateString) throws LukeTimeError { String[] words = dateString.split(" "); if (!words[0].equals("by")) { @@ -40,11 +61,19 @@ public void setDate(String dateString) throws LukeTimeError { date = dateString.substring(spaceCut + 1); } + /** + * Displays a guide on how to format a deadline task when printing an error message. + */ @Override public void printGuide() { System.out.println(deadlineGuide); } + /** + * Returns a string representation of the deadline task, including its completion status and deadline date. + * + * @return A string representation of the deadline task. + */ @Override public String toString() { String isDoneString; @@ -58,6 +87,11 @@ public String toString() { return "\t[D]" + isDoneString + " " + getDescription() + "(do by: " + getDate() + ")"; } + /** + * Returns a string representation of the deadline task for memory storage. + * + * @return A string representation of the deadline task for memory storage. + */ @Override public String memoryString() { String isDoneString; diff --git a/src/main/java/luke/tasks/Event.java b/src/main/java/luke/tasks/Event.java index 08e0d36f5..526844cba 100644 --- a/src/main/java/luke/tasks/Event.java +++ b/src/main/java/luke/tasks/Event.java @@ -1,11 +1,21 @@ package luke.tasks; import luke.user.LukeTimeError; +/** + * The Event class represents a task of type "Event" in the LukeTime application. + * It extends the Task class and includes specific behavior for event tasks. + */ public class Event extends Task { protected String startDate; protected String endDate; protected String eventGuide = "\tevent /from /to "; + /** + * Constructs an Event task with the specified task description, start date, and end date. + * + * @param taskDescription The description of the event task including start and end dates. + * @throws LukeTimeError If there are syntax or formatting errors in the task description. + */ public Event(String taskDescription) throws LukeTimeError { super(taskDescription); @@ -22,14 +32,30 @@ public Event(String taskDescription) throws LukeTimeError { setDates(taskDuration); } + /** + * Gets the start date of the event. + * + * @return The start date of the event. + */ public String getStartDate() { return startDate; } + /** + * Gets the end date of the event. + * + * @return The end date of the event. + */ public String getEndDate() { return endDate; } + /** + * Parses and sets the start and end dates of the event from the provided date string. + * + * @param dates The date string containing start and end date information. + * @throws LukeTimeError If there are syntax or formatting errors in the date string. + */ public void setDates(String dates) throws LukeTimeError { String[] words = dates.split(" "); if (!words[0].equals("from")) { @@ -60,11 +86,19 @@ public void setDates(String dates) throws LukeTimeError { endDate = dates.substring(3); } + /** + * Displays a guide on how to format an event task when printing an error message. + */ @Override public void printGuide() { System.out.println(eventGuide); } + /** + * Returns a string representation of the event task for printing. + * + * @return A string representation of the event task. + */ @Override public String toString() { //super.toString(); @@ -79,6 +113,11 @@ public String toString() { return "\t[E]" + isDoneString + " " + getDescription() + "(from: " + getStartDate() + "to: " + getEndDate() + ")"; } + /** + * Returns a string representation of the event task for memory storage. + * + * @return A string representation of the event task for memory storage. + */ @Override public String memoryString() { String isDoneString; diff --git a/src/main/java/luke/tasks/Task.java b/src/main/java/luke/tasks/Task.java index 876a301b2..263c71ec3 100644 --- a/src/main/java/luke/tasks/Task.java +++ b/src/main/java/luke/tasks/Task.java @@ -1,22 +1,46 @@ package luke.tasks; +/** + * The Task Class represents a generic task in the LukeTime application. + * It serves as the base class for various types of tasks and provides common task attributes and methods. + */ public abstract class Task { protected String description; protected boolean isDone; + /** + * Constructs a Task object with the specified description and sets its initial completion status to false. + * + * @param description The description of the task. + */ public Task(String description) { this.description = description; isDone = false; } + /** + * Gets the description of the task. + * + * @return The description of the task. + */ public String getDescription() { return description; } + /** + * Checks if the task is marked as done. + * + * @return true if the task is done, false otherwise. + */ public boolean isDone() { return isDone; } + /** + * Sets the completion status of the task and displays a corresponding message. + * + * @param done true if the task is done, false otherwise. + */ public void setDone(boolean done) { if (done) { System.out.println("\tWoohoo! You have accomplished:"); @@ -26,10 +50,18 @@ public void setDone(boolean done) { isDone = done; } + /** + * Provides a default implementation for printing a guide specific to each task type. + */ public void printGuide() { - //do nothing + //Default Implementation: do nothing } + /** + * Returns a string representation of the task for memory storage. + * + * @return A string representation of the task for memory storage. + */ public String memoryString() { String isDoneString; @@ -41,5 +73,4 @@ public String memoryString() { return "[T]" + isDoneString + " task" + getDescription(); } - } \ No newline at end of file diff --git a/src/main/java/luke/tasks/TaskList.java b/src/main/java/luke/tasks/TaskList.java index e8ec8a33d..d6957c1a7 100644 --- a/src/main/java/luke/tasks/TaskList.java +++ b/src/main/java/luke/tasks/TaskList.java @@ -3,12 +3,22 @@ import java.util.ArrayList; import luke.user.LukeTimeError; +/** + * The TaskList Class contains a list of tasks and provides operations to manage tasks. + */ public class TaskList{ //contains the task list e.g., it has operations to add/delete tasks in the list private ArrayList mainTaskList; public int numberOfTasks; + /** + * Constructs a TaskList object from an existing ArrayList of tasks. + * + * @param thetasks An ArrayList of Task objects to initialize the task list with. + * @throws LukeTimeError If an error specific to the LukeTime application occurs during initialization. + */ + public TaskList(ArrayList thetasks) throws LukeTimeError { mainTaskList = new ArrayList(); numberOfTasks = 0; @@ -17,30 +27,58 @@ public TaskList(ArrayList thetasks) throws LukeTimeError { } } + /** + * Constructs an empty TaskList object. + */ public TaskList() { } + /** + * Adds a task to the task list. + * + * @param taskName The Task object to be added. + */ public void addTask(Task taskName) { mainTaskList.add(taskName); - //System.out.println(numbers); numberOfTasks += 1; } + /** + * Removes a task from the task list by its index. + * + * @param taskNumber The index of the task to be removed. + */ public void removeTask(int taskNumber) { mainTaskList.remove(taskNumber); - //System.out.println(numbers); numberOfTasks -= 1; } + /** + * Returns the number of tasks in the task list. + * + * @return The number of tasks in the task list. + */ public int size() { return numberOfTasks; } - public Task get(int TaskNumber) throws IndexOutOfBoundsException { - return mainTaskList.get(TaskNumber); + /** + * Retrieves a task from the task list by its index. + * + * @param taskNumber The index of the task to be retrieved. + * @return The Task object at the specified index. + * @throws IndexOutOfBoundsException If the specified index is out of bounds. + */ + public Task get(int taskNumber) throws IndexOutOfBoundsException { + return mainTaskList.get(taskNumber); } + /** + * Returns the main ArrayList of Task objects containing the task list. + * + * @return An ArrayList of Task objects representing the task list. + */ public ArrayList getMainTaskList() { return mainTaskList; } diff --git a/src/main/java/luke/tasks/Todo.java b/src/main/java/luke/tasks/Todo.java index a34a372d2..a01275523 100644 --- a/src/main/java/luke/tasks/Todo.java +++ b/src/main/java/luke/tasks/Todo.java @@ -1,9 +1,18 @@ package luke.tasks; +/** + * The Todo class represents a task of type "Todo" in the Luke application. + * It extends the Task class and includes specific behavior for todo tasks. + */ public class Todo extends Task { //protected boolean isDone; protected String todoGuide = "\ttodo "; + /** + * Constructs a Todo task with the specified description. + * + * @param description The description of the todo task. + */ public Todo(String description) { super(description); //ensures superclass is properly initialised @@ -14,11 +23,19 @@ public Todo(String description) { } } + /** + * Displays a guide on how to format a todo task when printing an error message. + */ @Override public void printGuide() { System.out.println(todoGuide); } + /** + * Returns a string representation of the todo task for printing. + * + * @return A string representation of the todo task. + */ @Override public String toString() { //super.toString(); @@ -33,6 +50,11 @@ public String toString() { return "\t[T]" + isDoneString + " " + getDescription(); } + /** + * Returns a string representation of the todo task for storing in memory. + * + * @return A string representation of the todo task for memory storage. + */ @Override public String memoryString() { String isDoneString; @@ -45,5 +67,4 @@ public String memoryString() { return "[T]" + isDoneString + getDescription(); } - } diff --git a/src/main/java/luke/user/LukeTimeError.java b/src/main/java/luke/user/LukeTimeError.java index 907a7c61c..9b0f60619 100644 --- a/src/main/java/luke/user/LukeTimeError.java +++ b/src/main/java/luke/user/LukeTimeError.java @@ -1,4 +1,9 @@ package luke.user; + +/** + * The LukeTimeError Class represents custom exceptions specific to the LukeTime application. + * It extends the Exception class. + */ public class LukeTimeError extends Exception { @Override public String getMessage() { diff --git a/src/main/java/luke/user/Ui.java b/src/main/java/luke/user/Ui.java index 3071a46d7..3e970d3de 100644 --- a/src/main/java/luke/user/Ui.java +++ b/src/main/java/luke/user/Ui.java @@ -2,19 +2,31 @@ import java.util.Scanner; +/** + * The Ui Class is responsible for user interaction, including reading user input and displaying messages. + */ public class Ui { //directly interact with user (read in (to Parser)/print) public String echo; public Scanner userInput; + + /** + * Constructs a Ui object and initializes the user input scanner. + */ public Ui () { userInput = new Scanner(System.in); } - //decompiler??? + /** + * Closes the user input scanner. + */ public void closeUi() { userInput.close(); } + /** + * Displays a welcome message with a logo when the application starts. + */ public void showWelcome() { String logo = "\t _ _ \n" + "\t| | _ _| | _____ \n" @@ -26,18 +38,35 @@ public void showWelcome() { System.out.println("\tWhat can I do for you?"); } + /** + * Displays a divider line to separate different sections of output. + */ public void showLine() { // show the divider line ("_______") System.out.println("\t____________________________________________________________"); } + + /** + * Displays an error message for loading issues. + */ public void showLoadingError() { System.out.println("Loading Error... (pls change)"); } + /** + * Displays an error message to the user. + * + * @param error The error message to be displayed. + */ public void showError(String error) { System.out.println(error); } + /** + * Reads a command from the user and returns it as a string. + * + * @return The user's input command as a string. + */ public String readCommand() { echo = userInput.nextLine(); return echo; From 54c9b4cbba91ff79d933d44ff78d90f090ef8e3d Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Fri, 6 Oct 2023 02:11:33 +0800 Subject: [PATCH 62/77] Fix Level-9 --- src/main/java/luke/actions/Parser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/luke/actions/Parser.java b/src/main/java/luke/actions/Parser.java index ce3742624..7e1768889 100644 --- a/src/main/java/luke/actions/Parser.java +++ b/src/main/java/luke/actions/Parser.java @@ -24,7 +24,7 @@ public static Command parse(String fullCommand) throws LukeTimeError { break; case FIND: - parameters = fullCommand.substring(4); + parameters = fullCommand.substring(5); c = new FindCommand(theAction, parameters); break; From 56970bdf2880e86927597e5657bbd19b5911b676 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Fri, 6 Oct 2023 03:30:08 +0800 Subject: [PATCH 63/77] Update docs\README.md --- docs/README.md | 166 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 157 insertions(+), 9 deletions(-) diff --git a/docs/README.md b/docs/README.md index 8077118eb..88aba00ed 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2,28 +2,176 @@ ## Features -### Feature-ABC +### Task List -Description of the feature. +Luke keeps a list of all the todo, deadlines and events. -### Feature-XYZ +### Store Memory -Description of the feature. +When closing Luke, all current tasks are stored in a txt file. +The next time Luke is opened, all tasks in the txt file is loaded back into Luke. ## Usage -### `Keyword` - Describe action -Describe the action and its outcome. +### `todo` - Add todo + +Add new task (todo) to your list. + +Example of usage: + +`todo read book` + +Expected outcome: + +New todo task added, so there will be a confirmation message. + +``` + Got it. I've added this task: + [T][ ] read book + Now you have 1 tasks in the list. +``` + +### `deadline` - Add deadline + +Add new task (deadline) to your list. + +Example of usage: + +`deadline return book /by next saturday` + +Expected outcome: + +New deadline task added, so there will be a confirmation message. + +``` + Got it. I've added this task: + [D][ ] return book (do by: next saturday) + Now you have 2 tasks in the list. +``` + +### `event` - Add event + +Add new task (event) to your list. + +Example of usage: + +`event reading club session /from friday 4 /to 6pm` + +Expected outcome: + +New event task added, so there will be a confirmation message. + +``` + Got it. I've added this task: + [E][ ] reading club session (from: friday 4 to: 6pm) + Now you have 1 tasks in the list. +``` + +### `list` - Lists all tasks + +Lists all tasks including their type (todo, deadline, event), their task description and whether they have been completed. Example of usage: -`keyword (optional arguments)` +`list` + +Expected outcome: + +This will display all your tasks, including their status (completed or not). + +``` + Here are the tasks in your list: + 1. [T][ ] read book + 2. [D][ ] return book (do by: next saturday) + 3. [E][ ] reading club session (from: friday 4 to: 6pm) +``` + +### `mark` - Mark a task as completed + +Mark a task as completed using the "mark" command followed by the task number. + +Example of usage: + +`mark 1` + +Expected outcome: + +This will mark the task with index 1 as completed. + +``` + Woohoo! You have accomplished: + [T][X] read book +``` + +### `unmark` - Mark a task as incomplete + +Mark a task as incomplete using the "unmark" command followed by the task number. + +Example of usage: + +`mark 1` + +Expected outcome: + +This will mark the task with index 1 as incomplete. + +``` + HA! You still have to complete: + [T][ ] read book +``` + + +### `find` - Find user's input in tasks descriptions + +Show the corresponding tasks. + +Example of usage: + +`find book` + +Expected outcome: + +List of tasks that have descriptions matching the user's input. + +``` + Here are the matching tasks in your list: + 1. [T][ ] read book + 2. [D][ ] return book (do by: next saturday) +``` + +### `delete` - Remove a task from the task list + +To delete a task from your list, use the "delete" command followed by the task number: + +Example of usage: + +`delete 2` + +Expected outcome: + +This will remove the task with index 2 from your list. + + +``` + Noted. I've removed this task: + [D][ ] return book (do by: next saturday) + Now you have 2 tasks in the list. +``` + +### `bye` - Close Luke + +Close Luke and store memory to a txt file. + +Example of usage: + +`bye` Expected outcome: -Description of the outcome. +Message whether memory is stored safely, and Luke is closed. ``` -expected output + Memory Stored Safely! + Bye. Hope to see you again soon! ``` From 688c7da62379616c424f8c22207f27d7ada0df09 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Fri, 6 Oct 2023 03:36:22 +0800 Subject: [PATCH 64/77] Update docs\README.md part 2 --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 88aba00ed..203765ecc 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,4 +1,4 @@ -# User Guide +# User Guide for Luke ## Features From 3ed47396d1a1627709ee275c5617a358ced06687 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Fri, 6 Oct 2023 11:06:45 +0800 Subject: [PATCH 65/77] Update docs\README.md part 3 --- docs/README.md | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/docs/README.md b/docs/README.md index 203765ecc..2b72e8357 100644 --- a/docs/README.md +++ b/docs/README.md @@ -4,7 +4,11 @@ ### Task List -Luke keeps a list of all the todo, deadlines and events. +Luke keeps a task list of all the todo, deadlines and events. + +### Mark as Completed/Incomplete + +You can mark tasks as completed or incompleted. ### Store Memory @@ -18,6 +22,10 @@ The next time Luke is opened, all tasks in the txt file is loaded back into Luke Add new task (todo) to your list. +Format of usage: + +`todo DESCRIPTION` + Example of usage: `todo read book` @@ -36,6 +44,10 @@ New todo task added, so there will be a confirmation message. Add new task (deadline) to your list. +Format of usage: + +`deadline DESCRIPTION /by DATE` + Example of usage: `deadline return book /by next saturday` @@ -54,6 +66,10 @@ New deadline task added, so there will be a confirmation message. Add new task (event) to your list. +Format of usage: + +`event DESCRIPTION /from STARTDATE /to ENDDATE` + Example of usage: `event reading club session /from friday 4 /to 6pm` @@ -70,7 +86,7 @@ New event task added, so there will be a confirmation message. ### `list` - Lists all tasks -Lists all tasks including their type (todo, deadline, event), their task description and whether they have been completed. +Lists all tasks in the task list. Example of usage: @@ -78,7 +94,7 @@ Example of usage: Expected outcome: -This will display all your tasks, including their status (completed or not). +This will display all your tasks, including their type (todo, deadline, event), their task description and their status (completed or not). ``` Here are the tasks in your list: @@ -91,6 +107,10 @@ This will display all your tasks, including their status (completed or not). Mark a task as completed using the "mark" command followed by the task number. +Format of usage: + +`mark INDEX` + Example of usage: `mark 1` @@ -108,9 +128,13 @@ This will mark the task with index 1 as completed. Mark a task as incomplete using the "unmark" command followed by the task number. +Format of usage: + +`unmark INDEX` + Example of usage: -`mark 1` +`unark 1` Expected outcome: @@ -126,6 +150,10 @@ This will mark the task with index 1 as incomplete. Show the corresponding tasks. +Format of usage: + +`find KEYWORD` + Example of usage: `find book` @@ -142,7 +170,11 @@ List of tasks that have descriptions matching the user's input. ### `delete` - Remove a task from the task list -To delete a task from your list, use the "delete" command followed by the task number: +To delete a task from your list, use the "delete" command followed by the task number. + +Format of usage: + +`delete INDEX` Example of usage: From a1a0256fdc742356f9635238360205650e5adbc5 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Fri, 6 Oct 2023 11:11:02 +0800 Subject: [PATCH 66/77] Update docs\README.md part 4 --- docs/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/README.md b/docs/README.md index 2b72e8357..14ff8e973 100644 --- a/docs/README.md +++ b/docs/README.md @@ -36,8 +36,8 @@ New todo task added, so there will be a confirmation message. ``` Got it. I've added this task: - [T][ ] read book - Now you have 1 tasks in the list. + [T][ ] read book + Now you have 1 tasks in the list. ``` ### `deadline` - Add deadline @@ -58,8 +58,8 @@ New deadline task added, so there will be a confirmation message. ``` Got it. I've added this task: - [D][ ] return book (do by: next saturday) - Now you have 2 tasks in the list. + [D][ ] return book (do by: next saturday) + Now you have 2 tasks in the list. ``` ### `event` - Add event From f21791fc978bae570a6f105ea628d30aba9a76e1 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Fri, 6 Oct 2023 11:51:56 +0800 Subject: [PATCH 67/77] Update Level 7 Save: Luke runs even if no memory.txt exists --- src/main/java/Luke.java | 3 +++ src/main/java/luke/files/Storage.java | 11 ++++++----- src/main/java/luke/tasks/TaskList.java | 5 +++-- src/main/java/luke/user/Ui.java | 9 ++++++++- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/main/java/Luke.java b/src/main/java/Luke.java index cdebbba12..a66020481 100644 --- a/src/main/java/Luke.java +++ b/src/main/java/Luke.java @@ -29,6 +29,9 @@ public Luke(String filePath) { } catch (LukeTimeError e) { ui.showLoadingError(); tasks = new TaskList(); + } catch (NullPointerException e) { + //ui.showNoMemoryError(); + tasks = new TaskList(); } } diff --git a/src/main/java/luke/files/Storage.java b/src/main/java/luke/files/Storage.java index 13eee8996..505e386d1 100644 --- a/src/main/java/luke/files/Storage.java +++ b/src/main/java/luke/files/Storage.java @@ -28,16 +28,17 @@ public Storage(String filePath) { tasks = Memory.readMemory(filePath); System.out.println("\n\tMemory retrieval successful!\n"); } catch (FileNotFoundException e) { - System.out.println("\tNo existing memory. (1)"); + System.out.println("\n\tNo existing memory. (1)\n"); } } else { try { - taskListFile.createNewFile(); - System.out.println("\tNo existing memory."); + if (taskListFile.createNewFile()) { + System.out.println("\n\tNo existing memory. Creating new memory...\n"); + } } catch (IOException e) { - System.out.println("\tIOException."); + System.out.println("\n\tIOException.\n"); } catch (SecurityException e) { - System.out.println("\tSecurityException."); + System.out.println("\n\tSecurityException.\n"); } } } diff --git a/src/main/java/luke/tasks/TaskList.java b/src/main/java/luke/tasks/TaskList.java index d6957c1a7..07d71f9c8 100644 --- a/src/main/java/luke/tasks/TaskList.java +++ b/src/main/java/luke/tasks/TaskList.java @@ -19,7 +19,7 @@ public class TaskList{ * @throws LukeTimeError If an error specific to the LukeTime application occurs during initialization. */ - public TaskList(ArrayList thetasks) throws LukeTimeError { + public TaskList(ArrayList thetasks) throws LukeTimeError, NullPointerException { mainTaskList = new ArrayList(); numberOfTasks = 0; for (Task item: thetasks) { @@ -31,7 +31,8 @@ public TaskList(ArrayList thetasks) throws LukeTimeError { * Constructs an empty TaskList object. */ public TaskList() { - + mainTaskList = new ArrayList(); + numberOfTasks = 0; } /** diff --git a/src/main/java/luke/user/Ui.java b/src/main/java/luke/user/Ui.java index 3e970d3de..9f3215d55 100644 --- a/src/main/java/luke/user/Ui.java +++ b/src/main/java/luke/user/Ui.java @@ -50,7 +50,14 @@ public void showLine() { * Displays an error message for loading issues. */ public void showLoadingError() { - System.out.println("Loading Error... (pls change)"); + System.out.println("\tError in loading memory."); + } + + /** + * Displays an error message for loading issues. + */ + public void showNoMemoryError() { + System.out.println("\tNo memory is loaded."); } /** From e1e19fb8255d27a13e46c35c907ee176e913d23d Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Fri, 6 Oct 2023 16:36:24 +0800 Subject: [PATCH 68/77] Update Level 7 Save: Luke runs even if no memory.txt exists part 2 --- .gitignore | 3 +- src/main/java/Luke.java | 22 ++++++++---- src/main/java/luke/files/Storage.java | 51 ++++++++++++++++----------- 3 files changed, 47 insertions(+), 29 deletions(-) diff --git a/.gitignore b/.gitignore index e4e8b982e..bfa90d182 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,5 @@ bin/ text-ui-test/EXPECTED-UNIX.TXT /src/main/java/META-INF -/src/main/java/luke/files/memory.txt \ No newline at end of file +/src/main/java/luke/files/memory.txt +/data/memory.txt \ No newline at end of file diff --git a/src/main/java/Luke.java b/src/main/java/Luke.java index a66020481..6a212050e 100644 --- a/src/main/java/Luke.java +++ b/src/main/java/Luke.java @@ -10,6 +10,7 @@ * It manages the user interface, task storage, and task list. */ public class Luke { + public static final String folderPath = "data"; private Storage storage; private TaskList tasks; @@ -17,13 +18,10 @@ public class Luke { /** * Constructs a Luke object. - * - * @param filePath The file path to the storage file. - * The storage file contains task data that will be loaded into the application. */ - public Luke(String filePath) { + public Luke() { ui = new Ui(); - storage = new Storage(filePath); + storage = new Storage(folderPath); try { tasks = new TaskList(storage.load()); } catch (LukeTimeError e) { @@ -66,8 +64,18 @@ public void run() { * @param args The command-line arguments (not used in this application). */ public static void main(String[] args) { - new Luke("./out/artifacts/ip_jar/memory.txt").run(); - //new Luke("data/tasks.txt").run(); + /* + String home = System.getProperty("user.home"); + java.nio.file.Path path = java.nio.file.Paths.get(home, "out", "artifacts", "ip_jar", "memory.txt"); + boolean directoryExists = java.nio.file.Files.exists(path); + + new Luke(path).run(); + + */ + + //new Luke("./out/artifacts/ip_jar/memory.txt").run(); + + new Luke().run(); } } diff --git a/src/main/java/luke/files/Storage.java b/src/main/java/luke/files/Storage.java index 505e386d1..f4149de73 100644 --- a/src/main/java/luke/files/Storage.java +++ b/src/main/java/luke/files/Storage.java @@ -12,35 +12,44 @@ * The Storage Class handles the reading and writing of task data from/to a file. */ public class Storage { + protected String filePath; + protected String folderPath; private ArrayList tasks; /** * Constructs a Storage object with the specified file path. If the file exists, * it retrieves tasks from the file. If the file doesn't exist, it creates a new file. - * - * @param filePath The path to the file where task data is stored. */ - public Storage(String filePath) { - File taskListFile = new File(filePath); - if (taskListFile.exists()) { - try { - System.out.println("\n\tRetrieving memory...\n"); - tasks = Memory.readMemory(filePath); - System.out.println("\n\tMemory retrieval successful!\n"); - } catch (FileNotFoundException e) { - System.out.println("\n\tNo existing memory. (1)\n"); - } + public Storage(String folderPath) { + this.folderPath = folderPath; + filePath = folderPath + "/memory.txt"; + + createDirectory(); + createFile(); + } + + public void createDirectory () { + File d = new File(folderPath); + if (d.mkdir()) { + System.out.println("Directory has been successfully created!"); } else { - try { - if (taskListFile.createNewFile()) { - System.out.println("\n\tNo existing memory. Creating new memory...\n"); - } - } catch (IOException e) { - System.out.println("\n\tIOException.\n"); - } catch (SecurityException e) { - System.out.println("\n\tSecurityException.\n"); + System.out.println("Directory cannot be created. Directory may already exist."); + } + System.out.println("Full path: " + d.getAbsolutePath()); + } + + public void createFile () { + File f = new File(filePath); + try { + if (f.createNewFile()) { + System.out.println("New memory file has been successfully created!"); + } else { + System.out.println("New memory file cannot be created. Memory file may already exist."); } + } catch (IOException e) { + System.out.println("An error occurred." + e.getMessage()); } + System.out.println("Full path: " + f.getAbsolutePath()); } /** @@ -59,7 +68,7 @@ public ArrayList load() { */ public void store(TaskList tasksToStore) { //store in memory.txt - Memory.storeMemory("./out/artifacts/ip_jar/memory.txt", tasksToStore.getMainTaskList()); + Memory.storeMemory(filePath, tasksToStore.getMainTaskList()); System.out.println("\tBye. Hope to see you again soon!"); } From 5c566bd43d59c4d3c0ea45df11d9523cdc01a4e2 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Fri, 6 Oct 2023 16:53:41 +0800 Subject: [PATCH 69/77] Update Level 7 Save: directory "data" is created and file "memory.txt" are created if they do not exist --- src/main/java/luke/files/Memory.java | 4 +++- src/main/java/luke/files/Storage.java | 24 ++++++++++++++++-------- src/main/java/luke/tasks/Deadline.java | 2 +- src/main/java/luke/tasks/Event.java | 2 +- src/main/java/luke/tasks/Todo.java | 2 +- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/main/java/luke/files/Memory.java b/src/main/java/luke/files/Memory.java index 7facf0d78..bf8750fa9 100644 --- a/src/main/java/luke/files/Memory.java +++ b/src/main/java/luke/files/Memory.java @@ -24,6 +24,7 @@ public class Memory { * @throws FileNotFoundException If the specified file is not found. */ public static ArrayList readMemory(String filePath) throws FileNotFoundException { + System.out.println("\n\tRetrieving memory..."); ArrayList tasks = new ArrayList<>(); @@ -34,7 +35,7 @@ public static ArrayList readMemory(String filePath) throws FileNotFoundExc System.out.println("\t" + currentLine); String taskDetails = currentLine.substring(0,5); - String taskDescription = currentLine.substring(6); + String taskDescription = currentLine.substring(7); char[] characters = taskDetails.toCharArray(); try { Task newTask; @@ -57,6 +58,7 @@ public static ArrayList readMemory(String filePath) throws FileNotFoundExc System.out.println("\tsomethings wrong"); } } + System.out.println("\tMemory retrieval successful!\n"); return tasks; } diff --git a/src/main/java/luke/files/Storage.java b/src/main/java/luke/files/Storage.java index f4149de73..226bbebae 100644 --- a/src/main/java/luke/files/Storage.java +++ b/src/main/java/luke/files/Storage.java @@ -24,32 +24,34 @@ public Storage(String folderPath) { this.folderPath = folderPath; filePath = folderPath + "/memory.txt"; + System.out.println(); createDirectory(); createFile(); + //tasks = Memory.readMemory(filePath); } public void createDirectory () { File d = new File(folderPath); if (d.mkdir()) { - System.out.println("Directory has been successfully created!"); + System.out.println("\tDirectory has been successfully created!"); } else { - System.out.println("Directory cannot be created. Directory may already exist."); + System.out.println("\tDirectory cannot be created. Directory may already exist."); } - System.out.println("Full path: " + d.getAbsolutePath()); + //System.out.println("\tFull path: " + d.getAbsolutePath()); } public void createFile () { File f = new File(filePath); try { if (f.createNewFile()) { - System.out.println("New memory file has been successfully created!"); + System.out.println("\tNew memory file has been successfully created!"); } else { - System.out.println("New memory file cannot be created. Memory file may already exist."); + System.out.println("\tNew memory file cannot be created. Memory file may already exist."); } } catch (IOException e) { - System.out.println("An error occurred." + e.getMessage()); + System.out.println("\tAn error occurred." + e.getMessage()); } - System.out.println("Full path: " + f.getAbsolutePath()); + System.out.println("\tFull path: " + f.getAbsolutePath()); } /** @@ -58,7 +60,13 @@ public void createFile () { * @return An ArrayList of Task objects loaded from the file. */ public ArrayList load() { - return tasks; + try { + tasks = Memory.readMemory(filePath); + return tasks; + } catch (FileNotFoundException e) { + System.out.println("An error occurred." + e.getMessage()); + } + return null; } /** diff --git a/src/main/java/luke/tasks/Deadline.java b/src/main/java/luke/tasks/Deadline.java index c3d60115f..b4f9bf018 100644 --- a/src/main/java/luke/tasks/Deadline.java +++ b/src/main/java/luke/tasks/Deadline.java @@ -102,6 +102,6 @@ public String memoryString() { isDoneString = "[ ]"; } - return "[D]" + isDoneString + getDescription() + "/by " + getDate(); + return "[D]" + isDoneString + " " + getDescription() + "/by " + getDate(); } } diff --git a/src/main/java/luke/tasks/Event.java b/src/main/java/luke/tasks/Event.java index 526844cba..22d0401f5 100644 --- a/src/main/java/luke/tasks/Event.java +++ b/src/main/java/luke/tasks/Event.java @@ -128,6 +128,6 @@ public String memoryString() { isDoneString = "[ ]"; } - return "[E]" + isDoneString + getDescription() + "/from " + getStartDate() + "/to " + getEndDate(); + return "[E]" + isDoneString + " " + getDescription() + "/from " + getStartDate() + "/to " + getEndDate(); } } diff --git a/src/main/java/luke/tasks/Todo.java b/src/main/java/luke/tasks/Todo.java index a01275523..191e553e3 100644 --- a/src/main/java/luke/tasks/Todo.java +++ b/src/main/java/luke/tasks/Todo.java @@ -65,6 +65,6 @@ public String memoryString() { isDoneString = "[ ]"; } - return "[T]" + isDoneString + getDescription(); + return "[T]" + isDoneString + " " + getDescription(); } } From 2e094bf480e320db4db8342bfcce71601e215c80 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Fri, 6 Oct 2023 17:03:01 +0800 Subject: [PATCH 70/77] Rename LukeTimeError to LukeException --- src/main/java/Luke.java | 6 +++--- src/main/java/luke/actions/AddCommand.java | 14 +++++++------- src/main/java/luke/actions/Parser.java | 10 +++++----- src/main/java/luke/files/Memory.java | 4 ++-- src/main/java/luke/tasks/Deadline.java | 16 ++++++++-------- src/main/java/luke/tasks/Event.java | 18 +++++++++--------- src/main/java/luke/tasks/TaskList.java | 6 +++--- src/main/java/luke/user/LukeException.java | 12 ++++++++++++ src/main/java/luke/user/LukeTimeError.java | 12 ------------ 9 files changed, 49 insertions(+), 49 deletions(-) create mode 100644 src/main/java/luke/user/LukeException.java delete mode 100644 src/main/java/luke/user/LukeTimeError.java diff --git a/src/main/java/Luke.java b/src/main/java/Luke.java index 6a212050e..4d3eaef24 100644 --- a/src/main/java/Luke.java +++ b/src/main/java/Luke.java @@ -1,6 +1,6 @@ import luke.actions.*; -import luke.user.LukeTimeError; +import luke.user.LukeException; import luke.user.Ui; import luke.tasks.*; import luke.files.*; @@ -24,7 +24,7 @@ public Luke() { storage = new Storage(folderPath); try { tasks = new TaskList(storage.load()); - } catch (LukeTimeError e) { + } catch (LukeException e) { ui.showLoadingError(); tasks = new TaskList(); } catch (NullPointerException e) { @@ -50,7 +50,7 @@ public void run() { c.execute(tasks, ui, storage); //tasks has ArrayList mainTaskList, ui has String echo, storage has ArrayList tasks isExit = c.isExit(); //for bye command - } catch (LukeTimeError e) { //from Parser.parse i think + } catch (LukeException e) { //from Parser.parse i think ui.showError(e.getMessage()); } finally { ui.showLine(); diff --git a/src/main/java/luke/actions/AddCommand.java b/src/main/java/luke/actions/AddCommand.java index 5d59e2932..defdcc698 100644 --- a/src/main/java/luke/actions/AddCommand.java +++ b/src/main/java/luke/actions/AddCommand.java @@ -2,7 +2,7 @@ import luke.files.Storage; import luke.tasks.*; -import luke.user.LukeTimeError; +import luke.user.LukeException; import luke.user.Ui; import static luke.actions.ActionType.*; @@ -22,9 +22,9 @@ public class AddCommand extends Command { * * @param theAction The action type (TODO, DEADLINE, EVENT). * @param parameters The parameters provided with the command (task description or task details). - * @throws LukeTimeError If there are missing or invalid arguments for creating the task. + * @throws LukeException If there are missing or invalid arguments for creating the task. */ - public AddCommand(ActionType theAction, String parameters) throws LukeTimeError { + public AddCommand(ActionType theAction, String parameters) throws LukeException { super(theAction, parameters); if (theAction == TODO) { @@ -33,17 +33,17 @@ public AddCommand(ActionType theAction, String parameters) throws LukeTimeError if (theAction == DEADLINE) { try { latestTask = new Deadline(parameters); - } catch (LukeTimeError e) { + } catch (LukeException e) { System.out.println("\tOOPS!!! You have missing/invalid arguments for deadline. No changes have been made."); - throw new LukeTimeError(); + throw new LukeException(); } } if (theAction == EVENT) { try { latestTask = new Event(parameters); - } catch (LukeTimeError e) { + } catch (LukeException e) { System.out.println("\tOOPS!!! You have missing/invalid arguments for event. No changes have been made."); - throw new LukeTimeError(); + throw new LukeException(); } } diff --git a/src/main/java/luke/actions/Parser.java b/src/main/java/luke/actions/Parser.java index 3bc7f6308..07360e4a0 100644 --- a/src/main/java/luke/actions/Parser.java +++ b/src/main/java/luke/actions/Parser.java @@ -1,6 +1,6 @@ package luke.actions; -import luke.user.LukeTimeError; +import luke.user.LukeException; /** * The Parser Class handles the parsing of user input into valid commands. @@ -13,9 +13,9 @@ public class Parser{ * * @param fullCommand The full user input command. * @return A Command object corresponding to the parsed command. - * @throws LukeTimeError If an error specific to the LukeTime application occurs during parsing. + * @throws LukeException If an error specific to the LukeTime application occurs during parsing. */ - public static Command parse(String fullCommand) throws LukeTimeError { + public static Command parse(String fullCommand) throws LukeException { ActionType theAction; String parameters; @@ -52,7 +52,7 @@ public static Command parse(String fullCommand) throws LukeTimeError { parameters = fullCommand.substring(9); try { c = new AddCommand(theAction, parameters); - } catch (LukeTimeError e) { + } catch (LukeException e) { c = new DoNothingCommand(ActionType.LIST, parameters); } break; @@ -61,7 +61,7 @@ public static Command parse(String fullCommand) throws LukeTimeError { parameters = fullCommand.substring(6); try { c = new AddCommand(theAction, parameters); - } catch (LukeTimeError e) { + } catch (LukeException e) { c = new DoNothingCommand(ActionType.LIST, parameters); } break; diff --git a/src/main/java/luke/files/Memory.java b/src/main/java/luke/files/Memory.java index bf8750fa9..ac29e8c04 100644 --- a/src/main/java/luke/files/Memory.java +++ b/src/main/java/luke/files/Memory.java @@ -1,6 +1,6 @@ package luke.files; -import luke.user.LukeTimeError; +import luke.user.LukeException; import luke.tasks.*; import java.io.File; @@ -54,7 +54,7 @@ public static ArrayList readMemory(String filePath) throws FileNotFoundExc break; } tasks.add(newTask); - } catch (LukeTimeError e) { + } catch (LukeException e) { System.out.println("\tsomethings wrong"); } } diff --git a/src/main/java/luke/tasks/Deadline.java b/src/main/java/luke/tasks/Deadline.java index b4f9bf018..13709e97c 100644 --- a/src/main/java/luke/tasks/Deadline.java +++ b/src/main/java/luke/tasks/Deadline.java @@ -1,5 +1,5 @@ package luke.tasks; -import luke.user.LukeTimeError; +import luke.user.LukeException; /** * The Deadline Class represents a task of type "Deadline" in the LukeTime application. @@ -13,16 +13,16 @@ public class Deadline extends Task { * Constructs a Deadline task with the specified task description and deadline date. * * @param taskDescription The description of the deadline task including the deadline date. - * @throws LukeTimeError If there are syntax or formatting errors in the task description. + * @throws LukeException If there are syntax or formatting errors in the task description. */ - public Deadline(String taskDescription) throws LukeTimeError { + public Deadline(String taskDescription) throws LukeException { super(taskDescription); int slashCut = taskDescription.indexOf("/"); if (slashCut <= 0) { System.out.println("\tThere is a missing task description. Please follow this format:"); printGuide(); - throw new LukeTimeError(); + throw new LukeException(); } description = taskDescription.substring(0, slashCut); @@ -43,20 +43,20 @@ public String getDate() { * Parses and sets the deadline date of the deadline task from the provided date string. * * @param dateString The date string containing the deadline date information. - * @throws LukeTimeError If there are syntax or formatting errors in the date string. + * @throws LukeException If there are syntax or formatting errors in the date string. */ - public void setDate(String dateString) throws LukeTimeError { + public void setDate(String dateString) throws LukeException { String[] words = dateString.split(" "); if (!words[0].equals("by")) { System.out.println("\tThere is a syntax problem. Please follow this format:"); printGuide(); - throw new LukeTimeError(); + throw new LukeException(); } int spaceCut = dateString.indexOf(" "); if (spaceCut <= 0) { System.out.println("\tThere is a missing date. Please follow this format:"); printGuide(); - throw new LukeTimeError(); + throw new LukeException(); } date = dateString.substring(spaceCut + 1); } diff --git a/src/main/java/luke/tasks/Event.java b/src/main/java/luke/tasks/Event.java index 22d0401f5..2e9b5bef1 100644 --- a/src/main/java/luke/tasks/Event.java +++ b/src/main/java/luke/tasks/Event.java @@ -1,5 +1,5 @@ package luke.tasks; -import luke.user.LukeTimeError; +import luke.user.LukeException; /** * The Event class represents a task of type "Event" in the LukeTime application. @@ -14,16 +14,16 @@ public class Event extends Task { * Constructs an Event task with the specified task description, start date, and end date. * * @param taskDescription The description of the event task including start and end dates. - * @throws LukeTimeError If there are syntax or formatting errors in the task description. + * @throws LukeException If there are syntax or formatting errors in the task description. */ - public Event(String taskDescription) throws LukeTimeError { + public Event(String taskDescription) throws LukeException { super(taskDescription); int slashCut = taskDescription.indexOf("/"); if (slashCut <= 0) { System.out.println("\tThere is a missing task description. Please follow this format:"); printGuide(); - throw new LukeTimeError(); + throw new LukeException(); } description = taskDescription.substring(0, slashCut); @@ -54,14 +54,14 @@ public String getEndDate() { * Parses and sets the start and end dates of the event from the provided date string. * * @param dates The date string containing start and end date information. - * @throws LukeTimeError If there are syntax or formatting errors in the date string. + * @throws LukeException If there are syntax or formatting errors in the date string. */ - public void setDates(String dates) throws LukeTimeError { + public void setDates(String dates) throws LukeException { String[] words = dates.split(" "); if (!words[0].equals("from")) { System.out.println("\tThere is a syntax problem. Please follow this format:"); printGuide(); - throw new LukeTimeError(); + throw new LukeException(); } dates = dates.substring(5); @@ -70,7 +70,7 @@ public void setDates(String dates) throws LukeTimeError { if (slashCut <= 0) { System.out.println("\tThere is a syntax problem. Please follow this format:"); printGuide(); - throw new LukeTimeError(); + throw new LukeException(); } startDate = dates.substring(0, slashCut); @@ -80,7 +80,7 @@ public void setDates(String dates) throws LukeTimeError { if (!words[0].equals("to")) { System.out.println("\tThere is a syntax problem. Please follow this format:"); printGuide(); - throw new LukeTimeError(); + throw new LukeException(); } endDate = dates.substring(3); diff --git a/src/main/java/luke/tasks/TaskList.java b/src/main/java/luke/tasks/TaskList.java index 07d71f9c8..ac328a6b0 100644 --- a/src/main/java/luke/tasks/TaskList.java +++ b/src/main/java/luke/tasks/TaskList.java @@ -1,7 +1,7 @@ package luke.tasks; import java.util.ArrayList; -import luke.user.LukeTimeError; +import luke.user.LukeException; /** * The TaskList Class contains a list of tasks and provides operations to manage tasks. @@ -16,10 +16,10 @@ public class TaskList{ * Constructs a TaskList object from an existing ArrayList of tasks. * * @param thetasks An ArrayList of Task objects to initialize the task list with. - * @throws LukeTimeError If an error specific to the LukeTime application occurs during initialization. + * @throws LukeException If an error specific to the LukeTime application occurs during initialization. */ - public TaskList(ArrayList thetasks) throws LukeTimeError, NullPointerException { + public TaskList(ArrayList thetasks) throws LukeException, NullPointerException { mainTaskList = new ArrayList(); numberOfTasks = 0; for (Task item: thetasks) { diff --git a/src/main/java/luke/user/LukeException.java b/src/main/java/luke/user/LukeException.java new file mode 100644 index 000000000..b36483854 --- /dev/null +++ b/src/main/java/luke/user/LukeException.java @@ -0,0 +1,12 @@ +package luke.user; + +/** + * The LukeException Class represents custom exceptions specific to the LukeTime application. + * It extends the Exception class. + */ +public class LukeException extends Exception { + @Override + public String getMessage() { + return "LukeException has occurred."; + } +} \ No newline at end of file diff --git a/src/main/java/luke/user/LukeTimeError.java b/src/main/java/luke/user/LukeTimeError.java deleted file mode 100644 index 9b0f60619..000000000 --- a/src/main/java/luke/user/LukeTimeError.java +++ /dev/null @@ -1,12 +0,0 @@ -package luke.user; - -/** - * The LukeTimeError Class represents custom exceptions specific to the LukeTime application. - * It extends the Exception class. - */ -public class LukeTimeError extends Exception { - @Override - public String getMessage() { - return "LukeTimeError"; - } -} \ No newline at end of file From 4e9d393b6aec983aab7cd83dc90ddbeba4108bf9 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Fri, 6 Oct 2023 20:29:44 +0800 Subject: [PATCH 71/77] Refine error from invalid user input --- src/main/java/luke/tasks/Deadline.java | 23 ++++++------- src/main/java/luke/tasks/Event.java | 46 +++++++++----------------- 2 files changed, 25 insertions(+), 44 deletions(-) diff --git a/src/main/java/luke/tasks/Deadline.java b/src/main/java/luke/tasks/Deadline.java index 13709e97c..bb164f869 100644 --- a/src/main/java/luke/tasks/Deadline.java +++ b/src/main/java/luke/tasks/Deadline.java @@ -18,16 +18,20 @@ public class Deadline extends Task { public Deadline(String taskDescription) throws LukeException { super(taskDescription); - int slashCut = taskDescription.indexOf("/"); - if (slashCut <= 0) { + int byIndex = taskDescription.indexOf("/by "); + if (byIndex == 0) { System.out.println("\tThere is a missing task description. Please follow this format:"); printGuide(); throw new LukeException(); + } else if (byIndex < 0) { + System.out.println("\tThere is a syntax problem. Please follow this format:"); + printGuide(); + throw new LukeException(); } - description = taskDescription.substring(0, slashCut); + description = taskDescription.substring(0, byIndex); - setDate(taskDescription.substring(slashCut + 1)); + setDate(taskDescription.substring(byIndex + 4)); } /** @@ -46,19 +50,12 @@ public String getDate() { * @throws LukeException If there are syntax or formatting errors in the date string. */ public void setDate(String dateString) throws LukeException { - String[] words = dateString.split(" "); - if (!words[0].equals("by")) { - System.out.println("\tThere is a syntax problem. Please follow this format:"); - printGuide(); - throw new LukeException(); - } - int spaceCut = dateString.indexOf(" "); - if (spaceCut <= 0) { + if (dateString.isEmpty()) { System.out.println("\tThere is a missing date. Please follow this format:"); printGuide(); throw new LukeException(); } - date = dateString.substring(spaceCut + 1); + date = dateString; } /** diff --git a/src/main/java/luke/tasks/Event.java b/src/main/java/luke/tasks/Event.java index 2e9b5bef1..3cc60a952 100644 --- a/src/main/java/luke/tasks/Event.java +++ b/src/main/java/luke/tasks/Event.java @@ -19,17 +19,20 @@ public class Event extends Task { public Event(String taskDescription) throws LukeException { super(taskDescription); - int slashCut = taskDescription.indexOf("/"); - if (slashCut <= 0) { + int fromIndex = taskDescription.indexOf("/from "); + int toIndex = taskDescription.indexOf("/to "); + if (fromIndex == 0) { System.out.println("\tThere is a missing task description. Please follow this format:"); printGuide(); throw new LukeException(); + } else if (fromIndex < 0 || toIndex <= fromIndex) { + System.out.println("\tThere is a syntax problem. Please follow this format:"); + printGuide(); + throw new LukeException(); } - description = taskDescription.substring(0, slashCut); - - String taskDuration = taskDescription.substring(slashCut + 1); - setDates(taskDuration); + description = taskDescription.substring(0, fromIndex); + setDates(taskDescription.substring(fromIndex + 6, toIndex), taskDescription.substring(toIndex + 4)); } /** @@ -53,37 +56,18 @@ public String getEndDate() { /** * Parses and sets the start and end dates of the event from the provided date string. * - * @param dates The date string containing start and end date information. + * * @throws LukeException If there are syntax or formatting errors in the date string. */ - public void setDates(String dates) throws LukeException { - String[] words = dates.split(" "); - if (!words[0].equals("from")) { - System.out.println("\tThere is a syntax problem. Please follow this format:"); - printGuide(); - throw new LukeException(); - } - - dates = dates.substring(5); - - int slashCut = dates.indexOf("/"); - if (slashCut <= 0) { - System.out.println("\tThere is a syntax problem. Please follow this format:"); - printGuide(); - throw new LukeException(); - } - - startDate = dates.substring(0, slashCut); - dates = dates.substring(slashCut + 1); - - words = dates.split(" "); - if (!words[0].equals("to")) { - System.out.println("\tThere is a syntax problem. Please follow this format:"); + public void setDates(String fromDateString, String toDateString) throws LukeException { + if (fromDateString.isEmpty() || toDateString.isEmpty()) { + System.out.println("\tThere is a missing date. Please follow this format:"); printGuide(); throw new LukeException(); } - endDate = dates.substring(3); + startDate = fromDateString; + endDate = toDateString; } /** From 05973a4637237e7dd8e01081f87499e2f6917e5f Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Fri, 6 Oct 2023 20:31:58 +0800 Subject: [PATCH 72/77] Catch NumberFormatException errors for delete, mark and unmark --- src/main/java/luke/actions/DeleteCommand.java | 15 +++++++++++++-- src/main/java/luke/actions/MarkCommand.java | 19 +++++++++++++++---- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/main/java/luke/actions/DeleteCommand.java b/src/main/java/luke/actions/DeleteCommand.java index dbb431ddf..d397f4451 100644 --- a/src/main/java/luke/actions/DeleteCommand.java +++ b/src/main/java/luke/actions/DeleteCommand.java @@ -9,7 +9,6 @@ * It extends the Command class and includes specific behavior for deleting a task. */ public class DeleteCommand extends Command { - /** * Constructs a DeleteCommand with the specified action type and parameters. * @@ -20,6 +19,14 @@ public DeleteCommand(ActionType theAction, String parameters) { super(theAction, parameters); } + public void printIntegerGuide(TaskList tasks) { + if (tasks.isEmpty()) { + System.out.println("\tNo tasks in task list. Please add a task before using " + theAction + "."); + } else { + System.out.println("\tPlease input an integer from 1 to " + tasks.size() + "."); + } + } + /** * Executes the DeleteCommand to remove a task from the task list. * @@ -34,8 +41,12 @@ public void execute(TaskList tasks, Ui ui, Storage storage) { System.out.println("\tNoted. I've removed this task:\n" + tasks.get(taskNumber)); tasks.removeTask(taskNumber); System.out.println("\tNow you have " + tasks.size() + " tasks in the list."); + return; } catch (IndexOutOfBoundsException e) { - System.out.println("\tOOPS!!! Your arguments for " + theAction + " exceeds your task list."); + System.out.println("\t☹ OOPS!!! Your argument for " + theAction + " exceeds your task list."); + } catch (NumberFormatException e) { + System.out.println("\t☹ OOPS!!! Your argument for " + theAction + " need to be an integer."); } + printIntegerGuide(tasks); } } diff --git a/src/main/java/luke/actions/MarkCommand.java b/src/main/java/luke/actions/MarkCommand.java index f08a3e038..38b633de4 100644 --- a/src/main/java/luke/actions/MarkCommand.java +++ b/src/main/java/luke/actions/MarkCommand.java @@ -14,6 +14,7 @@ public class MarkCommand extends Command { private boolean isDone; + /** * Constructs a MarkCommand with the specified action type and parameters. * @@ -31,6 +32,14 @@ public MarkCommand(ActionType theAction, String parameters) { } } + public void printIntegerGuide(TaskList tasks) { + if (tasks.isEmpty()) { + System.out.println("\tNo tasks in task list. Please add a task before using " + theAction + "."); + } else { + System.out.println("\tPlease input an integer from 1 to " + tasks.size() + "."); + } + } + /** * Executes the MarkCommand to mark or unmark a task as done in the task list. * @@ -40,14 +49,16 @@ public MarkCommand(ActionType theAction, String parameters) { */ @Override public void execute(TaskList tasks, Ui ui, Storage storage) { - int taskNumber = Integer.parseInt(parameters) - 1; - try { + int taskNumber = Integer.parseInt(parameters) - 1; tasks.get(taskNumber).setDone(isDone); System.out.println(tasks.get(taskNumber)); + return; } catch (IndexOutOfBoundsException e) { - System.out.println("\tOOPS!!! Your arguments for " + theAction + " exceeds your task list."); + System.out.println("\t☹ OOPS!!! Your argument for " + theAction + " exceeds your task list."); + } catch (NumberFormatException e) { + System.out.println("\t☹ OOPS!!! Your argument for " + theAction + " need to be an integer."); } - + printIntegerGuide(tasks); } } From 2294806d774dfc4aee440e5fd2711ac8976148e6 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Fri, 6 Oct 2023 20:32:29 +0800 Subject: [PATCH 73/77] Refine error messages --- src/main/java/Luke.java | 4 ++-- src/main/java/luke/actions/AddCommand.java | 6 ++---- src/main/java/luke/actions/Parser.java | 4 ++-- src/main/java/luke/files/Memory.java | 6 +++--- src/main/java/luke/files/Storage.java | 5 ++--- src/main/java/luke/tasks/TaskList.java | 7 +++++++ src/main/java/luke/user/Ui.java | 2 +- 7 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/main/java/Luke.java b/src/main/java/Luke.java index 4d3eaef24..ea9fb05b0 100644 --- a/src/main/java/Luke.java +++ b/src/main/java/Luke.java @@ -28,7 +28,7 @@ public Luke() { ui.showLoadingError(); tasks = new TaskList(); } catch (NullPointerException e) { - //ui.showNoMemoryError(); + //ui.showNoMemoryFileError(); tasks = new TaskList(); } } @@ -51,7 +51,7 @@ public void run() { //tasks has ArrayList mainTaskList, ui has String echo, storage has ArrayList tasks isExit = c.isExit(); //for bye command } catch (LukeException e) { //from Parser.parse i think - ui.showError(e.getMessage()); + ui.showError("\t☹ An error occurred." + e.getMessage()); } finally { ui.showLine(); } diff --git a/src/main/java/luke/actions/AddCommand.java b/src/main/java/luke/actions/AddCommand.java index defdcc698..f8be63881 100644 --- a/src/main/java/luke/actions/AddCommand.java +++ b/src/main/java/luke/actions/AddCommand.java @@ -34,7 +34,7 @@ public AddCommand(ActionType theAction, String parameters) throws LukeException try { latestTask = new Deadline(parameters); } catch (LukeException e) { - System.out.println("\tOOPS!!! You have missing/invalid arguments for deadline. No changes have been made."); + System.out.println("\t☹ OOPS!!! You have missing/invalid arguments for deadline. No changes have been made."); throw new LukeException(); } } @@ -42,7 +42,7 @@ public AddCommand(ActionType theAction, String parameters) throws LukeException try { latestTask = new Event(parameters); } catch (LukeException e) { - System.out.println("\tOOPS!!! You have missing/invalid arguments for event. No changes have been made."); + System.out.println("\t☹ OOPS!!! You have missing/invalid arguments for event. No changes have been made."); throw new LukeException(); } } @@ -58,8 +58,6 @@ public AddCommand(ActionType theAction, String parameters) throws LukeException */ @Override public void execute(TaskList tasks, Ui ui, Storage storage) { - //ui has String echo, storage has ArrayList tasks, tasks has ArrayList mainTaskList; - tasks.addTask(latestTask); System.out.println("\tGot it. I've added this task:" + "\n" + tasks.get(tasks.size() - 1)); diff --git a/src/main/java/luke/actions/Parser.java b/src/main/java/luke/actions/Parser.java index 07360e4a0..fb5d936ab 100644 --- a/src/main/java/luke/actions/Parser.java +++ b/src/main/java/luke/actions/Parser.java @@ -82,11 +82,11 @@ public static Command parse(String fullCommand) throws LukeException { break; } } catch (IndexOutOfBoundsException e) { //empty for MARK, UNMARK, TO DO description, DEADLINE description, EVENT description - System.out.println("\tOOPS!!! You have missing arguments for " + words[0] + ". No changes have been made."); + System.out.println("\t☹ OOPS!!! You have missing arguments for " + words[0] + ". No changes have been made."); c = new DoNothingCommand(ActionType.LIST, ""); } } catch (IllegalArgumentException e) { - System.out.println("\tOOPS!!! I'm sorry, but I don't know what that means :-("); + System.out.println("\t☹ OOPS!!! I'm sorry, but I don't know what that means :-("); c = new DoNothingCommand(ActionType.LIST, ""); } return c; diff --git a/src/main/java/luke/files/Memory.java b/src/main/java/luke/files/Memory.java index ac29e8c04..839d2d8d8 100644 --- a/src/main/java/luke/files/Memory.java +++ b/src/main/java/luke/files/Memory.java @@ -49,13 +49,13 @@ public static ArrayList readMemory(String filePath) throws FileNotFoundExc case 'E': newTask = new Event(taskDescription); break; - default: + default: //memory.txt is corrupted/in the wrong format newTask = new Todo("error"); break; } tasks.add(newTask); } catch (LukeException e) { - System.out.println("\tsomethings wrong"); + System.out.println("\t☹ An error occurred." + e.getMessage()); } } System.out.println("\tMemory retrieval successful!\n"); @@ -81,7 +81,7 @@ public static void storeMemory(String filePath, ArrayList taskList){ System.out.println("\tMemory Stored Safely!"); } catch (IOException e) { - System.out.println("\tIO Exception: fail to store memory"); + System.out.println(("\t☹ An error occurred." + e.getMessage())); } } diff --git a/src/main/java/luke/files/Storage.java b/src/main/java/luke/files/Storage.java index 226bbebae..b7c86472f 100644 --- a/src/main/java/luke/files/Storage.java +++ b/src/main/java/luke/files/Storage.java @@ -27,7 +27,6 @@ public Storage(String folderPath) { System.out.println(); createDirectory(); createFile(); - //tasks = Memory.readMemory(filePath); } public void createDirectory () { @@ -49,7 +48,7 @@ public void createFile () { System.out.println("\tNew memory file cannot be created. Memory file may already exist."); } } catch (IOException e) { - System.out.println("\tAn error occurred." + e.getMessage()); + System.out.println("\t☹ An error occurred." + e.getMessage()); } System.out.println("\tFull path: " + f.getAbsolutePath()); } @@ -64,7 +63,7 @@ public ArrayList load() { tasks = Memory.readMemory(filePath); return tasks; } catch (FileNotFoundException e) { - System.out.println("An error occurred." + e.getMessage()); + System.out.println("\t☹ An error occurred." + e.getMessage()); } return null; } diff --git a/src/main/java/luke/tasks/TaskList.java b/src/main/java/luke/tasks/TaskList.java index ac328a6b0..7fd6e100e 100644 --- a/src/main/java/luke/tasks/TaskList.java +++ b/src/main/java/luke/tasks/TaskList.java @@ -64,6 +64,13 @@ public int size() { return numberOfTasks; } + public boolean isEmpty() { + if (numberOfTasks <= 0) { + return true; + } + return false; + } + /** * Retrieves a task from the task list by its index. * diff --git a/src/main/java/luke/user/Ui.java b/src/main/java/luke/user/Ui.java index 9f3215d55..53fe1f61d 100644 --- a/src/main/java/luke/user/Ui.java +++ b/src/main/java/luke/user/Ui.java @@ -56,7 +56,7 @@ public void showLoadingError() { /** * Displays an error message for loading issues. */ - public void showNoMemoryError() { + public void showNoMemoryFileError() { System.out.println("\tNo memory is loaded."); } From bfe863ae7ee4f8ec3c443ec4889bb5f7e21c6365 Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Fri, 6 Oct 2023 20:50:08 +0800 Subject: [PATCH 74/77] Add user guide within Luke application --- .gitignore | 3 ++- docs/README.md | 2 +- src/main/java/luke/user/Ui.java | 26 ++++++++++++++++++++------ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index bfa90d182..c20381871 100644 --- a/.gitignore +++ b/.gitignore @@ -17,5 +17,6 @@ bin/ text-ui-test/EXPECTED-UNIX.TXT /src/main/java/META-INF -/src/main/java/luke/files/memory.txt + +/data /data/memory.txt \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index 14ff8e973..4c5e76d14 100644 --- a/docs/README.md +++ b/docs/README.md @@ -134,7 +134,7 @@ Format of usage: Example of usage: -`unark 1` +`unmark 1` Expected outcome: diff --git a/src/main/java/luke/user/Ui.java b/src/main/java/luke/user/Ui.java index 53fe1f61d..5fbac174b 100644 --- a/src/main/java/luke/user/Ui.java +++ b/src/main/java/luke/user/Ui.java @@ -10,6 +10,23 @@ public class Ui { public String echo; public Scanner userInput; + private String logo = "\t _ _ \n" + + "\t| | _ _| | _____ \n" + + "\t| | | | | | |/ / _ \\\n" + + "\t| |___| |_| | < __/\n" + + "\t|_____|\\__,_|_|\\_\\___|\n"; + + private String userGuide = "\n\tQuick guide to using Luke...\n" + + "\t\tlist\n" + + "\t\ttodo \n" + + "\t\tdeadline /by \n" + + "\t\tevent /from /to \n" + + "\t\tmark \n" + + "\t\tunmark \n" + + "\t\tdelete \n" + + "\t\tfind \n" + + "\t\tbye\n"; + /** * Constructs a Ui object and initializes the user input scanner. */ @@ -28,14 +45,11 @@ public void closeUi() { * Displays a welcome message with a logo when the application starts. */ public void showWelcome() { - String logo = "\t _ _ \n" - + "\t| | _ _| | _____ \n" - + "\t| | | | | | |/ / _ \\\n" - + "\t| |___| |_| | < __/\n" - + "\t|_____|\\__,_|_|\\_\\___|\n"; - System.out.println("\t" + "Hello! I'm\n" + logo); System.out.println("\tWhat can I do for you?"); + + System.out.print(userGuide); + showLine(); } /** From bef32d45860928737db05f9cfd58256fc4df50cf Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Fri, 6 Oct 2023 21:28:58 +0800 Subject: [PATCH 75/77] Edit JavaDoc Comments --- src/main/java/Luke.java | 16 +++-------- src/main/java/luke/actions/AddCommand.java | 1 + src/main/java/luke/actions/Command.java | 6 ++--- src/main/java/luke/actions/DeleteCommand.java | 8 +++++- src/main/java/luke/actions/ExitCommand.java | 4 +-- src/main/java/luke/actions/MarkCommand.java | 8 ++++-- src/main/java/luke/actions/Parser.java | 1 - src/main/java/luke/files/Storage.java | 12 +++++++-- src/main/java/luke/tasks/Deadline.java | 24 ++++------------- src/main/java/luke/tasks/Event.java | 26 ++++-------------- src/main/java/luke/tasks/Task.java | 27 +++++++++++-------- src/main/java/luke/tasks/TaskList.java | 14 ++++++---- src/main/java/luke/tasks/Todo.java | 22 ++------------- src/main/java/luke/user/LukeException.java | 2 +- src/main/java/luke/user/Ui.java | 1 - 15 files changed, 70 insertions(+), 102 deletions(-) diff --git a/src/main/java/Luke.java b/src/main/java/Luke.java index ea9fb05b0..323b9e8d1 100644 --- a/src/main/java/Luke.java +++ b/src/main/java/Luke.java @@ -7,7 +7,8 @@ /** * The Luke Class represents the main application class for Luke, a task management application. - * It manages the user interface, task storage, and task list. + * It initializes the user interface, task storage and task list. + * It runs the application loop, managing the user interface, task storage, and task list. */ public class Luke { public static final String folderPath = "data"; @@ -50,7 +51,7 @@ public void run() { c.execute(tasks, ui, storage); //tasks has ArrayList mainTaskList, ui has String echo, storage has ArrayList tasks isExit = c.isExit(); //for bye command - } catch (LukeException e) { //from Parser.parse i think + } catch (LukeException e) { //from Parser.parse ui.showError("\t☹ An error occurred." + e.getMessage()); } finally { ui.showLine(); @@ -64,17 +65,6 @@ public void run() { * @param args The command-line arguments (not used in this application). */ public static void main(String[] args) { - /* - String home = System.getProperty("user.home"); - java.nio.file.Path path = java.nio.file.Paths.get(home, "out", "artifacts", "ip_jar", "memory.txt"); - boolean directoryExists = java.nio.file.Files.exists(path); - - new Luke(path).run(); - - */ - - //new Luke("./out/artifacts/ip_jar/memory.txt").run(); - new Luke().run(); } } diff --git a/src/main/java/luke/actions/AddCommand.java b/src/main/java/luke/actions/AddCommand.java index f8be63881..cbf900383 100644 --- a/src/main/java/luke/actions/AddCommand.java +++ b/src/main/java/luke/actions/AddCommand.java @@ -12,6 +12,7 @@ * It extends the Command class and includes specific behavior for adding different types of tasks. */ public class AddCommand extends Command { + /** * The latest task created as a result of the add command. */ diff --git a/src/main/java/luke/actions/Command.java b/src/main/java/luke/actions/Command.java index 564cfc179..8b984abbf 100644 --- a/src/main/java/luke/actions/Command.java +++ b/src/main/java/luke/actions/Command.java @@ -5,8 +5,8 @@ import luke.user.Ui; /** - * The Command class represents a generic command in the LukeTime application. - * It serves as the base class for specific command types, such as AddCommand, ListCommand, etc. + * The Command class represents an abstract command in the Luke application. + * It serves as the base class for more specific command types. */ public abstract class Command { @@ -44,7 +44,7 @@ public Command(ActionType theAction, String parameters) { * @param storage The storage for saving task changes (not used in all commands). */ public void execute(TaskList tasks, Ui ui, Storage storage) { - //do nothing? should not be executed + System.out.println("Error. This line should not be reached."); } /** diff --git a/src/main/java/luke/actions/DeleteCommand.java b/src/main/java/luke/actions/DeleteCommand.java index d397f4451..62e1a8d75 100644 --- a/src/main/java/luke/actions/DeleteCommand.java +++ b/src/main/java/luke/actions/DeleteCommand.java @@ -9,6 +9,7 @@ * It extends the Command class and includes specific behavior for deleting a task. */ public class DeleteCommand extends Command { + /** * Constructs a DeleteCommand with the specified action type and parameters. * @@ -19,6 +20,11 @@ public DeleteCommand(ActionType theAction, String parameters) { super(theAction, parameters); } + /** + * Prints a guide to provide user instructions for giving a DeleteCommand. + * + * @param tasks The task list to check if it is empty for a more specific user guide. + */ public void printIntegerGuide(TaskList tasks) { if (tasks.isEmpty()) { System.out.println("\tNo tasks in task list. Please add a task before using " + theAction + "."); @@ -28,7 +34,7 @@ public void printIntegerGuide(TaskList tasks) { } /** - * Executes the DeleteCommand to remove a task from the task list. + * Executes the DeleteCommand to remove a task from the task list when given valid arguments. * * @param tasks The task list from which the task will be deleted. * @param ui The user interface for displaying messages. diff --git a/src/main/java/luke/actions/ExitCommand.java b/src/main/java/luke/actions/ExitCommand.java index 14105df50..7f20e4c2f 100644 --- a/src/main/java/luke/actions/ExitCommand.java +++ b/src/main/java/luke/actions/ExitCommand.java @@ -30,8 +30,8 @@ public ExitCommand(ActionType theAction, String parameters) { */ @Override public void execute(TaskList tasks, Ui ui, Storage storage) throws IllegalArgumentException{ - storage.store(tasks); + storage.store(tasks); // Store the task list setIsExit(true); - ui.closeUi(); + ui.closeUi(); // Close the user interface } } diff --git a/src/main/java/luke/actions/MarkCommand.java b/src/main/java/luke/actions/MarkCommand.java index 38b633de4..859b187d5 100644 --- a/src/main/java/luke/actions/MarkCommand.java +++ b/src/main/java/luke/actions/MarkCommand.java @@ -14,7 +14,6 @@ public class MarkCommand extends Command { private boolean isDone; - /** * Constructs a MarkCommand with the specified action type and parameters. * @@ -32,6 +31,11 @@ public MarkCommand(ActionType theAction, String parameters) { } } + /** + * Prints a guide to provide user instructions for giving a DeleteCommand. + * + * @param tasks The task list to check if it is empty for a more specific user guide. + */ public void printIntegerGuide(TaskList tasks) { if (tasks.isEmpty()) { System.out.println("\tNo tasks in task list. Please add a task before using " + theAction + "."); @@ -41,7 +45,7 @@ public void printIntegerGuide(TaskList tasks) { } /** - * Executes the MarkCommand to mark or unmark a task as done in the task list. + * Executes the MarkCommand to mark or unmark a task as done in the task list when given valid arguments. * * @param tasks The task list where the task should be marked or unmarked. * @param ui The user interface for displaying messages. diff --git a/src/main/java/luke/actions/Parser.java b/src/main/java/luke/actions/Parser.java index fb5d936ab..6ec65ed3a 100644 --- a/src/main/java/luke/actions/Parser.java +++ b/src/main/java/luke/actions/Parser.java @@ -6,7 +6,6 @@ * The Parser Class handles the parsing of user input into valid commands. */ public class Parser{ - //user input from Ui to luke command to Command /** * Parses the user's full command and returns an appropriate Command object. diff --git a/src/main/java/luke/files/Storage.java b/src/main/java/luke/files/Storage.java index b7c86472f..95b1c052e 100644 --- a/src/main/java/luke/files/Storage.java +++ b/src/main/java/luke/files/Storage.java @@ -9,7 +9,7 @@ import java.util.ArrayList; /** - * The Storage Class handles the reading and writing of task data from/to a file. + * The Storage Class handles the reading from and writing task data to a file. */ public class Storage { protected String filePath; @@ -18,7 +18,9 @@ public class Storage { /** * Constructs a Storage object with the specified file path. If the file exists, - * it retrieves tasks from the file. If the file doesn't exist, it creates a new file. + * it retrieves tasks from the file. If the file does not exist, it creates a new file. + * + * @param folderPath The path to the folder where the memory file is located. */ public Storage(String folderPath) { this.folderPath = folderPath; @@ -29,6 +31,9 @@ public Storage(String folderPath) { createFile(); } + /** + * Creates a directory at the specified folder path if it does not already exist. + */ public void createDirectory () { File d = new File(folderPath); if (d.mkdir()) { @@ -39,6 +44,9 @@ public void createDirectory () { //System.out.println("\tFull path: " + d.getAbsolutePath()); } + /** + * Creates a memory file at the specified file path if it does not already exist. + */ public void createFile () { File f = new File(filePath); try { diff --git a/src/main/java/luke/tasks/Deadline.java b/src/main/java/luke/tasks/Deadline.java index bb164f869..a30ea9ba9 100644 --- a/src/main/java/luke/tasks/Deadline.java +++ b/src/main/java/luke/tasks/Deadline.java @@ -2,7 +2,7 @@ import luke.user.LukeException; /** - * The Deadline Class represents a task of type "Deadline" in the LukeTime application. + * The Deadline Class represents a task of type "Deadline" in the Luke application. * It extends the Task class and includes specific behavior for deadline tasks. */ public class Deadline extends Task { @@ -43,6 +43,8 @@ public String getDate() { return date; } + + /** * Parses and sets the deadline date of the deadline task from the provided date string. * @@ -73,15 +75,7 @@ public void printGuide() { */ @Override public String toString() { - String isDoneString; - - if (isDone()) { - isDoneString = "[X]"; - } else { - isDoneString = "[ ]"; - } - - return "\t[D]" + isDoneString + " " + getDescription() + "(do by: " + getDate() + ")"; + return "\t[D]" + getIsDone() + " " + getDescription() + "(do by: " + getDate() + ")"; } /** @@ -91,14 +85,6 @@ public String toString() { */ @Override public String memoryString() { - String isDoneString; - - if (isDone()) { - isDoneString = "[X]"; - } else { - isDoneString = "[ ]"; - } - - return "[D]" + isDoneString + " " + getDescription() + "/by " + getDate(); + return "[D]" + getIsDone() + " " + getDescription() + "/by " + getDate(); } } diff --git a/src/main/java/luke/tasks/Event.java b/src/main/java/luke/tasks/Event.java index 3cc60a952..89d2fb60d 100644 --- a/src/main/java/luke/tasks/Event.java +++ b/src/main/java/luke/tasks/Event.java @@ -2,7 +2,7 @@ import luke.user.LukeException; /** - * The Event class represents a task of type "Event" in the LukeTime application. + * The Event class represents a task of type "Event" in the Luke application. * It extends the Task class and includes specific behavior for event tasks. */ public class Event extends Task { @@ -56,7 +56,8 @@ public String getEndDate() { /** * Parses and sets the start and end dates of the event from the provided date string. * - * + * @param fromDateString The start date string. + * @param toDateString The end date string. * @throws LukeException If there are syntax or formatting errors in the date string. */ public void setDates(String fromDateString, String toDateString) throws LukeException { @@ -85,16 +86,7 @@ public void printGuide() { */ @Override public String toString() { - //super.toString(); - String isDoneString; - - if (isDone()) { - isDoneString = "[X]"; - } else { - isDoneString = "[ ]"; - } - - return "\t[E]" + isDoneString + " " + getDescription() + "(from: " + getStartDate() + "to: " + getEndDate() + ")"; + return "\t[E]" + getIsDone() + " " + getDescription() + "(from: " + getStartDate() + "to: " + getEndDate() + ")"; } /** @@ -104,14 +96,6 @@ public String toString() { */ @Override public String memoryString() { - String isDoneString; - - if (isDone()) { - isDoneString = "[X]"; - } else { - isDoneString = "[ ]"; - } - - return "[E]" + isDoneString + " " + getDescription() + "/from " + getStartDate() + "/to " + getEndDate(); + return "[E]" + getIsDone() + " " + getDescription() + "/from " + getStartDate() + "/to " + getEndDate(); } } diff --git a/src/main/java/luke/tasks/Task.java b/src/main/java/luke/tasks/Task.java index 263c71ec3..038de47a2 100644 --- a/src/main/java/luke/tasks/Task.java +++ b/src/main/java/luke/tasks/Task.java @@ -1,8 +1,8 @@ package luke.tasks; /** - * The Task Class represents a generic task in the LukeTime application. - * It serves as the base class for various types of tasks and provides common task attributes and methods. + * The Task Class represents an abstract class in the Luke application. + * It serves as the base class for different types of tasks and provides common task attributes and methods. */ public abstract class Task { protected String description; @@ -36,6 +36,19 @@ public boolean isDone() { return isDone; } + /** + * Gets a string representation of the task's completion status. + * + * @return "[X]" if the task is done, "[ ]" if it's not done. + */ + public String getIsDone() { + if (isDone()) { + return "[X]"; + } else { + return "[ ]"; + } + } + /** * Sets the completion status of the task and displays a corresponding message. * @@ -63,14 +76,6 @@ public void printGuide() { * @return A string representation of the task for memory storage. */ public String memoryString() { - String isDoneString; - - if (isDone()) { - isDoneString = "[X]"; - } else { - isDoneString = "[ ]"; - } - - return "[T]" + isDoneString + " task" + getDescription(); + return "[T]" + getIsDone() + " task" + getDescription(); } } \ No newline at end of file diff --git a/src/main/java/luke/tasks/TaskList.java b/src/main/java/luke/tasks/TaskList.java index 7fd6e100e..abaf1ad68 100644 --- a/src/main/java/luke/tasks/TaskList.java +++ b/src/main/java/luke/tasks/TaskList.java @@ -4,10 +4,9 @@ import luke.user.LukeException; /** - * The TaskList Class contains a list of tasks and provides operations to manage tasks. + * The TaskList Class contains the task list and provides methods to manage and retrieve tasks from the task list. */ public class TaskList{ - //contains the task list e.g., it has operations to add/delete tasks in the list private ArrayList mainTaskList; public int numberOfTasks; @@ -15,14 +14,14 @@ public class TaskList{ /** * Constructs a TaskList object from an existing ArrayList of tasks. * - * @param thetasks An ArrayList of Task objects to initialize the task list with. + * @param tasklist An ArrayList of Task objects to initialize the task list with. * @throws LukeException If an error specific to the LukeTime application occurs during initialization. */ - public TaskList(ArrayList thetasks) throws LukeException, NullPointerException { + public TaskList(ArrayList tasklist) throws LukeException, NullPointerException { mainTaskList = new ArrayList(); numberOfTasks = 0; - for (Task item: thetasks) { + for (Task item: tasklist) { addTask(item); } } @@ -64,6 +63,11 @@ public int size() { return numberOfTasks; } + /** + * Checks if the task list is empty. + * + * @return true if the task list is empty, false otherwise. + */ public boolean isEmpty() { if (numberOfTasks <= 0) { return true; diff --git a/src/main/java/luke/tasks/Todo.java b/src/main/java/luke/tasks/Todo.java index 191e553e3..7a9c89c7b 100644 --- a/src/main/java/luke/tasks/Todo.java +++ b/src/main/java/luke/tasks/Todo.java @@ -5,7 +5,6 @@ * It extends the Task class and includes specific behavior for todo tasks. */ public class Todo extends Task { - //protected boolean isDone; protected String todoGuide = "\ttodo "; /** @@ -38,16 +37,7 @@ public void printGuide() { */ @Override public String toString() { - //super.toString(); - String isDoneString; - - if (isDone()) { - isDoneString = "[X]"; - } else { - isDoneString = "[ ]"; - } - - return "\t[T]" + isDoneString + " " + getDescription(); + return "\t[T]" + getIsDone() + " " + getDescription(); } /** @@ -57,14 +47,6 @@ public String toString() { */ @Override public String memoryString() { - String isDoneString; - - if (isDone()) { - isDoneString = "[X]"; - } else { - isDoneString = "[ ]"; - } - - return "[T]" + isDoneString + " " + getDescription(); + return "[T]" + getIsDone() + " " + getDescription(); } } diff --git a/src/main/java/luke/user/LukeException.java b/src/main/java/luke/user/LukeException.java index b36483854..862eff4a3 100644 --- a/src/main/java/luke/user/LukeException.java +++ b/src/main/java/luke/user/LukeException.java @@ -1,7 +1,7 @@ package luke.user; /** - * The LukeException Class represents custom exceptions specific to the LukeTime application. + * The LukeException Class represents custom exceptions specific to the Luke application. * It extends the Exception class. */ public class LukeException extends Exception { diff --git a/src/main/java/luke/user/Ui.java b/src/main/java/luke/user/Ui.java index 5fbac174b..841e0b27b 100644 --- a/src/main/java/luke/user/Ui.java +++ b/src/main/java/luke/user/Ui.java @@ -6,7 +6,6 @@ * The Ui Class is responsible for user interaction, including reading user input and displaying messages. */ public class Ui { - //directly interact with user (read in (to Parser)/print) public String echo; public Scanner userInput; From bd4a715f20262f9c9906646088c0e605b86af57e Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Fri, 6 Oct 2023 21:36:41 +0800 Subject: [PATCH 76/77] Minor Edit --- src/main/java/luke/actions/Command.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/luke/actions/Command.java b/src/main/java/luke/actions/Command.java index 8b984abbf..541ebdfe5 100644 --- a/src/main/java/luke/actions/Command.java +++ b/src/main/java/luke/actions/Command.java @@ -44,7 +44,6 @@ public Command(ActionType theAction, String parameters) { * @param storage The storage for saving task changes (not used in all commands). */ public void execute(TaskList tasks, Ui ui, Storage storage) { - System.out.println("Error. This line should not be reached."); } /** From e27b2258317714853f01bcd2018bc4d49a15b15b Mon Sep 17 00:00:00 2001 From: janelleenqi <110933149+janelleenqi@users.noreply.github.com> Date: Fri, 6 Oct 2023 22:09:03 +0800 Subject: [PATCH 77/77] Fix Memory Saving for Task Completion Status --- src/main/java/luke/files/Memory.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/luke/files/Memory.java b/src/main/java/luke/files/Memory.java index 839d2d8d8..021bf4533 100644 --- a/src/main/java/luke/files/Memory.java +++ b/src/main/java/luke/files/Memory.java @@ -53,6 +53,14 @@ public static ArrayList readMemory(String filePath) throws FileNotFoundExc newTask = new Todo("error"); break; } + switch (characters[4]) { + case 'X': + newTask.setDone(true); + break; + case ' ': + newTask.setDone(false); + break; + } tasks.add(newTask); } catch (LukeException e) { System.out.println("\t☹ An error occurred." + e.getMessage());