diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000000..7906c2e9dd --- /dev/null +++ b/build.gradle @@ -0,0 +1,53 @@ +plugins { + id 'java' + id 'application' + id 'checkstyle' + id 'com.github.johnrengelman.shadow' version '5.1.0' +} + +shadowJar { + archiveBaseName = "duke" + archiveVersion = "0.1.4" + archiveClassifier = null + archiveAppendix = null +} + +checkstyle { + toolVersion = '8.23' +} + +group 'seedu.duke' //need change here also or not +version '0.1.0' + +repositories { + mavenCentral() +} + +dependencies { + testImplementation 'org.junit.jupiter:junit-jupiter: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' + implementation group: 'org.openjfx', name: 'javafx-media', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-media', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-media', version: javaFxVersion, classifier: 'linux' +} + +test { + useJUnitPlatform() +} + +application { + // Change this to your main class. + mainClassName = "Launcher" +} diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml new file mode 100644 index 0000000000..b1a57ba6c0 --- /dev/null +++ b/config/checkstyle/checkstyle.xml @@ -0,0 +1,257 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/savedTasks.txt b/data/savedTasks.txt new file mode 100644 index 0000000000..965e558c6c --- /dev/null +++ b/data/savedTasks.txt @@ -0,0 +1,5 @@ +D | 1 | submit | 11/10/2019 1500 +T | 0 | finish work +T | 1 | make project +E | 0 | attend lec | 12/12/0012 1212 +T | 1 | Learn python diff --git a/docs/README.md b/docs/README.md index fd44069597..5f04a3349f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,20 +1,67 @@ # User Guide -## Features +## Introduction +Welcome to Duke User Guide. This application allows user to manage their daily tasks via +**Command Line Interface (CLI)** and through a friendly **Graphical User Interface (GUI)**. +The application comes with the feature to add tasks, mark task as done and much more! -### Feature 1 -Description of feature. +## How to get Started +1. Ensure your computer has `Java 11` version for compatibility to run the program. Otherwise, you can download it from + [here](https://www.oracle.com/technetwork/java/javase/downloads/jdk11-downloads-5066655.html). +1. After download the latest release version of the `Duke.jar` [here](https://github.com/ArgVampir/duke/releases). +1. Open terminal and `cd` to the path of the downloaded jar. Execute the command `java -jar duke.jar`. -## Usage +## Features -### `Keyword` - Describe action +### 1. View all tasks: **`list`** +Type `list` to view the list -Describe action and its outcome. +### 2. Add a new task: **`todo`**, **`event`**, **`deadline`** -Example of usage: +#### There are 3 types of tasks you can add into Duke: +1. `todo` task - A to-do task that only need description + Type `todo ` to add todo task +2. `deadline` task - A deadline to meet which requires a description and datetime. + Type `deadline /by ` to add deadline task +3. `event` task - An event requires the description and datetime + Type `event /at ` to event task + +**Examples:** +- `todo borrow book` +- `deadline Assignment#2 /by 23/11/2019 2359` +- `event Career Fair /at 15/3/2020 1800` -`keyword (optional arguments)` +### 3. Find task using a keyword: **`find`** +Type `find ` to find task related to keyword -Expected outcome: +**Examples** +1. `find homework` +2. `find art exhibition` -`outcome` +### 4. Mark task as done: **`done`** +Type `done `to mark particular task as finish + + +### 5. Delete task: **`delete`** +Type `delete ` to delete particular task from the task list + + +### 6. Sort the tasks: **`sort`** + +#### There are 3 types of sorts: + +1. `sort todo` sorts the task list displaying the todo first + +2. `sort deadline` sort the task list displaying the deadline first + +3. `sort event` sort the task list displaying the event first + + +### 7. Farewell to Duke: **`bye`** +type `bye` to make a farewell + + +## Additional Notes + +- Keep in mind that the commands are **case-sensitive** +- Date format needs to be follow strictly diff --git a/docs/Ui.png b/docs/Ui.png new file mode 100644 index 0000000000..ad6b28fe56 Binary files /dev/null and b/docs/Ui.png differ diff --git a/docs/_config.yml b/docs/_config.yml new file mode 100644 index 0000000000..3397c9a492 --- /dev/null +++ b/docs/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-architect \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000..87b738cbd0 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..e689992845 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Thu Sep 05 20:04:31 SGT 2019 +distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-all.zip +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStorePath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew new file mode 100755 index 0000000000..af6708ff22 --- /dev/null +++ b/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## 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"' + +# 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, switch paths to Windows format before running java +if $cygwin ; 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=$((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" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000000..6d57edc706 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,84 @@ +@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 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" + +@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/lib/apiguardian-api-1.0.0-javadoc.jar b/lib/apiguardian-api-1.0.0-javadoc.jar new file mode 100644 index 0000000000..42d7d6aa64 Binary files /dev/null and b/lib/apiguardian-api-1.0.0-javadoc.jar differ diff --git a/lib/apiguardian-api-1.0.0-sources.jar b/lib/apiguardian-api-1.0.0-sources.jar new file mode 100644 index 0000000000..297363ec8a Binary files /dev/null and b/lib/apiguardian-api-1.0.0-sources.jar differ diff --git a/lib/apiguardian-api-1.0.0.jar b/lib/apiguardian-api-1.0.0.jar new file mode 100644 index 0000000000..6cbff70f22 Binary files /dev/null and b/lib/apiguardian-api-1.0.0.jar differ diff --git a/lib/junit-jupiter-5.4.2-javadoc.jar b/lib/junit-jupiter-5.4.2-javadoc.jar new file mode 100644 index 0000000000..f31885d910 Binary files /dev/null and b/lib/junit-jupiter-5.4.2-javadoc.jar differ diff --git a/lib/junit-jupiter-5.4.2-sources.jar b/lib/junit-jupiter-5.4.2-sources.jar new file mode 100644 index 0000000000..f31885d910 Binary files /dev/null and b/lib/junit-jupiter-5.4.2-sources.jar differ diff --git a/lib/junit-jupiter-5.4.2.jar b/lib/junit-jupiter-5.4.2.jar new file mode 100644 index 0000000000..b3bf697621 Binary files /dev/null and b/lib/junit-jupiter-5.4.2.jar differ diff --git a/lib/junit-jupiter-api-5.4.2-javadoc.jar b/lib/junit-jupiter-api-5.4.2-javadoc.jar new file mode 100644 index 0000000000..ebb65fd422 Binary files /dev/null and b/lib/junit-jupiter-api-5.4.2-javadoc.jar differ diff --git a/lib/junit-jupiter-api-5.4.2-sources.jar b/lib/junit-jupiter-api-5.4.2-sources.jar new file mode 100644 index 0000000000..3cb82c7622 Binary files /dev/null and b/lib/junit-jupiter-api-5.4.2-sources.jar differ diff --git a/lib/junit-jupiter-api-5.4.2.jar b/lib/junit-jupiter-api-5.4.2.jar new file mode 100644 index 0000000000..40828b7a90 Binary files /dev/null and b/lib/junit-jupiter-api-5.4.2.jar differ diff --git a/lib/junit-jupiter-engine-5.4.2-javadoc.jar b/lib/junit-jupiter-engine-5.4.2-javadoc.jar new file mode 100644 index 0000000000..14955d409c Binary files /dev/null and b/lib/junit-jupiter-engine-5.4.2-javadoc.jar differ diff --git a/lib/junit-jupiter-engine-5.4.2-sources.jar b/lib/junit-jupiter-engine-5.4.2-sources.jar new file mode 100644 index 0000000000..699c3fc176 Binary files /dev/null and b/lib/junit-jupiter-engine-5.4.2-sources.jar differ diff --git a/lib/junit-jupiter-engine-5.4.2.jar b/lib/junit-jupiter-engine-5.4.2.jar new file mode 100644 index 0000000000..3444a9806a Binary files /dev/null and b/lib/junit-jupiter-engine-5.4.2.jar differ diff --git a/lib/junit-jupiter-params-5.4.2-javadoc.jar b/lib/junit-jupiter-params-5.4.2-javadoc.jar new file mode 100644 index 0000000000..0cfed785e4 Binary files /dev/null and b/lib/junit-jupiter-params-5.4.2-javadoc.jar differ diff --git a/lib/junit-jupiter-params-5.4.2-sources.jar b/lib/junit-jupiter-params-5.4.2-sources.jar new file mode 100644 index 0000000000..c654f4083e Binary files /dev/null and b/lib/junit-jupiter-params-5.4.2-sources.jar differ diff --git a/lib/junit-jupiter-params-5.4.2.jar b/lib/junit-jupiter-params-5.4.2.jar new file mode 100644 index 0000000000..ee5650412e Binary files /dev/null and b/lib/junit-jupiter-params-5.4.2.jar differ diff --git a/lib/junit-platform-commons-1.4.2-javadoc.jar b/lib/junit-platform-commons-1.4.2-javadoc.jar new file mode 100644 index 0000000000..a470d7ec0e Binary files /dev/null and b/lib/junit-platform-commons-1.4.2-javadoc.jar differ diff --git a/lib/junit-platform-commons-1.4.2-sources.jar b/lib/junit-platform-commons-1.4.2-sources.jar new file mode 100644 index 0000000000..37e4b89b5b Binary files /dev/null and b/lib/junit-platform-commons-1.4.2-sources.jar differ diff --git a/lib/junit-platform-commons-1.4.2.jar b/lib/junit-platform-commons-1.4.2.jar new file mode 100644 index 0000000000..270552518e Binary files /dev/null and b/lib/junit-platform-commons-1.4.2.jar differ diff --git a/lib/junit-platform-engine-1.4.2-javadoc.jar b/lib/junit-platform-engine-1.4.2-javadoc.jar new file mode 100644 index 0000000000..3cab8e0553 Binary files /dev/null and b/lib/junit-platform-engine-1.4.2-javadoc.jar differ diff --git a/lib/junit-platform-engine-1.4.2-sources.jar b/lib/junit-platform-engine-1.4.2-sources.jar new file mode 100644 index 0000000000..2f487c5105 Binary files /dev/null and b/lib/junit-platform-engine-1.4.2-sources.jar differ diff --git a/lib/junit-platform-engine-1.4.2.jar b/lib/junit-platform-engine-1.4.2.jar new file mode 100644 index 0000000000..2c46ae92d3 Binary files /dev/null and b/lib/junit-platform-engine-1.4.2.jar differ diff --git a/lib/opentest4j-1.1.1-javadoc.jar b/lib/opentest4j-1.1.1-javadoc.jar new file mode 100644 index 0000000000..dadc6af164 Binary files /dev/null and b/lib/opentest4j-1.1.1-javadoc.jar differ diff --git a/lib/opentest4j-1.1.1-sources.jar b/lib/opentest4j-1.1.1-sources.jar new file mode 100644 index 0000000000..7cb1de75d0 Binary files /dev/null and b/lib/opentest4j-1.1.1-sources.jar differ diff --git a/lib/opentest4j-1.1.1.jar b/lib/opentest4j-1.1.1.jar new file mode 100644 index 0000000000..3f355292e0 Binary files /dev/null and b/lib/opentest4j-1.1.1.jar differ diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000000..d1e92fe5db --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'duke' diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java new file mode 100644 index 0000000000..659af6368c --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,23 @@ +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class Deadline extends Task { + private Date by; + + Deadline(String description, Date by) { + super(description); + this.by = by; + } + + private DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HHmm"); + + String getBy() { + return dateFormat.format(this.by); + } + + @Override + public String toString() { + return "[D]" + super.toString() + " (by: " + dateFormat.format(this.by) + ")"; + } +} \ No newline at end of file diff --git a/src/main/java/DeadlineSort.java b/src/main/java/DeadlineSort.java new file mode 100644 index 0000000000..ccb90bb274 --- /dev/null +++ b/src/main/java/DeadlineSort.java @@ -0,0 +1,16 @@ +import java.util.Comparator; + +public class DeadlineSort implements Comparator { + + @Override + public int compare(Task t1, Task t2) { + if (!(t1 instanceof Deadline) && !(t2 instanceof Deadline)) { + return 0; + } else if (!(t1 instanceof Deadline)) { + return 1; + } else if (!(t2 instanceof Deadline)) { + return -1; + } + return ((Deadline) t1).getBy().compareTo(((Deadline) t2).getBy()); + } +} \ No newline at end of file diff --git a/src/main/java/DialogBox.java b/src/main/java/DialogBox.java new file mode 100644 index 0000000000..79598c9362 --- /dev/null +++ b/src/main/java/DialogBox.java @@ -0,0 +1,68 @@ +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); + } + + + /** + * Contains the image and message of Duke. + * + * @param text String of text to display. + * @param img Image of display photo for Duke. + * @return Flipped horizontal dialog box. + */ + + 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.java b/src/main/java/Duke.java index 5d313334cc..def68a356c 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,10 +1,37 @@ +/** + * Represents the initialisation and continuation of the program. + */ + public class Duke { - public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); + + private Ui ui; + private TaskList taskList; + private Parser parser; + + /** + * Initialises the Duke application and the storage file. + */ + + public Duke() { + ui = new Ui(); + Storage storage = new Storage("data/savedTasks.txt"); + taskList = new TaskList(storage.load()); + parser = new Parser(); + } + + /** + * Gets response when user enters an input. + * + * @param input User input for the command. + * @return response to the User input. + */ + + String getResponse(String input) { + try { + parser.parse(input, ui, taskList); + } catch (DukeException e) { + return e.getMessage(); + } + return ui.getOutput(); } } diff --git a/src/main/java/DukeException.java b/src/main/java/DukeException.java new file mode 100644 index 0000000000..f3aaf61ca7 --- /dev/null +++ b/src/main/java/DukeException.java @@ -0,0 +1,5 @@ +public class DukeException extends Exception { + public DukeException(String errorMessage) { + super(errorMessage); + } +} \ No newline at end of file diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 0000000000..75d07a8b6c --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,24 @@ +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class Event extends Task { + protected Date at; + + public Event(String description, Date at) { + super(description); + this.at = at; + } + + private DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HHmm"); + + String getAt() { + return dateFormat.format(this.at); + } + + @Override + public String toString() { + return "[E]" + super.toString() + " (at: " + dateFormat.format(this.at) + ")"; + } + +} \ No newline at end of file diff --git a/src/main/java/EventSort.java b/src/main/java/EventSort.java new file mode 100644 index 0000000000..8644587824 --- /dev/null +++ b/src/main/java/EventSort.java @@ -0,0 +1,16 @@ +import java.util.Comparator; + +public class EventSort implements Comparator { + + @Override + public int compare(Task t1, Task t2) { + if (!(t1 instanceof Event) && !(t2 instanceof Event)) { + return 0; + } else if (!(t1 instanceof Event)) { + return 1; + } else if (!(t2 instanceof Event)) { + return -1; + } + return ((Event) t1).getAt().compareTo(((Event) t2).getAt()); + } +} \ No newline at end of file diff --git a/src/main/java/Launcher.java b/src/main/java/Launcher.java new file mode 100644 index 0000000000..43d64c26fb --- /dev/null +++ b/src/main/java/Launcher.java @@ -0,0 +1,10 @@ +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/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..d2ffd5b4d2 --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: Duke + diff --git a/src/main/java/Main.java b/src/main/java/Main.java new file mode 100644 index 0000000000..02889c96fa --- /dev/null +++ b/src/main/java/Main.java @@ -0,0 +1,28 @@ +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Scene; +import javafx.scene.layout.AnchorPane; +import javafx.stage.Stage; +import java.io.IOException; + +/** + * 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(); + } + } +} \ No newline at end of file diff --git a/src/main/java/MainWindow.java b/src/main/java/MainWindow.java new file mode 100644 index 0000000000..d96f65abec --- /dev/null +++ b/src/main/java/MainWindow.java @@ -0,0 +1,52 @@ +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; +import javafx.scene.paint.ImagePattern; +import javafx.scene.shape.Circle; + +/** + * 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/DaUser.png")); + private Image dukeImage = new Image(this.getClass().getResourceAsStream("/images/DaDuke.png")); + + @FXML + public void initialize() { + scrollPane.vvalueProperty().bind(dialogContainer.heightProperty()); + } + + public void setDuke(Duke d) { + duke = d; + } + + /** + * 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(); + } +} \ No newline at end of file diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java new file mode 100644 index 0000000000..e5cf6a7768 --- /dev/null +++ b/src/main/java/Parser.java @@ -0,0 +1,142 @@ +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Collections; + +/** + * Deals with making sense of the user command. + */ + +class Parser { + + /** + * Parses the user input to execute the following intended command. + * + * @param input The user input to execute command. + * @param ui User Interface in dealing with duke. + * @param taskList Task list of the current file. + * @throws DukeException If user input is in wrong format. + */ + + void parse(String input, Ui ui, TaskList taskList) throws DukeException { + String command = input.split(" ")[0].trim(); + assert !command.isEmpty() : "Input must not be empty"; //added assert + switch (command) { + case "bye": + if (!input.substring(3).isEmpty()) { + throw new DukeException("☹ OOPS!!! Type only bye to terminate the program"); + } + ui.setToFarewell(); + break; + case "list": + if (!input.substring(4).isEmpty()) { + throw new DukeException("☹ OOPS!!! Type only list to display the Task list"); + } + ui.setToList(taskList); + break; + case "todo": + String todoDescription = input.substring(4).trim(); + if (todoDescription.isEmpty()) { + throw new DukeException("☹ OOPS!!! todo cannot be empty"); + } + Task todoTask = new Todo(todoDescription); + taskList.getTaskList().add(todoTask); + ui.setToTodo(todoTask, taskList); + Storage.saveTaskList(taskList.getTaskList()); //saves file + break; + case "deadline": + try { + String deadlineDescription = input.substring(8).trim(); + String[] deadlineArray = deadlineDescription.split("/by"); + String deadlineName = deadlineArray[0].trim(); + String deadlineBy = deadlineArray[1].trim(); + if (deadlineDescription.isEmpty() || deadlineBy.isEmpty()) { + throw new DukeException("☹ OOPS!!! deadline and time cannot be empty"); + } + SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HHmm"); + Task dlTask = new Deadline(deadlineName, sdf.parse(deadlineBy)); + taskList.getTaskList().add(dlTask); + ui.setToDeadline(dlTask, taskList); + Storage.saveTaskList(taskList.getTaskList()); //saves file + break; + } catch (ParseException e) { + throw new DukeException("☹ OOPS!!! Please insert correct time format: dd/MM/yyyy HHmm"); + } catch (Exception e) { + throw new DukeException("☹ OOPS!!! Wrong format. Use: deadline (description) /at dd/MM/yyyy HHmm"); + } + case "event": + try { + String eventDescription = input.substring(5).trim(); + String[] eventArray = eventDescription.split("/at"); + String eventName = eventArray[0].trim(); + String eventAt = eventArray[1].trim(); + if (eventDescription.isEmpty() || eventAt.isEmpty()) { + throw new DukeException("☹ OOPS!!! event and time cannot be empty"); + } + SimpleDateFormat sdf2 = new SimpleDateFormat("dd/MM/yyyy HHmm"); + Task eventTask = new Event(eventName, sdf2.parse(eventAt)); + taskList.getTaskList().add(eventTask); + ui.setToEvent(eventTask, taskList); + Storage.saveTaskList(taskList.getTaskList()); //save file + break; + } catch (ParseException e) { + throw new DukeException("☹ OOPS!!! Please insert correct time format: dd/MM/yyyy HHmm"); + } catch (Exception e) { + throw new DukeException("☹ OOPS!!! Wrong format. Use: event (description) /at dd/MM/yyyy HHmm"); + } + case "done": + try { + int taskNum = Integer.parseInt(input.substring(5).trim()); + taskList.getTaskList().get(taskNum - 1).markAsDone(); + ui.setToDone(taskNum, taskList); + Storage.saveTaskList(taskList.getTaskList()); //save file + break; + } catch (IndexOutOfBoundsException e) { + throw new DukeException("☹ OOPS!!! The task number is not in the list"); + } catch (Exception e) { + throw new DukeException("☹ OOPS!!! Wrong format. Use: done (task number)"); + } + case "delete": + try { + int taskNum2 = Integer.parseInt(input.substring(6).trim()); + ui.setToDelete(taskNum2, taskList); + taskList.getTaskList().remove(taskNum2 - 1); + Storage.saveTaskList(taskList.getTaskList()); //save file + break; + } catch (IndexOutOfBoundsException e) { + throw new DukeException("☹ OOPS!!! The task number is not in the list"); + } catch (Exception e) { + throw new DukeException("☹ OOPS!!! Wrong format. Use: delete (task number)"); + } + case "find": + try { + String findWord = input.substring(4).trim(); + ArrayList relatedTasks = new ArrayList<>(); + ui.setToFind(relatedTasks, taskList, findWord); + break; + } catch (Exception e) { + throw new DukeException("☹ OOPS!!! Wrong format. Use: delete (task number)"); + } + case "sort": + try { + String sortType = input.substring(4).trim(); + if (sortType.equals("event")) { + Collections.sort(taskList.getTaskList(), new EventSort()); + } else if (sortType.equals("deadline")) { + Collections.sort(taskList.getTaskList(), new DeadlineSort()); + } else if (sortType.equals("todo")) { + Collections.sort(taskList.getTaskList(), new TodoSort()); + } else { + throw new DukeException("☹ OOPS!!! There are only event/deadline/todo for type of sort"); + } + ui.setToSort(taskList.getTaskList(), sortType); + break; + } catch (Exception e) { + throw new DukeException("☹ OOPS!!! Your input format is wrong. Use: sort (type of sort)"); + } + default: + throw new DukeException("☹ OOPS!!! I'm sorry, but I don't know what that means :-("); + } + } +} + diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java new file mode 100644 index 0000000000..522d9e2ed9 --- /dev/null +++ b/src/main/java/Storage.java @@ -0,0 +1,142 @@ +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +/** + * Deals with loading tasks from the file and saving tasks in the file. + */ + +class Storage { + + private static File file; + + Storage(String filePath) { + file = new File(filePath); + } + + /** + * Loads a file to add tasks into taskList. + * + * @return taskList. + */ + + static ArrayList load() { + ArrayList taskList = new ArrayList<>(); + try { + Scanner sc = new Scanner(file); + while (sc.hasNext()) { + String[] task = sc.nextLine().split("\\|"); + updateData(taskList, task); + } + } catch (FileNotFoundException | ParseException e) { + System.out.println(e.getMessage()); + } + return taskList; + } + + /** + * Update the taskList that will later be loaded. + * + * @param taskList The record of tasks to be updated. + * @param task An array split into sections within the task. + */ + + private static void updateData(ArrayList taskList, String[] task) throws ParseException { + String taskType = task[0].trim(); + boolean isTaskDone = task[1].trim().equals("1"); + + switch (taskType) { + case "T": + Todo newTask = new Todo(task[2].trim()); + if (isTaskDone) { + newTask.markAsDone(); + } + taskList.add(newTask); + break; + case "E": + String eventDescription = task[2].trim(); + String at = task[3].trim(); + SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HHmm"); + Event newEvent = new Event(eventDescription, sdf.parse(at)); + if (isTaskDone) { + newEvent.markAsDone(); + } + taskList.add(newEvent); + break; + case "D": + String deadlineDescription = task[2].trim(); + String by = task[3].trim(); + SimpleDateFormat sdf2 = new SimpleDateFormat("dd/MM/yyyy HHmm"); + Deadline newDeadline = new Deadline(deadlineDescription, sdf2.parse(by)); + if (isTaskDone) { + newDeadline.markAsDone(); + } + taskList.add(newDeadline); + break; + default: + } + } + + /** + * Saves the current taskList onto the hard drive. + * + * @param taskList The record of tasks to be saved. + */ + + static void saveTaskList(List taskList) throws DukeException { + File newFile = checkFile(file); + + try { + FileWriter fw = new FileWriter(newFile); + for (Task task : taskList) { + if (task instanceof Event) { + String str = String.format("E | %s | %s | %s\n", task.isDone() ? "1" : "0", + task.getDescription(), ((Event) task).getAt()); + fw.write(str); + } else if (task instanceof Deadline) { + String str = String.format("D | %s | %s | %s\n", task.isDone() ? "1" : "0", + task.getDescription(), ((Deadline) task).getBy()); + fw.write(str); + } else { + String str = String.format("T | %s | %s\n", task.isDone() ? "1" : "0", + task.getDescription()); + fw.write(str); + } + } + fw.close(); + } catch (IOException e) { + System.out.println(e.getMessage()); + } + } + + /** + * Check whether to create a new file becuase it does not exist. + * + * @param file The record of tasks to be saved. + */ + + private static File checkFile(File file) throws DukeException { + if (file.exists()) { + return file; + } + + if (!file.getParentFile().mkdir()) { + throw new DukeException("Unable to make directory to save the task file"); + } + + try { + file.createNewFile(); + } catch (IOException e) { + throw new DukeException("Error cannot create new file"); + } + return file; + } + + +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 0000000000..9b1d97c34d --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,30 @@ +public class Task { + private String description; + private boolean isDone; + + Task(String description) { + this.description = description; + this.isDone = false; + } + + private String getStatusIcon() { + return (isDone ? "\u2713" : "\u2718"); //return tick or X symbols + } + + void markAsDone() { + this.isDone = true; + } + + boolean isDone() { + return this.isDone; + } + + String getDescription() { + return this.description; + } + + @Override + public String toString() { + return "[" + this.getStatusIcon() + "] " + this.description; + } +} \ No newline at end of file diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java new file mode 100644 index 0000000000..fb06a2b225 --- /dev/null +++ b/src/main/java/TaskList.java @@ -0,0 +1,23 @@ +import java.util.ArrayList; + +public class TaskList { + + private ArrayList taskList = new ArrayList<>(); + + public TaskList(ArrayList taskList) { + this.taskList = taskList; + } + + public void addTask(Task task) { + taskList.add(task); + } + + public void deleteTask(int taskNum) { + this.taskList.remove(taskNum); + } + + public ArrayList getTaskList() { + return taskList; + } + +} \ No newline at end of file diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java new file mode 100644 index 0000000000..02d42d07e4 --- /dev/null +++ b/src/main/java/Todo.java @@ -0,0 +1,12 @@ +public class Todo extends Task { + + Todo(String description) { + super(description); + } + + @Override + public String toString() { + return "[T]" + super.toString(); + } + +} \ No newline at end of file diff --git a/src/main/java/TodoSort.java b/src/main/java/TodoSort.java new file mode 100644 index 0000000000..37e428a010 --- /dev/null +++ b/src/main/java/TodoSort.java @@ -0,0 +1,16 @@ +import java.util.Comparator; + +public class TodoSort implements Comparator { + + @Override + public int compare(Task t1, Task t2) { + if (!(t1 instanceof Todo) && !(t2 instanceof Todo)) { + return 0; + } else if (!(t1 instanceof Todo)) { + return 1; + } else if (!(t2 instanceof Todo)) { + return -1; + } + return t1.getDescription().compareTo(t2.getDescription()); + } +} diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java new file mode 100644 index 0000000000..f2c1c8e65f --- /dev/null +++ b/src/main/java/Ui.java @@ -0,0 +1,75 @@ +import java.util.ArrayList; + +class Ui { + private String output; + + String getOutput() { + return this.output; + } + + void setToFarewell() { + output = "Bye. Hope to see you again soon!"; + } + + void setToList(TaskList taskList) { + + output = "Here are the tasks in your list:\n"; + for (int i = 0; i < taskList.getTaskList().size(); i++) { + int taskNum = i + 1; + output += taskNum + ". " + taskList.getTaskList().get(i).toString() + "\n"; + } + } + + void setToTodo(Task todoTask, TaskList taskList) { + output = "Got it. I've added this task:\n" + + todoTask.toString() + + "\n" + "Now you have " + taskList.getTaskList().size() + " tasks in the list."; + } + + void setToDeadline(Task dlTask, TaskList taskList) { + output = "Got it. I've added this task:\n" + + dlTask.toString() + "\n" + + "Now you have " + taskList.getTaskList().size() + " tasks in the list."; + } + + void setToEvent(Task eventTask, TaskList taskList) { + output = "Got it. I've added this task:\n" + + eventTask.toString() + "\n" + "Now you have " + + taskList.getTaskList().size() + " tasks in the list."; + } + + void setToDone(int taskNum, TaskList taskList) { + assert (taskNum > 0) : "Task number must be more than 1"; + output = "Nice! I've marked this task as done:\n" + + taskList.getTaskList().get(taskNum - 1).toString(); + } + + void setToDelete(int taskNum2, TaskList taskList) { + assert (taskNum2 > 0) : "Task number must be more than 1"; + output = "Noted. I've removed this task:\n" + + taskList.getTaskList().get(taskNum2 - 1).toString() + "\n" + + "Now you have " + (taskList.getTaskList().size() - 1) + "tasks in the list."; + } + + void setToFind(ArrayList relatedTasks, TaskList taskList, String findWord) { + for (Task task : taskList.getTaskList()) { + if (task.getDescription().contains(findWord)) { + relatedTasks.add(task); + } + } + output = "Here are the matching tasks in your list:\n"; + for (int i = 0; i < relatedTasks.size(); i++) { + int num = i + 1; + output += num + ". " + relatedTasks.get(i) + "\n"; + } + } + + void setToSort(ArrayList taskList, String sortType) { + output = "The list is now sorted according to: " + sortType + "\n"; + for (int i = 0; i < taskList.size(); i++) { + int taskNum = i + 1; + output += taskNum + ". " + taskList.get(i) + "\n"; + } + } + +} \ No newline at end of file diff --git a/src/main/resources/images/DaDuke.png b/src/main/resources/images/DaDuke.png new file mode 100644 index 0000000000..66e3e2817a 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..4f36f095a9 Binary files /dev/null and b/src/main/resources/images/DaUser.png differ diff --git a/src/main/resources/view/DialogBox.fxml b/src/main/resources/view/DialogBox.fxml new file mode 100644 index 0000000000..d8db3c9c6b --- /dev/null +++ b/src/main/resources/view/DialogBox.fxml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/view/MainWindow.fxml b/src/main/resources/view/MainWindow.fxml new file mode 100644 index 0000000000..b903283366 --- /dev/null +++ b/src/main/resources/view/MainWindow.fxml @@ -0,0 +1,19 @@ + + + + + + + + + + + +