diff --git a/data/tasklist.txt b/data/tasklist.txt
new file mode 100644
index 000000000..023f4767d
--- /dev/null
+++ b/data/tasklist.txt
@@ -0,0 +1 @@
+T | Not Done | rice
diff --git a/docs/README.md b/docs/README.md
index 8077118eb..5fd8e07e5 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -1,29 +1,267 @@
# User Guide
-## Features
+## Table of Contents
+
+* [User Guide](#user-guide)
+ * [Features](#features)
+ * [Task Type 1: `Todo`](#task-type-1--todos)
+ * [Task Type 2: `Event`](#task-type-2--events)
+ * [Task Type 3: `Deadline`](#task-type-3--deadlines)
+ * [Find Tasks By Keyword](#find-tasks-by-description)
+ * [Task Completion Status](#task-completion-status)
+ * [Task Deletion](#task-deletion)
+ * [Task Data Storage](#task-data-storage)
+ * [Usage](#usage)
+ * [`todo` - New Todo Task](#todo---new-todo-task)
+ * [`deadline` - New Deadline Task](#deadline---new-deadline-task)
+ * [`event` - New Event Task](#event---new-event-task)
+ * [`list` - List all Tasks](#list---list-all-tasks)
+ * [`mark` - Marks a Task as done](#mark---marks-a-task-as-done)
+ * [`unmark` - Marks a Task as not done](#unmark---marks-a-task-as-not-done)
+ * [`delete` - Deletes a Task](#delete---deletes-a-task)
+ * [`find` - Find Task by Keyword](#find---find-task-by-keyword)
+ * [`bye` - Terminate the program](#bye---shut-down-program)
+
-### Feature-ABC
+## Features
-Description of the feature.
+### Task Type 1: `Todo`
-### Feature-XYZ
+The function of 'Todo' is to record the planning, like what are the things are reuqred to be done.
-Description of the feature.
+### Task Type 2: `Event`
+
+Event can be considered as part of the Todo, but it required the **start date and/or time** and **end date and/or time**, which can be more specific.
+
+### Task Type 3: `Deadline`
+
+Another kind of Todo is Deadline which has a specified **due date** so that the user can track the deadline for the task. Therefore, the priority of the tasks can be visualized.
+
+### Find Tasks By Description
+
+After creating many tasks, users can type a certain **keyword** to find the tasks that have been created before. As such, all the related tasks can be reviewed.
+
+### Task Completion Status
+
+All Tasks can be marked **done** or **not done**, so it helps to keep tracking the completion of the tasks
+The status of the tasks can be indicated by `[X]` if a task is completed or an empty box `[ ]` if the task haven't been completed yet.
+
+### Task Deletion
+
+Users can **delete** a task if they no longer need it in the task list.
+
+### Task Data Storage
+
+A list of Tasks can be recorded in computer's storage and _restore it_ the next time when the program start.
+The data memories will be stored in the data\taskList.txt file.
## Usage
-### `Keyword` - Describe action
+### `todo` - New Todo Task
+
+Creates a new Todo Task with the specific requirement and uncompleted status.
-Describe the action and its outcome.
+**Syntax**:
-Example of usage:
+`todo (task-that-need-to-be-done)`
-`keyword (optional arguments)`
+**Example of usage**:
-Expected outcome:
+`todo buy food`
-Description of the outcome.
+**Expected outcome**:
```
-expected output
+todo buy food
+ ____________________________________________________________
+ Got it. I've added this task:
+ [T][ ] buy food
+ Now you have 1 tasks in the list.
+ ____________________________________________________________
+```
+
+### `deadline` - New Deadline Task
+
+Creates a new Deadline Task with the given description and due date.
+
+**Syntax**:
+
+`deadline (task-description) /by (deadline-with-time)`
+
+**Example of usage**:
+
+`deadline CS2113 Assignmentt /by 3 March`
+
+**Expected outcome**:
+
+Rica will remember that you have a deadline called 'Fall asleep' to meet by 10pm, which is added to your list of Tasks.
+
+```
+deadline Fall asleep /by 10pm
+ ____________________________________________________________
+ Got it. I've added this task:
+ [D][ ] CS2113 Assignmentt (by: 3 March)
+ Now you have 2 tasks in the list.
+ ____________________________________________________________
+```
+
+### `event` - New Event Task
+
+Creates a new Event Task with the given description, start date/time and end date/time.
+
+**Syntax**:
+
+`event (tassk-description) /from (start-date) /to (end-date)`
+
+**Example of usage**:
+
+`event shopping /from 4pm /to 8:30pm`
+
+**Expected outcome**:
+
+Rica will keep in mind that you want to 'Watch sunset' from 7pm to 7.15pm, and this Deadline is added to your list of Tasks.
+
+```
+event shopping /from 4pm /to 8.30pm
+ ____________________________________________________________
+ Got it. I've added this task:
+ [E][ ] shopping (from: 4pm to: 8:30pm)
+ Now you have 1 tasks in the list.
+ ____________________________________________________________
+```
+
+### `list` - List all Tasks
+
+Lists all Tasks that Rica currently remembers along with their completion status.
+
+**Example of usage**:
+
+`list`
+
+**Expected outcome**:
+
+Description of all the Tasks that have been entered as well as which Tasks are done or not done.
+
+```
+list
+ ____________________________________________________________
+ Here are the task in your list:
+ 1.[E][ ] shopping (from: 4pm to: 8:30pm)
+ ____________________________________________________________
+```
+
+### `mark` - Marks a Task as done
+
+Given the Task number based on the task list, mark the corresponding Task as done by the user.
+
+**Syntax**:
+
+`mark (task-index)`
+
+**Example of usage**:
+
+`mark 1`
+
+**Expected outcome**:
+
+Index 1 of the task list is now done, so it will update this task as done in the task list.
+
+```
+mark 1
+ ____________________________________________________________
+ Nice! I've marked this task as done:
+ [E][X] shopping (from: 4pm to: 8:30pm)
+ ____________________________________________________________
+```
+
+### `unmark` - Marks a Task as not done
+
+
+
+
+**Syntax**:
+
+`unmark (task-index)`
+
+**Example of usage**:
+
+`unmark 1`
+
+**Expected outcome**:
+
+Index 1 of the task list is now not done, so it will update this task as not done in the task list
+
+```
+unmark 1
+ ____________________________________________________________
+ Nice! I've marked this task as done:
+ [E][X] shopping (from: 4pm to: 8:30pm)
+ ____________________________________________________________
+```
+
+### `delete` - Deletes a Task
+
+Given the Task number based on the task list, delete the corresponding Task by the user.
+
+**Syntax**:
+
+`delete (task-number)`
+
+**Example of usage**:
+
+`delete 1`
+
+**Expected outcome**:
+
+Index 1 of the task list is now deleted, so it will be deleted from the task list.
+
+```
+delete 1
+ ____________________________________________________________
+ Noted. I've removed this task:
+ [E][ ] project meeting (from: Aug 6th 2pm to: 4pm)
+ Now you have 4 tasks in the list.
+ ____________________________________________________________
+```
+
+### `find` - Find Task by Keyword
+
+Given a keyword, a list of all Tasks with a matching description will be shown.
+
+**Syntax**:
+
+`find (keyword)`
+
+**Example of usage**:
+
+`find book`
+
+**Expected outcome**:
+
+Task with a description containing the word 'book' is shown to the user.
+
+```
+find book
+ ____________________________________________________________
+ Here are the matching tasks in your list:
+ 1.[T][X] read book
+ 2.[D][X] return book (by: June 6th)
+ ____________________________________________________________
+```
+
+### `bye` - Turns Program Off
+
+The program will shut down.
+
+**Example of usage**:
+
+`bye`
+
+**Expected outcome**:
+
+
```
+ ____________________________________________________________
+ Bye. Hope to see you again soon!
+ ____________________________________________________________
+```
\ No newline at end of file
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/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF
new file mode 100644
index 000000000..2c9a9745c
--- /dev/null
+++ b/src/main/java/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Main-Class: duke.Duke
+
diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java
new file mode 100644
index 000000000..33deaa388
--- /dev/null
+++ b/src/main/java/duke/Duke.java
@@ -0,0 +1,40 @@
+package duke;
+
+import duke.instructions.*;
+import java.util.ArrayList;
+public class Duke {
+
+ private static final ArrayList taskNameList = new ArrayList<>();
+ private static String filePath = "data/tasklist.txt";
+
+
+ public Duke(String filePath) {
+
+ try {
+ Storage.readFile(filePath, taskNameList);
+ } catch (java.io.FileNotFoundException e) {
+ Ui.showNotFoundError();
+ }
+ }
+
+ /**
+ * The starting and ending of the program
+ * This methods will keep checking if "bye" is entered by the user
+ *
+ */
+ public static void run() {
+
+ Ui.greeting();
+ boolean isRunning = true;
+ while (isRunning) {
+ isRunning = Parser.checkInput(taskNameList, filePath);
+ }
+ Parser.sayBye();
+
+ }
+
+
+ public static void main(String[] args) {
+ new Duke(filePath).run();
+ }
+}
diff --git a/src/main/java/duke/DukeException.java b/src/main/java/duke/DukeException.java
new file mode 100644
index 000000000..cf2b2978e
--- /dev/null
+++ b/src/main/java/duke/DukeException.java
@@ -0,0 +1,9 @@
+
+package duke;
+
+public class DukeException extends Exception{
+ public DukeException(String message) {
+ super(message);
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java
new file mode 100644
index 000000000..40418e52c
--- /dev/null
+++ b/src/main/java/duke/Parser.java
@@ -0,0 +1,84 @@
+package duke;
+
+import duke.instructions.Storage;
+import duke.instructions.Task;
+
+import java.util.ArrayList;
+import java.util.Scanner;
+
+public class Parser {
+ private static final String UNRECOGNISED_INPUT = " ☹ OOPS!!! I'm sorry, but I don't know what that means :-(";
+ public static final String LINE = " ____________________________________________________________";
+
+ public static void sayBye() {
+ System.out.println(LINE);
+ System.out.println(" Bye. Hope to see you again soon!");
+ System.out.println(LINE);
+ }
+
+ /**
+ * Excute different instructions based on the command
+ * @param input user input
+ * @param taskNameInput list of task
+ * @throws DukeException check for errors
+ */
+ public static void inputValues(String input, ArrayList taskNameInput) throws DukeException {
+ String[] command = input.split("\\s+");
+ switch (command[0]) {
+ case "list":
+ TaskList.listCommand(input, taskNameInput);
+ break;
+ case "mark":
+ TaskList.markCommand(command, taskNameInput);
+ break;
+ case "unmark":
+ TaskList.unMarkCommand(command, taskNameInput);
+ break;
+ case "todo":
+ TaskList.toDoCommand(input, taskNameInput);
+ break;
+ case "deadline":
+ TaskList.deadlineCommand(input, taskNameInput);
+ break;
+ case "event":
+ TaskList.eventCommand(input, taskNameInput);
+ break;
+ case "delete":
+ TaskList.deleteCommand(input, taskNameInput);
+ break;
+ case "find":
+ TaskList.findCommand(input, taskNameInput);
+ break;
+ default:
+ throw new DukeException(UNRECOGNISED_INPUT);
+
+ }
+ }
+
+ /**
+ * to check if the program end using the keyword "bye"
+ * @param taskNameList list of task
+ * @param filePath the path of the file
+ * @return boolean values for checking the program
+ */
+ public static boolean checkInput(ArrayList taskNameList, String filePath) {
+ Scanner userInput = new Scanner(System.in);
+ while (true) {
+ String taskName = userInput.nextLine();
+ if (taskName.equalsIgnoreCase("bye")) {
+ if(taskNameList.size() < 1){
+ System.out.println(" You do not enter any task and program will be terminated!!!");
+ }else{
+ Storage.writeTaskToFile(filePath, taskNameList);}
+ return false;
+ }
+ try {
+ inputValues(taskName, taskNameList);
+ } catch (Exception e) {
+ System.out.println(LINE);
+ System.out.println(e.getMessage());
+ System.out.println(LINE);
+ }
+ }
+ }
+}
diff --git a/src/main/java/duke/TaskList.java b/src/main/java/duke/TaskList.java
new file mode 100644
index 000000000..e270bd183
--- /dev/null
+++ b/src/main/java/duke/TaskList.java
@@ -0,0 +1,167 @@
+package duke;
+
+import duke.instructions.Deadline;
+import duke.instructions.Event;
+import duke.instructions.Task;
+import duke.instructions.Todo;
+
+import java.util.ArrayList;
+
+/*
+ contains the methods for different instructions
+ */
+
+public class TaskList {
+
+ public static final String LINE = " ____________________________________________________________";
+ public static final String EMPTY_DESCRIPTION = " ☹ OOPS!!! The description cannot be empty.";
+
+
+ /**
+ * Print a list of tasks that have been entered
+ * @param command user input that contains the user-specific keyword "list"
+ */
+ public static void listCommand(String command, ArrayList taskNameList) {
+ Task task = new Task(command);
+ System.out.println(LINE);
+ System.out.print(task.guideline());
+ for (int indexOfInstruction = 0; indexOfInstruction < taskNameList.size(); indexOfInstruction++) {
+ System.out.print(" " + (indexOfInstruction + 1) + "."
+ + taskNameList.get(indexOfInstruction).getState().trim() + System.lineSeparator());
+ }
+ System.out.println(LINE);
+
+ }
+
+ /**
+ * Print the task that have been marked
+ * @param command user input that contains the user-specific keyword "mark"
+ */
+
+ public static void markCommand(String[] command, ArrayList taskNameList) {
+ int indexTask = Integer.parseInt(command[1]);
+ System.out.println(LINE);
+ taskNameList.get(indexTask - 1).mark();
+ System.out.print(" Nice! I've marked this task as done:"
+ + System.lineSeparator()
+ + taskNameList.get(indexTask - 1).getState());
+ System.out.println(LINE);
+ }
+
+ /**
+ * Print the task that have been unmarked
+ * @param command user input that contains the user-specific keyword "unmark"
+ */
+ public static void unMarkCommand(String[] command , ArrayList taskNameList) {
+ int indexOfTask = Integer.parseInt(command[1]);
+ System.out.println(LINE);
+ taskNameList.get(indexOfTask - 1).unMark();
+ System.out.print(" OK, I've marked this task as not done yet:"
+ + System.lineSeparator()
+ + taskNameList.get(indexOfTask - 1).getState());
+ System.out.println(LINE);
+
+ }
+
+ /**
+ * Print the task that need to be done by user
+ * @param command user input that contains the user-specific keyword "todo"
+ */
+ public static void toDoCommand(String command , ArrayList taskNameList) throws DukeException {
+ Todo toDo = new Todo(command);
+ //toDo.setTaskType("T");
+ Task task = new Task(command);
+ String[] tokens = command.split("\\s+", 2);
+ if (tokens.length < 2) {
+ throw new DukeException(EMPTY_DESCRIPTION);
+ }
+ System.out.println(LINE);
+ taskNameList.add(toDo);
+ String outputForTodo = toDo.guideline()
+ + toDo.getState()
+ + task.numberOfTask(taskNameList.size());
+ System.out.println(outputForTodo);
+ System.out.println(LINE);
+
+ }
+
+
+ /**
+ * Print the event that have been entered
+ * @param command user input that contains the user-specific keyword "mark"
+ */
+ public static void eventCommand(String command , ArrayList taskNameList) {
+ Event event = new Event(command);
+ //event.setTaskType("E");
+ Task task = new Task(command);
+ System.out.println(LINE);
+ taskNameList.add(event);
+ String outputForEvent = event.guideline()
+ + event.getState()
+ + task.numberOfTask(taskNameList.size());
+ System.out.println(outputForEvent);
+ System.out.println(LINE);
+
+ }
+
+ /**
+ * Print the deadline that for the task they have entered
+ * @param command user input that contains the user-specific keyword "deadline"
+ */
+ public static void deadlineCommand(String command , ArrayList taskNameList) {
+ Deadline deadLine = new Deadline(command);
+ //deadLine.setTaskType("D");
+ Task task = new Task(command);
+ System.out.println(LINE);
+ taskNameList.add(deadLine);
+ String outputForDeadline = deadLine.guideline()
+ + deadLine.getState()
+ + task.numberOfTask(taskNameList.size());
+ System.out.println(outputForDeadline);
+ System.out.println(LINE);
+ }
+
+ /**
+ * Print the task that have been deleted
+ * @param command user input that contains the user-specific keyword "delete"
+ */
+ public static void deleteCommand(String command, ArrayList taskNameList){
+ String[] tokens = command.split("\\s+");
+ int indexTask = Integer.parseInt(tokens[1]);
+ Task task = new Task(command);
+ System.out.println(LINE);
+ System.out.print(" Noted. I've removed this task:"
+ + System.lineSeparator()
+ + taskNameList.get(indexTask - 1).getState());
+ taskNameList.remove(indexTask - 1);
+ System.out.println(task.numberOfTask(taskNameList.size()));
+ System.out.println(LINE);
+ }
+ /**
+ * Print the task that can be found in the tasks list
+ * @param command user input that contains the user-specific keyword "find
+ */
+ public static void findCommand(String command, ArrayList taskNameList){
+ String keyword = command.substring(5);
+
+ ArrayList matchedTask = new ArrayList<>();
+
+ for (Task task : taskNameList) {
+ if ((task.getState()).contains(keyword)) {
+ matchedTask.add(task);
+ }
+ }
+ int numberOfFoundTasks = matchedTask.size();
+ int number0fTask = 1;
+ System.out.println(" There are " + numberOfFoundTasks
+ + " matching tasks in your list");
+ for (Task foundTask : matchedTask) {
+ if (foundTask != null) {
+ System.out.print(" " +number0fTask + "." + foundTask.getState().trim()
+ + System.lineSeparator());
+ }
+ number0fTask++;
+ }
+ }
+
+}
diff --git a/src/main/java/duke/Ui.java b/src/main/java/duke/Ui.java
new file mode 100644
index 000000000..3d03a7cf8
--- /dev/null
+++ b/src/main/java/duke/Ui.java
@@ -0,0 +1,25 @@
+package duke;
+
+/*
+ Contains the methods to display the greeting when the program start
+ */
+
+public class Ui {
+ public static final String LINE = " ____________________________________________________________";
+
+ /**
+ * For greeting and display each time the program run
+ */
+ public static void greeting() {
+
+ System.out.println(LINE);
+ System.out.println(" Hello! I'm Duke");
+ System.out.println(" What can I do for you?");
+ System.out.println(LINE);
+ }
+
+
+ public static void showNotFoundError(){
+ System.out.println("Failed to locate the file");
+ }
+}
diff --git a/src/main/java/duke/instructions/Deadline.java b/src/main/java/duke/instructions/Deadline.java
new file mode 100644
index 000000000..05a51bedd
--- /dev/null
+++ b/src/main/java/duke/instructions/Deadline.java
@@ -0,0 +1,76 @@
+package duke.instructions;
+
+public class Deadline extends Task{
+ String input;
+ boolean isComplete;
+ String status;
+ protected String taskType;
+ public Deadline(String input) {
+ super(input);
+ this.input = input;
+ this.taskType = "D";
+ }
+
+
+ public void setTaskType(String taskType) {
+ this.taskType = taskType;
+ }
+ @Override
+ public String getTaskType(){
+ return "D";
+ }
+ public void statusIcon(boolean isComplete){
+ this.isComplete = isComplete;
+ this.status = (this.isComplete ? "X" : " ");
+ }
+
+ /**
+ * Format the input task
+ * @return return the new format of the task
+ */
+ @Override
+ public String getState(){
+ if(input.contains("|")){
+ String[] inputCommands = input.split("\\|");
+ return " [D]" + "[" + this.status + "]" + " "
+ + inputCommands[2].trim() + " (by: " + inputCommands[3].trim() + ")"
+ + System.lineSeparator();
+ }else {
+ String deadline = input.substring(input.indexOf('/') + 1);
+ StringBuffer showDeadline = new StringBuffer(deadline);
+ showDeadline.insert(2, ":");
+ String arrayOfDeadline = this.description.substring(description.indexOf(" ") + 1);
+ String[] eventName = arrayOfDeadline.split("/");
+ return " [D]" + "[" + getStatusIcon() + "]" + " "
+ + eventName[0] + " (" + showDeadline + ")"
+ + System.lineSeparator();
+ }
+ }
+
+ /**
+ * Format the task
+ * @return return the formatting task and save it in text file
+ */
+ @Override
+ public String getTaskList(){
+ String deadline = input.substring(input.indexOf(' ') + 1);
+ String[] newDeadline = deadline.split("/by");
+ return newDeadline[0] + " | " + newDeadline[1];
+
+
+ }
+
+ @Override
+ public String guideline(){
+ return " Got it. I've added this task: "
+ + System.lineSeparator();
+ }
+
+ public String taskStatus(){
+ if(getStatusIcon().equals("X")){
+ return "Done";
+ }else{
+ return "Not Done";
+ }
+ }
+}
diff --git a/src/main/java/duke/instructions/Event.java b/src/main/java/duke/instructions/Event.java
new file mode 100644
index 000000000..11e53b387
--- /dev/null
+++ b/src/main/java/duke/instructions/Event.java
@@ -0,0 +1,84 @@
+
+package duke.instructions;
+
+public class Event extends Task{
+ protected String input;
+ protected String taskType;
+ protected String taskName;
+
+ boolean isComplete;
+ String status;
+
+ public Event(String input) {
+ super(input);
+ this.input = input;
+ this.taskType = "E";
+ this.taskName = input;
+ }
+
+ public void statusIcon(boolean isComplete){
+ this.isComplete = isComplete;
+ this.status = (this.isComplete ? "X" : " ");
+ }
+ /**
+ * format the task
+ * @return return the respective task format based on the input
+ * if the input from text file, then it will execute the if condition, if the input from the input, then it will execute the else condition
+ */
+
+ @Override
+ public String getState(){
+
+ if(description.contains("|")){
+ String[] inputCommands = description.split("\\|");
+ String[] event = inputCommands[3].split("-");
+ return " [E]" + "[" + this.status + "]" + " "
+ + inputCommands[2].trim() +
+ " (from: " + event[0].trim() + " to: "
+ + event[1].trim() + ")" + System.lineSeparator();
+ }else {
+ String wholeArrayOfEvent = this.description.substring(description.indexOf(" ") + 1);
+ String[] arrayOfEvent = wholeArrayOfEvent.split("/from");
+ String eventStart = arrayOfEvent[1].split("/to")[0].trim();
+ String eventEnd = arrayOfEvent[1].split("/to")[1].trim();
+
+ String full;
+ full = " [E]" + "[" + getStatusIcon() + "]" + " "
+ + arrayOfEvent[0] +
+ "(from: " + eventStart + " to: "
+ + eventEnd + ")" + System.lineSeparator();
+
+ return full;
+ }
+}
+
+@Override
+ public String guideline(){
+ return " Got it. I've added this task: "
+ + System.lineSeparator();
+ }
+
+
+ public void setTaskType(String taskType) {
+ this.taskType = taskType;
+ }
+
+ @Override
+ public String getTaskType(){
+ return this.taskType;
+ }
+
+
+ @Override
+ public String getTaskList(){
+
+ String wholeArrayOfEvent = this.description.substring(description.indexOf(" ") + 1);
+ String[] arrayOfEvent = wholeArrayOfEvent.split("/from");
+ String eventStart = arrayOfEvent[1].split("/to")[0].trim();
+ String eventEnd = arrayOfEvent[1].split("/to")[1].trim();
+
+ return arrayOfEvent[0] +
+ " | " + eventStart + "-"
+ + eventEnd + System.lineSeparator();
+ }
+}
diff --git a/src/main/java/duke/instructions/Storage.java b/src/main/java/duke/instructions/Storage.java
new file mode 100644
index 000000000..8b404bf51
--- /dev/null
+++ b/src/main/java/duke/instructions/Storage.java
@@ -0,0 +1,129 @@
+package duke.instructions;
+
+import duke.DukeException;
+
+import java.io.*;
+import java.util.ArrayList;
+import java.util.Scanner;
+
+/**
+ * Storage class mainly used for saving and loading the file when user exit the program
+ */
+public class Storage {
+ protected static String filePath;
+ private static final ArrayList taskNameList = new ArrayList<>();
+
+ public Storage(String filePath) {
+ this.filePath = filePath;
+ }
+ public static final String LINE = " ____________________________________________________________";
+
+
+ /**
+ * Store the task to txt file
+ * @param filePath the path where the file stored
+ * @param taskNameList the array list that store the tasks
+ */
+ public static void writeTaskToFile(String filePath, ArrayList taskNameList){
+
+ try{
+ File savedFile = new File(filePath);
+ FileWriter writeFile = new FileWriter(savedFile);
+ for(Task tasks : taskNameList){
+ String typeOfTask = tasks.getTaskType();
+ switch(typeOfTask){
+ case "D":
+ Deadline newDeadline = (Deadline) tasks;
+ writeFile.write("D | " + newDeadline.taskStatus() + " | " + newDeadline.getTaskList() + System.lineSeparator());
+ break;
+ case "E":
+ Event newEvent = (Event) tasks;
+ writeFile.write("E | " + newEvent.taskStatus() + " | " + newEvent.getTaskList() + System.lineSeparator());
+ break;
+ case "T":
+ Todo newToDo = (Todo) tasks;
+ writeFile.write("T | " + newToDo.taskStatus() + " | " + newToDo.getTaskList() + System.lineSeparator());
+ break;
+ default:
+ System.out.println("Invalid input, please enter a valid command");
+ }
+ }
+ writeFile.close();
+
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+
+ }
+
+ /**
+ *
+ * Write the file to external txt file
+ * @param filePath filePath the path where the file stored
+ * @param taskNameList store the list of task
+ * @throws FileNotFoundException
+ */
+
+ public static void readFile(String filePath, ArrayList taskNameList) throws FileNotFoundException {
+
+ File savedFile = new File(filePath);
+ if (!savedFile.getParentFile().exists()) {
+ savedFile.getParentFile().mkdirs();
+
+ }
+ try {
+ if (!savedFile.exists()) {
+ savedFile.createNewFile();
+ }
+ } catch (IOException e) {
+ System.out.println("Failed to create a new file!!!");
+ }
+ Scanner fileRead = new Scanner(new FileInputStream((filePath)));
+ try {
+ while (fileRead.hasNext()) {
+ String command = fileRead.nextLine();
+ String[] inputCommands = command.split("\\|");
+ String fileType = inputCommands[0].trim();
+ boolean isCompleted = true;
+ if (inputCommands[1].trim().equals("Not Done")) {
+ isCompleted = false;
+ }
+
+ switch (fileType) {
+ case "D":
+ Deadline newDeadline = new Deadline(command);
+ taskNameList.add(newDeadline);
+ newDeadline.statusIcon(isCompleted);
+ break;
+ case "T":
+ Todo newTodo = new Todo(command);
+ taskNameList.add(newTodo);
+ newTodo.statusIcon(isCompleted);
+ break;
+ case "E":
+ Event newEvent = new Event(command);
+ taskNameList.add(newEvent);
+ newEvent.statusIcon(isCompleted);
+ break;
+ default:
+ throw new FileNotFoundException();
+ }
+
+ }
+ System.out.println(" Hear is the previous task: " + System.lineSeparator() + LINE);
+ for (int indexOfInstruction = 0; indexOfInstruction < taskNameList.size(); indexOfInstruction++) {
+ System.out.print(" " + (indexOfInstruction + 1) + "."
+ + taskNameList.get(indexOfInstruction).getState().trim() + System.lineSeparator());
+ }
+ }catch(ArrayIndexOutOfBoundsException e){
+ System.out.println("Tasklist.txt file cannot be accessed!");
+ }
+
+ }
+
+ }
+
+
+
+
+
diff --git a/src/main/java/duke/instructions/Task.java b/src/main/java/duke/instructions/Task.java
new file mode 100644
index 000000000..3d5623f86
--- /dev/null
+++ b/src/main/java/duke/instructions/Task.java
@@ -0,0 +1,77 @@
+package duke.instructions;
+
+public class Task {
+
+ protected String description;
+ protected boolean isDone = false;
+ protected String state;
+ protected String checkComplete;
+ protected static String taskType;
+
+ boolean isComplete;
+ String status;
+
+
+ protected String taskList;
+ public Task(String description) {
+ this.description = description;
+ }
+ public Task(){
+
+ }
+
+ public void mark() {
+ this.isDone = true;
+ }
+
+ public void unMark() {
+ this.isDone = false;
+ }
+
+ /**
+ * To update the status of the task and use "X" to indicate the task had been completed
+ * while " " is used to indicate the task haven't been done yet
+ * @return return the completion of the task
+ */
+ public String getStatusIcon() {
+ checkComplete = (this.isDone ? "X" : " ");
+ return checkComplete; // mark done task with X
+ }
+ public String getState(){
+ return state;
+ }
+ public String getTaskList(){
+ return taskList;
+ }
+ public String getTaskType(){
+ return taskType;
+ }
+
+
+ public String guideline(){
+ return " Here are the task in your list: "
+ + System.lineSeparator();
+ }
+
+
+
+ /**
+ * update the length of the task list
+ * @param length the length of the current task list
+ * @return return a string which shows the lasted number of tasks in the list
+ */
+ public String numberOfTask(int length){
+ return " Now you have "
+ + length + " tasks in the list.";
+
+ }
+
+ public String taskStatus(){
+ if(getStatusIcon().equals("X")){
+ return "Done";
+ }else{
+ return "Not Done";
+ }
+ }
+}
+
diff --git a/src/main/java/duke/instructions/Todo.java b/src/main/java/duke/instructions/Todo.java
new file mode 100644
index 000000000..290765100
--- /dev/null
+++ b/src/main/java/duke/instructions/Todo.java
@@ -0,0 +1,76 @@
+package duke.instructions;
+
+public class Todo extends Task{
+
+ protected String taskType;
+ boolean isComplete;
+ String status;
+ public Todo(String description) {
+ super(description);
+ this.taskType = "T";
+ }
+
+
+ public void statusIcon(boolean isComplete){
+ this.isComplete = isComplete;
+ this.status = (this.isComplete ? "X" : " ");
+ }
+
+ @Override
+ public String getState(){
+ if(description.contains("|")){
+ String[] inputCommands = description.split("\\|");
+ return " [T]" + "[" + getStatusIcon() + "]" + " "
+ + inputCommands[2].trim() + System.lineSeparator();
+ }else {
+ String arrayOfTodo = this.description.substring(description.indexOf(" ") + 1);
+ return " [T]" + "[" + getStatusIcon() + "]" + " "
+ + arrayOfTodo + System.lineSeparator();
+ }
+ }
+
+ @Override
+ public String guideline(){
+ return " Got it. I've added this task: "
+ + System.lineSeparator();
+ }
+
+
+ /**
+ * get the task type
+ * @return the type of task
+ */
+ @Override
+ public String getTaskType() {
+ return taskType;
+ }
+
+
+
+ public void setTaskType(String taskType) {
+ this.taskType = taskType;
+ }
+ @Override
+ public String getTaskType(){
+ return this.taskType;
+ }
+
+
+ @Override
+ public String getTaskList(){
+ String arrayOfTodo = this.description.substring(description.indexOf(" ") + 1);
+ return arrayOfTodo;
+ }
+ public String taskStatus(){
+ if(getStatusIcon().equals("X")){
+ return "Done";
+ }else{
+ return "Not Done";
+ }
+ }
+ }
+
+
+
+
+
diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT
index 657e74f6e..6e11edd51 100644
--- a/text-ui-test/EXPECTED.TXT
+++ b/text-ui-test/EXPECTED.TXT
@@ -1,7 +1,19 @@
-Hello from
- ____ _
-| _ \ _ _| | _____
-| | | | | | | |/ / _ \
-| |_| | |_| | < __/
-|____/ \__,_|_|\_\___|
-
+ ____________________________________________________________
+ Hello! I'm Duke
+ What can I do for you?
+ ____________________________________________________________
+ ____________________________________________________________
+ Got it. I've added this task:
+ [T][ ] borrow book
+ Now you have 1 tasks in the list.
+ ____________________________________________________________
+ ____________________________________________________________
+ Got it. I've added this task:
+ [D][ ] return book (by: Sunday)
+ Now you have 2 tasks in the list.
+ ____________________________________________________________
+ ____________________________________________________________
+ Got it. I've added this task:
+ [E][ ] project meeting (from: Mon 2pm to: 4pm)
+ Now you have 3 tasks in the list.
+ ____________________________________________________________
diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt
index e69de29bb..ea34661f2 100644
--- a/text-ui-test/input.txt
+++ b/text-ui-test/input.txt
@@ -0,0 +1,3 @@
+todo borrow book
+deadline return book /by Sunday
+event project meeting /from Mon 2pm /to 4pm
diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat
index 087374464..5c47c1c57 100644
--- a/text-ui-test/runtest.bat
+++ b/text-ui-test/runtest.bat
@@ -7,7 +7,7 @@ REM delete output from previous run
if exist ACTUAL.TXT del ACTUAL.TXT
REM compile the code into the bin folder
-javac -cp ..\src\main\java -Xlint:none -d ..\bin ..\src\main\java\*.java
+javac -cp ..\src\main\java -Xlint:none -d ..\bin ..\src\main\java\duke\*.java ..\src\main\java\duke\instructions\*.java
IF ERRORLEVEL 1 (
echo ********** BUILD FAILURE **********
exit /b 1
@@ -15,7 +15,7 @@ IF ERRORLEVEL 1 (
REM no error here, errorlevel == 0
REM run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT
-java -classpath ..\bin Duke < input.txt > ACTUAL.TXT
+java -classpath ..\bin duke.Duke < input.txt > ACTUAL.TXT
REM compare the output to the expected output
FC ACTUAL.TXT EXPECTED.TXT