diff --git a/README.md b/README.md
index 8715d4d915..0f2208ab64 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# Duke project template
+# duke.Duke project template
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.
@@ -13,7 +13,7 @@ Prerequisites: JDK 11, update Intellij to the most recent version.
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:
+3. After that, locate the `src/main/java/duke.Duke.java` file, right-click it, and choose `Run duke.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
____ _
diff --git a/build.gradle b/build.gradle
new file mode 100644
index 0000000000..a8b9f24cb5
--- /dev/null
+++ b/build.gradle
@@ -0,0 +1,67 @@
+plugins {
+ id 'java'
+ id 'application'
+ id 'checkstyle'
+ id 'org.openjfx.javafxplugin' version '0.0.10'
+ id 'com.github.johnrengelman.shadow' version '5.1.0'
+}
+
+checkstyle {
+ toolVersion = '10.2'
+}
+
+javafx {
+ version = "18.0.2"
+ modules = [ 'javafx.controls' ]
+}
+
+repositories {
+ mavenCentral()
+}
+
+dependencies {
+ testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.5.0'
+ testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.5.0'
+
+ String javaFxVersion = '11'
+
+ implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'win'
+ implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'mac'
+ implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'linux'
+ implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'win'
+ implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'mac'
+ implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'linux'
+ implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'win'
+ implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'mac'
+ implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'linux'
+ implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'win'
+ implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'mac'
+ implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'linux'
+}
+
+test {
+ useJUnitPlatform()
+
+ testLogging {
+ events "passed", "skipped", "failed"
+
+ showExceptions true
+ exceptionFormat "full"
+ showCauses true
+ showStackTraces true
+ showStandardStreams = false
+ }
+}
+
+application {
+ mainClassName = "duke.javafx.Launcher"
+}
+
+shadowJar {
+ archiveBaseName = "duke"
+ archiveClassifier = null
+}
+
+run{
+ standardInput = System.in
+}
diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml
new file mode 100644
index 0000000000..e8ee76467b
--- /dev/null
+++ b/config/checkstyle/checkstyle.xml
@@ -0,0 +1,429 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/config/checkstyle/suppressions.xml b/config/checkstyle/suppressions.xml
new file mode 100644
index 0000000000..135ea49ee0
--- /dev/null
+++ b/config/checkstyle/suppressions.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/data/Duke.txt b/data/Duke.txt
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/data/data.txt b/data/data.txt
new file mode 100644
index 0000000000..c4ab884cc3
--- /dev/null
+++ b/data/data.txt
@@ -0,0 +1,2 @@
+[D][1] CS2103T | 16 Sep 2022 2359
+[E][0] celebrate | 17 Sep 2022 0000
\ No newline at end of file
diff --git a/docs/README.md b/docs/README.md
index 8077118ebe..e5698e2b27 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -1,29 +1,159 @@
# User Guide
+Welcome to this user guide for the chatbot Duke!
+You may find the list of available commands below.
+
## Features
-### Feature-ABC
+Here you may finnd a list of features.
+
+### Adding a Deadline task
+
+Adds a task that has a deadline.
+
+Usage: `deadline TASK_DESCRIPTION /by DATE TIME`
+
+`DATE` is in the form of day followed by month followed by year,
+separated by either a `.`, `-` or `/`.
+
+`TIME` (optional) is in the 24-hour clock format.
+
+Example 1: `deadline submit homework /by 30-9-2022 2359`
+
+Outcome:
+```
+I've added a new deadline task:
+[D][0] submit homework | 30 Sep 2022 2359
+```
+
+Example 2: `deadline sleep /by 1-1-2022`
+
+Outcome:
+```
+I've added a new deadline task:
+[D][0] sleep | 01 Jan 2022
+```
+
+### Adding an Event task
+
+Adds a task that occurs at a certain time
-Description of the feature.
+Usage: `event TASK_DESCRIPTION /at DATE TIME`
-### Feature-XYZ
+`DATE` is in the form of day followed by month followed by year,
+separated by either a `.`, `-` or `/`.
-Description of the feature.
+`TIME`(optional) is in the 24-hour clock format.
-## Usage
+Example 1: `event party /at 30-9-2022 2000`
-### `Keyword` - Describe action
+Outcome:
+```
+I've added a new event task:
+[E][0] party | 30 Sep 2022 2000
+```
+
+Example 2: `event give speech /at 1-1-2022`
+
+Outcome:
+```
+I've added a new event task:
+[E][0] give speech | 01 Jan 2022
+```
+
+### Adding a Todo Task
+
+Usage: `todo TASK_DESCRIPTION`
-Describe the action and its outcome.
+Example: `todo read book`
-Example of usage:
+Outcome:
+```
+I've added a new todo task:
+[T][0] read book
+```
+
+### Listing all tasks
+
+Usage: `list`
+
+Example: `list`
+
+Outcome:
+```
+[T][0] read book
+[E][1] celebrate new year | 01 Jan 2022
+```
-`keyword (optional arguments)`
+### Deleting a task
-Expected outcome:
+Usage: `delete TASK_NUMBER`
-Description of the outcome.
+Example: `delete 1`
+Outcome:
```
-expected output
+I've deleted this task:
+[T][1] watch movie
```
+
+### Finding a task
+
+Usage: `find KEYWORD`
+
+Only tasks that contain `KEYWORD` in the description will be shown.
+
+Example: `find book`
+
+Outcome:
+```
+[T][1] read book
+[D][0] return books | 31 Dec 2022
+```
+
+### Marking a task as done
+
+Usage: `mark TASK_NUMBER`
+
+Example: `mark 2`
+
+Outcome:
+```
+I've marked this task as complete:
+[T][1] write book
+```
+
+### Marking a task as undone
+
+Usage: `unmark TASK_NUMBER`
+
+Example: `unmark 3`
+
+Outcome:
+```
+I've marked this task as incomplete:
+[T][0] write reflections
+```
+
+### Setting the filepath for local storage
+
+Usage: `file FILE_PATH`
+
+`FILE_PATH` is the file location of the local storage file.
+
+Example: `file data/data.txt`
+
+### Exiting Duke
+
+Usage: `bye`
+
+Example: `bye`
+
+Outcome:
+```
+Bye!
+```
+
+## End
+
+Thank you for reading this user guide!
\ No newline at end of file
diff --git a/docs/Ui.png b/docs/Ui.png
new file mode 100644
index 0000000000..9aaad17ead
Binary files /dev/null and b/docs/Ui.png differ
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000000..f3d88b1c2f
Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000000..b7c8c5dbf5
--- /dev/null
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,5 @@
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-bin.zip
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
diff --git a/gradlew b/gradlew
new file mode 100755
index 0000000000..2fe81a7d95
--- /dev/null
+++ b/gradlew
@@ -0,0 +1,183 @@
+#!/usr/bin/env sh
+
+#
+# Copyright 2015 the original author or authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn () {
+ echo "$*"
+}
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+ NONSTOP* )
+ nonstop=true
+ ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin or MSYS, switch paths to Windows format before running java
+if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+ JAVACMD=`cygpath --unix "$JAVACMD"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=`expr $i + 1`
+ done
+ case $i in
+ 0) set -- ;;
+ 1) set -- "$args0" ;;
+ 2) set -- "$args0" "$args1" ;;
+ 3) set -- "$args0" "$args1" "$args2" ;;
+ 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Escape application args
+save () {
+ for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
+ echo " "
+}
+APP_ARGS=`save "$@"`
+
+# Collect all arguments for the java command, following the shell quoting and substitution rules
+eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
+
+exec "$JAVACMD" "$@"
diff --git a/gradlew.bat b/gradlew.bat
new file mode 100644
index 0000000000..62bd9b9cce
--- /dev/null
+++ b/gradlew.bat
@@ -0,0 +1,103 @@
+@rem
+@rem Copyright 2015 the original author or authors.
+@rem
+@rem Licensed under the Apache License, Version 2.0 (the "License");
+@rem you may not use this file except in compliance with the License.
+@rem You may obtain a copy of the License at
+@rem
+@rem https://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing, software
+@rem distributed under the License is distributed on an "AS IS" BASIS,
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@rem See the License for the specific language governing permissions and
+@rem limitations under the License.
+@rem
+
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Resolve any "." and ".." in APP_HOME to make it shorter.
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windows variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java
deleted file mode 100644
index 5d313334cc..0000000000
--- 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/duke/Duke.java b/src/main/java/duke/Duke.java
new file mode 100644
index 0000000000..f51c351ab0
--- /dev/null
+++ b/src/main/java/duke/Duke.java
@@ -0,0 +1,91 @@
+package duke;
+
+import java.io.IOException;
+import java.util.Scanner;
+
+import duke.command.Command;
+import duke.storage.Storage;
+import javafx.scene.Scene;
+import javafx.scene.control.Button;
+import javafx.scene.control.ScrollPane;
+import javafx.scene.control.TextField;
+import javafx.scene.image.Image;
+import javafx.scene.layout.VBox;
+
+/**
+ * Represents a ChatBot named Duke. Duke can help you track your tasks.
+ */
+public class Duke {
+
+ private final Storage storage;
+ private TaskList tasks;
+ private final Ui ui;
+
+ /**
+ * Creates a new Duke.
+ */
+ public Duke() {
+ ui = new Ui();
+ storage = new Storage();
+ try {
+ tasks = new TaskList(storage.load());
+ } catch (IOException e) {
+ tasks = new TaskList();
+ }
+ }
+
+ /**
+ * Creates a new Duke.
+ *
+ * @param filePath Path to the file where data of your tasks will be locally stored.
+ */
+ public Duke(String filePath) {
+ ui = new Ui();
+ storage = new Storage(filePath);
+ try {
+ tasks = new TaskList(storage.load());
+ } catch (Exception e) {
+ ui.showLoadingError();
+ tasks = new TaskList();
+ }
+ }
+
+ public static void main(String[] args) {
+ new Duke("data/data.txt").run();
+ }
+
+ /**
+ * Returns a string output to the user based on the user input.
+ *
+ * @param input The user input
+ * @return Duke's reply to the user.
+ */
+ public String getResponse(String input) {
+ try {
+ Command command = Parser.parse(input);
+ return command.execute(tasks, storage);
+ } catch (DukeException e) {
+ return e.getMessage();
+ }
+ }
+
+ /**
+ * Start the conversation with Duke.
+ */
+ public void run() {
+ ui.showWelcome();
+ boolean isExit = false;
+ while (!isExit) {
+ try {
+ Scanner sc = new Scanner(System.in);
+ String input = sc.nextLine();
+ Command command = Parser.parse(input);
+ command.execute(tasks, ui, storage);
+ isExit = command.isExit();
+ } catch (DukeException e) {
+ ui.displayError(e);
+ }
+ }
+ }
+
+}
diff --git a/src/main/java/duke/DukeException.java b/src/main/java/duke/DukeException.java
new file mode 100644
index 0000000000..35b9eaf6da
--- /dev/null
+++ b/src/main/java/duke/DukeException.java
@@ -0,0 +1,17 @@
+package duke;
+
+/**
+ * Represents a Duke related exception.
+ */
+public class DukeException extends RuntimeException {
+
+ /**
+ * Creates a new Duke related exception with an error message.
+ *
+ * @param message Error message to be displayed to the user.
+ */
+ public DukeException(String message) {
+ super(message);
+ }
+
+}
diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java
new file mode 100644
index 0000000000..8a7bd69626
--- /dev/null
+++ b/src/main/java/duke/Parser.java
@@ -0,0 +1,435 @@
+package duke;
+
+import java.time.DateTimeException;
+import java.time.LocalDate;
+
+import duke.command.AddDeadlineCommand;
+import duke.command.AddEventCommand;
+import duke.command.AddTodoCommand;
+import duke.command.ByeCommand;
+import duke.command.Command;
+import duke.command.DeleteCommand;
+import duke.command.FindCommand;
+import duke.command.ListCommand;
+import duke.command.MarkCommand;
+import duke.command.NullCommand;
+import duke.command.SetPathCommand;
+import duke.command.UnmarkCommand;
+import duke.command.UnrecognisedCommand;
+
+/**
+ * Used to interpret user inputs and match them to available commands.
+ */
+public class Parser {
+
+ private static String removeWhitespace(String input) {
+ return input.replaceAll(" ", "");
+ }
+
+ private static String removeStartingWhitespace(String input) {
+ if (input.length() == 0) {
+ return "blank";
+ }
+ if (input.indexOf(' ') == 0) {
+ if (input.length() == 1) {
+ return "blank";
+ }
+ return removeStartingWhitespace(input.substring(1));
+ }
+ return input;
+ }
+
+ private static int countArguments(String input) {
+ String str = input;
+ int count = 0;
+ while (str.length() > 0) {
+ int index = str.indexOf(' ');
+ if (index == -1) {
+ count++;
+ break;
+ } else if (index == str.length() - 1) {
+ break;
+ } else {
+ if (index != 0) {
+ count++;
+ }
+ str = str.substring(index + 1);
+ }
+ }
+ return count;
+ }
+
+ private static String findArgument(String input, int argNum) {
+ if (argNum > countArguments(input)) {
+ return "NOT FOUND";
+ }
+ String str = input;
+ int count = 0;
+ while (true) {
+ count++;
+ int index = str.indexOf(' ');
+ if (count == argNum) {
+ if (index == -1) {
+ return str;
+ } else {
+ return str.substring(0, index);
+ }
+ }
+ while (true) {
+ if (str.charAt(index + 1) == ' ') {
+ index++;
+ } else {
+ break;
+ }
+ }
+ str = str.substring(index + 1);
+ }
+ }
+
+ private static String combineArguments(String text, int start, int end) {
+ if (start > end) {
+ throw new DukeException("No string found");
+ }
+ StringBuilder stringBuilder = new StringBuilder();
+ stringBuilder.append(findArgument(text, start));
+ for (int i = start + 1; i < end + 1; i++) {
+ stringBuilder.append(' ').append(findArgument(text, i));
+ }
+ return stringBuilder.toString();
+ }
+
+ private static String parseDate(String date) {
+ int firstIndex;
+ int secondIndex;
+ if (date.contains("/")) {
+ firstIndex = date.indexOf("/");
+ secondIndex = date.substring(firstIndex + 1).indexOf("/") + firstIndex + 1;
+ } else if (date.contains("-")) {
+ firstIndex = date.indexOf("-");
+ secondIndex = date.substring(firstIndex + 1).indexOf("-") + firstIndex + 1;
+ } else if (date.contains(".")) {
+ firstIndex = date.indexOf(".");
+ secondIndex = date.substring(firstIndex + 1).indexOf(".") + firstIndex + 1;
+ } else {
+ throw new DateTimeException("Not a valid date format");
+ }
+ if (secondIndex == -1) {
+ throw new DateTimeException("Not a valid date format");
+ }
+ int year;
+ int month;
+ int day;
+ if (firstIndex == 1) {
+ if (secondIndex == 3) {
+ day = Integer.parseInt(date.substring(0, 1));
+ month = Integer.parseInt(date.substring(2, 3));
+ year = Integer.parseInt(date.substring(4, 8));
+ } else if (secondIndex == 4) {
+ day = Integer.parseInt(date.substring(0, 1));
+ month = Integer.parseInt(date.substring(2, 4));
+ year = Integer.parseInt(date.substring(5, 9));
+ } else {
+ throw new DateTimeException("Not a valid date format");
+ }
+ } else if (firstIndex == 2) {
+ if (secondIndex == 4) {
+ day = Integer.parseInt(date.substring(0, 2));
+ month = Integer.parseInt(date.substring(3, 4));
+ year = Integer.parseInt(date.substring(5, 9));
+ } else if (secondIndex == 5) {
+ day = Integer.parseInt(date.substring(0, 2));
+ month = Integer.parseInt(date.substring(3, 5));
+ year = Integer.parseInt(date.substring(6, 10));
+ } else {
+ throw new DateTimeException("Not a valid date format");
+ }
+ } else {
+ throw new DateTimeException("Not a valid date format");
+ }
+ try {
+ LocalDate.of(year, month, day);
+ } catch (DateTimeException e) {
+ throw new DateTimeException("No such day exists!");
+ }
+ String wordDay = Integer.toString(day);
+ String wordMonth = Integer.toString(month);
+ if (day < 10) {
+ wordDay = "0" + day;
+ }
+ if (month < 10) {
+ wordMonth = "0" + month;
+ }
+ return String.format("%s%s%d", wordDay, wordMonth, year);
+ }
+
+ /**
+ * Converts a date from word format to ddmmyyyy format.
+ * e.g. 31 Jan 2022 will be converted to 31012022
+ *
+ * @param date Date to be converted into ddmmyy format. date should be in the format of e.g. 25 Mar 2019
+ * @return The converted date in ddmmyyyy format.
+ */
+ public static String parseWordDate(String date) {
+ if (date.length() != 11) {
+ throw new DateTimeException("Not recognised!");
+ }
+ String wordDate = date.substring(3, 6);
+ String numDate;
+ switch (wordDate) {
+ case "Jan":
+ numDate = "01";
+ break;
+ case "Feb":
+ numDate = "02";
+ break;
+ case "Mar":
+ numDate = "03";
+ break;
+ case "Apr":
+ numDate = "04";
+ break;
+ case "May":
+ numDate = "05";
+ break;
+ case "Jun":
+ numDate = "06";
+ break;
+ case "Jul":
+ numDate = "07";
+ break;
+ case "Aug":
+ numDate = "08";
+ break;
+ case "Sep":
+ numDate = "09";
+ break;
+ case "Oct":
+ numDate = "10";
+ break;
+ case "Nov":
+ numDate = "11";
+ break;
+ case "Dec":
+ numDate = "12";
+ break;
+ default:
+ numDate = "00";
+ }
+ return date.substring(0, 2) + numDate + date.substring(7);
+ }
+
+ /**
+ * Converts an integer between 1-12 to a 3-letter representation of the month.
+ * e.g. 5 will be converted to May, 12 will be converted to Dec.
+ *
+ * @param m Integer representation of a month, ranging from 1-12.
+ * @return A 3-letter word representation of the month.
+ */
+ public static String intToWordMonth(int m) {
+ switch (m) {
+ case 1:
+ return "Jan";
+ case 2:
+ return "Feb";
+ case 3:
+ return "Mar";
+ case 4:
+ return "Apr";
+ case 5:
+ return "May";
+ case 6:
+ return "Jun";
+ case 7:
+ return "Jul";
+ case 8:
+ return "Aug";
+ case 9:
+ return "Sep";
+ case 10:
+ return "Oct";
+ case 11:
+ return "Nov";
+ case 12:
+ return "Dec";
+ default:
+ return "Nam";
+ }
+ }
+
+ private static String parseTime(String time) {
+ if (time.length() != 4) {
+ throw new DateTimeException("Time should be provided as 4 digits as per the 24 hour clock");
+ }
+ try {
+ int intTime = Integer.parseInt(time);
+ int hour = intTime / 100;
+ if (hour > 23) {
+ throw new DateTimeException("No such time exists!");
+ }
+ int minute = intTime - hour * 100;
+ if (minute > 59) {
+ throw new DateTimeException("No such time exists!");
+ }
+ } catch (NumberFormatException e) {
+ throw new DateTimeException("Please input numbers as time!");
+ }
+ return time;
+ }
+
+ /**
+ * Takes in a string input from the user and converts it to a command recognised by Duke.
+ *
+ * @param input String input from the user.
+ * @return A command that can be executed by Duke.
+ * @throws DukeException if the user's desired command cannot be properly performed.
+ */
+ public static Command parse(String input) throws DukeException {
+ input = removeStartingWhitespace(input);
+ if (input.equals("blank")) {
+ return new NullCommand();
+ }
+ String command = findArgument(input, 1).toLowerCase();
+ assert command.charAt(0) != ' ';
+ switch (command) {
+ case "bye":
+ return parseBye(input);
+ case "list":
+ return parseList(input);
+ case "mark":
+ return parseMark(input);
+ case "unmark":
+ return parseUnmark(input);
+ case "delete":
+ return parseDelete(input);
+ case "deadline":
+ return parseDeadline(input);
+ case "event":
+ return parseEvent(input);
+ case "todo":
+ return parseTodo(input);
+ case "find":
+ return parseFind(input);
+ case "file":
+ return parseFile(input);
+ default:
+ return new UnrecognisedCommand();
+ }
+ }
+
+ private static Command parseBye(String input) {
+ if (countArguments(input) != 1) {
+ throw new DukeException("Who is that?");
+ }
+ return new ByeCommand();
+ }
+
+ private static Command parseList(String input) {
+ if (countArguments(input) != 1) {
+ throw new DukeException("Just use 'list'!");
+ }
+ return new ListCommand();
+ }
+
+ private static Command parseMark(String input) {
+ if (countArguments(input) != 2) {
+ throw new DukeException("Incorrect number of arguments for command mark");
+ }
+ try {
+ input = (removeWhitespace(input));
+ int taskNum = Integer.parseInt(input.substring(4));
+ return new MarkCommand(taskNum);
+ } catch (NumberFormatException e) {
+ throw new DukeException("Must input a number!");
+ }
+ }
+
+ private static Command parseUnmark(String input) {
+ if (countArguments(input) != 2) {
+ throw new DukeException("Incorrect number of arguments for command unmark");
+ }
+ try {
+ input = (removeWhitespace(input));
+ int taskNum = Integer.parseInt(input.substring(6));
+ return new UnmarkCommand(taskNum);
+ } catch (NumberFormatException e) {
+ throw new DukeException("Must input a number!");
+ }
+ }
+
+ private static Command parseDelete(String input) {
+ if (countArguments(input) != 2) {
+ throw new DukeException("Incorrect number of arguments for command delete");
+ }
+ try {
+ input = (removeWhitespace(input));
+ int taskNum = Integer.parseInt(input.substring(6));
+ return new DeleteCommand(taskNum);
+ } catch (NumberFormatException e) {
+ throw new DukeException("Must input a number!");
+ }
+ }
+
+ private static Command parseDeadline(String input) {
+ int numOfArguments = countArguments(input);
+ if (numOfArguments < 4) {
+ String message = "To add a deadline task, enter a task description followed by /by and then a deadline";
+ throw new DukeException(message);
+ }
+ if (findArgument(input, numOfArguments - 1).equalsIgnoreCase("/by")) {
+ String taskName = combineArguments(input, 2, numOfArguments - 2);
+ String date = parseDate(findArgument(input, numOfArguments));
+ return new AddDeadlineCommand(taskName, date);
+ } else if (findArgument(input, numOfArguments - 2).equalsIgnoreCase("/by")) {
+ String taskName = combineArguments(input, 2, numOfArguments - 3);
+ String date = parseDate(findArgument(input, numOfArguments - 1));
+ String time = parseTime(findArgument(input, numOfArguments));
+ return new AddDeadlineCommand(taskName, date, time);
+ } else {
+ throw new DukeException("You need to add /by after the task description to specify a date");
+ }
+ }
+
+ private static Command parseEvent(String input) {
+ int numOfArguments = countArguments(input);
+ if (numOfArguments < 4) {
+ String message = "To add an event task, enter a task description followed by /by and then a date";
+ throw new DukeException(message);
+ }
+ if (findArgument(input, numOfArguments - 1).equalsIgnoreCase("/at")) {
+ String taskName = combineArguments(input, 2, numOfArguments - 2);
+ String date = parseDate(findArgument(input, numOfArguments));
+ return new AddEventCommand(taskName, date);
+ } else if (findArgument(input, numOfArguments - 2).equalsIgnoreCase("/at")) {
+ String taskName = combineArguments(input, 2, numOfArguments - 3);
+ String date = parseDate(findArgument(input, numOfArguments - 1));
+ String time = parseTime(findArgument(input, numOfArguments));
+ return new AddEventCommand(taskName, date, time);
+ } else {
+ throw new DukeException("You need to add /at after the task description to specify a date");
+ }
+ }
+
+ private static Command parseTodo(String input) {
+ if (countArguments(input) < 2) {
+ throw new DukeException("You need to enter a task description!");
+ }
+ String taskName = combineArguments(input, 2, countArguments(input));
+ return new AddTodoCommand(taskName);
+ }
+
+ private static Command parseFind(String input) {
+ if (countArguments(input) != 2) {
+ throw new DukeException("Please enter only 1 keyword!");
+ }
+ String keyword = findArgument(input, 2);
+ return new FindCommand(keyword);
+ }
+
+ private static Command parseFile(String input) {
+ if (countArguments(input) != 2) {
+ throw new DukeException("Enter a valid filepath");
+ }
+ String filePath = findArgument(input, 2);
+ return new SetPathCommand(filePath);
+ }
+}
diff --git a/src/main/java/duke/TaskList.java b/src/main/java/duke/TaskList.java
new file mode 100644
index 0000000000..e9539fa672
--- /dev/null
+++ b/src/main/java/duke/TaskList.java
@@ -0,0 +1,146 @@
+package duke;
+
+import java.util.ArrayList;
+
+import duke.task.Task;
+
+/**
+ * Represents a list of tasks.
+ */
+public class TaskList {
+
+ private final ArrayList taskList;
+
+ /**
+ * Creates a list of tasks with existing tasks.
+ * @param taskList A list of tasks to initialise with.
+ */
+ public TaskList(ArrayList taskList) {
+ this.taskList = taskList;
+ }
+
+ /**
+ * Creates an empty list of tasks.
+ */
+ public TaskList() {
+ taskList = new ArrayList<>();
+ }
+
+ /**
+ * Adds a new task to the end of the list.
+ *
+ * @param task The task to be added.
+ */
+ public void add(Task task) {
+ taskList.add(task);
+ }
+
+ /**
+ * Lists out all the tasks in the list, line by line, as a single string.
+ *
+ * @return A line by line string representation of every task in the list.
+ */
+ public String list() {
+ if (taskList.size() == 0) {
+ return "No tasks yet";
+ }
+ StringBuilder listOfTasks = new StringBuilder();
+ for (Task task : taskList) {
+ listOfTasks.append(task);
+ listOfTasks.append("\n");
+ }
+ int last = listOfTasks.lastIndexOf("\n");
+ listOfTasks.deleteCharAt(last);
+ return listOfTasks.toString();
+ }
+
+ /**
+ * Returns a Task specified by its position in the list.
+ *
+ * @param taskNum The index of the task to retrieve. The first task is 1.
+ * @return The Task at the specified index.
+ * @throws IndexOutOfBoundsException if there is no task at the input index.
+ */
+ public Task getTask(int taskNum) throws IndexOutOfBoundsException {
+ try {
+ return taskList.get(taskNum - 1);
+ } catch (IndexOutOfBoundsException e) {
+ throw new IndexOutOfBoundsException("No such task!");
+ }
+ }
+
+ /**
+ * Returns the number of tasks in the list.
+ *
+ * @return The number of tasks in the list.
+ */
+ public int size() {
+ return taskList.size();
+ }
+
+ /**
+ * Marks a specified task in the list as complete.
+ *
+ * @param taskNum The task to be marked. The first task is task 1.
+ * @return The task that was marked.
+ * @throws IndexOutOfBoundsException if taskNum is not a valid task number.
+ */
+ public Task mark(int taskNum) throws IndexOutOfBoundsException {
+ try {
+ Task task = taskList.get(taskNum - 1);
+ task.markComplete();
+ return task;
+ } catch (IndexOutOfBoundsException e) {
+ throw new IndexOutOfBoundsException("No such task!");
+ }
+ }
+
+ /**
+ * Marks a specified task in the list as incomplete.
+ *
+ * @param taskNum The task to be marked. The first task is task 1.
+ * @return The task that was marked.
+ * @throws IndexOutOfBoundsException if taskNum is not a valid task number.
+ */
+ public Task unmark(int taskNum) throws IndexOutOfBoundsException {
+ try {
+ Task task = taskList.get(taskNum - 1);
+ task.markIncomplete();
+ return task;
+ } catch (IndexOutOfBoundsException e) {
+ throw new IndexOutOfBoundsException("No such task!");
+ }
+ }
+
+ /**
+ * Deletes a specified task from the list.
+ *
+ * @param taskNum The task to be deleted. The first task is task 1.
+ * @return The task that was deleted.
+ * @throws IndexOutOfBoundsException if taskNum is not a valid task number.
+ */
+ public Task delete(int taskNum) throws IndexOutOfBoundsException {
+ try {
+ return taskList.remove(taskNum - 1);
+ } catch (IndexOutOfBoundsException e) {
+ throw new IndexOutOfBoundsException("No such task!");
+ }
+ }
+
+ /**
+ * Filters the task list to only contain tasks with the specified keyword in the task description.
+ *
+ * @param keyword The keyword to search for in the tasks.
+ * @return A TaskList that contains only tasks that contain the keyword.
+ */
+ public TaskList filter(String keyword) {
+ TaskList filteredTaskList = new TaskList();
+ for (Task task : taskList) {
+ if (task.getTaskDescription().contains(keyword)) {
+ filteredTaskList.add(task);
+ }
+ }
+ return filteredTaskList;
+ }
+
+}
diff --git a/src/main/java/duke/Ui.java b/src/main/java/duke/Ui.java
new file mode 100644
index 0000000000..d681fc8210
--- /dev/null
+++ b/src/main/java/duke/Ui.java
@@ -0,0 +1,32 @@
+package duke;
+
+/**
+ * A class for dealing with displaying outputs to the user.
+ */
+public class Ui {
+
+ public void showWelcome() {
+ System.out.println("Hi I'm Duke! What may I do for you?");
+ }
+
+ public void showGoodbye() {
+ System.out.println("Bye!");
+ }
+
+ public void showLoadingError() {
+ System.out.println("Unable to load from file. Check if the file exists and whether it was formatted properly.");
+ }
+
+ public void showWritingError() {
+ System.out.println("Unable to write to file. Check if the file exists.");
+ }
+
+ public void display(String output) {
+ System.out.println(output);
+ }
+
+ public void displayError(Exception e) {
+ System.out.println(e.getMessage());
+ }
+
+}
diff --git a/src/main/java/duke/command/AddDeadlineCommand.java b/src/main/java/duke/command/AddDeadlineCommand.java
new file mode 100644
index 0000000000..dcf10b1a9b
--- /dev/null
+++ b/src/main/java/duke/command/AddDeadlineCommand.java
@@ -0,0 +1,54 @@
+package duke.command;
+
+import java.io.IOException;
+
+import duke.DukeException;
+import duke.TaskList;
+import duke.Ui;
+import duke.storage.Storage;
+import duke.task.DeadlineTask;
+import duke.task.Task;
+
+/**
+ * Can be executed to add a DeadlineTask.
+ */
+public class AddDeadlineCommand extends Command {
+
+ private final Task deadlineTask;
+
+ public AddDeadlineCommand(String taskName, String date, String time) {
+ deadlineTask = new DeadlineTask(taskName, date, time);
+ }
+
+ public AddDeadlineCommand(String taskName, String date) {
+ deadlineTask = new DeadlineTask(taskName, date);
+ }
+
+ @Override
+ public boolean isExit() {
+ return false;
+ }
+
+ @Override
+ public void execute(TaskList taskList, Ui ui, Storage storage) {
+ try {
+ taskList.add(deadlineTask);
+ storage.writeToFile(taskList.list());
+ ui.display(String.format("Added new deadline task:%n%s%n", deadlineTask));
+ } catch (IOException e) {
+ throw new DukeException("Could not write to file");
+ }
+ }
+
+ @Override
+ public String execute(TaskList taskList, Storage storage) {
+ try {
+ taskList.add(deadlineTask);
+ storage.writeToFile(taskList.list());
+ return String.format("I've added a new deadline task:%n%s%n", deadlineTask);
+ } catch (IOException e) {
+ throw new DukeException("Could not write to file");
+ }
+ }
+
+}
diff --git a/src/main/java/duke/command/AddEventCommand.java b/src/main/java/duke/command/AddEventCommand.java
new file mode 100644
index 0000000000..990d2a6a09
--- /dev/null
+++ b/src/main/java/duke/command/AddEventCommand.java
@@ -0,0 +1,54 @@
+package duke.command;
+
+import java.io.IOException;
+
+import duke.DukeException;
+import duke.TaskList;
+import duke.Ui;
+import duke.storage.Storage;
+import duke.task.EventTask;
+import duke.task.Task;
+
+/**
+ * Can be executed to add an EventTask.
+ */
+public class AddEventCommand extends Command {
+
+ private final Task eventTask;
+
+ public AddEventCommand(String taskName, String date, String time) {
+ eventTask = new EventTask(taskName, date, time);
+ }
+
+ public AddEventCommand(String taskName, String date) {
+ eventTask = new EventTask(taskName, date);
+ }
+
+ @Override
+ public boolean isExit() {
+ return false;
+ }
+
+ @Override
+ public void execute(TaskList taskList, Ui ui, Storage storage) {
+ try {
+ taskList.add(eventTask);
+ storage.writeToFile(taskList.list());
+ ui.display(String.format("Added new event task:%n%s%n", eventTask));
+ } catch (IOException e) {
+ throw new DukeException("Could not write to file");
+ }
+ }
+
+ @Override
+ public String execute(TaskList taskList, Storage storage) {
+ try {
+ taskList.add(eventTask);
+ storage.writeToFile(taskList.list());
+ return String.format("I've added a new event task:%n%s%n", eventTask);
+ } catch (IOException e) {
+ throw new DukeException("Could not write to file");
+ }
+ }
+
+}
diff --git a/src/main/java/duke/command/AddTodoCommand.java b/src/main/java/duke/command/AddTodoCommand.java
new file mode 100644
index 0000000000..c69e4d3375
--- /dev/null
+++ b/src/main/java/duke/command/AddTodoCommand.java
@@ -0,0 +1,51 @@
+package duke.command;
+
+import java.io.IOException;
+
+import duke.DukeException;
+import duke.TaskList;
+import duke.Ui;
+import duke.storage.Storage;
+import duke.task.Task;
+import duke.task.TodoTask;
+
+/**
+ * Can be executed to add a TodoTask.
+ */
+public class AddTodoCommand extends Command {
+
+ private final Task todoTask;
+
+ public AddTodoCommand(String taskName) {
+ todoTask = new TodoTask(taskName);
+ }
+
+ @Override
+ public boolean isExit() {
+ return false;
+ }
+
+
+ @Override
+ public void execute(TaskList taskList, Ui ui, Storage storage) {
+ try {
+ taskList.add(todoTask);
+ storage.writeToFile(taskList.list());
+ ui.display(String.format("Added new todo task:%n%s%n", todoTask));
+ } catch (IOException e) {
+ throw new DukeException("Could not write to file");
+ }
+ }
+
+ @Override
+ public String execute(TaskList taskList, Storage storage) {
+ try {
+ taskList.add(todoTask);
+ storage.writeToFile(taskList.list());
+ return String.format("I've added a new todo task:%n%s%n", todoTask);
+ } catch (IOException e) {
+ throw new DukeException("Could not write to file");
+ }
+ }
+
+}
diff --git a/src/main/java/duke/command/ByeCommand.java b/src/main/java/duke/command/ByeCommand.java
new file mode 100644
index 0000000000..7e50e63dbb
--- /dev/null
+++ b/src/main/java/duke/command/ByeCommand.java
@@ -0,0 +1,31 @@
+package duke.command;
+
+import java.util.concurrent.TimeUnit;
+
+import duke.TaskList;
+import duke.Ui;
+import duke.storage.Storage;
+
+/**
+ * Can be executed to exit the Duke program.
+ */
+public class ByeCommand extends Command {
+
+ @Override
+ public boolean isExit() {
+ return true;
+ }
+
+
+ @Override
+ public void execute(TaskList taskList, Ui ui, Storage storage) {
+ ui.showGoodbye();
+ }
+
+ @Override
+ public String execute(TaskList taskList, Storage storage) {
+ System.exit(0);
+ return "Bye!";
+ }
+
+}
diff --git a/src/main/java/duke/command/Command.java b/src/main/java/duke/command/Command.java
new file mode 100644
index 0000000000..5a2a40d9d1
--- /dev/null
+++ b/src/main/java/duke/command/Command.java
@@ -0,0 +1,37 @@
+package duke.command;
+
+import duke.TaskList;
+import duke.Ui;
+import duke.storage.Storage;
+
+/**
+ * Represents a user command that can be executed.
+ */
+public abstract class Command {
+
+ /**
+ * Returns whether the command is a ByeCommand.
+ *
+ * @return true if the command is a ByeCommand, false otherwise.
+ */
+ public abstract boolean isExit();
+
+ /**
+ * Executes the task, displaying the output on the UI.
+ *
+ * @param taskList The TaskList for this Duke program.
+ * @param ui The Ui for this Duke program.
+ * @param storage The Storage for this Duke program.
+ */
+ public abstract void execute(TaskList taskList, Ui ui, Storage storage);
+
+ /**
+ * Executes the task, displaying the output on the GUI.
+ *
+ * @param taskList The TaskList for this Duke program.
+ * @param storage The Storage for this Duke program.
+ * @return A String to be displayed to the user on the GUI.
+ */
+ public abstract String execute(TaskList taskList, Storage storage);
+
+}
diff --git a/src/main/java/duke/command/DeleteCommand.java b/src/main/java/duke/command/DeleteCommand.java
new file mode 100644
index 0000000000..925bc083c5
--- /dev/null
+++ b/src/main/java/duke/command/DeleteCommand.java
@@ -0,0 +1,54 @@
+package duke.command;
+
+import java.io.IOException;
+
+import duke.DukeException;
+import duke.TaskList;
+import duke.Ui;
+import duke.storage.Storage;
+import duke.task.Task;
+
+/**
+ * Can be executed to delete a task.
+ */
+public class DeleteCommand extends Command {
+
+ private final int taskNum;
+
+ public DeleteCommand(int taskNum) {
+ this.taskNum = taskNum;
+ }
+
+ @Override
+ public boolean isExit() {
+ return false;
+ }
+
+
+ @Override
+ public void execute(TaskList taskList, Ui ui, Storage storage) {
+ try {
+ Task task = taskList.delete(taskNum);
+ storage.writeToFile(taskList.list());
+ ui.display(String.format("I've deleted this task:%n%s%n", task));
+ } catch (IndexOutOfBoundsException e) {
+ throw new DukeException("No such task!");
+ } catch (IOException e) {
+ throw new DukeException("Could not write to file");
+ }
+ }
+
+ @Override
+ public String execute(TaskList taskList, Storage storage) {
+ try {
+ Task task = taskList.delete(taskNum);
+ storage.writeToFile(taskList.list());
+ return String.format("I've deleted this task:%n%s%n", task);
+ } catch (IndexOutOfBoundsException e) {
+ throw new DukeException("No such task!");
+ } catch (IOException e) {
+ throw new DukeException("Could not write to file");
+ }
+ }
+
+}
diff --git a/src/main/java/duke/command/FindCommand.java b/src/main/java/duke/command/FindCommand.java
new file mode 100644
index 0000000000..2c9898e499
--- /dev/null
+++ b/src/main/java/duke/command/FindCommand.java
@@ -0,0 +1,35 @@
+package duke.command;
+
+import duke.TaskList;
+import duke.Ui;
+import duke.storage.Storage;
+
+/**
+ * Can be executed to filter a task.
+ */
+public class FindCommand extends Command {
+
+ private final String keyword;
+
+ public FindCommand(String keyword) {
+ this.keyword = keyword;
+ }
+
+ @Override
+ public boolean isExit() {
+ return false;
+ }
+
+ @Override
+ public void execute(TaskList taskList, Ui ui, Storage storage) {
+ TaskList filteredTaskList = taskList.filter(keyword);
+ String output = filteredTaskList.list();
+ ui.display(output);
+ }
+
+ @Override
+ public String execute(TaskList taskList, Storage storage) {
+ TaskList filteredTaskList = taskList.filter(keyword);
+ return filteredTaskList.list();
+ }
+}
diff --git a/src/main/java/duke/command/ListCommand.java b/src/main/java/duke/command/ListCommand.java
new file mode 100644
index 0000000000..353ac43d1f
--- /dev/null
+++ b/src/main/java/duke/command/ListCommand.java
@@ -0,0 +1,28 @@
+package duke.command;
+
+import duke.TaskList;
+import duke.Ui;
+import duke.storage.Storage;
+
+/**
+ * Can be executed to display the list of tasks.
+ */
+public class ListCommand extends Command {
+
+ @Override
+ public boolean isExit() {
+ return false;
+ }
+
+
+ @Override
+ public void execute(TaskList taskList, Ui ui, Storage storage) {
+ ui.display(taskList.list());
+ }
+
+ @Override
+ public String execute(TaskList taskList, Storage storage) {
+ return taskList.list();
+ }
+
+}
diff --git a/src/main/java/duke/command/MarkCommand.java b/src/main/java/duke/command/MarkCommand.java
new file mode 100644
index 0000000000..a7b59695b6
--- /dev/null
+++ b/src/main/java/duke/command/MarkCommand.java
@@ -0,0 +1,54 @@
+package duke.command;
+
+import java.io.IOException;
+
+import duke.DukeException;
+import duke.TaskList;
+import duke.Ui;
+import duke.storage.Storage;
+import duke.task.Task;
+
+/**
+ * Can be executed to mark a task.
+ */
+public class MarkCommand extends Command {
+
+ private final int taskNum;
+
+ public MarkCommand(int taskNum) {
+ this.taskNum = taskNum;
+ }
+
+ @Override
+ public boolean isExit() {
+ return false;
+ }
+
+
+ @Override
+ public void execute(TaskList taskList, Ui ui, Storage storage) {
+ try {
+ Task task = taskList.mark(taskNum);
+ storage.writeToFile(taskList.list());
+ ui.display(String.format("I've marked this task as complete:%n%s%n", task));
+ } catch (IndexOutOfBoundsException e) {
+ throw new DukeException("No such task!");
+ } catch (IOException e) {
+ throw new DukeException("Could not write to file");
+ }
+ }
+
+ @Override
+ public String execute(TaskList taskList, Storage storage) {
+ try {
+ Task task = taskList.mark(taskNum);
+ storage.writeToFile(taskList.list());
+ return String.format("I've marked this task as complete:%n%s%n", task);
+ } catch (IndexOutOfBoundsException e) {
+ throw new DukeException("No such task!");
+ } catch (IOException e) {
+ throw new DukeException("Could not write to file");
+ }
+ }
+
+}
diff --git a/src/main/java/duke/command/NullCommand.java b/src/main/java/duke/command/NullCommand.java
new file mode 100644
index 0000000000..1449a44b65
--- /dev/null
+++ b/src/main/java/duke/command/NullCommand.java
@@ -0,0 +1,25 @@
+package duke.command;
+
+import duke.TaskList;
+import duke.Ui;
+import duke.storage.Storage;
+
+/**
+ * Represents a command that does nothing.
+ */
+public class NullCommand extends Command {
+
+ @Override
+ public boolean isExit() {
+ return false;
+ }
+
+ @Override
+ public void execute(TaskList taskList, Ui ui, Storage storage) {}
+
+ @Override
+ public String execute(TaskList taskList, Storage storage) {
+ return "?";
+ }
+
+}
diff --git a/src/main/java/duke/command/SetPathCommand.java b/src/main/java/duke/command/SetPathCommand.java
new file mode 100644
index 0000000000..50f743bf5d
--- /dev/null
+++ b/src/main/java/duke/command/SetPathCommand.java
@@ -0,0 +1,49 @@
+package duke.command;
+
+import java.io.IOException;
+
+import duke.DukeException;
+import duke.TaskList;
+import duke.Ui;
+import duke.storage.Storage;
+
+/**
+ * Can be executed to change the file path for local storage.
+ */
+public class SetPathCommand extends Command {
+
+ private final String filePath;
+
+ public SetPathCommand(String path) {
+ filePath = path;
+ }
+
+ @Override
+ public boolean isExit() {
+ return false;
+ }
+
+ @Override
+ public void execute(TaskList taskList, Ui ui, Storage storage) {
+ try {
+ storage.setFilePath(filePath);
+ storage.writeToFile(taskList.list());
+ ui.display("Changed filepath. Be careful, if a file did not already "
+ + "exist at that location, a new file would be created");
+ } catch (IOException e) {
+ throw new DukeException("Check if the specified filepath exists");
+ }
+ }
+
+ @Override
+ public String execute(TaskList taskList, Storage storage) {
+ try {
+ storage.setFilePath(filePath);
+ storage.writeToFile(taskList.list());
+ return String.format("File path change successfully to %s", filePath);
+ } catch (IOException e) {
+ throw new DukeException("Check if the specified filepath exists");
+ }
+ }
+
+}
diff --git a/src/main/java/duke/command/UnmarkCommand.java b/src/main/java/duke/command/UnmarkCommand.java
new file mode 100644
index 0000000000..f68ee4b587
--- /dev/null
+++ b/src/main/java/duke/command/UnmarkCommand.java
@@ -0,0 +1,54 @@
+package duke.command;
+
+import java.io.IOException;
+
+import duke.DukeException;
+import duke.TaskList;
+import duke.Ui;
+import duke.storage.Storage;
+import duke.task.Task;
+
+/**
+ * Can be executed to mark a task as incomplete.
+ */
+public class UnmarkCommand extends Command {
+
+ private final int taskNum;
+
+ public UnmarkCommand(int taskNum) {
+ this.taskNum = taskNum;
+ }
+
+ @Override
+ public boolean isExit() {
+ return false;
+ }
+
+
+ @Override
+ public void execute(TaskList taskList, Ui ui, Storage storage) {
+ try {
+ Task task = taskList.mark(taskNum);
+ storage.writeToFile(taskList.list());
+ ui.display(String.format("I've marked this task as complete:%n%s%n", task));
+ } catch (IndexOutOfBoundsException e) {
+ throw new DukeException("No such task!");
+ } catch (IOException e) {
+ throw new DukeException("Could not write to file");
+ }
+ }
+
+ @Override
+ public String execute(TaskList taskList, Storage storage) {
+ try {
+ Task task = taskList.mark(taskNum);
+ storage.writeToFile(taskList.list());
+ return String.format("I've marked this task as incomplete:%n%s%n", task);
+ } catch (IndexOutOfBoundsException e) {
+ throw new DukeException("No such task!");
+ } catch (IOException e) {
+ throw new DukeException("Could not write to file");
+ }
+ }
+
+}
diff --git a/src/main/java/duke/command/UnrecognisedCommand.java b/src/main/java/duke/command/UnrecognisedCommand.java
new file mode 100644
index 0000000000..029048fbfe
--- /dev/null
+++ b/src/main/java/duke/command/UnrecognisedCommand.java
@@ -0,0 +1,27 @@
+package duke.command;
+
+import duke.TaskList;
+import duke.Ui;
+import duke.storage.Storage;
+
+/**
+ * Represents a user command that is unrecognised.
+ */
+public class UnrecognisedCommand extends Command {
+
+ @Override
+ public boolean isExit() {
+ return false;
+ }
+
+ @Override
+ public void execute(TaskList taskList, Ui ui, Storage storage) {
+ ui.display("Sorry, I don't recognise that command :(");
+ }
+
+ @Override
+ public String execute(TaskList taskList, Storage storage) {
+ return "Sorry, I don't know what that means :(";
+ }
+
+}
diff --git a/src/main/java/duke/javafx/DialogBox.java b/src/main/java/duke/javafx/DialogBox.java
new file mode 100644
index 0000000000..3bff07208d
--- /dev/null
+++ b/src/main/java/duke/javafx/DialogBox.java
@@ -0,0 +1,61 @@
+package duke.javafx;
+
+import java.io.IOException;
+import java.util.Collections;
+
+import javafx.collections.FXCollections;
+import javafx.collections.ObservableList;
+import javafx.fxml.FXML;
+import javafx.fxml.FXMLLoader;
+import javafx.geometry.Pos;
+import javafx.scene.Node;
+import javafx.scene.control.Label;
+import javafx.scene.image.Image;
+import javafx.scene.image.ImageView;
+import javafx.scene.layout.HBox;
+
+/**
+ * An example of a custom control using FXML.
+ * This control represents a dialog box consisting of an ImageView to represent the speaker's face and a label
+ * containing text from the speaker.
+ */
+public class DialogBox extends HBox {
+ @FXML
+ private Label dialog;
+ @FXML
+ private ImageView displayPicture;
+
+ private DialogBox(String text, Image img) {
+ try {
+ FXMLLoader fxmlLoader = new FXMLLoader(MainWindow.class.getResource("/view/DialogBox.fxml"));
+ fxmlLoader.setController(this);
+ fxmlLoader.setRoot(this);
+ fxmlLoader.load();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ dialog.setText(text);
+ displayPicture.setImage(img);
+ }
+
+ /**
+ * Flips the dialog box such that the ImageView is on the left and text on the right.
+ */
+ private void flip() {
+ ObservableList tmp = FXCollections.observableArrayList(this.getChildren());
+ Collections.reverse(tmp);
+ getChildren().setAll(tmp);
+ setAlignment(Pos.TOP_LEFT);
+ }
+
+ public static DialogBox getUserDialog(String text, Image img) {
+ return new DialogBox(text, img);
+ }
+
+ public static DialogBox getDukeDialog(String text, Image img) {
+ var db = new DialogBox(text, img);
+ db.flip();
+ return db;
+ }
+}
diff --git a/src/main/java/duke/javafx/Launcher.java b/src/main/java/duke/javafx/Launcher.java
new file mode 100644
index 0000000000..6fb0c74906
--- /dev/null
+++ b/src/main/java/duke/javafx/Launcher.java
@@ -0,0 +1,14 @@
+package duke.javafx;
+
+import javafx.application.Application;
+
+/**
+ * A launcher class to workaround classpath issues.
+ */
+public class Launcher {
+
+ public static void main(String[] args) {
+ Application.launch(Main.class, args);
+ }
+
+}
diff --git a/src/main/java/duke/javafx/Main.java b/src/main/java/duke/javafx/Main.java
new file mode 100644
index 0000000000..b76ff75c99
--- /dev/null
+++ b/src/main/java/duke/javafx/Main.java
@@ -0,0 +1,32 @@
+package duke.javafx;
+
+import java.io.IOException;
+
+import duke.Duke;
+import javafx.application.Application;
+import javafx.fxml.FXMLLoader;
+import javafx.scene.Scene;
+import javafx.scene.layout.AnchorPane;
+import javafx.stage.Stage;
+
+/**
+ * A GUI for Duke using FXML.
+ */
+public class Main extends Application {
+
+ private Duke duke = new Duke();
+
+ @Override
+ public void start(Stage stage) {
+ try {
+ FXMLLoader fxmlLoader = new FXMLLoader(Main.class.getResource("/view/MainWindow.fxml"));
+ AnchorPane ap = fxmlLoader.load();
+ Scene scene = new Scene(ap);
+ stage.setScene(scene);
+ fxmlLoader.getController().setDuke(duke);
+ stage.show();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/main/java/duke/javafx/MainWindow.java b/src/main/java/duke/javafx/MainWindow.java
new file mode 100644
index 0000000000..6576550919
--- /dev/null
+++ b/src/main/java/duke/javafx/MainWindow.java
@@ -0,0 +1,54 @@
+package duke.javafx;
+
+import duke.Duke;
+import javafx.fxml.FXML;
+import javafx.scene.control.Button;
+import javafx.scene.control.ScrollPane;
+import javafx.scene.control.TextField;
+import javafx.scene.image.Image;
+import javafx.scene.layout.AnchorPane;
+import javafx.scene.layout.VBox;
+
+/**
+ * Controller for MainWindow. Provides the layout for the other controls.
+ */
+public class MainWindow extends AnchorPane {
+ @FXML
+ private ScrollPane scrollPane;
+ @FXML
+ private VBox dialogContainer;
+ @FXML
+ private TextField userInput;
+ @FXML
+ private Button sendButton;
+
+ private Duke duke;
+
+ private Image userImage = new Image(this.getClass().getResourceAsStream("/images/Frisk.png"));
+ private Image dukeImage = new Image(this.getClass().getResourceAsStream("/images/Mettaton.png"));
+
+ @FXML
+ public void initialize() {
+ scrollPane.vvalueProperty().bind(dialogContainer.heightProperty());
+ }
+
+ public void setDuke(Duke d) {
+ duke = d;
+ dialogContainer.getChildren().add(DialogBox.getDukeDialog("Hi! What can I do for you?", dukeImage));
+ }
+
+ /**
+ * Creates two dialog boxes, one echoing user input and the other containing Duke's reply and then appends them to
+ * the dialog container. Clears the user input after processing.
+ */
+ @FXML
+ private void handleUserInput() {
+ String input = userInput.getText();
+ String response = duke.getResponse(input);
+ dialogContainer.getChildren().addAll(
+ DialogBox.getUserDialog(input, userImage),
+ DialogBox.getDukeDialog(response, dukeImage)
+ );
+ userInput.clear();
+ }
+}
diff --git a/src/main/java/duke/storage/Storage.java b/src/main/java/duke/storage/Storage.java
new file mode 100644
index 0000000000..495ac3026d
--- /dev/null
+++ b/src/main/java/duke/storage/Storage.java
@@ -0,0 +1,216 @@
+package duke.storage;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.InputMismatchException;
+
+import duke.DukeException;
+import duke.Parser;
+import duke.task.DeadlineTask;
+import duke.task.EventTask;
+import duke.task.Task;
+import duke.task.TodoTask;
+
+/**
+ * Used to read and write data between Duke and a local file.
+ */
+public class Storage {
+
+ private String filePath;
+
+ /**
+ * Creates an instance of Storage with a user specified file path.
+ *
+ * @param filePath The location of the file to read from and write to.
+ */
+ public Storage(String filePath) {
+ this.filePath = filePath;
+ }
+
+ /**
+ * Creates an instance of Storage with a default file path. A file will be created in the location if it does not
+ * exist.
+ */
+ public Storage() {
+ this.filePath = "data/data.txt";
+ }
+
+ /**
+ * Reads from an entire text file.
+ *
+ * @return The contents of the text file as a single string.
+ * @throws IOException if the file cannot be located or read from.
+ */
+ public String readFromFile() throws IOException {
+ BufferedReader reader = new BufferedReader(new FileReader(filePath));
+ StringBuilder outputMessage = new StringBuilder();
+ String line = reader.readLine();
+ while (line != null) {
+ outputMessage.append(line);
+ outputMessage.append("\n");
+ line = reader.readLine();
+ }
+ reader.close();
+ return outputMessage.toString();
+ }
+
+ /**
+ * Updates the filepath for storage to read from.
+ *
+ * @param path New filepath to read from.
+ */
+ public void setFilePath(String path) {
+ filePath = path;
+ }
+
+ /**
+ * Replaces the file's content with an input string.
+ *
+ * @param content Contents used to overwrite the file.
+ * @throws IOException if the file cannot be located or written to.
+ */
+ public void writeToFile(String content) throws IOException {
+ BufferedWriter writer = new BufferedWriter(new FileWriter(filePath));
+ writer.write(content);
+ writer.close();
+ }
+
+ /**
+ * Reads a single line from the file.
+ *
+ * @param lineNum The line number to read from. The first line is line 1.
+ * @return The contents of the specified line.
+ * @throws IOException if the file cannot be located or read from.
+ */
+ public String readLine(int lineNum) throws IOException {
+ BufferedReader reader = new BufferedReader(new FileReader(filePath));
+ String line = "INIT";
+ int counter = 0;
+ while (line != null) {
+ counter++;
+ line = reader.readLine();
+ if (counter == lineNum) {
+ return line;
+ }
+ }
+ reader.close();
+ return null;
+ }
+
+ /**
+ * Overwrites a single line in the file with the provided contents.
+ *
+ * @param content The new content to overwrite the line.
+ * @param lineNum The line number to overwrite.
+ * @return true if the line exists, false otherwise.
+ * @throws IOException if the file cannot be located, read from or written to.
+ */
+ public boolean editLine(String content, int lineNum) throws IOException {
+ BufferedReader reader = new BufferedReader(new FileReader(filePath));
+ StringBuilder outputMessage = new StringBuilder();
+ String line = reader.readLine();
+ int counter = 0;
+ while (line != null) {
+ counter++;
+ if (counter == lineNum) {
+ outputMessage.append(content);
+ } else {
+ outputMessage.append(line);
+ }
+ outputMessage.append("\n");
+ line = reader.readLine();
+ }
+ reader.close();
+ writeToFile(outputMessage.toString());
+ return lineNum <= counter;
+ }
+
+ /**
+ * Adds a new line with contents to the end of the file.
+ *
+ * @param content Contents to be added to the end of the file.
+ * @throws IOException if the file cannot be located, read from or written to.
+ */
+ public void addLine(String content) throws IOException {
+ String fileContent = readFromFile();
+ fileContent += content + "\n";
+ writeToFile(fileContent);
+ }
+
+ /**
+ * Load up a list of tasks from the file into Duke when he starts up.
+ *
+ * @return An ArrayList of tasks specified by the file.
+ * @throws IOException if the file cannot be located or read from.
+ */
+ public ArrayList load() throws IOException {
+ //@@author tin-jy-reused
+ //Reused from https://github.com/nus-cs2103-AY2223S1/ip/pull/75/files#diff-fc0329f0e80ed7375e64928e3f814aadfc17888a375a110d013704f9cbdfc7d7
+ //with minor modifications
+ File dataStorage = new File(filePath);
+ new File("data").mkdir();
+ try {
+ dataStorage.createNewFile();
+ } catch (IOException e) {
+ throw new DukeException("Unable to create storage file");
+ }
+
+ try {
+ String line = readLine(1);
+ int lineNum = 1;
+ ArrayList listOfTasks = new ArrayList<>();
+ while (line != null) {
+ Task task;
+ if (line.charAt(1) == 'D') {
+ int index = line.indexOf('|');
+ String taskName = line.substring(7, index - 1);
+ String date = line.substring(index + 2, index + 13);
+ date = Parser.parseWordDate(date);
+ if (line.length() > index + 13) {
+ String time = line.substring(index + 14);
+ task = new DeadlineTask(taskName, date, time);
+ } else {
+ task = new DeadlineTask(taskName, date);
+ }
+ } else if (line.charAt(1) == 'E') {
+ int index = line.indexOf('|');
+ String taskName = line.substring(7, index - 1);
+ String date = line.substring(index + 2, index + 13);
+ date = Parser.parseWordDate(date);
+ if (line.length() > index + 13) {
+ String time = line.substring(index + 14);
+ task = new EventTask(taskName, date, time);
+ } else {
+ task = new EventTask(taskName, date);
+ }
+ } else if (line.charAt(1) == 'T') {
+ String taskName = line.substring(7);
+ task = new TodoTask(taskName);
+ } else {
+ throw new InputMismatchException();
+ }
+ if (line.charAt(4) == '1') {
+ task.markComplete();
+ }
+ listOfTasks.add(task);
+ lineNum++;
+ line = readLine(lineNum);
+ }
+ return listOfTasks;
+ } catch (FileNotFoundException e) {
+ System.out.println("No file found to read from");
+ } catch (IOException e) {
+ System.out.println("Unknown IO Exception");
+ } catch (NullPointerException | InputMismatchException e) {
+ System.out.println("Input file format not recognised");
+ }
+ return new ArrayList<>();
+ }
+
+}
diff --git a/src/main/java/duke/task/DeadlineTask.java b/src/main/java/duke/task/DeadlineTask.java
new file mode 100644
index 0000000000..38ec7411ff
--- /dev/null
+++ b/src/main/java/duke/task/DeadlineTask.java
@@ -0,0 +1,83 @@
+package duke.task;
+
+import java.time.LocalDateTime;
+
+import duke.Parser;
+
+/**
+ * Represents a task that is to be completed by a deadline.
+ */
+
+public class DeadlineTask extends Task {
+
+ private final LocalDateTime deadline;
+ private final boolean hasTime;
+
+ /**
+ * Creates a new task with a description and a deadline.
+ *
+ * @param description Task that needs to be done.
+ * @param date Date which task should be done by.
+ */
+ public DeadlineTask(String description, String date) {
+ super(description);
+ int day = Integer.parseInt(date.substring(0, 2));
+ int month = Integer.parseInt(date.substring(2, 4));
+ int year = Integer.parseInt(date.substring(4));
+ deadline = LocalDateTime.of(year, month, day, 0, 0);
+ hasTime = false;
+ }
+
+ /**
+ * Creates a new task with a description and a deadline.
+ *
+ * @param description Task that needs to be done.
+ * @param date Date which task should be done by, in ddmmyyyy format.
+ * @param time Time which task should be done by in 24-hour format.
+ */
+ public DeadlineTask(String description, String date, String time) {
+ super(description);
+ int day = Integer.parseInt(date.substring(0, 2));
+ int month = Integer.parseInt(date.substring(2, 4));
+ int year = Integer.parseInt(date.substring(4));
+ int hour = Integer.parseInt(time.substring(0, 2));
+ int minute = Integer.parseInt(time.substring(2, 4));
+ deadline = LocalDateTime.of(year, month, day, hour, minute);
+ hasTime = true;
+ }
+
+ /**
+ * Returns a string representation of the task.
+ *
+ * @return String representation of the task.
+ */
+ @Override
+ public String toString() {
+ int completed = 0;
+ if (isCompleted()) {
+ completed = 1;
+ }
+ String wordMonth = Parser.intToWordMonth(deadline.getMonth().getValue());
+ String wordDay = String.valueOf(deadline.getDayOfMonth());
+ if (deadline.getDayOfMonth() < 10) {
+ wordDay = "0" + wordDay;
+ }
+ String wordMinute = String.valueOf(deadline.getMinute());
+ if (deadline.getMinute() < 10) {
+ wordMinute = "0" + wordMinute;
+ }
+ String wordHour = String.valueOf(deadline.getHour());
+ if (deadline.getHour() < 10) {
+ wordHour = "0" + wordHour;
+ }
+ if (hasTime) {
+ return String.format("[D][%d] %s | %s %s %d %s%s", completed, getTaskDescription(),
+ wordDay, wordMonth, deadline.getYear(),
+ wordHour, wordMinute);
+ } else {
+ return String.format("[D][%d] %s | %s %s %d", completed, getTaskDescription(),
+ wordDay, wordMonth, deadline.getYear());
+ }
+ }
+
+}
diff --git a/src/main/java/duke/task/EventTask.java b/src/main/java/duke/task/EventTask.java
new file mode 100644
index 0000000000..fc541b65db
--- /dev/null
+++ b/src/main/java/duke/task/EventTask.java
@@ -0,0 +1,82 @@
+package duke.task;
+
+import java.time.LocalDateTime;
+
+import duke.Parser;
+
+/**
+ * Represents a task that will occur at a certain time.
+ */
+public class EventTask extends Task {
+
+ private final LocalDateTime datetime;
+ private final boolean hasTime;
+
+ /**
+ * Creates a new task that will occur at a certain time.
+ *
+ * @param description Task that needs to be done.
+ * @param date Date on which task will occur.
+ */
+ public EventTask(String description, String date) {
+ super(description);
+ int day = Integer.parseInt(date.substring(0, 2));
+ int month = Integer.parseInt(date.substring(2, 4));
+ int year = Integer.parseInt(date.substring(4));
+ datetime = LocalDateTime.of(year, month, day, 0, 0);
+ hasTime = false;
+ }
+
+ /**
+ * Creates a new task that will occur at a certain time.
+ *
+ * @param description Task that needs to be done.
+ * @param date Date on which task will occur.
+ * @param time Time at which task will occur.
+ */
+ public EventTask(String description, String date, String time) {
+ super(description);
+ int day = Integer.parseInt(date.substring(0, 2));
+ int month = Integer.parseInt(date.substring(2, 4));
+ int year = Integer.parseInt(date.substring(4));
+ int hour = Integer.parseInt(time.substring(0, 2));
+ int minute = Integer.parseInt(time.substring(2, 4));
+ datetime = LocalDateTime.of(year, month, day, hour, minute);
+ hasTime = true;
+ }
+
+ /**
+ * Returns a string representation of the task.
+ *
+ * @return String representation of the task.
+ */
+ @Override
+ public String toString() {
+ int completed = 0;
+ if (isCompleted()) {
+ completed = 1;
+ }
+ String wordMonth = Parser.intToWordMonth(datetime.getMonth().getValue());
+ String wordDay = String.valueOf(datetime.getDayOfMonth());
+ if (datetime.getDayOfMonth() < 10) {
+ wordDay = "0" + wordDay;
+ }
+ String wordMinute = String.valueOf(datetime.getMinute());
+ if (datetime.getMinute() < 10) {
+ wordMinute = "0" + wordMinute;
+ }
+ String wordHour = String.valueOf(datetime.getHour());
+ if (datetime.getHour() < 10) {
+ wordHour = "0" + wordHour;
+ }
+ if (hasTime) {
+ return String.format("[E][%d] %s | %s %s %d %s%s", completed, getTaskDescription(),
+ wordDay, wordMonth, datetime.getYear(),
+ wordHour, wordMinute);
+ } else {
+ return String.format("[E][%d] %s | %s %s %d", completed, getTaskDescription(),
+ wordDay, wordMonth, datetime.getYear());
+ }
+ }
+
+}
diff --git a/src/main/java/duke/task/Task.java b/src/main/java/duke/task/Task.java
new file mode 100644
index 0000000000..1d923ec43c
--- /dev/null
+++ b/src/main/java/duke/task/Task.java
@@ -0,0 +1,52 @@
+package duke.task;
+
+/**
+ * Represents a task.
+ */
+public abstract class Task {
+ private final String taskDescription;
+ private boolean isCompleted;
+
+ /**
+ * Creates a new task with a description.
+ *
+ * @param description Task that needs to be done.
+ */
+ public Task(String description) {
+ taskDescription = description;
+ isCompleted = false;
+ }
+
+ /**
+ * Returns the task description.
+ *
+ * @return The task description.
+ */
+ public String getTaskDescription() {
+ return taskDescription;
+ }
+
+ /**
+ * Marks the task as complete.
+ */
+ public void markComplete() {
+ isCompleted = true;
+ }
+
+ /**
+ * Marks the task as incomplete.
+ */
+ public void markIncomplete() {
+ isCompleted = false;
+ }
+
+ /**
+ * Returns whether the task has been completed
+ *
+ * @return true if the task is completed, false otherwise.
+ */
+ public boolean isCompleted() {
+ return isCompleted;
+ }
+
+}
diff --git a/src/main/java/duke/task/TodoTask.java b/src/main/java/duke/task/TodoTask.java
new file mode 100644
index 0000000000..64b5a19893
--- /dev/null
+++ b/src/main/java/duke/task/TodoTask.java
@@ -0,0 +1,31 @@
+package duke.task;
+
+/**
+ * Represents a task without a date or time.
+ */
+public class TodoTask extends Task {
+
+ /**
+ * Creates a new task without a date or time.
+ *
+ * @param description Task that needs to be done.
+ */
+ public TodoTask(String description) {
+ super(description);
+ }
+
+ /**
+ * Returns a string representation of the task.
+ *
+ * @return String representation of the task.
+ */
+ @Override
+ public String toString() {
+ if (isCompleted()) {
+ return String.format("[T][1] %s", getTaskDescription());
+ } else {
+ return String.format("[T][0] %s", getTaskDescription());
+ }
+ }
+
+}
diff --git a/src/main/resources/images/DaDuke.png b/src/main/resources/images/DaDuke.png
new file mode 100644
index 0000000000..d893658717
Binary files /dev/null and b/src/main/resources/images/DaDuke.png differ
diff --git a/src/main/resources/images/DaUser.png b/src/main/resources/images/DaUser.png
new file mode 100644
index 0000000000..3c82f45461
Binary files /dev/null and b/src/main/resources/images/DaUser.png differ
diff --git a/src/main/resources/images/Frisk.png b/src/main/resources/images/Frisk.png
new file mode 100644
index 0000000000..109ebc60ee
Binary files /dev/null and b/src/main/resources/images/Frisk.png differ
diff --git a/src/main/resources/images/Mettaton.png b/src/main/resources/images/Mettaton.png
new file mode 100644
index 0000000000..a6b15ece88
Binary files /dev/null and b/src/main/resources/images/Mettaton.png differ
diff --git a/src/main/resources/view/DialogBox.fxml b/src/main/resources/view/DialogBox.fxml
new file mode 100644
index 0000000000..e433809947
--- /dev/null
+++ b/src/main/resources/view/DialogBox.fxml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/resources/view/MainWindow.fxml b/src/main/resources/view/MainWindow.fxml
new file mode 100644
index 0000000000..84c540a154
--- /dev/null
+++ b/src/main/resources/view/MainWindow.fxml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/test/java/duke/TaskListTest.java b/src/test/java/duke/TaskListTest.java
new file mode 100644
index 0000000000..6fe7ac764b
--- /dev/null
+++ b/src/test/java/duke/TaskListTest.java
@@ -0,0 +1,66 @@
+package duke;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Test;
+
+import duke.task.DeadlineTask;
+import duke.task.EventTask;
+import duke.task.TodoTask;
+
+public class TaskListTest {
+
+ @Test
+ public void addTest1() {
+ TaskList taskList = new TaskList();
+ taskList.add(new TodoTask("Task 1"));
+ int actual = taskList.size();
+ int expected = 1;
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void addTest2() {
+ TaskList taskList = new TaskList();
+ taskList.add(new TodoTask("Task 1"));
+ taskList.add(new TodoTask("Task 2"));
+ taskList.add(new TodoTask("Task 3"));
+ int actual = taskList.size();
+ int expected = 3;
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void listTest1() {
+ TaskList taskList = new TaskList();
+ String actual = taskList.list();
+ String expected = "No tasks yet";
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void listTest2() {
+ TaskList taskList = new TaskList();
+ taskList.add(new TodoTask("Task 1"));
+ taskList.add(new DeadlineTask("Task 2", "13072000"));
+ taskList.add(new EventTask("Task 3", "01012022", "1234"));
+ taskList.mark(3);
+ String actual = taskList.list();
+ String expected = "[T][0] Task 1\n[D][0] Task 2 | 13 Jul 2000\n[E][1] Task 3 | 01 Jan 2022 1234";
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void markTest() {
+ TaskList taskList = new TaskList();
+ taskList.add(new TodoTask("Task 1"));
+ taskList.add(new DeadlineTask("Task 2", "13072000"));
+ taskList.add(new EventTask("Task 3", "01012022", "1234"));
+ taskList.mark(1);
+ boolean actual = taskList.getTask(1).isCompleted();
+ boolean expected = true;
+ assertEquals(expected, actual);
+ }
+
+
+}
diff --git a/src/test/java/duke/task/DeadlineTaskTest.java b/src/test/java/duke/task/DeadlineTaskTest.java
new file mode 100644
index 0000000000..764f381d54
--- /dev/null
+++ b/src/test/java/duke/task/DeadlineTaskTest.java
@@ -0,0 +1,16 @@
+package duke.task;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Test;
+
+public class DeadlineTaskTest {
+
+ @Test
+ public void toStringTest() {
+ String actual = new DeadlineTask("CS2103", "16092022", "2359").toString();
+ String expected = "[D][0] CS2103 | 16 Sep 2022 2359";
+ assertEquals(expected, actual);
+ }
+
+}
diff --git a/src/test/java/duke/task/EventTaskTest.java b/src/test/java/duke/task/EventTaskTest.java
new file mode 100644
index 0000000000..fdc4739f23
--- /dev/null
+++ b/src/test/java/duke/task/EventTaskTest.java
@@ -0,0 +1,16 @@
+package duke.task;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Test;
+
+public class EventTaskTest {
+
+ @Test
+ public void toStringTest() {
+ String actual = new EventTask("Meeting", "16092022", "1500").toString();
+ String expected = "[E][0] Meeting | 16 Sep 2022 1500";
+ assertEquals(expected, actual);
+ }
+
+}
diff --git a/src/test/java/duke/task/TaskTest.java b/src/test/java/duke/task/TaskTest.java
new file mode 100644
index 0000000000..2a05cc1c52
--- /dev/null
+++ b/src/test/java/duke/task/TaskTest.java
@@ -0,0 +1,35 @@
+package duke.task;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Test;
+
+public class TaskTest {
+
+ @Test
+ public void getTaskDescriptionTest() {
+ String actual = new TodoTask("CS2103").getTaskDescription();
+ String expected = "CS2103";
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void markCompleteTest() {
+ Task task = new TodoTask("CS2103");
+ task.markComplete();
+ boolean actual = task.isCompleted();
+ boolean expected = true;
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void markIncompleteTest() {
+ Task task = new TodoTask("CS2103");
+ task.markComplete();
+ task.markIncomplete();
+ boolean actual = task.isCompleted();
+ boolean expected = false;
+ assertEquals(expected, actual);
+ }
+
+}
diff --git a/src/test/java/duke/task/TodoTaskTest.java b/src/test/java/duke/task/TodoTaskTest.java
new file mode 100644
index 0000000000..db6ea4daa9
--- /dev/null
+++ b/src/test/java/duke/task/TodoTaskTest.java
@@ -0,0 +1,16 @@
+package duke.task;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Test;
+
+public class TodoTaskTest {
+
+ @Test
+ public void toStringTest() {
+ String actual = "[T][0] CS2103";
+ String expected = (new TodoTask("CS2103")).toString();
+ assertEquals(expected, actual);
+ }
+
+}
diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT
index 657e74f6e7..5c7d1206b8 100644
--- a/text-ui-test/EXPECTED.TXT
+++ b/text-ui-test/EXPECTED.TXT
@@ -1,7 +1,18 @@
-Hello from
- ____ _
-| _ \ _ _| | _____
-| | | | | | | |/ / _ \
-| |_| | |_| | < __/
-|____/ \__,_|_|\_\___|
-
+Hi, I'm Duke. What can I do for you?
+Added new deadline task:
+[D][0] CS2103 | 16 Sep 2022 2359
+Added new deadline task:
+[D][0] pack | 8 Sep 2022
+Added new event task:
+[E][0] cca | 7 Sep 2022 1900
+[D][0] CS2103 | 16 Sep 2022 2359
+[D][0] pack | 8 Sep 2022
+[E][0] cca | 7 Sep 2022 1900
+I've marked this task as complete:
+[E][1] cca | 7 Sep 2022 1900
+No such task!
+I've deleted this task:
+[D][0] pack | 8 Sep 2022
+[D][0] CS2103 | 16 Sep 2022 2359
+[E][0] cca | 7 Sep 2022 1900
+Bye!
\ No newline at end of file
diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt
index e69de29bb2..b7a734e3a5 100644
--- a/text-ui-test/input.txt
+++ b/text-ui-test/input.txt
@@ -0,0 +1,9 @@
+deadline CS2103 /by 16-9-2022 2359
+deadline pack /by 8-9-2022
+event cca /at 7-9-2022 1900
+list
+mark 3
+delete 4
+delete 2
+list
+bye
\ No newline at end of file
diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat
index 0873744649..7b91c38286 100644
--- a/text-ui-test/runtest.bat
+++ b/text-ui-test/runtest.bat
@@ -1,4 +1,4 @@
-@ECHO OFF
+ @ECHO OFF
REM create bin directory if it doesn't exist
if not exist ..\bin mkdir ..\bin
diff --git a/text-ui-test/runtest.sh b/text-ui-test/runtest.sh
old mode 100644
new mode 100755