diff --git a/README.md b/README.md index 84755485a7..adc89910d5 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,5 @@ -# Setting up +# DUKE the Chat Bot -**Prerequisites** +DUKE is a chat bot to help you manage your tasks more efficiently! -* JDK 11 -* Recommended: IntelliJ IDE -* Fork this repo to your GitHub account and clone the fork to your computer - -**Importing the project into IntelliJ** - -1. Open IntelliJ (if you are not in the welcome screen, click `File` > `Close Project` to close the existing project dialog first). -1. Set up the correct JDK version. - * Click `Configure` > `Structure for new Projects` (in older versions of Intellij:`Configure` > `Project Defaults` > `Project Structure`). - * If JDK 11 is listed in the drop down, select it. If it is not, click `New...` and select the directory where you installed JDK 11. - * Click `OK`. -1. Click `Import Project`. -1. Locate the project directory and click `OK`. -1. Select `Create project from existing sources` and click `Next`. -1. Rename the project if you want. Click `Next`. -1. Ensure that your src folder is checked. Keep clicking `Next`. -1. Click `Finish`. - -# Tutorials - -Duke Increment | Tutorial ----------------|--------------- -`A-Gradle` | [Gradle Tutorial](tutorials/gradleTutorial.md) -`A-TextUiTesting` | [Text UI Testing Tutorial](tutorials/textUiTestingTutorial.md) -`Level-10` | JavaFX tutorials:
→ [Part 1: Introduction to JavaFX][fx1]
→ [Part 2: Creating a GUI for Duke][fx2]
→ [Part 3: Interacting with the user][fx3]
→ [Part 4: Introduction to FXML][fx4] - -[fx1]: -[fx2]: -[fx3]: -[fx4]: - -# Feedback, Bug Reports - -* If you have feedback or bug reports, please post in [se-edu/duke issue tracker](https://github.com/se-edu/duke/issues). -* We welcome pull requests too. \ No newline at end of file +To learn more about duke, please refer to our [User Guide](https://sitinadiah25.github.io/duke/). diff --git a/data/duke.txt b/data/duke.txt new file mode 100644 index 0000000000..634f1a8c8e --- /dev/null +++ b/data/duke.txt @@ -0,0 +1,6 @@ +T|0|work +E|0|kill people |work +D|0|assignment |next wk +T|0|sleep +E|1|meeting |sch +T|1|buy cat food diff --git a/docs/README.md b/docs/README.md index fd44069597..5962bb7270 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,20 +1,158 @@ -# User Guide +# DUKE User Guide +DUKE is a chat bot that helps users manage their tasks. + +## Table of Contents +- [Quick Start](#quick-start) +- [Features](#features) + + - [Add a new task](#add-a-new-task) + - [Find tasks](#find-task) + - [Delete task](#delete-task) + - [List tasks](#list-tasks) + - [Mark task as done](#mark-task-as-done) + - [Exit program](#exit-program) + +- [Feedback](#feedback) + +## Quick Start + +1. Ensure that you have `Java 11` or later installed in your computer + +2. Download `DUKE v0.2` [here](https://github.com/sitinadiah25/duke/releases/tag/A-Release) + +3. Move `duke.jar` onto your Desktop + +4. Navigate to your Desktop folder and open Terminal or Command Prompt + +5. Enter `java -jar duke.jar` to start up the program ## Features +### Add a new task +Add a new task for DUKE to store +##### Usage example: + +`todo [description]` + +`deadline [description] /by [deadline]` + +`event [description] /at [place/time]` + +###### Example: + + - `todo CS2113T iP` + + Adds a new todo task with description `CS2113T iP` into the task list. + + - `event meeting /at school` + + Adds a new event task with description `meeting` with the location of the event as `school`. + + - `deadline CS2113T iP final /by 2 March` + + Adds a deadline with description `CS2113T iP final`. + + The due date of the deadline is by `2 March`. + +> ***Expected outcome:*** +> +> ____________________________________________________________ +> Got it! I've added this task: +> [T][✘] CS2113T iP +> Now you have 1 task(s) in the list. +> ____________________________________________________________ + +### Find task +Find tasks in the task list according to the keyword given +##### Usage example: + +`find [work]` + +###### Example: + + - `find CS2113T iP` + + Finds any task that contains `CS2113T iP` in its description. + + +> ***Expected outcome:*** +> +> ____________________________________________________________ +> Here are the matching tasks in your list: +> 1.[T][✘] CS2113T iP +> ____________________________________________________________ + +### Delete task +Delete a task according to the task number given +##### Usage example: + +`delete [task number]` + +###### Example: + + - `delete 3` + + Deletes the task with task number `3`. + + +> ***Expected outcome:*** +> +> ____________________________________________________________ +> Noted. I've removed this task: +> [T][✘] work +> Now you have 3 task(s) in the list. +> ____________________________________________________________ + +### List tasks +List all the tasks that are in the task list +##### Usage example: + +`list` + +> ***Expected outcome:*** +> +> ____________________________________________________________ +> Here are the tasks in your list: +> 1. [T][✘] work +> 2. [T][✘] CS2113T iP +> 3. [E][✘] sleep (at: 12am) +> ____________________________________________________________ + +### Mark task as done +Mark a task as done according to the task number given +##### Usage example: + +`done [task number]` + +###### Example: + + - `done 3` + + Deletes the task with task number `3`. + + +> ***Expected outcome:*** +> +> ____________________________________________________________ +> Nice! I've marked this task as done: +> [E][✓] sleep (at: 12am) +> ____________________________________________________________ + +### Exit program -### Feature 1 -Description of feature. +Exit the program -## Usage +##### Usage example: -### `Keyword` - Describe action +`bye` -Describe action and its outcome. +> ***Expected outcome:*** +> +> ____________________________________________________________ +> Bye. Hope to see you again soon! +> ____________________________________________________________ -Example of usage: +## Feedback -`keyword (optional arguments)` +If you have any feedback or bugs to report, please email me at e0318697@u.nus.edu -Expected outcome: -`outcome` diff --git a/docs/_config.yml b/docs/_config.yml new file mode 100644 index 0000000000..fc24e7a62d --- /dev/null +++ b/docs/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-hacker \ No newline at end of file diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5d313334cc..ac8fb41865 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,10 +1,57 @@ +import task.Deadline; +import task.Event; +import task.Task; +import task.Todo; + +import java.io.*; +import java.util.ArrayList; +import java.util.Scanner; + public class Duke { + + private static int NUM_OF_TASK = 0; + private static final String BYE_COMMAND = "bye"; + private static final String LIST_COMMAND = "list"; + private static final String DONE_COMMAND = "done"; + private static final String TODO_COMMAND = "todo"; + private static final String EVENT_COMMAND = "event"; + private static final String DEADLINE_COMMAND = "deadline"; + private static final String DELETE_COMMAND = "delete"; + + private Ui ui; + private DukeManager dukeManager; + private Scanner in; + private Storage storage; + public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); + new Duke().start(); + } + + /* + * Set up the required classes + */ + private void start() { + this.ui = new Ui(); + this.dukeManager = new DukeManager(); + this.in = new Scanner(System.in); + this.storage = new Storage(); + run(); + } + + /* + * Run DUKE until user terminates + */ + public void run() { + ui.printWelcomeMessage(); + boolean isExit = false; + ArrayList Tasks = storage.openData(); + while (!isExit) { + String fullCommand[] = Parser.readInput(in); + ui.showLine(); + dukeManager.execute(fullCommand); + isExit = dukeManager.getIsExit(); + } + ui.printExitMessage(); } } + diff --git a/src/main/java/DukeException.java b/src/main/java/DukeException.java new file mode 100644 index 0000000000..028344f6a4 --- /dev/null +++ b/src/main/java/DukeException.java @@ -0,0 +1,2 @@ +public class DukeException extends Exception { +} diff --git a/src/main/java/DukeManager.java b/src/main/java/DukeManager.java new file mode 100644 index 0000000000..8017456fae --- /dev/null +++ b/src/main/java/DukeManager.java @@ -0,0 +1,78 @@ +import task.Task; + +import java.io.IOException; +import java.util.ArrayList; + +public class DukeManager { + + private static final String BYE_COMMAND = "bye"; + private static final String LIST_COMMAND = "list"; + private static final String DONE_COMMAND = "done"; + private static final String TODO_COMMAND = "todo"; + private static final String EVENT_COMMAND = "event"; + private static final String DEADLINE_COMMAND = "deadline"; + private static final String DELETE_COMMAND = "delete"; + private static final String FIND_COMMAND = "find"; + + private boolean isExit = false; + private TaskList taskList; + + + /** + * Constructor for the DukeManager class + * create a new TaskList + */ + public DukeManager() { + taskList = new TaskList(); + } + + /** + * Manage the command input by user + * + * @param arr The string array command input by user split by spaces + */ + public void execute(String[] arr) { + try { + switch (arr[0]) { + case (BYE_COMMAND): + isExit = true; + taskList.exitAndSave(); + break; + case (LIST_COMMAND): + taskList.getList(); + break; + case (DONE_COMMAND): + taskList.setTaskDone(arr[1]); + break; + case (TODO_COMMAND): + taskList.addTodo(arr); + break; + case (EVENT_COMMAND): + taskList.addEvent(arr); + break; + case (DEADLINE_COMMAND): + taskList.addDeadline(arr); + break; + case (DELETE_COMMAND): + taskList.deleteTask(arr); + break; + case (FIND_COMMAND): + taskList.findKeyword(arr); + break; + default: + Ui.showError("I'm sorry but I don't understand ●︿●"); + } + } catch (DukeException e) { + + } + } + + /** + * Get the boolean value of isExit + * + * @return true if user exits, false otherwise + */ + public boolean getIsExit() { + return isExit; + } +} diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..d2ffd5b4d2 --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: Duke + diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java new file mode 100644 index 0000000000..4880bba4ab --- /dev/null +++ b/src/main/java/Parser.java @@ -0,0 +1,38 @@ +import java.util.Scanner; + +public class Parser { + + /** + * Read input and split it by spaces + * + * @param in Scanner object + * @return the parsed input + */ + public static String[] readInput(Scanner in) { + String s = in.nextLine(); + String arr[] = s.split(" ", 2); + return arr; + } + + /** + * Parse the command for an event task + * + * @param arr user's command + * @return string of array split by '/at' + */ + public static String[] parseEvent(String[] arr) { + String arr2[] = arr[1].split("/at ", 2); + return arr2; + } + + /** + * Parse the command for an deadline task + * + * @param arr user's command + * @return string of array split by '/by' + */ + public static String[] parseDeadline(String[] arr) { + String arr2[] = arr[1].split("/by ", 2); + return arr2; + } +} diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java new file mode 100644 index 0000000000..00e3fc9e84 --- /dev/null +++ b/src/main/java/Storage.java @@ -0,0 +1,78 @@ +import task.Deadline; +import task.Event; +import task.Task; +import task.Todo; + +import java.io.*; +import java.util.ArrayList; + +public class Storage { + + /** + * Save the task list into a text file + * + * @param Tasks The ArrayList of tasks to be saved + */ + public static void saveData(ArrayList Tasks) { + try { + File file = new File("duke.txt"); + file.createNewFile(); + FileWriter fileWriter = new FileWriter("duke.txt", false); + for (Task task : Tasks) { + fileWriter.write(task.getDescription()); + fileWriter.write(System.lineSeparator()); + } + fileWriter.close(); + System.out.println("Data saved successfully."); + } catch (IOException e) { + System.out.println("Data cannot be saved."); + } + + } + + /** + * Open the text file that contains the previous task list data + * + * @return ArrayList of saved tasks + */ + public static ArrayList openData() { + ArrayList Tasks = new ArrayList(); + try { + FileReader fileReader = new FileReader("duke.txt"); + BufferedReader bufferedReader = new BufferedReader(fileReader); + String line = bufferedReader.readLine(); + while (line != null) { + String arr[] = line.split("[|]", 4); + switch (arr[0]) { + case ("T"): + Todo todo = new Todo(arr[2]); + if (arr[1].equals("1")) { + todo.setDone(true); + } + Tasks.add(todo); + break; + case ("D"): + Deadline deadline = new Deadline(arr[2], arr[3]); + if (arr[1].equals("1")) { + deadline.setDone(true); + } + Tasks.add(deadline); + break; + case ("E"): + Event event = new Event(arr[2], arr[3]); + if (arr[1].equals("1")) { + event.setDone(true); + } + Tasks.add(event); + break; + } + line = bufferedReader.readLine(); + } + return Tasks; + } catch (IOException e) { + System.out.println("No previous data found."); + return Tasks; + } + } + +} diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java new file mode 100644 index 0000000000..7556e8b3a8 --- /dev/null +++ b/src/main/java/TaskList.java @@ -0,0 +1,139 @@ +import task.Event; +import task.Task; +import task.Todo; + +import java.util.ArrayList; + +public class TaskList { + + private ArrayList tasks; + private Ui ui = new Ui(); + + /** + * Stores all of the user's task and opens previous data from file + */ + public TaskList() { + this.tasks = new ArrayList<>(); + this.tasks = Storage.openData(); + } + + /** + * Stores task list into text file + */ + public void exitAndSave() { + Storage.saveData(tasks); + } + + /** + * Set user task as done + * + * @param taskNum The task number for the task to be set as done + */ + public void setTaskDone(String taskNum) throws DukeException { + try { + int taskNumInt = Integer.parseInt(taskNum); + taskNumInt--; + tasks.get(taskNumInt).setDone(true); + ui.printDone(tasks.get(taskNumInt)); + } catch (NullPointerException | NumberFormatException e) { + ui.showError("Please include the task number."); + throw new DukeException(); + } catch (IndexOutOfBoundsException e) { + ui.showError("Task number does not exist. Please try again!"); + throw new DukeException(); + } + } + + /** + * Get and print the list of tasks + */ + public void getList() { + if (tasks.size() == 0) { + ui.showError("No tasks found!"); + } else { + ui.printList(tasks, tasks.size()); + } + } + + /** + * Add new todo task into the last list + * + * @param arr The string array command input by user split by spaces + */ + public void addTodo(String[] arr) throws DukeException { + try { + Todo todo = new Todo(arr[1]); + tasks.add(todo); + ui.printConfirm(tasks.get(tasks.size()-1), tasks.size()); + } catch (ArrayIndexOutOfBoundsException e) { + ui.showError("Please include your task."); + throw new DukeException(); + } + } + + /** + * Add new event task into the task list + * + * @param arr The string array command input by user split by spaces + */ + public void addEvent(String[] arr) throws DukeException { + try { + String arr2[] = Parser.parseEvent(arr); + Event event = new Event(arr2[0], arr2[1]); + tasks.add(event); + ui.printConfirm(tasks.get(tasks.size()-1), tasks.size()); + } catch (ArrayIndexOutOfBoundsException e) { + ui.showError("Please include your task."); + throw new DukeException(); + } + } + + /** + * Add new deadline task into the task list + * + * @param arr The string array command input by user split by spaces + */ + public void addDeadline(String[] arr) throws DukeException { + try { + String arr2[] = Parser.parseDeadline(arr); + Event event = new Event(arr2[0], arr2[1]); + tasks.add(event); + ui.printConfirm(tasks.get(tasks.size()-1), tasks.size()); + } catch (ArrayIndexOutOfBoundsException e) { + ui.showError("Please include your task."); + throw new DukeException(); + } + } + + /** + * Delete a task from the task list + * + * @param arr The string array command input by user split by spaces + */ + public void deleteTask(String[] arr) throws DukeException { + try { + int taskNum = Integer.parseInt(arr[1]) - 1; + ui.printDelete(tasks.get(taskNum), tasks.size()); + tasks.remove(taskNum); + } catch (NullPointerException | NumberFormatException e) { + ui.showError("Please include the task number."); + throw new DukeException(); + } catch (IndexOutOfBoundsException e) { + ui.showError("Task number does not exist. Please try again!"); + throw new DukeException(); + } + } + + public void findKeyword(String[] arr) { + String word = String.join(" ", arr[1]); + ArrayList findTask = new ArrayList(); + for (int i = 0; i < tasks.size(); i++) { + String desc = tasks.get(i).getDescription(); + if (desc.contains(word)) { + findTask.add(tasks.get(i)); + } + } + ui.findList(findTask, findTask.size()); + } + +} diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java new file mode 100644 index 0000000000..ee0afcaf44 --- /dev/null +++ b/src/main/java/Ui.java @@ -0,0 +1,158 @@ +import task.Task; + +import java.io.InputStream; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Scanner; + +public class Ui { + + private static String LINE = "____________________________________________________________"; + + + private final Scanner in; + private final PrintStream out; + + public Ui() { + this(System.in, System.out); + } + + public Ui(InputStream in, PrintStream out) { + this.in = new Scanner(in); + this.out = out; + } + + public static void showLine() { + System.out.println(LINE); + } + + /** + * Prints welcome message as the application starts + */ + public static void printWelcomeMessage() { + String logo = " _____ ___ ___ ___ \n" + + " / /::\\ /__/\\ /__/| / /\\ \n" + + " / /:/\\:\\ \\ \\:\\ | |:| / /:/_ \n" + + " / /:/ \\:\\ \\ \\:\\ | |:| / /:/ /\\ \n" + + " /__/:/ \\__\\:| ___ \\ \\:\\ __| |:| / /:/ /:/_ \n" + + " \\ \\:\\ / /:/ /__/\\ \\__\\:\\ /__/\\_|:|____ /__/:/ /:/ /\\\n" + + " \\ \\:\\ /:/ \\ \\:\\ / /:/ \\ \\:\\/:::::/ \\ \\:\\/:/ /:/\n" + + " \\ \\:\\/:/ \\ \\:\\ /:/ \\ \\::/~~~~ \\ \\::/ /:/ \n" + + " \\ \\::/ \\ \\:\\/:/ \\ \\:\\ \\ \\:\\/:/ \n" + + " \\__\\/ \\ \\::/ \\ \\:\\ \\ \\::/ \n" + + " \\__\\/ \\__\\/ \\__\\/ \n"; + + System.out.println("What is up my dudes!\n" + logo); + + String intro = " Hello there, welcome to DUKE!\n" + + " How may I help you today?"; + + showLine(); + System.out.println(intro); + showLine(); + } + + /** + * Displays the task which the user has deleted + * Shows the number of tasks remaining in the task list + * + * @param task The task which the user wants to delete from the list + * @param numOfTasks The number of tasks in the list + */ + public static void printDelete(Task task, int numOfTasks) { + showLine(); + System.out.println("Noted. I've removed this task: "); + System.out.println(" " + task); + numOfTasks--; + System.out.println("Now you have " + numOfTasks + " task(s) in the list."); + showLine(); + } + + /** + * Displays the task which the user has marked as done + * + * @param task The task which the user has marked as done + */ + public static void printDone(Task task) { + showLine(); + System.out.println("Nice! I've marked this task as done: "); + System.out.println(" " + task); + showLine(); + } + + /** + * Displays a confirmation message to show that the task was added into the list + * Shows the number of tasks in the list + * + * @param Task The list of tasks + * @param numOfTasks The number of tasks in the list + */ + public static void printConfirm(Task task, int numOfTasks) { + showLine(); + System.out.println("Got it! I've added this task:"); + System.out.println(" " + task); + System.out.println("Now you have " + numOfTasks + " task(s) in the list."); + showLine(); + } + + /** + * Prints the exit message when the user exits the application + */ + public static void printExitMessage() { + showLine(); + String outro = "Bye. Hope to see you again soon!"; + System.out.println(outro); + showLine(); + } + + /** + * Displays the list of tasks that are in the list + * + * @param Task The list of tasks + * @param numOfTasks The number of tasks in the list + */ + public static void printList(ArrayList Task, int numOfTasks) { + showLine(); + if (numOfTasks == 0) { + showError("No tasks found!"); + } else { + System.out.println("Here are the tasks in your list: \n"); + for (int i = 0; i < numOfTasks; i++) { + int num = i + 1; + System.out.println(num + ". " + Task.get(i)); + } + } + showLine(); + } + + /** + * Displays the list of tasks that have descriptions matching keyword + * + * @param Task The list of tasks + * @param numOfTasks The number of tasks in the list + */ + public static void findList(ArrayList Task, int numOfTasks) { + showLine(); + if (numOfTasks == 0) { + showError("No tasks found!"); + } else { + System.out.println("Here are the matching tasks in your list: "); + for (int i = 0; i < numOfTasks; i++) { + int num = i + 1; + System.out.println(num + ". " + Task.get(i)); + } + } + showLine(); + } + + /** + * Displays an error message + * + * @param error The message to be displayed + */ + public static void showError(String error) { + showLine(); + System.out.println(error); + showLine(); + } +} diff --git a/src/main/java/task/Deadline.java b/src/main/java/task/Deadline.java new file mode 100644 index 0000000000..55149bf9b5 --- /dev/null +++ b/src/main/java/task/Deadline.java @@ -0,0 +1,55 @@ +package task; + +public class Deadline extends Task { + protected String by; + + /** + * Constructor for the Deadline class + * + * @param description the description of the deadline + * @param by the deadline of the task + */ + public Deadline(String description, String by) { + super(description); + this.by = by; + } + + /** + * Get the deadline of the task + * + * @return the task's deadline + */ + public String getBy() { + return by; + } + + /** + * Set the deadline of the task + * + * @param by the task's deadline + */ + public void setBy(String by) { + this.by = by; + } + + /** + * Returns the status and the description as a string prepended with "[D]" + * and appended with "(by ...") + * + * @return String of status and description of task + */ + @Override + public String toString() { + return "[D]" + super.toString() + "(by: " + this.by + ")"; + } + + /** + * The description of the task to be saved + * + * @return Description of task and its status with T to indicate Deadline + */ + @Override + public String saveTask() { + return "D|" + super.isDoneNum() + "|" + super.saveTask() + "|" + this.by; + } +} diff --git a/src/main/java/task/Event.java b/src/main/java/task/Event.java new file mode 100644 index 0000000000..ef151f2cf9 --- /dev/null +++ b/src/main/java/task/Event.java @@ -0,0 +1,38 @@ +package task; + +public class Event extends Task { + + protected String time; + + /** + * Constructor of the Event class + * + * @param description description of the event + * @param time time of the event + */ + public Event(String description, String time) { + super(description); + this.time = time; + } + + /** + * Returns the status and the description as a string prepended with "[E]" + * and appended with "(at ...)" + * + * @return String of status and description of task + */ + @Override + public String toString() { + return "[E]" + super.toString() + "(at: " + this.time + ")"; + } + + /** + * The description of the task to be saved + * + * @return Description of task and its status with T to indicate Event + */ + @Override + public String saveTask() { + return "E|" + super.isDoneNum() + "|" + super.saveTask() + "|" + this.time; + } +} diff --git a/src/main/java/task/Task.java b/src/main/java/task/Task.java new file mode 100644 index 0000000000..2d24c89c0d --- /dev/null +++ b/src/main/java/task/Task.java @@ -0,0 +1,90 @@ +package task; + +public class Task { + protected String description; + protected boolean isDone; + protected int num; + + private static int curr = 1; + + /** + * Constructor for Task class + * Sets isDone to false + * + * @param description The description of the task + */ + public Task(String description) { + this.description = description; + this.isDone = false; + this.num = curr; + curr++; + } + + /** + * Returns the status of the task in form of an icon. + * "\u2713" is returned to denote that the task is complete. + * "\u2718" is returned to denote that the task is incomplete. + * + * @return statusIcon Represents the current status of the task as described above. + */ + public String getStatusIcon() { + return (isDone ? "\u2713" : "\u2718"); //return tick or X symbols + } + + /** + * Get the description of the task + * + * @return description of task + */ + public String getDescription() { + return description; + } + + /** + * Set the description of task + * + * @param description The modified description of the task + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * Get the integer value of boolean value isDone + * + * @return 1 if isDone is true, 0 otherwise + */ + public int isDoneNum() { + if (isDone) { + return 1; + } + return 0; + } + + /** + * Set the isDone value to the input + * + * @param done Boolean value to be set to isDone + */ + public void setDone(boolean done) { + isDone = done; + } + + /** + * Returns the status and the description as a string + * + * @return String of status and description of task + */ + public String toString() { + return "[" + this.getStatusIcon() + "] " + description; + } + + /** + * The description of the task to be saved + * + * @return Description of task + */ + public String saveTask() { + return description; + } +} diff --git a/src/main/java/task/Todo.java b/src/main/java/task/Todo.java new file mode 100644 index 0000000000..f1c39088dd --- /dev/null +++ b/src/main/java/task/Todo.java @@ -0,0 +1,33 @@ +package task; + +public class Todo extends Task{ + + /** + * Constructor for Todo class + * + * @param description the description of the todo task + */ + public Todo(String description) { + super(description); + } + + /** + * Returns the status and the description as a string prepended with "[T]" + * + * @return String of status and description of task + */ + @Override + public String toString() { + return "[T]" + super.toString(); + } + + /** + * The description of the task to be saved + * + * @return Description of task and its status with T to indicate Todo + */ + @Override + public String saveTask() { + return "T|" + super.isDoneNum() + "|" + super.saveTask(); + } +} diff --git a/text-ui-test/EXPECTED.txt b/text-ui-test/EXPECTED.txt new file mode 100644 index 0000000000..0bf93ee06f --- /dev/null +++ b/text-ui-test/EXPECTED.txt @@ -0,0 +1,105 @@ +What is up my dudes! +──────────▄▄▄▄▄▄▄▄▄▄▄────────── +─────▄▄▀▀▀▀──────────▀▀▄▄────── +───▄▀───────────────────▀▀▄──── +──█────────────────────────█─── +─█─────────────────────▄▀▀▀▀▀█▄ +█▀────────────────────█────▄███ +█─────────────────────█────▀███ +█─────▄▀▀██▀▄─────────█───────█ +█────█──████─█─────────▀▄▄▄▄▄█─ +█────█──▀██▀─█───────────────█─ +█────█───────█──────────────▄▀─ +█────▀▄─────▄▀──▄▄▄▄▄▄▄▄▄───█── +█──────▀▀▀▀▀────█─█─█─█─█──▄▀── +─█──────────────▀▄█▄█▄█▀──▄▀─── +──█──────────────────────▄▀──── +───▀▀▀▄──────────▄▄▄▄▄▄▀▀────── +────▄▀─────────▀▀──▄▀────────── +──▄▀───────────────█─────────── +─▄▀────────────────█──▄▀▀▀█▀▀▄─ +─█────█──█▀▀▀▄─────█▀▀────█──█─ +▄█────▀▀▀────█─────█────▀▀───█─ +█▀▄──────────█─────█▄────────█─ +█──▀▀▀▀▀█▄▄▄▄▀─────▀█▀▀▀▄▄▄▄▀── +█───────────────────▀▄───────── + +____________________________________________________________ + It is I, Bob! + How may I spook you today? +____________________________________________________________ + +____________________________________________________________ + +Got it! I've added this task: + [T][✘] call dentist +Now you have 1 task(s) in the list. +____________________________________________________________ + +____________________________________________________________ + +Got it! I've added this task: + [T][✘] make appointment at clinic +Now you have 2 task(s) in the list. +____________________________________________________________ + +____________________________________________________________ + +Got it! I've added this task: + [E][✘] team meeting (at: AS3 10 Feb 10am) +Now you have 3 task(s) in the list. +____________________________________________________________ + +____________________________________________________________ + +Got it! I've added this task: + [D][✘] OP1 research (by: 6 Feb) +Now you have 4 task(s) in the list. +____________________________________________________________ + +____________________________________________________________ + +Got it! I've added this task: + [E][✘] Project Link sales (at: 4 Feb 1pm) +Now you have 5 task(s) in the list. +____________________________________________________________ + +____________________________________________________________ + +Here are the tasks in your list: + +1. [T][✘] call dentist +2. [T][✘] make appointment at clinic +3. [E][✘] team meeting (at: AS3 10 Feb 10am) +4. [D][✘] OP1 research (by: 6 Feb) +5. [E][✘] Project Link sales (at: 4 Feb 1pm) +____________________________________________________________ + +____________________________________________________________ + +Nice! I've marked this task as done: + [T][✓] make appointment at clinic +____________________________________________________________ + +____________________________________________________________ + +Nice! I've marked this task as done: + [D][✓] OP1 research (by: 6 Feb) +____________________________________________________________ + +____________________________________________________________ + +Here are the tasks in your list: + +1. [T][✘] call dentist +2. [T][✓] make appointment at clinic +3. [E][✘] team meeting (at: AS3 10 Feb 10am) +4. [D][✓] OP1 research (by: 6 Feb) +5. [E][✘] Project Link sales (at: 4 Feb 1pm) +____________________________________________________________ + +____________________________________________________________ + +Bye. Hope to see you again soon! +____________________________________________________________ + diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt new file mode 100644 index 0000000000..f7e65381c3 --- /dev/null +++ b/text-ui-test/input.txt @@ -0,0 +1,10 @@ +todo call dentist +todo make appointment at clinic +event team meeting /at AS3 10 Feb 10am +deadline OP1 research /by 6 Feb +event Project Link sales /at 4 Feb 1pm +list +done 2 +done 4 +list +bye diff --git a/text-ui-test/runtest.sh b/text-ui-test/runtest.sh new file mode 100644 index 0000000000..7d1e729682 --- /dev/null +++ b/text-ui-test/runtest.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +# create bin directory if it doesn't exist +if [ ! -d "../bin" ] +then + mkdir ../bin +fi + +# delete output from previous run +if [ -e "./ACTUAL.TXT" ] +then + rm ACTUAL.TXT +fi + +# compile the code into the bin folder, terminates if error occurred +if ! javac -cp ../src -Xlint:none -d ../bin ../src/main/java/*.java +then + echo "********** BUILD FAILURE **********" + exit 1 +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 + +# compare the output to the expected output +diff ACTUAL.TXT EXPECTED.TXT +if [ $? -eq 0 ] +then + echo "Test result: PASSED" + exit 0 +else + echo "Test result: FAILED" + exit 1 +fi +