diff --git a/.gitignore b/.gitignore index f69985ef1f..3b0f00be14 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,8 @@ +# Binary files +*.class +*.jar +*.exe + # IDEA files /.idea/ /out/ @@ -15,3 +20,9 @@ bin/ /text-ui-test/ACTUAL.txt text-ui-test/EXPECTED-UNIX.TXT + +# Ignore Gradle project-specific cache directory +.gradle + +# Ignore Gradle build output directory +build diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000000..d45da22c2c --- /dev/null +++ b/build.gradle @@ -0,0 +1,51 @@ +plugins { + id 'java' + id 'application' + id 'checkstyle' + id 'com.github.johnrengelman.shadow' version '5.1.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' + 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' + implementation 'org.junit.jupiter:junit-jupiter:5.8.1' +} + +repositories { + mavenCentral() +} + +checkstyle { + toolVersion = '8.29' +} + +application { + mainClassName = "jeff.main.Launcher" +} + +shadowJar { + archiveBaseName = "jeff" + archiveClassifier = null +} + +test { + useJUnitPlatform() +} + +run { + enableAssertions = true +} diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml new file mode 100644 index 0000000000..b1e659a3f8 --- /dev/null +++ b/config/checkstyle/checkstyle.xml @@ -0,0 +1,403 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/config/checkstyle/suppressions.xml b/config/checkstyle/suppressions.xml new file mode 100644 index 0000000000..dcaa1af3c3 --- /dev/null +++ b/config/checkstyle/suppressions.xml @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/data/tasks.txt b/data/tasks.txt new file mode 100644 index 0000000000..e986cd3ec8 --- /dev/null +++ b/data/tasks.txt @@ -0,0 +1,3 @@ +T | 1 | read book +E | 0 | project meeting | 2/01/2019 1800 +E | 0 | friend's concert | 10/02/2022 1900 diff --git a/docs/README.md b/docs/README.md index 8077118ebe..9826da086e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2,28 +2,236 @@ ## Features -### Feature-ABC +### Create tasks -Description of the feature. +Jeff allows the tracking of 3 types of tasks: +- Todos: Task with no deadline. +- Deadlines: Task with a deadline. +- Events: Task with a specific timeframe. -### Feature-XYZ +### List tasks -Description of the feature. +Shows all tasks currently tracked by Jeff. + +### Find tasks + +Jeff allows the user to search through all the tasks, returning only +the ones that matches a given keyword. + +### Mark and Unmark task + +Jeff can keep track of what task are marked as done or not done. + +### Delete task + +Jeff can "forget" any task that the user doesn't want to track anymore. + +### Save tasks + +Jeff automatically saves any changes made to it's memory. + +### Storing of notes + +Jeff also allows store of short notes to prevent the user from forgetting +the important things. ## Usage -### `Keyword` - Describe action +### `todo` - Adds a ToDo task + +Adds a ToDo task for Jeff to keep track. + +Example of usage: + +`todo homework` + +Expected outcome: + +Jeff would respond with a confirmation message, stating the task added and the +amount of task tracked by Jeff. + +``` +Got it. I've added this task: + [T][ ] homework +Now you have 1 task(s) in the list. +``` +### `deadline` - Adds a Deadline task + +Adds a Deadline task for Jeff to keep track. + +Example of usage: + +`deadline project meeting /by 20-02-2020 1800` + +Expected outcome: + +Jeff would respond with a confirmation message, stating the task added and the +amount of task tracked by Jeff. + +``` +Got it. I've added this task: + [D][ ] project meeting (by: Feb 20 2022 06:00 pm) +Now you have 2 task(s) in the list. +``` +### `event` - Adds a Event task + +Adds a Event task for Jeff to keep track. + +Example of usage: + +`event friend's concert /at 15-02-2020 2100` + +Expected outcome: + +Jeff would respond with a confirmation message, stating the task added and the +amount of task tracked by Jeff. + +``` +Got it. I've added this task: + [E][ ] friend's concert (by: Feb 15 2022 09:00 pm) +Now you have 3 task(s) in the list. +``` +### `list` - List out all the tasks + +Show all the tasks currently being tracked by Jeff. + +Example of usage: + +`list` + +Expected outcome: + +Jeff list out all the task indexed by the order of creation. + +``` + 1.[T][ ] homework + 2.[D][ ] project meeting (by: Feb 20 2022 06:00 pm) + 3.[E][ ] friend's concert (by: Feb 15 2022 09:00 pm) +``` +### `find` - Find matching tasks + +Return all tasks matching a keyword given by the user. + +Example of usage: + +`find project` + +Expected outcome: + +Jeff list out all the task with the keyword 'project' in it. + +``` +Here are the matching tasks in your list: + 1.[D][ ] project meeting (by: Feb 20 2022 06:00 pm) +``` +### `mark` - Mark a specific task as done -Describe the action and its outcome. +Mark a specific task as done based on the index given. Example of usage: -`keyword (optional arguments)` +`mark 2` Expected outcome: -Description of the outcome. +Jeff would mark a 'X' on the second box. ``` -expected output +Nice! I've marked this task as done: + [D][X] project meeting (by: Feb 20 2022 06:00 pm) +``` +### `unmark` - Unmark a specific task as not done + +Unmark a specific task as not done based on the index given. + +Example of usage: + +`unmark 2` + +Expected outcome: + +Jeff would mark a ' ' on the second box. + +``` +OK, I've marked this task as not done yet: + [D][ ] project meeting (by: Feb 20 2022 06:00 pm) +``` +### `delete` - Delete a specific task + +Delete a specific task as not done based on the index given. + +Example of usage: + +`delete 2` + +Expected outcome: + +Jeff would 'forget' the task entirely. + +``` +Noted. I've removed this task: + [D][ ] project meeting (by: Feb 20 2022 06:00 pm) +Now you have 2 task(s) in the list. +``` +### `note` - Add to note + +Add user input into note. + +Example of usage: + +`note 2 + 2 = 4` + +Expected outcome: + +Jeff would respond with a confirmation message, stating the note that was added. + +``` +Added this note for you: + 2 + 2 = 4 +``` +### `note list` - List out all the notes + +Show all the notes that Jeff is currently 'holding'. + +Example of usage: + +`note list` + +Expected outcome: + +Jeff would respond all the notes he have, a new line for each note. + +``` +These are your notes: + 2 + 2 = 4 +``` +### `note clear` - Clear all the notes + +Delete all the notes Jeff is 'holding'. + +Example of usage: + +`note clear` + +Expected outcome: + +Jeff would delete all the note he has. + +``` +I've cleared all your notes for you! +``` +### `bye` - Exit the Jeff program + +Ends the Jeff program. + +Example of usage: + +`bye` + +Expected outcome: + +Jeff would return a goodbye message, and promptly closes the program in 2 seconds. + ``` +Bye, my name is Jeff +``` \ No newline at end of file diff --git a/docs/Ui.png b/docs/Ui.png new file mode 100644 index 0000000000..72389cc5cd Binary files /dev/null and b/docs/Ui.png differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..b7c8c5dbf5 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000000..2fe81a7d95 --- /dev/null +++ b/gradlew @@ -0,0 +1,183 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000000..62bd9b9cce --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,103 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java deleted file mode 100644 index 5d313334cc..0000000000 --- a/src/main/java/Duke.java +++ /dev/null @@ -1,10 +0,0 @@ -public class Duke { - public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - } -} diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..a3489298bc --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: jeff.main.Jeff + diff --git a/src/main/java/jeff/command/AddNoteCommand.java b/src/main/java/jeff/command/AddNoteCommand.java new file mode 100644 index 0000000000..2828242d3e --- /dev/null +++ b/src/main/java/jeff/command/AddNoteCommand.java @@ -0,0 +1,27 @@ +package jeff.command; + +import jeff.main.JeffException; +import jeff.note.Note; +import jeff.storage.Storage; +import jeff.task.TaskList; +import jeff.ui.Ui; + +public class AddNoteCommand extends Command { + + private String body; + + public AddNoteCommand(String body) { + this.body = body; + } + @Override + public String execute(TaskList tasks, Note notes, Ui ui, Storage storage) throws JeffException { + notes.add(body); + String response = ui.showNoteAdded(body); + return response; + } + + @Override + public boolean isExit() { + return false; + } +} diff --git a/src/main/java/jeff/command/ByeCommand.java b/src/main/java/jeff/command/ByeCommand.java new file mode 100644 index 0000000000..f65d7dbef3 --- /dev/null +++ b/src/main/java/jeff/command/ByeCommand.java @@ -0,0 +1,38 @@ +package jeff.command; + +import jeff.note.Note; +import jeff.storage.Storage; +import jeff.task.TaskList; +import jeff.ui.Ui; + +/** + * ByeCommand class is a Command that contains instructions + * to run when user wants to exit the program. + */ +public class ByeCommand extends Command { + + /** + * Say "bye" to the user. + * + * @param tasks TaskList containing all the tasks. + * @param notes Contains all the notes. + * @param ui Ui class for invoking user feedback. + * @param storage Storage class used to save files. + * @return goodbye response. + */ + @Override + public String execute(TaskList tasks, Note notes, Ui ui, Storage storage) { + String response = ui.showBye(); + return response; + } + + /** + * Used to exit the Jeff program. + * + * @return true to exit the while loop. + */ + @Override + public boolean isExit() { + return true; + } +} diff --git a/src/main/java/jeff/command/ClearNoteCommand.java b/src/main/java/jeff/command/ClearNoteCommand.java new file mode 100644 index 0000000000..0bf88aa250 --- /dev/null +++ b/src/main/java/jeff/command/ClearNoteCommand.java @@ -0,0 +1,21 @@ +package jeff.command; + +import jeff.main.JeffException; +import jeff.note.Note; +import jeff.storage.Storage; +import jeff.task.TaskList; +import jeff.ui.Ui; + +public class ClearNoteCommand extends Command { + @Override + public String execute(TaskList tasks, Note notes, Ui ui, Storage storage) throws JeffException { + notes.clear(); + String response = ui.showNoteCleared(); + return response; + } + + @Override + public boolean isExit() { + return false; + } +} diff --git a/src/main/java/jeff/command/Command.java b/src/main/java/jeff/command/Command.java new file mode 100644 index 0000000000..2f5c5e4a52 --- /dev/null +++ b/src/main/java/jeff/command/Command.java @@ -0,0 +1,17 @@ +package jeff.command; + +import jeff.main.JeffException; +import jeff.note.Note; +import jeff.storage.Storage; +import jeff.task.TaskList; +import jeff.ui.Ui; + +/** + * Command class acts as a format for other Command classes. + */ +public abstract class Command { + + public abstract String execute(TaskList tasks, Note notes, Ui ui, Storage storage) throws JeffException; + + public abstract boolean isExit(); +} diff --git a/src/main/java/jeff/command/DeadlineCommand.java b/src/main/java/jeff/command/DeadlineCommand.java new file mode 100644 index 0000000000..b1b183aea1 --- /dev/null +++ b/src/main/java/jeff/command/DeadlineCommand.java @@ -0,0 +1,61 @@ +package jeff.command; + +import jeff.main.JeffException; +import jeff.note.Note; +import jeff.storage.Storage; +import jeff.task.Deadline; +import jeff.task.Task; +import jeff.task.TaskList; +import jeff.ui.Ui; + +/** + * DeadlineCommand class is a Command that contains instructions + * to run when user wants to add a new Deadline task. + */ +public class DeadlineCommand extends Command { + + private String description; + private String dateInfo; + + /** + * Constructor of DeadlineCommand that stores the description + * and dateInfo to be used in the creation of Deadline object. + * + * @param description Name of the task. + * @param dateInfo End date of the task. + */ + public DeadlineCommand(String description, String dateInfo) { + this.description = description; + this.dateInfo = dateInfo; + } + + /** + * Creates a new Deadline task and store it into the task list and feedback to the user. + * + * @param tasks TaskList containing all the tasks. + * @param notes Contains all the notes. + * @param ui Ui class for invoking user feedback. + * @param storage Storage class used to save files. + * @return confirmation response that a new deadline has been added. + * @throws JeffException When no available format is available + * to parse dateInfo or file cannot be saved. + */ + @Override + public String execute(TaskList tasks, Note notes, Ui ui, Storage storage) throws JeffException { + Task currTask = new Deadline(description, dateInfo); + tasks.add(currTask); + storage.save(tasks); + String response = ui.showAdded(currTask.toString(), tasks.size()); + return response; + } + + /** + * Used to exit the Jeff program. + * + * @return false to keep running. + */ + @Override + public boolean isExit() { + return false; + } +} diff --git a/src/main/java/jeff/command/DeleteCommand.java b/src/main/java/jeff/command/DeleteCommand.java new file mode 100644 index 0000000000..22d044aca9 --- /dev/null +++ b/src/main/java/jeff/command/DeleteCommand.java @@ -0,0 +1,62 @@ +package jeff.command; + +import jeff.main.JeffException; +import jeff.note.Note; +import jeff.storage.Storage; +import jeff.task.TaskList; +import jeff.ui.Ui; + +/** + * DeleteCommand class is a Command that contains instructions + * to run when user wants to delete a specific task. + */ +public class DeleteCommand extends Command { + + private int index; + + /** + * Constructor of DeleteCommand stores the index in index 0 format. + * + * @param body Position of the task to delete. + */ + public DeleteCommand(String body) { + this.index = Integer.parseInt(body) - 1; + } + + /** + * Deletes the Task according to index given by the user if available. + * + * @param tasks TaskList containing all the tasks. + * @param notes Contains all the notes. + * @param ui Ui class for invoking user feedback. + * @param storage Storage class used to save files. + * @return confirmation response that a task has been deleted. + * @throws JeffException When index of task to delete is + * out of bounds or file cannot be saved. + */ + @Override + public String execute(TaskList tasks, Note notes, Ui ui, Storage storage) throws JeffException { + try { + tasks.getAt(index); + } catch (IndexOutOfBoundsException e) { + int temp = index + 1; + throw new JeffException(" ☹ OOPS!!! The task you want to delete at index " + + temp + " is out of bounds," + + "please double check the index number"); + } + String response = ui.showDelete(tasks.getString(index), tasks.size() - 1); + tasks.delete(index); + storage.save(tasks); + return response; + } + + /** + * Used to exit the Jeff program. + * + * @return false to keep running. + */ + @Override + public boolean isExit() { + return false; + } +} diff --git a/src/main/java/jeff/command/EventCommand.java b/src/main/java/jeff/command/EventCommand.java new file mode 100644 index 0000000000..fdad2a7c09 --- /dev/null +++ b/src/main/java/jeff/command/EventCommand.java @@ -0,0 +1,61 @@ +package jeff.command; + +import jeff.main.JeffException; +import jeff.note.Note; +import jeff.storage.Storage; +import jeff.task.Event; +import jeff.task.Task; +import jeff.task.TaskList; +import jeff.ui.Ui; + +/** + * EventCommand class is a Command that contains instructions + * to run when user wants to add a new Event task. + */ +public class EventCommand extends Command { + + private String description; + private String dateInfo; + + /** + * Constructor of EventCommand that stores the description + * and dateInfo to be used in the creation of Event object. + * + * @param description Name of the task. + * @param dateInfo Date of the task. + */ + public EventCommand(String description, String dateInfo) { + this.description = description; + this.dateInfo = dateInfo; + } + + /** + * Creates a new Event task and store it into the task list and feedback to the user. + * + * @param tasks TaskList containing all the tasks. + * @param notes Contains all the notes. + * @param ui Ui class for invoking user feedback. + * @param storage Storage class used to save files. + * @return confirmation response that a new event has been added. + * @throws JeffException When no available format is available + * to parse dateInfo or file cannot be saved. + */ + @Override + public String execute(TaskList tasks, Note notes, Ui ui, Storage storage) throws JeffException { + Task currTask = new Event(description, dateInfo); + tasks.add(currTask); + storage.save(tasks); + String response = ui.showAdded(currTask.toString(), tasks.size()); + return response; + } + + /** + * Used to exit the Jeff program. + * + * @return false to keep running. + */ + @Override + public boolean isExit() { + return false; + } +} diff --git a/src/main/java/jeff/command/FindCommand.java b/src/main/java/jeff/command/FindCommand.java new file mode 100644 index 0000000000..96126bc241 --- /dev/null +++ b/src/main/java/jeff/command/FindCommand.java @@ -0,0 +1,85 @@ +package jeff.command; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import jeff.note.Note; +import jeff.storage.Storage; +import jeff.task.TaskList; +import jeff.ui.Ui; + +/** + * FindCommand class is a Command that contains instructions + * to run when user wants to find tasks with matching keywords. + */ +public class FindCommand extends Command { + + private String description; + + /** + * Constructor of MarkCommand that stores the input string to be checked into description. + * + * @param body String to be found, input from user. + */ + public FindCommand(String body) { + this.description = body; + } + + /** + * Check through all the Tasks in the TaskList and check if they + * match with the keyword, if so set them up to print. + * + * @param tasks TaskList containing all the tasks. + * @param notes Contains all the notes. + * @param ui Ui class for invoking user feedback. + * @param storage Storage class used to save files. + * @return list of task that matches the user input. + */ + @Override + public String execute(TaskList tasks, Note notes, Ui ui, Storage storage) { + String response; + if (tasks.isEmpty()) { + response = ui.showEmptyListFound(); + } else { + StringBuilder taskStrings = new StringBuilder(); + int currCounter = 1; + + // Store string the user want to find in the list. + String toBeFound = description; + Pattern pattern = Pattern.compile(toBeFound); + + for (int n = 0; n < tasks.size(); n++) { + + // Store description of this task. + String toBeChecked = tasks.getAt(n).getDescription(); + + // Check if the string to be found is found in the description to be checked. + Matcher matcher = pattern.matcher(toBeChecked); + boolean isFound = matcher.find(); + + // If found, store to print it out, else skip. + if (isFound) { + String currTaskString = currCounter + "." + tasks.getString(n) + "\n"; + taskStrings.append(Ui.addPrefix(currTaskString)); + currCounter++; + } + } + if (taskStrings.length() == 0) { + response = ui.showNoneFound(toBeFound); + } else { + response = ui.showFoundList(taskStrings.toString()); + } + } + return response; + } + + /** + * Used to exit the Jeff program. + * + * @return false to keep running. + */ + @Override + public boolean isExit() { + return false; + } +} diff --git a/src/main/java/jeff/command/HelpCommand.java b/src/main/java/jeff/command/HelpCommand.java new file mode 100644 index 0000000000..9b5d105817 --- /dev/null +++ b/src/main/java/jeff/command/HelpCommand.java @@ -0,0 +1,38 @@ +package jeff.command; + +import jeff.note.Note; +import jeff.storage.Storage; +import jeff.task.TaskList; +import jeff.ui.Ui; + +/** + * HelpCommand class is a Command that contains instructions + * to run when user inputs an invalid command. + */ +public class HelpCommand extends Command { + + /** + * Helps the user find available commands. + * + * @param tasks TaskList containing all the tasks. + * @param notes Contains all the notes. + * @param ui Ui class for invoking user feedback. + * @param storage Storage class used to save files. + * @return points to the readme.txt to help the users. + */ + @Override + public String execute(TaskList tasks, Note notes, Ui ui, Storage storage) { + String response = ui.showHelp(); + return response; + } + + /** + * Used to exit the Jeff program. + * + * @return false to keep running. + */ + @Override + public boolean isExit() { + return false; + } +} diff --git a/src/main/java/jeff/command/ListCommand.java b/src/main/java/jeff/command/ListCommand.java new file mode 100644 index 0000000000..89c1813d9f --- /dev/null +++ b/src/main/java/jeff/command/ListCommand.java @@ -0,0 +1,49 @@ +package jeff.command; + +import jeff.note.Note; +import jeff.storage.Storage; +import jeff.task.TaskList; +import jeff.ui.Ui; + +/** + * ListCommand class is a Command that contains instructions + * to run when user wants to list out every task. + */ +public class ListCommand extends Command { + + /** + * Passes the string to print to ui class to print out every entry of the list if any. + * + * @param tasks TaskList containing all the tasks. + * @param notes Contains all the notes. + * @param ui Ui class for invoking user feedback. + * @param storage Storage class used to save files. + * @return list of all tasks. + */ + @Override + public String execute(TaskList tasks, Note notes, Ui ui, Storage storage) { + String response; + if (tasks.isEmpty()) { + response = ui.showEmptyList(); + } else { + StringBuilder taskStrings = new StringBuilder(); + for (int n = 0; n < tasks.size(); n++) { + int temp = n + 1; + String currTaskString = temp + "." + tasks.getString(n) + "\n"; + taskStrings.append(Ui.addPrefix(currTaskString)); + } + response = ui.showList(taskStrings.toString()); + } + return response; + } + + /** + * Used to exit the Jeff program. + * + * @return false to keep running. + */ + @Override + public boolean isExit() { + return false; + } +} diff --git a/src/main/java/jeff/command/ListNoteCommand.java b/src/main/java/jeff/command/ListNoteCommand.java new file mode 100644 index 0000000000..32c4341850 --- /dev/null +++ b/src/main/java/jeff/command/ListNoteCommand.java @@ -0,0 +1,25 @@ +package jeff.command; + +import jeff.main.JeffException; +import jeff.note.Note; +import jeff.storage.Storage; +import jeff.task.TaskList; +import jeff.ui.Ui; + +public class ListNoteCommand extends Command { + @Override + public String execute(TaskList tasks, Note notes, Ui ui, Storage storage) throws JeffException { + String response; + if (notes.isEmpty()) { + response = ui.showEmptyNote(); + } else { + response = ui.showNote(notes.toString()); + } + return response; + } + + @Override + public boolean isExit() { + return false; + } +} diff --git a/src/main/java/jeff/command/MarkCommand.java b/src/main/java/jeff/command/MarkCommand.java new file mode 100644 index 0000000000..6df9361c3e --- /dev/null +++ b/src/main/java/jeff/command/MarkCommand.java @@ -0,0 +1,62 @@ +package jeff.command; + +import jeff.main.JeffException; +import jeff.note.Note; +import jeff.storage.Storage; +import jeff.task.TaskList; +import jeff.ui.Ui; + +/** + * MarkCommand class is a Command that contains instructions + * to run when user wants to mark a specific task as done. + */ +public class MarkCommand extends Command { + + private int index; + + /** + * Constructor of MarkCommand stores the index in index 0 format. + * + * @param body Position of the task to mark as done. + */ + public MarkCommand(String body) { + this.index = Integer.parseInt(body) - 1; + } + + /** + * Marks the Task as done according to index given by the user if available. + * + * @param tasks TaskList containing all the tasks. + * @param notes Contains all the notes. + * @param ui Ui class for invoking user feedback. + * @param storage Storage class used to save files. + * @return confirmation response that a task has been marked. + * @throws JeffException When index of task to mark as done is + * out of bounds or file cannot be saved. + */ + @Override + public String execute(TaskList tasks, Note notes, Ui ui, Storage storage) throws JeffException { + try { + tasks.getAt(index); + } catch (IndexOutOfBoundsException e) { + int temp = index + 1; + throw new JeffException(" ☹ OOPS!!! The task you want to mark as done at index " + + temp + " is out of bounds," + + "please double check the index number"); + } + tasks.mark(index); + String response = ui.showMark(tasks.getString(index)); + storage.save(tasks); + return response; + } + + /** + * Used to exit the Jeff program. + * + * @return false to keep running. + */ + @Override + public boolean isExit() { + return false; + } +} diff --git a/src/main/java/jeff/command/TodoCommand.java b/src/main/java/jeff/command/TodoCommand.java new file mode 100644 index 0000000000..93e0ea9e2e --- /dev/null +++ b/src/main/java/jeff/command/TodoCommand.java @@ -0,0 +1,57 @@ +package jeff.command; + +import jeff.main.JeffException; +import jeff.note.Note; +import jeff.storage.Storage; +import jeff.task.Task; +import jeff.task.TaskList; +import jeff.task.Todo; +import jeff.ui.Ui; + +/** + * TodoCommand class is a Command that contains instructions + * to run when user wants to add a new Todo task. + */ +public class TodoCommand extends Command { + + private String description; + + /** + * Constructor of TodoCommand that stores the description + * to be used in the creation of Todo object. + * + * @param body Name of the task. + */ + public TodoCommand(String body) { + this.description = body; + } + + /** + * Creates a new Todo task and store it into the task list and feedback to the user. + * + * @param tasks TaskList containing all the tasks. + * @param notes Contains all the notes. + * @param ui Ui class for invoking user feedback. + * @param storage Storage class used to save files. + * @return confirmation response that a new todo has been added. + * @throws JeffException When file cannot be saved. + */ + @Override + public String execute(TaskList tasks, Note notes, Ui ui, Storage storage) throws JeffException { + Task currTask = new Todo(description); + tasks.add(currTask); + String response = ui.showAdded(currTask.toString(), tasks.size()); + storage.save(tasks); + return response; + } + + /** + * Used to exit the Jeff program. + * + * @return false to keep running. + */ + @Override + public boolean isExit() { + return false; + } +} diff --git a/src/main/java/jeff/command/UnmarkCommand.java b/src/main/java/jeff/command/UnmarkCommand.java new file mode 100644 index 0000000000..396cad995a --- /dev/null +++ b/src/main/java/jeff/command/UnmarkCommand.java @@ -0,0 +1,62 @@ +package jeff.command; + +import jeff.main.JeffException; +import jeff.note.Note; +import jeff.storage.Storage; +import jeff.task.TaskList; +import jeff.ui.Ui; + +/** + * UnmarkCommand class is a Command that contains instructions + * to run when user wants to mark a specific task as not done. + */ +public class UnmarkCommand extends Command { + + private int index; + + /** + * Constructor of UnmarkCommand stores the index in index 0 format. + * + * @param body Position of the task to mark as not done. + */ + public UnmarkCommand(String body) { + this.index = Integer.parseInt(body) - 1; + } + + /** + * Marks the Task as not done according to index given by the user if available. + * + * @param tasks TaskList containing all the tasks. + * @param notes Contains all the notes. + * @param ui Ui class for invoking user feedback. + * @param storage Storage class used to save files. + * @return confirmation response that a task has been unmarked. + * @throws JeffException When index of task to mark as not done + * is out of bounds or file cannot be saved. + */ + @Override + public String execute(TaskList tasks, Note notes, Ui ui, Storage storage) throws JeffException { + try { + tasks.getAt(index); + } catch (IndexOutOfBoundsException e) { + int temp = index + 1; + throw new JeffException(" ☹ OOPS!!! The task you want to mark as not done at index " + + temp + " is out of bounds," + + "please double check the index number"); + } + tasks.unmark(index); + String response = ui.showUnmark(tasks.getString(index)); + storage.save(tasks); + return response; + } + + /** + * Used to exit the Jeff program. + * + * @return false to keep running. + */ + @Override + public boolean isExit() { + return false; + } +} diff --git a/src/main/java/jeff/main/Jeff.java b/src/main/java/jeff/main/Jeff.java new file mode 100644 index 0000000000..c51bf0a878 --- /dev/null +++ b/src/main/java/jeff/main/Jeff.java @@ -0,0 +1,54 @@ +package jeff.main; + +import jeff.command.Command; +import jeff.note.Note; +import jeff.parser.Parser; +import jeff.storage.Storage; +import jeff.task.TaskList; +import jeff.ui.Ui; + +/** + * Jeff class is a task manager with a variety of commands. + * To see the full list of commands, check the readme.txt. + */ +public class Jeff { + + private Storage storage; + private TaskList tasks; + private Ui ui; + private Note notes; + + /** + * Constructor for Jeff class. + * + * @param filePath Path of saved file. + */ + public Jeff(String filePath) { + ui = new Ui(); + notes = new Note(); + storage = new Storage(filePath); + try { + tasks = new TaskList(storage.load()); + } catch (JeffException e) { + ui.showError(e.getMessage()); + tasks = new TaskList(); + } + } + + /** + * Get the response for Jeff to display in the GUI, response can be + * either a confirmation that the intended task is done, or in the case an exception + * was thrown, display what went wrong. + * + * @param input user input. + * @return Jeff's response. + */ + public String getResponse(String input) { + try { + Command c = Parser.parse(input); + return c.execute(tasks, notes, ui, storage); + } catch (JeffException e) { + return ui.showError(e.getMessage()); + } + } +} diff --git a/src/main/java/jeff/main/JeffException.java b/src/main/java/jeff/main/JeffException.java new file mode 100644 index 0000000000..999fa35f17 --- /dev/null +++ b/src/main/java/jeff/main/JeffException.java @@ -0,0 +1,18 @@ +package jeff.main; + +/** + * JeffException class is a custom exception class to handle + * problems that might occur. + */ +public class JeffException extends Exception { + + /** + * Constructor for the JeffException class. + * + * @param errorMessage Exception message. + */ + public JeffException(String errorMessage) { + super(errorMessage); + } + +} diff --git a/src/main/java/jeff/main/Launcher.java b/src/main/java/jeff/main/Launcher.java new file mode 100644 index 0000000000..79e36ea480 --- /dev/null +++ b/src/main/java/jeff/main/Launcher.java @@ -0,0 +1,12 @@ +package jeff.main; + +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/jeff/main/Main.java b/src/main/java/jeff/main/Main.java new file mode 100644 index 0000000000..6041857786 --- /dev/null +++ b/src/main/java/jeff/main/Main.java @@ -0,0 +1,33 @@ +package jeff.main; + +import java.io.IOException; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Scene; +import javafx.scene.layout.AnchorPane; +import javafx.stage.Stage; +import jeff.ui.MainWindow; + +/** + * A GUI for Jeff using FXML. + */ +public class Main extends Application { + + private Jeff jeff = new Jeff("data/tasks.txt"); + @Override + public void start(Stage stage) { + try { + FXMLLoader fxmlLoader = new FXMLLoader(Main.class.getResource("/view/MainWindow.fxml")); + stage.setTitle("Jeff"); + stage.setResizable(false); + AnchorPane ap = fxmlLoader.load(); + Scene scene = new Scene(ap); + stage.setScene(scene); + fxmlLoader.getController().setJeff(jeff); + stage.show(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/jeff/note/Note.java b/src/main/java/jeff/note/Note.java new file mode 100644 index 0000000000..d79a1f4a6a --- /dev/null +++ b/src/main/java/jeff/note/Note.java @@ -0,0 +1,47 @@ +package jeff.note; + +import jeff.ui.Ui; + +/** + * Note class stores all the user entered notes in a StringBuilder object. + */ +public class Note { + private StringBuilder notes; + + /** + * Constructor for Note class. + */ + public Note() { + this.notes = new StringBuilder(); + } + + /** + * Appends a given string onto the StringBuilder object. + * + * @param str string to be added. + */ + public void add(String str) { + String newEntry = Ui.addPrefix(str) + "\n"; + notes.append(newEntry); + } + + /** + * Delete all entries in the note. + */ + public void clear() { + notes.setLength(0); + } + + /** + * Checks if the note is empty. + * + * @return if the StringBuilder is empty + */ + public boolean isEmpty() { + return notes.length() == 0; + } + + public String toString() { + return notes.toString(); + } +} diff --git a/src/main/java/jeff/parser/DateParse.java b/src/main/java/jeff/parser/DateParse.java new file mode 100644 index 0000000000..f9ed028064 --- /dev/null +++ b/src/main/java/jeff/parser/DateParse.java @@ -0,0 +1,80 @@ +package jeff.parser; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; +import java.util.ArrayList; + +import jeff.main.JeffException; + +/** + * DateParse class parse a varying format of dates into a LocalDate object. + */ +public class DateParse { + + private LocalDate date; + private boolean isFound = false; + + // All the available formats Jeff accepts as dates + private DateTimeFormatter format1 = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + private DateTimeFormatter format2 = DateTimeFormatter.ofPattern("yyyy/MM/dd"); + private DateTimeFormatter format3 = DateTimeFormatter.ofPattern("yyyy-MM-d"); + private DateTimeFormatter format4 = DateTimeFormatter.ofPattern("yyyy/MM/d"); + private DateTimeFormatter format5 = DateTimeFormatter.ofPattern("yyyy-M-d"); + private DateTimeFormatter format6 = DateTimeFormatter.ofPattern("yyyy/M/d"); + private DateTimeFormatter format7 = DateTimeFormatter.ofPattern("yyyy-M-dd"); + private DateTimeFormatter format8 = DateTimeFormatter.ofPattern("yyyy/M/dd"); + private DateTimeFormatter format9 = DateTimeFormatter.ofPattern("dd-MM-yyyy"); + private DateTimeFormatter format10 = DateTimeFormatter.ofPattern("dd/MM/yyyy"); + private DateTimeFormatter format11 = DateTimeFormatter.ofPattern("d-MM-yyyy"); + private DateTimeFormatter format12 = DateTimeFormatter.ofPattern("d/MM/yyyy"); + private DateTimeFormatter format13 = DateTimeFormatter.ofPattern("d-M-yyyy"); + private DateTimeFormatter format14 = DateTimeFormatter.ofPattern("d/M/yyyy"); + private DateTimeFormatter format15 = DateTimeFormatter.ofPattern("dd-M-yyyy"); + private DateTimeFormatter format16 = DateTimeFormatter.ofPattern("dd/M/yyyy"); + private ArrayList knownPatterns = new ArrayList(); + + /** + * Constructor for DateParse + * + * @param str String to be parsed into a LocalDate object + * @throws JeffException When no available format is available to parse date input. + */ + public DateParse(String str) throws JeffException { + knownPatterns.add(format1); + knownPatterns.add(format2); + knownPatterns.add(format3); + knownPatterns.add(format4); + knownPatterns.add(format5); + knownPatterns.add(format6); + knownPatterns.add(format7); + knownPatterns.add(format8); + knownPatterns.add(format9); + knownPatterns.add(format10); + knownPatterns.add(format11); + knownPatterns.add(format12); + knownPatterns.add(format13); + knownPatterns.add(format14); + knownPatterns.add(format15); + knownPatterns.add(format16); + + int curr = 0; + while ((!isFound) && curr < 16) { + try { + date = LocalDate.parse(str, knownPatterns.get(curr)); + isFound = true; + } catch (DateTimeParseException e) { + curr++; + } + } + + if ((!isFound) && curr == 16) { + throw new JeffException("Sorry but Jeff does not understand the date format given\n" + + "Please check the readme.txt for the acceptable formats."); + } + } + + public String toString() { + return date.format(DateTimeFormatter.ofPattern("MMM dd yyyy")); + } +} diff --git a/src/main/java/jeff/parser/Parser.java b/src/main/java/jeff/parser/Parser.java new file mode 100644 index 0000000000..ca25ff4d1e --- /dev/null +++ b/src/main/java/jeff/parser/Parser.java @@ -0,0 +1,149 @@ +package jeff.parser; + +import jeff.command.AddNoteCommand; +import jeff.command.ByeCommand; +import jeff.command.ClearNoteCommand; +import jeff.command.Command; +import jeff.command.DeadlineCommand; +import jeff.command.DeleteCommand; +import jeff.command.EventCommand; +import jeff.command.FindCommand; +import jeff.command.HelpCommand; +import jeff.command.ListCommand; +import jeff.command.ListNoteCommand; +import jeff.command.MarkCommand; +import jeff.command.TodoCommand; +import jeff.command.UnmarkCommand; +import jeff.main.JeffException; + +/** + * Parser class is used to parse the raw input from the user + * and call the correct Command class while handling exceptions. + */ +public class Parser { + private static boolean isExit = false; + /** + * Parses the user input and calls the correct command + * + * @param fullCommand Raw input from user. + * @return Returns the command according to what the user wants. + * @throws JeffException When certain information are missing, or formatting is wrong. + */ + public static Command parse(String fullCommand) throws JeffException { + String[] splitCommand = fullCommand.split(" ", 2); + String keyword = splitCommand[0]; + String body = checkValidInfo(splitCommand); + int len = splitCommand.length; + + // Perform the correct instructions according to the keyword. + switch(keyword) { + case ("bye"): + isExit = true; + return new ByeCommand(); + case ("list") : + return new ListCommand(); + case ("mark"): + checkValidFirstEntry(len, " ☹ OOPS!!! Please tell me the task's" + + " index number so that I can mark it as done."); + return new MarkCommand(body); + case ("unmark"): + checkValidFirstEntry(len, " ☹ OOPS!!! Please tell me the task's" + + " index number so that I can mark it as not done."); + return new UnmarkCommand(body); + case ("todo"): + checkValidFirstEntry(len, " ☹ OOPS!!! The description of a todo cannot be empty."); + return new TodoCommand(body); + case ("deadline"): + checkValidFirstEntry(len, " ☹ OOPS!!! The description of a deadline cannot be empty."); + + String[] splitBody = body.split(" /by ", 2); + String description = splitBody[0]; + String dateInfo = checkValidInfo(splitBody); + int bodyLength = splitBody.length; + + checkValidDateTime(bodyLength, dateInfo, " ☹ OOPS!!! Please input a due date for this task"); + return new DeadlineCommand(description, dateInfo); + case ("event"): + checkValidFirstEntry(len, " ☹ OOPS!!! The description of a event cannot be empty."); + + splitBody = body.split(" /at ", 2); + description = splitBody[0]; + dateInfo = checkValidInfo(splitBody); + bodyLength = splitBody.length; + + checkValidDateTime(bodyLength, dateInfo, " ☹ OOPS!!! Please input a event date"); + return new EventCommand(description, dateInfo); + case ("delete"): + checkValidFirstEntry(len, " ☹ OOPS!!! Please tell me the task's" + + " index number so that I can delete it from the list."); + return new DeleteCommand(body); + case ("find"): + checkValidFirstEntry(len, " ☹ OOPS!!! Please tell me the keyword" + + " so that I know what you are looking for."); + return new FindCommand(body); + case ("note"): + checkValidFirstEntry(len, " ☹ OOPS!!! Please tell me what you want" + + " to be added into the notes."); + switch(body) { + case ("clear"): + return new ClearNoteCommand(); + case ("list"): + return new ListNoteCommand(); + default: + break; + } + return new AddNoteCommand(body); + default: + return new HelpCommand(); + } + } + + /** + * Checks if the user did input a value for the body. + * + * @param length Length of the parsed command. + * @param errorMessage Appropriate error message to throw. + * @throws JeffException When user left out the body of the command. + */ + private static void checkValidFirstEntry(int length, String errorMessage) throws JeffException { + if (length == 1) { + throw new JeffException(errorMessage); + } + } + + /** + * Prevent NullPointerException when declaring a variable that doesn't exist. + * + * @param arr Contains information of the desired return value, if it exist. + * @return Desired output if it exists. + */ + private static String checkValidInfo(String[] arr) { + if (arr.length > 1) { + return arr[1]; + } + return null; + } + + /** + * Checks if date and time information are given correctly. + * + * @param length Length of array containing date and time. + * @param dateInfo String containing date and time information. + * @param errorMessage Appropriate error message to throw. + * @throws JeffException When the date time element does not exist, or means nothing. + */ + private static void checkValidDateTime(int length, String dateInfo, String errorMessage) throws JeffException { + if (length == 1 || dateInfo.equals("") || dateInfo.equals(" ")) { + throw new JeffException(errorMessage); + } + } + + /** + * Returns if exit is requested. + * + * @return Boolean value of isExit. + */ + public static boolean isExit() { + return isExit; + } +} diff --git a/src/main/java/jeff/parser/TimeParse.java b/src/main/java/jeff/parser/TimeParse.java new file mode 100644 index 0000000000..648517c0b5 --- /dev/null +++ b/src/main/java/jeff/parser/TimeParse.java @@ -0,0 +1,27 @@ +package jeff.parser; + +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; + +/** + * TimeParse class parses a varying 4 digit military time into a 12 hour LocalTime object. + */ +public class TimeParse { + + private String timeStr; + private LocalTime time; + + /** + * Constructor of TimeParse. + * + * @param str String to be parsed into LocalTime object. + */ + public TimeParse(String str) { + this.timeStr = str.substring(0, 2) + ":" + str.substring(2); + time = LocalTime.parse(timeStr); + } + + public String toString() { + return time.format(DateTimeFormatter.ofPattern("hh:mm a")); + } +} diff --git a/src/main/java/jeff/storage/Storage.java b/src/main/java/jeff/storage/Storage.java new file mode 100644 index 0000000000..fb26196021 --- /dev/null +++ b/src/main/java/jeff/storage/Storage.java @@ -0,0 +1,160 @@ +package jeff.storage; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.time.format.DateTimeParseException; +import java.util.Scanner; + +import jeff.main.JeffException; +import jeff.task.Deadline; +import jeff.task.Event; +import jeff.task.Task; +import jeff.task.TaskList; +import jeff.task.Todo; + +/** + * Storage class for loading and saving from an external file. + */ +public class Storage { + + private String filePath; + + /** + * Constructor for Storage class. + * + * @param filePath Location of external file. + */ + public Storage(String filePath) { + this.filePath = filePath; + } + + /** + * Loads the contents of the external file into a TaskList if any. + * + * @return TaskList filled with the contents of the external file. + * @throws JeffException When no available format is available to parse dateInfo. + */ + public TaskList load() throws JeffException { + + File f = new File(filePath); + TaskList tasks = new TaskList(); + + // When the file or directory does not exist, create it. + Scanner sc; + try { + sc = new Scanner(f); + } catch (FileNotFoundException e) { + File parent = f.getParentFile(); + if (!parent.exists()) { + parent.mkdir(); + } + return tasks; + } + + // Look through every line on the external file and add to TaskList. + while (sc.hasNext()) { + String input = sc.nextLine(); + try { + String[] inputLine = input.split("\\| ", 4); + String type = inputLine[0]; + String done = inputLine[1]; + String name = inputLine[2]; + String time; + + // New task from the current line + Task curr; + // Check what type of task is this. + switch (type) { + case "T ": + curr = new Todo(name); + break; + case "D ": + time = inputLine[3]; + curr = new Deadline(name.substring(0, name.length() - 1), time); + break; + case "E ": + time = inputLine[3]; + curr = new Event(name.substring(0, name.length() - 1), time); + break; + default: + curr = null; + } + // Check if the task is marked as done. + switch (done) { + case "1 ": + curr.setMark(); + break; + case "0 ": + break; + default: + break; + } + // After all the necessary information, add it into the TaskList. + tasks.add(curr); + } catch (DateTimeParseException e) { + throw new JeffException("Invalid date time format at: " + input + + "Please refer to readme.txt for the available formats"); + } + } + sc.close(); + return tasks; + } + + /** + * Saves the current Tasks on the TaskList directly onto the filePath. + * + * @param tasks TaskList to be saved. + */ + public void save(TaskList tasks) throws JeffException { + + try { + FileWriter fw = new FileWriter(filePath); + + // For each task, store all its information into a string. + for (int n = 0; n < tasks.size(); n++) { + Task currTask = tasks.getAt(n); + String str = null; + String suffix = null; + + // Assign string values according to the type of Task. + switch (currTask.whatType()) { + case "T": + str = "T | "; + suffix = currTask.getDescription(); + break; + case "D": + str = "D | "; + Deadline tempD = (Deadline) currTask; + suffix = tempD.getDescription() + " | " + tempD.getOriginalDate(); + break; + case "E": + str = "E | "; + Event tempE = (Event) currTask; + suffix = tempE.getDescription() + " | " + tempE.getOriginalDate(); + break; + default: + break; + } + // Assign string values according to if the Task is done. + switch (currTask.getStatusIcon()) { + case "X": + str = str + "1 | "; + break; + case " ": + str = str + "0 | "; + break; + default: + break; + } + // Once all the information is extracted, write it into the file. + fw.write(str + suffix + System.lineSeparator()); + } + fw.close(); + } catch (IOException e) { + throw new JeffException("Please make sure that" + filePath + + " is available to write."); + } + } +} diff --git a/src/main/java/jeff/task/Deadline.java b/src/main/java/jeff/task/Deadline.java new file mode 100644 index 0000000000..6a48ce7b96 --- /dev/null +++ b/src/main/java/jeff/task/Deadline.java @@ -0,0 +1,65 @@ +package jeff.task; + +import jeff.main.JeffException; +import jeff.parser.DateParse; +import jeff.parser.TimeParse; + +/** + * Deadline class is a task customised to store end date of deadlines. + */ +public class Deadline extends Task { + + protected String dateInfo; + protected String originalDate; + protected DateParse date; + protected TimeParse time; + + /** + * Constructor for Deadline class. + * + * @param description Name of the Deadline. + * @param dateInfo Information for which this task is due. + * @throws JeffException When no available format is available to parse dateInfo. + */ + public Deadline(String description, String dateInfo) throws JeffException { + super(description); + this.originalDate = dateInfo; + String[] str = dateInfo.split(" ", 2); + String inputDate = str[0]; + String inputTime = str[1]; + assert inputDate.length() >= 8 : "Date input seems shorter than expected, expect 8 or more"; + assert inputTime.length() >= 4 : "Time input seems shorter than expected, expect 4 or more"; + this.date = new DateParse(str[0]); + this.time = new TimeParse(str[1]); + this.dateInfo = this.date.toString() + " " + this.time.toString(); + } + + /** + * Returns the identity of this Task class. + * + * @return D for Deadline. + */ + public String whatType() { + return "D"; + } + + /** + * Returns the original string of dateInfo. + * Used for saving to file. + * + * @return Original string of dateInfo. + */ + public String getOriginalDate() { + return this.originalDate; + } + + /** + * toString method specific for Deadline class, + * inherits toString() fromTask class while adding additional information. + * Like the type of task, [D], and date information. + */ + @Override + public String toString() { + return "[D]" + super.toString() + " (by: " + this.dateInfo + ")"; + } +} diff --git a/src/main/java/jeff/task/Event.java b/src/main/java/jeff/task/Event.java new file mode 100644 index 0000000000..5cf60bd5d4 --- /dev/null +++ b/src/main/java/jeff/task/Event.java @@ -0,0 +1,65 @@ +package jeff.task; + +import jeff.main.JeffException; +import jeff.parser.DateParse; +import jeff.parser.TimeParse; + +/** + * Event class is a task customised to store date of the Event. + */ +public class Event extends Task { + + protected String dateInfo; + protected String originalDate; + protected DateParse date; + protected TimeParse time; + + /** + * Constructor for Event class. + * + * @param description Name of the Event. + * @param dateInfo Information for which this task is due. + * @throws JeffException When no available format is available to parse dateInfo. + */ + public Event(String description, String dateInfo) throws JeffException { + super(description); + this.originalDate = dateInfo; + String[] str = dateInfo.split(" ", 2); + String inputDate = str[0]; + String inputTime = str[1]; + assert inputDate.length() >= 8 : "Date input seems shorter than expected, expect 8 or more"; + assert inputTime.length() >= 4 : "Time input seems shorter than expected, expect 4 or more"; + this.date = new DateParse(str[0]); + this.time = new TimeParse(str[1]); + this.dateInfo = this.date.toString() + " " + this.time.toString(); + } + + /** + * Returns the identity of this Task class. + * + * @return E for Event. + */ + public String whatType() { + return "E"; + } + + /** + * Returns the original string of dateInfo. + * Used for saving to file. + * + * @return Original string of dateInfo. + */ + public String getOriginalDate() { + return this.originalDate; + } + + /** + * toString method specific for Event class, + * inherits toString() fromTask class while adding additional information. + * Like the type of task, [E], and date information. + */ + @Override + public String toString() { + return "[E]" + super.toString() + " (at: " + this.dateInfo + ")"; + } +} diff --git a/src/main/java/jeff/task/Task.java b/src/main/java/jeff/task/Task.java new file mode 100644 index 0000000000..713a534e7c --- /dev/null +++ b/src/main/java/jeff/task/Task.java @@ -0,0 +1,59 @@ +package jeff.task; + +/** + * Task class acts as a format for other Task classes. + */ +public abstract class Task { + + protected String description; + protected boolean isDone; + + /** + * Constructor for Task class, set isDone to false by default. + * + * @param description Name of the task. + */ + public Task(String description) { + this.description = description; + this.isDone = false; + } + + /** + * Returns a string representation of if the task is done. + * + * @return "X" if task is done. + * " " if task is not done. + */ + public String getStatusIcon() { + return (isDone ? "X" : " "); // mark done task with X + } + + /** + * Returns a string representation of the description. + * + * @return Description of this task. + */ + public String getDescription() { + return description; + } + + /** + * Sets the current task to be done. + */ + public void setMark() { + isDone = true; + } + + /** + * Sets the current task to be not done. + */ + public void setUnmark() { + isDone = false; + } + + public abstract String whatType(); + + public String toString() { + return "[" + getStatusIcon() + "] " + this.description; + } +} diff --git a/src/main/java/jeff/task/TaskList.java b/src/main/java/jeff/task/TaskList.java new file mode 100644 index 0000000000..b58b5bc845 --- /dev/null +++ b/src/main/java/jeff/task/TaskList.java @@ -0,0 +1,101 @@ +package jeff.task; + +import java.util.ArrayList; + +/** + * TaskList class is used to store all the Task using an ArrayList + * while providing various methods to manipulate the entries. + */ +public class TaskList { + + private ArrayList tasks; + + /** + * Constructor of TaskList with no parameters. + */ + public TaskList() { + this.tasks = new ArrayList<>(); + } + + /** + * Constructor of TaskList with another TaskList as reference.. + */ + public TaskList(TaskList taskList) { + this.tasks = taskList.tasks; + } + + /** + * Returns the number of Tasks stored. + * + * @return Size of the ArrayList. + */ + public int size() { + return tasks.size(); + } + + /** + * Adds the current Task into the TaskList. + * + * @param currTask Task to be stored. + */ + public void add(Task currTask) { + this.tasks.add(currTask); + } + + /** + * Deletes the Task at the index. + * + * @param num Index of Task to be deleted. + */ + public void delete(int num) { + this.tasks.remove(num); + } + + /** + * Marks the Task at the index as done. + * + * @param num Index of task to be marked as done. + */ + public void mark(int num) { + this.tasks.get(num).setMark(); + } + + /** + * Unmarks the Task at the index as not done. + * + * @param num Index of task to be marked as not done. + */ + public void unmark(int num) { + this.tasks.get(num).setUnmark(); + } + + /** + * Returns the Task at the given index. + * + * @param num Index of the Task to return. + * @return Task at the current index. + * @throws IndexOutOfBoundsException When Task at index is no available. + */ + public Task getAt(int num) throws IndexOutOfBoundsException { + return this.tasks.get(num); + } + + /** + * Returns the string of the Task at the given index. + * + * @param num Index of the String of Task to return. + * @return String representation of the Task. + */ + public String getString(int num) { + return this.tasks.get(num).toString(); + } + + /** + * Checks if the current TaskList is empty. + * + * @return Boolean value of if the TaskList is empty. + */ + public boolean isEmpty() { + return this.tasks.size() == 0; + } +} diff --git a/src/main/java/jeff/task/Todo.java b/src/main/java/jeff/task/Todo.java new file mode 100644 index 0000000000..62984458fb --- /dev/null +++ b/src/main/java/jeff/task/Todo.java @@ -0,0 +1,35 @@ +package jeff.task; + +/** + * Todo class is a task customised to store the descriptions of task to do. + */ +public class Todo extends Task { + + /** + * Constructor for Todo class. + * + * @param description Name of the to-do task. + */ + public Todo(String description) { + super(description); + } + + /** + * Returns the identity of this Task class. + * + * @return T for Event. + */ + public String whatType() { + return "T"; + } + + /** + * toString method specific for Todo class, + * inherits toString() fromTask class while adding additional information. + * Like the type of task, [T]. + */ + @Override + public String toString() { + return "[T]" + super.toString(); + } +} diff --git a/src/main/java/jeff/ui/DialogBox.java b/src/main/java/jeff/ui/DialogBox.java new file mode 100644 index 0000000000..c7fafb5c07 --- /dev/null +++ b/src/main/java/jeff/ui/DialogBox.java @@ -0,0 +1,57 @@ +package jeff.ui; + +import java.io.IOException; + +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; + +/** + * Contains the layout of DialogBox and what is in it. + */ +public class DialogBox extends HBox { + @FXML + private Label dialog; + @FXML + private ImageView displayPicture; + + private DialogBox(String text, Image pic) { + 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(pic); + } + + /** + * 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(String input, Image userPic) { + return new DialogBox(input, userPic); + } + + public static DialogBox getJeffDialog(String response, Image jeffPic) { + var db = new DialogBox(response, jeffPic); + db.flip(); + return db; + } +} diff --git a/src/main/java/jeff/ui/MainWindow.java b/src/main/java/jeff/ui/MainWindow.java new file mode 100644 index 0000000000..6a4384a871 --- /dev/null +++ b/src/main/java/jeff/ui/MainWindow.java @@ -0,0 +1,71 @@ +package jeff.ui; + +import javafx.animation.PauseTransition; +import javafx.application.Platform; +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.util.Duration; +import jeff.main.Jeff; +import jeff.parser.Parser; + +/** + * 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 Jeff jeff; + + private Image userImage = new Image(this.getClass().getResourceAsStream("/images/User.png")); + private Image jeffImage = new Image(this.getClass().getResourceAsStream("/images/Jeff.png")); + + /** + * Initialised the first message with a greeting. + */ + @FXML + public void initialize() { + dialogContainer.getChildren().add( + DialogBox.getJeffDialog("My name is Jeff, how may I help you?", jeffImage)); + scrollPane.vvalueProperty().bind(dialogContainer.heightProperty()); + } + + public void setJeff(Jeff jeff) { + this.jeff = jeff; + } + + /** + * 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 = jeff.getResponse(input); + dialogContainer.getChildren().addAll( + DialogBox.getUserDialog(input, userImage), + DialogBox.getJeffDialog(response, jeffImage) + ); + if (Parser.isExit()) { + //@@author James_D-reused + //Reused from https://stackoverflow.com/questions/27334455/how-to-close-a-stage-after-a-certain-amount-of-time-javafx + // with minor modifications + PauseTransition delay = new PauseTransition(Duration.seconds(2)); + delay.setOnFinished(event -> Platform.exit()); + delay.play(); + //@@author + } + userInput.clear(); + } +} diff --git a/src/main/java/jeff/ui/Ui.java b/src/main/java/jeff/ui/Ui.java new file mode 100644 index 0000000000..40a9ef43d1 --- /dev/null +++ b/src/main/java/jeff/ui/Ui.java @@ -0,0 +1,101 @@ +package jeff.ui; + +/** + * Ui class is used to interact with the user. + */ +public class Ui { + + private static final String PREFIX = " "; + public static String addPrefix(String str) { + return PREFIX + str; + } + + /** + * Return the goodbye message string. + */ + public String showBye() { + return "Bye, my name is Jeff"; + } + + public String showList(String str) { + return str; + } + + public String showEmptyList() { + return "Your task list is currently empty."; + } + + public String showEmptyListFound() { + return "I cannot find any such entry since your task list is currently empty."; + } + + public String showNoneFound(String str) { + return "Sorry but Jeff could not find any task matching the keyword: " + str + "\n"; + } + + public String showFoundList(String str) { + return "Here are the matching tasks in your list:\n" + str; + } + + public String showMark(String currTask) { + return "Nice! I've marked this task as done:\n" + addPrefix(currTask); + } + + public String showUnmark(String currTask) { + return "OK, I've marked this task as not done yet:\n" + addPrefix(currTask); + } + + public String showNote(String currNotes) { + return "These are your notes:\n" + currNotes; + } + + public String showEmptyNote() { + return "Your note is currently empty."; + } + + public String showNoteCleared() { + return "I've cleared all your note for you!"; + } + + public String showNoteAdded(String currNote) { + return "Added this note for you:\n" + addPrefix(currNote); + } + + /** + * Display the confirmation response when adding a new task. + * + * @param currTask current task that was added. + * @param size amount of tasks in the list. + * @return Jeff's confirmation response and the size of the list. + */ + public String showAdded(String currTask, int size) { + return "Got it. I've added this task:\n" + addPrefix(currTask) + "\n" + + "Now you have " + size + " task(s) in the list."; + } + + /** + * Display the confirmation response when deleting a task. + * + * @param currTask task that was deleted. + * @param size amount of tasks left in the list. + * @return Jeff's confirmation response and the size of the list. + */ + public String showDelete(String currTask, int size) { + return "Noted. I've removed this task:\n" + addPrefix(currTask) + "\n" + + "Now you have " + size + " task(s) in the list."; + } + + public String showError(String message) { + return message; + } + + /** + * Display a message showing users where to get help. + * + * @return Jeff's response to ask user to read readme.txt + */ + public String showHelp() { + return "I do not understand your commands\n" + + "Please refer to the readme.txt for the available commands\n"; + } +} diff --git a/src/main/resources/images/Background.jpg b/src/main/resources/images/Background.jpg new file mode 100644 index 0000000000..ac3d62cd33 Binary files /dev/null and b/src/main/resources/images/Background.jpg differ diff --git a/src/main/resources/images/Jeff.png b/src/main/resources/images/Jeff.png new file mode 100644 index 0000000000..dd17ca50fe Binary files /dev/null and b/src/main/resources/images/Jeff.png differ diff --git a/src/main/resources/images/User.png b/src/main/resources/images/User.png new file mode 100644 index 0000000000..5911d30481 Binary files /dev/null and b/src/main/resources/images/User.png differ diff --git a/src/main/resources/view/DialogBox.fxml b/src/main/resources/view/DialogBox.fxml new file mode 100644 index 0000000000..fcc2b95668 --- /dev/null +++ b/src/main/resources/view/DialogBox.fxml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + diff --git a/src/main/resources/view/MainWindow.fxml b/src/main/resources/view/MainWindow.fxml new file mode 100644 index 0000000000..2d2f1a6ef9 --- /dev/null +++ b/src/main/resources/view/MainWindow.fxml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/java/jeff/task/DeadlineTest.java b/src/test/java/jeff/task/DeadlineTest.java new file mode 100644 index 0000000000..69e9594501 --- /dev/null +++ b/src/test/java/jeff/task/DeadlineTest.java @@ -0,0 +1,18 @@ +package jeff.task; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +import jeff.main.JeffException; + +public class DeadlineTest { + + @Test + public void testString() throws JeffException { + String description = "testing"; + String dateInfo = "2/8/2019 2000"; + Deadline currTask = new Deadline(description, dateInfo); + assertEquals("[D][ ] testing (by: Aug 02 2019 08:00 pm)", currTask.toString()); + } +} diff --git a/src/test/java/jeff/task/EventTest.java b/src/test/java/jeff/task/EventTest.java new file mode 100644 index 0000000000..cc4dd18475 --- /dev/null +++ b/src/test/java/jeff/task/EventTest.java @@ -0,0 +1,19 @@ +package jeff.task; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +import jeff.main.JeffException; + + +public class EventTest { + + @Test + public void testString() throws JeffException { + String description = "testing"; + String dateInfo = "20-8-2019 1800"; + Event currTask = new Event(description, dateInfo); + assertEquals("[E][ ] testing (at: Aug 20 2019 06:00 pm)", currTask.toString()); + } +} diff --git a/src/test/java/jeff/task/TodoTest.java b/src/test/java/jeff/task/TodoTest.java new file mode 100644 index 0000000000..1fc1a30dcb --- /dev/null +++ b/src/test/java/jeff/task/TodoTest.java @@ -0,0 +1,15 @@ +package jeff.task; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +public class TodoTest { + + @Test + public void testString() { + String description = "testing"; + Todo currTask = new Todo(description); + assertEquals("[T][ ] testing", currTask.toString()); + } +} diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 657e74f6e7..3e09d063ad 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,7 +1,28 @@ -Hello from - ____ _ -| _ \ _ _| | _____ -| | | | | | | |/ / _ \ -| |_| | |_| | < __/ -|____/ \__,_|_|\_\___| - +Hello! I'm Duke +What can I do for you? +Got it. I've added this task: + [T][ ] read book +Now you have 1 tasks in the list. +Nice! I've marked this task as done: + [T][X] read book +Got it. I've added this task: + [D][ ] return book (by: June 6th) +Now you have 2 tasks in the list. +Nice! I've marked this task as done: + [D][X] return book (by: June 6th) +Got it. I've added this task: + [E][ ] project meeting (at: Aug 6th 2-4pm) +Now you have 3 tasks in the list. +Got it. I've added this task: + [T][ ] join sports club +Now you have 4 tasks in the list. +Nice! I've marked this task as done: + [T][X] join sports club +Got it. I've added this task: + [T][ ] borrow book +Now you have 5 tasks in the list. +1.[T][X] read book +2.[D][X] return book (by: June 6th) +3.[E][ ] project meeting (at: Aug 6th 2-4pm) +4.[T][X] join sports club +5.[T][ ] borrow book diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index e69de29bb2..e97aa833ce 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -0,0 +1,9 @@ +todo read book +mark 1 +deadline return book /by June 6th +mark 2 +event project meeting /at Aug 6th 2-4pm +todo join sports club +mark 4 +todo borrow book +list \ No newline at end of file