diff --git a/README.md b/README.md index 8715d4d91..2ca9a54d8 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,4 @@ -# Duke project template +# Huan +A simple, easy to use chatbot for task managing. -This is a project template for a greenfield Java project. It's named after the Java mascot _Duke_. Given below are instructions on how to use it. - -## Setting up in Intellij - -Prerequisites: JDK 11, update Intellij to the most recent version. - -1. Open Intellij (if you are not in the welcome screen, click `File` > `Close Project` to close the existing project first) -1. Open the project into Intellij as follows: - 1. Click `Open`. - 1. Select the project directory, and click `OK`. - 1. If there are any further prompts, accept the defaults. -1. Configure the project to use **JDK 11** (not other versions) as explained in [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk).
- In the same dialog, set the **Project language level** field to the `SDK default` option. -3. After that, locate the `src/main/java/Duke.java` file, right-click it, and choose `Run Duke.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output: - ``` - Hello from - ____ _ - | _ \ _ _| | _____ - | | | | | | | |/ / _ \ - | |_| | |_| | < __/ - |____/ \__,_|_|\_\___| - ``` +Its name's Huan, btw diff --git a/docs/README.md b/docs/README.md index 8077118eb..f73aae35b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,29 +1,63 @@ # User Guide -## Features - -### Feature-ABC - -Description of the feature. - -### Feature-XYZ - -Description of the feature. - -## Usage - -### `Keyword` - Describe action - -Describe the action and its outcome. - -Example of usage: - -`keyword (optional arguments)` - -Expected outcome: - -Description of the outcome. - -``` -expected output -``` +## Features + +### Simple, easy to use interface + +Huan's a bot of few words, but the meaning always gets across + +### Supports multiple types of tasks + +currently have 3 types: + +- todo-tasks, which can be marked as finished or unfinished. +- EventTasks, for representing your future events, have a start time and an end time, can also be marked as finished or unfinished +- DeadlineTasks, for tasks with specific deadlines, comes with an additional datetime field which can be used for organizing your deadlines + +### data persistence through file storage + +All changes to the task list will be saved on your computer, and will be safely loaded next time when launching the chatbot. + +So there's no data loss between different instances of launching. + +### find tasks via name + +supports task-filtering using names + +### filter deadline tasks before a specific time + +find all deadlines before a specific time with special formatting + +## Commands + +- bye + - safely quit the chatbot +- list + - list all the tasks you currently have +- todo *taskName + - add a todo type task to your list, taskname can have in-between spaces + - e.g. `todo do homework` +- event *taskname /from *starttime /to *endtime + - add a event type task to your list, taskname, starttime, endtime can have in-between spaces + - e.g. `event concert with gf /from 3pm /to 6pm` +- deadline *task /by *ddltime + - add a deadline type task to your list, taskname, ddltime can have in-between spaces + - ddltime can be formatted in a special way to support date time tracking, format is "yyyy-MM-dd HH:mm:ss" + - e.g. "deadline 2113 gp /by 2024-03-08 23:59:59" or "deadline book report /by tonight" +- mark *index + - mark the n-th task in the list as completed + - use `list` to check for index if not certain + - e.g. `mark 3` +- unmark *index + - unmark the n-th task in the list + - e.g. `unmark 2` +- delete *index + - remove the n-th task from the list + - e.g. `delete 6` +- find *name + - list all tasks with tasknames containing *name + - e.g. `find book` +- list_deadline *datetime + - list all deadline tasks before a given time + - all time must be correctly formatted("yyyy-MM-dd HH:mm:ss") + - only deadline tasks with correctly formatted datetime values will be listed 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/huan/main/Huan.java b/src/main/java/huan/main/Huan.java new file mode 100644 index 000000000..4451e06fd --- /dev/null +++ b/src/main/java/huan/main/Huan.java @@ -0,0 +1,19 @@ +package huan.main; + +/** + * Main Class + */ +public class Huan { + /** + * Main function + * @param args unused + */ + public static void main(String[] args) { + UI.displayWelcomeMessage(); + + Storage.readFile(); + + Parser.parseCommands(); + } + +} diff --git a/src/main/java/huan/main/Parser.java b/src/main/java/huan/main/Parser.java new file mode 100644 index 000000000..3bb64b390 --- /dev/null +++ b/src/main/java/huan/main/Parser.java @@ -0,0 +1,259 @@ +package huan.main; +import huan.task.*; + +import java.util.Objects; +import java.util.Scanner; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; + +/** + * Class for parsing all user commands + */ +public class Parser { + /** + * Method for parsing command inputs + */ + public static void parseCommands() { + + Scanner scanner = new Scanner(System.in); + while(true) { + UI.displaySeparator(); + + String inputCommand = scanner.nextLine(); + String[] words = inputCommand.split(" "); + String firstWord = words[0]; + String suffixWord; + if(words.length > 1) { + suffixWord = inputCommand.substring(words[0].length() + 1); + } + else { + suffixWord = ""; + } + + + switch (firstWord) { + case ("bye"): + if(!suffixWord.isEmpty()) { + UI.displayFormatError("'bye'"); + break; + } + UI.displayByeMessage(); + return; + case ("list"): + if(!suffixWord.isEmpty()) { + UI.displayFormatError("'list'"); + break; + } + UI.listTasks(); + break; + case ("mark"): + try { + int markIndex = Integer.parseInt(suffixWord); + if (!TaskList.isIndexValid(markIndex)) { + UI.displayIndexError(); + } else { + TaskList.tasks.get(markIndex - 1).setIsDone(true); + + UI.displayMarkTaskSuccess(markIndex); + + Storage.writeFile(); + } + } catch (Exception e){ + UI.displayFormatError("'mark *n', where n is the index of the task you wish to mark as finished"); + } + break; + case ("unmark"): + try { + int unmarkIndex = Integer.parseInt(suffixWord); + if (!TaskList.isIndexValid(unmarkIndex)) { + UI.displayIndexError(); + } else { + TaskList.tasks.get(unmarkIndex - 1).setIsDone(false); + + UI.displayUnmarkTaskSuccess(unmarkIndex); + + Storage.writeFile(); + } + } catch (Exception e){ + UI.displayFormatError("'unmark *n', where n is the index of the task you wish to mark as unfinished."); + } + break; + case ("todo"): + if(suffixWord.isEmpty()) { + UI.displayFormatError("'todo *task_name'"); + break; + } + TodoTask todoTask = parseTodoTask(suffixWord, false); + TaskList.addTask(todoTask); + + UI.displayAddTodoSuccess(todoTask.getName()); + + Storage.writeFile(); + break; + case ("event"): + try { + EventTask eventTask = parseEventTask(suffixWord, false); + TaskList.addTask(eventTask); + + UI.displayAddEventSuccess(eventTask.getName()); + + Storage.writeFile(); + } catch (Exception e) { + UI.displayFormatError("'event *event_name /from *start_time /to *end_time'"); + } + break; + case ("deadline"): + try { + DeadlineTask deadlineTask = parseDeadlineTask(suffixWord, false); + + TaskList.addTask(deadlineTask); + + UI.displayAddDeadlineSuccess(deadlineTask.getName()); + + Storage.writeFile(); + } catch (Exception e) { + UI.displayFormatError("'deadline *task_name /by *deadline_time'"); + } + break; + case ("delete"): + try { + int deleteIndex = Integer.parseInt(suffixWord); + if (!TaskList.isIndexValid(deleteIndex)) { + UI.displayIndexError(); + } else { + TaskList.tasks.get(deleteIndex - 1).setIsDone(true); + + UI.displayDeleteTaskSuccess(deleteIndex); + + TaskList.tasks.remove(deleteIndex - 1); + + Storage.writeFile(); + } + } catch (Exception e) { + UI.displayFormatError("'delete *n', where n is the index of the task you wish to delete."); + } + break; + case ("find"): + if(!suffixWord.isEmpty()) { + UI.displayMatchingTasks(suffixWord); + } else { + UI.displayFormatError("'find *keyword'"); + } + break; + case ("list_deadline"): + try { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + + LocalDateTime dateTime = LocalDateTime.parse(suffixWord, formatter); + + UI.listTaskBeforeDateTime(dateTime); + } catch(DateTimeParseException e) { + UI.displayFormatError("'list_deadline yyyy-MM-dd HH:mm:ss'"); + } + break; + default: + UI.displayUnrecognizedMessage(); + break; + } + + } + } + + /** + * Method for parsing a TodoTask from the command + * @param suffixWord the command-string to be parsed + * @param isDone whether the task is marked as finished + * @return a parsed TodoTask type object + */ + public static TodoTask parseTodoTask(String suffixWord, Boolean isDone) { + return new TodoTask(suffixWord, isDone); + } + + /** + * Method for parsing a DeadlineTask from the command + * @param suffixWord the command-string to be parsed + * @param isDone whether the task is marked as finished + * @return a parsed DeadlineTask type object + * @throws Exception detect whether the command format is incorrect + */ + public static DeadlineTask parseDeadlineTask(String suffixWord, Boolean isDone) throws Exception{ + StringBuilder ddlTime = new StringBuilder(); + StringBuilder name = new StringBuilder(); + String[] words = suffixWord.split(" "); + /* + state: + 0 means currently concatenating name + 1 means currently concatenating ddlTime + */ + int state = 0; + for(String word : words) { + if (Objects.equals(word, "/by")) { + state += 1; + } + else { + switch (state) { + case (0): + name.append((name.length() == 0) ? "" : " ").append(word); + break; + case (1): + ddlTime.append((ddlTime.length() == 0 ? "" : " ")).append(word); + break; + } + } + } + if(state != 1 || name.toString().isEmpty() || ddlTime.toString().isEmpty()) { + throw new Exception(); + } + + return new DeadlineTask(name.toString(), ddlTime.toString(), isDone); + } + + /** + * Method for parsing a EventTask from the command + * @param suffixWord the command-string to be parsed + * @param isDone whether the task is marked as finished + * @return a parsed EventTask type object + * @throws Exception detect whether the command format is incorrect + */ + public static EventTask parseEventTask(String suffixWord, Boolean isDone) throws Exception{ + StringBuilder startTime = new StringBuilder(); + StringBuilder endTime = new StringBuilder(); + StringBuilder name = new StringBuilder(); + String[] words = suffixWord.split(" "); + /* + state: + 0 means currently concatenating name + 1 means currently concatenating startTime + 2 means currently concatenating endTime + */ + int state = 0; + for(String word : words) { + if (Objects.equals(word, "/from")) { + state += 1; + } + else if (Objects.equals(word, "/to")) { + state += 1; + } + else { + switch (state) { + case (0): + name.append((name.length() == 0) ? "" : " ").append(word); + break; + case (1): + startTime.append((startTime.length() == 0 ? "" : " ")).append(word); + break; + case (2): + endTime.append((endTime.length() == 0 ? "" : " ")).append(word); + break; + } + } + } + if(state != 2 || name.toString().isEmpty() || startTime.toString().isEmpty() || endTime.toString().isEmpty()) { + throw new Exception(); + } + + return new EventTask(name.toString(), startTime.toString(), endTime.toString(), isDone); + } +} diff --git a/src/main/java/huan/main/Storage.java b/src/main/java/huan/main/Storage.java new file mode 100644 index 000000000..cbbb74ea4 --- /dev/null +++ b/src/main/java/huan/main/Storage.java @@ -0,0 +1,78 @@ +package huan.main; + +import huan.task.Task; + +import java.io.IOException; +import java.io.FileReader; +import java.io.BufferedReader; +import java.io.FileWriter; +import java.io.BufferedWriter; + +/** + * Class for reading & writing input/output to file + */ +public class Storage { + private static String taskFile = "tasklist.txt"; + + /** + * Method for processing a line of input + * @param line the line to be processed + * @throws Exception exception is thrown whenever the input format is corrupt. + */ + public static void processLine(String line) throws Exception{ + String[] words = line.split(" "); + String suffixWord = line.substring(words[0].length() + 1); + + if (words[0].length() != 2 || (words[0].charAt(1) != 'T' && words[0].charAt(1) != 'F')) { + throw new Exception(); + } + + switch (words[0].charAt(0)) { + case ('T'): + TaskList.addTask(Parser.parseTodoTask(suffixWord, words[0].charAt(1) == 'T')); + break; + case ('D'): + TaskList.addTask(Parser.parseDeadlineTask(suffixWord, words[0].charAt(1) == 'T')); + break; + case ('E'): + TaskList.addTask(Parser.parseEventTask(suffixWord, words[0].charAt(1) == 'T')); + break; + default: + throw new Exception(); + } + } + + /** + * Method for reading the input file + */ + public static void readFile() { + try (BufferedReader reader= new BufferedReader(new FileReader(taskFile))){ + String line; + try { + while ((line = reader.readLine()) != null) { + processLine(line); + } + } catch (Exception e) { + TaskList.clearTasks(); + } + } catch (IOException e) { + TaskList.clearTasks(); + } + } + + /** + * Method for writing the current task list to the file + */ + public static void writeFile() { + try { + BufferedWriter writer = new BufferedWriter(new FileWriter(taskFile)); + for (Task task : TaskList.tasks) { + writer.write(task.writeLine()); + writer.newLine(); + } + writer.flush(); + }catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/huan/main/TaskList.java b/src/main/java/huan/main/TaskList.java new file mode 100644 index 000000000..e36de91e8 --- /dev/null +++ b/src/main/java/huan/main/TaskList.java @@ -0,0 +1,38 @@ +package huan.main; + +import huan.task.Task; + +import java.util.ArrayList; +import java.util.List; + +/** + * Class for storing the list of tasks, include methods for checking index validity, adding task and clear entire list + */ +public class TaskList { + public static List tasks = new ArrayList<>(); + + /** + * Method for checking whether the given index is valid + * @param index the given index, can be used for either marking, unmarking, and deleting the indexed tasks + * @return whether the index in within range of the list + */ + public static Boolean isIndexValid(int index) { + return index >= 1 && index <= tasks.size(); + } + + /** + * Method for adding a task to the List + * @param newTask the task to be added + */ + public static void addTask(Task newTask) { + tasks.add(newTask); + } + + /** + * Method for clearing the list, in case of corrupt or empty input + */ + public static void clearTasks() { + tasks.clear(); + } + +} diff --git a/src/main/java/huan/main/UI.java b/src/main/java/huan/main/UI.java new file mode 100644 index 000000000..68293b84e --- /dev/null +++ b/src/main/java/huan/main/UI.java @@ -0,0 +1,162 @@ +package huan.main; + +import huan.task.DeadlineTask; +import huan.task.Task; + +import java.time.LocalDateTime; + +public class UI { + private static String botName = "Huan"; + + /** + * Display welcome message + */ + public static void displayWelcomeMessage() { + System.out.println("Hello! I'm " + botName + ", a chat bot"); + } + + /** + * Display a separator line + */ + public static void displaySeparator() { + System.out.println("-------------------------"); + } + + /** + * Display a message to inform format error, and show the correct format + * @param correctFormat the correct format, as well as any necessary information + */ + public static void displayFormatError(String correctFormat) { + System.out.println("Invalid format! Should be " + correctFormat); + } + + /** + * Display a message informing an unrecognized message + */ + public static void displayUnrecognizedMessage() { + System.out.println("Unrecognized command, please try again!"); + } + + /** + * Display a message informing success adding a new TodoTask + * @param taskName name of the task + */ + public static void displayAddTodoSuccess(String taskName) { + System.out.println("Added todo type task with name: " + taskName); + } + + /** + * Display a message informing success adding a new EventTask + * @param taskName name of the task + */ + public static void displayAddEventSuccess(String taskName) { + System.out.println("Added event type task with name: " + taskName); + } + + /** + * Display a message informing success adding a new DeadlineTask + * @param taskName + */ + public static void displayAddDeadlineSuccess(String taskName) { + System.out.println("Added deadline type task with name: " + taskName); + } + + /** + * Display a message informing success deleting a new task + * @param deleteIndex index of the to-be-deleted task + */ + public static void displayDeleteTaskSuccess(int deleteIndex) { + System.out.println("Removed task number " + deleteIndex + ": " + TaskList.tasks.get(deleteIndex - 1).getName()); + } + + /** + * Display a message informing success marking a Task as completed + * @param markIndex index of the to-be-marked task + */ + public static void displayMarkTaskSuccess(int markIndex) { + System.out.println("Set task number " + markIndex + ": " + TaskList.tasks.get(markIndex - 1).getName() + " as done."); + } + + /** + * Display a message informing success unmarking a Task as completed + * @param unmarkIndex index of the to-be-unmarked task + */ + public static void displayUnmarkTaskSuccess(int unmarkIndex) { + System.out.println("Set task number " + unmarkIndex + ": " + TaskList.tasks.get(unmarkIndex - 1).getName() + " as not done."); + } + + /** + * Display a message informing the index input is incorrect + */ + public static void displayIndexError() { + System.out.println("Invalid task index!"); + } + + /** + * Display a goodbye message + */ + public static void displayByeMessage() { + System.out.println("Bye! See ya!"); + } + + /** + * Show the matching tasks in the list, with a given keyword + * @param keyword the keyword for matching + */ + public static void displayMatchingTasks(String keyword) { + int cnt = 0; + for (Task task : TaskList.tasks) { + if (task.getName().toLowerCase().contains(keyword.toLowerCase())) { + cnt += 1; + task.printTask(); + } + } + System.out.println("Found " + cnt + " matching tasks."); + } + + /** + * Display a message informing success in parsing a LocalDateTime + */ + public static void displayDateTimeParseSuccess() { + System.out.println("Parsing dateTime success!"); + } + + /** + * Display a message informing failure in parsing a LocalDateTime + */ + public static void displayDateTimeParseError() { + System.out.println("Parsing dateTime failed, Use format 'yyyy-mm-dd HH:mm:ss'"); + } + + /** + * List all tasks in the List + */ + public static void listTasks() { + int cnt = 0; + System.out.println("You have a total of " + TaskList.tasks.size() + " tasks."); + for (Task task : TaskList.tasks) { + cnt += 1; + System.out.printf(cnt + ". "); + + task.printTask(); + } + } + + /** + * List all DeadlineTasks before the given date time + * @param dateTime the given datetime + */ + public static void listTaskBeforeDateTime(LocalDateTime dateTime) { + int cnt = 0; + for (Task task : TaskList.tasks) { + if (task.getTaskType() == 3) { + DeadlineTask ddlTask = (DeadlineTask)task; + if(ddlTask.isBefore(dateTime)) { + cnt += 1; + ddlTask.printTask(); + } + } + } + System.out.println("You have a total of " + cnt + " deadlines before " + dateTime); + } +} diff --git a/src/main/java/huan/task/DeadlineTask.java b/src/main/java/huan/task/DeadlineTask.java new file mode 100644 index 000000000..9067d583b --- /dev/null +++ b/src/main/java/huan/task/DeadlineTask.java @@ -0,0 +1,83 @@ +package huan.task; + +import huan.main.UI; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; + +/** + * Class for tasks with a specific deadline + */ +public class DeadlineTask extends Task{ + private String ddlTime; + private LocalDateTime dateTime; + + /** + * Constructor method for DeadlineTask + * @param name task name + * @param ddlTime the time of the deadline + * @param isDone whether the task is marked as finished + */ + public DeadlineTask(String name, String ddlTime, Boolean isDone) { + setName(name); + this.ddlTime = ddlTime; + setIsDone(isDone); + setTaskType(3); + + try { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + dateTime = LocalDateTime.parse(ddlTime, formatter); + UI.displayDateTimeParseSuccess(); + + } catch(DateTimeParseException e) { + dateTime = null; + UI.displayDateTimeParseError(); + } + } + + /** + * Method for checking whether the deadline is before a specific time + * @param dateTime the given time + * @return whether the deadline is before a specific time + */ + public Boolean isBefore(LocalDateTime dateTime) { + if (this.dateTime == null) { + return false; + } + return this.dateTime.isBefore(dateTime); + } + + /** + * Method for printing an DeadlineTask + */ + @Override + public void printTask() { + System.out.println("[D][" + (getIsDone() ? "X" : " ") + "] " + getName() + " (by: " + ddlTime + ")"); + } + + /** + * Method for writing the DeadlineTask to file + * @return the line to be written to ile + */ + @Override + public String writeLine() { + return "D" + (getIsDone() ? "T" : "F") + " " + getName() + " /by " + ddlTime; + } + + /** + * Get method for the ddlTime attribute + * @return the ddlTime attribute + */ + public String getDdlTime() { + return ddlTime; + } + + /** + * Set method for the ddlTime attribute + * @param ddlTime the ddlTime attribute + */ + public void setDdlTime(String ddlTime) { + this.ddlTime = ddlTime; + } + +} diff --git a/src/main/java/huan/task/EventTask.java b/src/main/java/huan/task/EventTask.java new file mode 100644 index 000000000..62563d46f --- /dev/null +++ b/src/main/java/huan/task/EventTask.java @@ -0,0 +1,71 @@ +package huan.task; + +/** + * Class for a task representing an event + */ +public class EventTask extends Task{ + private String startTime, endTime; + + /** + * Constructor class for an EventTask + * @param name the name of the Task + * @param startTime the start date of the event + * @param endTime the end date of the event + * @param isDone whether the task is marked as finished + */ + public EventTask(String name, String startTime, String endTime, Boolean isDone) { + setName(name); + this.startTime = startTime; + this.endTime = endTime; + setIsDone(isDone); + setTaskType(2); + } + + /** + * Method for printing the Task + */ + public void printTask() { + System.out.println("[E][" + (getIsDone() ? "X" : " ") + "] " + getName() + " (from: " + startTime + " to: " + endTime + ")"); + } + + /** + * Method for writing the Task to file + * @return the line to be written to file + */ + @Override + public String writeLine() { + return "E" + (getIsDone() ? "T" : "F") + " " + getName() + " /from " + startTime + " /to " + endTime; + } + + /** + * Set method for the start date + * @param startTime the start date + */ + public void setStartTime(String startTime) { + this.startTime = startTime; + } + + /** + * Get method for the start date + * @return the start date + */ + public String getStartTime() { + return startTime; + } + + /** + * Set method for the end date + * @param endTime the end date + */ + public void setEndTime(String endTime) { + this.endTime = endTime; + } + + /** + * Get method for the end date + * @return the end date + */ + public String getEndTime() { + return endTime; + } +} diff --git a/src/main/java/huan/task/Task.java b/src/main/java/huan/task/Task.java new file mode 100644 index 000000000..369910360 --- /dev/null +++ b/src/main/java/huan/task/Task.java @@ -0,0 +1,93 @@ +package huan.task; + +/** + * Class for a regular task + */ +public class Task { + private String name; + private Boolean isDone; + + private int taskType; + + /** + * Set method for task name + * @param name the task name + */ + public void setName(String name) { + this.name = name; + } + + /** + * Set method for isDone + * @param isDone whether the task is marked as finished + */ + public void setIsDone(Boolean isDone) { + this.isDone = isDone; + } + + /** + * Set method for task type + * @param taskType the type of task, 1 for TodoTask, 2 for EventTask, 3 for Deadline Task. Used for recasting + */ + public void setTaskType(int taskType) { + this.taskType = taskType; + } + + /** + * Get method for task name + * @return the task name + */ + public String getName() { + return name; + } + + /** + * Get method for isDone + * @return whether the task is marked as finished + */ + public Boolean getIsDone() { + return isDone; + } + + /** + * Get method for taskType + * @return the type of task, 1 for TodoTask, 2 for EventTask, 3 for Deadline Task. + */ + public int getTaskType() { + return taskType; + } + + /** + * Method for printing a task. Will be overridden by other classes + */ + public void printTask() { + System.out.println("[" + (isDone ? "X" : " ") + "] " + name); + } + + /** + * Method for writing the line. Will be overridden by other classes + * @return nothing + */ + public String writeLine() { + return null; + } + + /** + * Default Constructor class for Task + */ + public Task() { + setName("task"); + setIsDone(false); + taskType = 0; + } + + /** + * Constructor class for Task + * @param name the task name + * @param isDone whether the task will be marked as finished + */ + public Task(String name, Boolean isDone) { + setName(name); + setIsDone(isDone); + } +} diff --git a/src/main/java/huan/task/TodoTask.java b/src/main/java/huan/task/TodoTask.java new file mode 100644 index 000000000..e3dd283e9 --- /dev/null +++ b/src/main/java/huan/task/TodoTask.java @@ -0,0 +1,33 @@ +package huan.task; + +/** + * Class for a regular todo Task + */ +public class TodoTask extends Task{ + /** + * Constructor method for TodoTask + * @param name name of task + * @param isDone whether the task is marked as finished + */ + public TodoTask(String name, Boolean isDone) { + super(name, isDone); + setTaskType(1); + } + + /** + * Method for printing the TodoTask + */ + @Override + public void printTask() { + System.out.println("[T][" + (getIsDone() ? "X" : " ") + "] " + getName()); + } + + /** + * Method for writing the Task to file + * @return the line to be written on the file + */ + @Override + public String writeLine() { + return "T" + (getIsDone() ? "T" : "F") + " " + getName(); + } +} diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 657e74f6e..8c8cd4202 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,7 +1,24 @@ -Hello from - ____ _ -| _ \ _ _| | _____ -| | | | | | | |/ / _ \ -| |_| | |_| | < __/ -|____/ \__,_|_|\_\___| - +Hello! I'm Huan, a chat bot +------------------------- +Added todo type task with name: read book +------------------------- +Added deadline type task with name: return book +------------------------- +Added event type task with name: project meeting +------------------------- +Set task number 1: read book as done. +------------------------- +Added todo type task with name: join sports club +------------------------- +Added todo type task with name: borrow book +------------------------- +Set task number 4: join sports club as done. +------------------------- +You have a total of 5 tasks. +1. [T][X] read book +2. [D][ ] return book (by: June 6th) +3. [E][ ] project meeting (from: Aug 6th 2pm to: 4pm) +4. [T][X] join sports club +5. [T][ ] borrow book +------------------------- +Bye! See ya! diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index e69de29bb..13601e3f9 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -0,0 +1,9 @@ +todo read book +deadline return book /by June 6th +event project meeting /from Aug 6th 2pm /to 4pm +mark 1 +todo join sports club +todo borrow book +mark 4 +list +bye