diff --git a/data/sunny.txt b/data/sunny.txt new file mode 100644 index 000000000..fc0cc8b2a --- /dev/null +++ b/data/sunny.txt @@ -0,0 +1,2 @@ +[D][ ] Submit report (by:mon) +[E][ ] Team meeting (from:12pm to:2pm`) diff --git a/docs/README.md b/docs/README.md index 8077118eb..2dced64ce 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,29 +1,240 @@ -# User Guide +# SUNNY BOT USER GUIDE + +Welcome to Sunny Bot, your personal task manager! Below are the features and usage guidelines to help you make the most of Sunny Bot. ## Features -### Feature-ABC +### Feature 0 - Greeting the User + +Sunny bot greets the user upon starting the program. + +_Usage_ + +Example: + +`Hello! I'm Sunny +What can I do for you?` + +### Feature 1 - Adding of tasks + +Sunny Bot allows you to add different types of tasks, such as Todo, Deadline, and Event. + +_Usage_ + +**'todo' - Add a Todo task** + +Add a new task without any specific date or time. + +Example of usage: + +`todo Buy groceries` + +Expected outcome: +Sunny Bot will add a new Todo task and confirm the addition. + +`Got it! I have successfully added: +[T][ ] Buy groceries +Now you have 1 task in the list.` + + + + +**'deadline' - Add a Deadline task** + +Add a task with a specific deadline. + +Example of usage: -Description of the feature. +`deadline Submit report /by mon` -### Feature-XYZ +Expected outcome: +Sunny Bot will add a new Deadline task and confirm the addition. + +`Got it! I have successfully added: +[D][ ] Submit report (by:mon) +Now you have 2 tasks in the list.` -Description of the feature. -## Usage -### `Keyword` - Describe action -Describe the action and its outcome. +**event - Add an Event task** -Example of usage: +Add a task with a specific start and end time. -`keyword (optional arguments)` +Example of usage: + +`event Team meeting /from 12pm /to 2pm` Expected outcome: +Sunny Bot will add a new Event task and confirm the addition. + +`Got it! I have successfully added: +[E][ ] Team meeting (from:12pm to:2pm) +Now you have 3 tasks in the list.` + +Feel free to explore and try different variations with optional arguments! + + + + +### Feature 2 - Viewing Task List + +Sunny Bot allows you to view the list of tasks currently in your task manager. + + +_Usage_ + +**list - Display the list of tasks** + +View all tasks currently in your task manager. + +Example of usage: + +`list` + +Expected outcome: +Sunny Bot will display the list of tasks. + +`Here are the tasks in your list: +1. [T][ ] Buy groceries +2. [D][ ] Submit report (by:mon) +3. [E][ ] Team meeting (from:12pm to:2pm)` + + + + +### Feature 3 - Mark/Unmark Task as Done +Mark a task as done or undo the mark to indicate completion status. + +_Usage_ + +**mark - Mark a task as done** + +Mark a specific task as completed. + +Example of usage: + +`mark 2` + +Expected outcome: +Sunny Bot will mark the specified task as done and confirm the action. + +`Nice! I've marked this task as done! +[D][X] Submit report (by:mon)` + + + + +**unmark - Unmark a task as done** + +Undo the completion status of a task. + +Example of usage: + +`unmark 2` + +Expected outcome: +Sunny Bot will undo the completion status of the specified task and confirm the action. + +`OK, I've marked this task as not done yet. +[D][ ] Submit report (by:mon)` + + + + +### Feature 4 - Find Tasks +Search for tasks containing specific keywords. + +_Usage_ + +**find - Find tasks based on keywords** + +Find tasks that match specific keywords. + +Example of usage: + +`find report` + +Expected outcome: +Sunny Bot will display tasks containing the specified keyword. + +`Here are the matching tasks in your list: +1.[D][ ] Submit report (by:mon)` + +Feel free to experiment with different keywords to locate the tasks you need. Sunny Bot's flexible search functionality makes it easy to find and manage your tasks effectively. + + + +### Feature 5 - Delete Task +Sunny Bot allows you to delete tasks. + +_Usage_ + +**delete - Delete a task from the list** + +Example of usage: + +`delete 1` + +Expected outcome: + +`Noted. I've removed this task: +[T][ ] buy groceries +Now you have 2 tasks in the list.` + + + + + +### Feature 6 - Load, Save, and Display Data +Sunny Bot provides the ability to load tasks from a file, save tasks to a file, and display them again when the program runs. + +_Usage_ +**Loading Tasks from File:** +Sunny Bot automatically loads tasks from a file when you start the program. + +Example: + +`Tasks loaded from file: +Read from file: [T][ ] buy groceries +Read from file: [D][ ] Submit report (by:mon) +Read from file: [E][ ] Team meeting (from:12pm to:2pm) +Tasks loaded successfully!` + + +**Saving Tasks to File:** +Sunny Bot will automatically save your tasks in the file for future use. + +Every time a change is made, the program displays: + +`Saving tasks to file... +Tasks saved successfully!` + + +**Displaying Tasks:** +Sunny Bot displays the loaded tasks when you run the program. If you have saved tasks, they will be loaded and presented in the task list. + +Example: + +`Here are the tasks in your list: +1. [T][ ] buy groceries +2. [D][ ] Submit report (by:mon) +3. [E][ ] Team meeting (from:12pm to:2pm)` + + + + +### Feature 7 - Exit the Program +Sunny bot allows you to exit the program. + +_Usage_ + +**bye - Exits the program** + +Example of usage: + +`bye` -Description of the outcome. +Expected Outcome: -``` -expected output -``` +`Bye. Hope to see you again soon!` diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java new file mode 100644 index 000000000..b5d5bce44 --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,27 @@ +/** + * Represents a Deadline task with a specific deadline. + */ +public class Deadline extends Task { + private String by; + + /** + * Creates a new Deadline task with the given description and deadline. + * + * @param description The description of the Deadline task. + * @param by The deadline of the Deadline task. + */ + public Deadline(String description, String by) { + super(description); + this.by = by; + } + + /** + * Returns a string representation of the Deadline task, including the deadline. + * + * @return A string representation of the Deadline task. + */ + @Override + public String toString() { + return "[D]" + super.toString() + " (by:" + by + ")"; + } +} 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/Event.java b/src/main/java/Event.java new file mode 100644 index 000000000..bb8171bc1 --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,30 @@ +/** + * Represents an Event task with a specific start and end date/time. + */ +public class Event extends Task { + private String from; + private String to; + + /** + * Creates a new Event task with the given description, start, and end date/time. + * + * @param description The description of the Event task. + * @param from The start date/time of the Event task. + * @param to The end date/time of the Event task. + */ + public Event(String description, String from, String to) { + super(description); + this.from = from; + this.to = to; + } + + /** + * Returns a string representation of the Event task, including start and end date/time. + * + * @return A string representation of the Event task. + */ + @Override + public String toString() { + return "[E]" + super.toString() + " (from:" + from + " to:" + to + ")"; + } +} diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 000000000..1cc2e5dba --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: Sunny + diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java new file mode 100644 index 000000000..b7824f344 --- /dev/null +++ b/src/main/java/Parser.java @@ -0,0 +1,109 @@ +import java.util.Scanner; + +/** + * Parses user commands and performs corresponding actions. + */ +public class Parser { + private static Ui ui = new Ui(); + private Storage storage; + private TaskList tasks; + private Scanner scanner = new Scanner(System.in); + + /** + * Constructs a Parser with the given Storage and TaskList. + * + * @param storage The storage used to handle file operations. + * @param tasks The task list to be manipulated. + */ + public Parser(Storage storage, TaskList tasks) { + this.storage = storage; + this.tasks = tasks; + } + + /** + * Reads user commands and executes corresponding actions until the "bye" command is received. + */ + public void readCommand() { + String command; + + while (true) { + command = scanner.nextLine(); + String taskType = command.contains(" ") ? command.substring(0, command.indexOf(" ")) : command; + + switch (taskType) { + case "bye": + handleByeCommand(); + return; + case "list": + handleListCommand(); + break; + case "mark": + handleMarkCommand(command); + break; + case "unmark": + handleUnmarkCommand(command); + break; + case "todo": + handleTodoCommand(command); + break; + case "deadline": + handleDeadlineCommand(command); + break; + case "event": + handleEventCommand(command); + break; + case "delete": + handleDeleteCommand(command); + break; + case "find": + handleFindCommand(command); + break; + default: + ui.showInvalidCommand(); + } + } + } + + private void handleByeCommand() { + ui.showBye(); + scanner.close(); + } + + private void handleListCommand() { + tasks.printTaskList(); + } + + private void handleMarkCommand(String command) { + tasks.markTaskAsDone(command); + storage.saveTasksToFile(tasks); + } + + private void handleUnmarkCommand(String command) { + tasks.unmarkTaskAsDone(command); + storage.saveTasksToFile(tasks); + } + + private void handleTodoCommand(String command) { + tasks.addTodoTask(command); + storage.saveTasksToFile(tasks); + } + + private void handleDeadlineCommand(String command) { + tasks.addDeadlineTask(command); + storage.saveTasksToFile(tasks); + } + + private void handleEventCommand(String command) { + tasks.addEventTask(command); + storage.saveTasksToFile(tasks); + } + + private void handleDeleteCommand(String command) { + tasks.deleteTask(command); + storage.saveTasksToFile(tasks); + } + + private void handleFindCommand(String command) { + tasks.findTask(command); + } +} diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java new file mode 100644 index 000000000..405f2f50a --- /dev/null +++ b/src/main/java/Storage.java @@ -0,0 +1,84 @@ +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Scanner; + +/** + * Deals with loading tasks from the file and saving tasks to the file. + */ +public class Storage { + + private String filePath; + private static Ui ui = new Ui(); + + /** + * Creates a new Storage instance with the specified file path. + * + * @param filePath The path to the file. + */ + public Storage(String filePath) { + this.filePath = filePath; + } + + /** + * Loads tasks from the specified file into the provided TaskList. + * + * @param tasks The TaskList to load tasks into. + */ + public void loadTasksFromFile(TaskList tasks) { + try { + Path path = Paths.get(filePath); + + if (!Files.exists(path)) { + createFileAndDirectories(path); + } else { + loadTasksFromExistingFile(path, tasks); + } + } catch (IOException e) { + ui.handleErrors(e); + } + } + + private void createFileAndDirectories(Path path) throws IOException { + Files.createDirectories(path.getParent()); + Files.createFile(path); + ui.showFileCreated(); + } + + private void loadTasksFromExistingFile(Path path, TaskList tasks) throws IOException { + try (Scanner scanner = new Scanner(path)) { + System.out.println("Tasks loaded from file:"); + while (scanner.hasNext()) { + String fileLine = scanner.nextLine(); + System.out.println("Read from file: " + fileLine); + + char taskType = fileLine.charAt(1); + tasks.addTaskFromSaved(fileLine, taskType); + } + } + ui.showTasksLoaded(); + tasks.printTaskList(); + } + + /** + * Saves tasks from the provided TaskList to the specified file. + * + * @param tasks The TaskList to save tasks from. + */ + public void saveTasksToFile(TaskList tasks) { + try { + FileWriter writer = new FileWriter(filePath); + System.out.println("Saving tasks to file..."); + for (int i = 0; i < tasks.size(); i++) { + String taskString = tasks.get(i).toString(); + writer.write(taskString + System.lineSeparator()); + } + writer.close(); + ui.showTasksSaved(); + } catch (IOException e) { + ui.handleErrors(e); + } + } +} diff --git a/src/main/java/Sunny.java b/src/main/java/Sunny.java new file mode 100644 index 000000000..3b51435b9 --- /dev/null +++ b/src/main/java/Sunny.java @@ -0,0 +1,21 @@ +/** + * The main class for the Sunny task management application. + */ +public class Sunny { + static TaskList tasksList = new TaskList(); + public static final String FILE_PATH = "./data/sunny.txt"; + private static Ui ui = new Ui(); + private static Storage storage = new Storage(FILE_PATH); + private static Parser parser = new Parser(storage, tasksList); + + /** + * The main entry point of the Sunny application. + * + * @param args The command line arguments. + */ + public static void main(String[] args) { + storage.loadTasksFromFile(tasksList); + ui.showWelcome(); + parser.readCommand(); + } +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 000000000..35ff7fb01 --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,58 @@ +/** + * Represents a basic task with a description and a completion status. + */ +public class Task { + protected String description; + protected boolean isDone; + + /** + * Creates a new task with the given description. + * + * @param description The description of the task. + */ + public Task(String description) { + this.description = description; + this.isDone = false; + } + + /** + * Gets the description of the task. + * + * @return The description of the task. + */ + public String getDescription() { + return description; + } + + /** + * Gets the status icon indicating whether the task is done or not. + * + * @return The status icon ("X" for done, " " for not done). + */ + public String getStatusIcon() { + return (isDone ? "X" : " "); + } + + /** + * Marks the task as done. + */ + public void markAsDone() { + this.isDone = true; + } + + /** + * Marks the task as not done. + */ + public void unmarkAsDone() { + this.isDone = false; + } + + /** + * Returns a string representation of the task. + * + * @return A string representation of the task. + */ + public String toString() { + return "[" + getStatusIcon() + "] " + description; + } +} diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java new file mode 100644 index 000000000..1a9d33e51 --- /dev/null +++ b/src/main/java/TaskList.java @@ -0,0 +1,345 @@ +import java.util.ArrayList; + +/** + * Represents a list of tasks and provides methods for managing tasks. + */ +public class TaskList { + private static Ui ui = new Ui(); + + private static ArrayList tasksList = new ArrayList<>(); + + /** + * Constructs an empty TaskList. + */ + public TaskList() { + this.tasksList = new ArrayList<>(); + } + + /** + * Returns the number of tasks in the list. + * + * @return The number of tasks in the list. + */ + public int size() { + return tasksList.size(); + } + + /** + * Retrieves the task at the specified index in the list. + * + * @param index The index of the task to retrieve. + * @return The task at the specified index. + */ + public Task get(int index) { + return tasksList.get(index); + } + + /** + * Handles the "todo" command, creating a new Todo task and adding it to the list. + * + * @param command The user command containing the task description. + */ + public void addTodoTask(String command) { + try { + if (command.length() <= 5) { + throw new StringIndexOutOfBoundsException(); + } + ui.showTaskAdded(); + tasksList.add(new Todo(command.substring(5))); + System.out.println(tasksList.get(tasksList.size() - 1)); + + ui.showTaskCountMessage(); + } catch (Exception e) { + ui.handleErrors(e); + } + } + + /** + * Handles the "deadline" command, creating a new Deadline task and adding it to the list. + * + * @param command The user command containing the task description and deadline. + */ + public void addDeadlineTask(String command) { + try { + int dividerPosition = command.indexOf("/by "); + if (dividerPosition == -1) { + throw new StringIndexOutOfBoundsException(); + } + ui.showTaskAdded(); + tasksList.add(new Deadline(command.substring(9, dividerPosition - 1), command.substring(dividerPosition + 4))); + System.out.println(tasksList.get(tasksList.size() - 1)); + + ui.showTaskCountMessage(); + } catch (Exception e) { + ui.handleErrors(e); + } + } + + /** + * Handles the "event" command, creating a new Event task and adding it to the list. + * + * @param command The user command containing the task description and event details. + */ + public void addEventTask(String command) { + try { + int from = command.indexOf("/from "); + int to = command.indexOf("/to "); + if (from == -1 || to == -1) { + throw new StringIndexOutOfBoundsException(); + } + ui.showTaskAdded(); + tasksList.add(new Event(command.substring(6, from - 1), command.substring(from + 6, to - 1), command.substring(to + 4))); + System.out.println(tasksList.get(tasksList.size() - 1)); + + ui.showTaskCountMessage(); + } catch (Exception e) { + ui.handleErrors(e); + } + } + + /** + * Prints the task list to the console. + */ + public void printTaskList() { + ui.showTaskList(); + + for (int i = 0; i < tasksList.size(); i++) { + System.out.println(i + 1 + ". " + tasksList.get(i)); + } + System.out.println(" "); + } + + /** + * Extracts the task index from a user command. + * + * @param command The user command containing the task index. + * @return The extracted task index or -1 if not found. + */ + public static int extractTaskIndex(String command) { + String[] parts = command.split(" "); + return (parts.length >= 2) ? Integer.parseInt(parts[1]) : -1; + } + + private static boolean isValidTaskIndex(int taskIndex) { + return taskIndex > 0 && taskIndex <= tasksList.size(); + } + + /** + * Marks a task as done based on the user command. + * + * @param command The user command containing the task index. + */ + public void markTaskAsDone(String command) { + try { + int taskIndex = extractTaskIndex(command); + + if (isValidTaskIndex(taskIndex)) { + tasksList.get(taskIndex - 1).markAsDone(); + ui.showTaskAsMarked(); + System.out.println(tasksList.get(taskIndex - 1)); + } else { + ui.showInvalidTaskIndexMessage(); + } + System.out.println(" "); + } catch (NumberFormatException e) { + // Handle the NumberFormatException (e.g., if extractTaskIndex() fails to parse an integer) + ui.handleErrors(e); + } catch (IndexOutOfBoundsException e) { + // Handle the IndexOutOfBoundsException (e.g., if tasksList.get() accesses an invalid index) + ui.handleErrors(e); + } catch (Exception e) { + // Handle any other unexpected exceptions + ui.handleErrors(e); + } + } + + /** + * Unmarks a task as done based on the user command. + * + * @param command The user command containing the task index. + */ + public void unmarkTaskAsDone(String command) { + try { + int taskIndex = extractTaskIndex(command); + + if (isValidTaskIndex(taskIndex)) { + tasksList.get(taskIndex - 1).unmarkAsDone(); + ui.showTaskAsUnmarked(); + System.out.println(tasksList.get(taskIndex - 1)); + } else { + ui.showInvalidTaskIndexMessage(); + } + System.out.println(" "); + } catch (NumberFormatException e) { + // Handle the NumberFormatException (e.g., if extractTaskIndex() fails to parse an integer) + ui.handleErrors(e); + } catch (IndexOutOfBoundsException e) { + // Handle the IndexOutOfBoundsException (e.g., if tasksList.get() accesses an invalid index) + ui.handleErrors(e); + } catch (Exception e) { + // Handle any other unexpected exceptions + ui.handleErrors(e); + } + } + + /** + * Adds a task from a saved command to the list based on the task type. + * + * @param command The saved command representing the task. + * @param taskType The type of task (T, D, or E). + */ + public void addTaskFromSaved(String command, char taskType) { + try { + Task task; + switch (taskType) { + case 'T': + task = addTodoFromSaved(command); + break; + case 'D': + task = addDeadlineFromSaved(command); + break; + case 'E': + task = addEventFromSaved(command); + break; + default: + // Handle unknown task type or return if needed + System.out.println("Unknown task type: " + taskType); + return; + } + if (task != null) { + tasksList.add(task); + } + + } catch (Exception e) { + ui.handleErrors(e); + } + } + + /** + * Creates a Todo task from a saved command. + * + * @param description The saved command representing the Todo task. + * @return The created Todo task. + */ + public Todo addTodoFromSaved(String description) { + char status = description.charAt(4); + String taskDescription = description.substring(7); + Todo todoTask = new Todo(taskDescription); + + if (status == 'X') { + todoTask.markAsDone(); + } else { + todoTask.unmarkAsDone(); + } + + return todoTask; + } + + /** + * Creates a Deadline task from a saved command. + * + * @param description The saved command representing the Deadline task. + * @return The created Deadline task. + */ + public Deadline addDeadlineFromSaved(String description) { + char status = description.charAt(4); + int byIndex = description.indexOf("(by:"); + + String taskDescription = description.substring(7, byIndex).trim(); + String by = description.substring(byIndex + 4, description.indexOf(")")).trim(); + Deadline deadlineTask = new Deadline(taskDescription, by); + + if (status == 'X') { + deadlineTask.markAsDone(); + } else { + deadlineTask.unmarkAsDone(); + } + + return deadlineTask; + + } + + /** + * Creates an Event task from a saved command. + * + * @param description The saved command representing the Event task. + * @return The created Event task. + */ + public Event addEventFromSaved(String description) { + char status = description.charAt(4); + int fromIndex = description.indexOf("(from:"); + int toIndex = description.indexOf("to:"); + + String taskDescription = description.substring(7, fromIndex).trim(); + String from = description.substring(fromIndex + 6, toIndex).trim(); + String to = description.substring(toIndex + 3, description.indexOf(")")).trim(); + Event eventTask = new Event(taskDescription, from, to); + + if (status == 'X') { + eventTask.markAsDone(); + } else { + eventTask.unmarkAsDone(); + } + + return eventTask; + } + + /** + * Deletes a task based on the user command. + * + * @param command The user command containing the task index. + */ + public void deleteTask(String command) { + try { + int taskIndex = extractTaskIndex(command); + + if (isValidTaskIndex(taskIndex)) { + ui.showTaskDeleted(); + System.out.println(tasksList.get(taskIndex - 1)); + tasksList.remove(taskIndex - 1); + ui.showTaskCountMessage(); + } else { + ui.showInvalidTaskIndexMessage(); + } + } catch (NumberFormatException e) { + // Handle the NumberFormatException (e.g., if extractTaskIndex() fails to parse an integer) + ui.handleErrors(e); + } catch (IndexOutOfBoundsException e) { + // Handle the IndexOutOfBoundsException (e.g., if tasksList.get() accesses an invalid index) + ui.handleErrors(e); + } catch (Exception e) { + // Handle any other unexpected exceptions + ui.handleErrors(e); + } + } + + /** + * Finds tasks containing a specific keyword and displays them. + * + * @param command The user command containing the keyword. + */ + public void findTask(String command) { + String keyword; + + try { + keyword = command.substring(5); + } catch (StringIndexOutOfBoundsException e) { + ui.handleErrors(e); + return; + } + + int foundIndex = 0; + ui.showFoundTasks(); + for (Task task : tasksList) { + if (task.getDescription().contains(keyword)) { + foundIndex++; + System.out.println(foundIndex + "." + task); + } + } + if (foundIndex == 0) { + System.out.println("OH, no matching tasks found :("); + } + + System.out.println(" "); + } +} diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java new file mode 100644 index 000000000..d8c09f29a --- /dev/null +++ b/src/main/java/Todo.java @@ -0,0 +1,24 @@ +/** + * Represents a Todo task without any date or time attached. + */ +public class Todo extends Task { + + /** + * Creates a new Todo task with the given description. + * + * @param description The description of the Todo task. + */ + public Todo(String description) { + super(description); + } + + /** + * Returns a string representation of the Todo task. + * + * @return A string representation of the Todo task. + */ + @Override + public String toString() { + return "[T]" + super.toString(); + } +} diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java new file mode 100644 index 000000000..a2fdeb496 --- /dev/null +++ b/src/main/java/Ui.java @@ -0,0 +1,135 @@ +import java.io.IOException; + +/** + * Handles interactions with the user. + */ +public class Ui { + + /** + * Displays a welcome message. + */ + public void showWelcome() { + System.out.println("Hello! I'm Sunny"); + System.out.println("What can I do for you?"); + System.out.println(" "); + } + + /** + * Displays a goodbye message. + */ + public void showBye() { + System.out.println("Bye. Hope to see you again soon!"); + } + + /** + * Displays a message indicating that tasks have been successfully loaded. + */ + public void showTasksLoaded() { + System.out.println("Tasks loaded successfully!"); + System.out.println(" "); + } + + /** + * Displays a message indicating that tasks have been successfully saved. + */ + public void showTasksSaved() { + System.out.println("Tasks saved successfully!"); + System.out.println(" "); + } + + /** + * Displays the message indicating the start of the task list. + */ + public void showTaskList() { + System.out.println("Here are the tasks in your list:"); + } + + /** + * Displays a message for an invalid command. + */ + public void showInvalidCommand() { + System.out.println("OOPS!!! I'm sorry, but I don't know what that means :-("); + System.out.println(" "); + } + + /** + * Displays a message for an invalid task index. + */ + public void showInvalidTaskIndexMessage() { + System.out.println("Invalid task index. Please provide a valid task index."); + } + + /** + * Displays a message for marking a task as done. + */ + public void showTaskAsMarked() { + System.out.println("Nice! I've marked this task as done!"); + } + + /** + * Displays a message for marking a task as not done. + */ + public void showTaskAsUnmarked() { + System.out.println("OK, I've marked this task as not done yet."); + } + + /** + * Displays a message for successfully adding a task. + */ + public void showTaskAdded() { + System.out.println("Got it! I have successfully added:"); + } + + /** + * Displays a message for removing a task. + */ + public void showTaskDeleted() { + System.out.println("Noted. I've removed this task:"); + } + + /** + * Displays a message with the current task count. + */ + public void showTaskCountMessage() { + int taskCount = Sunny.tasksList.size(); + String taskNoun = (taskCount == 1) ? "task" : "tasks"; + System.out.println("Now you have " + taskCount + " " + taskNoun + " in the list."); + System.out.println(" "); + } + + /** + * Displays a message for the creation of a file. + */ + public void showFileCreated() { + System.out.println("File created: " + Sunny.FILE_PATH); + } + + /** + * Displays a message for found tasks during a search. + */ + public void showFoundTasks() { + System.out.println("Here are the matching tasks in your list:"); + } + + /** + * Handles and displays errors based on exception types. + * + * @param e The exception to be handled. + */ + public void handleErrors(Exception e) { + if (e instanceof IOException) { + System.out.println("OOPS!!! An error occurred while handling the file."); + } else if (e instanceof ArrayIndexOutOfBoundsException) { + System.out.println("OOPS!!! The command seems to be incomplete or incorrect."); + } else if (e instanceof NumberFormatException) { + System.out.println("OOPS!!! Please provide a valid task index."); + } else if (e instanceof StringIndexOutOfBoundsException) { + System.out.println("OOPS!!! The description cannot be empty."); + } else if (e instanceof IllegalArgumentException) { + System.out.println("OOPS!!! " + e.getMessage()); + } else { + System.out.println("OOPS!!! I'm sorry, but I encountered an unexpected error."); + } + System.out.println(" "); + } +}