diff --git a/README.md b/README.md index 9d95025bce..b9e11953ef 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. @@ -15,7 +15,7 @@ Prerequisites: JDK 11, update Intellij to the most recent version. 1. Click `Open or Import`. 1. Select the project directory, and click `OK` 1. If there are any further prompts, accept the defaults. -1. After the importing is complete, locate the `src/main/java/Duke.java` file, right-click it, and choose `Run Duke.main()`. If the setup is correct, you should see something like the below: +1. After the importing is complete, locate the `src/main/java/duke.Duke.java` file, right-click it, and choose `Run duke.Duke.main()`. If the setup is correct, you should see something like the below: ``` Hello from ____ _ diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000000..74a6358571 --- /dev/null +++ b/build.gradle @@ -0,0 +1,59 @@ +plugins { + id 'java' + id 'application' + //id 'checkstyle' + id "com.github.johnrengelman.shadow" version "6.0.0" +} + +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' +} + +dependencies { + 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.Launcher" +} + +shadowJar { + archiveBaseName = "duke" + archiveClassifier = null +} + +run{ + standardInput = System.in +} diff --git a/data/duke.txt b/data/duke.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/README.md b/docs/README.md index fd44069597..65eafd94c5 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,20 +1,160 @@ # User Guide -## Features +KaTo Task Manager (KTM) is a desktop app for managing tasks, +optimized for use via a Chat Window with Ka To. +Ka To can keep track of all your remaining tasks, +and help you to finish the tasks on time. +At the same time, you could update Ka To to mark the tasks as done or delete them. +KTM helps you to be more aware of your schedule and become a better task manager. +## Features with commands + Notes about the command format: + + - `+` represents typing down the information in order, without the `+` itself, + e.g. `Done + " " + 3` can be typed as `Done 3` in the send box + - `" "` represents a space, + e.g. `todo + " " + info` can be typed as `todo info` in the text box + - `Number` represents any number sequence of the task lists, + e.g. `Done 3` is one possible way of `Done + " " + Number` + - `info` represents any details provided for the task", + e.g. `todo eat` is one possible way of `todo + "_" + info` + - `time` represents any date target for the task and it must be in the format of "yyyy-MM-dd" + e.g. 2020-09-09 is one possible way of time + + Feature List: + 1. Checking for food left in fridge: `food` + 2. Checking for allowance left in account: `allowance` + 3. Adding a todo task: `todo + " " + info` + 4. Adding a deadline task: `deadline + " " + info + "/by" + time` + 5. Adding a event task: `event + " " + info + "/at" + time` + 6. Deleting a task: `delete + " " + Number` + 7. Marking a task as done: `done + " " + Number` + 8. Finding relevant tasks: `find + " " + info` + 9. Viewing the task list: `tasks` + 10. Saying bye to KaTo: `bye` + 11. Exiting KTM : `exit` + + ### Feature 1 -Description of feature. +Checking for food left in fridge: `food` -## Usage +- Example of usage: +`food left` -### `Keyword` - Describe action +- Expected outcome: +KaTo will reply `"Only an apple pie"` in the window -Describe action and its outcome. +### Feature 2 +Checking for allowance left in account: `allowance` -Example of usage: +- Example of usage: +`allowance left` -`keyword (optional arguments)` +- Expected outcome: +KaTo will reply `I have checked, it is 2000000 SGD` in the window -Expected outcome: +### Feature 3 +Adding a todo task: `todo + " " + info` + +- Example of usage: +`todo finish my ip` + +- Expected outcome: +KaTo will add `todo finish my ip` to the list, +KaTo will inform you whether it is successful +and state the total number of tasks in the task list. + +### Feature 4 +Adding a deadline task: `deadline + " " + info + "/by" + time` + ( The time format must be "yyyy-MM-dd" ) +- Example of usage: +`deadline finish my ip /by 2020-09-17` + +- Expected outcome: +KaTo will add `deadline finish my ip /by 2020-09-17` to the list, +KaTo will inform you whether it is added successfully +and state the total number of tasks in the task list. + +### Feature 5 +Adding a event task: `event + " " + info + "/at" + time` + ( The time format must be "yyyy-MM-dd" ) +- Example of usage: +`event finish my ip /at 2020-09-17` + +- Expected outcome: +KaTo will add `event finish my ip /at 2020-09-17` to the list, +KaTo will inform you whether it is added successfully +and state the total number of tasks in the task list. + +### Feature 6 +Deleting a task: `delete + " " + Number` + +- Example of usage: +`delete 3` + +- Expected outcome: +KaTo will delete the task with sequence number 3 in the list. + + Note: + (The number must be not be larger than the size of the current task list +and be a positive integer number) + + KaTo will inform you whether it is successful and update the task list and storage. + +### Feature 7 +Marking a task as done: `done + " " + Number` + +- Example of usage: +`done 3` + +- Expected outcome: +KaTo will change the status of the respective task from a cross to a tick. + + Note: + (The number must be not be larger than the size of the current task list +and be a positive integer number) + + KaTo will inform you whether it is successful and update the task list and storage. + +### Feature 8 +Finding relevant tasks: `find + " " + info` + +- Example of usage: +`find ip` + +- Expected outcome: + +KaTo will list out the relevant tasks that contain `info`. + +### Feature 9 +Viewing the task list: `tasks` + +- Example of usage: +`tasks` + +- Expected outcome: + +KaTo will list out the current tasks in the task list and inform the user if it is empty. + +### Feature 10 + +Saying bye to KaTo: `bye` + +- Example of usage: +`bye` + +- Expected outcome: + +KaTo will print out the bye message to the user. + + ### Feature 11 +Exiting KTM : `exit` + +- Example of usage: +`exit` + +- Expected outcome: + +The user will exit the KTM application. + -`outcome` diff --git a/docs/Ui.png b/docs/Ui.png new file mode 100644 index 0000000000..0bba425d6d 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..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..4f8aa9b5fb --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Fri Sep 04 16:49:21 SGT 2020 +distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-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..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/lib/javafx-swt.jar b/lib/javafx-swt.jar new file mode 100644 index 0000000000..9a7cc5780b Binary files /dev/null and b/lib/javafx-swt.jar differ diff --git a/lib/javafx.base.jar b/lib/javafx.base.jar new file mode 100644 index 0000000000..ee3118fd73 Binary files /dev/null and b/lib/javafx.base.jar differ diff --git a/lib/javafx.controls.jar b/lib/javafx.controls.jar new file mode 100644 index 0000000000..a24d390b4b Binary files /dev/null and b/lib/javafx.controls.jar differ diff --git a/lib/javafx.fxml.jar b/lib/javafx.fxml.jar new file mode 100644 index 0000000000..8f7f4cffe2 Binary files /dev/null and b/lib/javafx.fxml.jar differ diff --git a/lib/javafx.graphics.jar b/lib/javafx.graphics.jar new file mode 100644 index 0000000000..43496de438 Binary files /dev/null and b/lib/javafx.graphics.jar differ diff --git a/lib/javafx.media.jar b/lib/javafx.media.jar new file mode 100644 index 0000000000..3ee059cc4e Binary files /dev/null and b/lib/javafx.media.jar differ diff --git a/lib/javafx.properties b/lib/javafx.properties new file mode 100644 index 0000000000..efec880e3c --- /dev/null +++ b/lib/javafx.properties @@ -0,0 +1,3 @@ +javafx.version=11.0.2 +javafx.runtime.version=11.0.2+1 +javafx.runtime.build=1 diff --git a/lib/javafx.swing.jar b/lib/javafx.swing.jar new file mode 100644 index 0000000000..30df4229f5 Binary files /dev/null and b/lib/javafx.swing.jar differ diff --git a/lib/javafx.web.jar b/lib/javafx.web.jar new file mode 100644 index 0000000000..c61b45b9a3 Binary files /dev/null and b/lib/javafx.web.jar differ diff --git a/lib/libdecora_sse.dylib b/lib/libdecora_sse.dylib new file mode 100755 index 0000000000..4a42b25323 Binary files /dev/null and b/lib/libdecora_sse.dylib differ diff --git a/lib/libfxplugins.dylib b/lib/libfxplugins.dylib new file mode 100755 index 0000000000..e1eddc7823 Binary files /dev/null and b/lib/libfxplugins.dylib differ diff --git a/lib/libglass.dylib b/lib/libglass.dylib new file mode 100755 index 0000000000..4e2d982a27 Binary files /dev/null and b/lib/libglass.dylib differ diff --git a/lib/libglib-lite.dylib b/lib/libglib-lite.dylib new file mode 100755 index 0000000000..e171a56fd1 Binary files /dev/null and b/lib/libglib-lite.dylib differ diff --git a/lib/libgstreamer-lite.dylib b/lib/libgstreamer-lite.dylib new file mode 100755 index 0000000000..c9198f5c75 Binary files /dev/null and b/lib/libgstreamer-lite.dylib differ diff --git a/lib/libjavafx_font.dylib b/lib/libjavafx_font.dylib new file mode 100755 index 0000000000..72e39fe703 Binary files /dev/null and b/lib/libjavafx_font.dylib differ diff --git a/lib/libjavafx_iio.dylib b/lib/libjavafx_iio.dylib new file mode 100755 index 0000000000..77c4c2fb4b Binary files /dev/null and b/lib/libjavafx_iio.dylib differ diff --git a/lib/libjfxmedia.dylib b/lib/libjfxmedia.dylib new file mode 100755 index 0000000000..37573f878f Binary files /dev/null and b/lib/libjfxmedia.dylib differ diff --git a/lib/libjfxmedia_avf.dylib b/lib/libjfxmedia_avf.dylib new file mode 100755 index 0000000000..c048b15b8d Binary files /dev/null and b/lib/libjfxmedia_avf.dylib differ diff --git a/lib/libjfxwebkit.dylib b/lib/libjfxwebkit.dylib new file mode 100755 index 0000000000..f79b8dc3d1 Binary files /dev/null and b/lib/libjfxwebkit.dylib differ diff --git a/lib/libprism_common.dylib b/lib/libprism_common.dylib new file mode 100755 index 0000000000..99db5b4f69 Binary files /dev/null and b/lib/libprism_common.dylib differ diff --git a/lib/libprism_es2.dylib b/lib/libprism_es2.dylib new file mode 100755 index 0000000000..c4d3a25d92 Binary files /dev/null and b/lib/libprism_es2.dylib differ diff --git a/lib/libprism_sw.dylib b/lib/libprism_sw.dylib new file mode 100755 index 0000000000..d6dbb77472 Binary files /dev/null and b/lib/libprism_sw.dylib differ diff --git a/lib/src.zip b/lib/src.zip new file mode 100644 index 0000000000..afdfc99f3e Binary files /dev/null and b/lib/src.zip differ 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/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..6e864153e8 --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: duke.Duke + diff --git a/src/main/java/duke/Deadline.java b/src/main/java/duke/Deadline.java new file mode 100644 index 0000000000..b026e29a09 --- /dev/null +++ b/src/main/java/duke/Deadline.java @@ -0,0 +1,30 @@ +package duke; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +/** + * Represents the task of "deadline" category + */ + +public class Deadline extends Task { + + protected LocalDate dateBy; + + public Deadline(int category, int status, String command, String date) { + super(category, status, command); + DateTimeFormatter inputFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + this.dateBy = LocalDate.parse(date, inputFormat); + } + + /** + * Prints out the deadline task and converts the date format + * @return string representation + */ + + @Override + public String toString() { + String date = dateBy.format(DateTimeFormatter.ofPattern("MMM dd yyyy")); + return super.toString() + "/by: " + date + ""; + } +} \ No newline at end of file diff --git a/src/main/java/duke/DialogBox.java b/src/main/java/duke/DialogBox.java new file mode 100644 index 0000000000..22627e5131 --- /dev/null +++ b/src/main/java/duke/DialogBox.java @@ -0,0 +1,72 @@ +package duke; + +import javafx.geometry.Pos; + +import javafx.scene.Node; +import javafx.scene.control.Label; +import javafx.scene.image.Image; +import javafx.scene.layout.HBox; +import javafx.scene.layout.BackgroundImage; +import javafx.scene.layout.BackgroundPosition; +import javafx.scene.layout.BackgroundRepeat; +import javafx.scene.layout.BackgroundSize; +import javafx.scene.layout.Background; +import javafx.scene.paint.ImagePattern; +import javafx.scene.shape.Circle; + +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; + +/** + * Creates the chatBox for user or KaTo + * Modifies the chat background image and the profile image + */ + + +public class DialogBox extends HBox { + + public DialogBox(Label label, Image image, Image background) { + // set profile image to circle shape + Circle circle = new Circle(40); + circle.setFill(new ImagePattern(image)); + + label.setWrapText(true); + + // create a background image + BackgroundImage backgroundimage = new BackgroundImage(background, + BackgroundRepeat.NO_REPEAT, + BackgroundRepeat.NO_REPEAT, + BackgroundPosition.DEFAULT, + BackgroundSize.DEFAULT); + + // create Background + Background backgroundImage = new Background(backgroundimage); + + // set background + this.setBackground(backgroundImage); + this.setAlignment(Pos.TOP_RIGHT); + this.getChildren().addAll(label, circle); + } + + /** + * Flips the dialog box such that the ImageView is on the left and text on the right. + */ + + private void flip() { + this.setAlignment(Pos.TOP_LEFT); + ObservableList tmp = FXCollections.observableArrayList(this.getChildren()); + FXCollections.reverse(tmp); + this.getChildren().setAll(tmp); + } + + public static DialogBox getUserDialog(Label label, Image image, Image background) { + return new DialogBox(label, image, background); + } + + public static DialogBox getDukeDialog(Label label, Image image, Image background) { + var dialogBox = new DialogBox(label, image, background); + dialogBox.flip(); + return dialogBox; + } + +} diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java new file mode 100644 index 0000000000..baae79c789 --- /dev/null +++ b/src/main/java/duke/Duke.java @@ -0,0 +1,208 @@ +package duke; + +import javafx.application.Application; + +import javafx.scene.Scene; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.control.ScrollPane; +import javafx.scene.control.TextField; +import javafx.scene.image.Image; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.Region; +import javafx.scene.layout.VBox; + +import javafx.stage.Stage; + + +/** + * Presents Duke class with "Ka To" + * Interacts with the user and answers user commands + * Starts the GUI chat window + * Manages the task list of the user + * Follows the coding standard + */ + +public class Duke extends Application { + + private Storage storage; + private TaskList tasks; + private Ui ui; + private ScrollPane scrollPane; + private VBox dialogContainer; + private TextField userInput; + + + private Image user = new Image(this.getClass().getResourceAsStream("/images/Me.png")); + private Image duke = new Image(this.getClass().getResourceAsStream("/images/KaTo.png")); + private Image userBackground = new Image(this.getClass().getResourceAsStream("/images/background2.png")); + private Image dukeBackground = new Image(this.getClass().getResourceAsStream("/images/Sea.png")); + + public Duke() { + } + + public Duke(String filePath) { + //initialise ui and storage + this.ui = new Ui(); + this.storage = new Storage(filePath); + + //load the storage file into task list + if (this.storage.load().isEmpty()) { + // create new task list if empty file + this.tasks = new TaskList(); + } else { + this.tasks = new TaskList(storage.load()); + } + } + + //run the ui and parser + private void run() { + // KaTo greets the user + this.ui.printGreet(); + + // KaTo takes in user commands + while (this.ui.input.hasNextLine()) { + String command = this.ui.getInput(); + Parser.processCommand(command, this.ui, this.tasks, this.storage.filePath); + } + } + + @Override + public void start(Stage stage) { + //The better Gui includes a chat background and a circular profile page + //The container for the content of the chat to scroll. + scrollPane = new ScrollPane(); + dialogContainer = new VBox(); + userInput = new TextField(); + + Button sendButton = new Button("Send"); + AnchorPane mainLayout = new AnchorPane(); + Scene scene = new Scene(mainLayout); + + setMainLayout(mainLayout, sendButton); + + setDialogContainer(); + + setStage(stage, scene); + + setScrollPane(); + + setUserInput(); + + setSendButton(sendButton); + + setAnchorPane(sendButton); + + } + + private void setMainLayout(AnchorPane mainLayout, Button sendButton) { + mainLayout.getChildren().addAll(scrollPane, userInput, sendButton); + mainLayout.setPrefSize(400.0, 600.0); + } + + private void setUserInput() { + userInput.setPrefWidth(345.0); + userInput.setOnAction((event) -> handleUserInput()); + } + + private void setDialogContainer() { + + // KaTo greats user in the chat window + Label dukeText = new Label("Hello, Ka To here, how can I serve you?"); + dialogContainer.getChildren().addAll( + DialogBox.getDukeDialog(dukeText, duke, dukeBackground) + ); + + dialogContainer.setPrefHeight(Region.USE_COMPUTED_SIZE); + dialogContainer.heightProperty().addListener((observable) -> scrollPane.setVvalue(1.0)); + + } + + private void setStage(Stage stage, Scene scene){ + stage.setScene(scene); + stage.show(); + + stage.setTitle("KaTo Task Manager"); + stage.setResizable(false); + stage.setMinHeight(600.0); + stage.setMinWidth(400.0); + } + + private void setScrollPane(){ + + scrollPane.setContent(dialogContainer); + scrollPane.setPrefSize(385, 575); + scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); + scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS); + + scrollPane.setVvalue(1.0); + scrollPane.setFitToWidth(true); + } + + private void setAnchorPane(Button button){ + AnchorPane.setTopAnchor(scrollPane, 1.0); + + AnchorPane.setBottomAnchor(button, 1.0); + AnchorPane.setRightAnchor(button, 1.0); + + AnchorPane.setLeftAnchor(userInput , 1.0); + AnchorPane.setBottomAnchor(userInput, 1.0); + + } + + private void setSendButton(Button sendButton) { + + sendButton.setPrefWidth(55.0); + + sendButton.setOnMouseClicked((event) -> { + handleUserInput(); + }); + } + /** + * 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. + */ + + private void handleUserInput() { + + Label userText = new Label("Me :\n" + userInput.getText()); + Label dukeText = new Label(getResponse(userInput.getText())); + + dialogContainer.getChildren().addAll( + DialogBox.getUserDialog(userText, user, userBackground), + DialogBox.getDukeDialog(dukeText, duke, dukeBackground) + ); + userInput.clear(); + } + + /** + * Gets and processes user commands + * Returns the response to those commands + * + * @param input String user input + * @return output String KaTo response + */ + private String getResponse(String input) { + + String filePath = "./data/duke.txt"; + GUI gui = new GUI(); + this.storage = new Storage(filePath); + + if (this.storage.load().isEmpty()) { + this.tasks = new TaskList(); + } else { + this.tasks = new TaskList(storage.load()); + } + // get the KaTo response + String output = ParserGUI.processCommand(input, gui, this.tasks, this.storage.filePath); + + return "Ka To: \n" + output; + } + + public static void main(String[] args) { + String filePath = "./data/duke.txt"; + Duke manager = new Duke(filePath); + manager.run(); + } + +} diff --git a/src/main/java/duke/Event.java b/src/main/java/duke/Event.java new file mode 100644 index 0000000000..fcda9cb423 --- /dev/null +++ b/src/main/java/duke/Event.java @@ -0,0 +1,31 @@ +package duke; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +/** + * Represents the task of "event" category + */ + + +public class Event extends Task { + + protected LocalDate dateAt; + + public Event(int category, int status, String command, String date) { + super(category, status, command); + DateTimeFormatter inputFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + this.dateAt = LocalDate.parse(date, inputFormat); + } + + /** + * Prints out the event task and converts the date format + * @return string representation + */ + + @Override + public String toString() { + String date = dateAt.format(DateTimeFormatter.ofPattern("MMM dd yyyy")); + return super.toString() + "/at: " + date + ""; + } +} \ No newline at end of file diff --git a/src/main/java/duke/FileEditing.java b/src/main/java/duke/FileEditing.java new file mode 100644 index 0000000000..fb28f2cf47 --- /dev/null +++ b/src/main/java/duke/FileEditing.java @@ -0,0 +1,18 @@ +package duke; + +import java.io.FileWriter; +import java.io.IOException; + +/** + * Writes the data into the intended file path + * + * @throws IOException + */ + +public class FileEditing { + public static void writeToFile(String filePath, String data) throws IOException { + FileWriter fileWriter = new FileWriter(filePath); + fileWriter.write(data); + fileWriter.close(); + } +} diff --git a/src/main/java/duke/GUI.java b/src/main/java/duke/GUI.java new file mode 100644 index 0000000000..464511d900 --- /dev/null +++ b/src/main/java/duke/GUI.java @@ -0,0 +1,148 @@ +package duke; + + +/** + * Interacts with the user and answers user commands + * Returns the responses in a String + */ + +public class GUI { + private static final String Message_Bye = "I am happy to serve you. See you soon!"; + + GUI() { + } + + public String printBye() { + return Message_Bye; + } + + /** + * Returns the current task list in a single string + * + * @param taskList Task List to be read and printed + * @return String output + */ + public String printTaskList(TaskList taskList) { + StringBuilder output = new StringBuilder("This is your task list: \n"); + + for (int i = 1; i < taskList.taskCounts + 1; i++) { + Task task = taskList.tasks.get(i - 1); + String oneLine = "" + i + "." + task + "\n"; + output.append(oneLine); + } + return output.toString(); + } + + /** + * Returns out the message of empty list + */ + public String printEmptyList() { + return "Oops, the task list is empty"; + } + + /** + * Returns out the current task list + * + * @param added Task added successfully + * @param list Task List to be added into + * @return String output + */ + public String addTaskSuccessful(Task added, TaskList list) { + return "Congratulations! This is added! \n" + + added + "\n You have " + list.getTaskCounts() + " tasks in the list"; + } + + /** + * Returns the task from the list + * + * @param deleted Task deleted successfully + * @param list Task List to be deleted from + * @return String output + */ + public String deleteTaskSuccessful(Task deleted, TaskList list) { + return " Kay, this task now is deleted: \n" + + deleted + "\n You have " + list.getTaskCounts() + " tasks in the list"; + } + + /** + * Returns the task as done + * + * @param done Task to be changed status into Done + * @return String output + */ + public String markTaskDone(Task done) { + return "Congratulations! This is now marked as done:\n" + done; + } + + public String failToMarkDone() { + return "Oops, please specify the task index to be marked"; + } + + /** + * Warns the user to include task index when finding task to mark done + */ + public String failToFindTask() { + return "Oops, please ensure the task index to be marked is correct"; + } + + /** + * Warns the user to include task index when deleting task + */ + public String failToDelete() { + return "Oops, please specify the task index to be deleted"; + } + + /** + * Warns the user to include task details + */ + public String failToFindDetails() { + return "Oops, please specify your task"; + } + + /** + * Warns the user to include task intended date + */ + + public String failToFindTime() { + return "Oops, please specify the time for the task"; + } + + /** + * Warns the user to key in correct commands + */ + + public String failToUnderstand() { + return "Sorry, I could not answer that .."; + } + + public String findDuplicates() { + return "Sorry, this task is already added.."; + } + + /** + * Returns the relevant task to the key word + * + * @param keyWord String keyword to be searched + * @param taskList TaskList taskList to be searched within + * @return String output + */ + + public String printFound(String keyWord, TaskList taskList) { + StringBuilder output = new StringBuilder("This is what I found: \n"); + for (int i = 1; i < taskList.taskCounts + 1; i++) { + Task task = taskList.tasks.get(i - 1); + if (task.toString().contains(keyWord)) { + output.append(i).append(".").append(task).append("\n"); + } + } + return output.toString(); + } + + /** + * Informs the user that the task list in the storage is now cleared + */ + + public String printClassCleared() { + return "Clear Successful! Now you have no tasks in the list"; + } +} diff --git a/src/main/java/duke/Launcher.java b/src/main/java/duke/Launcher.java new file mode 100644 index 0000000000..9438ec7d71 --- /dev/null +++ b/src/main/java/duke/Launcher.java @@ -0,0 +1,12 @@ +package duke; + +import javafx.application.Application; + +/** + * A launcher class to workaround classpath issues. + */ +public class Launcher { + public static void main(String[] args) { + Application.launch(Duke.class, args); + } +} diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java new file mode 100644 index 0000000000..1af11a2d93 --- /dev/null +++ b/src/main/java/duke/Parser.java @@ -0,0 +1,256 @@ +package duke; + +/** + * Parses the data and processes the command from the users + */ + +public class Parser { + + /** + * Processes the command entered by the user + * + * @param command String command entered + * @param ui Ui created to interact with users + * @param taskList TaskList to be processed with + * @param filePath String the path of the data storage + */ + public static void processCommand(String command, Ui ui, TaskList taskList, String filePath) { + + String[] portions = command.split(" ", 2); + String commandFront = portions[0]; + + switch (commandFront) { + case "food": + ui.replyFood(); + break; + case "allowance": + ui.replyAllowance(); + break; + case "tasks": + processTasksCommand(taskList, ui); + break; + case "done": + processDoneCommand(taskList, ui, filePath, portions); + break; + case "delete": + processDeleteCommand(taskList, ui, filePath, portions); + break; + case "find": + processFindCommand(taskList, ui, portions); + break; + case "bye": + ui.printBye(); + System.exit(0); + case "todo": + processToDoCommand(taskList, ui, portions, filePath); + break; + case "deadline": + processDeadlineCommand(taskList, ui, portions, filePath); + break; + case "event": + processEventCommand(taskList, ui, portions, filePath); + break; + default: + ui.failToUnderstand(); + break; + } + } + + + /** + * Processes the command "tasks" and prints the task list + */ + + private static void processTasksCommand(TaskList taskList, Ui ui) { + if (taskList.tasks.isEmpty()) { + ui.printEmptyList(); + } else { + ui.printTaskList(taskList); + } + } + + /** + * Processes the command "done + number" and marks the relative task done + */ + + private static void processDoneCommand(TaskList taskList, Ui ui, String filePath, String[] portions) { + if (portions.length == 1) { + ui.failToMarkDone(); + } else { + int taskNumber = Integer.parseInt(portions[1]); + if (taskNumber < 1 || taskNumber > taskList.taskCounts) { + ui.failToFindTask(); + } else { + Task task = taskList.tasks.get(taskNumber - 1); + task.markTaskAsDone(); + ui.markTaskDone(task); + } + } + Storage.updateTasks(taskList.getTaskCounts(), taskList.tasks, filePath); + } + + /** + * Processes the command "delete + number" and deletes the relative task + */ + + private static void processDeleteCommand(TaskList taskList, Ui ui, String filePath, String[] portions) { + if (portions.length == 1) { + ui.failToDelete(); + } else { + int taskNumber = Integer.parseInt(portions[1]); + if (taskNumber < 1 || taskNumber > taskList.taskCounts) { + ui.failToFindTask(); + } else { + Task task = taskList.tasks.get(taskNumber - 1); + task.markTaskAsDeleted(); + taskList.deleteTask(task); + ui.deleteTaskSuccessful(task, taskList); + } + } + Storage.updateTasks(taskList.getTaskCounts(), taskList.tasks, filePath); + } + + /** + * Processes the command "find + info" and deletes the relative task to the info + */ + + private static void processFindCommand(TaskList taskList, Ui ui, String[] portions){ + if (taskList.tasks.isEmpty()) { + ui.printEmptyList(); + } else { + ui.printFound(portions[1], taskList); + } + } + + /** + * Processes the command and adds the task to the task list if task is valid + * Updates the storage if task is valid + */ + + private static void processToDoCommand(TaskList taskList, Ui ui, String[] portions, String filePath) { + boolean isCorrectCommand = true; + + if (portions.length == 1) { + ui.failToFindDetails(); + isCorrectCommand = false; + } + + if(isCorrectCommand){ + ToDo toDo = new ToDo(Task.TASK_TODO, Task.DOING, portions[1]); + + boolean hasDuplicates = false; + //find duplicates + for (int i = 0; i < taskList.taskCounts; i++) { + if (taskList.tasks.get(i).toString().equals(toDo.toString())) { + hasDuplicates = true; + break; + } + } + //add task if no duplicates + if (hasDuplicates) { + ui.findDuplicates(); + } else { + taskList.addTask(toDo); + ui.addTaskSuccessful(toDo, taskList); + } + Storage.updateTasks(taskList.getTaskCounts(), taskList.tasks, filePath); + } + } + + /** + * Processes the deadline command and adds the task to the task list if task is valid + * updates the storage if the task is valid + */ + + private static void processDeadlineCommand(TaskList taskList, Ui ui, String[] portions, String filePath) { + boolean isCorrectCommand = true; + boolean includesTime = false; + String detail = ""; + String date = ""; + if (portions.length == 1) { + ui.failToFindDetails(); + isCorrectCommand = false; + } + + if (isCorrectCommand) { + String[] deadlineSplitter = portions[1].split("/by "); + if (deadlineSplitter.length == 1) { + ui.failToFindTime(); + + } else { + detail = deadlineSplitter[0]; + date = deadlineSplitter[1]; + includesTime = true; + } + } + + if(includesTime) { + Deadline deadline = new Deadline(Task.TASK_DEADLINE, Task.DOING, detail, date); + + boolean hasDuplicates = false; + //find duplicates + for(int i = 0; i < taskList.taskCounts; i++){ + if (taskList.tasks.get(i).toString().equals(deadline.toString())) { + hasDuplicates = true; + break; + } + } + //add task if no duplicates + if (hasDuplicates) { + ui.findDuplicates(); + } else { + taskList.addTask(deadline); + ui.addTaskSuccessful(deadline, taskList); + } + Storage.updateTasks(taskList.getTaskCounts(), taskList.tasks, filePath); + } + } + + /** + * Processes the event command and adds the task to the task list if task is valid + * updates the storage if the task is valid + */ + private static void processEventCommand(TaskList taskList, Ui ui, String[] portions, String filePath) { + boolean isCorrectCommand = true; + boolean includesTime = false; + String detail = ""; + String date = ""; + if (portions.length == 1) { + ui.failToFindDetails(); + isCorrectCommand = false; + } + + if (isCorrectCommand) { + String[] eventSplitter = portions[1].split("/at "); + if (eventSplitter.length == 1) { + ui.failToFindTime(); + + } else { + detail = eventSplitter[0]; + date = eventSplitter[1]; + includesTime = true; + } + } + + if (includesTime) { + Event event = new Event(Task.TASK_EVENT, Task.DOING, detail, date); + boolean hasDuplicates = false; + //find duplicates + for (int i = 0; i < taskList.taskCounts; i++) { + if (taskList.tasks.get(i).toString().equals(event.toString())) { + hasDuplicates = true; + break; + } + } + //add task if no duplicates + if (hasDuplicates) { + ui.findDuplicates(); + } else { + taskList.addTask(event); + ui.addTaskSuccessful(event, taskList); + } + Storage.updateTasks(taskList.getTaskCounts(), taskList.tasks, filePath); + } + } + +} \ No newline at end of file diff --git a/src/main/java/duke/ParserGUI.java b/src/main/java/duke/ParserGUI.java new file mode 100644 index 0000000000..1794c5e277 --- /dev/null +++ b/src/main/java/duke/ParserGUI.java @@ -0,0 +1,258 @@ +package duke; + +/** + * Parses the data and processes the command from the users + * Returns the response as a string + */ + +public class ParserGUI { + + /** + * Processes the command entered by the user + * Returns the output of response + * + * @param command String command entered + * @param ui GUI created to interact with users + * @param taskList TaskList to be processed with + * @param filePath String the path of the data storage + * @return output String + */ + public static String processCommand(String command, GUI ui, TaskList taskList, String filePath) { + + String[] portions = command.split(" ", 2); + String commandFront = portions[0]; + String output = ""; + + switch (commandFront) { + case "food": + output = "Only an apple pie"; + break; + case "allowance": + output = "I have checked, it is 2000000 SGD"; + break; + case "tasks": + output = processTasksCommand(taskList, ui); + break; + case "clear": + output = processClearCommand(taskList, ui, filePath); + break; + case "done": + output = processDoneCommand(taskList, ui, filePath, portions); + break; + case "delete": + output = processDeleteCommand(taskList, ui, filePath, portions); + break; + case "find": + output = processFindCommand(taskList, ui, portions); + break; + case "bye": + output = ui.printBye(); + break; + case "exit": + System.exit(0); + break; + case "todo": + output = processToDoCommand(taskList, ui, portions, filePath); + break; + case "deadline": + output = processDeadlineCommand(taskList, ui, portions, filePath); + break; + case "event": + output = processEventCommand(taskList, ui, portions, filePath); + break; + default: + output = ui.failToUnderstand(); + break; + } + return output; + } + + /** + * Processes the command "clear" and clears the task list + * Updates the storage with the cleared task list + */ + + private static String processClearCommand(TaskList taskList, GUI ui, String filePath ) { + if (taskList.tasks.isEmpty()) { + return ui.printEmptyList(); + } else { + taskList.tasks.clear(); + Storage.updateTasks(taskList.getTaskCounts(), taskList.tasks, filePath); + return ui.printClassCleared(); + } + } + + /** + * Processes the command "tasks" and prints the task list + */ + + private static String processTasksCommand(TaskList taskList, GUI ui) { + if (taskList.tasks.isEmpty()) { + return ui.printEmptyList(); + } else { + return ui.printTaskList(taskList); + } + } + + /** + * Processes the command "done + number" and marks the relative task done + */ + + private static String processDoneCommand(TaskList taskList, GUI ui, String filePath, String[] portions) { + if (portions.length == 1) { + return ui.failToMarkDone(); + } else { + int taskNumber = Integer.parseInt(portions[1]); + if (taskNumber < 1 || taskNumber > taskList.taskCounts) { + return ui.failToFindTask(); + } else { + Task task = taskList.tasks.get(taskNumber - 1); + task.markTaskAsDone(); + Storage.updateTasks(taskList.getTaskCounts(), taskList.tasks, filePath); + return ui.markTaskDone(task); + } + } + + } + + /** + * Processes the command "delete + number" and deletes the relative task + */ + + private static String processDeleteCommand(TaskList taskList, GUI ui, String filePath, String[] portions) { + if (portions.length == 1) { + return ui.failToDelete(); + } else { + int taskNumber = Integer.parseInt(portions[1]); + if (taskNumber < 1 || taskNumber > taskList.taskCounts) { + return ui.failToFindTask(); + } else { + Task task = taskList.tasks.get(taskNumber - 1); + taskList.deleteTask(task); + Storage.updateTasks(taskList.getTaskCounts(), taskList.tasks, filePath); + return ui.deleteTaskSuccessful(task, taskList); + } + } + + } + + /** + * Processes the command "find + info" and deletes the relative task to the info + */ + + private static String processFindCommand(TaskList taskList, GUI ui, String[] portions) { + if (taskList.tasks.isEmpty()) { + return ui.printEmptyList(); + } else { + return ui.printFound(portions[1], taskList); + } + } + + /** + * Processes the command and adds the task to the task list if task is valid + * Updates the storage if task is valid + */ + + private static String processToDoCommand(TaskList taskList, GUI ui, String[] portions, String filePath) { + + if (portions.length == 1) { + return ui.failToFindDetails(); + } + + ToDo toDo = new ToDo(Task.TASK_TODO, Task.DOING, portions[1]); + boolean hasDuplicates = false; + + //find duplicates + for (int i = 0; i < taskList.taskCounts; i++) { + if (taskList.tasks.get(i).toString().equals(toDo.toString())) { + hasDuplicates = true; + break; + } + } + //add task if no duplicates + if (hasDuplicates) { + return ui.findDuplicates(); + } else { + taskList.addTask(toDo); + Storage.updateTasks(taskList.getTaskCounts(), taskList.tasks, filePath); + return ui.addTaskSuccessful(toDo, taskList); + } + } + + /** + * Processes the deadline command and adds the task to the task list if task is valid + * updates the storage if the task is valid + */ + + private static String processDeadlineCommand(TaskList taskList, GUI ui, String[] portions, String filePath) { + + if (portions.length == 1) { + return ui.failToFindDetails(); + } + + String[] deadlineSplitter = portions[1].split("/by "); + if (deadlineSplitter.length == 1) { + return ui.failToFindTime(); + } + + String detail = deadlineSplitter[0]; + String date = deadlineSplitter[1]; + Deadline deadline = new Deadline(Task.TASK_DEADLINE, Task.DOING, detail, date); + boolean hasDuplicates = false; + + //find duplicates + for (int i = 0; i < taskList.taskCounts; i++) { + if (taskList.tasks.get(i).toString().equals(deadline.toString())) { + hasDuplicates = true; + break; + } + } + //add task if no duplicates + if (hasDuplicates) { + return ui.findDuplicates(); + } else { + taskList.addTask(deadline); + Storage.updateTasks(taskList.getTaskCounts(), taskList.tasks, filePath); + return ui.addTaskSuccessful(deadline, taskList); + } + } + + /** + * Processes the event command and adds the task to the task list if task is valid + * updates the storage if the task is valid + */ + private static String processEventCommand(TaskList taskList, GUI ui, String[] portions, String filePath) { + + if (portions.length == 1) { + return ui.failToFindDetails(); + } + + String[] eventSplitter = portions[1].split("/at "); + if (eventSplitter.length == 1) { + return ui.failToFindTime(); + } + + String detail = eventSplitter[0]; + String date = eventSplitter[1]; + Event event = new Event(Task.TASK_EVENT, Task.DOING, detail, date); + boolean hasDuplicates = false; + + //find duplicates + for (int i = 0; i < taskList.taskCounts; i++) { + if (taskList.tasks.get(i).toString().equals(event.toString())) { + hasDuplicates = true; + break; + } + } + + //add task if no duplicates + if (hasDuplicates) { + return ui.findDuplicates(); + } else { + taskList.addTask(event); + Storage.updateTasks(taskList.getTaskCounts(), taskList.tasks, filePath); + return ui.addTaskSuccessful(event, taskList); + } + + } +} \ No newline at end of file diff --git a/src/main/java/duke/Storage.java b/src/main/java/duke/Storage.java new file mode 100644 index 0000000000..233da68937 --- /dev/null +++ b/src/main/java/duke/Storage.java @@ -0,0 +1,99 @@ +package duke; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + + +/** + * Stores the data in a file path and update the storage + */ + + +public class Storage { + public String filePath; + + public Storage(String filePath) { + this.filePath = filePath; + } + + /** + * Returns the data from the file storage in lists of Strings + * If the fire storage is not created, creates a new storage file + * + * @return inputs List inputs data from the storage. + */ + + public List load() { + + List inputs = new ArrayList<>(); + + try { + File myFile = new File(filePath); + Scanner myReader = new Scanner(myFile); + + while (myReader.hasNextLine()) { + String data = myReader.nextLine(); + inputs.add(data); + } + myReader.close(); + } catch (FileNotFoundException e) { + System.out.println("Creating the file to save"); + try { + String folderPath = "./data"; + Path path = Paths.get(folderPath); + + Files.createDirectories(path); + + System.out.println("Directory is created!"); + } catch (IOException error) { + System.err.println("Failed to create directory!" + error.getMessage()); + } + try { + File fileCreator = new File(filePath); + if (fileCreator.createNewFile()) { + System.out.println("File created: " + fileCreator.getName()); + } else { + System.out.println("File already exists."); + } + } catch (IOException ex) { + System.out.println("An error occurred."); + e.printStackTrace(); + } + } + return inputs; + } + + /** + * Updates the task list in the storage after changes + * + * @param count int number of tasks in the list + * @param list List to be updated + * @param filePath String the data storage file to be updated + */ + + public static void updateTasks(int count, List list, String filePath) { + String data = ""; + + for (int i = 1; i < count + 1; i++) { + Task task = list.get(i - 1); + String currentTask = i + "." + task + "\n"; + data = data + currentTask; + } + + try { + FileEditing.writeToFile(filePath, data); + } catch (IOException e) { + e.printStackTrace(); + } + + } + +} \ No newline at end of file diff --git a/src/main/java/duke/Task.java b/src/main/java/duke/Task.java new file mode 100644 index 0000000000..b2fc035ff6 --- /dev/null +++ b/src/main/java/duke/Task.java @@ -0,0 +1,63 @@ +package duke; + +/** + * Represents the task and includes the task information + * Records the status, category and command of the task + */ + +public class Task { + + private int status; + private int category; + private String command; + + protected static int DONE = 1; + protected static int DOING = 2; + protected static int TASK_TODO = 1; + protected static int TASK_DEADLINE = 2; + protected static int TASK_EVENT = 3; + + public Task(int category, int status, String command) { + this.category = category; + this.status = status; + this.command = command; + } + + + public String getStatusIcon() { + return ((this.status == DONE) ? "v" : "x"); + } + + /** + * marks the task as done status + */ + public void markTaskAsDone() { + if (this.status != DONE) { + this.status = DONE; + } + } + + public void markTaskAsDeleted() { + this.status = DOING; + } + + /** + * Returns string representation of the task according to the category + * + * @return String string representation of the task. + */ + + @Override + public String toString() { + String category = ""; + if (this.category == TASK_TODO) { + category = "ToDo"; + } else if (this.category == TASK_DEADLINE) { + category = "DeadLine"; + } else if (this.category == TASK_EVENT) { + category = "Event"; + } + return "[" + category + "][" + this.getStatusIcon() + "] " + this.command; + } + +} \ No newline at end of file diff --git a/src/main/java/duke/TaskList.java b/src/main/java/duke/TaskList.java new file mode 100644 index 0000000000..da57e0b0bd --- /dev/null +++ b/src/main/java/duke/TaskList.java @@ -0,0 +1,133 @@ +package duke; + +import java.util.ArrayList; +import java.util.List; +import java.util.Date; + +import java.text.SimpleDateFormat; +import java.text.ParseException; + +/** + * Reads data from the storage files + * Stores tasks assigned by users in a list + * Adds or deletes the data from the list + * If data is empty, a new task list is initiated + */ + +public class TaskList { + protected List tasks; + protected int taskCounts; + String ORIGINAL_FORMAT = "MMM dd yyyy"; + String UPDATED_FORMAT = "yyyy-MM-dd"; + + public TaskList() { + this.tasks = new ArrayList<>(); + this.taskCounts = 0; + } + + public TaskList(List data) { + this.tasks = new ArrayList<>(); + for (String command : data) { + assert command.length() > 2 : "incorrect command length"; + command = command.substring(3); + String[] commandPortions = command.split("]", 3); + String category = commandPortions[0]; + + assert commandPortions.length > 2 : "incorrect command portions"; + String mark = commandPortions[1].substring(commandPortions[1].length() - 1); + + int status = (mark.equals("v")) ? Task.DONE : Task.DOING; + String commandDetails = commandPortions[2].substring(1); + Task task = new Task(0, 0, ""); + + switch (category) { + case "ToDo": + task = new ToDo(Task.TASK_TODO, status, commandDetails); + break; + case "DeadLine": + task = addDeadlineTask(commandDetails, status); + break; + case "Event": + task = addEventTask(commandDetails, status); + break; + default: + break; + } + { + assert false; + tasks.add(task); + taskCounts++; + } + } + } + + + public int getTaskCounts() { + return this.taskCounts; + } + + /** + * Adds task into the task list and increases the task counts + * + * @param task Task to be added + */ + + public void addTask(Task task) { + this.tasks.add(task); + taskCounts++; + } + + /** + * Removes task from the task list and decreases the task counts + * + * @param task Task to be deleted + */ + + public void deleteTask(Task task) { + assert this.tasks.contains(task) : "unable to remove task that is not in the list"; + this.tasks.remove(task); + taskCounts--; + } + + private Deadline addDeadlineTask(String commandDetails, int status) { + + String[] deadlineSplitter = commandDetails.split("/by: "); + assert deadlineSplitter.length == 2 : "unable to format the time"; + + String originalDate = deadlineSplitter[1]; + String updatedDate; + + SimpleDateFormat formatter = new SimpleDateFormat(ORIGINAL_FORMAT); + Date date = null; + try { + date = formatter.parse(originalDate); + } catch (ParseException e) { + e.printStackTrace(); + } + formatter.applyPattern(UPDATED_FORMAT); + updatedDate = formatter.format(date); + + return new Deadline(Task.TASK_DEADLINE, status, deadlineSplitter[0], updatedDate); + } + + private Event addEventTask(String commandDetails, int status) { + String[] eventSplitter = commandDetails.split("/at: "); + + assert eventSplitter.length == 2 : "unable to format the time"; + + String originalEventDate = eventSplitter[1]; + String updatedEventDate; + + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(ORIGINAL_FORMAT); + Date time = null; + try { + time = simpleDateFormat.parse(originalEventDate); + } catch (ParseException e) { + e.printStackTrace(); + } + simpleDateFormat.applyPattern(UPDATED_FORMAT); + updatedEventDate = simpleDateFormat.format(time); + + return new Event(Task.TASK_EVENT, status, eventSplitter[0], updatedEventDate); + } +} \ No newline at end of file diff --git a/src/main/java/duke/ToDo.java b/src/main/java/duke/ToDo.java new file mode 100644 index 0000000000..b9d8afc931 --- /dev/null +++ b/src/main/java/duke/ToDo.java @@ -0,0 +1,17 @@ +package duke; + +/** + * Represents the task of "todo" category + */ + +public class ToDo extends Task { + + public ToDo(int category, int status, String command) { + super(category, status, command); + } + + @Override + public String toString() { + return super.toString(); + } +} \ No newline at end of file diff --git a/src/main/java/duke/Ui.java b/src/main/java/duke/Ui.java new file mode 100644 index 0000000000..13fa22b4aa --- /dev/null +++ b/src/main/java/duke/Ui.java @@ -0,0 +1,204 @@ +package duke; + +import java.io.InputStream; +import java.util.Scanner; + +/** + * Interacts with the user and answers user commands + * Prints out answers in the terminal + */ + +public class Ui { + protected final Scanner input; + private static final String Message_GREETING + = "Hello :))! I'm your daily manager, Ka To! Welcome Back! \n" + + "how could I serve you now? \n" + + "You could ask me any question if you like! \n" + + "____________________________________________________________"; + private static final String Message_Bye = "Ka To: \n" + + "I am happy to serve you. See you soon!"; + + public Ui() { + this(System.in); + } + + public Ui(InputStream in) { + this.input = new Scanner(in); + } + + public void printGreet() { + System.out.println(Message_GREETING); + } + + public void printBye() { + System.out.println(Message_Bye); + } + + public String getInput() { + return input.nextLine(); + } + + /** + * Prints out the food left: "apple" + */ + + public void replyFood() { + System.out.println("Ka To:"); + System.out.println(" "); + System.out.println("Only an apple pie"); + } + + /** + * Prints out the allowance left in the account; + */ + + public void replyAllowance() { + System.out.println("Ka To:"); + System.out.println(" "); + System.out.println("I have checked, it is 2000000 SGD"); + } + + /** + * Prints out the current task list + * + * @param taskList Task List to be read and printed + */ + public void printTaskList(TaskList taskList) { + System.out.println("Ka To:"); + System.out.println(" "); + System.out.println("This is your task list: \n"); + for (int i = 1; i < taskList.taskCounts + 1; i++) { + Task task = taskList.tasks.get(i - 1); + System.out.println("" + i + "." + task); + } + + } + + /** + * Prints out the message of empty list + */ + public void printEmptyList() { + System.out.println("Ka To:"); + System.out.println(" "); + System.out.println("Oops, the task list is empty"); + } + + /** + * Prints out the current task list + * + * @param added Task added successfully + * @param list Task List to be added into + */ + public void addTaskSuccessful(Task added, TaskList list) { + System.out.println("Ka To:"); + System.out.println(" "); + System.out.println("Congratulations! This is added! \n"); + System.out.println(added); + System.out.println(" You have " + list.getTaskCounts() + " tasks in the list"); + } + + /** + * Deletes the task from the list + * + * @param deleted Task deleted successfully + * @param list Task List to be deleted from + */ + public void deleteTaskSuccessful(Task deleted, TaskList list) { + System.out.println("Ka To:"); + System.out.println(" "); + System.out.println("Kay, this task now is deleted: \n"); + System.out.println(deleted); + System.out.println("Now you have " + list.getTaskCounts() + " tasks in the list"); + } + + /** + * Marks the task as done + * + * @param done Task to be changed status into Done + */ + public void markTaskDone(Task done) { + System.out.println("Ka To:"); + System.out.println(" "); + System.out.println("Congratulations! This is now marked as done!\n"); + System.out.println(done); + } + + public void failToMarkDone() { + System.out.println("Ka To:"); + System.out.println(" "); + System.out.println("Oops, please specify the task index to be marked"); + } + + /** + * Warns the user to include task index when finding task to mark done + */ + public void failToFindTask() { + System.out.println("Ka To:"); + System.out.println(" "); + System.out.println("Oops, please ensure the task index to be marked is correct"); + } + + /** + * Warns the user to include task index when deleting task + */ + public void failToDelete() { + System.out.println("Ka To:"); + System.out.println(" "); + System.out.println("Oops, please specify the task index to be deleted"); + } + + /** + * Warns the user to include task details + */ + public void failToFindDetails() { + System.out.println("Ka To:"); + System.out.println(" "); + System.out.println("Oops, please specify your task"); + } + + /** + * Warns the user to include task intended date + */ + + public void failToFindTime() { + System.out.println("Ka To:"); + System.out.println(" "); + System.out.println("Oops, please specify the time for the task"); + } + + /** + * Warns the user to key in correct commands + */ + + public void failToUnderstand() { + System.out.println("Ka To:"); + System.out.println(" "); + System.out.println("Sorry, I could not answer that .."); + } + + public void findDuplicates() { + System.out.println("Ka To:"); + System.out.println(" "); + System.out.println("Sorry, this task is already added.."); + } + + /** + * Prints the relevant task to the key word + * + * @param keyWord String keyword to be searched + * @param taskList TaskList taskList to be searched within + */ + + public void printFound(String keyWord, TaskList taskList) { + + for (int i = 1; i < taskList.taskCounts + 1; i++) { + + Task task = taskList.tasks.get(i - 1); + + if (task.toString().contains(keyWord)) { + System.out.println("" + i + "." + task); + } + + } + } +} \ No newline at end of file diff --git a/src/main/resources/images/KaTo.png b/src/main/resources/images/KaTo.png new file mode 100644 index 0000000000..be57b9ec49 Binary files /dev/null and b/src/main/resources/images/KaTo.png differ diff --git a/src/main/resources/images/Me.png b/src/main/resources/images/Me.png new file mode 100644 index 0000000000..4ac935f212 Binary files /dev/null and b/src/main/resources/images/Me.png differ diff --git a/src/main/resources/images/Sea.png b/src/main/resources/images/Sea.png new file mode 100644 index 0000000000..f57359cf60 Binary files /dev/null and b/src/main/resources/images/Sea.png differ diff --git a/src/main/resources/images/background.png b/src/main/resources/images/background.png new file mode 100644 index 0000000000..3576646837 Binary files /dev/null and b/src/main/resources/images/background.png differ diff --git a/src/main/resources/images/background2.png b/src/main/resources/images/background2.png new file mode 100644 index 0000000000..11c09ecd5c Binary files /dev/null and b/src/main/resources/images/background2.png differ diff --git a/src/test/java/duke/DeadlineTest.java b/src/test/java/duke/DeadlineTest.java new file mode 100644 index 0000000000..e67f41141e --- /dev/null +++ b/src/test/java/duke/DeadlineTest.java @@ -0,0 +1,18 @@ +package duke; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * Tests the deadline class + */ + +public class DeadlineTest { + @Test + public void DeadlineTest(){ + Deadline deadline = new Deadline(Task.TASK_DEADLINE, Task.DONE, "Homework", "2020-09-03"); + assertEquals(deadline.toString(), "[DeadLine][v] Homework/by: Sep 03 2020"); + + } +} diff --git a/src/test/java/duke/ToDoTest.java b/src/test/java/duke/ToDoTest.java new file mode 100644 index 0000000000..fdd3d7f042 --- /dev/null +++ b/src/test/java/duke/ToDoTest.java @@ -0,0 +1,18 @@ +package duke; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * Tests the ToDo class + */ + +public class ToDoTest { + @Test + public void ToDoTest(){ + ToDo toDo = new ToDo(Task.TASK_TODO, Task.DONE, "Homework"); + assertEquals(toDo.toString(), "[ToDo][v] Homework"); + + } +} diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 657e74f6e7..e69de29bb2 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,7 +0,0 @@ -Hello from - ____ _ -| _ \ _ _| | _____ -| | | | | | | |/ / _ \ -| |_| | |_| | < __/ -|____/ \__,_|_|\_\___| - diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index e69de29bb2..1c35af01c4 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -0,0 +1,10 @@ +food +allowance +tasks +todo ip project +deadline ip /by 2020-09-16 +event tp /at 2020-09-17 +done 2 +delete 2 +find ip +bye \ No newline at end of file diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index d0facc6310..00ed6a04cd 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -7,7 +7,7 @@ REM delete output from previous run del ACTUAL.TXT REM compile the code into the bin folder -javac -cp ..\src -Xlint:none -d ..\bin ..\src\main\java\Duke.java +javac -cp ..\src -Xlint:none -d ..\bin ..\src\main\java\duke.Duke.java IF ERRORLEVEL 1 ( echo ********** BUILD FAILURE ********** exit /b 1 @@ -15,7 +15,7 @@ IF ERRORLEVEL 1 ( REM no error here, errorlevel == 0 REM run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT -java -classpath ..\bin Duke < input.txt > ACTUAL.TXT +java -classpath ..\bin duke.Duke < input.txt > ACTUAL.TXT REM compare the output to the expected output FC ACTUAL.TXT EXPECTED.TXT diff --git a/text-ui-test/runtest.sh b/text-ui-test/runtest.sh old mode 100644 new mode 100755 index e169618a34..820e8ca74f --- a/text-ui-test/runtest.sh +++ b/text-ui-test/runtest.sh @@ -13,14 +13,14 @@ then fi # compile the code into the bin folder, terminates if error occurred -if ! javac -cp ../src -Xlint:none -d ../bin ../src/main/java/Duke.java +if ! javac -cp ../src -Xlint:none -d ../bin ../src/main/java/duke/Duke.java then echo "********** BUILD FAILURE **********" exit 1 fi # run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT -java -classpath ../bin Duke < input.txt > ACTUAL.TXT +java -classpath ../bin duke < input.txt > ACTUAL.TXT # convert to UNIX format cp EXPECTED.TXT EXPECTED-UNIX.TXT