diff --git a/docs/README.md b/docs/README.md index 8077118eb..91854ce50 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,29 +1,163 @@ # User Guide +Duke is an application for managing task list via a **Command Line Interface (CLI)** that helps you to remember the tasks that you do not wish to forget. -## Features ++ [Quick Start](#quick-start) ++ [Features](#features) + + [Create a ToDo task: `todo`](#create-a-todo-task--todo) + + [Create a Deadline task: `deadline`](#create-a-deadline-task--deadline) + + [Create an Event task: `event`](#create-an-event-task--event) + + [Mark a task as done: `mark`](#mark-a-task-as-done--mark) + + [Mark a task as not done: `unmark`](#mark-a-task-as-not-done--unmark) + + [List out the tasks: `list`](#list-out-the-tasks--list) + + [Delete a specific task: `delete`](#delete-a-specific-task--delete) + + [Find a task by keyword: `find`](#find-a-task-by-keyword--find) + + [Exit the application: `bye`](#exit-the-application--bye) -### Feature-ABC +### Quick Start +1. Ensure that you have Java 11 installed. +2. Download the latest duke.jar from [here](). +3. Copy the file to the folder you want your Duke to be in. +4. Open a command terminal, navigate into the folder using `cd` +5. Run the application using `-jar duke.jar` -Description of the feature. +### Features +#### Create a ToDo Task: `todo` +Adds a todo task into the list. -### Feature-XYZ +Format: `todo TASK_NAME` -Description of the feature. +Example: `todo borrow book` -## Usage +Output: +``` +____________________________________________________ +Got it. I've added this tasks: +[T][ ] borrow book +Now you have 1 tasks in the list. +____________________________________________________ +``` +#### Create a Deadline Task: `deadline` +Adds a deadline task into the list that includes the date of the deadline. + +Format: `deadline TASK_NAME /by DATE` -### `Keyword` - Describe action +Example: `deadline return book /by Sunday` + +Output: +``` +____________________________________________________ +Got it. I've added this tasks: +[D][ ] return book(by: Sunday) +Now you have 2 tasks in the list. +____________________________________________________ +``` -Describe the action and its outcome. +#### Create an Event Task: `event` +Adds an event task into the list that include the start and end time of the event. + +Format: `event TASK_NAME /from START_TIME /to END_TIME` + +Example: `event project meeting /from Mon 2pm /to 4pm` + +Output: +``` +____________________________________________________ +Got it. I've added this tasks: +[E][ ] project meeting(from: Mon 2pm to: 4pm) +Now you have 3 tasks in the list. +____________________________________________________ +``` -Example of usage: +#### Mark a task as done: `mark` +Mark an existing task in the list as completed. + +Format: `mark TASK_NUMBER` + +Example: `mark 1` + +Output: +``` +____________________________________________________ +Nice! I've marked this task as done: +[T][X] borrow book +____________________________________________________ +``` + +#### Mark a task as not done: `unmark` +Mark an existing task in the list as not completed. + +Format: `unmark TASK_NUMBER` + +Example: `unmark 1` + +Output: +``` +____________________________________________________ +Nice! I've marked this task as not done yet: +[T][ ] borrow book +____________________________________________________ +``` + +#### List out the tasks: `list` +List out the tasks in the order it was added. + +Format: `list` + +Example: `list` + +Output: +``` +____________________________________________________ +Here are the tasks in your list: +1.[T][ ] borrow book +2.[D][ ] return book(by: Sunday) +3.[E][ ] project meeting(from: Mon 2pm to: 4pm) +____________________________________________________ +``` + + +#### Delete a specific task: `delete` +Remove a specific task by its number in the list. + +Format: `delete TASK_NUMBER` + +Example: `delete 3` + +Output: +``` +____________________________________________________ +Noted. I've removed this task: +[E][ ] project meeting(from: Mon 2pm to: 4pm) +Now you have 2 tasks in the list. +____________________________________________________ +``` + +#### Find a task by keyword: `find` +Find the tasks containing the keyword. + +Format: `find KEYWORD` + +Example: `find book` + +Output: +``` +____________________________________________________ +Here are the matching tasks in your list: +1.[T][ ] borrow book +2.[D][ ] return book(by: Sunday) +____________________________________________________ +``` -`keyword (optional arguments)` +#### Exit the application: `bye` +Exits the application Duke. -Expected outcome: +Format: `bye` -Description of the outcome. +Example: `bye` +Output: ``` -expected output +____________________________________________________ +Bye. Hope to see you again soon! +____________________________________________________ ``` diff --git a/src/main/java/Data.java b/src/main/java/Data.java new file mode 100644 index 000000000..7efe27819 --- /dev/null +++ b/src/main/java/Data.java @@ -0,0 +1,73 @@ +import duke.task.Task; + +import java.io.File; +import java.io.FileWriter; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Scanner; +import java.io.IOException; + +public class Data { + + protected String filePath; + protected String fileDirectory; + + + public Data(String filePath, String fileDirectory) { + this.filePath = filePath; + this.fileDirectory = fileDirectory; + } + + /** + * Checks if the directory exists and creates one if it does not. + * Then it will check if the file exists and creates one if it does not. + * + * @throws IOException if there is an error in creating the directory or file. + */ + public void checkFile() throws IOException { + File file = new File(filePath); + File directory = new File(fileDirectory); + if (!directory.isDirectory()) { + Path path = Paths.get(String.valueOf(directory)); + Files.createDirectories(path); + } + if (!file.isFile()) { + Files.createFile(Path.of(filePath)); + } + } + /** + * Reads in the file duke.txt and categorise into its respective task: Todo, Deadline or Event. + * + * @param taskList taskList contains the functions to read and create the tasks correspondingly + * @throws IOException if there is and error when reading in the file. + */ + public void readFile(TaskList taskList) throws IOException { + File file = new File(filePath); + Scanner scanner = new Scanner(file); + while (scanner.hasNextLine()) { + String input = scanner.nextLine(); + String[] substring = input.split("-|\\|"); + if (substring[0].trim().equals("T")) { + taskList.readTodoTask(substring[1].trim(), substring[2].trim()); + } else if (substring[0].trim().equals("D")) { + taskList.readDeadlineTask(substring[1].trim(), substring[2].trim(), substring[3].trim()); + } else if (substring[0].trim().equals("E")) { + taskList.readEventTask(substring[1].trim(), substring[2].trim(), substring[3].trim(), substring[4].trim()); + } + } + } + + /** + * Writes the updated of tasks in the ArrayList back into the file duke.txt + * + * @throws IOException if there is an error in writing the file. + */ + public void writeFile() throws IOException { + FileWriter fileWriter = new FileWriter(filePath); + for (Task task : TaskList.tasks) { + fileWriter.write(task.saveToFile()); + } + fileWriter.close(); + } +} diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5d313334c..990cc4843 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,10 +1,62 @@ +import duke.exception.CommandNotFoundException; +import duke.exception.DukeException; +import duke.exception.IllegalFormatException; +import duke.exception.InvalidInputException; +import duke.exception.MissingInputException; + +import java.io.FileNotFoundException; +import java.io.IOException; + public class Duke { + + protected UI ui = new UI(); + protected TaskList taskList = new TaskList(); + protected Parser parser = new Parser(); + protected Data data = new Data("data/duke.txt", "data"); + + public void run(){ + ui.printHelloMessage(); + boolean proceedToNextCommand = true; + try { + data.readFile(taskList); + } catch (FileNotFoundException e) { + try { + data.checkFile(); + } catch (IOException checkException) { + ui.printErrorMessage("File not found. I will be creating one for you."); + } + } catch (IOException readException) { + ui.printErrorMessage("I'm sorry, but there is an error in reading the file."); + } + while (proceedToNextCommand) { + String userInput = UI.readCommand(); + ui.printDivider(); + try { + proceedToNextCommand = parser.executeCommand(userInput); + if (userInput.equals("bye")) { + data.writeFile(); + break; + } + } catch (CommandNotFoundException e) { + ui.printErrorMessage("I'm sorry, but I don't know what that means."); + } catch (MissingInputException e) { + ui.printErrorMessage("Description of the command is empty."); + } catch (IllegalFormatException e) { + ui.printErrorMessage("Please check the format of command in the user guide."); + } catch (InvalidInputException e) { + ui.printErrorMessage("Please check if the input is correct."); + } catch (NumberFormatException e) { + ui.printErrorMessage("Task number should be an integer."); + } catch (IOException e) { + ui.printErrorMessage("I'm sorry, but there is an error in writing the file."); + } catch (DukeException e) { + ui.printErrorMessage("Error..."); + } + ui.printDivider(); + } + } + public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); + new Duke().run(); } } diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java new file mode 100644 index 000000000..b6c4963f1 --- /dev/null +++ b/src/main/java/Parser.java @@ -0,0 +1,44 @@ +import duke.exception.CommandNotFoundException; +import duke.exception.DukeException; + +import java.io.IOException; + +public class Parser { + protected TaskList tasklist = new TaskList(); + protected UI ui = new UI(); + + protected Data data = new Data("data/duke.txt", "data"); + + /** + * Interprets the command that was given by the user input and execute the commands accordingly to its specified usage. + * + * @return false if "bye" executed to close the loop and exit the application + * @param userInput Input string that is provided by user in the CLI. + * @throws CommandNotFoundException if command is not found. + */ + public boolean executeCommand(String userInput) throws DukeException { + if (userInput.equals("bye")) { + ui.printByeMessage(); + return false; + } else if (userInput.equals("list")) { + tasklist.showList(); + } else if (userInput.startsWith("todo")) { + tasklist.createTodo(userInput); + } else if (userInput.startsWith("deadline")) { + tasklist.createDeadline(userInput); + } else if (userInput.startsWith("event")) { + tasklist.createEvent(userInput); + } else if (userInput.startsWith("mark")) { + tasklist.markTask(userInput); + } else if (userInput.startsWith("unmark")) { + tasklist.unmarkTask(userInput); + } else if (userInput.startsWith("delete")) { + tasklist.deleteTask(userInput); + } else if (userInput.startsWith("find")) { + tasklist.findTask(userInput); + } else { + throw new CommandNotFoundException(); + } + return true; + } +} diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java new file mode 100644 index 000000000..a3791264f --- /dev/null +++ b/src/main/java/TaskList.java @@ -0,0 +1,219 @@ +import duke.exception.IllegalFormatException; +import duke.exception.InvalidInputException; +import duke.exception.MissingInputException; +import duke.task.Deadline; +import duke.task.Event; +import duke.task.Task; +import duke.task.Todo; + +import java.util.ArrayList; + +public class TaskList { + + public static ArrayList tasks = new ArrayList<>(); + + protected UI ui = new UI(); + + protected void showList() { + ui.printList(tasks, tasks.size()); + } + + /** + * Marks the task as completed based on its index. + * + * @param userInput Input string that is provided by the user. + * @throws InvalidInputException when the index provided is not within the task list + * @throws MissingInputException when the index is not provided by the user. + */ + protected void markTask(String userInput) throws InvalidInputException, MissingInputException { + if (userInput.substring(4).trim().equals("")) { + throw new MissingInputException(); + } else { + int taskIndex = Integer.parseInt(userInput.substring(4).trim()); + if (taskIndex == 0 || taskIndex > tasks.size()){ + throw new InvalidInputException(); + } else { + Task markedTask = tasks.get(taskIndex - 1); + markedTask.markDone(); + ui.printTaskMarked(markedTask); + } + } + } + + /** + * Undo the mark on the task based on its index. + * + * @param userInput Input string that is provided by the user. + * @throws InvalidInputException when the index provided is not within the task list. + * @throws MissingInputException when the index is not provided by the user. + */ + protected void unmarkTask(String userInput) throws InvalidInputException, MissingInputException { + if (userInput.substring(6).trim().equals("")) { + throw new MissingInputException(); + } else { + int taskIndex = Integer.parseInt(userInput.substring(6).trim()); + if (taskIndex == 0 || taskIndex > tasks.size()){ + throw new InvalidInputException(); + } else { + Task unmarkedTask = tasks.get(taskIndex - 1); + unmarkedTask.unmarkDone(); + ui.printTaskUnmarked(unmarkedTask); + } + } + } + + + /** + * Creates a Todo task by taking the substring of the word(s) after "todo". + * + * @param userInput Input string that is provided by the user. + * @throws MissingInputException when the description of the task if not provided. + */ + protected void createTodo(String userInput) throws MissingInputException { + if (userInput.substring(4).trim().equals("")) { + throw new MissingInputException(); + } else { + String description = userInput.substring(4).trim(); + Todo todoTask = new Todo(description); + tasks.add(todoTask); + ui.printTaskAdded(todoTask, tasks.size()); + } + } + + /** + * Creates a deadline task by taking the substring of the words after "deadline" and before "/by". + * The deadline of the task is based on the substring of word(s) after "/by'. + * + * @param userInput Input string that is provided by the user. + * @throws MissingInputException if either the deadline date or description is incomplete. + * @throws InvalidInputException if "/by" is no provided. + */ + protected void createDeadline(String userInput) throws InvalidInputException, MissingInputException { + if ((userInput.substring(8).trim().equals("") || userInput.indexOf("/by") < 8)) { + throw new InvalidInputException(); + } else { + int byIndex = userInput.indexOf("/by"); + String description = userInput.substring(8, byIndex).trim(); + String date = userInput.substring(byIndex + 3).trim(); + if (description.length() < 1 | date.length() < 1) { + throw new MissingInputException(); + } + Deadline deadlineTask = new Deadline(description, date); + tasks.add(deadlineTask); + ui.printTaskAdded(deadlineTask, tasks.size()); + } + } + + /** + * Creates an event task by taking the substring of the words after "event" and before "/from". + * Start time of the event is derived from taking the substring between "/from" and "/to". + * End time of the event is derived from taking the substring after "/to". + * + * @param userInput Input string that is provided by the user. + * @throws IllegalFormatException if the order of "/from" has been placed after "/to". + * @throws InvalidInputException if either the expected description "/from" or "/to" is not provided. + * @throws MissingInputException if either the description, start time or end time is incomplete. + */ + protected void createEvent(String userInput) throws IllegalFormatException, InvalidInputException, MissingInputException { + if (userInput.substring(5).trim().equals("") || userInput.indexOf("/from") < 5 || userInput.indexOf("/to") < 5) { + throw new InvalidInputException(); + } else { + int fromIndex = userInput.indexOf("/from"); + int toIndex = userInput.indexOf("/to"); + String description = userInput.substring(5, fromIndex).trim(); + String eventStart = userInput.substring(fromIndex + 5, toIndex).trim(); + String eventEnd = userInput.substring(toIndex + 3).trim(); + if (description.length() < 1 | eventStart.length() < 1 | eventEnd.length() < 1) { + throw new MissingInputException(); + } else if (fromIndex > toIndex) { + throw new IllegalFormatException(); + } + Event eventTask = new Event(description, eventStart, eventEnd); + tasks.add(eventTask); + ui.printTaskAdded(eventTask, tasks.size()); + } + } + + /** + * Removes the task in the list based on the index provided. + * + * @param userInput Input string that is provided by the user. + * @throws InvalidInputException if the task to be deleted is not within the list + */ + protected void deleteTask(String userInput) throws InvalidInputException { + int deleteIndex = Integer.parseInt(userInput.substring(6).trim()); + if (deleteIndex > tasks.size() || deleteIndex == 0) { + throw new InvalidInputException(); + } else { + Task deleteTask = tasks.get(deleteIndex - 1); + tasks.remove(deleteTask); + ui.printTaskDeleted(deleteTask, tasks.size()); + } + } + + /** + * Finds the tasks in the list that contains the keyword provided and store in a new taskList. + * + * @param userInput Input string that is provided by the user. + * @throws MissingInputException if the keyword is not provided. + */ + protected void findTask(String userInput) throws MissingInputException { + if (userInput.substring(4).trim().equals("")) { + throw new MissingInputException(); + } else { + String keyword = userInput.substring(4).trim(); + ArrayList matchingTasks = new ArrayList<>(); + for (Task task : tasks) { + if (task.findMatch(keyword)) { + matchingTasks.add(task); + } + } + ui.printTaskFound(matchingTasks, matchingTasks.size()); + } + } + + /** + * Creates a Todo task based on the file being read in duke.txt + * + * @param taskStatus Input string of either "0" or "1" to determine if the task is done. + * @param taskDescription Input string that describes the task. + */ + public void readTodoTask(String taskStatus, String taskDescription) { + Todo existingTask = new Todo(taskDescription); + if (taskStatus.equals("1")) { + existingTask.markDone(); + } + tasks.add(existingTask); + } + + /** + * Creates a Deadline task based on the file being read in duke.txt + * + * @param taskStatus Input string of either "0" or "1" to determine if the task is done. + * @param taskDescription Input string that describes the task. + * @param byDate Input string that contains the date of the deadline task. + */ + public void readDeadlineTask(String taskStatus, String taskDescription, String byDate) { + Deadline existingTask = new Deadline(taskDescription, byDate); + if (taskStatus.equals("1")) { + existingTask.markDone(); + } + tasks.add(existingTask); + } + + /** + * Create an Event task based on the file being read in duke.txt + * + * @param taskStatus Input string of either "0" or "1" to determine if the task is done. + * @param taskDescription Input string that describes the task. + * @param fromDate Input string that contains the start date of the Event task. + * @param toDate Input string that contains the end date of the Event task. + */ + public void readEventTask(String taskStatus, String taskDescription, String fromDate, String toDate) { + Event existingTask = new Event(taskDescription, fromDate, toDate); + if (taskStatus.equals("1")) { + existingTask.markDone(); + } + tasks.add(existingTask); + } +} diff --git a/src/main/java/UI.java b/src/main/java/UI.java new file mode 100644 index 000000000..0fcb47c92 --- /dev/null +++ b/src/main/java/UI.java @@ -0,0 +1,91 @@ +import duke.task.Task; +import java.util.ArrayList; +import java.util.Scanner; + +public class UI { + protected final String LOGO = " ____ _ \n" + + "| _ \\ _ _| | _____ \n" + + "| | | | | | | |/ / _ \\\n" + + "| |_| | |_| | < __/\n" + + "|____/ \\__,_|_|\\_\\___|\n"; + protected void printDivider() { + final String DIVIDER = "____________________________________________________"; + System.out.println(DIVIDER); + } + + public void printHelloMessage() { + System.out.println("Hello from\n" + LOGO); + printDivider(); + System.out.println("Hello! I'm Duke\n" + "What can I do for you?\n"); + printDivider(); + } + + public void printByeMessage() { + System.out.println("Bye. Hope to see you again soon!"); + printDivider(); + } + + public static String readCommand() { + Scanner scanner = new Scanner(System.in); + return scanner.nextLine(); + } + + public void printTaskMarked(Task description) { + System.out.println("Nice! I've marked this task as done:\n" + description); + } + + public void printTaskUnmarked(Task description) { + System.out.println("Nice! I've marked this task as not done yet:\n" + description); + } + public void printTaskAdded(Task description, int size) { + System.out.println("Got it. I've added this tasks:\n" + description); + System.out.println("Now you have " + size + " tasks in the list."); + } + + public void printTaskDeleted(Task description, int size) { + System.out.println("Noted. I've removed this task:\n" + description); + System.out.println("Now you have " + size + " tasks in the list."); + } + + /** + * Checks if there is any task present before printing the list of tasks + * or a message that tells the user that there is no task in the list. + * + * @param tasks List of task that has been stored in the array to be printed. + * @param size Size of the array to determine if there is any task to be printed. + */ + public void printList(ArrayList tasks, int size) { + if (size > 0) { + System.out.println("Here are the tasks in your list:"); + int count = 1; + for (Task output : tasks) { + System.out.println(count + "." + output); + count++; + } + } else { + System.out.println("There are no task in the list."); + } + } + + /** + * Checks if there is any task in the list before printing the list of tasks + * or a message that tells the user that there is no task containing that keyword. + * + * @param matchingTasks List of tasks that has been stored if it contains the keyword + * @param size Size of the task list. + */ + public void printTaskFound(ArrayList matchingTasks, int size) { + if (size > 0) { + System.out.println("Here are the matching tasks in your list:"); + for (int count = 0; count < size; count++) { + System.out.println(count + 1 + "." + matchingTasks.get(count)); + } + } else { + System.out.println("There are no task in the list containing the keyword."); + } + } + + public void printErrorMessage(String errorMessage) { + System.out.println(errorMessage); + } +} diff --git a/src/main/java/duke/exception/CommandNotFoundException.java b/src/main/java/duke/exception/CommandNotFoundException.java new file mode 100644 index 000000000..15485cdc3 --- /dev/null +++ b/src/main/java/duke/exception/CommandNotFoundException.java @@ -0,0 +1,4 @@ +package duke.exception; + +public class CommandNotFoundException extends DukeException{ +} diff --git a/src/main/java/duke/exception/DukeException.java b/src/main/java/duke/exception/DukeException.java new file mode 100644 index 000000000..ceea79b71 --- /dev/null +++ b/src/main/java/duke/exception/DukeException.java @@ -0,0 +1,4 @@ +package duke.exception; + +public class DukeException extends Exception{ +} diff --git a/src/main/java/duke/exception/IllegalFormatException.java b/src/main/java/duke/exception/IllegalFormatException.java new file mode 100644 index 000000000..69acac0da --- /dev/null +++ b/src/main/java/duke/exception/IllegalFormatException.java @@ -0,0 +1,4 @@ +package duke.exception; + +public class IllegalFormatException extends DukeException{ +} diff --git a/src/main/java/duke/exception/InvalidInputException.java b/src/main/java/duke/exception/InvalidInputException.java new file mode 100644 index 000000000..23f7a51f2 --- /dev/null +++ b/src/main/java/duke/exception/InvalidInputException.java @@ -0,0 +1,4 @@ +package duke.exception; + +public class InvalidInputException extends DukeException{ +} diff --git a/src/main/java/duke/exception/MissingInputException.java b/src/main/java/duke/exception/MissingInputException.java new file mode 100644 index 000000000..a27348daa --- /dev/null +++ b/src/main/java/duke/exception/MissingInputException.java @@ -0,0 +1,4 @@ +package duke.exception; + +public class MissingInputException extends DukeException{ +} diff --git a/src/main/java/duke/task/Deadline.java b/src/main/java/duke/task/Deadline.java new file mode 100644 index 000000000..98b1eba4f --- /dev/null +++ b/src/main/java/duke/task/Deadline.java @@ -0,0 +1,25 @@ +package duke.task; + +public class Deadline extends Task { + protected String by; + + public Deadline(String description, String by) { + super(description); + this.by = by; + } + + /** + * Printing the Task that includes whether it is done + * + * @return Returns a string that describes the object + */ + @Override + public String toString() { + return "[D]" + super.toString() + "(by: " + by + ")"; + } + + @Override + public String saveToFile() { + return "D | " + this.getStatus() + " | " + description + " | " + by + "\n"; + } +} diff --git a/src/main/java/duke/task/Event.java b/src/main/java/duke/task/Event.java new file mode 100644 index 000000000..162ef3fc0 --- /dev/null +++ b/src/main/java/duke/task/Event.java @@ -0,0 +1,23 @@ +package duke.task; + +public class Event extends Task { + + protected String from; + protected String to; + + public Event(String description, String from, String to) { + super(description); + this.from = from; + this.to = to; + } + + @Override + public String toString() { + return "[E]" + super.toString() + "(from: " + from + " to: " + to + ")"; + } + + @Override + public String saveToFile() { + return "E | " + this.getStatus() + " | " + description + " | " + from + "-" + to + "\n"; + } +} diff --git a/src/main/java/duke/task/Task.java b/src/main/java/duke/task/Task.java new file mode 100644 index 000000000..2561e265b --- /dev/null +++ b/src/main/java/duke/task/Task.java @@ -0,0 +1,66 @@ +package duke.task; + +public class Task { + protected String description; + protected boolean isDone; + + protected Task(String description) { + this.isDone = false; + this.description = description; + } + + public void markDone() { + isDone = true; + } + + public void unmarkDone() { + isDone = false; + } + + /** + * Determine if the keyword is found within the task. + * + * @param partialName Keyword that has to be found within the specified task in the list. + * @return Returns true if the specified task in the list contains the keyword and false otherwise. + */ + public boolean findMatch(String partialName) { + return description.contains(partialName); + } + + protected String getDescription() { + return description; + } + + public String status(){ + if(isDone) { + return "X"; + } + else { + return " "; + } + } + + public String getStatus(){ + if(isDone) { + return "1"; + } + else { + return "O"; + } + } + + public String saveToFile() { + return ""; + } + + /** + * Printing the Task that includes whether it is done + * + * @return Returns a string that describes the object + */ + @Override + public String toString() { + return "[" + status() + "] " + getDescription(); + } + +} diff --git a/src/main/java/duke/task/Todo.java b/src/main/java/duke/task/Todo.java new file mode 100644 index 000000000..a5baf6851 --- /dev/null +++ b/src/main/java/duke/task/Todo.java @@ -0,0 +1,24 @@ +package duke.task; + +public class Todo extends Task { + + public Todo(String description) { + super(description); + } + + + /** + * Printing the Task that includes whether it is done + * + * @return Returns a string that describes the object + */ + @Override + public String toString() { + return "[T]" + super.toString(); + } + + @Override + public String saveToFile() { + return "T | " + this.getStatus() + " | " + description + "\n"; + } +} diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 657e74f6e..d1469520d 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,7 +1,98 @@ -Hello from - ____ _ -| _ \ _ _| | _____ + ____ _ +| _ \ _ _| | _____ | | | | | | | |/ / _ \ | |_| | |_| | < __/ |____/ \__,_|_|\_\___| +____________________________________________________ +Hello! I'm Duke +What can I do for you? + +____________________________________________________ +____________________________________________________ +Got it. I've added this tasks: +[T][ ] borrow book +Now you have 1 tasks in the list. +____________________________________________________ +____________________________________________________ +Here are the tasks in your list: +1.[T][ ] borrow book +____________________________________________________ +____________________________________________________ +Got it. I've added this tasks: +[D][ ] return book(by: Sunday) +Now you have 2 tasks in the list. +____________________________________________________ +____________________________________________________ +Got it. I've added this tasks: +[E][ ] project meeting(from: Mon 2pm to: 4pm) +Now you have 3 tasks in the list. +____________________________________________________ +____________________________________________________ +Nice! I've marked this task as done: +[T][X] borrow book +____________________________________________________ +____________________________________________________ +Here are the tasks in your list: +1.[T][X] borrow book +2.[D][ ] return book(by: Sunday) +3.[E][ ] project meeting(from: Mon 2pm to: 4pm) +____________________________________________________ +____________________________________________________ +Nice! I've marked this task as done: +[D][X] return book(by: Sunday) +____________________________________________________ +____________________________________________________ +Here are the tasks in your list: +1.[T][X] borrow book +2.[D][X] return book(by: Sunday) +3.[E][ ] project meeting(from: Mon 2pm to: 4pm) +____________________________________________________ +____________________________________________________ +Nice! I've marked this task as not done yet: +[T][ ] borrow book +____________________________________________________ +____________________________________________________ +Here are the tasks in your list: +1.[T][ ] borrow book +2.[D][X] return book(by: Sunday) +3.[E][ ] project meeting(from: Mon 2pm to: 4pm) +____________________________________________________ +____________________________________________________ +Nice! I've marked this task as done: +[E][X] project meeting(from: Mon 2pm to: 4pm) +____________________________________________________ +____________________________________________________ +Here are the tasks in your list: +1.[T][ ] borrow book +2.[D][X] return book(by: Sunday) +3.[E][X] project meeting(from: Mon 2pm to: 4pm) +____________________________________________________ +____________________________________________________ +Description of the command is empty. +____________________________________________________ +____________________________________________________ +Description of the command is empty. +____________________________________________________ +____________________________________________________ +Description of the command is empty. +____________________________________________________ +____________________________________________________ +Description of the command is empty. +____________________________________________________ +____________________________________________________ +Description of the command is empty. +____________________________________________________ +____________________________________________________ +Noted. I've removed this task: +[E][X] project meeting(from: Mon 2pm to: 4pm) +Now you have 2 tasks in the list. +____________________________________________________ +____________________________________________________ +Here are the tasks in your list: +1.[T][ ] borrow book +2.[D][X] return book(by: Sunday) +____________________________________________________ +____________________________________________________ +Bye. Hope to see you again soon! +____________________________________________________ diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index e69de29bb..1b65692f3 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -0,0 +1,20 @@ +todo borrow book +list +deadline return book /by Sunday +event project meeting /from Mon 2pm /to 4pm +mark 1 +list +mark 2 +list +unmark 1 +list +mark 3 +list +todo +deadline +event +mark +unmark +delete 3 +list +bye