From 90c8452a124bb2ada6d39eb46157e470ba40134a Mon Sep 17 00:00:00 2001 From: DarkDragoon2002 Date: Thu, 22 Aug 2024 22:41:14 +0800 Subject: [PATCH 01/31] Level-0 Increment 1. Renamed Duke to Franz 2. Created the greeting and exit functions 3. Implemented the lines in between the messages --- src/main/java/Duke.java | 10 ---------- src/main/java/Franz.java | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 10 deletions(-) delete mode 100644 src/main/java/Duke.java create mode 100644 src/main/java/Franz.java diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java deleted file mode 100644 index 5d313334c..000000000 --- a/src/main/java/Duke.java +++ /dev/null @@ -1,10 +0,0 @@ -public class Duke { - public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - } -} diff --git a/src/main/java/Franz.java b/src/main/java/Franz.java new file mode 100644 index 000000000..60b4792f6 --- /dev/null +++ b/src/main/java/Franz.java @@ -0,0 +1,22 @@ +public class Franz { + public static void main(String[] args) { + lineMessage(); + helloMessage(); + lineMessage(); + byeMessage(); + lineMessage(); + } + public static void lineMessage() { + String line = "____________________________________________________________\n"; + System.out.print(line); + } + public static void helloMessage() { + String greeting = "Hello! I'm Franz \n" + + "What can I do for you?\n"; + System.out.print(greeting); + } + public static void byeMessage() { + String bye = "Bye. Hope to see you again soon!\n"; + System.out.print(bye); + } +} \ No newline at end of file From 6027a2d45390ca7e3d7212577a0ed4a0baf3992c Mon Sep 17 00:00:00 2001 From: DarkDragoon2002 Date: Wed, 28 Aug 2024 15:33:54 +0800 Subject: [PATCH 02/31] Level-1 1. Renamed Franz to Juan 2. Implemented Echo feature --- src/main/java/Franz.java | 22 ---------------------- src/main/java/Juan.java | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 22 deletions(-) delete mode 100644 src/main/java/Franz.java create mode 100644 src/main/java/Juan.java diff --git a/src/main/java/Franz.java b/src/main/java/Franz.java deleted file mode 100644 index 60b4792f6..000000000 --- a/src/main/java/Franz.java +++ /dev/null @@ -1,22 +0,0 @@ -public class Franz { - public static void main(String[] args) { - lineMessage(); - helloMessage(); - lineMessage(); - byeMessage(); - lineMessage(); - } - public static void lineMessage() { - String line = "____________________________________________________________\n"; - System.out.print(line); - } - public static void helloMessage() { - String greeting = "Hello! I'm Franz \n" - + "What can I do for you?\n"; - System.out.print(greeting); - } - public static void byeMessage() { - String bye = "Bye. Hope to see you again soon!\n"; - System.out.print(bye); - } -} \ No newline at end of file diff --git a/src/main/java/Juan.java b/src/main/java/Juan.java new file mode 100644 index 000000000..5d2e5785c --- /dev/null +++ b/src/main/java/Juan.java @@ -0,0 +1,39 @@ +import java.util.Scanner; + +public class Juan { + public static void main(String[] args) { + lineMessage(); + helloMessage(); + lineMessage(); + + boolean exit = false; + Scanner scanner = new Scanner(System.in); + while (!exit) { + String line = scanner.nextLine(); + lineMessage(); + if (line.equals("bye")) { + exit = true; + } else { + System.out.println(line); + lineMessage(); + } + } + byeMessage(); + lineMessage(); + } + public static void lineMessage() { + String line = "____________________________________________________________\n"; + System.out.print(line); + } + public static void helloMessage() { + String greeting = "Hola Amigo, I am Juan Jose Santiago from Michoacan\n" + + "Welcome to la familia\n" + + "What I do for you??\n"; + System.out.print(greeting); + } + public static void byeMessage() { + String bye = "Adios amigo mucha gracias\n"; + System.out.print(bye); + } + +} \ No newline at end of file From 0d164dd4269026a8fca3ecaf81fcbcc70c431528 Mon Sep 17 00:00:00 2001 From: DarkDragoon2002 Date: Wed, 28 Aug 2024 16:01:32 +0800 Subject: [PATCH 03/31] Level-2 1. Added chatFeature Function to chat 2. Neatened Code --- src/main/java/Juan.java | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/Juan.java b/src/main/java/Juan.java index 5d2e5785c..3820bbdfa 100644 --- a/src/main/java/Juan.java +++ b/src/main/java/Juan.java @@ -1,11 +1,17 @@ import java.util.Scanner; public class Juan { + private static String[] Strings = new String[100]; + private static int stringsCounter = 0; public static void main(String[] args) { lineMessage(); helloMessage(); lineMessage(); - + chatFeature(); + byeMessage(); + lineMessage(); + } + public static void chatFeature(){ boolean exit = false; Scanner scanner = new Scanner(System.in); while (!exit) { @@ -13,13 +19,22 @@ public static void main(String[] args) { lineMessage(); if (line.equals("bye")) { exit = true; + return; + } else if (line.equals("list")) { + if (stringsCounter == 0) { + System.out.println("Por Favor? Nothing Here"); + } + for (int i = 0; i < stringsCounter; i++) { + System.out.println((i + 1) + ". " + Strings[i]); + } } else { - System.out.println(line); - lineMessage(); + Strings[stringsCounter] = line; + stringsCounter++; + System.out.println("Added: " + line); } + + lineMessage(); } - byeMessage(); - lineMessage(); } public static void lineMessage() { String line = "____________________________________________________________\n"; From dded6bf2bf2e10db67d2d009f79da52dd2dfee29 Mon Sep 17 00:00:00 2001 From: DarkDragoon2002 Date: Thu, 29 Aug 2024 01:28:08 +0800 Subject: [PATCH 04/31] Level-3 1. Creates Task Class 2. Shifted Functions from Main to Task class 3. Created functions to mark and unmark --- src/main/java/Juan.java | 44 ++++++++++++++++++++++++++------------ src/main/java/Task.java | 47 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 13 deletions(-) create mode 100644 src/main/java/Task.java diff --git a/src/main/java/Juan.java b/src/main/java/Juan.java index 3820bbdfa..802c85f05 100644 --- a/src/main/java/Juan.java +++ b/src/main/java/Juan.java @@ -21,16 +21,21 @@ public static void chatFeature(){ exit = true; return; } else if (line.equals("list")) { - if (stringsCounter == 0) { - System.out.println("Por Favor? Nothing Here"); - } - for (int i = 0; i < stringsCounter; i++) { - System.out.println((i + 1) + ". " + Strings[i]); - } + Task.printTasksList(); } else { - Strings[stringsCounter] = line; - stringsCounter++; - System.out.println("Added: " + line); + // Check for mark and unmark + String[] parts = line.split(" "); + if (parts[0].equals("mark")){ + // Mark + Task.mark(Integer.parseInt(parts[1]) - 1); + } else if (parts[0].equals("unmark")){ + // Unmark + Task.unmark(Integer.parseInt(parts[1]) - 1); + } else { + // else add task + Task newTask = new Task(line); + } + } lineMessage(); @@ -41,13 +46,26 @@ public static void lineMessage() { System.out.print(line); } public static void helloMessage() { - String greeting = "Hola Amigo, I am Juan Jose Santiago from Michoacan\n" - + "Welcome to la familia\n" - + "What I do for you??\n"; + String greeting = + " ._-'-_ .\n" + + " . ' /_-_-_\\ ` .\n" + + " .' |-_-_-_-| `.\n" + + " ( `.-_-_-.' )\n" + + " !`. .'!\n" + + " ! ` . . ' !\n" + + " ! ! ! ! ! ! ! ! !\n" + + " / / \\ \\\n" + + " _-| \\___ ___/ /-_\n" + + " (_ )__\\_)\\(_/__( _)\n" + + " ))))\\X\\ ((((\n" + + " \\/ \\/ \n" + + "Hola Amigo, I am Juan Cervantes Salamanca from Michoacan \n" + + "Welcome to la familia \n" + + "How can we help you? \n"; System.out.print(greeting); } public static void byeMessage() { - String bye = "Adios amigo mucha gracias\n"; + String bye = "Adios amigo, la familia will miss you\n"; System.out.print(bye); } diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 000000000..5c69d0b1b --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,47 @@ +public class Task { + + private static Task[] tasks = new Task[100]; + private static int taskNumber = 0; + + public String taskString; + public boolean taskDone = false; + + public Task(String taskString) { + this.taskString = taskString; + tasks[taskNumber] = this; + taskNumber++; + System.out.println("Muy Bien, work hard compadre!"); + System.out.println("I've Added the Task:"); + System.out.println(taskString); + } + public static void mark(int taskIndex){ + tasks[taskIndex].taskDone = true; + System.out.println("Fantastica!!!! I marked it:"); + System.out.println(tasks[taskIndex].checkboxString()); + } + public static void unmark(int taskIndex){ + tasks[taskIndex].taskDone = false; + System.out.println("Ay Caramba, I unmarked it:"); + System.out.println(tasks[taskIndex].checkboxString()); + } + public String checkboxString(){ + String returnString = "["; + if (this.taskDone){ + returnString += "X"; + } else { + returnString += " "; + } + returnString += "] " + this.taskString; + return returnString; + } + public static void printTasksList(){ + if (taskNumber == 0){ + System.out.println("Por Favor? Nothing Here"); + } else { + System.out.println("Si compinche, your tasks:"); + for (int i = 0; i < taskNumber; i++){ + System.out.println((i+1) + "." + tasks[i].checkboxString()); + } + } + } +} \ No newline at end of file From d0d0bda1ee42f1f8e291c7e891f336d4265e2af6 Mon Sep 17 00:00:00 2001 From: DarkDragoon2002 Date: Thu, 29 Aug 2024 02:12:59 +0800 Subject: [PATCH 05/31] A-CodingStandard 1. Cleaned up Code 2. Reduced Nesting 3. Added Comments --- src/main/java/Juan.java | 64 +++++++++++++++++++++++------------------ src/main/java/Task.java | 19 ++++++++++++ 2 files changed, 55 insertions(+), 28 deletions(-) diff --git a/src/main/java/Juan.java b/src/main/java/Juan.java index 802c85f05..a65c26b29 100644 --- a/src/main/java/Juan.java +++ b/src/main/java/Juan.java @@ -1,46 +1,54 @@ import java.util.Scanner; public class Juan { - private static String[] Strings = new String[100]; - private static int stringsCounter = 0; public static void main(String[] args) { lineMessage(); helloMessage(); lineMessage(); - chatFeature(); + + boolean continueChatting = true; + while (continueChatting) { + continueChatting = chatFeature(); + } byeMessage(); lineMessage(); } - public static void chatFeature(){ - boolean exit = false; + public static boolean chatFeature(){ + // Less efficient to create a new scanner everytime but code is much neater + // If return True means continue + // Else End + Scanner scanner = new Scanner(System.in); - while (!exit) { - String line = scanner.nextLine(); - lineMessage(); - if (line.equals("bye")) { - exit = true; - return; - } else if (line.equals("list")) { - Task.printTasksList(); - } else { - // Check for mark and unmark - String[] parts = line.split(" "); - if (parts[0].equals("mark")){ - // Mark - Task.mark(Integer.parseInt(parts[1]) - 1); - } else if (parts[0].equals("unmark")){ - // Unmark - Task.unmark(Integer.parseInt(parts[1]) - 1); - } else { - // else add task - Task newTask = new Task(line); - } + String line = scanner.nextLine(); + lineMessage(); - } + if (line.equals("bye")) { + return false; + } else if (line.equals("list")) { + Task.printTasksList(); + return true; + } - lineMessage(); + // Check for mark and unmark or just add task + String[] parts = line.split(" "); + if (parts[0].equals("mark")){ + // Mark + int taskIndex = Integer.parseInt(parts[1]) - 1; + Task.mark(taskIndex); + } else if (parts[0].equals("unmark")){ + // Unmark + int taskIndex = Integer.parseInt(parts[1]) - 1; + Task.unmark(taskIndex); + } else { + // else add task + Task newTask = new Task(line); } + + lineMessage(); + return true; } + + // Message Functions for cleaner main Function public static void lineMessage() { String line = "____________________________________________________________\n"; System.out.print(line); diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 5c69d0b1b..289fb0cd7 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -1,11 +1,14 @@ public class Task { + // Keep track of tasks private static Task[] tasks = new Task[100]; private static int taskNumber = 0; + // Object specific variables public String taskString; public boolean taskDone = false; + // Constructor Function public Task(String taskString) { this.taskString = taskString; tasks[taskNumber] = this; @@ -14,16 +17,30 @@ public Task(String taskString) { System.out.println("I've Added the Task:"); System.out.println(taskString); } + + // Class mark function public static void mark(int taskIndex){ + if (taskIndex < 0 || taskIndex >= taskNumber){ // Validity Check + System.out.println("Not possible Amigo, try again"); + return; + } tasks[taskIndex].taskDone = true; System.out.println("Fantastica!!!! I marked it:"); System.out.println(tasks[taskIndex].checkboxString()); } + + // Class unmark function public static void unmark(int taskIndex){ + if (taskIndex < 0 || taskIndex >= taskNumber){ // Validity Check + System.out.println("Not possible Amigo, try again"); + return; + } tasks[taskIndex].taskDone = false; System.out.println("Ay Caramba, I unmarked it:"); System.out.println(tasks[taskIndex].checkboxString()); } + + // Function to create String with Checkbox and Task public String checkboxString(){ String returnString = "["; if (this.taskDone){ @@ -34,6 +51,8 @@ public String checkboxString(){ returnString += "] " + this.taskString; return returnString; } + + // Function to print out task checklist public static void printTasksList(){ if (taskNumber == 0){ System.out.println("Por Favor? Nothing Here"); From a43c3b2927b32d3a1ffd4431fef28f544288b61a Mon Sep 17 00:00:00 2001 From: DarkDragoon2002 Date: Fri, 6 Sep 2024 14:38:10 +0800 Subject: [PATCH 06/31] Added ToDo, Deadline and Event --- src/main/java/Deadline.java | 14 ++++++++++++++ src/main/java/Event.java | 15 +++++++++++++++ src/main/java/Juan.java | 22 +++++++++++----------- src/main/java/Task.java | 29 +++++++++++++++-------------- src/main/java/ToDo.java | 11 +++++++++++ 5 files changed, 66 insertions(+), 25 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..d3db15043 --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,14 @@ +public class Deadline extends Task{ + + private String deadlineString; + + public Deadline(String inputString){ + super(inputString.replace("deadline ", "").split(" /by ")[0]); + this.deadlineString = inputString.replace("deadline ", "").split(" /by ")[1]; + + } + @Override + public String checkboxString(){ + return "[D]" + super.checkboxString() + " (by: " + deadlineString + ")"; + } +} diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 000000000..dddb0c2d9 --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,15 @@ +public class Event extends Task{ + private String fromString; + private String toString; + public Event(String inputString){ + super(inputString.replace("event ", "").split(" /from ")[0]); + String[] fromToStrings = inputString.replace("event ", "").split(" /from ")[1].split(" /to "); + this.fromString = fromToStrings[0]; + this.toString = fromToStrings[1]; + } + + @Override + public String checkboxString(){ + return "[E]" + super.checkboxString() + " (from: " + fromString + " to: " + toString + ")"; + } +} diff --git a/src/main/java/Juan.java b/src/main/java/Juan.java index a65c26b29..5d7f9ab54 100644 --- a/src/main/java/Juan.java +++ b/src/main/java/Juan.java @@ -26,22 +26,22 @@ public static boolean chatFeature(){ return false; } else if (line.equals("list")) { Task.printTasksList(); - return true; - } - - // Check for mark and unmark or just add task - String[] parts = line.split(" "); - if (parts[0].equals("mark")){ + } else if (line.startsWith("mark")){ // Mark - int taskIndex = Integer.parseInt(parts[1]) - 1; + int taskIndex = Integer.parseInt(line.replace("mark ", "")) - 1; Task.mark(taskIndex); - } else if (parts[0].equals("unmark")){ + } else if (line.startsWith("unmark")){ // Unmark - int taskIndex = Integer.parseInt(parts[1]) - 1; + int taskIndex = Integer.parseInt(line.replace("unmark ", "")) - 1; Task.unmark(taskIndex); + } else if (line.startsWith("todo")) { + new ToDo(line); + } else if (line.startsWith("deadline")) { + new Deadline(line); + } else if (line.startsWith("event")) { + new Event(line); } else { - // else add task - Task newTask = new Task(line); + System.out.println("Por Favor? Try a new request"); } lineMessage(); diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 289fb0cd7..4230a7692 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -2,40 +2,41 @@ public class Task { // Keep track of tasks private static Task[] tasks = new Task[100]; - private static int taskNumber = 0; + private static int taskCount = 0; // Object specific variables public String taskString; - public boolean taskDone = false; + public boolean isDone = false; // Constructor Function - public Task(String taskString) { - this.taskString = taskString; - tasks[taskNumber] = this; - taskNumber++; + public Task(String inputString) { + this.taskString = inputString; + tasks[taskCount] = this; + taskCount++; System.out.println("Muy Bien, work hard compadre!"); System.out.println("I've Added the Task:"); - System.out.println(taskString); + System.out.println(checkboxString()); + System.out.println("You've got " + taskCount + " tasks, better start working!"); } // Class mark function public static void mark(int taskIndex){ - if (taskIndex < 0 || taskIndex >= taskNumber){ // Validity Check + if (taskIndex < 0 || taskIndex >= taskCount){ // Validity Check System.out.println("Not possible Amigo, try again"); return; } - tasks[taskIndex].taskDone = true; + tasks[taskIndex].isDone = true; System.out.println("Fantastica!!!! I marked it:"); System.out.println(tasks[taskIndex].checkboxString()); } // Class unmark function public static void unmark(int taskIndex){ - if (taskIndex < 0 || taskIndex >= taskNumber){ // Validity Check + if (taskIndex < 0 || taskIndex >= taskCount){ // Validity Check System.out.println("Not possible Amigo, try again"); return; } - tasks[taskIndex].taskDone = false; + tasks[taskIndex].isDone = false; System.out.println("Ay Caramba, I unmarked it:"); System.out.println(tasks[taskIndex].checkboxString()); } @@ -43,7 +44,7 @@ public static void unmark(int taskIndex){ // Function to create String with Checkbox and Task public String checkboxString(){ String returnString = "["; - if (this.taskDone){ + if (this.isDone){ returnString += "X"; } else { returnString += " "; @@ -54,11 +55,11 @@ public String checkboxString(){ // Function to print out task checklist public static void printTasksList(){ - if (taskNumber == 0){ + if (taskCount == 0){ System.out.println("Por Favor? Nothing Here"); } else { System.out.println("Si compinche, your tasks:"); - for (int i = 0; i < taskNumber; i++){ + for (int i = 0; i < taskCount; i++){ System.out.println((i+1) + "." + tasks[i].checkboxString()); } } diff --git a/src/main/java/ToDo.java b/src/main/java/ToDo.java new file mode 100644 index 000000000..5fd0f8a0e --- /dev/null +++ b/src/main/java/ToDo.java @@ -0,0 +1,11 @@ +public class ToDo extends Task{ + + public ToDo(String inputString){ + super(inputString.replace("todo ", "")); + } + + @Override + public String checkboxString() { + return "[T]" + super.checkboxString(); + } +} From 6a7f02081548071a9b2e2a9a6e286dfd90a47295 Mon Sep 17 00:00:00 2001 From: DarkDragoon2002 Date: Sat, 7 Sep 2024 23:51:04 +0800 Subject: [PATCH 07/31] Added UI Text Testing --- src/main/java/Deadline.java | 1 + src/main/java/Event.java | 1 + src/main/java/Task.java | 3 ++ src/main/java/ToDo.java | 1 + text-ui-test/EXPECTED.TXT | 68 +++++++++++++++++++++++++++++++++---- text-ui-test/input.txt | 7 ++++ text-ui-test/runtest.bat | 2 +- text-ui-test/runtest.sh | 2 +- 8 files changed, 76 insertions(+), 9 deletions(-) diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index d3db15043..2c6edaf96 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -5,6 +5,7 @@ public class Deadline extends Task{ public Deadline(String inputString){ super(inputString.replace("deadline ", "").split(" /by ")[0]); this.deadlineString = inputString.replace("deadline ", "").split(" /by ")[1]; + constructorMessage(); } @Override diff --git a/src/main/java/Event.java b/src/main/java/Event.java index dddb0c2d9..ecc8dbcfe 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -6,6 +6,7 @@ public Event(String inputString){ String[] fromToStrings = inputString.replace("event ", "").split(" /from ")[1].split(" /to "); this.fromString = fromToStrings[0]; this.toString = fromToStrings[1]; + constructorMessage(); } @Override diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 4230a7692..f5453eeea 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -13,6 +13,9 @@ public Task(String inputString) { this.taskString = inputString; tasks[taskCount] = this; taskCount++; + } + + public void constructorMessage(){ System.out.println("Muy Bien, work hard compadre!"); System.out.println("I've Added the Task:"); System.out.println(checkboxString()); diff --git a/src/main/java/ToDo.java b/src/main/java/ToDo.java index 5fd0f8a0e..387eb93b6 100644 --- a/src/main/java/ToDo.java +++ b/src/main/java/ToDo.java @@ -2,6 +2,7 @@ public class ToDo extends Task{ public ToDo(String inputString){ super(inputString.replace("todo ", "")); + constructorMessage(); } @Override diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 657e74f6e..8ae18219b 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,7 +1,61 @@ -Hello from - ____ _ -| _ \ _ _| | _____ -| | | | | | | |/ / _ \ -| |_| | |_| | < __/ -|____/ \__,_|_|\_\___| - +____________________________________________________________ + ._-'-_ . + . ' /_-_-_\ ` . + .' |-_-_-_-| `. + ( `.-_-_-.' ) + !`. .'! + ! ` . . ' ! + ! ! ! ! ! ! ! ! ! + / / \ \ + _-| \___ ___/ /-_ + (_ )__\_)\(_/__( _) + ))))\X\ (((( + \/ \/ +Hola Amigo, I am Juan Cervantes Salamanca from Michoacan +Welcome to la familia +How can we help you? +____________________________________________________________ +event La Familia Meeting /from 5pm /to 6pm +____________________________________________________________ +Muy Bien, work hard compadre! +I've Added the Task: +[E][ ] La Familia Meeting (from: 5pm to: 6pm) +You've got 1 tasks, better start working! +____________________________________________________________ +deadline Fry the Pollo with the Hermanos /by 5th July +____________________________________________________________ +Muy Bien, work hard compadre! +I've Added the Task: +[D][ ] Fry the Pollo with the Hermanos (by: 5th July) +You've got 2 tasks, better start working! +____________________________________________________________ +todo eat the pollo +____________________________________________________________ +Muy Bien, work hard compadre! +I've Added the Task: +[T][ ] eat the pollo +You've got 3 tasks, better start working! +____________________________________________________________ +list +____________________________________________________________ +Si compinche, your tasks: +1.[E][ ] La Familia Meeting (from: 5pm to: 6pm) +2.[D][ ] Fry the Pollo with the Hermanos (by: 5th July) +3.[T][ ] eat the pollo +____________________________________________________________ +mark 2 +____________________________________________________________ +Fantastica!!!! I marked it: +[D][X] Fry the Pollo with the Hermanos (by: 5th July) +____________________________________________________________ +list +____________________________________________________________ +Si compinche, your tasks: +1.[E][ ] La Familia Meeting (from: 5pm to: 6pm) +2.[D][X] Fry the Pollo with the Hermanos (by: 5th July) +3.[T][ ] eat the pollo +____________________________________________________________ +bye +____________________________________________________________ +Adios amigo, la familia will miss you +____________________________________________________________ \ No newline at end of file diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index e69de29bb..250e6e539 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -0,0 +1,7 @@ +event La Familia Meeting /from 5pm /to 6pm +deadline Fry the Pollo with the Hermanos /by 5th July +todo eat the pollo +list +mark 2 +list +bye \ No newline at end of file diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 087374464..e5e20765c 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -15,7 +15,7 @@ IF ERRORLEVEL 1 ( REM no error here, errorlevel == 0 REM run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT -java -classpath ..\bin Duke < input.txt > ACTUAL.TXT +java -classpath ..\bin Juan < input.txt > ACTUAL.TXT REM compare the output to the expected output FC ACTUAL.TXT EXPECTED.TXT diff --git a/text-ui-test/runtest.sh b/text-ui-test/runtest.sh index c9ec87003..b81ccd5e8 100644 --- a/text-ui-test/runtest.sh +++ b/text-ui-test/runtest.sh @@ -20,7 +20,7 @@ then fi # run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT -java -classpath ../bin Duke < input.txt > ACTUAL.TXT +java -classpath ../bin Juan < input.txt > ACTUAL.TXT # convert to UNIX format cp EXPECTED.TXT EXPECTED-UNIX.TXT From 0d502733212e52bb48005e1585e5d9be640f3009 Mon Sep 17 00:00:00 2001 From: DarkDragoon2002 Date: Tue, 10 Sep 2024 15:13:18 +0800 Subject: [PATCH 08/31] Implemented Deadline and Event Constructor Exceptions --- src/main/java/Deadline.java | 5 +++- .../java/DeadlineConstructorException.java | 17 ++++++++++++++ src/main/java/Event.java | 8 ++++++- src/main/java/EventConstructorException.java | 20 ++++++++++++++++ src/main/java/Juan.java | 23 +++++++++++++------ src/main/java/Task.java | 7 +++++- 6 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 src/main/java/DeadlineConstructorException.java create mode 100644 src/main/java/EventConstructorException.java diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index 2c6edaf96..951224bd5 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -2,8 +2,11 @@ public class Deadline extends Task{ private String deadlineString; - public Deadline(String inputString){ + public Deadline(String inputString) throws DeadlineConstructorException{ super(inputString.replace("deadline ", "").split(" /by ")[0]); + if (!(inputString.contains(" /by ")) | this.taskString == "" | this.taskString == null){ + throw new DeadlineConstructorException(inputString); + } this.deadlineString = inputString.replace("deadline ", "").split(" /by ")[1]; constructorMessage(); diff --git a/src/main/java/DeadlineConstructorException.java b/src/main/java/DeadlineConstructorException.java new file mode 100644 index 000000000..47e0b429f --- /dev/null +++ b/src/main/java/DeadlineConstructorException.java @@ -0,0 +1,17 @@ +public class DeadlineConstructorException extends Exception { + public DeadlineConstructorException(String message) { + super("DEADLINE CONTRUCTOR EXCEPTION: " + message); + Task.deleteLatestTask(); + } + + private static String errorMessage(String message) { + if (!(message.contains(" /by "))) { + return "MISSING BY COMMAND"; + } + String[] taskStringBreakdown = message.replace("event ", "").split(" /by "); + if (taskStringBreakdown[0] == "" | taskStringBreakdown[0] == null) { + return "MISSING TASK STATEMENT"; + } + return "UNKNOWN ERROR"; + } +} diff --git a/src/main/java/Event.java b/src/main/java/Event.java index ecc8dbcfe..d1feb3f57 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -1,9 +1,15 @@ public class Event extends Task{ private String fromString; private String toString; - public Event(String inputString){ + public Event(String inputString) throws EventConstructorException{ super(inputString.replace("event ", "").split(" /from ")[0]); + if (!(inputString.contains(" /from ") & inputString.contains(" /to ")) | this.taskString == "" | this.taskString == null){ + throw new EventConstructorException(inputString); + } String[] fromToStrings = inputString.replace("event ", "").split(" /from ")[1].split(" /to "); + if (fromToStrings.length != 2) { + throw new EventConstructorException(inputString); + } this.fromString = fromToStrings[0]; this.toString = fromToStrings[1]; constructorMessage(); diff --git a/src/main/java/EventConstructorException.java b/src/main/java/EventConstructorException.java new file mode 100644 index 000000000..339737854 --- /dev/null +++ b/src/main/java/EventConstructorException.java @@ -0,0 +1,20 @@ +public class EventConstructorException extends Exception { + public EventConstructorException(String message) { + super("EVENT CONTRUCTOR EXCEPTION: " + message); + Task.deleteLatestTask(); + } + private static String errorMessage(String message) { + if (!(message.contains(" /from ") | message.contains(" /to "))) { + return "MISSING FROM/TO COMMANDS"; + } + String[] taskStringBreakdown = message.replace("event ", "").split(" /from "); + if (taskStringBreakdown[0] == "" | taskStringBreakdown[0] == null) { + return "MISSING TASK STATEMENT"; + } + String[] fromToStringBreakdown = taskStringBreakdown[1].split(" /to "); + if (fromToStringBreakdown.length != 2){ + return "MISSING FROM/TO DATES"; + } + return "UNKNOWN ERROR"; + } +} diff --git a/src/main/java/Juan.java b/src/main/java/Juan.java index 5d7f9ab54..f2891d731 100644 --- a/src/main/java/Juan.java +++ b/src/main/java/Juan.java @@ -1,3 +1,4 @@ +import java.text.ParseException; import java.util.Scanner; public class Juan { @@ -26,20 +27,28 @@ public static boolean chatFeature(){ return false; } else if (line.equals("list")) { Task.printTasksList(); - } else if (line.startsWith("mark")){ + } else if (line.startsWith("mark ")){ // Mark int taskIndex = Integer.parseInt(line.replace("mark ", "")) - 1; Task.mark(taskIndex); - } else if (line.startsWith("unmark")){ + } else if (line.startsWith("unmark ")){ // Unmark int taskIndex = Integer.parseInt(line.replace("unmark ", "")) - 1; Task.unmark(taskIndex); - } else if (line.startsWith("todo")) { + } else if (line.startsWith("todo ")) { new ToDo(line); - } else if (line.startsWith("deadline")) { - new Deadline(line); - } else if (line.startsWith("event")) { - new Event(line); + } else if (line.startsWith("deadline ")) { + try { + new Deadline(line); + } catch (DeadlineConstructorException e) { + System.out.println(e.getMessage()); + } + } else if (line.startsWith("event ")) { + try { + new Event(line); + } catch (EventConstructorException e) { + System.out.println(e.getMessage()); + } } else { System.out.println("Por Favor? Try a new request"); } diff --git a/src/main/java/Task.java b/src/main/java/Task.java index f5453eeea..17b356ee6 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -9,12 +9,17 @@ public class Task { public boolean isDone = false; // Constructor Function - public Task(String inputString) { + public Task(String inputString){ this.taskString = inputString; tasks[taskCount] = this; taskCount++; } + public static void deleteLatestTask(){ + tasks[taskCount-1] = null; + taskCount--; + } + public void constructorMessage(){ System.out.println("Muy Bien, work hard compadre!"); System.out.println("I've Added the Task:"); From cb16bf3d30531fa942e7ffe742aa44ca97cb2ee8 Mon Sep 17 00:00:00 2001 From: DarkDragoon2002 Date: Tue, 10 Sep 2024 15:48:38 +0800 Subject: [PATCH 09/31] Implemented ToDo Constructor Exceptions and Error Catching for chat commands --- src/main/java/Deadline.java | 2 +- .../java/DeadlineConstructorException.java | 6 ++-- src/main/java/Event.java | 2 +- src/main/java/EventConstructorException.java | 4 +-- src/main/java/Juan.java | 34 ++++++++++++++----- src/main/java/Task.java | 8 ----- src/main/java/ToDo.java | 5 ++- src/main/java/ToDoConstructorException.java | 14 ++++++++ 8 files changed, 51 insertions(+), 24 deletions(-) create mode 100644 src/main/java/ToDoConstructorException.java diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index 951224bd5..e441d0265 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -4,7 +4,7 @@ public class Deadline extends Task{ public Deadline(String inputString) throws DeadlineConstructorException{ super(inputString.replace("deadline ", "").split(" /by ")[0]); - if (!(inputString.contains(" /by ")) | this.taskString == "" | this.taskString == null){ + if (!(inputString.contains(" /by ")) | this.taskString.isEmpty()){ throw new DeadlineConstructorException(inputString); } this.deadlineString = inputString.replace("deadline ", "").split(" /by ")[1]; diff --git a/src/main/java/DeadlineConstructorException.java b/src/main/java/DeadlineConstructorException.java index 47e0b429f..581ee626b 100644 --- a/src/main/java/DeadlineConstructorException.java +++ b/src/main/java/DeadlineConstructorException.java @@ -1,6 +1,6 @@ public class DeadlineConstructorException extends Exception { public DeadlineConstructorException(String message) { - super("DEADLINE CONTRUCTOR EXCEPTION: " + message); + super("DEADLINE CONSTRUCTOR EXCEPTION: " + errorMessage(message)); Task.deleteLatestTask(); } @@ -8,8 +8,8 @@ private static String errorMessage(String message) { if (!(message.contains(" /by "))) { return "MISSING BY COMMAND"; } - String[] taskStringBreakdown = message.replace("event ", "").split(" /by "); - if (taskStringBreakdown[0] == "" | taskStringBreakdown[0] == null) { + String[] taskStringBreakdown = message.replace("deadline ", "").split(" /by "); + if (taskStringBreakdown[0].isEmpty()) { return "MISSING TASK STATEMENT"; } return "UNKNOWN ERROR"; diff --git a/src/main/java/Event.java b/src/main/java/Event.java index d1feb3f57..8acf1aa28 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -3,7 +3,7 @@ public class Event extends Task{ private String toString; public Event(String inputString) throws EventConstructorException{ super(inputString.replace("event ", "").split(" /from ")[0]); - if (!(inputString.contains(" /from ") & inputString.contains(" /to ")) | this.taskString == "" | this.taskString == null){ + if (!(inputString.contains(" /from ") & inputString.contains(" /to ")) | this.taskString.isEmpty()){ throw new EventConstructorException(inputString); } String[] fromToStrings = inputString.replace("event ", "").split(" /from ")[1].split(" /to "); diff --git a/src/main/java/EventConstructorException.java b/src/main/java/EventConstructorException.java index 339737854..f54c2a2e5 100644 --- a/src/main/java/EventConstructorException.java +++ b/src/main/java/EventConstructorException.java @@ -1,6 +1,6 @@ public class EventConstructorException extends Exception { public EventConstructorException(String message) { - super("EVENT CONTRUCTOR EXCEPTION: " + message); + super("EVENT CONSTRUCTOR EXCEPTION: " + errorMessage(message)); Task.deleteLatestTask(); } private static String errorMessage(String message) { @@ -8,7 +8,7 @@ private static String errorMessage(String message) { return "MISSING FROM/TO COMMANDS"; } String[] taskStringBreakdown = message.replace("event ", "").split(" /from "); - if (taskStringBreakdown[0] == "" | taskStringBreakdown[0] == null) { + if (taskStringBreakdown[0].isEmpty()) { return "MISSING TASK STATEMENT"; } String[] fromToStringBreakdown = taskStringBreakdown[1].split(" /to "); diff --git a/src/main/java/Juan.java b/src/main/java/Juan.java index f2891d731..212bc12ac 100644 --- a/src/main/java/Juan.java +++ b/src/main/java/Juan.java @@ -2,6 +2,7 @@ import java.util.Scanner; public class Juan { + private final static String porFavor = "Por Favor?\n"; public static void main(String[] args) { lineMessage(); helloMessage(); @@ -29,28 +30,45 @@ public static boolean chatFeature(){ Task.printTasksList(); } else if (line.startsWith("mark ")){ // Mark - int taskIndex = Integer.parseInt(line.replace("mark ", "")) - 1; - Task.mark(taskIndex); + try { + int taskIndex = Integer.parseInt(line.replace("mark ", "")) - 1; + Task.mark(taskIndex); + } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) { + System.out.println(porFavor + "MARK EXCEPTION: INVALID TASK INDEX"); + } catch (NullPointerException e) { + System.out.println(porFavor + "MARK EXCEPTION: NULL TASK INDEX"); + } } else if (line.startsWith("unmark ")){ // Unmark - int taskIndex = Integer.parseInt(line.replace("unmark ", "")) - 1; - Task.unmark(taskIndex); + try { + int taskIndex = Integer.parseInt(line.replace("unmark ", "")) - 1; + Task.unmark(taskIndex); + } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) { + System.out.println(porFavor + "UNMARK EXCEPTION: INVALID TASK INDEX"); + } catch (NullPointerException e) { + System.out.println(porFavor + "UNMARK EXCEPTION: NULL TASK INDEX"); + } + } else if (line.startsWith("todo ")) { - new ToDo(line); + try { + new ToDo(line); + } catch (ToDoConstructorException e) { + System.out.println(porFavor + e.getMessage()); + } } else if (line.startsWith("deadline ")) { try { new Deadline(line); } catch (DeadlineConstructorException e) { - System.out.println(e.getMessage()); + System.out.println(porFavor + e.getMessage()); } } else if (line.startsWith("event ")) { try { new Event(line); } catch (EventConstructorException e) { - System.out.println(e.getMessage()); + System.out.println(porFavor + e.getMessage()); } } else { - System.out.println("Por Favor? Try a new request"); + System.out.println(porFavor + "TRY A NEW REQUEST"); } lineMessage(); diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 17b356ee6..bf91a65ed 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -29,10 +29,6 @@ public void constructorMessage(){ // Class mark function public static void mark(int taskIndex){ - if (taskIndex < 0 || taskIndex >= taskCount){ // Validity Check - System.out.println("Not possible Amigo, try again"); - return; - } tasks[taskIndex].isDone = true; System.out.println("Fantastica!!!! I marked it:"); System.out.println(tasks[taskIndex].checkboxString()); @@ -40,10 +36,6 @@ public static void mark(int taskIndex){ // Class unmark function public static void unmark(int taskIndex){ - if (taskIndex < 0 || taskIndex >= taskCount){ // Validity Check - System.out.println("Not possible Amigo, try again"); - return; - } tasks[taskIndex].isDone = false; System.out.println("Ay Caramba, I unmarked it:"); System.out.println(tasks[taskIndex].checkboxString()); diff --git a/src/main/java/ToDo.java b/src/main/java/ToDo.java index 387eb93b6..42f47b9df 100644 --- a/src/main/java/ToDo.java +++ b/src/main/java/ToDo.java @@ -1,7 +1,10 @@ public class ToDo extends Task{ - public ToDo(String inputString){ + public ToDo(String inputString) throws ToDoConstructorException{ super(inputString.replace("todo ", "")); + if (this.taskString.isEmpty()){ + throw new ToDoConstructorException(inputString); + } constructorMessage(); } diff --git a/src/main/java/ToDoConstructorException.java b/src/main/java/ToDoConstructorException.java new file mode 100644 index 000000000..12348fda9 --- /dev/null +++ b/src/main/java/ToDoConstructorException.java @@ -0,0 +1,14 @@ +public class ToDoConstructorException extends Exception{ + public ToDoConstructorException(String message) { + super("TODO CONSTRUCTOR EXCEPTION: " + errorMessage(message)); + Task.deleteLatestTask(); + } + private static String errorMessage(String message) { + + String taskString = message.replace("todo ", ""); + if (taskString.isEmpty()) { + return "MISSING TASK STATEMENT"; + } + return "UNKNOWN ERROR"; + } +} From 913e6413b96d33aaf988a222ab1da458b83db328 Mon Sep 17 00:00:00 2001 From: DarkDragoon2002 Date: Tue, 10 Sep 2024 16:24:24 +0800 Subject: [PATCH 10/31] Implemented Packages --- .../DeadlineConstructorException.java | 3 +++ .../EventConstructorException.java | 3 +++ .../{ => CustomExceptions}/ToDoConstructorException.java | 3 +++ src/main/java/Juan.java | 9 ++++++++- src/main/java/{ => TaskChildren}/Deadline.java | 6 +++++- src/main/java/{ => TaskChildren}/Event.java | 6 +++++- src/main/java/{ => TaskChildren}/Task.java | 4 +++- src/main/java/{ => TaskChildren}/ToDo.java | 6 +++++- text-ui-test/EXPECTED.TXT | 6 +++--- 9 files changed, 38 insertions(+), 8 deletions(-) rename src/main/java/{ => CustomExceptions}/DeadlineConstructorException.java (92%) rename src/main/java/{ => CustomExceptions}/EventConstructorException.java (93%) rename src/main/java/{ => CustomExceptions}/ToDoConstructorException.java (89%) rename src/main/java/{ => TaskChildren}/Deadline.java (87%) rename src/main/java/{ => TaskChildren}/Event.java (91%) rename src/main/java/{ => TaskChildren}/Task.java (95%) rename src/main/java/{ => TaskChildren}/ToDo.java (83%) diff --git a/src/main/java/DeadlineConstructorException.java b/src/main/java/CustomExceptions/DeadlineConstructorException.java similarity index 92% rename from src/main/java/DeadlineConstructorException.java rename to src/main/java/CustomExceptions/DeadlineConstructorException.java index 581ee626b..3b6ff1162 100644 --- a/src/main/java/DeadlineConstructorException.java +++ b/src/main/java/CustomExceptions/DeadlineConstructorException.java @@ -1,3 +1,6 @@ +package CustomExceptions; +import TaskChildren.Task; + public class DeadlineConstructorException extends Exception { public DeadlineConstructorException(String message) { super("DEADLINE CONSTRUCTOR EXCEPTION: " + errorMessage(message)); diff --git a/src/main/java/EventConstructorException.java b/src/main/java/CustomExceptions/EventConstructorException.java similarity index 93% rename from src/main/java/EventConstructorException.java rename to src/main/java/CustomExceptions/EventConstructorException.java index f54c2a2e5..08389ab0a 100644 --- a/src/main/java/EventConstructorException.java +++ b/src/main/java/CustomExceptions/EventConstructorException.java @@ -1,3 +1,6 @@ +package CustomExceptions; +import TaskChildren.Task; + public class EventConstructorException extends Exception { public EventConstructorException(String message) { super("EVENT CONSTRUCTOR EXCEPTION: " + errorMessage(message)); diff --git a/src/main/java/ToDoConstructorException.java b/src/main/java/CustomExceptions/ToDoConstructorException.java similarity index 89% rename from src/main/java/ToDoConstructorException.java rename to src/main/java/CustomExceptions/ToDoConstructorException.java index 12348fda9..d7a00c57e 100644 --- a/src/main/java/ToDoConstructorException.java +++ b/src/main/java/CustomExceptions/ToDoConstructorException.java @@ -1,3 +1,6 @@ +package CustomExceptions; +import TaskChildren.Task; + public class ToDoConstructorException extends Exception{ public ToDoConstructorException(String message) { super("TODO CONSTRUCTOR EXCEPTION: " + errorMessage(message)); diff --git a/src/main/java/Juan.java b/src/main/java/Juan.java index 212bc12ac..0de93d21b 100644 --- a/src/main/java/Juan.java +++ b/src/main/java/Juan.java @@ -1,4 +1,11 @@ -import java.text.ParseException; +import CustomExceptions.DeadlineConstructorException; +import CustomExceptions.EventConstructorException; +import CustomExceptions.ToDoConstructorException; +import TaskChildren.Deadline; +import TaskChildren.Event; +import TaskChildren.Task; +import TaskChildren.ToDo; + import java.util.Scanner; public class Juan { diff --git a/src/main/java/Deadline.java b/src/main/java/TaskChildren/Deadline.java similarity index 87% rename from src/main/java/Deadline.java rename to src/main/java/TaskChildren/Deadline.java index e441d0265..92701e652 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/TaskChildren/Deadline.java @@ -1,8 +1,12 @@ +package TaskChildren; + +import CustomExceptions.DeadlineConstructorException; + public class Deadline extends Task{ private String deadlineString; - public Deadline(String inputString) throws DeadlineConstructorException{ + public Deadline(String inputString) throws DeadlineConstructorException { super(inputString.replace("deadline ", "").split(" /by ")[0]); if (!(inputString.contains(" /by ")) | this.taskString.isEmpty()){ throw new DeadlineConstructorException(inputString); diff --git a/src/main/java/Event.java b/src/main/java/TaskChildren/Event.java similarity index 91% rename from src/main/java/Event.java rename to src/main/java/TaskChildren/Event.java index 8acf1aa28..d141b8a8d 100644 --- a/src/main/java/Event.java +++ b/src/main/java/TaskChildren/Event.java @@ -1,7 +1,11 @@ +package TaskChildren; + +import CustomExceptions.EventConstructorException; + public class Event extends Task{ private String fromString; private String toString; - public Event(String inputString) throws EventConstructorException{ + public Event(String inputString) throws EventConstructorException { super(inputString.replace("event ", "").split(" /from ")[0]); if (!(inputString.contains(" /from ") & inputString.contains(" /to ")) | this.taskString.isEmpty()){ throw new EventConstructorException(inputString); diff --git a/src/main/java/Task.java b/src/main/java/TaskChildren/Task.java similarity index 95% rename from src/main/java/Task.java rename to src/main/java/TaskChildren/Task.java index bf91a65ed..92d708529 100644 --- a/src/main/java/Task.java +++ b/src/main/java/TaskChildren/Task.java @@ -1,3 +1,5 @@ +package TaskChildren; + public class Task { // Keep track of tasks @@ -41,7 +43,7 @@ public static void unmark(int taskIndex){ System.out.println(tasks[taskIndex].checkboxString()); } - // Function to create String with Checkbox and Task + // Function to create String with Checkbox and TaskChildren.Task public String checkboxString(){ String returnString = "["; if (this.isDone){ diff --git a/src/main/java/ToDo.java b/src/main/java/TaskChildren/ToDo.java similarity index 83% rename from src/main/java/ToDo.java rename to src/main/java/TaskChildren/ToDo.java index 42f47b9df..69ffeb1ae 100644 --- a/src/main/java/ToDo.java +++ b/src/main/java/TaskChildren/ToDo.java @@ -1,6 +1,10 @@ +package TaskChildren; + +import CustomExceptions.ToDoConstructorException; + public class ToDo extends Task{ - public ToDo(String inputString) throws ToDoConstructorException{ + public ToDo(String inputString) throws ToDoConstructorException { super(inputString.replace("todo ", "")); if (this.taskString.isEmpty()){ throw new ToDoConstructorException(inputString); diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 8ae18219b..9366ad85f 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -18,21 +18,21 @@ ____________________________________________________________ event La Familia Meeting /from 5pm /to 6pm ____________________________________________________________ Muy Bien, work hard compadre! -I've Added the Task: +I've Added the TaskChildren.Task: [E][ ] La Familia Meeting (from: 5pm to: 6pm) You've got 1 tasks, better start working! ____________________________________________________________ deadline Fry the Pollo with the Hermanos /by 5th July ____________________________________________________________ Muy Bien, work hard compadre! -I've Added the Task: +I've Added the TaskChildren.Task: [D][ ] Fry the Pollo with the Hermanos (by: 5th July) You've got 2 tasks, better start working! ____________________________________________________________ todo eat the pollo ____________________________________________________________ Muy Bien, work hard compadre! -I've Added the Task: +I've Added the TaskChildren.Task: [T][ ] eat the pollo You've got 3 tasks, better start working! ____________________________________________________________ From f0c0fabcb18661798494e89008eb51e23568a2d9 Mon Sep 17 00:00:00 2001 From: DarkDragoon2002 Date: Thu, 12 Sep 2024 15:56:22 +0800 Subject: [PATCH 11/31] Added Comments Created branch-A-Packages for tracker Packages commit in level-5 branch --- .../DeadlineConstructorException.java | 23 ++- .../EventConstructorException.java | 34 ++++- .../ToDoConstructorException.java | 22 ++- src/main/java/Juan.java | 137 +++++++++++------- src/main/java/TaskChildren/Deadline.java | 26 +++- src/main/java/TaskChildren/Event.java | 32 +++- src/main/java/TaskChildren/Task.java | 72 ++++----- src/main/java/TaskChildren/ToDo.java | 20 ++- 8 files changed, 241 insertions(+), 125 deletions(-) diff --git a/src/main/java/CustomExceptions/DeadlineConstructorException.java b/src/main/java/CustomExceptions/DeadlineConstructorException.java index 3b6ff1162..e921ed780 100644 --- a/src/main/java/CustomExceptions/DeadlineConstructorException.java +++ b/src/main/java/CustomExceptions/DeadlineConstructorException.java @@ -1,20 +1,35 @@ -package CustomExceptions; -import TaskChildren.Task; +package CustomExceptions; // Package for custom exceptions +import TaskChildren.Task; // Import Task class to manage task deletion +// Custom exception class for handling errors in Deadline task construction public class DeadlineConstructorException extends Exception { + + // Constructor that takes an error message as input public DeadlineConstructorException(String message) { + // Call the superclass (Exception) constructor with a detailed error message super("DEADLINE CONSTRUCTOR EXCEPTION: " + errorMessage(message)); + + // If an error occurs, the latest task added is deleted to prevent invalid tasks Task.deleteLatestTask(); } + // Private helper method to interpret the error message + // It checks for specific missing components in the deadline command private static String errorMessage(String message) { + // Check if the "/by" keyword is missing, which is needed for deadline tasks if (!(message.contains(" /by "))) { - return "MISSING BY COMMAND"; + return "MISSING BY COMMAND"; // Return specific error if "/by" is not found } + + // Split the task input string into task description and deadline parts String[] taskStringBreakdown = message.replace("deadline ", "").split(" /by "); + + // Check if the task description before "/by" is empty if (taskStringBreakdown[0].isEmpty()) { - return "MISSING TASK STATEMENT"; + return "MISSING TASK STATEMENT"; // Return specific error if no task description } + + // If none of the specific errors match, return an unknown error return "UNKNOWN ERROR"; } } diff --git a/src/main/java/CustomExceptions/EventConstructorException.java b/src/main/java/CustomExceptions/EventConstructorException.java index 08389ab0a..d14da61cd 100644 --- a/src/main/java/CustomExceptions/EventConstructorException.java +++ b/src/main/java/CustomExceptions/EventConstructorException.java @@ -1,23 +1,43 @@ -package CustomExceptions; -import TaskChildren.Task; +package CustomExceptions; // Package for custom exceptions +import TaskChildren.Task; // Import Task class to manage task deletion +// Custom exception class for handling errors in Event task construction public class EventConstructorException extends Exception { + + // Constructor that takes an error message as input public EventConstructorException(String message) { + // Call the superclass (Exception) constructor with a detailed error message super("EVENT CONSTRUCTOR EXCEPTION: " + errorMessage(message)); + + // If an error occurs, the latest task added is deleted to prevent invalid tasks Task.deleteLatestTask(); } + + // Private helper method to interpret the error message + // It checks for specific missing components in the event command private static String errorMessage(String message) { - if (!(message.contains(" /from ") | message.contains(" /to "))) { - return "MISSING FROM/TO COMMANDS"; + // Check if the "/from" and "/to" keywords are missing, which are needed for event tasks + if (!(message.contains(" /from ") || message.contains(" /to "))) { + return "MISSING FROM/TO COMMANDS"; // Return specific error if either "/from" or "/to" is missing } + + // Split the task input string into task description and the time period starting with "/from" String[] taskStringBreakdown = message.replace("event ", "").split(" /from "); + + // Check if the task description before "/from" is empty if (taskStringBreakdown[0].isEmpty()) { - return "MISSING TASK STATEMENT"; + return "MISSING TASK STATEMENT"; // Return specific error if no task description is provided } + + // Further split the time period into "from" and "to" parts String[] fromToStringBreakdown = taskStringBreakdown[1].split(" /to "); - if (fromToStringBreakdown.length != 2){ - return "MISSING FROM/TO DATES"; + + // Check if both "from" and "to" components are present + if (fromToStringBreakdown.length != 2) { + return "MISSING FROM/TO DATES"; // Return specific error if either "from" or "to" date is missing } + + // If none of the specific errors match, return an unknown error return "UNKNOWN ERROR"; } } diff --git a/src/main/java/CustomExceptions/ToDoConstructorException.java b/src/main/java/CustomExceptions/ToDoConstructorException.java index d7a00c57e..7afc07ba6 100644 --- a/src/main/java/CustomExceptions/ToDoConstructorException.java +++ b/src/main/java/CustomExceptions/ToDoConstructorException.java @@ -1,17 +1,31 @@ -package CustomExceptions; -import TaskChildren.Task; +package CustomExceptions; // Package for custom exceptions +import TaskChildren.Task; // Import Task class to manage task deletion -public class ToDoConstructorException extends Exception{ +// Custom exception class for handling errors in ToDo task construction +public class ToDoConstructorException extends Exception { + + // Constructor that takes an error message as input public ToDoConstructorException(String message) { + // Call the superclass (Exception) constructor with a detailed error message super("TODO CONSTRUCTOR EXCEPTION: " + errorMessage(message)); + + // If an error occurs, the latest task added is deleted to prevent invalid tasks Task.deleteLatestTask(); } + + // Private helper method to interpret the error message + // It checks for specific missing components in the todo command private static String errorMessage(String message) { + // Remove the "todo" keyword from the message to isolate the task statement String taskString = message.replace("todo ", ""); + + // Check if the task statement is empty if (taskString.isEmpty()) { - return "MISSING TASK STATEMENT"; + return "MISSING TASK STATEMENT"; // Return specific error if the task description is missing } + + // If none of the specific errors match, return an unknown error return "UNKNOWN ERROR"; } } diff --git a/src/main/java/Juan.java b/src/main/java/Juan.java index 0de93d21b..b50e37de7 100644 --- a/src/main/java/Juan.java +++ b/src/main/java/Juan.java @@ -1,114 +1,139 @@ -import CustomExceptions.DeadlineConstructorException; -import CustomExceptions.EventConstructorException; -import CustomExceptions.ToDoConstructorException; -import TaskChildren.Deadline; -import TaskChildren.Event; -import TaskChildren.Task; -import TaskChildren.ToDo; +import CustomExceptions.*; // Import custom exception classes +import TaskChildren.*; // Import task-related classes like ToDo, Deadline, and Event -import java.util.Scanner; +import java.util.Scanner; // Import Scanner for user input public class Juan { + // Constant for common error message to improve code readability and reusability private final static String porFavor = "Por Favor?\n"; + + // Main entry point for the application public static void main(String[] args) { + // Display initial line and welcome message lineMessage(); helloMessage(); lineMessage(); + // Continue chatting as long as user doesn't exit boolean continueChatting = true; while (continueChatting) { + // Chat feature to handle user input continueChatting = chatFeature(); } + + // Display goodbye message when the chat ends byeMessage(); lineMessage(); } - public static boolean chatFeature(){ - // Less efficient to create a new scanner everytime but code is much neater - // If return True means continue - // Else End - Scanner scanner = new Scanner(System.in); - String line = scanner.nextLine(); - lineMessage(); + // Handles user input and executes corresponding actions + public static boolean chatFeature() { + + Scanner scanner = new Scanner(System.in); // Initialize the scanner for reading user input + String line = scanner.nextLine(); // Read user input + lineMessage(); // Print separator line + // Handle "bye" command to end chat if (line.equals("bye")) { - return false; - } else if (line.equals("list")) { - Task.printTasksList(); - } else if (line.startsWith("mark ")){ - // Mark + return false; // End the conversation + } + // Handle "list" command to display the list of tasks + else if (line.equals("list")) { + Task.printTasksList(); // Print task list from Task class + } + // Handle "mark" command to mark a task as completed + else if (line.startsWith("mark ")) { try { - int taskIndex = Integer.parseInt(line.replace("mark ", "")) - 1; - Task.mark(taskIndex); + int taskIndex = Integer.parseInt(line.replace("mark ", "")) - 1; // Parse the task index + Task.mark(taskIndex); // Mark the task as done } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) { + // Handle invalid index or format exceptions System.out.println(porFavor + "MARK EXCEPTION: INVALID TASK INDEX"); } catch (NullPointerException e) { + // Handle null task case System.out.println(porFavor + "MARK EXCEPTION: NULL TASK INDEX"); } - } else if (line.startsWith("unmark ")){ - // Unmark + } + // Handle "unmark" command to unmark a task as completed + else if (line.startsWith("unmark ")) { try { - int taskIndex = Integer.parseInt(line.replace("unmark ", "")) - 1; - Task.unmark(taskIndex); + int taskIndex = Integer.parseInt(line.replace("unmark ", "")) - 1; // Parse the task index + Task.unmark(taskIndex); // Unmark the task } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) { + // Handle invalid index or format exceptions System.out.println(porFavor + "UNMARK EXCEPTION: INVALID TASK INDEX"); } catch (NullPointerException e) { + // Handle null task case System.out.println(porFavor + "UNMARK EXCEPTION: NULL TASK INDEX"); } - } else if (line.startsWith("todo ")) { + } + // Handle "todo" command to create a new ToDo task + else if (line.startsWith("todo ")) { try { - new ToDo(line); + new ToDo(line); // Create a new ToDo object } catch (ToDoConstructorException e) { + // Handle custom ToDo exception System.out.println(porFavor + e.getMessage()); } - } else if (line.startsWith("deadline ")) { + } + // Handle "deadline" command to create a new Deadline task + else if (line.startsWith("deadline ")) { try { - new Deadline(line); + new Deadline(line); // Create a new Deadline object } catch (DeadlineConstructorException e) { + // Handle custom Deadline exception System.out.println(porFavor + e.getMessage()); } - } else if (line.startsWith("event ")) { + } + // Handle "event" command to create a new Event task + else if (line.startsWith("event ")) { try { - new Event(line); + new Event(line); // Create a new Event object } catch (EventConstructorException e) { + // Handle custom Event exception System.out.println(porFavor + e.getMessage()); } - } else { - System.out.println(porFavor + "TRY A NEW REQUEST"); + } + // Default case for unrecognized commands + else { + System.out.println(porFavor + "UNRECOGNIZED REQUEST"); // Inform user about an unrecognized command } - lineMessage(); - return true; + lineMessage(); // Print separator line + return true; // Continue conversation } - // Message Functions for cleaner main Function + // Utility function to print a separator line for clean output formatting public static void lineMessage() { String line = "____________________________________________________________\n"; System.out.print(line); } + + // Displays a welcome message when the program starts public static void helloMessage() { String greeting = - " ._-'-_ .\n" + - " . ' /_-_-_\\ ` .\n" + - " .' |-_-_-_-| `.\n" + - " ( `.-_-_-.' )\n" + - " !`. .'!\n" + - " ! ` . . ' !\n" + - " ! ! ! ! ! ! ! ! !\n" + - " / / \\ \\\n" + - " _-| \\___ ___/ /-_\n" + - " (_ )__\\_)\\(_/__( _)\n" + - " ))))\\X\\ ((((\n" + - " \\/ \\/ \n" + - "Hola Amigo, I am Juan Cervantes Salamanca from Michoacan \n" + - "Welcome to la familia \n" + - "How can we help you? \n"; - System.out.print(greeting); + " ._-'-_ .\n" + + " . ' /_-_-_\\ ` .\n" + + " .' |-_-_-_-| `.\n" + + " ( `.-_-_-.' )\n" + + " !`. .'!\n" + + " ! ` . . ' !\n" + + " ! ! ! ! ! ! ! ! !\n" + + " / / \\ \\\n" + + " _-| \\___ ___/ /-_\n" + + " (_ )__\\_)\\(_/__( _)\n" + + " ))))\\X\\ ((((\n" + + " \\/ \\/ \n" + + "Hola Amigo, I am Juan Cervantes Salamanca from Michoacan \n" + + "Welcome to la familia \n" + + "How can we help you? \n"; + System.out.print(greeting); // Print the welcome message } + + // Displays a goodbye message when the program ends public static void byeMessage() { String bye = "Adios amigo, la familia will miss you\n"; - System.out.print(bye); + System.out.print(bye); // Print the goodbye message } - -} \ No newline at end of file +} diff --git a/src/main/java/TaskChildren/Deadline.java b/src/main/java/TaskChildren/Deadline.java index 92701e652..588299b55 100644 --- a/src/main/java/TaskChildren/Deadline.java +++ b/src/main/java/TaskChildren/Deadline.java @@ -1,22 +1,34 @@ -package TaskChildren; +package TaskChildren; // Package for Task-related classes -import CustomExceptions.DeadlineConstructorException; +import CustomExceptions.DeadlineConstructorException; // Import custom exception for Deadline tasks -public class Deadline extends Task{ +// Deadline class, a child class of Task, represents a task with a specific deadline +public class Deadline extends Task { + // Variable to store the deadline date/time string private String deadlineString; + // Constructor for creating a Deadline task public Deadline(String inputString) throws DeadlineConstructorException { + // Call the parent class (Task) constructor with the task description (before the "/by" keyword) super(inputString.replace("deadline ", "").split(" /by ")[0]); - if (!(inputString.contains(" /by ")) | this.taskString.isEmpty()){ - throw new DeadlineConstructorException(inputString); + + // Check if the "/by" keyword is missing or if the task description is empty + if (!(inputString.contains(" /by ")) || this.taskString.isEmpty()) { + throw new DeadlineConstructorException(inputString); // Throw custom exception if validation fails } + + // Extract the deadline portion of the input string (after the "/by" keyword) this.deadlineString = inputString.replace("deadline ", "").split(" /by ")[1]; - constructorMessage(); + // Display a confirmation message when a Deadline task is successfully created + constructorMessage(); } + + // Override the checkboxString method to include the "[D]" tag and the deadline information @Override - public String checkboxString(){ + public String checkboxString() { + // Call the parent method and add the "[D]" tag and deadline string to the checkbox format return "[D]" + super.checkboxString() + " (by: " + deadlineString + ")"; } } diff --git a/src/main/java/TaskChildren/Event.java b/src/main/java/TaskChildren/Event.java index d141b8a8d..eb647b413 100644 --- a/src/main/java/TaskChildren/Event.java +++ b/src/main/java/TaskChildren/Event.java @@ -1,26 +1,44 @@ -package TaskChildren; +package TaskChildren; // Package for Task-related classes -import CustomExceptions.EventConstructorException; +import CustomExceptions.EventConstructorException; // Import custom exception for Event tasks -public class Event extends Task{ +// Event class, a child class of Task, represents a task with a specific start and end time +public class Event extends Task { + + // Variables to store the start and end times of the event private String fromString; private String toString; + + // Constructor for creating an Event task public Event(String inputString) throws EventConstructorException { + // Call the parent class (Task) constructor with the task description (before the "/from" keyword) super(inputString.replace("event ", "").split(" /from ")[0]); - if (!(inputString.contains(" /from ") & inputString.contains(" /to ")) | this.taskString.isEmpty()){ - throw new EventConstructorException(inputString); + + // Validate if both "/from" and "/to" keywords are present, and the task description is not empty + if (!(inputString.contains(" /from ") & inputString.contains(" /to ")) || this.taskString.isEmpty()) { + throw new EventConstructorException(inputString); // Throw custom exception if validation fails } + + // Split the input to extract the start and end times String[] fromToStrings = inputString.replace("event ", "").split(" /from ")[1].split(" /to "); + + // Check if both "from" and "to" times are provided if (fromToStrings.length != 2) { - throw new EventConstructorException(inputString); + throw new EventConstructorException(inputString); // Throw custom exception if either is missing } + + // Set the from and to times for the event this.fromString = fromToStrings[0]; this.toString = fromToStrings[1]; + + // Display a confirmation message when an Event task is successfully created constructorMessage(); } + // Override the checkboxString method to include the "[E]" tag, start time, and end time @Override - public String checkboxString(){ + public String checkboxString() { + // Call the parent method and add the "[E]" tag along with the event's start and end times return "[E]" + super.checkboxString() + " (from: " + fromString + " to: " + toString + ")"; } } diff --git a/src/main/java/TaskChildren/Task.java b/src/main/java/TaskChildren/Task.java index 92d708529..b452f1dc0 100644 --- a/src/main/java/TaskChildren/Task.java +++ b/src/main/java/TaskChildren/Task.java @@ -1,69 +1,73 @@ -package TaskChildren; +package TaskChildren; // Package for Task-related classes +// Parent class Task which serves as a base for ToDo, Deadline, and Event tasks public class Task { - // Keep track of tasks - private static Task[] tasks = new Task[100]; - private static int taskCount = 0; + // Array to keep track of all tasks added + private static Task[] tasks = new Task[100]; // Task array of size 100 to store tasks + private static int taskCount = 0; // Counter to keep track of the number of tasks - // Object specific variables - public String taskString; - public boolean isDone = false; + // Object-specific variables + public String taskString; // String to hold the task description + public boolean isDone = false; // Boolean to track if the task is marked as done - // Constructor Function + // Constructor Function: initializes a Task object and adds it to the tasks array public Task(String inputString){ - this.taskString = inputString; - tasks[taskCount] = this; - taskCount++; + this.taskString = inputString; // Set the task description + tasks[taskCount] = this; // Add the current task to the array + taskCount++; // Increment the task count } + // Static method to delete the latest task in case of errors public static void deleteLatestTask(){ - tasks[taskCount-1] = null; - taskCount--; + tasks[taskCount-1] = null; // Remove the latest task from the array + taskCount--; // Decrement the task count } + // Method to display a message when a task is successfully created public void constructorMessage(){ - System.out.println("Muy Bien, work hard compadre!"); + System.out.println("Muy Bien, work hard compadre!"); // Success message in Spanish System.out.println("I've Added the Task:"); - System.out.println(checkboxString()); - System.out.println("You've got " + taskCount + " tasks, better start working!"); + System.out.println(checkboxString()); // Display the task in checkbox format + System.out.println("You've got " + taskCount + " tasks, better start working!"); // Display the current task count } - // Class mark function + // Static method to mark a task as done by index public static void mark(int taskIndex){ - tasks[taskIndex].isDone = true; - System.out.println("Fantastica!!!! I marked it:"); - System.out.println(tasks[taskIndex].checkboxString()); + tasks[taskIndex].isDone = true; // Mark the task as done + System.out.println("Fantastica!!!! I marked it:"); // Success message in Spanish + System.out.println(tasks[taskIndex].checkboxString()); // Display the updated task } - // Class unmark function + // Static method to unmark a task as undone by index public static void unmark(int taskIndex){ - tasks[taskIndex].isDone = false; - System.out.println("Ay Caramba, I unmarked it:"); - System.out.println(tasks[taskIndex].checkboxString()); + tasks[taskIndex].isDone = false; // Unmark the task as not done + System.out.println("Ay Caramba, I unmarked it:"); // Message indicating task was unmarked + System.out.println(tasks[taskIndex].checkboxString()); // Display the updated task } - // Function to create String with Checkbox and TaskChildren.Task + // Method to create and return a string with a checkbox (marked or unmarked) for the task public String checkboxString(){ - String returnString = "["; + String returnString = "["; // Start of the checkbox string if (this.isDone){ - returnString += "X"; + returnString += "X"; // Mark the checkbox as done if the task is completed } else { - returnString += " "; + returnString += " "; // Leave the checkbox empty if the task is not completed } - returnString += "] " + this.taskString; - return returnString; + returnString += "] " + this.taskString; // Append the task description + return returnString; // Return the formatted string } - // Function to print out task checklist + // Static method to print all tasks in the list public static void printTasksList(){ if (taskCount == 0){ - System.out.println("Por Favor? Nothing Here"); + System.out.println("Por Favor? Nothing Here"); // Message when there are no tasks } else { - System.out.println("Si compinche, your tasks:"); + System.out.println("Si compinche, your tasks:"); // Message when displaying tasks for (int i = 0; i < taskCount; i++){ + // Print each task with its index and checkbox format System.out.println((i+1) + "." + tasks[i].checkboxString()); } } } -} \ No newline at end of file +} diff --git a/src/main/java/TaskChildren/ToDo.java b/src/main/java/TaskChildren/ToDo.java index 69ffeb1ae..8b751e0f6 100644 --- a/src/main/java/TaskChildren/ToDo.java +++ b/src/main/java/TaskChildren/ToDo.java @@ -1,19 +1,27 @@ -package TaskChildren; +package TaskChildren; // Package for Task-related classes -import CustomExceptions.ToDoConstructorException; +import CustomExceptions.ToDoConstructorException; // Import custom exception for ToDo tasks -public class ToDo extends Task{ +// ToDo class, a child class of Task, represents a simple to-do task +public class ToDo extends Task { + // Constructor for creating a ToDo task public ToDo(String inputString) throws ToDoConstructorException { + // Call the parent class (Task) constructor, removing the "todo" prefix from the input super(inputString.replace("todo ", "")); - if (this.taskString.isEmpty()){ - throw new ToDoConstructorException(inputString); + + // If the task description is empty, throw a custom exception + if (this.taskString.isEmpty()) { + throw new ToDoConstructorException(inputString); // Handle invalid ToDo input } + + // Display a confirmation message when a ToDo task is successfully created constructorMessage(); } + // Override the checkboxString method to prefix "[T]" to indicate that the task is a ToDo @Override public String checkboxString() { - return "[T]" + super.checkboxString(); + return "[T]" + super.checkboxString(); // Call the parent method and add the "[T]" tag } } From 2d8b65a838ab63d4f76dc29f56a05eb7db7248bf Mon Sep 17 00:00:00 2001 From: DarkDragoon2002 Date: Fri, 20 Sep 2024 02:26:29 +0800 Subject: [PATCH 12/31] Implemented ArrayList --- src/main/java/META-INF/MANIFEST.MF | 3 +++ src/main/java/TaskChildren/Task.java | 17 +++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 src/main/java/META-INF/MANIFEST.MF diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 000000000..d02c17cc4 --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: Juan + diff --git a/src/main/java/TaskChildren/Task.java b/src/main/java/TaskChildren/Task.java index b452f1dc0..193e71b11 100644 --- a/src/main/java/TaskChildren/Task.java +++ b/src/main/java/TaskChildren/Task.java @@ -1,10 +1,11 @@ package TaskChildren; // Package for Task-related classes +import java.util.ArrayList; // Parent class Task which serves as a base for ToDo, Deadline, and Event tasks public class Task { // Array to keep track of all tasks added - private static Task[] tasks = new Task[100]; // Task array of size 100 to store tasks + private static ArrayList tasks = new ArrayList<>(100); // Task array of size 100 to store tasks private static int taskCount = 0; // Counter to keep track of the number of tasks // Object-specific variables @@ -14,13 +15,13 @@ public class Task { // Constructor Function: initializes a Task object and adds it to the tasks array public Task(String inputString){ this.taskString = inputString; // Set the task description - tasks[taskCount] = this; // Add the current task to the array + tasks.add(this); // Add the current task to the array taskCount++; // Increment the task count } // Static method to delete the latest task in case of errors public static void deleteLatestTask(){ - tasks[taskCount-1] = null; // Remove the latest task from the array + tasks.remove(taskCount - 1); // Remove the latest task from the array taskCount--; // Decrement the task count } @@ -34,16 +35,16 @@ public void constructorMessage(){ // Static method to mark a task as done by index public static void mark(int taskIndex){ - tasks[taskIndex].isDone = true; // Mark the task as done + tasks.get(taskIndex).isDone = true; // Mark the task as done System.out.println("Fantastica!!!! I marked it:"); // Success message in Spanish - System.out.println(tasks[taskIndex].checkboxString()); // Display the updated task + System.out.println(tasks.get(taskIndex).checkboxString()); // Display the updated task } // Static method to unmark a task as undone by index public static void unmark(int taskIndex){ - tasks[taskIndex].isDone = false; // Unmark the task as not done + tasks.get(taskIndex).isDone = false; // Unmark the task as not done System.out.println("Ay Caramba, I unmarked it:"); // Message indicating task was unmarked - System.out.println(tasks[taskIndex].checkboxString()); // Display the updated task + System.out.println(tasks.get(taskIndex).checkboxString()); // Display the updated task } // Method to create and return a string with a checkbox (marked or unmarked) for the task @@ -66,7 +67,7 @@ public static void printTasksList(){ System.out.println("Si compinche, your tasks:"); // Message when displaying tasks for (int i = 0; i < taskCount; i++){ // Print each task with its index and checkbox format - System.out.println((i+1) + "." + tasks[i].checkboxString()); + System.out.println((i+1) + "." + tasks.get(i).checkboxString()); } } } From 5b59c6f8abad1fff6a5bcf7a2c67cd6a6215f220 Mon Sep 17 00:00:00 2001 From: DarkDragoon2002 Date: Fri, 20 Sep 2024 02:49:14 +0800 Subject: [PATCH 13/31] Implemented delete function & cleaned up code --- src/main/java/Juan.java | 17 +++++++++++++++-- src/main/java/TaskChildren/Task.java | 19 +++++++++++-------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/main/java/Juan.java b/src/main/java/Juan.java index b50e37de7..ab51c8c9c 100644 --- a/src/main/java/Juan.java +++ b/src/main/java/Juan.java @@ -41,12 +41,25 @@ public static boolean chatFeature() { else if (line.equals("list")) { Task.printTasksList(); // Print task list from Task class } + // Handle "delete" command + else if (line.startsWith("delete ")) { + try { + int taskIndex = Integer.parseInt(line.replace("delete ", "")) - 1; // Parse the task index + Task.deleteTask(taskIndex); // Mark the task as done + } catch (NumberFormatException | IndexOutOfBoundsException e) { + // Handle invalid index or format exceptions + System.out.println(porFavor + "DELETE EXCEPTION: INVALID TASK INDEX"); + } catch (NullPointerException e) { + // Handle null task case + System.out.println(porFavor + "DELETE EXCEPTION: NULL TASK INDEX"); + } + } // Handle "mark" command to mark a task as completed else if (line.startsWith("mark ")) { try { int taskIndex = Integer.parseInt(line.replace("mark ", "")) - 1; // Parse the task index Task.mark(taskIndex); // Mark the task as done - } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) { + } catch (NumberFormatException | IndexOutOfBoundsException e) { // Handle invalid index or format exceptions System.out.println(porFavor + "MARK EXCEPTION: INVALID TASK INDEX"); } catch (NullPointerException e) { @@ -59,7 +72,7 @@ else if (line.startsWith("unmark ")) { try { int taskIndex = Integer.parseInt(line.replace("unmark ", "")) - 1; // Parse the task index Task.unmark(taskIndex); // Unmark the task - } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) { + } catch (NumberFormatException | IndexOutOfBoundsException e) { // Handle invalid index or format exceptions System.out.println(porFavor + "UNMARK EXCEPTION: INVALID TASK INDEX"); } catch (NullPointerException e) { diff --git a/src/main/java/TaskChildren/Task.java b/src/main/java/TaskChildren/Task.java index 193e71b11..d83e1c7da 100644 --- a/src/main/java/TaskChildren/Task.java +++ b/src/main/java/TaskChildren/Task.java @@ -5,8 +5,7 @@ public class Task { // Array to keep track of all tasks added - private static ArrayList tasks = new ArrayList<>(100); // Task array of size 100 to store tasks - private static int taskCount = 0; // Counter to keep track of the number of tasks + private static ArrayList tasks = new ArrayList<>(); // Object-specific variables public String taskString; // String to hold the task description @@ -16,13 +15,17 @@ public class Task { public Task(String inputString){ this.taskString = inputString; // Set the task description tasks.add(this); // Add the current task to the array - taskCount++; // Increment the task count + } + + public static void deleteTask(int taskIndex){ + String taskString = tasks.get(taskIndex).checkboxString(); + tasks.remove(taskIndex); + System.out.println("Ay Caramba, Task deleted: " + taskString); } // Static method to delete the latest task in case of errors public static void deleteLatestTask(){ - tasks.remove(taskCount - 1); // Remove the latest task from the array - taskCount--; // Decrement the task count + tasks.remove(tasks.size() - 1); // Remove the latest task from the array } // Method to display a message when a task is successfully created @@ -30,7 +33,7 @@ public void constructorMessage(){ System.out.println("Muy Bien, work hard compadre!"); // Success message in Spanish System.out.println("I've Added the Task:"); System.out.println(checkboxString()); // Display the task in checkbox format - System.out.println("You've got " + taskCount + " tasks, better start working!"); // Display the current task count + System.out.println("You've got " + tasks.size() + " tasks, better start working!"); // Display the current task count } // Static method to mark a task as done by index @@ -61,11 +64,11 @@ public String checkboxString(){ // Static method to print all tasks in the list public static void printTasksList(){ - if (taskCount == 0){ + if (tasks.size() == 0){ System.out.println("Por Favor? Nothing Here"); // Message when there are no tasks } else { System.out.println("Si compinche, your tasks:"); // Message when displaying tasks - for (int i = 0; i < taskCount; i++){ + for (int i = 0; i < tasks.size(); i++){ // Print each task with its index and checkbox format System.out.println((i+1) + "." + tasks.get(i).checkboxString()); } From c4ca544f4c6801149c50065a11a848f37302f976 Mon Sep 17 00:00:00 2001 From: DarkDragoon2002 Date: Fri, 20 Sep 2024 15:30:44 +0800 Subject: [PATCH 14/31] Implemented Data Writing System --- data.text | 1 + src/main/java/Juan.java | 87 +++++++++++++++++++++++- src/main/java/TaskChildren/Deadline.java | 9 ++- src/main/java/TaskChildren/Event.java | 8 ++- src/main/java/TaskChildren/Task.java | 13 ++++ src/main/java/TaskChildren/ToDo.java | 9 ++- 6 files changed, 116 insertions(+), 11 deletions(-) create mode 100644 data.text diff --git a/data.text b/data.text new file mode 100644 index 000000000..8933a5a89 --- /dev/null +++ b/data.text @@ -0,0 +1 @@ +todo go to class /isdone true \ No newline at end of file diff --git a/src/main/java/Juan.java b/src/main/java/Juan.java index b50e37de7..2204eb9d2 100644 --- a/src/main/java/Juan.java +++ b/src/main/java/Juan.java @@ -1,12 +1,18 @@ import CustomExceptions.*; // Import custom exception classes import TaskChildren.*; // Import task-related classes like ToDo, Deadline, and Event +import java.io.File; +import java.io.FileWriter; +import java.io.FileNotFoundException; +import java.io.IOException; import java.util.Scanner; // Import Scanner for user input public class Juan { // Constant for common error message to improve code readability and reusability private final static String porFavor = "Por Favor?\n"; + private final static String dataFilePath = "data.text"; + // Main entry point for the application public static void main(String[] args) { // Display initial line and welcome message @@ -14,6 +20,10 @@ public static void main(String[] args) { helloMessage(); lineMessage(); + // Add function to Read Data + readData(); + lineMessage(); + // Continue chatting as long as user doesn't exit boolean continueChatting = true; while (continueChatting) { @@ -21,11 +31,82 @@ public static void main(String[] args) { continueChatting = chatFeature(); } + // Add Function to Write Data + writeDate(); + lineMessage(); // Display goodbye message when the chat ends byeMessage(); lineMessage(); } + public static void readData() { + + File dataFile = new File(dataFilePath); + try { + Scanner scanner = new Scanner(dataFile); + while (scanner.hasNextLine()) { + String inputLine = scanner.nextLine(); + String[] lineSegments = inputLine.split(" /isdone "); + String line = lineSegments[0]; + boolean isDone = Boolean.parseBoolean(lineSegments[1]); + if (line.startsWith("todo ")) { + try { + new ToDo(line, false); // Create a new ToDo object + } catch (ToDoConstructorException e) { + // Handle custom ToDo exception + System.out.println("CORRUPTED: " + line); + return; + } + } + // Handle "deadline" command to create a new Deadline task + else if (line.startsWith("deadline ")) { + try { + new Deadline(line, false); // Create a new Deadline object + } catch (DeadlineConstructorException e) { + // Handle custom Deadline exception + System.out.println("CORRUPTED: " + line); + return; + } + } + // Handle "event" command to create a new Event task + else if (line.startsWith("event ")) { + try { + new Event(line, false); // Create a new Event object + } catch (EventConstructorException e) { + // Handle custom Event exception + System.out.println("CORRUPTED: " + line); + return; + } + } + else { + System.out.println("CORRUPTED: " + line); + return; + } + + if (isDone) { + Task.markLatestTask(); + } + } + System.out.println("Data File Read"); + } catch (FileNotFoundException e) { + System.out.println("Data File does not exist"); + } + + } + + public static void writeDate() { + try { + FileWriter writer = new FileWriter(dataFilePath); + for (int i = 0; i < Task.size(); i++) { + writer.write(Task.dataFileEntry(i)); + } + writer.close(); + System.out.println("Data File Written"); + } catch (IOException e) { + System.out.println("Error writing to file"); + } + } + // Handles user input and executes corresponding actions public static boolean chatFeature() { @@ -71,7 +152,7 @@ else if (line.startsWith("unmark ")) { // Handle "todo" command to create a new ToDo task else if (line.startsWith("todo ")) { try { - new ToDo(line); // Create a new ToDo object + new ToDo(line, true); // Create a new ToDo object } catch (ToDoConstructorException e) { // Handle custom ToDo exception System.out.println(porFavor + e.getMessage()); @@ -80,7 +161,7 @@ else if (line.startsWith("todo ")) { // Handle "deadline" command to create a new Deadline task else if (line.startsWith("deadline ")) { try { - new Deadline(line); // Create a new Deadline object + new Deadline(line, true); // Create a new Deadline object } catch (DeadlineConstructorException e) { // Handle custom Deadline exception System.out.println(porFavor + e.getMessage()); @@ -89,7 +170,7 @@ else if (line.startsWith("deadline ")) { // Handle "event" command to create a new Event task else if (line.startsWith("event ")) { try { - new Event(line); // Create a new Event object + new Event(line, true); // Create a new Event object } catch (EventConstructorException e) { // Handle custom Event exception System.out.println(porFavor + e.getMessage()); diff --git a/src/main/java/TaskChildren/Deadline.java b/src/main/java/TaskChildren/Deadline.java index 588299b55..392b7e37f 100644 --- a/src/main/java/TaskChildren/Deadline.java +++ b/src/main/java/TaskChildren/Deadline.java @@ -8,11 +8,12 @@ public class Deadline extends Task { // Variable to store the deadline date/time string private String deadlineString; + // Constructor for creating a Deadline task - public Deadline(String inputString) throws DeadlineConstructorException { + public Deadline(String inputString, boolean constructorMessage) throws DeadlineConstructorException { // Call the parent class (Task) constructor with the task description (before the "/by" keyword) super(inputString.replace("deadline ", "").split(" /by ")[0]); - + this.inputString = inputString; // Check if the "/by" keyword is missing or if the task description is empty if (!(inputString.contains(" /by ")) || this.taskString.isEmpty()) { throw new DeadlineConstructorException(inputString); // Throw custom exception if validation fails @@ -22,7 +23,9 @@ public Deadline(String inputString) throws DeadlineConstructorException { this.deadlineString = inputString.replace("deadline ", "").split(" /by ")[1]; // Display a confirmation message when a Deadline task is successfully created - constructorMessage(); + if (constructorMessage) { + constructorMessage(); + } } // Override the checkboxString method to include the "[D]" tag and the deadline information diff --git a/src/main/java/TaskChildren/Event.java b/src/main/java/TaskChildren/Event.java index eb647b413..b25ab0381 100644 --- a/src/main/java/TaskChildren/Event.java +++ b/src/main/java/TaskChildren/Event.java @@ -10,10 +10,12 @@ public class Event extends Task { private String toString; // Constructor for creating an Event task - public Event(String inputString) throws EventConstructorException { + public Event(String inputString, boolean constructorMessage) throws EventConstructorException { // Call the parent class (Task) constructor with the task description (before the "/from" keyword) super(inputString.replace("event ", "").split(" /from ")[0]); + this.inputString = inputString; + // Validate if both "/from" and "/to" keywords are present, and the task description is not empty if (!(inputString.contains(" /from ") & inputString.contains(" /to ")) || this.taskString.isEmpty()) { throw new EventConstructorException(inputString); // Throw custom exception if validation fails @@ -32,7 +34,9 @@ public Event(String inputString) throws EventConstructorException { this.toString = fromToStrings[1]; // Display a confirmation message when an Event task is successfully created - constructorMessage(); + if (constructorMessage) { + constructorMessage(); + } } // Override the checkboxString method to include the "[E]" tag, start time, and end time diff --git a/src/main/java/TaskChildren/Task.java b/src/main/java/TaskChildren/Task.java index b452f1dc0..c780f3739 100644 --- a/src/main/java/TaskChildren/Task.java +++ b/src/main/java/TaskChildren/Task.java @@ -6,6 +6,7 @@ public class Task { // Array to keep track of all tasks added private static Task[] tasks = new Task[100]; // Task array of size 100 to store tasks private static int taskCount = 0; // Counter to keep track of the number of tasks + public String inputString; // Object-specific variables public String taskString; // String to hold the task description @@ -24,6 +25,18 @@ public static void deleteLatestTask(){ taskCount--; // Decrement the task count } + public static void markLatestTask(){ + tasks[taskCount-1].isDone = true; + } + + public static int size() { + return taskCount; + } + + public static String dataFileEntry(int index) { + return (tasks[index].inputString + " /isdone " + tasks[index].isDone); + } + // Method to display a message when a task is successfully created public void constructorMessage(){ System.out.println("Muy Bien, work hard compadre!"); // Success message in Spanish diff --git a/src/main/java/TaskChildren/ToDo.java b/src/main/java/TaskChildren/ToDo.java index 8b751e0f6..358fe9cf5 100644 --- a/src/main/java/TaskChildren/ToDo.java +++ b/src/main/java/TaskChildren/ToDo.java @@ -5,18 +5,21 @@ // ToDo class, a child class of Task, represents a simple to-do task public class ToDo extends Task { + // Constructor for creating a ToDo task - public ToDo(String inputString) throws ToDoConstructorException { + public ToDo(String inputString, boolean constructorMessage) throws ToDoConstructorException { // Call the parent class (Task) constructor, removing the "todo" prefix from the input super(inputString.replace("todo ", "")); - + this.inputString = inputString; // If the task description is empty, throw a custom exception if (this.taskString.isEmpty()) { throw new ToDoConstructorException(inputString); // Handle invalid ToDo input } // Display a confirmation message when a ToDo task is successfully created - constructorMessage(); + if (constructorMessage) { + constructorMessage(); + } } // Override the checkboxString method to prefix "[T]" to indicate that the task is a ToDo From 2d5e67e5a40a86250c69b6e7f0fbbb1c5a679ff1 Mon Sep 17 00:00:00 2001 From: DarkDragoon2002 Date: Fri, 20 Sep 2024 15:42:03 +0800 Subject: [PATCH 15/31] Bugfix and Created JAR file --- data.text | 2 +- src/main/java/TaskChildren/Task.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/data.text b/data.text index 8933a5a89..5bc8aa305 100644 --- a/data.text +++ b/data.text @@ -1 +1 @@ -todo go to class /isdone true \ No newline at end of file +todo go to class /isdone false \ No newline at end of file diff --git a/src/main/java/TaskChildren/Task.java b/src/main/java/TaskChildren/Task.java index 474ac6e8e..4c8b63337 100644 --- a/src/main/java/TaskChildren/Task.java +++ b/src/main/java/TaskChildren/Task.java @@ -34,7 +34,7 @@ public static void markLatestTask(){ } public static int size() { - return taskCount; + return tasks.size(); } public static String dataFileEntry(int index) { @@ -77,7 +77,7 @@ public String checkboxString(){ // Static method to print all tasks in the list public static void printTasksList(){ - if (tasks.size() == 0){ + if (tasks.isEmpty()){ System.out.println("Por Favor? Nothing Here"); // Message when there are no tasks } else { System.out.println("Si compinche, your tasks:"); // Message when displaying tasks From c88fc8c3c1db11c664bc93eff212cbaf13527cd4 Mon Sep 17 00:00:00 2001 From: DarkDragoon2002 Date: Tue, 8 Oct 2024 21:33:38 +0800 Subject: [PATCH 16/31] Migrated UI to separate Class --- src/main/java/Juan.java | 101 +++++++++-------------- src/main/java/Parser.java | 2 + src/main/java/Storage.java | 2 + src/main/java/TaskChildren/TaskList.java | 4 + src/main/java/UI.java | 61 ++++++++++++++ 5 files changed, 107 insertions(+), 63 deletions(-) create mode 100644 src/main/java/Parser.java create mode 100644 src/main/java/Storage.java create mode 100644 src/main/java/TaskChildren/TaskList.java create mode 100644 src/main/java/UI.java diff --git a/src/main/java/Juan.java b/src/main/java/Juan.java index e03dad8a5..0fa0d1356 100644 --- a/src/main/java/Juan.java +++ b/src/main/java/Juan.java @@ -1,45 +1,50 @@ import CustomExceptions.*; // Import custom exception classes import TaskChildren.*; // Import task-related classes like ToDo, Deadline, and Event -import java.io.File; -import java.io.FileWriter; +import java.io.File; import java.io.FileNotFoundException; +import java.io.FileWriter; import java.io.IOException; -import java.util.Scanner; // Import Scanner for user input +import java.util.Scanner; + public class Juan { - // Constant for common error message to improve code readability and reusability - private final static String porFavor = "Por Favor?\n"; + private final static String dataFilePath = "data.text"; + private UI ui; + + // Constructor + public void Juan() { + + ui = new UI(); + } + + // Main running function + public void run() { - // Main entry point for the application - public static void main(String[] args) { // Display initial line and welcome message - lineMessage(); - helloMessage(); - lineMessage(); + ui.helloMessage(); // Add function to Read Data readData(); - lineMessage(); + ui.lineMessage(); // Continue chatting as long as user doesn't exit boolean continueChatting = true; while (continueChatting) { // Chat feature to handle user input - continueChatting = chatFeature(); + continueChatting = chatFeature(ui.readUserInput()); } // Add Function to Write Data writeDate(); - lineMessage(); + ui.lineMessage(); // Display goodbye message when the chat ends - byeMessage(); - lineMessage(); + ui.byeMessage(); } - public static void readData() { + public void readData() { File dataFile = new File(dataFilePath); try { @@ -94,7 +99,7 @@ else if (line.startsWith("event ")) { } - public static void writeDate() { + public void writeDate() { try { FileWriter writer = new FileWriter(dataFilePath); for (int i = 0; i < Task.size(); i++) { @@ -103,16 +108,14 @@ public static void writeDate() { writer.close(); System.out.println("Data File Written"); } catch (IOException e) { - System.out.println("Error writing to file"); + ui.porFavorMessage(e.getMessage()); } } // Handles user input and executes corresponding actions - public static boolean chatFeature() { + public boolean chatFeature(String line) { - Scanner scanner = new Scanner(System.in); // Initialize the scanner for reading user input - String line = scanner.nextLine(); // Read user input - lineMessage(); // Print separator line + ui.lineMessage(); // Print separator line // Handle "bye" command to end chat if (line.equals("bye")) { @@ -129,10 +132,10 @@ else if (line.startsWith("delete ")) { Task.deleteTask(taskIndex); // Mark the task as done } catch (NumberFormatException | IndexOutOfBoundsException e) { // Handle invalid index or format exceptions - System.out.println(porFavor + "DELETE EXCEPTION: INVALID TASK INDEX"); + ui.porFavorMessage("DELETE EXCEPTION: INVALID TASK INDEX"); } catch (NullPointerException e) { // Handle null task case - System.out.println(porFavor + "DELETE EXCEPTION: NULL TASK INDEX"); + ui.porFavorMessage("DELETE EXCEPTION: NULL TASK INDEX"); } } // Handle "mark" command to mark a task as completed @@ -142,10 +145,10 @@ else if (line.startsWith("mark ")) { Task.mark(taskIndex); // Mark the task as done } catch (NumberFormatException | IndexOutOfBoundsException e) { // Handle invalid index or format exceptions - System.out.println(porFavor + "MARK EXCEPTION: INVALID TASK INDEX"); + ui.porFavorMessage("MARK EXCEPTION: INVALID TASK INDEX"); } catch (NullPointerException e) { // Handle null task case - System.out.println(porFavor + "MARK EXCEPTION: NULL TASK INDEX"); + ui.porFavorMessage("MARK EXCEPTION: NULL TASK INDEX"); } } // Handle "unmark" command to unmark a task as completed @@ -155,10 +158,10 @@ else if (line.startsWith("unmark ")) { Task.unmark(taskIndex); // Unmark the task } catch (NumberFormatException | IndexOutOfBoundsException e) { // Handle invalid index or format exceptions - System.out.println(porFavor + "UNMARK EXCEPTION: INVALID TASK INDEX"); + ui.porFavorMessage("UNMARK EXCEPTION: INVALID TASK INDEX"); } catch (NullPointerException e) { // Handle null task case - System.out.println(porFavor + "UNMARK EXCEPTION: NULL TASK INDEX"); + ui.porFavorMessage("UNMARK EXCEPTION: NULL TASK INDEX"); } } @@ -168,7 +171,7 @@ else if (line.startsWith("todo ")) { new ToDo(line, true); // Create a new ToDo object } catch (ToDoConstructorException e) { // Handle custom ToDo exception - System.out.println(porFavor + e.getMessage()); + ui.porFavorMessage(e.getMessage()); } } // Handle "deadline" command to create a new Deadline task @@ -177,7 +180,7 @@ else if (line.startsWith("deadline ")) { new Deadline(line, true); // Create a new Deadline object } catch (DeadlineConstructorException e) { // Handle custom Deadline exception - System.out.println(porFavor + e.getMessage()); + ui.porFavorMessage(e.getMessage()); } } // Handle "event" command to create a new Event task @@ -186,48 +189,20 @@ else if (line.startsWith("event ")) { new Event(line, true); // Create a new Event object } catch (EventConstructorException e) { // Handle custom Event exception - System.out.println(porFavor + e.getMessage()); + ui.porFavorMessage(e.getMessage()); } } // Default case for unrecognized commands else { - System.out.println(porFavor + "UNRECOGNIZED REQUEST"); // Inform user about an unrecognized command + ui.porFavorMessage("UNRECOGNIZED REQUEST"); // Inform user about an unrecognized command } - lineMessage(); // Print separator line + ui.lineMessage(); // Print separator line return true; // Continue conversation } - // Utility function to print a separator line for clean output formatting - public static void lineMessage() { - String line = "____________________________________________________________\n"; - System.out.print(line); - } - - // Displays a welcome message when the program starts - public static void helloMessage() { - String greeting = - " ._-'-_ .\n" + - " . ' /_-_-_\\ ` .\n" + - " .' |-_-_-_-| `.\n" + - " ( `.-_-_-.' )\n" + - " !`. .'!\n" + - " ! ` . . ' !\n" + - " ! ! ! ! ! ! ! ! !\n" + - " / / \\ \\\n" + - " _-| \\___ ___/ /-_\n" + - " (_ )__\\_)\\(_/__( _)\n" + - " ))))\\X\\ ((((\n" + - " \\/ \\/ \n" + - "Hola Amigo, I am Juan Cervantes Salamanca from Michoacan \n" + - "Welcome to la familia \n" + - "How can we help you? \n"; - System.out.print(greeting); // Print the welcome message + public static void main(String[] args) { + new Juan().run(); } - // Displays a goodbye message when the program ends - public static void byeMessage() { - String bye = "Adios amigo, la familia will miss you\n"; - System.out.print(bye); // Print the goodbye message - } } diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java new file mode 100644 index 000000000..4d27fe15e --- /dev/null +++ b/src/main/java/Parser.java @@ -0,0 +1,2 @@ +public class Parser { +} diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java new file mode 100644 index 000000000..14d305913 --- /dev/null +++ b/src/main/java/Storage.java @@ -0,0 +1,2 @@ +public class Storage { +} diff --git a/src/main/java/TaskChildren/TaskList.java b/src/main/java/TaskChildren/TaskList.java new file mode 100644 index 000000000..b24edb74b --- /dev/null +++ b/src/main/java/TaskChildren/TaskList.java @@ -0,0 +1,4 @@ +package TaskChildren; + +public class TaskList { +} diff --git a/src/main/java/UI.java b/src/main/java/UI.java new file mode 100644 index 000000000..1ca1a861f --- /dev/null +++ b/src/main/java/UI.java @@ -0,0 +1,61 @@ +import java.util.Scanner; // Import Scanner for user input + +public class UI { + + // Constant for common error message to improve code readability and reusability + private final static String PORFAVOR = "Por Favor?\n"; + private final static String SEPARATOR = "____________________________________________________________\n"; + private final static String BYEMESSAGE = "Adios amigo, la familia will miss you\n"; + private final static String GREETINGMESSAGE = + " ._-'-_ .\n" + + " . ' /_-_-_\\ ` .\n" + + " .' |-_-_-_-| `.\n" + + " ( `.-_-_-.' )\n" + + " !`. .'!\n" + + " ! ` . . ' !\n" + + " ! ! ! ! ! ! ! ! !\n" + + " / / \\ \\\n" + + " _-| \\___ ___/ /-_\n" + + " (_ )__\\_)\\(_/__( _)\n" + + " ))))\\X\\ ((((\n" + + " \\/ \\/ \n" + + "Hola Amigo, I am Juan Cervantes Salamanca from Michoacan \n" + + "Welcome to la familia \n" + + "How can we help you? \n"; + + private Scanner scanner; + + public UI() { + scanner = new Scanner(System.in); // Initialize the scanner for reading user input + } + + public String readUserInput() { + return scanner.nextLine(); // Read user input + } + + // Utility function to print a separator line for clean output formatting + public void lineMessage() { + System.out.print(SEPARATOR); + } + + // Displays a Message with por favor message + public void porFavorMessage(String message) { + System.out.println(PORFAVOR + message); + } + + + // Displays a welcome message when the program starts + public void helloMessage() { + + System.out.print(SEPARATOR); + System.out.print(GREETINGMESSAGE); // Print the welcome message + System.out.print(SEPARATOR); + } + + // Displays a goodbye message when the program ends + public void byeMessage() { + System.out.print(BYEMESSAGE); // Print the goodbye message + System.out.print(SEPARATOR); + } + +} From e2f954e88646678f76fa1f8027d4b920fa87d0d2 Mon Sep 17 00:00:00 2001 From: DarkDragoon2002 Date: Wed, 9 Oct 2024 10:30:24 +0800 Subject: [PATCH 17/31] Migrate TaskList Functions from Task --- data.text | 2 +- src/main/java/Juan.java | 107 ++++-------------- src/main/java/Storage.java | 90 +++++++++++++++ src/main/java/TaskChildren/Task.java | 90 --------------- src/main/java/TaskChildren/TaskList.java | 4 - src/main/java/UI.java | 6 + .../DeadlineConstructorException.java | 7 +- .../EventConstructorException.java | 6 +- .../ToDoConstructorException.java | 6 +- .../Deadline.java | 8 +- .../{TaskChildren => taskpackage}/Event.java | 8 +- src/main/java/taskpackage/Task.java | 41 +++++++ src/main/java/taskpackage/TaskList.java | 66 +++++++++++ .../{TaskChildren => taskpackage}/ToDo.java | 8 +- text-ui-test/EXPECTED.TXT | 6 +- 15 files changed, 244 insertions(+), 211 deletions(-) delete mode 100644 src/main/java/TaskChildren/Task.java delete mode 100644 src/main/java/TaskChildren/TaskList.java rename src/main/java/{CustomExceptions => customexceptions}/DeadlineConstructorException.java (84%) rename src/main/java/{CustomExceptions => customexceptions}/EventConstructorException.java (87%) rename src/main/java/{CustomExceptions => customexceptions}/ToDoConstructorException.java (80%) rename src/main/java/{TaskChildren => taskpackage}/Deadline.java (85%) rename src/main/java/{TaskChildren => taskpackage}/Event.java (88%) create mode 100644 src/main/java/taskpackage/Task.java create mode 100644 src/main/java/taskpackage/TaskList.java rename src/main/java/{TaskChildren => taskpackage}/ToDo.java (76%) diff --git a/data.text b/data.text index 5bc8aa305..b32fbbe12 100644 --- a/data.text +++ b/data.text @@ -1 +1 @@ -todo go to class /isdone false \ No newline at end of file +todo go to class /isdone truetodo not be late for class /isdone false \ No newline at end of file diff --git a/src/main/java/Juan.java b/src/main/java/Juan.java index 0fa0d1356..cf2427fa0 100644 --- a/src/main/java/Juan.java +++ b/src/main/java/Juan.java @@ -1,11 +1,5 @@ -import CustomExceptions.*; // Import custom exception classes -import TaskChildren.*; // Import task-related classes like ToDo, Deadline, and Event - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileWriter; -import java.io.IOException; -import java.util.Scanner; +import customexceptions.*; // Import custom exception classes +import taskpackage.*; // Import task-related classes like ToDo, Deadline, and Event public class Juan { @@ -13,11 +7,15 @@ public class Juan { private final static String dataFilePath = "data.text"; private UI ui; + private Storage storage; + private TaskList tasks; // Constructor - public void Juan() { + public Juan(String dataFilePath) { ui = new UI(); + storage = new Storage(dataFilePath, ui); + tasks = storage.readData(); } // Main running function @@ -26,10 +24,6 @@ public void run() { // Display initial line and welcome message ui.helloMessage(); - // Add function to Read Data - readData(); - ui.lineMessage(); - // Continue chatting as long as user doesn't exit boolean continueChatting = true; while (continueChatting) { @@ -38,79 +32,13 @@ public void run() { } // Add Function to Write Data - writeDate(); + storage.writeDate(tasks); ui.lineMessage(); // Display goodbye message when the chat ends ui.byeMessage(); } - public void readData() { - - File dataFile = new File(dataFilePath); - try { - Scanner scanner = new Scanner(dataFile); - while (scanner.hasNextLine()) { - String inputLine = scanner.nextLine(); - String[] lineSegments = inputLine.split(" /isdone "); - String line = lineSegments[0]; - boolean isDone = Boolean.parseBoolean(lineSegments[1]); - if (line.startsWith("todo ")) { - try { - new ToDo(line, false); // Create a new ToDo object - } catch (ToDoConstructorException e) { - // Handle custom ToDo exception - System.out.println("CORRUPTED: " + line); - return; - } - } - // Handle "deadline" command to create a new Deadline task - else if (line.startsWith("deadline ")) { - try { - new Deadline(line, false); // Create a new Deadline object - } catch (DeadlineConstructorException e) { - // Handle custom Deadline exception - System.out.println("CORRUPTED: " + line); - return; - } - } - // Handle "event" command to create a new Event task - else if (line.startsWith("event ")) { - try { - new Event(line, false); // Create a new Event object - } catch (EventConstructorException e) { - // Handle custom Event exception - System.out.println("CORRUPTED: " + line); - return; - } - } - else { - System.out.println("CORRUPTED: " + line); - return; - } - - if (isDone) { - Task.markLatestTask(); - } - } - System.out.println("Data File Read"); - } catch (FileNotFoundException e) { - System.out.println("Data File does not exist"); - } - - } - public void writeDate() { - try { - FileWriter writer = new FileWriter(dataFilePath); - for (int i = 0; i < Task.size(); i++) { - writer.write(Task.dataFileEntry(i)); - } - writer.close(); - System.out.println("Data File Written"); - } catch (IOException e) { - ui.porFavorMessage(e.getMessage()); - } - } // Handles user input and executes corresponding actions public boolean chatFeature(String line) { @@ -123,13 +51,13 @@ public boolean chatFeature(String line) { } // Handle "list" command to display the list of tasks else if (line.equals("list")) { - Task.printTasksList(); // Print task list from Task class + tasks.printTasksList(); // Print task list from Task class } // Handle "delete" command else if (line.startsWith("delete ")) { try { int taskIndex = Integer.parseInt(line.replace("delete ", "")) - 1; // Parse the task index - Task.deleteTask(taskIndex); // Mark the task as done + tasks.deleteTask(taskIndex); // Mark the task as done } catch (NumberFormatException | IndexOutOfBoundsException e) { // Handle invalid index or format exceptions ui.porFavorMessage("DELETE EXCEPTION: INVALID TASK INDEX"); @@ -142,7 +70,7 @@ else if (line.startsWith("delete ")) { else if (line.startsWith("mark ")) { try { int taskIndex = Integer.parseInt(line.replace("mark ", "")) - 1; // Parse the task index - Task.mark(taskIndex); // Mark the task as done + tasks.mark(taskIndex); // Mark the task as done } catch (NumberFormatException | IndexOutOfBoundsException e) { // Handle invalid index or format exceptions ui.porFavorMessage("MARK EXCEPTION: INVALID TASK INDEX"); @@ -155,7 +83,7 @@ else if (line.startsWith("mark ")) { else if (line.startsWith("unmark ")) { try { int taskIndex = Integer.parseInt(line.replace("unmark ", "")) - 1; // Parse the task index - Task.unmark(taskIndex); // Unmark the task + tasks.unmark(taskIndex); // Unmark the task } catch (NumberFormatException | IndexOutOfBoundsException e) { // Handle invalid index or format exceptions ui.porFavorMessage("UNMARK EXCEPTION: INVALID TASK INDEX"); @@ -168,28 +96,31 @@ else if (line.startsWith("unmark ")) { // Handle "todo" command to create a new ToDo task else if (line.startsWith("todo ")) { try { - new ToDo(line, true); // Create a new ToDo object + new ToDo(line, tasks, true); // Create a new ToDo object } catch (ToDoConstructorException e) { // Handle custom ToDo exception ui.porFavorMessage(e.getMessage()); + tasks.deleteLatestTask(); } } // Handle "deadline" command to create a new Deadline task else if (line.startsWith("deadline ")) { try { - new Deadline(line, true); // Create a new Deadline object + new Deadline(line, tasks, true); // Create a new Deadline object } catch (DeadlineConstructorException e) { // Handle custom Deadline exception ui.porFavorMessage(e.getMessage()); + tasks.deleteLatestTask(); } } // Handle "event" command to create a new Event task else if (line.startsWith("event ")) { try { - new Event(line, true); // Create a new Event object + new Event(line, tasks, true); // Create a new Event object } catch (EventConstructorException e) { // Handle custom Event exception ui.porFavorMessage(e.getMessage()); + tasks.deleteLatestTask(); } } // Default case for unrecognized commands @@ -202,7 +133,7 @@ else if (line.startsWith("event ")) { } public static void main(String[] args) { - new Juan().run(); + new Juan(dataFilePath).run(); } } diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index 14d305913..27cd74f3f 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -1,2 +1,92 @@ +import customexceptions.DeadlineConstructorException; +import customexceptions.EventConstructorException; +import customexceptions.ToDoConstructorException; +import taskpackage.*; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + public class Storage { + + private String dataFilePath; + private UI ui; + + public Storage(String dataFilePath, UI ui) { + this.dataFilePath = dataFilePath; + this.ui = ui; + } + + public TaskList readData() { + + TaskList tempTaskList = new TaskList(); + + File dataFile = new File(dataFilePath); + try { + Scanner scanner = new Scanner(dataFile); + while (scanner.hasNextLine()) { + String inputLine = scanner.nextLine(); + String[] lineSegments = inputLine.split(" /isdone "); + String line = lineSegments[0]; + boolean isDone = Boolean.parseBoolean(lineSegments[1]); + if (line.startsWith("todo ")) { + try { + new ToDo(line, tempTaskList, false); // Create a new ToDo object + } catch (ToDoConstructorException e) { + // Handle custom ToDo exception + ui.printMessage("CORRUPTED: " + line); + tempTaskList.deleteLatestTask(); + } + } + // Handle "deadline" command to create a new Deadline task + else if (line.startsWith("deadline ")) { + try { + new Deadline(line, tempTaskList, false); // Create a new Deadline object + } catch (DeadlineConstructorException e) { + // Handle custom Deadline exception + ui.printMessage("CORRUPTED: " + line); + tempTaskList.deleteLatestTask(); + } + } + // Handle "event" command to create a new Event task + else if (line.startsWith("event ")) { + try { + new Event(line, tempTaskList, false); // Create a new Event object + } catch (EventConstructorException e) { + // Handle custom Event exception + ui.printMessage("CORRUPTED: " + line); + tempTaskList.deleteLatestTask(); + } + } + else { + ui.printMessage("CORRUPTED: " + line); + } + + if (isDone) { + tempTaskList.markLatestTask(); + } + } + ui.printMessage("Data File Read"); + } catch (FileNotFoundException e) { + ui.printMessage("Data File does not exist"); + return null; + } + + return tempTaskList; + } + + public void writeDate(TaskList taskList) { + try { + FileWriter writer = new FileWriter(dataFilePath); + for (int i = 0; i < taskList.size(); i++) { + writer.write(taskList.dataFileEntry(i)); + } + writer.close(); + ui.printMessage("Data File Written"); + } catch (IOException e) { + ui.porFavorMessage(e.getMessage()); + } + } } diff --git a/src/main/java/TaskChildren/Task.java b/src/main/java/TaskChildren/Task.java deleted file mode 100644 index 4c8b63337..000000000 --- a/src/main/java/TaskChildren/Task.java +++ /dev/null @@ -1,90 +0,0 @@ -package TaskChildren; // Package for Task-related classes -import java.util.ArrayList; - -// Parent class Task which serves as a base for ToDo, Deadline, and Event tasks -public class Task { - - // Array to keep track of all tasks added - public String inputString; - private static ArrayList tasks = new ArrayList<>(); - - // Object-specific variables - public String taskString; // String to hold the task description - public boolean isDone = false; // Boolean to track if the task is marked as done - - // Constructor Function: initializes a Task object and adds it to the tasks array - public Task(String inputString){ - this.taskString = inputString; // Set the task description - tasks.add(this); // Add the current task to the array - } - - public static void deleteTask(int taskIndex){ - String taskString = tasks.get(taskIndex).checkboxString(); - tasks.remove(taskIndex); - System.out.println("Ay Caramba, Task deleted: " + taskString); - } - - // Static method to delete the latest task in case of errors - public static void deleteLatestTask(){ - tasks.remove(tasks.size() - 1); // Remove the latest task from the array - } - - public static void markLatestTask(){ - tasks.get(tasks.size() - 1).isDone = true; - } - - public static int size() { - return tasks.size(); - } - - public static String dataFileEntry(int index) { - return (tasks.get(index).inputString + " /isdone " + tasks.get(index).isDone); - } - - // Method to display a message when a task is successfully created - public void constructorMessage(){ - System.out.println("Muy Bien, work hard compadre!"); // Success message in Spanish - System.out.println("I've Added the Task:"); - System.out.println(checkboxString()); // Display the task in checkbox format - System.out.println("You've got " + tasks.size() + " tasks, better start working!"); // Display the current task count - } - - // Static method to mark a task as done by index - public static void mark(int taskIndex){ - tasks.get(taskIndex).isDone = true; // Mark the task as done - System.out.println("Fantastica!!!! I marked it:"); // Success message in Spanish - System.out.println(tasks.get(taskIndex).checkboxString()); // Display the updated task - } - - // Static method to unmark a task as undone by index - public static void unmark(int taskIndex){ - tasks.get(taskIndex).isDone = false; // Unmark the task as not done - System.out.println("Ay Caramba, I unmarked it:"); // Message indicating task was unmarked - System.out.println(tasks.get(taskIndex).checkboxString()); // Display the updated task - } - - // Method to create and return a string with a checkbox (marked or unmarked) for the task - public String checkboxString(){ - String returnString = "["; // Start of the checkbox string - if (this.isDone){ - returnString += "X"; // Mark the checkbox as done if the task is completed - } else { - returnString += " "; // Leave the checkbox empty if the task is not completed - } - returnString += "] " + this.taskString; // Append the task description - return returnString; // Return the formatted string - } - - // Static method to print all tasks in the list - public static void printTasksList(){ - if (tasks.isEmpty()){ - System.out.println("Por Favor? Nothing Here"); // Message when there are no tasks - } else { - System.out.println("Si compinche, your tasks:"); // Message when displaying tasks - for (int i = 0; i < tasks.size(); i++){ - // Print each task with its index and checkbox format - System.out.println((i+1) + "." + tasks.get(i).checkboxString()); - } - } - } -} diff --git a/src/main/java/TaskChildren/TaskList.java b/src/main/java/TaskChildren/TaskList.java deleted file mode 100644 index b24edb74b..000000000 --- a/src/main/java/TaskChildren/TaskList.java +++ /dev/null @@ -1,4 +0,0 @@ -package TaskChildren; - -public class TaskList { -} diff --git a/src/main/java/UI.java b/src/main/java/UI.java index 1ca1a861f..18b105ba5 100644 --- a/src/main/java/UI.java +++ b/src/main/java/UI.java @@ -29,10 +29,16 @@ public UI() { scanner = new Scanner(System.in); // Initialize the scanner for reading user input } + // Function to read user input public String readUserInput() { return scanner.nextLine(); // Read user input } + // Function to print out any messages + public void printMessage(String message) { + System.out.println(message); + } + // Utility function to print a separator line for clean output formatting public void lineMessage() { System.out.print(SEPARATOR); diff --git a/src/main/java/CustomExceptions/DeadlineConstructorException.java b/src/main/java/customexceptions/DeadlineConstructorException.java similarity index 84% rename from src/main/java/CustomExceptions/DeadlineConstructorException.java rename to src/main/java/customexceptions/DeadlineConstructorException.java index e921ed780..34fe91d9b 100644 --- a/src/main/java/CustomExceptions/DeadlineConstructorException.java +++ b/src/main/java/customexceptions/DeadlineConstructorException.java @@ -1,5 +1,5 @@ -package CustomExceptions; // Package for custom exceptions -import TaskChildren.Task; // Import Task class to manage task deletion +package customexceptions; // Package for custom exceptions +import taskpackage.Task; // Import Task class to manage task deletion // Custom exception class for handling errors in Deadline task construction public class DeadlineConstructorException extends Exception { @@ -8,9 +8,6 @@ public class DeadlineConstructorException extends Exception { public DeadlineConstructorException(String message) { // Call the superclass (Exception) constructor with a detailed error message super("DEADLINE CONSTRUCTOR EXCEPTION: " + errorMessage(message)); - - // If an error occurs, the latest task added is deleted to prevent invalid tasks - Task.deleteLatestTask(); } // Private helper method to interpret the error message diff --git a/src/main/java/CustomExceptions/EventConstructorException.java b/src/main/java/customexceptions/EventConstructorException.java similarity index 87% rename from src/main/java/CustomExceptions/EventConstructorException.java rename to src/main/java/customexceptions/EventConstructorException.java index d14da61cd..c28106652 100644 --- a/src/main/java/CustomExceptions/EventConstructorException.java +++ b/src/main/java/customexceptions/EventConstructorException.java @@ -1,5 +1,5 @@ -package CustomExceptions; // Package for custom exceptions -import TaskChildren.Task; // Import Task class to manage task deletion +package customexceptions; // Package for custom exceptions +import taskpackage.Task; // Import Task class to manage task deletion // Custom exception class for handling errors in Event task construction public class EventConstructorException extends Exception { @@ -9,8 +9,6 @@ public EventConstructorException(String message) { // Call the superclass (Exception) constructor with a detailed error message super("EVENT CONSTRUCTOR EXCEPTION: " + errorMessage(message)); - // If an error occurs, the latest task added is deleted to prevent invalid tasks - Task.deleteLatestTask(); } // Private helper method to interpret the error message diff --git a/src/main/java/CustomExceptions/ToDoConstructorException.java b/src/main/java/customexceptions/ToDoConstructorException.java similarity index 80% rename from src/main/java/CustomExceptions/ToDoConstructorException.java rename to src/main/java/customexceptions/ToDoConstructorException.java index 7afc07ba6..de6858b50 100644 --- a/src/main/java/CustomExceptions/ToDoConstructorException.java +++ b/src/main/java/customexceptions/ToDoConstructorException.java @@ -1,5 +1,5 @@ -package CustomExceptions; // Package for custom exceptions -import TaskChildren.Task; // Import Task class to manage task deletion +package customexceptions; // Package for custom exceptions +import taskpackage.Task; // Import Task class to manage task deletion // Custom exception class for handling errors in ToDo task construction public class ToDoConstructorException extends Exception { @@ -9,8 +9,6 @@ public ToDoConstructorException(String message) { // Call the superclass (Exception) constructor with a detailed error message super("TODO CONSTRUCTOR EXCEPTION: " + errorMessage(message)); - // If an error occurs, the latest task added is deleted to prevent invalid tasks - Task.deleteLatestTask(); } // Private helper method to interpret the error message diff --git a/src/main/java/TaskChildren/Deadline.java b/src/main/java/taskpackage/Deadline.java similarity index 85% rename from src/main/java/TaskChildren/Deadline.java rename to src/main/java/taskpackage/Deadline.java index 392b7e37f..54945231b 100644 --- a/src/main/java/TaskChildren/Deadline.java +++ b/src/main/java/taskpackage/Deadline.java @@ -1,6 +1,6 @@ -package TaskChildren; // Package for Task-related classes +package taskpackage; // Package for Task-related classes -import CustomExceptions.DeadlineConstructorException; // Import custom exception for Deadline tasks +import customexceptions.DeadlineConstructorException; // Import custom exception for Deadline tasks // Deadline class, a child class of Task, represents a task with a specific deadline public class Deadline extends Task { @@ -10,9 +10,9 @@ public class Deadline extends Task { // Constructor for creating a Deadline task - public Deadline(String inputString, boolean constructorMessage) throws DeadlineConstructorException { + public Deadline(String inputString, TaskList tasks, boolean constructorMessage) throws DeadlineConstructorException { // Call the parent class (Task) constructor with the task description (before the "/by" keyword) - super(inputString.replace("deadline ", "").split(" /by ")[0]); + super(inputString.replace("deadline ", "").split(" /by ")[0], tasks); this.inputString = inputString; // Check if the "/by" keyword is missing or if the task description is empty if (!(inputString.contains(" /by ")) || this.taskString.isEmpty()) { diff --git a/src/main/java/TaskChildren/Event.java b/src/main/java/taskpackage/Event.java similarity index 88% rename from src/main/java/TaskChildren/Event.java rename to src/main/java/taskpackage/Event.java index b25ab0381..6b9fd4e4c 100644 --- a/src/main/java/TaskChildren/Event.java +++ b/src/main/java/taskpackage/Event.java @@ -1,6 +1,6 @@ -package TaskChildren; // Package for Task-related classes +package taskpackage; // Package for Task-related classes -import CustomExceptions.EventConstructorException; // Import custom exception for Event tasks +import customexceptions.EventConstructorException; // Import custom exception for Event tasks // Event class, a child class of Task, represents a task with a specific start and end time public class Event extends Task { @@ -10,9 +10,9 @@ public class Event extends Task { private String toString; // Constructor for creating an Event task - public Event(String inputString, boolean constructorMessage) throws EventConstructorException { + public Event(String inputString, TaskList tasks, boolean constructorMessage) throws EventConstructorException { // Call the parent class (Task) constructor with the task description (before the "/from" keyword) - super(inputString.replace("event ", "").split(" /from ")[0]); + super(inputString.replace("event ", "").split(" /from ")[0], tasks); this.inputString = inputString; diff --git a/src/main/java/taskpackage/Task.java b/src/main/java/taskpackage/Task.java new file mode 100644 index 000000000..ab5f58cf2 --- /dev/null +++ b/src/main/java/taskpackage/Task.java @@ -0,0 +1,41 @@ +package taskpackage; // Package for Task-related classes +import java.util.ArrayList; + +// Parent class Task which serves as a base for ToDo, Deadline, and Event tasks +public class Task { + + // Array to keep track of all tasks added + public String inputString; + + + // Object-specific variables + public String taskString; // String to hold the task description + public boolean isDone = false; // Boolean to track if the task is marked as done + + // Constructor Function: initializes a Task object and adds it to the tasks array + public Task(String inputString, TaskList tasks){ + this.taskString = inputString; // Set the task description + tasks.addTask(this); // Add the current task to the array + } + + // Method to display a message when a task is successfully created + public void constructorMessage(){ + System.out.println("Muy Bien, work hard compadre!"); // Success message in Spanish + System.out.println("I've Added the Task:"); + System.out.println(checkboxString()); // Display the task in checkbox format + } + + // Method to create and return a string with a checkbox (marked or unmarked) for the task + public String checkboxString(){ + String returnString = "["; // Start of the checkbox string + if (this.isDone){ + returnString += "X"; // Mark the checkbox as done if the task is completed + } else { + returnString += " "; // Leave the checkbox empty if the task is not completed + } + returnString += "] " + this.taskString; // Append the task description + return returnString; // Return the formatted string + } + + +} diff --git a/src/main/java/taskpackage/TaskList.java b/src/main/java/taskpackage/TaskList.java new file mode 100644 index 000000000..27dd8aeb3 --- /dev/null +++ b/src/main/java/taskpackage/TaskList.java @@ -0,0 +1,66 @@ +package taskpackage; + +import java.util.ArrayList; + +public class TaskList { + private ArrayList tasks; + + public TaskList() { + this.tasks = new ArrayList<>(); + } + + public void addTask(Task task) { + this.tasks.add(task); + } + + public void deleteTask(int taskIndex){ + String taskString = this.tasks.get(taskIndex).checkboxString(); + this.tasks.remove(taskIndex); + System.out.println("Ay Caramba, Task deleted: " + taskString); + } + + // Static method to delete the latest task in case of errors + public void deleteLatestTask(){ + this.tasks.remove(tasks.size() - 1); // Remove the latest task from the array + } + + public void markLatestTask(){ + this.tasks.get(tasks.size() - 1).isDone = true; + } + + public int size() { + return this.tasks.size(); + } + + public String dataFileEntry(int index) { + return (this.tasks.get(index).inputString + " /isdone " + this.tasks.get(index).isDone); + } + + // Static method to mark a task as done by index + public void mark(int taskIndex){ + tasks.get(taskIndex).isDone = true; // Mark the task as done + System.out.println("Fantastica!!!! I marked it:"); // Success message in Spanish + System.out.println(tasks.get(taskIndex).checkboxString()); // Display the updated task + } + + // Static method to unmark a task as undone by index + public void unmark(int taskIndex){ + tasks.get(taskIndex).isDone = false; // Unmark the task as not done + System.out.println("Ay Caramba, I unmarked it:"); // Message indicating task was unmarked + System.out.println(tasks.get(taskIndex).checkboxString()); // Display the updated task + } + + // Static method to print all tasks in the list + public void printTasksList(){ + if (tasks.isEmpty()){ + System.out.println("Por Favor? Nothing Here"); // Message when there are no tasks + } else { + System.out.println("Si compinche, your tasks:"); // Message when displaying tasks + for (int i = 0; i < tasks.size(); i++){ + // Print each task with its index and checkbox format + System.out.println((i+1) + "." + tasks.get(i).checkboxString()); + } + } + } + +} diff --git a/src/main/java/TaskChildren/ToDo.java b/src/main/java/taskpackage/ToDo.java similarity index 76% rename from src/main/java/TaskChildren/ToDo.java rename to src/main/java/taskpackage/ToDo.java index 358fe9cf5..e36693957 100644 --- a/src/main/java/TaskChildren/ToDo.java +++ b/src/main/java/taskpackage/ToDo.java @@ -1,15 +1,15 @@ -package TaskChildren; // Package for Task-related classes +package taskpackage; // Package for Task-related classes -import CustomExceptions.ToDoConstructorException; // Import custom exception for ToDo tasks +import customexceptions.ToDoConstructorException; // Import custom exception for ToDo tasks // ToDo class, a child class of Task, represents a simple to-do task public class ToDo extends Task { // Constructor for creating a ToDo task - public ToDo(String inputString, boolean constructorMessage) throws ToDoConstructorException { + public ToDo(String inputString, TaskList tasks, boolean constructorMessage) throws ToDoConstructorException { // Call the parent class (Task) constructor, removing the "todo" prefix from the input - super(inputString.replace("todo ", "")); + super(inputString.replace("todo ", ""), tasks); this.inputString = inputString; // If the task description is empty, throw a custom exception if (this.taskString.isEmpty()) { diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 9366ad85f..401936b20 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -18,21 +18,21 @@ ____________________________________________________________ event La Familia Meeting /from 5pm /to 6pm ____________________________________________________________ Muy Bien, work hard compadre! -I've Added the TaskChildren.Task: +I've Added the taskpackage.Task: [E][ ] La Familia Meeting (from: 5pm to: 6pm) You've got 1 tasks, better start working! ____________________________________________________________ deadline Fry the Pollo with the Hermanos /by 5th July ____________________________________________________________ Muy Bien, work hard compadre! -I've Added the TaskChildren.Task: +I've Added the taskpackage.Task: [D][ ] Fry the Pollo with the Hermanos (by: 5th July) You've got 2 tasks, better start working! ____________________________________________________________ todo eat the pollo ____________________________________________________________ Muy Bien, work hard compadre! -I've Added the TaskChildren.Task: +I've Added the taskpackage.Task: [T][ ] eat the pollo You've got 3 tasks, better start working! ____________________________________________________________ From 1e844eb2cc1ed940ed3bcb6527583ca167762081 Mon Sep 17 00:00:00 2001 From: DarkDragoon2002 Date: Wed, 9 Oct 2024 11:38:16 +0800 Subject: [PATCH 18/31] Migrated Parser functions from Juan --- data.text | 4 +- src/main/java/Juan.java | 108 +++-------------------- src/main/java/Parser.java | 110 ++++++++++++++++++++++++ src/main/java/taskpackage/TaskList.java | 2 +- 4 files changed, 125 insertions(+), 99 deletions(-) diff --git a/data.text b/data.text index b32fbbe12..d7e531728 100644 --- a/data.text +++ b/data.text @@ -1 +1,3 @@ -todo go to class /isdone truetodo not be late for class /isdone false \ No newline at end of file +todo go to class /isdone true +todo say hi /isdone false +todo leave class /isdone false diff --git a/src/main/java/Juan.java b/src/main/java/Juan.java index cf2427fa0..65996219b 100644 --- a/src/main/java/Juan.java +++ b/src/main/java/Juan.java @@ -1,6 +1,8 @@ import customexceptions.*; // Import custom exception classes import taskpackage.*; // Import task-related classes like ToDo, Deadline, and Event +import java.io.IOException; + public class Juan { @@ -9,13 +11,19 @@ public class Juan { private UI ui; private Storage storage; private TaskList tasks; + private Parser parser; // Constructor public Juan(String dataFilePath) { ui = new UI(); storage = new Storage(dataFilePath, ui); - tasks = storage.readData(); + try { + tasks = storage.readData(); + } catch (Exception e) { + ui.porFavorMessage(e.getMessage()); + } + parser = new Parser(ui, tasks); } // Main running function @@ -28,110 +36,16 @@ public void run() { boolean continueChatting = true; while (continueChatting) { // Chat feature to handle user input - continueChatting = chatFeature(ui.readUserInput()); + continueChatting = parser.chatFeature(ui.readUserInput()); } // Add Function to Write Data - storage.writeDate(tasks); + storage.writeDate(parser.getTasks()); ui.lineMessage(); // Display goodbye message when the chat ends ui.byeMessage(); } - - - // Handles user input and executes corresponding actions - public boolean chatFeature(String line) { - - ui.lineMessage(); // Print separator line - - // Handle "bye" command to end chat - if (line.equals("bye")) { - return false; // End the conversation - } - // Handle "list" command to display the list of tasks - else if (line.equals("list")) { - tasks.printTasksList(); // Print task list from Task class - } - // Handle "delete" command - else if (line.startsWith("delete ")) { - try { - int taskIndex = Integer.parseInt(line.replace("delete ", "")) - 1; // Parse the task index - tasks.deleteTask(taskIndex); // Mark the task as done - } catch (NumberFormatException | IndexOutOfBoundsException e) { - // Handle invalid index or format exceptions - ui.porFavorMessage("DELETE EXCEPTION: INVALID TASK INDEX"); - } catch (NullPointerException e) { - // Handle null task case - ui.porFavorMessage("DELETE EXCEPTION: NULL TASK INDEX"); - } - } - // Handle "mark" command to mark a task as completed - else if (line.startsWith("mark ")) { - try { - int taskIndex = Integer.parseInt(line.replace("mark ", "")) - 1; // Parse the task index - tasks.mark(taskIndex); // Mark the task as done - } catch (NumberFormatException | IndexOutOfBoundsException e) { - // Handle invalid index or format exceptions - ui.porFavorMessage("MARK EXCEPTION: INVALID TASK INDEX"); - } catch (NullPointerException e) { - // Handle null task case - ui.porFavorMessage("MARK EXCEPTION: NULL TASK INDEX"); - } - } - // Handle "unmark" command to unmark a task as completed - else if (line.startsWith("unmark ")) { - try { - int taskIndex = Integer.parseInt(line.replace("unmark ", "")) - 1; // Parse the task index - tasks.unmark(taskIndex); // Unmark the task - } catch (NumberFormatException | IndexOutOfBoundsException e) { - // Handle invalid index or format exceptions - ui.porFavorMessage("UNMARK EXCEPTION: INVALID TASK INDEX"); - } catch (NullPointerException e) { - // Handle null task case - ui.porFavorMessage("UNMARK EXCEPTION: NULL TASK INDEX"); - } - - } - // Handle "todo" command to create a new ToDo task - else if (line.startsWith("todo ")) { - try { - new ToDo(line, tasks, true); // Create a new ToDo object - } catch (ToDoConstructorException e) { - // Handle custom ToDo exception - ui.porFavorMessage(e.getMessage()); - tasks.deleteLatestTask(); - } - } - // Handle "deadline" command to create a new Deadline task - else if (line.startsWith("deadline ")) { - try { - new Deadline(line, tasks, true); // Create a new Deadline object - } catch (DeadlineConstructorException e) { - // Handle custom Deadline exception - ui.porFavorMessage(e.getMessage()); - tasks.deleteLatestTask(); - } - } - // Handle "event" command to create a new Event task - else if (line.startsWith("event ")) { - try { - new Event(line, tasks, true); // Create a new Event object - } catch (EventConstructorException e) { - // Handle custom Event exception - ui.porFavorMessage(e.getMessage()); - tasks.deleteLatestTask(); - } - } - // Default case for unrecognized commands - else { - ui.porFavorMessage("UNRECOGNIZED REQUEST"); // Inform user about an unrecognized command - } - - ui.lineMessage(); // Print separator line - return true; // Continue conversation - } - public static void main(String[] args) { new Juan(dataFilePath).run(); } diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index 4d27fe15e..2c98523eb 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -1,2 +1,112 @@ +import customexceptions.DeadlineConstructorException; +import customexceptions.EventConstructorException; +import customexceptions.ToDoConstructorException; +import taskpackage.Deadline; +import taskpackage.Event; +import taskpackage.TaskList; +import taskpackage.ToDo; + public class Parser { + + private UI ui; + private TaskList tasks; + + public Parser(UI ui, TaskList tasks) { + this.ui = ui; + this.tasks = tasks; + } + + public TaskList getTasks() { return tasks; } + + // Handles user input and executes corresponding actions + public boolean chatFeature(String line) { + + ui.lineMessage(); // Print separator line + + // Handle "bye" command to end chat + if (line.equals("bye")) { + return false; // End the conversation + } + // Handle "list" command to display the list of tasks + else if (line.equals("list")) { + tasks.printTasksList(); // Print task list from Task class + } + // Handle "delete" command + else if (line.startsWith("delete ")) { + try { + int taskIndex = Integer.parseInt(line.replace("delete ", "")) - 1; // Parse the task index + tasks.deleteTask(taskIndex); // Mark the task as done + } catch (NumberFormatException | IndexOutOfBoundsException e) { + // Handle invalid index or format exceptions + ui.porFavorMessage("DELETE EXCEPTION: INVALID TASK INDEX"); + } catch (NullPointerException e) { + // Handle null task case + ui.porFavorMessage("DELETE EXCEPTION: NULL TASK INDEX"); + } + } + // Handle "mark" command to mark a task as completed + else if (line.startsWith("mark ")) { + try { + int taskIndex = Integer.parseInt(line.replace("mark ", "")) - 1; // Parse the task index + tasks.mark(taskIndex); // Mark the task as done + } catch (NumberFormatException | IndexOutOfBoundsException e) { + // Handle invalid index or format exceptions + ui.porFavorMessage("MARK EXCEPTION: INVALID TASK INDEX"); + } catch (NullPointerException e) { + // Handle null task case + ui.porFavorMessage("MARK EXCEPTION: NULL TASK INDEX"); + } + } + // Handle "unmark" command to unmark a task as completed + else if (line.startsWith("unmark ")) { + try { + int taskIndex = Integer.parseInt(line.replace("unmark ", "")) - 1; // Parse the task index + tasks.unmark(taskIndex); // Unmark the task + } catch (NumberFormatException | IndexOutOfBoundsException e) { + // Handle invalid index or format exceptions + ui.porFavorMessage("UNMARK EXCEPTION: INVALID TASK INDEX"); + } catch (NullPointerException e) { + // Handle null task case + ui.porFavorMessage("UNMARK EXCEPTION: NULL TASK INDEX"); + } + + } + // Handle "todo" command to create a new ToDo task + else if (line.startsWith("todo ")) { + try { + new ToDo(line, tasks, true); // Create a new ToDo object + } catch (ToDoConstructorException e) { + // Handle custom ToDo exception + ui.porFavorMessage(e.getMessage()); + tasks.deleteLatestTask(); + } + } + // Handle "deadline" command to create a new Deadline task + else if (line.startsWith("deadline ")) { + try { + new Deadline(line, tasks, true); // Create a new Deadline object + } catch (DeadlineConstructorException e) { + // Handle custom Deadline exception + ui.porFavorMessage(e.getMessage()); + tasks.deleteLatestTask(); + } + } + // Handle "event" command to create a new Event task + else if (line.startsWith("event ")) { + try { + new Event(line, tasks, true); // Create a new Event object + } catch (EventConstructorException e) { + // Handle custom Event exception + ui.porFavorMessage(e.getMessage()); + tasks.deleteLatestTask(); + } + } + // Default case for unrecognized commands + else { + ui.porFavorMessage("UNRECOGNIZED REQUEST"); // Inform user about an unrecognized command + } + + ui.lineMessage(); // Print separator line + return true; // Continue conversation + } } diff --git a/src/main/java/taskpackage/TaskList.java b/src/main/java/taskpackage/TaskList.java index 27dd8aeb3..119ea9d27 100644 --- a/src/main/java/taskpackage/TaskList.java +++ b/src/main/java/taskpackage/TaskList.java @@ -33,7 +33,7 @@ public int size() { } public String dataFileEntry(int index) { - return (this.tasks.get(index).inputString + " /isdone " + this.tasks.get(index).isDone); + return (this.tasks.get(index).inputString + " /isdone " + this.tasks.get(index).isDone + "\n"); } // Static method to mark a task as done by index From 44b8d557dcc4a2c3fc120515d72a52df4dec8859 Mon Sep 17 00:00:00 2001 From: DarkDragoon2002 Date: Wed, 9 Oct 2024 12:42:17 +0800 Subject: [PATCH 19/31] Fixed Corrupted Data Handling --- src/main/java/Storage.java | 95 ++++++++++++++++++++++---------------- 1 file changed, 56 insertions(+), 39 deletions(-) diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index 27cd74f3f..770ba31a0 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -22,50 +22,16 @@ public Storage(String dataFilePath, UI ui) { public TaskList readData() { TaskList tempTaskList = new TaskList(); - - File dataFile = new File(dataFilePath); try { + File dataFile = new File(dataFilePath); Scanner scanner = new Scanner(dataFile); while (scanner.hasNextLine()) { String inputLine = scanner.nextLine(); - String[] lineSegments = inputLine.split(" /isdone "); - String line = lineSegments[0]; - boolean isDone = Boolean.parseBoolean(lineSegments[1]); - if (line.startsWith("todo ")) { - try { - new ToDo(line, tempTaskList, false); // Create a new ToDo object - } catch (ToDoConstructorException e) { - // Handle custom ToDo exception - ui.printMessage("CORRUPTED: " + line); - tempTaskList.deleteLatestTask(); - } - } - // Handle "deadline" command to create a new Deadline task - else if (line.startsWith("deadline ")) { - try { - new Deadline(line, tempTaskList, false); // Create a new Deadline object - } catch (DeadlineConstructorException e) { - // Handle custom Deadline exception - ui.printMessage("CORRUPTED: " + line); - tempTaskList.deleteLatestTask(); - } - } - // Handle "event" command to create a new Event task - else if (line.startsWith("event ")) { - try { - new Event(line, tempTaskList, false); // Create a new Event object - } catch (EventConstructorException e) { - // Handle custom Event exception - ui.printMessage("CORRUPTED: " + line); - tempTaskList.deleteLatestTask(); - } - } - else { - ui.printMessage("CORRUPTED: " + line); - } + try { + tempTaskList = handleDataLine(inputLine, tempTaskList); - if (isDone) { - tempTaskList.markLatestTask(); + } catch (Exception e) { + ui.printMessage("ERROR READING LINE: " + inputLine); } } ui.printMessage("Data File Read"); @@ -77,6 +43,57 @@ else if (line.startsWith("event ")) { return tempTaskList; } + private TaskList handleDataLine(String inputLine, TaskList tempTaskList) { + String[] lineSegments = inputLine.split(" /isdone "); + String line = lineSegments[0]; + boolean isDone; + if (lineSegments[1].trim().equals("true")) { + isDone = true; + } else if (lineSegments[1].trim().equals("false")) { + isDone = false; + } else { + ui.printMessage("ERROR READING LINE: " + inputLine); + return tempTaskList; + } + if (line.startsWith("todo ")) { + try { + new ToDo(line, tempTaskList, false); // Create a new ToDo object + } catch (ToDoConstructorException e) { + // Handle custom ToDo exception + ui.printMessage("CORRUPTED: " + line); + tempTaskList.deleteLatestTask(); + } + } + // Handle "deadline" command to create a new Deadline task + else if (line.startsWith("deadline ")) { + try { + new Deadline(line, tempTaskList, false); // Create a new Deadline object + } catch (DeadlineConstructorException e) { + // Handle custom Deadline exception + ui.printMessage("CORRUPTED: " + line); + tempTaskList.deleteLatestTask(); + } + } + // Handle "event" command to create a new Event task + else if (line.startsWith("event ")) { + try { + new Event(line, tempTaskList, false); // Create a new Event object + } catch (EventConstructorException e) { + // Handle custom Event exception + ui.printMessage("CORRUPTED: " + line); + tempTaskList.deleteLatestTask(); + } + } + else { + ui.printMessage("CORRUPTED: " + line); + } + + if (isDone) { + tempTaskList.markLatestTask(); + } + return tempTaskList; + } + public void writeDate(TaskList taskList) { try { FileWriter writer = new FileWriter(dataFilePath); From 43e739f389ca65e0e208dad9fc9b1986a9ee6f8d Mon Sep 17 00:00:00 2001 From: DarkDragoon2002 Date: Wed, 9 Oct 2024 14:36:22 +0800 Subject: [PATCH 20/31] Extracted Command Handling from Parser and Followed Good Coding Principles --- data.text | 2 +- src/main/java/CommandHandling.java | 89 +++++++++++++++++++++ src/main/java/Juan.java | 12 +-- src/main/java/Parser.java | 102 ++++-------------------- src/main/java/Storage.java | 22 ++--- src/main/java/taskpackage/Deadline.java | 2 +- src/main/java/taskpackage/Event.java | 4 +- src/main/java/taskpackage/Task.java | 1 - 8 files changed, 122 insertions(+), 112 deletions(-) create mode 100644 src/main/java/CommandHandling.java diff --git a/data.text b/data.text index d7e531728..274885724 100644 --- a/data.text +++ b/data.text @@ -1,3 +1,3 @@ todo go to class /isdone true todo say hi /isdone false -todo leave class /isdone false +deadline go for meeting /by 3pm /isdone true diff --git a/src/main/java/CommandHandling.java b/src/main/java/CommandHandling.java new file mode 100644 index 000000000..af2085c0a --- /dev/null +++ b/src/main/java/CommandHandling.java @@ -0,0 +1,89 @@ +import customexceptions.DeadlineConstructorException; +import customexceptions.EventConstructorException; +import customexceptions.ToDoConstructorException; +import taskpackage.Deadline; +import taskpackage.Event; +import taskpackage.TaskList; +import taskpackage.ToDo; + +public class CommandHandling { + public static final String BYE_COMMAND = "bye"; + public static final String LIST_COMMAND = "list"; + public static final String DELETE_COMMAND = "delete "; + public static final String MARK_COMMAND = "mark "; + public static final String UNMARK_COMMAND = "unmark "; + public static final String TODO_COMMAND = "todo "; + public static final String DEADLINE_COMMAND = "deadline "; + public static final String EVENT_COMMAND = "EVENT "; + + public static void deleteCommand(TaskList tasks, String line, UI ui) { + try { + int taskIndex = Integer.parseInt(line.replace("delete ", "")) - 1; // Parse the task index + tasks.deleteTask(taskIndex); // Mark the task as done + } catch (NumberFormatException | IndexOutOfBoundsException e) { + // Handle invalid index or format exceptions + ui.porFavorMessage("DELETE EXCEPTION: INVALID TASK INDEX"); + } catch (NullPointerException e) { + // Handle null task case + ui.porFavorMessage("DELETE EXCEPTION: NULL TASK INDEX"); + } + } + + public static void markCommand(TaskList tasks, String line, UI ui) { + try { + int taskIndex = Integer.parseInt(line.replace("mark ", "")) - 1; // Parse the task index + tasks.mark(taskIndex); // Mark the task as done + } catch (NumberFormatException | IndexOutOfBoundsException e) { + // Handle invalid index or format exceptions + ui.porFavorMessage("MARK EXCEPTION: INVALID TASK INDEX"); + } catch (NullPointerException e) { + // Handle null task case + ui.porFavorMessage("MARK EXCEPTION: NULL TASK INDEX"); + } + } + + public static void unmarkCommand(TaskList tasks, String line, UI ui) { + try { + int taskIndex = Integer.parseInt(line.replace("unmark ", "")) - 1; // Parse the task index + tasks.unmark(taskIndex); // Unmark the task + } catch (NumberFormatException | IndexOutOfBoundsException e) { + // Handle invalid index or format exceptions + ui.porFavorMessage("UNMARK EXCEPTION: INVALID TASK INDEX"); + } catch (NullPointerException e) { + // Handle null task case + ui.porFavorMessage("UNMARK EXCEPTION: NULL TASK INDEX"); + } + } + + public static void addTodoCommand(TaskList tasks, String line, UI ui) { + try { + new ToDo(line, tasks, true); // Create a new ToDo object + } catch (ToDoConstructorException e) { + // Handle custom ToDo exception + ui.porFavorMessage(e.getMessage()); + tasks.deleteLatestTask(); + } + } + + public static void addDeadlineCommand(TaskList tasks, String line, UI ui) { + try { + new Deadline(line, tasks, true); // Create a new Deadline object + } catch (DeadlineConstructorException e) { + // Handle custom Deadline exception + ui.porFavorMessage(e.getMessage()); + tasks.deleteLatestTask(); + } + } + + public static void addEventCommand(TaskList tasks, String line, UI ui) { + try { + new Event(line, tasks, true); // Create a new Event object + } catch (EventConstructorException e) { + // Handle custom Event exception + ui.porFavorMessage(e.getMessage()); + tasks.deleteLatestTask(); + } + } + +} + diff --git a/src/main/java/Juan.java b/src/main/java/Juan.java index 65996219b..34cedb58b 100644 --- a/src/main/java/Juan.java +++ b/src/main/java/Juan.java @@ -1,17 +1,13 @@ -import customexceptions.*; // Import custom exception classes -import taskpackage.*; // Import task-related classes like ToDo, Deadline, and Event - -import java.io.IOException; - +import taskpackage.TaskList; public class Juan { private final static String dataFilePath = "data.text"; - private UI ui; - private Storage storage; + private final UI ui; + private final Storage storage; private TaskList tasks; - private Parser parser; + private final Parser parser; // Constructor public Juan(String dataFilePath) { diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index 2c98523eb..1fb4f5514 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -1,15 +1,9 @@ -import customexceptions.DeadlineConstructorException; -import customexceptions.EventConstructorException; -import customexceptions.ToDoConstructorException; -import taskpackage.Deadline; -import taskpackage.Event; import taskpackage.TaskList; -import taskpackage.ToDo; public class Parser { - private UI ui; - private TaskList tasks; + private final UI ui; + private final TaskList tasks; public Parser(UI ui, TaskList tasks) { this.ui = ui; @@ -24,85 +18,23 @@ public boolean chatFeature(String line) { ui.lineMessage(); // Print separator line // Handle "bye" command to end chat - if (line.equals("bye")) { + if (line.equals(CommandHandling.BYE_COMMAND)) { return false; // End the conversation - } - // Handle "list" command to display the list of tasks - else if (line.equals("list")) { + } else if (line.equals(CommandHandling.LIST_COMMAND)) { tasks.printTasksList(); // Print task list from Task class - } - // Handle "delete" command - else if (line.startsWith("delete ")) { - try { - int taskIndex = Integer.parseInt(line.replace("delete ", "")) - 1; // Parse the task index - tasks.deleteTask(taskIndex); // Mark the task as done - } catch (NumberFormatException | IndexOutOfBoundsException e) { - // Handle invalid index or format exceptions - ui.porFavorMessage("DELETE EXCEPTION: INVALID TASK INDEX"); - } catch (NullPointerException e) { - // Handle null task case - ui.porFavorMessage("DELETE EXCEPTION: NULL TASK INDEX"); - } - } - // Handle "mark" command to mark a task as completed - else if (line.startsWith("mark ")) { - try { - int taskIndex = Integer.parseInt(line.replace("mark ", "")) - 1; // Parse the task index - tasks.mark(taskIndex); // Mark the task as done - } catch (NumberFormatException | IndexOutOfBoundsException e) { - // Handle invalid index or format exceptions - ui.porFavorMessage("MARK EXCEPTION: INVALID TASK INDEX"); - } catch (NullPointerException e) { - // Handle null task case - ui.porFavorMessage("MARK EXCEPTION: NULL TASK INDEX"); - } - } - // Handle "unmark" command to unmark a task as completed - else if (line.startsWith("unmark ")) { - try { - int taskIndex = Integer.parseInt(line.replace("unmark ", "")) - 1; // Parse the task index - tasks.unmark(taskIndex); // Unmark the task - } catch (NumberFormatException | IndexOutOfBoundsException e) { - // Handle invalid index or format exceptions - ui.porFavorMessage("UNMARK EXCEPTION: INVALID TASK INDEX"); - } catch (NullPointerException e) { - // Handle null task case - ui.porFavorMessage("UNMARK EXCEPTION: NULL TASK INDEX"); - } - - } - // Handle "todo" command to create a new ToDo task - else if (line.startsWith("todo ")) { - try { - new ToDo(line, tasks, true); // Create a new ToDo object - } catch (ToDoConstructorException e) { - // Handle custom ToDo exception - ui.porFavorMessage(e.getMessage()); - tasks.deleteLatestTask(); - } - } - // Handle "deadline" command to create a new Deadline task - else if (line.startsWith("deadline ")) { - try { - new Deadline(line, tasks, true); // Create a new Deadline object - } catch (DeadlineConstructorException e) { - // Handle custom Deadline exception - ui.porFavorMessage(e.getMessage()); - tasks.deleteLatestTask(); - } - } - // Handle "event" command to create a new Event task - else if (line.startsWith("event ")) { - try { - new Event(line, tasks, true); // Create a new Event object - } catch (EventConstructorException e) { - // Handle custom Event exception - ui.porFavorMessage(e.getMessage()); - tasks.deleteLatestTask(); - } - } - // Default case for unrecognized commands - else { + } else if (line.startsWith(CommandHandling.DELETE_COMMAND)) { + CommandHandling.deleteCommand(tasks, line, ui); + } else if (line.startsWith(CommandHandling.MARK_COMMAND)) { + CommandHandling.markCommand(tasks, line, ui); + } else if (line.startsWith(CommandHandling.UNMARK_COMMAND)) { + CommandHandling.unmarkCommand(tasks, line, ui); + } else if (line.startsWith(CommandHandling.TODO_COMMAND)) { + CommandHandling.addTodoCommand(tasks, line, ui); + } else if (line.startsWith(CommandHandling.DEADLINE_COMMAND)) { + CommandHandling.addDeadlineCommand(tasks, line, ui); + } else if (line.startsWith(CommandHandling.EVENT_COMMAND)) { + CommandHandling.addEventCommand(tasks, line, ui); + } else { ui.porFavorMessage("UNRECOGNIZED REQUEST"); // Inform user about an unrecognized command } diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index 770ba31a0..a5cfdcf9a 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -11,8 +11,8 @@ public class Storage { - private String dataFilePath; - private UI ui; + private final String dataFilePath; + private final UI ui; public Storage(String dataFilePath, UI ui) { this.dataFilePath = dataFilePath; @@ -28,7 +28,7 @@ public TaskList readData() { while (scanner.hasNextLine()) { String inputLine = scanner.nextLine(); try { - tempTaskList = handleDataLine(inputLine, tempTaskList); + handleDataLine(inputLine, tempTaskList); } catch (Exception e) { ui.printMessage("ERROR READING LINE: " + inputLine); @@ -43,7 +43,7 @@ public TaskList readData() { return tempTaskList; } - private TaskList handleDataLine(String inputLine, TaskList tempTaskList) { + private void handleDataLine(String inputLine, TaskList tempTaskList) { String[] lineSegments = inputLine.split(" /isdone "); String line = lineSegments[0]; boolean isDone; @@ -53,7 +53,7 @@ private TaskList handleDataLine(String inputLine, TaskList tempTaskList) { isDone = false; } else { ui.printMessage("ERROR READING LINE: " + inputLine); - return tempTaskList; + return; } if (line.startsWith("todo ")) { try { @@ -63,9 +63,7 @@ private TaskList handleDataLine(String inputLine, TaskList tempTaskList) { ui.printMessage("CORRUPTED: " + line); tempTaskList.deleteLatestTask(); } - } - // Handle "deadline" command to create a new Deadline task - else if (line.startsWith("deadline ")) { + } else if (line.startsWith("deadline ")) { try { new Deadline(line, tempTaskList, false); // Create a new Deadline object } catch (DeadlineConstructorException e) { @@ -73,9 +71,7 @@ else if (line.startsWith("deadline ")) { ui.printMessage("CORRUPTED: " + line); tempTaskList.deleteLatestTask(); } - } - // Handle "event" command to create a new Event task - else if (line.startsWith("event ")) { + } else if (line.startsWith("event ")) { try { new Event(line, tempTaskList, false); // Create a new Event object } catch (EventConstructorException e) { @@ -83,15 +79,13 @@ else if (line.startsWith("event ")) { ui.printMessage("CORRUPTED: " + line); tempTaskList.deleteLatestTask(); } - } - else { + } else { ui.printMessage("CORRUPTED: " + line); } if (isDone) { tempTaskList.markLatestTask(); } - return tempTaskList; } public void writeDate(TaskList taskList) { diff --git a/src/main/java/taskpackage/Deadline.java b/src/main/java/taskpackage/Deadline.java index 54945231b..59d0b09c2 100644 --- a/src/main/java/taskpackage/Deadline.java +++ b/src/main/java/taskpackage/Deadline.java @@ -6,7 +6,7 @@ public class Deadline extends Task { // Variable to store the deadline date/time string - private String deadlineString; + private final String deadlineString; // Constructor for creating a Deadline task diff --git a/src/main/java/taskpackage/Event.java b/src/main/java/taskpackage/Event.java index 6b9fd4e4c..05f463ec5 100644 --- a/src/main/java/taskpackage/Event.java +++ b/src/main/java/taskpackage/Event.java @@ -6,8 +6,8 @@ public class Event extends Task { // Variables to store the start and end times of the event - private String fromString; - private String toString; + private final String fromString; + private final String toString; // Constructor for creating an Event task public Event(String inputString, TaskList tasks, boolean constructorMessage) throws EventConstructorException { diff --git a/src/main/java/taskpackage/Task.java b/src/main/java/taskpackage/Task.java index ab5f58cf2..b21661dac 100644 --- a/src/main/java/taskpackage/Task.java +++ b/src/main/java/taskpackage/Task.java @@ -1,5 +1,4 @@ package taskpackage; // Package for Task-related classes -import java.util.ArrayList; // Parent class Task which serves as a base for ToDo, Deadline, and Event tasks public class Task { From 8eff0ee3942dff22868799bf70268dfba59bf36c Mon Sep 17 00:00:00 2001 From: DarkDragoon2002 Date: Thu, 10 Oct 2024 00:44:51 +0800 Subject: [PATCH 21/31] Implemented DateTime feature and Updated Exception Handling --- data.text | 3 ++- src/main/java/Storage.java | 19 +++++++-------- .../DeadlineConstructorException.java | 10 +++++++- .../EventConstructorException.java | 11 ++++++++- src/main/java/taskpackage/Deadline.java | 18 +++++++++++---- src/main/java/taskpackage/Event.java | 23 +++++++++++++++---- src/main/java/taskpackage/TaskList.java | 2 +- 7 files changed, 64 insertions(+), 22 deletions(-) diff --git a/data.text b/data.text index 274885724..b01de328c 100644 --- a/data.text +++ b/data.text @@ -1,3 +1,4 @@ todo go to class /isdone true todo say hi /isdone false -deadline go for meeting /by 3pm /isdone true +deadline go for meeting /by 01-01-2000 00:00 /isdone true +event Senior Seminar RC4 /from 10-10-2024 14:00 /to 10-10-2024 17:00 /isdone true diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index a5cfdcf9a..129b94d39 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -32,6 +32,7 @@ public TaskList readData() { } catch (Exception e) { ui.printMessage("ERROR READING LINE: " + inputLine); + ui.printMessage(e.getMessage()); } } ui.printMessage("Data File Read"); @@ -43,7 +44,7 @@ public TaskList readData() { return tempTaskList; } - private void handleDataLine(String inputLine, TaskList tempTaskList) { + private void handleDataLine(String inputLine, TaskList taskList) { String[] lineSegments = inputLine.split(" /isdone "); String line = lineSegments[0]; boolean isDone; @@ -52,39 +53,39 @@ private void handleDataLine(String inputLine, TaskList tempTaskList) { } else if (lineSegments[1].trim().equals("false")) { isDone = false; } else { - ui.printMessage("ERROR READING LINE: " + inputLine); + ui.printMessage("ERROR READING ISDONE VALUE: " + inputLine); return; } if (line.startsWith("todo ")) { try { - new ToDo(line, tempTaskList, false); // Create a new ToDo object + new ToDo(line, taskList, false); // Create a new ToDo object } catch (ToDoConstructorException e) { // Handle custom ToDo exception ui.printMessage("CORRUPTED: " + line); - tempTaskList.deleteLatestTask(); + taskList.deleteLatestTask(); } } else if (line.startsWith("deadline ")) { try { - new Deadline(line, tempTaskList, false); // Create a new Deadline object + new Deadline(line, taskList, false); // Create a new Deadline object } catch (DeadlineConstructorException e) { // Handle custom Deadline exception ui.printMessage("CORRUPTED: " + line); - tempTaskList.deleteLatestTask(); + taskList.deleteLatestTask(); } } else if (line.startsWith("event ")) { try { - new Event(line, tempTaskList, false); // Create a new Event object + new Event(line, taskList, false); // Create a new Event object } catch (EventConstructorException e) { // Handle custom Event exception ui.printMessage("CORRUPTED: " + line); - tempTaskList.deleteLatestTask(); + taskList.deleteLatestTask(); } } else { ui.printMessage("CORRUPTED: " + line); } if (isDone) { - tempTaskList.markLatestTask(); + taskList.markLatestTask(); } } diff --git a/src/main/java/customexceptions/DeadlineConstructorException.java b/src/main/java/customexceptions/DeadlineConstructorException.java index 34fe91d9b..9225c9831 100644 --- a/src/main/java/customexceptions/DeadlineConstructorException.java +++ b/src/main/java/customexceptions/DeadlineConstructorException.java @@ -1,5 +1,7 @@ package customexceptions; // Package for custom exceptions -import taskpackage.Task; // Import Task class to manage task deletion + +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; // Custom exception class for handling errors in Deadline task construction public class DeadlineConstructorException extends Exception { @@ -26,6 +28,12 @@ private static String errorMessage(String message) { return "MISSING TASK STATEMENT"; // Return specific error if no task description } + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HHmm"); + try { + dateTimeFormatter.parse(taskStringBreakdown[1]); + } catch (DateTimeParseException e) { + return "INVALID DATETIME EXCEPTION"; + } // If none of the specific errors match, return an unknown error return "UNKNOWN ERROR"; } diff --git a/src/main/java/customexceptions/EventConstructorException.java b/src/main/java/customexceptions/EventConstructorException.java index c28106652..634ec1849 100644 --- a/src/main/java/customexceptions/EventConstructorException.java +++ b/src/main/java/customexceptions/EventConstructorException.java @@ -1,5 +1,7 @@ package customexceptions; // Package for custom exceptions -import taskpackage.Task; // Import Task class to manage task deletion + +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; // Custom exception class for handling errors in Event task construction public class EventConstructorException extends Exception { @@ -34,6 +36,13 @@ private static String errorMessage(String message) { if (fromToStringBreakdown.length != 2) { return "MISSING FROM/TO DATES"; // Return specific error if either "from" or "to" date is missing } + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HHmm"); + try { + dateTimeFormatter.parse(fromToStringBreakdown[0]); + dateTimeFormatter.parse(fromToStringBreakdown[1]); + } catch (DateTimeParseException e) { + return "INVALID DATETIME EXCEPTION"; + } // If none of the specific errors match, return an unknown error return "UNKNOWN ERROR"; diff --git a/src/main/java/taskpackage/Deadline.java b/src/main/java/taskpackage/Deadline.java index 59d0b09c2..67f69a156 100644 --- a/src/main/java/taskpackage/Deadline.java +++ b/src/main/java/taskpackage/Deadline.java @@ -2,12 +2,17 @@ import customexceptions.DeadlineConstructorException; // Import custom exception for Deadline tasks +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; + // Deadline class, a child class of Task, represents a task with a specific deadline public class Deadline extends Task { // Variable to store the deadline date/time string - private final String deadlineString; + private final LocalDateTime deadlineDateTime; + private final static String DATE_TIME_FORMAT = "dd-MM-yyyy HH:mm"; // Constructor for creating a Deadline task public Deadline(String inputString, TaskList tasks, boolean constructorMessage) throws DeadlineConstructorException { @@ -18,9 +23,13 @@ public Deadline(String inputString, TaskList tasks, boolean constructorMessage) if (!(inputString.contains(" /by ")) || this.taskString.isEmpty()) { throw new DeadlineConstructorException(inputString); // Throw custom exception if validation fails } - // Extract the deadline portion of the input string (after the "/by" keyword) - this.deadlineString = inputString.replace("deadline ", "").split(" /by ")[1]; + try { + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(DATE_TIME_FORMAT); + this.deadlineDateTime = LocalDateTime.parse(inputString.replace("deadline ", "").split(" /by ")[1], dateTimeFormatter); + } catch (DateTimeParseException e) { + throw new DeadlineConstructorException(inputString); + } // Display a confirmation message when a Deadline task is successfully created if (constructorMessage) { @@ -32,6 +41,7 @@ public Deadline(String inputString, TaskList tasks, boolean constructorMessage) @Override public String checkboxString() { // Call the parent method and add the "[D]" tag and deadline string to the checkbox format - return "[D]" + super.checkboxString() + " (by: " + deadlineString + ")"; + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(DATE_TIME_FORMAT); + return "[D]" + super.checkboxString() + " (by: " + deadlineDateTime.format(dateTimeFormatter) + ")"; } } diff --git a/src/main/java/taskpackage/Event.java b/src/main/java/taskpackage/Event.java index 05f463ec5..6da429811 100644 --- a/src/main/java/taskpackage/Event.java +++ b/src/main/java/taskpackage/Event.java @@ -1,13 +1,20 @@ package taskpackage; // Package for Task-related classes +import customexceptions.DeadlineConstructorException; import customexceptions.EventConstructorException; // Import custom exception for Event tasks +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; + // Event class, a child class of Task, represents a task with a specific start and end time public class Event extends Task { // Variables to store the start and end times of the event - private final String fromString; - private final String toString; + private final LocalDateTime fromDateTime; + private final LocalDateTime toDateTime; + + private final static String DATE_TIME_FORMAT = "dd-MM-yyyy HH:mm"; // Constructor for creating an Event task public Event(String inputString, TaskList tasks, boolean constructorMessage) throws EventConstructorException { @@ -30,8 +37,13 @@ public Event(String inputString, TaskList tasks, boolean constructorMessage) thr } // Set the from and to times for the event - this.fromString = fromToStrings[0]; - this.toString = fromToStrings[1]; + try { + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(DATE_TIME_FORMAT); + this.fromDateTime = LocalDateTime.parse(fromToStrings[0], dateTimeFormatter); + this.toDateTime = LocalDateTime.parse(fromToStrings[1], dateTimeFormatter); + } catch (DateTimeParseException e) { + throw new EventConstructorException(inputString); + } // Display a confirmation message when an Event task is successfully created if (constructorMessage) { @@ -42,7 +54,8 @@ public Event(String inputString, TaskList tasks, boolean constructorMessage) thr // Override the checkboxString method to include the "[E]" tag, start time, and end time @Override public String checkboxString() { + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(DATE_TIME_FORMAT); // Call the parent method and add the "[E]" tag along with the event's start and end times - return "[E]" + super.checkboxString() + " (from: " + fromString + " to: " + toString + ")"; + return "[E]" + super.checkboxString() + " (from: " + fromDateTime.format(dateTimeFormatter) + " to: " + toDateTime.format(dateTimeFormatter) + ")"; } } diff --git a/src/main/java/taskpackage/TaskList.java b/src/main/java/taskpackage/TaskList.java index 119ea9d27..385eb0530 100644 --- a/src/main/java/taskpackage/TaskList.java +++ b/src/main/java/taskpackage/TaskList.java @@ -55,7 +55,7 @@ public void printTasksList(){ if (tasks.isEmpty()){ System.out.println("Por Favor? Nothing Here"); // Message when there are no tasks } else { - System.out.println("Si compinche, your tasks:"); // Message when displaying tasks + System.out.println("Si compinche, your " + tasks.size() + " tasks:"); // Message when displaying tasks for (int i = 0; i < tasks.size(); i++){ // Print each task with its index and checkbox format System.out.println((i+1) + "." + tasks.get(i).checkboxString()); From 01d0c9d0a5a7ca4c9000511e0e9f1b26a0c7b0ca Mon Sep 17 00:00:00 2001 From: DarkDragoon2002 Date: Thu, 10 Oct 2024 01:22:59 +0800 Subject: [PATCH 22/31] Implement find function --- src/main/java/CommandHandling.java | 24 +++++++++++++++++------- src/main/java/Parser.java | 2 ++ src/main/java/Storage.java | 12 ++++++------ src/main/java/taskpackage/Deadline.java | 2 +- src/main/java/taskpackage/Event.java | 2 +- src/main/java/taskpackage/TaskList.java | 22 ++++++++++++++++++++++ src/main/java/taskpackage/ToDo.java | 2 +- 7 files changed, 50 insertions(+), 16 deletions(-) diff --git a/src/main/java/CommandHandling.java b/src/main/java/CommandHandling.java index af2085c0a..65a2eada7 100644 --- a/src/main/java/CommandHandling.java +++ b/src/main/java/CommandHandling.java @@ -10,15 +10,16 @@ public class CommandHandling { public static final String BYE_COMMAND = "bye"; public static final String LIST_COMMAND = "list"; public static final String DELETE_COMMAND = "delete "; + public static final String FIND_COMMAND = "find "; public static final String MARK_COMMAND = "mark "; public static final String UNMARK_COMMAND = "unmark "; public static final String TODO_COMMAND = "todo "; public static final String DEADLINE_COMMAND = "deadline "; - public static final String EVENT_COMMAND = "EVENT "; + public static final String EVENT_COMMAND = "event "; public static void deleteCommand(TaskList tasks, String line, UI ui) { try { - int taskIndex = Integer.parseInt(line.replace("delete ", "")) - 1; // Parse the task index + int taskIndex = Integer.parseInt(line.replace(DELETE_COMMAND, "")) - 1; // Parse the task index tasks.deleteTask(taskIndex); // Mark the task as done } catch (NumberFormatException | IndexOutOfBoundsException e) { // Handle invalid index or format exceptions @@ -29,9 +30,18 @@ public static void deleteCommand(TaskList tasks, String line, UI ui) { } } + public static void findCommand(TaskList tasks, String line, UI ui) { + String findString = line.replace(FIND_COMMAND, ""); + if (findString.isEmpty()) { + ui.porFavorMessage("FIND EXCEPTION: INVALID TASK INDEX"); + return; + } + tasks.findTasksList(findString); + } + public static void markCommand(TaskList tasks, String line, UI ui) { try { - int taskIndex = Integer.parseInt(line.replace("mark ", "")) - 1; // Parse the task index + int taskIndex = Integer.parseInt(line.replace(MARK_COMMAND, "")) - 1; // Parse the task index tasks.mark(taskIndex); // Mark the task as done } catch (NumberFormatException | IndexOutOfBoundsException e) { // Handle invalid index or format exceptions @@ -44,7 +54,7 @@ public static void markCommand(TaskList tasks, String line, UI ui) { public static void unmarkCommand(TaskList tasks, String line, UI ui) { try { - int taskIndex = Integer.parseInt(line.replace("unmark ", "")) - 1; // Parse the task index + int taskIndex = Integer.parseInt(line.replace(UNMARK_COMMAND, "")) - 1; // Parse the task index tasks.unmark(taskIndex); // Unmark the task } catch (NumberFormatException | IndexOutOfBoundsException e) { // Handle invalid index or format exceptions @@ -57,7 +67,7 @@ public static void unmarkCommand(TaskList tasks, String line, UI ui) { public static void addTodoCommand(TaskList tasks, String line, UI ui) { try { - new ToDo(line, tasks, true); // Create a new ToDo object + new ToDo(line.replace(TODO_COMMAND, ""), tasks, true); // Create a new ToDo object } catch (ToDoConstructorException e) { // Handle custom ToDo exception ui.porFavorMessage(e.getMessage()); @@ -67,7 +77,7 @@ public static void addTodoCommand(TaskList tasks, String line, UI ui) { public static void addDeadlineCommand(TaskList tasks, String line, UI ui) { try { - new Deadline(line, tasks, true); // Create a new Deadline object + new Deadline(line.replace(DEADLINE_COMMAND, ""), tasks, true); // Create a new Deadline object } catch (DeadlineConstructorException e) { // Handle custom Deadline exception ui.porFavorMessage(e.getMessage()); @@ -77,7 +87,7 @@ public static void addDeadlineCommand(TaskList tasks, String line, UI ui) { public static void addEventCommand(TaskList tasks, String line, UI ui) { try { - new Event(line, tasks, true); // Create a new Event object + new Event(line.replace(EVENT_COMMAND, ""), tasks, true); // Create a new Event object } catch (EventConstructorException e) { // Handle custom Event exception ui.porFavorMessage(e.getMessage()); diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index 1fb4f5514..4a9176a0e 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -24,6 +24,8 @@ public boolean chatFeature(String line) { tasks.printTasksList(); // Print task list from Task class } else if (line.startsWith(CommandHandling.DELETE_COMMAND)) { CommandHandling.deleteCommand(tasks, line, ui); + } else if (line.startsWith(CommandHandling.FIND_COMMAND)) { + CommandHandling.findCommand(tasks, line, ui); } else if (line.startsWith(CommandHandling.MARK_COMMAND)) { CommandHandling.markCommand(tasks, line, ui); } else if (line.startsWith(CommandHandling.UNMARK_COMMAND)) { diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index a5cfdcf9a..e33b5c3b7 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -55,25 +55,25 @@ private void handleDataLine(String inputLine, TaskList tempTaskList) { ui.printMessage("ERROR READING LINE: " + inputLine); return; } - if (line.startsWith("todo ")) { + if (line.startsWith(CommandHandling.TODO_COMMAND)) { try { - new ToDo(line, tempTaskList, false); // Create a new ToDo object + new ToDo(line.replace(CommandHandling.TODO_COMMAND, ""), tempTaskList, false); // Create a new ToDo object } catch (ToDoConstructorException e) { // Handle custom ToDo exception ui.printMessage("CORRUPTED: " + line); tempTaskList.deleteLatestTask(); } - } else if (line.startsWith("deadline ")) { + } else if (line.startsWith(CommandHandling.DEADLINE_COMMAND)) { try { - new Deadline(line, tempTaskList, false); // Create a new Deadline object + new Deadline(line.replace(CommandHandling.DEADLINE_COMMAND, ""), tempTaskList, false); // Create a new Deadline object } catch (DeadlineConstructorException e) { // Handle custom Deadline exception ui.printMessage("CORRUPTED: " + line); tempTaskList.deleteLatestTask(); } - } else if (line.startsWith("event ")) { + } else if (line.startsWith(CommandHandling.EVENT_COMMAND)) { try { - new Event(line, tempTaskList, false); // Create a new Event object + new Event(line.replace(CommandHandling.EVENT_COMMAND, ""), tempTaskList, false); // Create a new Event object } catch (EventConstructorException e) { // Handle custom Event exception ui.printMessage("CORRUPTED: " + line); diff --git a/src/main/java/taskpackage/Deadline.java b/src/main/java/taskpackage/Deadline.java index 59d0b09c2..02a00582a 100644 --- a/src/main/java/taskpackage/Deadline.java +++ b/src/main/java/taskpackage/Deadline.java @@ -12,7 +12,7 @@ public class Deadline extends Task { // Constructor for creating a Deadline task public Deadline(String inputString, TaskList tasks, boolean constructorMessage) throws DeadlineConstructorException { // Call the parent class (Task) constructor with the task description (before the "/by" keyword) - super(inputString.replace("deadline ", "").split(" /by ")[0], tasks); + super(inputString.split(" /by ")[0], tasks); this.inputString = inputString; // Check if the "/by" keyword is missing or if the task description is empty if (!(inputString.contains(" /by ")) || this.taskString.isEmpty()) { diff --git a/src/main/java/taskpackage/Event.java b/src/main/java/taskpackage/Event.java index 05f463ec5..b88cf024c 100644 --- a/src/main/java/taskpackage/Event.java +++ b/src/main/java/taskpackage/Event.java @@ -12,7 +12,7 @@ public class Event extends Task { // Constructor for creating an Event task public Event(String inputString, TaskList tasks, boolean constructorMessage) throws EventConstructorException { // Call the parent class (Task) constructor with the task description (before the "/from" keyword) - super(inputString.replace("event ", "").split(" /from ")[0], tasks); + super(inputString.split(" /from ")[0], tasks); this.inputString = inputString; diff --git a/src/main/java/taskpackage/TaskList.java b/src/main/java/taskpackage/TaskList.java index 119ea9d27..3804b9536 100644 --- a/src/main/java/taskpackage/TaskList.java +++ b/src/main/java/taskpackage/TaskList.java @@ -63,4 +63,26 @@ public void printTasksList(){ } } + // Static method to print all tasks in the list + public void findTasksList(String findString){ + if (tasks.isEmpty()){ + System.out.println("Por Favor? Nothing Here"); // Message when there are no tasks + } else { + System.out.println("Si compinche, your tasks with the phrase <" + findString + ">:"); // Message when displaying tasks + int foundCount = 0; + for (int i = 0; i < tasks.size(); i++){ + // Check if findString in checkboxString + if (tasks.get(i).checkboxString().contains(findString)){ + foundCount++; + // Print each task with its index and checkbox format + System.out.println((i+1) + "." + tasks.get(i).checkboxString()); + } + } + + if (foundCount == 0) { + System.out.println("Nothing Here"); + } + } + } + } diff --git a/src/main/java/taskpackage/ToDo.java b/src/main/java/taskpackage/ToDo.java index e36693957..e44429c17 100644 --- a/src/main/java/taskpackage/ToDo.java +++ b/src/main/java/taskpackage/ToDo.java @@ -9,7 +9,7 @@ public class ToDo extends Task { // Constructor for creating a ToDo task public ToDo(String inputString, TaskList tasks, boolean constructorMessage) throws ToDoConstructorException { // Call the parent class (Task) constructor, removing the "todo" prefix from the input - super(inputString.replace("todo ", ""), tasks); + super(inputString, tasks); this.inputString = inputString; // If the task description is empty, throw a custom exception if (this.taskString.isEmpty()) { From 2935ec348ca803e61f1205c97c31781f8e2924cb Mon Sep 17 00:00:00 2001 From: DarkDragoon2002 Date: Thu, 10 Oct 2024 01:34:39 +0800 Subject: [PATCH 23/31] Improved Code Quality --- src/main/java/CommandHandling.java | 24 ++++++++++++------ src/main/java/Parser.java | 2 ++ src/main/java/Storage.java | 25 ++++++++++--------- .../DeadlineConstructorException.java | 10 +++++++- .../EventConstructorException.java | 11 +++++++- src/main/java/taskpackage/Deadline.java | 20 +++++++++++---- src/main/java/taskpackage/Event.java | 25 ++++++++++++++----- src/main/java/taskpackage/TaskList.java | 24 +++++++++++++++++- src/main/java/taskpackage/ToDo.java | 2 +- 9 files changed, 109 insertions(+), 34 deletions(-) diff --git a/src/main/java/CommandHandling.java b/src/main/java/CommandHandling.java index af2085c0a..65a2eada7 100644 --- a/src/main/java/CommandHandling.java +++ b/src/main/java/CommandHandling.java @@ -10,15 +10,16 @@ public class CommandHandling { public static final String BYE_COMMAND = "bye"; public static final String LIST_COMMAND = "list"; public static final String DELETE_COMMAND = "delete "; + public static final String FIND_COMMAND = "find "; public static final String MARK_COMMAND = "mark "; public static final String UNMARK_COMMAND = "unmark "; public static final String TODO_COMMAND = "todo "; public static final String DEADLINE_COMMAND = "deadline "; - public static final String EVENT_COMMAND = "EVENT "; + public static final String EVENT_COMMAND = "event "; public static void deleteCommand(TaskList tasks, String line, UI ui) { try { - int taskIndex = Integer.parseInt(line.replace("delete ", "")) - 1; // Parse the task index + int taskIndex = Integer.parseInt(line.replace(DELETE_COMMAND, "")) - 1; // Parse the task index tasks.deleteTask(taskIndex); // Mark the task as done } catch (NumberFormatException | IndexOutOfBoundsException e) { // Handle invalid index or format exceptions @@ -29,9 +30,18 @@ public static void deleteCommand(TaskList tasks, String line, UI ui) { } } + public static void findCommand(TaskList tasks, String line, UI ui) { + String findString = line.replace(FIND_COMMAND, ""); + if (findString.isEmpty()) { + ui.porFavorMessage("FIND EXCEPTION: INVALID TASK INDEX"); + return; + } + tasks.findTasksList(findString); + } + public static void markCommand(TaskList tasks, String line, UI ui) { try { - int taskIndex = Integer.parseInt(line.replace("mark ", "")) - 1; // Parse the task index + int taskIndex = Integer.parseInt(line.replace(MARK_COMMAND, "")) - 1; // Parse the task index tasks.mark(taskIndex); // Mark the task as done } catch (NumberFormatException | IndexOutOfBoundsException e) { // Handle invalid index or format exceptions @@ -44,7 +54,7 @@ public static void markCommand(TaskList tasks, String line, UI ui) { public static void unmarkCommand(TaskList tasks, String line, UI ui) { try { - int taskIndex = Integer.parseInt(line.replace("unmark ", "")) - 1; // Parse the task index + int taskIndex = Integer.parseInt(line.replace(UNMARK_COMMAND, "")) - 1; // Parse the task index tasks.unmark(taskIndex); // Unmark the task } catch (NumberFormatException | IndexOutOfBoundsException e) { // Handle invalid index or format exceptions @@ -57,7 +67,7 @@ public static void unmarkCommand(TaskList tasks, String line, UI ui) { public static void addTodoCommand(TaskList tasks, String line, UI ui) { try { - new ToDo(line, tasks, true); // Create a new ToDo object + new ToDo(line.replace(TODO_COMMAND, ""), tasks, true); // Create a new ToDo object } catch (ToDoConstructorException e) { // Handle custom ToDo exception ui.porFavorMessage(e.getMessage()); @@ -67,7 +77,7 @@ public static void addTodoCommand(TaskList tasks, String line, UI ui) { public static void addDeadlineCommand(TaskList tasks, String line, UI ui) { try { - new Deadline(line, tasks, true); // Create a new Deadline object + new Deadline(line.replace(DEADLINE_COMMAND, ""), tasks, true); // Create a new Deadline object } catch (DeadlineConstructorException e) { // Handle custom Deadline exception ui.porFavorMessage(e.getMessage()); @@ -77,7 +87,7 @@ public static void addDeadlineCommand(TaskList tasks, String line, UI ui) { public static void addEventCommand(TaskList tasks, String line, UI ui) { try { - new Event(line, tasks, true); // Create a new Event object + new Event(line.replace(EVENT_COMMAND, ""), tasks, true); // Create a new Event object } catch (EventConstructorException e) { // Handle custom Event exception ui.porFavorMessage(e.getMessage()); diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index 1fb4f5514..4a9176a0e 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -24,6 +24,8 @@ public boolean chatFeature(String line) { tasks.printTasksList(); // Print task list from Task class } else if (line.startsWith(CommandHandling.DELETE_COMMAND)) { CommandHandling.deleteCommand(tasks, line, ui); + } else if (line.startsWith(CommandHandling.FIND_COMMAND)) { + CommandHandling.findCommand(tasks, line, ui); } else if (line.startsWith(CommandHandling.MARK_COMMAND)) { CommandHandling.markCommand(tasks, line, ui); } else if (line.startsWith(CommandHandling.UNMARK_COMMAND)) { diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index a5cfdcf9a..55d306b1b 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -32,6 +32,7 @@ public TaskList readData() { } catch (Exception e) { ui.printMessage("ERROR READING LINE: " + inputLine); + ui.printMessage(e.getMessage()); } } ui.printMessage("Data File Read"); @@ -43,7 +44,7 @@ public TaskList readData() { return tempTaskList; } - private void handleDataLine(String inputLine, TaskList tempTaskList) { + private void handleDataLine(String inputLine, TaskList taskList) { String[] lineSegments = inputLine.split(" /isdone "); String line = lineSegments[0]; boolean isDone; @@ -52,39 +53,39 @@ private void handleDataLine(String inputLine, TaskList tempTaskList) { } else if (lineSegments[1].trim().equals("false")) { isDone = false; } else { - ui.printMessage("ERROR READING LINE: " + inputLine); + ui.printMessage("ERROR READING ISDONE VALUE: " + inputLine); return; } - if (line.startsWith("todo ")) { + if (line.startsWith(CommandHandling.TODO_COMMAND)) { try { - new ToDo(line, tempTaskList, false); // Create a new ToDo object + new ToDo(line.replace(CommandHandling.TODO_COMMAND, ""), taskList, false); // Create a new ToDo object } catch (ToDoConstructorException e) { // Handle custom ToDo exception ui.printMessage("CORRUPTED: " + line); - tempTaskList.deleteLatestTask(); + taskList.deleteLatestTask(); } - } else if (line.startsWith("deadline ")) { + } else if (line.startsWith(CommandHandling.DEADLINE_COMMAND)) { try { - new Deadline(line, tempTaskList, false); // Create a new Deadline object + new Deadline(line.replace(CommandHandling.DEADLINE_COMMAND, ""), taskList, false); // Create a new Deadline object } catch (DeadlineConstructorException e) { // Handle custom Deadline exception ui.printMessage("CORRUPTED: " + line); - tempTaskList.deleteLatestTask(); + taskList.deleteLatestTask(); } - } else if (line.startsWith("event ")) { + } else if (line.startsWith(CommandHandling.EVENT_COMMAND)) { try { - new Event(line, tempTaskList, false); // Create a new Event object + new Event(line.replace(CommandHandling.EVENT_COMMAND, ""), taskList, false); // Create a new Event object } catch (EventConstructorException e) { // Handle custom Event exception ui.printMessage("CORRUPTED: " + line); - tempTaskList.deleteLatestTask(); + taskList.deleteLatestTask(); } } else { ui.printMessage("CORRUPTED: " + line); } if (isDone) { - tempTaskList.markLatestTask(); + taskList.markLatestTask(); } } diff --git a/src/main/java/customexceptions/DeadlineConstructorException.java b/src/main/java/customexceptions/DeadlineConstructorException.java index 34fe91d9b..9225c9831 100644 --- a/src/main/java/customexceptions/DeadlineConstructorException.java +++ b/src/main/java/customexceptions/DeadlineConstructorException.java @@ -1,5 +1,7 @@ package customexceptions; // Package for custom exceptions -import taskpackage.Task; // Import Task class to manage task deletion + +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; // Custom exception class for handling errors in Deadline task construction public class DeadlineConstructorException extends Exception { @@ -26,6 +28,12 @@ private static String errorMessage(String message) { return "MISSING TASK STATEMENT"; // Return specific error if no task description } + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HHmm"); + try { + dateTimeFormatter.parse(taskStringBreakdown[1]); + } catch (DateTimeParseException e) { + return "INVALID DATETIME EXCEPTION"; + } // If none of the specific errors match, return an unknown error return "UNKNOWN ERROR"; } diff --git a/src/main/java/customexceptions/EventConstructorException.java b/src/main/java/customexceptions/EventConstructorException.java index c28106652..634ec1849 100644 --- a/src/main/java/customexceptions/EventConstructorException.java +++ b/src/main/java/customexceptions/EventConstructorException.java @@ -1,5 +1,7 @@ package customexceptions; // Package for custom exceptions -import taskpackage.Task; // Import Task class to manage task deletion + +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; // Custom exception class for handling errors in Event task construction public class EventConstructorException extends Exception { @@ -34,6 +36,13 @@ private static String errorMessage(String message) { if (fromToStringBreakdown.length != 2) { return "MISSING FROM/TO DATES"; // Return specific error if either "from" or "to" date is missing } + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HHmm"); + try { + dateTimeFormatter.parse(fromToStringBreakdown[0]); + dateTimeFormatter.parse(fromToStringBreakdown[1]); + } catch (DateTimeParseException e) { + return "INVALID DATETIME EXCEPTION"; + } // If none of the specific errors match, return an unknown error return "UNKNOWN ERROR"; diff --git a/src/main/java/taskpackage/Deadline.java b/src/main/java/taskpackage/Deadline.java index 59d0b09c2..54809a25b 100644 --- a/src/main/java/taskpackage/Deadline.java +++ b/src/main/java/taskpackage/Deadline.java @@ -2,25 +2,34 @@ import customexceptions.DeadlineConstructorException; // Import custom exception for Deadline tasks +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; + // Deadline class, a child class of Task, represents a task with a specific deadline public class Deadline extends Task { // Variable to store the deadline date/time string - private final String deadlineString; + private final LocalDateTime deadlineDateTime; + private final static String DATE_TIME_FORMAT = "dd-MM-yyyy HH:mm"; // Constructor for creating a Deadline task public Deadline(String inputString, TaskList tasks, boolean constructorMessage) throws DeadlineConstructorException { // Call the parent class (Task) constructor with the task description (before the "/by" keyword) - super(inputString.replace("deadline ", "").split(" /by ")[0], tasks); + super(inputString.split(" /by ")[0], tasks); this.inputString = inputString; // Check if the "/by" keyword is missing or if the task description is empty if (!(inputString.contains(" /by ")) || this.taskString.isEmpty()) { throw new DeadlineConstructorException(inputString); // Throw custom exception if validation fails } - // Extract the deadline portion of the input string (after the "/by" keyword) - this.deadlineString = inputString.replace("deadline ", "").split(" /by ")[1]; + try { + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(DATE_TIME_FORMAT); + this.deadlineDateTime = LocalDateTime.parse(inputString.replace("deadline ", "").split(" /by ")[1], dateTimeFormatter); + } catch (DateTimeParseException e) { + throw new DeadlineConstructorException(inputString); + } // Display a confirmation message when a Deadline task is successfully created if (constructorMessage) { @@ -32,6 +41,7 @@ public Deadline(String inputString, TaskList tasks, boolean constructorMessage) @Override public String checkboxString() { // Call the parent method and add the "[D]" tag and deadline string to the checkbox format - return "[D]" + super.checkboxString() + " (by: " + deadlineString + ")"; + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(DATE_TIME_FORMAT); + return "[D]" + super.checkboxString() + " (by: " + deadlineDateTime.format(dateTimeFormatter) + ")"; } } diff --git a/src/main/java/taskpackage/Event.java b/src/main/java/taskpackage/Event.java index 05f463ec5..3b0ff2328 100644 --- a/src/main/java/taskpackage/Event.java +++ b/src/main/java/taskpackage/Event.java @@ -1,18 +1,25 @@ package taskpackage; // Package for Task-related classes +import customexceptions.DeadlineConstructorException; import customexceptions.EventConstructorException; // Import custom exception for Event tasks +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; + // Event class, a child class of Task, represents a task with a specific start and end time public class Event extends Task { // Variables to store the start and end times of the event - private final String fromString; - private final String toString; + private final LocalDateTime fromDateTime; + private final LocalDateTime toDateTime; + + private final static String DATE_TIME_FORMAT = "dd-MM-yyyy HH:mm"; // Constructor for creating an Event task public Event(String inputString, TaskList tasks, boolean constructorMessage) throws EventConstructorException { // Call the parent class (Task) constructor with the task description (before the "/from" keyword) - super(inputString.replace("event ", "").split(" /from ")[0], tasks); + super(inputString.split(" /from ")[0], tasks); this.inputString = inputString; @@ -30,8 +37,13 @@ public Event(String inputString, TaskList tasks, boolean constructorMessage) thr } // Set the from and to times for the event - this.fromString = fromToStrings[0]; - this.toString = fromToStrings[1]; + try { + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(DATE_TIME_FORMAT); + this.fromDateTime = LocalDateTime.parse(fromToStrings[0], dateTimeFormatter); + this.toDateTime = LocalDateTime.parse(fromToStrings[1], dateTimeFormatter); + } catch (DateTimeParseException e) { + throw new EventConstructorException(inputString); + } // Display a confirmation message when an Event task is successfully created if (constructorMessage) { @@ -42,7 +54,8 @@ public Event(String inputString, TaskList tasks, boolean constructorMessage) thr // Override the checkboxString method to include the "[E]" tag, start time, and end time @Override public String checkboxString() { + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(DATE_TIME_FORMAT); // Call the parent method and add the "[E]" tag along with the event's start and end times - return "[E]" + super.checkboxString() + " (from: " + fromString + " to: " + toString + ")"; + return "[E]" + super.checkboxString() + " (from: " + fromDateTime.format(dateTimeFormatter) + " to: " + toDateTime.format(dateTimeFormatter) + ")"; } } diff --git a/src/main/java/taskpackage/TaskList.java b/src/main/java/taskpackage/TaskList.java index 119ea9d27..3a546218d 100644 --- a/src/main/java/taskpackage/TaskList.java +++ b/src/main/java/taskpackage/TaskList.java @@ -55,7 +55,7 @@ public void printTasksList(){ if (tasks.isEmpty()){ System.out.println("Por Favor? Nothing Here"); // Message when there are no tasks } else { - System.out.println("Si compinche, your tasks:"); // Message when displaying tasks + System.out.println("Si compinche, your " + tasks.size() + " tasks:"); // Message when displaying tasks for (int i = 0; i < tasks.size(); i++){ // Print each task with its index and checkbox format System.out.println((i+1) + "." + tasks.get(i).checkboxString()); @@ -63,4 +63,26 @@ public void printTasksList(){ } } + // Static method to print all tasks in the list + public void findTasksList(String findString){ + if (tasks.isEmpty()){ + System.out.println("Por Favor? Nothing Here"); // Message when there are no tasks + } else { + System.out.println("Si compinche, your tasks with the phrase <" + findString + ">:"); // Message when displaying tasks + int foundCount = 0; + for (int i = 0; i < tasks.size(); i++){ + // Check if findString in checkboxString + if (tasks.get(i).checkboxString().contains(findString)){ + foundCount++; + // Print each task with its index and checkbox format + System.out.println((i+1) + "." + tasks.get(i).checkboxString()); + } + } + + if (foundCount == 0) { + System.out.println("Nothing Here"); + } + } + } + } diff --git a/src/main/java/taskpackage/ToDo.java b/src/main/java/taskpackage/ToDo.java index e36693957..e44429c17 100644 --- a/src/main/java/taskpackage/ToDo.java +++ b/src/main/java/taskpackage/ToDo.java @@ -9,7 +9,7 @@ public class ToDo extends Task { // Constructor for creating a ToDo task public ToDo(String inputString, TaskList tasks, boolean constructorMessage) throws ToDoConstructorException { // Call the parent class (Task) constructor, removing the "todo" prefix from the input - super(inputString.replace("todo ", ""), tasks); + super(inputString, tasks); this.inputString = inputString; // If the task description is empty, throw a custom exception if (this.taskString.isEmpty()) { From 936c109ac23b283d345675cbb9ea7fd8baae2ae6 Mon Sep 17 00:00:00 2001 From: DarkDragoon2002 Date: Thu, 10 Oct 2024 02:20:05 +0800 Subject: [PATCH 24/31] Updated UI-Text-Testing Files --- data.text | 8 ++--- text-ui-test/EXPECTED.TXT | 68 +++++++++++++++++++++------------------ text-ui-test/input.txt | 10 +++--- 3 files changed, 46 insertions(+), 40 deletions(-) diff --git a/data.text b/data.text index b01de328c..60f7bed50 100644 --- a/data.text +++ b/data.text @@ -1,4 +1,4 @@ -todo go to class /isdone true -todo say hi /isdone false -deadline go for meeting /by 01-01-2000 00:00 /isdone true -event Senior Seminar RC4 /from 10-10-2024 14:00 /to 10-10-2024 17:00 /isdone true +go to class /isdone true +say hi /isdone false +go for meeting /by 01-01-2000 00:00 /isdone true +Senior Seminar RC4 /from 10-10-2024 14:00 /to 10-10-2024 17:00 /isdone true diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 401936b20..8b19cf0f6 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,3 +1,4 @@ +Data File Read ____________________________________________________________ ._-'-_ . . ' /_-_-_\ ` . @@ -10,52 +11,55 @@ ____________________________________________________________ _-| \___ ___/ /-_ (_ )__\_)\(_/__( _) ))))\X\ (((( - \/ \/ -Hola Amigo, I am Juan Cervantes Salamanca from Michoacan -Welcome to la familia -How can we help you? + \/ \/ +Hola Amigo, I am Juan Cervantes Salamanca from Michoacan +Welcome to la familia +How can we help you? ____________________________________________________________ -event La Familia Meeting /from 5pm /to 6pm ____________________________________________________________ -Muy Bien, work hard compadre! -I've Added the taskpackage.Task: -[E][ ] La Familia Meeting (from: 5pm to: 6pm) -You've got 1 tasks, better start working! +Si compinche, your 4 tasks: +1.[T][X] go to class +2.[T][ ] say hi +3.[D][X] go for meeting (by: 01-01-2000 00:00) +4.[E][X] Senior Seminar RC4 (from: 10-10-2024 14:00 to: 10-10-2024 17:00) ____________________________________________________________ -deadline Fry the Pollo with the Hermanos /by 5th July ____________________________________________________________ -Muy Bien, work hard compadre! -I've Added the taskpackage.Task: -[D][ ] Fry the Pollo with the Hermanos (by: 5th July) -You've got 2 tasks, better start working! +Si compinche, your tasks with the phrase : +4.[E][X] Senior Seminar RC4 (from: 10-10-2024 14:00 to: 10-10-2024 17:00) +____________________________________________________________ +____________________________________________________________ +Ay Caramba, I unmarked it: +[E][ ] Senior Seminar RC4 (from: 10-10-2024 14:00 to: 10-10-2024 17:00) +____________________________________________________________ +____________________________________________________________ +Fantastica!!!! I marked it: +[E][X] Senior Seminar RC4 (from: 10-10-2024 14:00 to: 10-10-2024 17:00) ____________________________________________________________ -todo eat the pollo ____________________________________________________________ Muy Bien, work hard compadre! -I've Added the taskpackage.Task: -[T][ ] eat the pollo -You've got 3 tasks, better start working! +I've Added the Task: +[T][ ] graduate ____________________________________________________________ -list ____________________________________________________________ -Si compinche, your tasks: -1.[E][ ] La Familia Meeting (from: 5pm to: 6pm) -2.[D][ ] Fry the Pollo with the Hermanos (by: 5th July) -3.[T][ ] eat the pollo +Si compinche, your 5 tasks: +1.[T][X] go to class +2.[T][ ] say hi +3.[D][X] go for meeting (by: 01-01-2000 00:00) +4.[E][X] Senior Seminar RC4 (from: 10-10-2024 14:00 to: 10-10-2024 17:00) +5.[T][ ] graduate ____________________________________________________________ -mark 2 ____________________________________________________________ -Fantastica!!!! I marked it: -[D][X] Fry the Pollo with the Hermanos (by: 5th July) +Ay Caramba, Task deleted: [T][ ] graduate +____________________________________________________________ ____________________________________________________________ -list +Si compinche, your 4 tasks: +1.[T][X] go to class +2.[T][ ] say hi +3.[D][X] go for meeting (by: 01-01-2000 00:00) +4.[E][X] Senior Seminar RC4 (from: 10-10-2024 14:00 to: 10-10-2024 17:00) ____________________________________________________________ -Si compinche, your tasks: -1.[E][ ] La Familia Meeting (from: 5pm to: 6pm) -2.[D][X] Fry the Pollo with the Hermanos (by: 5th July) -3.[T][ ] eat the pollo ____________________________________________________________ -bye +Data File Written ____________________________________________________________ Adios amigo, la familia will miss you ____________________________________________________________ \ No newline at end of file diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index 250e6e539..826a2abc0 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -1,7 +1,9 @@ -event La Familia Meeting /from 5pm /to 6pm -deadline Fry the Pollo with the Hermanos /by 5th July -todo eat the pollo list -mark 2 +find Senior +unmark 4 +mark 4 +todo graduate +list +delete 5 list bye \ No newline at end of file From 42cbb2cb372c3e00c0e29d87ddb314d6a07f59f4 Mon Sep 17 00:00:00 2001 From: DarkDragoon2002 Date: Thu, 10 Oct 2024 03:03:03 +0800 Subject: [PATCH 25/31] Updated JavaDoc Comments --- src/main/java/CommandHandling.java | 65 ++++++++-- src/main/java/Juan.java | 36 +++--- src/main/java/Parser.java | 29 ++++- src/main/java/Storage.java | 28 ++++- src/main/java/UI.java | 40 +++++-- .../DeadlineConstructorException.java | 35 +++--- .../EventConstructorException.java | 41 +++---- .../ToDoConstructorException.java | 32 ++--- src/main/java/taskpackage/Deadline.java | 39 +++--- src/main/java/taskpackage/Event.java | 44 +++---- src/main/java/taskpackage/Task.java | 41 ++++--- src/main/java/taskpackage/TaskList.java | 113 ++++++++++++------ src/main/java/taskpackage/ToDo.java | 30 +++-- 13 files changed, 385 insertions(+), 188 deletions(-) diff --git a/src/main/java/CommandHandling.java b/src/main/java/CommandHandling.java index 65a2eada7..4e6c63f2b 100644 --- a/src/main/java/CommandHandling.java +++ b/src/main/java/CommandHandling.java @@ -6,6 +6,9 @@ import taskpackage.TaskList; import taskpackage.ToDo; +/** + * Handles various user commands related to tasks such as adding, deleting, finding, and marking tasks. + */ public class CommandHandling { public static final String BYE_COMMAND = "bye"; public static final String LIST_COMMAND = "list"; @@ -17,19 +20,31 @@ public class CommandHandling { public static final String DEADLINE_COMMAND = "deadline "; public static final String EVENT_COMMAND = "event "; + /** + * Deletes a task from the task list based on the user input. + * + * @param tasks The task list from which to delete the task. + * @param line The user input line. + * @param ui The user interface to display messages. + */ public static void deleteCommand(TaskList tasks, String line, UI ui) { try { int taskIndex = Integer.parseInt(line.replace(DELETE_COMMAND, "")) - 1; // Parse the task index - tasks.deleteTask(taskIndex); // Mark the task as done + tasks.deleteTask(taskIndex); // Delete the task } catch (NumberFormatException | IndexOutOfBoundsException e) { - // Handle invalid index or format exceptions ui.porFavorMessage("DELETE EXCEPTION: INVALID TASK INDEX"); } catch (NullPointerException e) { - // Handle null task case ui.porFavorMessage("DELETE EXCEPTION: NULL TASK INDEX"); } } + /** + * Finds tasks in the task list that match the search string. + * + * @param tasks The task list to search in. + * @param line The user input line containing the search string. + * @param ui The user interface to display messages. + */ public static void findCommand(TaskList tasks, String line, UI ui) { String findString = line.replace(FIND_COMMAND, ""); if (findString.isEmpty()) { @@ -39,61 +54,87 @@ public static void findCommand(TaskList tasks, String line, UI ui) { tasks.findTasksList(findString); } + /** + * Marks a task as done in the task list based on user input. + * + * @param tasks The task list containing the task to be marked. + * @param line The user input line specifying the task index. + * @param ui The user interface to display messages. + */ public static void markCommand(TaskList tasks, String line, UI ui) { try { int taskIndex = Integer.parseInt(line.replace(MARK_COMMAND, "")) - 1; // Parse the task index tasks.mark(taskIndex); // Mark the task as done } catch (NumberFormatException | IndexOutOfBoundsException e) { - // Handle invalid index or format exceptions ui.porFavorMessage("MARK EXCEPTION: INVALID TASK INDEX"); } catch (NullPointerException e) { - // Handle null task case ui.porFavorMessage("MARK EXCEPTION: NULL TASK INDEX"); } } + /** + * Unmarks a task as not done in the task list based on user input. + * + * @param tasks The task list containing the task to be unmarked. + * @param line The user input line specifying the task index. + * @param ui The user interface to display messages. + */ public static void unmarkCommand(TaskList tasks, String line, UI ui) { try { int taskIndex = Integer.parseInt(line.replace(UNMARK_COMMAND, "")) - 1; // Parse the task index tasks.unmark(taskIndex); // Unmark the task } catch (NumberFormatException | IndexOutOfBoundsException e) { - // Handle invalid index or format exceptions ui.porFavorMessage("UNMARK EXCEPTION: INVALID TASK INDEX"); } catch (NullPointerException e) { - // Handle null task case ui.porFavorMessage("UNMARK EXCEPTION: NULL TASK INDEX"); } } + /** + * Adds a new to-do task to the task list based on user input. + * + * @param tasks The task list to add the to-do task to. + * @param line The user input line containing the to-do details. + * @param ui The user interface to display messages. + */ public static void addTodoCommand(TaskList tasks, String line, UI ui) { try { new ToDo(line.replace(TODO_COMMAND, ""), tasks, true); // Create a new ToDo object } catch (ToDoConstructorException e) { - // Handle custom ToDo exception ui.porFavorMessage(e.getMessage()); tasks.deleteLatestTask(); } } + /** + * Adds a new deadline task to the task list based on user input. + * + * @param tasks The task list to add the deadline task to. + * @param line The user input line containing the deadline details. + * @param ui The user interface to display messages. + */ public static void addDeadlineCommand(TaskList tasks, String line, UI ui) { try { new Deadline(line.replace(DEADLINE_COMMAND, ""), tasks, true); // Create a new Deadline object } catch (DeadlineConstructorException e) { - // Handle custom Deadline exception ui.porFavorMessage(e.getMessage()); tasks.deleteLatestTask(); } } + /** + * Adds a new event task to the task list based on user input. + * + * @param tasks The task list to add the event task to. + * @param line The user input line containing the event details. + * @param ui The user interface to display messages. + */ public static void addEventCommand(TaskList tasks, String line, UI ui) { try { new Event(line.replace(EVENT_COMMAND, ""), tasks, true); // Create a new Event object } catch (EventConstructorException e) { - // Handle custom Event exception ui.porFavorMessage(e.getMessage()); tasks.deleteLatestTask(); } } - } - diff --git a/src/main/java/Juan.java b/src/main/java/Juan.java index 34cedb58b..3a7e444e3 100644 --- a/src/main/java/Juan.java +++ b/src/main/java/Juan.java @@ -1,17 +1,24 @@ import taskpackage.TaskList; +/** + * Main class for the Juan task manager. + * This class handles the initialization of the system, including user interface, storage, and task list management. + */ public class Juan { - private final static String dataFilePath = "data.text"; private final UI ui; private final Storage storage; private TaskList tasks; private final Parser parser; - // Constructor + /** + * Constructor for Juan. + * Initializes the user interface, storage, and task list. + * + * @param dataFilePath Path to the file for storing task data. + */ public Juan(String dataFilePath) { - ui = new UI(); storage = new Storage(dataFilePath, ui); try { @@ -22,28 +29,29 @@ public Juan(String dataFilePath) { parser = new Parser(ui, tasks); } - // Main running function + /** + * Main running function of Juan. + * Displays welcome message, handles user input, and writes task data to the file upon termination. + */ public void run() { + ui.helloMessage(); // Display welcome message - // Display initial line and welcome message - ui.helloMessage(); - - // Continue chatting as long as user doesn't exit boolean continueChatting = true; while (continueChatting) { - // Chat feature to handle user input continueChatting = parser.chatFeature(ui.readUserInput()); } - // Add Function to Write Data - storage.writeDate(parser.getTasks()); + storage.writeDate(parser.getTasks()); // Write task data to file ui.lineMessage(); - // Display goodbye message when the chat ends - ui.byeMessage(); + ui.byeMessage(); // Display goodbye message } + /** + * Main method to start the Juan application. + * + * @param args Command-line arguments (not used). + */ public static void main(String[] args) { new Juan(dataFilePath).run(); } - } diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index 4a9176a0e..ea782a731 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -1,27 +1,46 @@ import taskpackage.TaskList; +/** + * The parser class handles user input and interprets commands for the task manager. + */ public class Parser { private final UI ui; private final TaskList tasks; + /** + * Constructor for Parser. + * + * @param ui The user interface to interact with the user. + * @param tasks The task list to manage tasks. + */ public Parser(UI ui, TaskList tasks) { this.ui = ui; this.tasks = tasks; } - public TaskList getTasks() { return tasks; } + /** + * Returns the current task list. + * + * @return The task list. + */ + public TaskList getTasks() { + return tasks; + } - // Handles user input and executes corresponding actions + /** + * Handles user input and executes the corresponding commands based on the input. + * + * @param line The user input. + * @return True if the chat should continue, false if the "bye" command was given. + */ public boolean chatFeature(String line) { - ui.lineMessage(); // Print separator line - // Handle "bye" command to end chat if (line.equals(CommandHandling.BYE_COMMAND)) { return false; // End the conversation } else if (line.equals(CommandHandling.LIST_COMMAND)) { - tasks.printTasksList(); // Print task list from Task class + tasks.printTasksList(); } else if (line.startsWith(CommandHandling.DELETE_COMMAND)) { CommandHandling.deleteCommand(tasks, line, ui); } else if (line.startsWith(CommandHandling.FIND_COMMAND)) { diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index 55d306b1b..41375adfe 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -9,16 +9,30 @@ import java.io.IOException; import java.util.Scanner; +/** + * The Storage class handles reading and writing task data from and to a file. + */ public class Storage { private final String dataFilePath; private final UI ui; + /** + * Constructor for Storage. + * + * @param dataFilePath Path to the file for storing task data. + * @param ui The user interface to display messages. + */ public Storage(String dataFilePath, UI ui) { this.dataFilePath = dataFilePath; this.ui = ui; } + /** + * Reads task data from the file and returns a TaskList. + * + * @return A TaskList containing the tasks from the file. + */ public TaskList readData() { TaskList tempTaskList = new TaskList(); @@ -44,6 +58,12 @@ public TaskList readData() { return tempTaskList; } + /** + * Handles each line of the data file and adds the corresponding task to the TaskList. + * + * @param inputLine The line from the data file. + * @param taskList The TaskList to which the task will be added. + */ private void handleDataLine(String inputLine, TaskList taskList) { String[] lineSegments = inputLine.split(" /isdone "); String line = lineSegments[0]; @@ -60,7 +80,6 @@ private void handleDataLine(String inputLine, TaskList taskList) { try { new ToDo(line.replace(CommandHandling.TODO_COMMAND, ""), taskList, false); // Create a new ToDo object } catch (ToDoConstructorException e) { - // Handle custom ToDo exception ui.printMessage("CORRUPTED: " + line); taskList.deleteLatestTask(); } @@ -68,7 +87,6 @@ private void handleDataLine(String inputLine, TaskList taskList) { try { new Deadline(line.replace(CommandHandling.DEADLINE_COMMAND, ""), taskList, false); // Create a new Deadline object } catch (DeadlineConstructorException e) { - // Handle custom Deadline exception ui.printMessage("CORRUPTED: " + line); taskList.deleteLatestTask(); } @@ -76,7 +94,6 @@ private void handleDataLine(String inputLine, TaskList taskList) { try { new Event(line.replace(CommandHandling.EVENT_COMMAND, ""), taskList, false); // Create a new Event object } catch (EventConstructorException e) { - // Handle custom Event exception ui.printMessage("CORRUPTED: " + line); taskList.deleteLatestTask(); } @@ -89,6 +106,11 @@ private void handleDataLine(String inputLine, TaskList taskList) { } } + /** + * Writes the task data to the file. + * + * @param taskList The TaskList to write to the file. + */ public void writeDate(TaskList taskList) { try { FileWriter writer = new FileWriter(dataFilePath); diff --git a/src/main/java/UI.java b/src/main/java/UI.java index 18b105ba5..ca87e8b80 100644 --- a/src/main/java/UI.java +++ b/src/main/java/UI.java @@ -1,5 +1,8 @@ import java.util.Scanner; // Import Scanner for user input +/** + * The UI class handles interaction with the user by reading input and displaying output messages. + */ public class UI { // Constant for common error message to improve code readability and reusability @@ -25,43 +28,62 @@ public class UI { private Scanner scanner; + /** + * Constructor for UI. + * Initializes the scanner for reading user input. + */ public UI() { scanner = new Scanner(System.in); // Initialize the scanner for reading user input } - // Function to read user input + /** + * Reads the user's input from the console. + * + * @return The user's input as a String. + */ public String readUserInput() { return scanner.nextLine(); // Read user input } - // Function to print out any messages + /** + * Prints a message to the console. + * + * @param message The message to be printed. + */ public void printMessage(String message) { System.out.println(message); } - // Utility function to print a separator line for clean output formatting + /** + * Prints a separator line to the console for clean output formatting. + */ public void lineMessage() { System.out.print(SEPARATOR); } - // Displays a Message with por favor message + /** + * Prints a message with a "Por Favor" prefix to the console. + * + * @param message The message to be printed. + */ public void porFavorMessage(String message) { System.out.println(PORFAVOR + message); } - - // Displays a welcome message when the program starts + /** + * Displays a welcome message when the program starts. + */ public void helloMessage() { - System.out.print(SEPARATOR); System.out.print(GREETINGMESSAGE); // Print the welcome message System.out.print(SEPARATOR); } - // Displays a goodbye message when the program ends + /** + * Displays a goodbye message when the program ends. + */ public void byeMessage() { System.out.print(BYEMESSAGE); // Print the goodbye message System.out.print(SEPARATOR); } - } diff --git a/src/main/java/customexceptions/DeadlineConstructorException.java b/src/main/java/customexceptions/DeadlineConstructorException.java index 9225c9831..444b2badb 100644 --- a/src/main/java/customexceptions/DeadlineConstructorException.java +++ b/src/main/java/customexceptions/DeadlineConstructorException.java @@ -3,38 +3,43 @@ import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; -// Custom exception class for handling errors in Deadline task construction +/** + * Custom exception class for handling errors in Deadline task construction. + */ public class DeadlineConstructorException extends Exception { - // Constructor that takes an error message as input + /** + * Constructor that takes an error message as input and generates a custom exception for Deadline tasks. + * + * @param message The error message for the exception. + */ public DeadlineConstructorException(String message) { - // Call the superclass (Exception) constructor with a detailed error message - super("DEADLINE CONSTRUCTOR EXCEPTION: " + errorMessage(message)); + super("DEADLINE CONSTRUCTOR EXCEPTION: " + errorMessage(message)); // Call superclass constructor } - // Private helper method to interpret the error message - // It checks for specific missing components in the deadline command + /** + * Private helper method to interpret and identify specific errors in the deadline command. + * + * @param message The input message that caused the error. + * @return The interpreted error message. + */ private static String errorMessage(String message) { - // Check if the "/by" keyword is missing, which is needed for deadline tasks if (!(message.contains(" /by "))) { - return "MISSING BY COMMAND"; // Return specific error if "/by" is not found + return "MISSING BY COMMAND"; // Error if "/by" is missing } - // Split the task input string into task description and deadline parts String[] taskStringBreakdown = message.replace("deadline ", "").split(" /by "); - - // Check if the task description before "/by" is empty if (taskStringBreakdown[0].isEmpty()) { - return "MISSING TASK STATEMENT"; // Return specific error if no task description + return "MISSING TASK STATEMENT"; // Error if task description is missing } DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HHmm"); try { dateTimeFormatter.parse(taskStringBreakdown[1]); } catch (DateTimeParseException e) { - return "INVALID DATETIME EXCEPTION"; + return "INVALID DATETIME EXCEPTION"; // Error if the date/time format is invalid } - // If none of the specific errors match, return an unknown error - return "UNKNOWN ERROR"; + + return "UNKNOWN ERROR"; // Fallback error message } } diff --git a/src/main/java/customexceptions/EventConstructorException.java b/src/main/java/customexceptions/EventConstructorException.java index 634ec1849..4c4399633 100644 --- a/src/main/java/customexceptions/EventConstructorException.java +++ b/src/main/java/customexceptions/EventConstructorException.java @@ -3,48 +3,49 @@ import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; -// Custom exception class for handling errors in Event task construction +/** + * Custom exception class for handling errors in Event task construction. + */ public class EventConstructorException extends Exception { - // Constructor that takes an error message as input + /** + * Constructor that takes an error message as input and generates a custom exception for Event tasks. + * + * @param message The error message for the exception. + */ public EventConstructorException(String message) { - // Call the superclass (Exception) constructor with a detailed error message - super("EVENT CONSTRUCTOR EXCEPTION: " + errorMessage(message)); - + super("EVENT CONSTRUCTOR EXCEPTION: " + errorMessage(message)); // Call superclass constructor } - // Private helper method to interpret the error message - // It checks for specific missing components in the event command + /** + * Private helper method to interpret and identify specific errors in the event command. + * + * @param message The input message that caused the error. + * @return The interpreted error message. + */ private static String errorMessage(String message) { - // Check if the "/from" and "/to" keywords are missing, which are needed for event tasks if (!(message.contains(" /from ") || message.contains(" /to "))) { - return "MISSING FROM/TO COMMANDS"; // Return specific error if either "/from" or "/to" is missing + return "MISSING FROM/TO COMMANDS"; // Error if "/from" or "/to" is missing } - // Split the task input string into task description and the time period starting with "/from" String[] taskStringBreakdown = message.replace("event ", "").split(" /from "); - - // Check if the task description before "/from" is empty if (taskStringBreakdown[0].isEmpty()) { - return "MISSING TASK STATEMENT"; // Return specific error if no task description is provided + return "MISSING TASK STATEMENT"; // Error if task description is missing } - // Further split the time period into "from" and "to" parts String[] fromToStringBreakdown = taskStringBreakdown[1].split(" /to "); - - // Check if both "from" and "to" components are present if (fromToStringBreakdown.length != 2) { - return "MISSING FROM/TO DATES"; // Return specific error if either "from" or "to" date is missing + return "MISSING FROM/TO DATES"; // Error if either "from" or "to" date is missing } + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HHmm"); try { dateTimeFormatter.parse(fromToStringBreakdown[0]); dateTimeFormatter.parse(fromToStringBreakdown[1]); } catch (DateTimeParseException e) { - return "INVALID DATETIME EXCEPTION"; + return "INVALID DATETIME EXCEPTION"; // Error if the date/time format is invalid } - // If none of the specific errors match, return an unknown error - return "UNKNOWN ERROR"; + return "UNKNOWN ERROR"; // Fallback error message } } diff --git a/src/main/java/customexceptions/ToDoConstructorException.java b/src/main/java/customexceptions/ToDoConstructorException.java index de6858b50..2399e6e90 100644 --- a/src/main/java/customexceptions/ToDoConstructorException.java +++ b/src/main/java/customexceptions/ToDoConstructorException.java @@ -1,29 +1,31 @@ package customexceptions; // Package for custom exceptions -import taskpackage.Task; // Import Task class to manage task deletion -// Custom exception class for handling errors in ToDo task construction +/** + * Custom exception class for handling errors in ToDo task construction. + */ public class ToDoConstructorException extends Exception { - // Constructor that takes an error message as input + /** + * Constructor that takes an error message as input and generates a custom exception for ToDo tasks. + * + * @param message The error message for the exception. + */ public ToDoConstructorException(String message) { - // Call the superclass (Exception) constructor with a detailed error message - super("TODO CONSTRUCTOR EXCEPTION: " + errorMessage(message)); - + super("TODO CONSTRUCTOR EXCEPTION: " + errorMessage(message)); // Call superclass constructor } - // Private helper method to interpret the error message - // It checks for specific missing components in the todo command + /** + * Private helper method to interpret and identify specific errors in the ToDo command. + * + * @param message The input message that caused the error. + * @return The interpreted error message. + */ private static String errorMessage(String message) { - - // Remove the "todo" keyword from the message to isolate the task statement String taskString = message.replace("todo ", ""); - - // Check if the task statement is empty if (taskString.isEmpty()) { - return "MISSING TASK STATEMENT"; // Return specific error if the task description is missing + return "MISSING TASK STATEMENT"; // Error if task description is missing } - // If none of the specific errors match, return an unknown error - return "UNKNOWN ERROR"; + return "UNKNOWN ERROR"; // Fallback error message } } diff --git a/src/main/java/taskpackage/Deadline.java b/src/main/java/taskpackage/Deadline.java index 54809a25b..59b69e489 100644 --- a/src/main/java/taskpackage/Deadline.java +++ b/src/main/java/taskpackage/Deadline.java @@ -6,24 +6,32 @@ import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; -// Deadline class, a child class of Task, represents a task with a specific deadline +/** + * Represents a task with a specific deadline, extending the Task class. + */ public class Deadline extends Task { - // Variable to store the deadline date/time string - private final LocalDateTime deadlineDateTime; - - private final static String DATE_TIME_FORMAT = "dd-MM-yyyy HH:mm"; - - // Constructor for creating a Deadline task + private final LocalDateTime deadlineDateTime; // Stores the deadline date/time + private final static String DATE_TIME_FORMAT = "dd-MM-yyyy HH:mm"; // Format for date and time + + /** + * Constructor for creating a Deadline task. + * + * @param inputString The input string containing the task description and deadline. + * @param tasks The task list to which the task is added. + * @param constructorMessage A flag to indicate whether to display a constructor message. + * @throws DeadlineConstructorException if the task description or deadline is invalid. + */ public Deadline(String inputString, TaskList tasks, boolean constructorMessage) throws DeadlineConstructorException { - // Call the parent class (Task) constructor with the task description (before the "/by" keyword) super(inputString.split(" /by ")[0], tasks); this.inputString = inputString; - // Check if the "/by" keyword is missing or if the task description is empty + + // Check if the "/by" keyword is present and if the task description is valid if (!(inputString.contains(" /by ")) || this.taskString.isEmpty()) { - throw new DeadlineConstructorException(inputString); // Throw custom exception if validation fails + throw new DeadlineConstructorException(inputString); } - // Extract the deadline portion of the input string (after the "/by" keyword) + + // Parse the deadline date/time try { DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(DATE_TIME_FORMAT); this.deadlineDateTime = LocalDateTime.parse(inputString.replace("deadline ", "").split(" /by ")[1], dateTimeFormatter); @@ -31,16 +39,19 @@ public Deadline(String inputString, TaskList tasks, boolean constructorMessage) throw new DeadlineConstructorException(inputString); } - // Display a confirmation message when a Deadline task is successfully created + // Display a confirmation message if the constructorMessage flag is true if (constructorMessage) { constructorMessage(); } } - // Override the checkboxString method to include the "[D]" tag and the deadline information + /** + * Returns the task's string with a checkbox and deadline details. + * + * @return The formatted task string with deadline information. + */ @Override public String checkboxString() { - // Call the parent method and add the "[D]" tag and deadline string to the checkbox format DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(DATE_TIME_FORMAT); return "[D]" + super.checkboxString() + " (by: " + deadlineDateTime.format(dateTimeFormatter) + ")"; } diff --git a/src/main/java/taskpackage/Event.java b/src/main/java/taskpackage/Event.java index 3b0ff2328..603a07cf5 100644 --- a/src/main/java/taskpackage/Event.java +++ b/src/main/java/taskpackage/Event.java @@ -1,42 +1,43 @@ package taskpackage; // Package for Task-related classes -import customexceptions.DeadlineConstructorException; import customexceptions.EventConstructorException; // Import custom exception for Event tasks import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; -// Event class, a child class of Task, represents a task with a specific start and end time +/** + * Represents a task with a specific start and end time, extending the Task class. + */ public class Event extends Task { - // Variables to store the start and end times of the event - private final LocalDateTime fromDateTime; - private final LocalDateTime toDateTime; + private final LocalDateTime fromDateTime; // Stores the event start time + private final LocalDateTime toDateTime; // Stores the event end time + private final static String DATE_TIME_FORMAT = "dd-MM-yyyy HH:mm"; // Format for date and time - private final static String DATE_TIME_FORMAT = "dd-MM-yyyy HH:mm"; - - // Constructor for creating an Event task + /** + * Constructor for creating an Event task. + * + * @param inputString The input string containing the task description, start time, and end time. + * @param tasks The task list to which the task is added. + * @param constructorMessage A flag to indicate whether to display a constructor message. + * @throws EventConstructorException if the task description, start time, or end time is invalid. + */ public Event(String inputString, TaskList tasks, boolean constructorMessage) throws EventConstructorException { - // Call the parent class (Task) constructor with the task description (before the "/from" keyword) super(inputString.split(" /from ")[0], tasks); - this.inputString = inputString; - // Validate if both "/from" and "/to" keywords are present, and the task description is not empty + // Check if both "/from" and "/to" keywords are present and the task description is valid if (!(inputString.contains(" /from ") & inputString.contains(" /to ")) || this.taskString.isEmpty()) { - throw new EventConstructorException(inputString); // Throw custom exception if validation fails + throw new EventConstructorException(inputString); } - // Split the input to extract the start and end times + // Parse the start and end times String[] fromToStrings = inputString.replace("event ", "").split(" /from ")[1].split(" /to "); - - // Check if both "from" and "to" times are provided if (fromToStrings.length != 2) { - throw new EventConstructorException(inputString); // Throw custom exception if either is missing + throw new EventConstructorException(inputString); } - // Set the from and to times for the event try { DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(DATE_TIME_FORMAT); this.fromDateTime = LocalDateTime.parse(fromToStrings[0], dateTimeFormatter); @@ -45,17 +46,20 @@ public Event(String inputString, TaskList tasks, boolean constructorMessage) thr throw new EventConstructorException(inputString); } - // Display a confirmation message when an Event task is successfully created + // Display a confirmation message if the constructorMessage flag is true if (constructorMessage) { constructorMessage(); } } - // Override the checkboxString method to include the "[E]" tag, start time, and end time + /** + * Returns the task's string with a checkbox, start time, and end time. + * + * @return The formatted task string with event details. + */ @Override public String checkboxString() { DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(DATE_TIME_FORMAT); - // Call the parent method and add the "[E]" tag along with the event's start and end times return "[E]" + super.checkboxString() + " (from: " + fromDateTime.format(dateTimeFormatter) + " to: " + toDateTime.format(dateTimeFormatter) + ")"; } } diff --git a/src/main/java/taskpackage/Task.java b/src/main/java/taskpackage/Task.java index b21661dac..9dd2f10cf 100644 --- a/src/main/java/taskpackage/Task.java +++ b/src/main/java/taskpackage/Task.java @@ -1,33 +1,42 @@ package taskpackage; // Package for Task-related classes -// Parent class Task which serves as a base for ToDo, Deadline, and Event tasks +/** + * Represents a general task that can be extended to specific types of tasks such as ToDo, Deadline, and Event. + */ public class Task { - // Array to keep track of all tasks added - public String inputString; - - - // Object-specific variables - public String taskString; // String to hold the task description + public String inputString; // Input string for the task + public String taskString; // Description of the task public boolean isDone = false; // Boolean to track if the task is marked as done - // Constructor Function: initializes a Task object and adds it to the tasks array - public Task(String inputString, TaskList tasks){ + /** + * Constructor for creating a general task. + * + * @param inputString The description of the task. + * @param tasks The task list to which the task is added. + */ + public Task(String inputString, TaskList tasks) { this.taskString = inputString; // Set the task description - tasks.addTask(this); // Add the current task to the array + tasks.addTask(this); // Add the task to the task list } - // Method to display a message when a task is successfully created - public void constructorMessage(){ + /** + * Displays a message confirming the task was successfully created. + */ + public void constructorMessage() { System.out.println("Muy Bien, work hard compadre!"); // Success message in Spanish System.out.println("I've Added the Task:"); System.out.println(checkboxString()); // Display the task in checkbox format } - // Method to create and return a string with a checkbox (marked or unmarked) for the task - public String checkboxString(){ + /** + * Returns the task's string with a checkbox indicating whether it's done. + * + * @return The formatted task string. + */ + public String checkboxString() { String returnString = "["; // Start of the checkbox string - if (this.isDone){ + if (this.isDone) { returnString += "X"; // Mark the checkbox as done if the task is completed } else { returnString += " "; // Leave the checkbox empty if the task is not completed @@ -35,6 +44,4 @@ public String checkboxString(){ returnString += "] " + this.taskString; // Append the task description return returnString; // Return the formatted string } - - } diff --git a/src/main/java/taskpackage/TaskList.java b/src/main/java/taskpackage/TaskList.java index 3a546218d..577a717b2 100644 --- a/src/main/java/taskpackage/TaskList.java +++ b/src/main/java/taskpackage/TaskList.java @@ -2,80 +2,124 @@ import java.util.ArrayList; +/** + * Represents a list of tasks, allowing for operations such as adding, deleting, marking, and unmarking tasks. + */ public class TaskList { - private ArrayList tasks; + private ArrayList tasks; // List to store tasks + + /** + * Constructor for initializing an empty TaskList. + */ public TaskList() { this.tasks = new ArrayList<>(); } + /** + * Adds a task to the task list. + * + * @param task The task to be added. + */ public void addTask(Task task) { this.tasks.add(task); } - public void deleteTask(int taskIndex){ + /** + * Deletes a task from the task list based on the task index. + * + * @param taskIndex The index of the task to be deleted. + */ + public void deleteTask(int taskIndex) { String taskString = this.tasks.get(taskIndex).checkboxString(); this.tasks.remove(taskIndex); System.out.println("Ay Caramba, Task deleted: " + taskString); } - // Static method to delete the latest task in case of errors - public void deleteLatestTask(){ - this.tasks.remove(tasks.size() - 1); // Remove the latest task from the array + /** + * Deletes the latest task in the task list in case of errors. + */ + public void deleteLatestTask() { + this.tasks.remove(tasks.size() - 1); // Remove the latest task from the list } - public void markLatestTask(){ + /** + * Marks the latest task in the task list as done. + */ + public void markLatestTask() { this.tasks.get(tasks.size() - 1).isDone = true; } + /** + * Returns the size of the task list. + * + * @return The number of tasks in the list. + */ public int size() { return this.tasks.size(); } + /** + * Returns the string representation of a task for storing in a data file. + * + * @param index The index of the task. + * @return The formatted string for storing the task data. + */ public String dataFileEntry(int index) { return (this.tasks.get(index).inputString + " /isdone " + this.tasks.get(index).isDone + "\n"); } - // Static method to mark a task as done by index - public void mark(int taskIndex){ - tasks.get(taskIndex).isDone = true; // Mark the task as done - System.out.println("Fantastica!!!! I marked it:"); // Success message in Spanish - System.out.println(tasks.get(taskIndex).checkboxString()); // Display the updated task + /** + * Marks a task as done by its index. + * + * @param taskIndex The index of the task to be marked as done. + */ + public void mark(int taskIndex) { + tasks.get(taskIndex).isDone = true; + System.out.println("Fantastica!!!! I marked it:"); + System.out.println(tasks.get(taskIndex).checkboxString()); } - // Static method to unmark a task as undone by index - public void unmark(int taskIndex){ - tasks.get(taskIndex).isDone = false; // Unmark the task as not done - System.out.println("Ay Caramba, I unmarked it:"); // Message indicating task was unmarked - System.out.println(tasks.get(taskIndex).checkboxString()); // Display the updated task + /** + * Unmarks a task as not done by its index. + * + * @param taskIndex The index of the task to be unmarked. + */ + public void unmark(int taskIndex) { + tasks.get(taskIndex).isDone = false; + System.out.println("Ay Caramba, I unmarked it:"); + System.out.println(tasks.get(taskIndex).checkboxString()); } - // Static method to print all tasks in the list - public void printTasksList(){ - if (tasks.isEmpty()){ - System.out.println("Por Favor? Nothing Here"); // Message when there are no tasks + /** + * Prints the list of tasks to the console. + */ + public void printTasksList() { + if (tasks.isEmpty()) { + System.out.println("Por Favor? Nothing Here"); } else { - System.out.println("Si compinche, your " + tasks.size() + " tasks:"); // Message when displaying tasks - for (int i = 0; i < tasks.size(); i++){ - // Print each task with its index and checkbox format - System.out.println((i+1) + "." + tasks.get(i).checkboxString()); + System.out.println("Si compinche, your " + tasks.size() + " tasks:"); + for (int i = 0; i < tasks.size(); i++) { + System.out.println((i + 1) + "." + tasks.get(i).checkboxString()); } } } - // Static method to print all tasks in the list - public void findTasksList(String findString){ - if (tasks.isEmpty()){ - System.out.println("Por Favor? Nothing Here"); // Message when there are no tasks + /** + * Prints the tasks that contain the specified search string. + * + * @param findString The string to search for in the tasks. + */ + public void findTasksList(String findString) { + if (tasks.isEmpty()) { + System.out.println("Por Favor? Nothing Here"); } else { - System.out.println("Si compinche, your tasks with the phrase <" + findString + ">:"); // Message when displaying tasks + System.out.println("Si compinche, your tasks with the phrase <" + findString + ">:"); int foundCount = 0; - for (int i = 0; i < tasks.size(); i++){ - // Check if findString in checkboxString - if (tasks.get(i).checkboxString().contains(findString)){ + for (int i = 0; i < tasks.size(); i++) { + if (tasks.get(i).checkboxString().contains(findString)) { foundCount++; - // Print each task with its index and checkbox format - System.out.println((i+1) + "." + tasks.get(i).checkboxString()); + System.out.println((i + 1) + "." + tasks.get(i).checkboxString()); } } @@ -84,5 +128,4 @@ public void findTasksList(String findString){ } } } - } diff --git a/src/main/java/taskpackage/ToDo.java b/src/main/java/taskpackage/ToDo.java index e44429c17..d7653fbe5 100644 --- a/src/main/java/taskpackage/ToDo.java +++ b/src/main/java/taskpackage/ToDo.java @@ -2,29 +2,41 @@ import customexceptions.ToDoConstructorException; // Import custom exception for ToDo tasks -// ToDo class, a child class of Task, represents a simple to-do task +/** + * Represents a simple to-do task, extending the Task class. + */ public class ToDo extends Task { - - // Constructor for creating a ToDo task + /** + * Constructor for creating a ToDo task. + * + * @param inputString The description of the to-do task. + * @param tasks The task list to which the task is added. + * @param constructorMessage A flag to indicate whether to display a constructor message. + * @throws ToDoConstructorException if the task description is empty. + */ public ToDo(String inputString, TaskList tasks, boolean constructorMessage) throws ToDoConstructorException { - // Call the parent class (Task) constructor, removing the "todo" prefix from the input super(inputString, tasks); this.inputString = inputString; - // If the task description is empty, throw a custom exception + + // Check if the task description is empty and throw an exception if true if (this.taskString.isEmpty()) { - throw new ToDoConstructorException(inputString); // Handle invalid ToDo input + throw new ToDoConstructorException(inputString); } - // Display a confirmation message when a ToDo task is successfully created + // Display a confirmation message if the constructorMessage flag is true if (constructorMessage) { constructorMessage(); } } - // Override the checkboxString method to prefix "[T]" to indicate that the task is a ToDo + /** + * Returns the task's string with a checkbox, prefixed with "[T]" to indicate it is a ToDo. + * + * @return The formatted task string. + */ @Override public String checkboxString() { - return "[T]" + super.checkboxString(); // Call the parent method and add the "[T]" tag + return "[T]" + super.checkboxString(); } } From e64f9dc6235d67c045b5cd159e1279016ba57736 Mon Sep 17 00:00:00 2001 From: DarkDragoon2002 Date: Thu, 10 Oct 2024 03:25:38 +0800 Subject: [PATCH 26/31] Resolved Merge Conflicts --- data.text | 8 ++++---- src/main/java/taskpackage/Deadline.java | 12 ++++++++---- src/main/java/taskpackage/Event.java | 9 +++++---- src/main/java/taskpackage/Task.java | 10 ++++++++-- src/main/java/taskpackage/TaskList.java | 2 +- src/main/java/taskpackage/ToDo.java | 16 ++++++++++++++-- 6 files changed, 40 insertions(+), 17 deletions(-) diff --git a/data.text b/data.text index 60f7bed50..b01de328c 100644 --- a/data.text +++ b/data.text @@ -1,4 +1,4 @@ -go to class /isdone true -say hi /isdone false -go for meeting /by 01-01-2000 00:00 /isdone true -Senior Seminar RC4 /from 10-10-2024 14:00 /to 10-10-2024 17:00 /isdone true +todo go to class /isdone true +todo say hi /isdone false +deadline go for meeting /by 01-01-2000 00:00 /isdone true +event Senior Seminar RC4 /from 10-10-2024 14:00 /to 10-10-2024 17:00 /isdone true diff --git a/src/main/java/taskpackage/Deadline.java b/src/main/java/taskpackage/Deadline.java index 54809a25b..b696a9e60 100644 --- a/src/main/java/taskpackage/Deadline.java +++ b/src/main/java/taskpackage/Deadline.java @@ -9,17 +9,21 @@ // Deadline class, a child class of Task, represents a task with a specific deadline public class Deadline extends Task { - // Variable to store the deadline date/time string - private final LocalDateTime deadlineDateTime; - private final static String DATE_TIME_FORMAT = "dd-MM-yyyy HH:mm"; + private final LocalDateTime deadlineDateTime; // Stores the deadline date/time + private final static String DATE_TIME_FORMAT = "dd-MM-yyyy HH:mm"; // Format for date and time + private static final String DEADLINE_COMMAND = "deadline "; + // Constructor for creating a Deadline task public Deadline(String inputString, TaskList tasks, boolean constructorMessage) throws DeadlineConstructorException { // Call the parent class (Task) constructor with the task description (before the "/by" keyword) super(inputString.split(" /by ")[0], tasks); this.inputString = inputString; - // Check if the "/by" keyword is missing or if the task description is empty + + this.storageString = DEADLINE_COMMAND + inputString; + + // Check if the "/by" keyword is present and if the task description is valid if (!(inputString.contains(" /by ")) || this.taskString.isEmpty()) { throw new DeadlineConstructorException(inputString); // Throw custom exception if validation fails } diff --git a/src/main/java/taskpackage/Event.java b/src/main/java/taskpackage/Event.java index 3b0ff2328..fd04804c9 100644 --- a/src/main/java/taskpackage/Event.java +++ b/src/main/java/taskpackage/Event.java @@ -10,11 +10,11 @@ // Event class, a child class of Task, represents a task with a specific start and end time public class Event extends Task { - // Variables to store the start and end times of the event - private final LocalDateTime fromDateTime; - private final LocalDateTime toDateTime; + private final LocalDateTime fromDateTime; // Stores the event start time + private final LocalDateTime toDateTime; // Stores the event end time + private final static String DATE_TIME_FORMAT = "dd-MM-yyyy HH:mm"; // Format for date and time + private static final String EVENT_COMMAND = "event "; - private final static String DATE_TIME_FORMAT = "dd-MM-yyyy HH:mm"; // Constructor for creating an Event task public Event(String inputString, TaskList tasks, boolean constructorMessage) throws EventConstructorException { @@ -22,6 +22,7 @@ public Event(String inputString, TaskList tasks, boolean constructorMessage) thr super(inputString.split(" /from ")[0], tasks); this.inputString = inputString; + this.storageString = EVENT_COMMAND + inputString; // Validate if both "/from" and "/to" keywords are present, and the task description is not empty if (!(inputString.contains(" /from ") & inputString.contains(" /to ")) || this.taskString.isEmpty()) { diff --git a/src/main/java/taskpackage/Task.java b/src/main/java/taskpackage/Task.java index b21661dac..1fa0f39a7 100644 --- a/src/main/java/taskpackage/Task.java +++ b/src/main/java/taskpackage/Task.java @@ -11,8 +11,14 @@ public class Task { public String taskString; // String to hold the task description public boolean isDone = false; // Boolean to track if the task is marked as done - // Constructor Function: initializes a Task object and adds it to the tasks array - public Task(String inputString, TaskList tasks){ + public String storageString; + /** + * Constructor for creating a general task. + * + * @param inputString The description of the task. + * @param tasks The task list to which the task is added. + */ + public Task(String inputString, TaskList tasks) { this.taskString = inputString; // Set the task description tasks.addTask(this); // Add the current task to the array } diff --git a/src/main/java/taskpackage/TaskList.java b/src/main/java/taskpackage/TaskList.java index 3a546218d..03c649f1f 100644 --- a/src/main/java/taskpackage/TaskList.java +++ b/src/main/java/taskpackage/TaskList.java @@ -33,7 +33,7 @@ public int size() { } public String dataFileEntry(int index) { - return (this.tasks.get(index).inputString + " /isdone " + this.tasks.get(index).isDone + "\n"); + return (this.tasks.get(index).storageString + " /isdone " + this.tasks.get(index).isDone + "\n"); } // Static method to mark a task as done by index diff --git a/src/main/java/taskpackage/ToDo.java b/src/main/java/taskpackage/ToDo.java index e44429c17..482f3c0ef 100644 --- a/src/main/java/taskpackage/ToDo.java +++ b/src/main/java/taskpackage/ToDo.java @@ -6,12 +6,24 @@ public class ToDo extends Task { - // Constructor for creating a ToDo task + private static final String TODO_COMMAND = "todo "; + + /** + * Constructor for creating a ToDo task. + * + * @param inputString The description of the to-do task. + * @param tasks The task list to which the task is added. + * @param constructorMessage A flag to indicate whether to display a constructor message. + * @throws ToDoConstructorException if the task description is empty. + */ public ToDo(String inputString, TaskList tasks, boolean constructorMessage) throws ToDoConstructorException { // Call the parent class (Task) constructor, removing the "todo" prefix from the input super(inputString, tasks); this.inputString = inputString; - // If the task description is empty, throw a custom exception + + this.storageString = TODO_COMMAND + inputString; + + // Check if the task description is empty and throw an exception if true if (this.taskString.isEmpty()) { throw new ToDoConstructorException(inputString); // Handle invalid ToDo input } From 97be193f04a2a8b5d7d804d540daeba78eb71068 Mon Sep 17 00:00:00 2001 From: DarkDragoon2002 Date: Thu, 10 Oct 2024 15:39:41 +0800 Subject: [PATCH 27/31] Updated README.md --- docs/README.md | 179 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 165 insertions(+), 14 deletions(-) diff --git a/docs/README.md b/docs/README.md index 47b9f984f..0b79d9ba9 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,30 +1,181 @@ -# Duke User Guide +# Juan Task Manager -// Update the title above to match the actual product name + ._-'-_ . + . ' /_-_-_\ ` . + .' |-_-_-_-| `. + ( `.-_-_-.' ) + !`. .'! + ! ` . . ' ! + ! ! ! ! ! ! ! ! ! + / / \ \ + _-| \___ ___/ /-_ + (_ )__\_)\(_/__( _) + ))))\X\ (((( + \/ \/ -// Product screenshot goes here +Juan is a simple command-line task manager that helps users keep track of tasks such as to-dos, deadlines, and events. It allows users to manage their tasks, mark them as complete, and store them for future use. Juan is written in Java and supports basic task operations with a fun user interface. -// Product intro goes here +## Features -## Adding deadlines +- **Add a ToDo task**: Adds a simple to-do task. +- **Add a Deadline task**: Adds a task with a specific deadline. +- **Add an Event task**: Adds a task with a start and end time. +- **Mark tasks as done**: Marks tasks as completed. +- **Unmark tasks**: Unmarks tasks as not completed. +- **Delete tasks**: Deletes tasks from the list. +- **List tasks**: Lists all current tasks. +- **Find tasks**: Searches for tasks that match a keyword. -// Describe the action and its outcome. +## Command Overview -// Give examples of usage +| Command | Description | Format | Example | +|--------------|------------------------------------|----------------------------------------------------|---------------------------------------------------------------------| +| Add ToDo | Adds a to-do task | `todo ` | `todo Buy groceries` | +| Add Deadline | Adds a deadline task | `deadline /by ` | `deadline Submit assignment /by 15-10-2024 23:59` | +| Add Event | Adds an event with start and end | `event /from /to ` | `event Project meeting /from 15-10-2024 10:00 /to 15-10-2024 12:00` | +| Mark Task | Marks a task as done | `mark ` | `mark 2` | +| Unmark Task | Unmarks a task | `unmark ` | `unmark 2` | +| Delete Task | Deletes a task | `delete ` | `delete 3` | +| List Tasks | Lists all tasks | `list` | `list` | +| Find Task | Finds tasks matching a keyword | `find ` | `find groceries` | -Example: `keyword (optional arguments)` +## Commands -// A description of the expected outcome goes here +### 1. Add ToDo Task +**Format**: ``` -expected output +todo ``` -## Feature ABC +Adds a new to-do task to the task list. -// Feature details +Example: +``` +todo Buy groceries + +Muy Bien, work hard compadre! +I've Added the Task: +[T][ ] Buy groceries +``` + +### 2. Add Deadline Task + +**Format**: +``` +deadline /by +``` + +Adds a task with a specific deadline. + +Example: +``` +deadline Submit assignment /by 15-10-2024 23:59 + +Muy Bien, work hard compadre! +I've Added the Task: +[D][ ] Submit assignment (by: 15-10-2024 23:59) +``` + +### 3. Add Event Task + +**Format**: +``` +event /from /to +``` +Adds a task with a specific start and end time. -## Feature XYZ +Example: +``` +event Project meeting /from 15-10-2024 10:00 /to 15-10-2024 12:00 + +Muy Bien, work hard compadre! +I've Added the Task: +[E][ ] Project meeting (from: 15-10-2024 10:00 to: 15-10-2024 12:00) +``` + +### 4. Mark Task as Done + +**Format**: +``` +mark +``` + +Marks the specified task as completed. + +Example: +``` +mark 1 + +Fantastica!!!! I marked it: +[T][X] Buy groceries +``` + +### 5. Unmark Task + +**Format**: +``` +unmark +``` -// Feature details \ No newline at end of file +Unmarks the specified task, indicating it is not completed. + +Example: +``` +unmark 1 + +Ay Caramba, I unmarked it: +[T][ ] Buy groceries +``` + +### 6. Delete Task + +**Format**: +``` +delete +``` + +Deletes the specified task from the task list. + +Example: +``` +delete 1 + +Ay Caramba, Task deleted: [T][ ] Buy groceries +``` + +### 7. List All Tasks + +**Format**: +``` +list +``` + +Lists all current tasks in the task list, including their status (marked as done or not done) and task numbers. + +Example: +``` +list + +Si compinche, your 2 tasks: +1.[D][X] Submit assignment (by: 15-10-2024 23:59) +2.[E][ ] Project meeting (from: 15-10-2024 10:00 to: 15-10-2024 12:00) +``` + +### 8. Find Task + +**Format**: +``` +find +``` + +Finds all tasks that contain the specified keyword in their description. + +Example: +``` +find meeting + +Si compinche, your tasks with the phrase : +2.[E][ ] Project meeting (from: 15-10-2024 10:00 to: 15-10-2024 12:00) +``` From 45abc71c55471ddc0c6f6797faf52163a68b0422 Mon Sep 17 00:00:00 2001 From: DarkDragoon2002 Date: Thu, 10 Oct 2024 15:40:11 +0800 Subject: [PATCH 28/31] Update README.md --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 0b79d9ba9..3d9f62495 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,4 +1,4 @@ -# Juan Task Manager +# Juan User Guide ._-'-_ . . ' /_-_-_\ ` . From 4175b23c06bfe02051c57b107d94c7c001683e88 Mon Sep 17 00:00:00 2001 From: DarkDragoon2002 Date: Thu, 10 Oct 2024 15:40:45 +0800 Subject: [PATCH 29/31] Update README.md --- docs/README.md | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/docs/README.md b/docs/README.md index 3d9f62495..ba336956e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -15,16 +15,6 @@ Juan is a simple command-line task manager that helps users keep track of tasks such as to-dos, deadlines, and events. It allows users to manage their tasks, mark them as complete, and store them for future use. Juan is written in Java and supports basic task operations with a fun user interface. -## Features - -- **Add a ToDo task**: Adds a simple to-do task. -- **Add a Deadline task**: Adds a task with a specific deadline. -- **Add an Event task**: Adds a task with a start and end time. -- **Mark tasks as done**: Marks tasks as completed. -- **Unmark tasks**: Unmarks tasks as not completed. -- **Delete tasks**: Deletes tasks from the list. -- **List tasks**: Lists all current tasks. -- **Find tasks**: Searches for tasks that match a keyword. ## Command Overview From 98d3df5b3040578ca4a6e3dddd72acb0320a9bb7 Mon Sep 17 00:00:00 2001 From: DarkDragoon2002 Date: Thu, 10 Oct 2024 16:13:41 +0800 Subject: [PATCH 30/31] Update README.md --- docs/README.md | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/docs/README.md b/docs/README.md index ba336956e..ca6c4a9ba 100644 --- a/docs/README.md +++ b/docs/README.md @@ -18,16 +18,18 @@ Juan is a simple command-line task manager that helps users keep track of tasks ## Command Overview -| Command | Description | Format | Example | -|--------------|------------------------------------|----------------------------------------------------|---------------------------------------------------------------------| -| Add ToDo | Adds a to-do task | `todo ` | `todo Buy groceries` | -| Add Deadline | Adds a deadline task | `deadline /by ` | `deadline Submit assignment /by 15-10-2024 23:59` | -| Add Event | Adds an event with start and end | `event /from /to ` | `event Project meeting /from 15-10-2024 10:00 /to 15-10-2024 12:00` | -| Mark Task | Marks a task as done | `mark ` | `mark 2` | -| Unmark Task | Unmarks a task | `unmark ` | `unmark 2` | -| Delete Task | Deletes a task | `delete ` | `delete 3` | -| List Tasks | Lists all tasks | `list` | `list` | -| Find Task | Finds tasks matching a keyword | `find ` | `find groceries` | +| Command | Description | Format | Example | +|---------------|--------------------------------------------|----------------------------------------------------|---------------------------------------------------------------------| +| Add ToDo | Adds a to-do task | `todo ` | `todo Buy groceries` | +| Add Deadline | Adds a deadline task | `deadline /by ` | `deadline Submit assignment /by 15-10-2024 23:59` | +| Add Event | Adds an event with start and end | `event /from /to ` | `event Project meeting /from 15-10-2024 10:00 /to 15-10-2024 12:00` | +| Mark Task | Marks a task as done | `mark ` | `mark 2` | +| Unmark Task | Unmarks a task | `unmark ` | `unmark 2` | +| Delete Task | Deletes a task | `delete ` | `delete 3` | +| List Tasks | Lists all tasks | `list` | `list` | +| Find Task | Finds tasks matching a keyword | `find ` | `find groceries` | +| Exit | Saves the tasks into a text file and exits | `bye` | `bye` | + ## Commands @@ -168,4 +170,22 @@ find meeting Si compinche, your tasks with the phrase : 2.[E][ ] Project meeting (from: 15-10-2024 10:00 to: 15-10-2024 12:00) +5.[T][X] Do Tutorial +``` + +### 9. Exit + +**Format**: +``` +bye ``` +Saves changes done to .txt file and exits program. + +Example: + +``` +bye + +Data File Written +Adios amigo, la familia will miss you +``` \ No newline at end of file From 246fbcbd7a3e393a275eb535c9fd4843fe45ab64 Mon Sep 17 00:00:00 2001 From: DarkDragoon2002 Date: Thu, 10 Oct 2024 17:45:33 +0800 Subject: [PATCH 31/31] Storage Bug Fix --- docs/README.md | 6 ++++++ src/main/java/Storage.java | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index ca6c4a9ba..ccdd20339 100644 --- a/docs/README.md +++ b/docs/README.md @@ -15,6 +15,12 @@ Juan is a simple command-line task manager that helps users keep track of tasks such as to-dos, deadlines, and events. It allows users to manage their tasks, mark them as complete, and store them for future use. Juan is written in Java and supports basic task operations with a fun user interface. +## Run + +To Run Juan, open Command Prompt and navigate to the directory `ip.jar` is located in and run the following command: +``` +java -jar ip.jar +``` ## Command Overview diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index 41375adfe..a75ac28bb 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -52,7 +52,6 @@ public TaskList readData() { ui.printMessage("Data File Read"); } catch (FileNotFoundException e) { ui.printMessage("Data File does not exist"); - return null; } return tempTaskList;