diff --git a/.gitignore b/.gitignore index 2873e189e1..4a8db972fd 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,4 @@ src/main/resources/docs/ bin/ /text-ui-test/ACTUAL.TXT -text-ui-test/EXPECTED-UNIX.TXT +text-ui-test/EXPECTED-UNIX.TXT \ No newline at end of file diff --git a/.vs/ProjectSettings.json b/.vs/ProjectSettings.json new file mode 100644 index 0000000000..f8b4888565 --- /dev/null +++ b/.vs/ProjectSettings.json @@ -0,0 +1,3 @@ +{ + "CurrentProjectSetting": null +} \ No newline at end of file diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json new file mode 100644 index 0000000000..6b6114114f --- /dev/null +++ b/.vs/VSWorkspaceState.json @@ -0,0 +1,6 @@ +{ + "ExpandedNodes": [ + "" + ], + "PreviewInSolutionExplorer": false +} \ No newline at end of file diff --git a/.vs/ip/FileContentIndex/064839b1-73e4-4745-a2ff-2c64f321c30a.vsidx b/.vs/ip/FileContentIndex/064839b1-73e4-4745-a2ff-2c64f321c30a.vsidx new file mode 100644 index 0000000000..5c97841fb1 Binary files /dev/null and b/.vs/ip/FileContentIndex/064839b1-73e4-4745-a2ff-2c64f321c30a.vsidx differ diff --git a/.vs/ip/v17/.wsuo b/.vs/ip/v17/.wsuo new file mode 100644 index 0000000000..32daed41e4 Binary files /dev/null and b/.vs/ip/v17/.wsuo differ diff --git a/.vs/ip/v17/DocumentLayout.json b/.vs/ip/v17/DocumentLayout.json new file mode 100644 index 0000000000..fe6a3471f4 --- /dev/null +++ b/.vs/ip/v17/DocumentLayout.json @@ -0,0 +1,12 @@ +{ + "Version": 1, + "WorkspaceRootPath": "C:\\Users\\65814\\OneDrive\\NUSY2S1\\CS2103T\\IP\\ip\\", + "Documents": [], + "DocumentGroupContainers": [ + { + "Orientation": 0, + "VerticalTabListWidth": 256, + "DocumentGroups": [] + } + ] +} \ No newline at end of file diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite new file mode 100644 index 0000000000..6d5f6ab964 Binary files /dev/null and b/.vs/slnx.sqlite differ diff --git a/README.md b/README.md index 90aa7f092a..c384d46352 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,68 @@ -# 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. - -## Setting up in Intellij - -Prerequisites: JDK 17, update Intellij to the most recent version. - -1. Open Intellij (if you are not in the welcome screen, click `File` > `Close Project` to close the existing project first) -1. Open the project into Intellij as follows: - 1. Click `Open`. - 1. Select the project directory, and click `OK`. - 1. If there are any further prompts, accept the defaults. -1. Configure the project to use **JDK 17** (not other versions) as explained in [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk).
- In the same dialog, set the **Project language level** field to the `SDK default` option. -3. After that, locate the `src/main/java/Duke.java` file, right-click it, and choose `Run Duke.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output: - ``` - Hello from - ____ _ - | _ \ _ _| | _____ - | | | | | | | |/ / _ \ - | |_| | |_| | < __/ - |____/ \__,_|_|\_\___| - ``` +# Ah Bang Mang + +This is a Singaporean uncle helper chatbot. + +## Features +1. View task list +2. Add varied tasks to task list + 1. Todo: regular task that only displays a description + 2. Deadline: task that can include a deadline + 3. Event: task that has a start and end date +3. Mark tasks as done/ undone +4. Delete tasks from list +5. Find tasks within list + + +### Bonus +* Appealing GUI +* Singlish responses by chatbot +* Task list is saved to computer hard drive to retrieve when needed +* Asking `help` will provide the full list of commands and respective notations + +-------------------------------------------- +## User Guide +This guide will walk you through how to use the key features of Ah Bang Mang. + +### 1. Viewing the Task List + +To view all the tasks you have in your list, simply use the following command: ```list``` + +This command will display all tasks with their current status (done or not done) and their details. + +### 2. Adding Tasks + +You can add various types of tasks to your list. Here's how: + +* #### Todo: ```todo ``` + * for example, ```todo finish homework``` + + +* #### Deadline: ```deadline /by ``` + * The date-time should be in the format `yyyy-MM-ddTHH:mm`, or `yyyy-MM-dd` to set the time automatically to `23:59`. + You can also use `today` to set the deadline to the end of the current day. + + * for example, ```deadline Submit report /by 2024-09-17T23:59``` + +* #### Event: ```event /from /to ``` +* The date-time should be in the format `yyyy-MM-ddTHH:mm`, or `yyyy-MM-dd` if the event has no specific time. + * for example, ```event Team meeting /from 2024-09-17T09:00 /to 2024-09-17T11:00``` + +### 3. Marking Tasks +You can mark tasks as done or undone using the following commands: +* #### Mark Task as Done: `mark ` + * for example, `mark 1` +* #### Mark Task as Undone: `unmark ` + * for example, `unmark 1` + +### 4. Delete Tasks +* You can delete tasks from list by this simple command: `delete ` + * for example, `delete 1` + +### 5. Find Tasks +* You can find tasks from list by this simple command: `find ` + * for example, `find homework` + +-------------------------------------------- +## Acknowledgements: +1. ChatGPT: Writing JUnit command tests +2. SE-EDU JavaFX Tutorial: GUI base code \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000000..7daae89bce --- /dev/null +++ b/build.gradle @@ -0,0 +1,77 @@ +plugins { + id 'java' + id 'application' + id 'com.github.johnrengelman.shadow' version '7.1.2' +} + +repositories { + mavenCentral() +} + +dependencies { + // JUnit Jupiter API + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2' + testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.9.2' + + // Mockito + testImplementation 'org.mockito:mockito-junit-jupiter:4.8.0' // Mockito for JUnit Jupiter + + // Use platform-specific JavaFX dependencies based on the operating system + String javaFxVersion = '17.0.7' + 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 { + mainClass.set("bangmang.gui.Launcher") +} + +shadowJar { + archiveBaseName = "duke" + archiveClassifier = null + archiveVersion = null +} + +run { + standardInput = System.in +} + +jar { + manifest { + attributes 'Main-Class': 'bangmang.gui.Launcher' + } + from { + configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } + } +} + +tasks.jar { + duplicatesStrategy = DuplicatesStrategy.EXCLUDE +} + +run { + enableAssertions = true +} \ No newline at end of file diff --git a/data/LittleMissHelpful.txt b/data/LittleMissHelpful.txt new file mode 100644 index 0000000000..8da6265637 --- /dev/null +++ b/data/LittleMissHelpful.txt @@ -0,0 +1,5 @@ +D | 0 | ca1 | 2024-09-07T23:59:50.651522300 +T | 0 | book grab +D | 0 | clubbing | 2024-09-20T23:59:08.299430100 +E | 0 | filming | 2024-09-20T00:00 | 2024-09-21T00:00 +E | 0 | wedding | 2024-09-21T18:00 | 2024-09-21T22:00 diff --git a/docs/README.md b/docs/README.md index 47b9f984f7..ea688e7654 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,30 +1,68 @@ -# Duke User Guide +# Ah Bang Mang -// Update the title above to match the actual product name +This is a Singaporean uncle helper chatbot. -// Product screenshot goes here +## Features +1. View task list +2. Add varied tasks to task list + 1. Todo: regular task that only displays a description + 2. Deadline: task that can include a deadline + 3. Event: task that has a start and end date +3. Mark tasks as done/ undone +4. Delete tasks from list +5. Find tasks within list -// Product intro goes here -## Adding deadlines +### Bonus +* Appealing GUI +* Singlish responses by chatbot +* Task list is saved to computer hard drive to retrieve when needed +* Asking `help` will provide the full list of commands and respective notations -// Describe the action and its outcome. +-------------------------------------------- +## User Guide +This guide will walk you through how to use the key features of Ah Bang Mang. -// Give examples of usage +### 1. Viewing the Task List -Example: `keyword (optional arguments)` +To view all the tasks you have in your list, simply use the following command: ```list``` -// A description of the expected outcome goes here +This command will display all tasks with their current status (done or not done) and their details. -``` -expected output -``` +### 2. Adding Tasks -## Feature ABC +You can add various types of tasks to your list. Here's how: -// Feature details +* #### Todo: ```todo ``` + * for example, ```todo finish homework``` -## Feature XYZ +* #### Deadline: ```deadline /by ``` + * The date-time should be in the format `yyyy-MM-ddTHH:mm`, or `yyyy-MM-dd` to set the time automatically to `23:59`. + You can also use `today` to set the deadline to the end of the current day. -// Feature details \ No newline at end of file + * for example, ```deadline Submit report /by 2024-09-17T23:59``` + +* #### Event: ```event /from /to ``` +* The date-time should be in the format `yyyy-MM-ddTHH:mm`, or `yyyy-MM-dd` if the event has no specific time. + * for example, ```event Team meeting /from 2024-09-17T09:00 /to 2024-09-17T11:00``` + +### 3. Marking Tasks +You can mark tasks as done or undone using the following commands: +* #### Mark Task as Done: `mark ` + * for example, `mark 1` +* #### Mark Task as Undone: `unmark ` + * for example, `unmark 1` + +### 4. Delete Tasks +* You can delete tasks from list by this simple command: `delete ` + * for example, `delete 1` + +### 5. Find Tasks +* You can find tasks from list by this simple command: `find ` + * for example, `find homework` + +-------------------------------------------- +## Acknowledgements: +1. ChatGPT: Writing JUnit command tests +2. SE-EDU JavaFX Tutorial: GUI base code \ No newline at end of file diff --git a/docs/Ui.png b/docs/Ui.png new file mode 100644 index 0000000000..673dd7ff0b Binary files /dev/null and b/docs/Ui.png differ diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000..033e24c4cd 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..66c01cfeba --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000000..fcb6fca147 --- /dev/null +++ b/gradlew @@ -0,0 +1,248 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original 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 POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# 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 ;; #( + MSYS* | 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 + if ! command -v java >/dev/null 2>&1 + then + 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 +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# 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"' + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000000..6689b85bee --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,92 @@ +@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=. +@rem This is normally unused +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% equ 0 goto execute + +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 execute + +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 + +: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 %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 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! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/src/main/java/.vs/ProjectSettings.json b/src/main/java/.vs/ProjectSettings.json new file mode 100644 index 0000000000..f8b4888565 --- /dev/null +++ b/src/main/java/.vs/ProjectSettings.json @@ -0,0 +1,3 @@ +{ + "CurrentProjectSetting": null +} \ No newline at end of file diff --git a/src/main/java/.vs/VSWorkspaceState.json b/src/main/java/.vs/VSWorkspaceState.json new file mode 100644 index 0000000000..6b6114114f --- /dev/null +++ b/src/main/java/.vs/VSWorkspaceState.json @@ -0,0 +1,6 @@ +{ + "ExpandedNodes": [ + "" + ], + "PreviewInSolutionExplorer": false +} \ No newline at end of file diff --git a/src/main/java/.vs/java/FileContentIndex/db542b10-de43-4080-993b-a10962a39c2f.vsidx b/src/main/java/.vs/java/FileContentIndex/db542b10-de43-4080-993b-a10962a39c2f.vsidx new file mode 100644 index 0000000000..2fe8400383 Binary files /dev/null and b/src/main/java/.vs/java/FileContentIndex/db542b10-de43-4080-993b-a10962a39c2f.vsidx differ diff --git a/src/main/java/.vs/java/v17/.wsuo b/src/main/java/.vs/java/v17/.wsuo new file mode 100644 index 0000000000..5b7fb6675d Binary files /dev/null and b/src/main/java/.vs/java/v17/.wsuo differ diff --git a/src/main/java/.vs/java/v17/DocumentLayout.json b/src/main/java/.vs/java/v17/DocumentLayout.json new file mode 100644 index 0000000000..564078ea04 --- /dev/null +++ b/src/main/java/.vs/java/v17/DocumentLayout.json @@ -0,0 +1,12 @@ +{ + "Version": 1, + "WorkspaceRootPath": "C:\\Users\\65814\\OneDrive\\NUSY2S1\\CS2103T\\IP\\ip\\src\\main\\java\\", + "Documents": [], + "DocumentGroupContainers": [ + { + "Orientation": 0, + "VerticalTabListWidth": 256, + "DocumentGroups": [] + } + ] +} \ No newline at end of file diff --git a/src/main/java/.vs/slnx.sqlite b/src/main/java/.vs/slnx.sqlite new file mode 100644 index 0000000000..394242d996 Binary files /dev/null and b/src/main/java/.vs/slnx.sqlite 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/bangmang/BangMang.java b/src/main/java/bangmang/BangMang.java new file mode 100644 index 0000000000..2b7a24ab6b --- /dev/null +++ b/src/main/java/bangmang/BangMang.java @@ -0,0 +1,78 @@ +/** + * BangMang is the main class for the BangMang chatbot application. + * It manages the interaction between the user, tasks, and storage system. + * The application loads tasks from storage, parses user input commands, + * and provides appropriate responses through its UI. + * + * Author: Chooi Shao Xian + */ +package bangmang; + +import bangmang.command.Command; +import bangmang.exception.InvalidCommandException; +import bangmang.parser.Parser; +import bangmang.storage.Storage; +import bangmang.tasks.TaskList; +import bangmang.ui.Ui; + +public class BangMang { + private Storage storage; + private TaskList tasks; + private Ui ui; + + /** + * Constructor for BangMang class. + * Initializes the UI, loads tasks from storage, and handles any loading errors. + * + * @param filePath The file path where tasks are stored. + */ + public BangMang(String filePath) { + ui = new Ui(); + storage = new Storage(filePath); + try { + tasks = new TaskList(storage.load()); + } catch (InvalidCommandException e) { + ui.showError(e.getMessage()); + tasks = new TaskList(); + } + + // Assert that tasks should not be null + assert tasks != null : "List of tasks should not be null"; + } + + /** + * Returns a greeting message when the application starts. + * + * @return A welcome message string. + */ + public String getGreeting() { + try { + return ui.showWelcome(); + } catch (Exception e) { + return e.getMessage(); + } + } + + /** + * Processes user input and returns the corresponding response. + * + * @param input The user input command string. + * @return The response message string. + */ + public String getResponse(String input) { + // Assert that input should not be null or empty + assert input != null && !input.isEmpty() : "Input should not be null or empty"; + + try { + Command command = Parser.parse(input); + + // Assert that command should not be null + assert command != null : "Command should not be null"; + + String response = command.execute(tasks, ui, storage); + return response; + } catch (InvalidCommandException e) { + return e.getMessage(); + } + } +} diff --git a/src/main/java/bangmang/command/AddDeadlineCommand.java b/src/main/java/bangmang/command/AddDeadlineCommand.java new file mode 100644 index 0000000000..8bd2a317a7 --- /dev/null +++ b/src/main/java/bangmang/command/AddDeadlineCommand.java @@ -0,0 +1,63 @@ +package bangmang.command; + +import java.time.LocalDateTime; +import java.time.LocalDate; +import java.time.format.DateTimeParseException; + +import bangmang.storage.Storage; +import bangmang.tasks.TaskList; +import bangmang.ui.Ui; +import bangmang.exception.InvalidCommandException; +import bangmang.tasks.Deadline; + +/** + * Represents a command to add a deadline task. + */ + +public class AddDeadlineCommand extends Command { + private String description; + private String byString; + + /** + * Constructs an AddDeadlineCommand with the specified description and deadline time. + * + * @param description A description of the deadline task. + * @param byString The deadline time as a String, which may be in the format 'yyyy-MM-ddTHH:mm' or 'yyyy-MM-dd'. + */ + public AddDeadlineCommand(String description, String byString) { + this.description = description; + this.byString = byString; + } + + @Override + public String execute(TaskList tasks, Ui ui, Storage storage) throws InvalidCommandException { + LocalDateTime by; + try { + if (byString.equalsIgnoreCase("today")) { + // Use current date and set time to 23:59 + by = LocalDateTime.now().withHour(23).withMinute(59); + } else { + // Try parsing by LocalDateTime + by = LocalDateTime.parse(byString); + } + } catch (DateTimeParseException e) { + // If parsing fails, try parsing as LocalDate and set time to 23:59 + try { + LocalDate deadlineDate = LocalDate.parse(byString); + by = deadlineDate.atTime(23, 59); + } catch (DateTimeParseException ex) { + throw new InvalidCommandException("Alamak, invalid date format for deadline. Please use 'yyyy-MM-ddTHH:mm' or 'yyyy-MM-dd'."); + } + } + + Deadline deadline = new Deadline(this.description, by); + tasks.add(deadline); + storage.save(tasks.getTasks()); + return ui.showAddedNewTask(deadline, tasks); + } + + @Override + public boolean isExit() { + return false; + } +} diff --git a/src/main/java/bangmang/command/AddEventCommand.java b/src/main/java/bangmang/command/AddEventCommand.java new file mode 100644 index 0000000000..b334e66845 --- /dev/null +++ b/src/main/java/bangmang/command/AddEventCommand.java @@ -0,0 +1,84 @@ +package bangmang.command; + +import java.time.LocalDateTime; +import java.time.LocalDate; +import java.time.format.DateTimeParseException; + +import bangmang.storage.Storage; +import bangmang.tasks.TaskList; +import bangmang.ui.Ui; +import bangmang.exception.InvalidCommandException; +import bangmang.tasks.Event; + +/** + * Represents a command to add an event task. + */ + +public class AddEventCommand extends Command { + private final String description; + private final String fromString; + private final String toString; + + /** + * Constructs an AddEventCommand with the specified description, start time, and end time. + * + * @param description A description of the event task. + * @param fromString The start time of the event as a String, which may be in the format 'yyyy-MM-ddTHH:mm' or 'yyyy-MM-dd'. + * @param toString The end time of the event as a String, which may be in the format 'yyyy-MM-ddTHH:mm' or 'yyyy-MM-dd'. + */ + public AddEventCommand(String description, String fromString, String toString) { + this.description = description; + this.fromString = fromString; + this.toString = toString; + } + + @Override + public String execute(TaskList tasks, Ui ui, Storage storage) throws InvalidCommandException { + LocalDateTime from; + LocalDateTime to; + + try { + from = parseDateTime(fromString); + to = parseDateTime(toString); + + Event event = new Event(description, from, to); + tasks.add(event); + storage.save(tasks.getTasks()); + return ui.showAddedNewTask(event, tasks); + + } catch (DateTimeParseException e) { + throw new InvalidCommandException("Alamak, invalid date format. Please use 'yyyy-MM-ddTHH:mm' or 'yyyy-MM-dd'."); + } + } + + @Override + public boolean isExit() { + return false; + } + + /** + * Parses a string into a LocalDateTime object. + * + * @param dateTimeString The string representing the date and time. + * @return A LocalDateTime object. + * @throws DateTimeParseException if the string cannot be parsed into a LocalDateTime. + */ + private LocalDateTime parseDateTime(String dateTimeString) throws DateTimeParseException { + if (dateTimeString.equalsIgnoreCase("today")) { + // Use current date and set time to 00:00 (start of the day) + return LocalDateTime.now().withHour(00).withMinute(00); + } + try { + // Try parsing as LocalDateTime + return LocalDateTime.parse(dateTimeString); + } catch (DateTimeParseException e) { + try { + // If LocalDateTime parsing fails, try parsing as LocalDate + LocalDate date = LocalDate.parse(dateTimeString); + return date.atTime(00, 00); + } catch (DateTimeParseException ex) { + throw ex; + } + } + } +} diff --git a/src/main/java/bangmang/command/AddTodoCommand.java b/src/main/java/bangmang/command/AddTodoCommand.java new file mode 100644 index 0000000000..8b93032a7c --- /dev/null +++ b/src/main/java/bangmang/command/AddTodoCommand.java @@ -0,0 +1,37 @@ +package bangmang.command; + +import bangmang.storage.Storage; +import bangmang.tasks.TaskList; +import bangmang.ui.Ui; +import bangmang.exception.InvalidCommandException; +import bangmang.tasks.Todo; + +/** + * Represents a command to add a todo task. + */ + +public class AddTodoCommand extends Command { + private final String description; + + /** + * Constructs an AddTodoCommand with the specified description. + * + * @param description A description of the todo task. + */ + public AddTodoCommand(String description) { + this.description = description; + } + + @Override + public String execute(TaskList tasks, Ui ui, Storage storage) throws InvalidCommandException { + Todo todo = new Todo(description); + tasks.add(todo); + storage.save(tasks.getTasks()); + return ui.showAddedNewTask(todo, tasks); + } + + @Override + public boolean isExit() { + return false; + } +} diff --git a/src/main/java/bangmang/command/Command.java b/src/main/java/bangmang/command/Command.java new file mode 100644 index 0000000000..846aca62c2 --- /dev/null +++ b/src/main/java/bangmang/command/Command.java @@ -0,0 +1,32 @@ +package bangmang.command; + +import bangmang.storage.Storage; +import bangmang.tasks.TaskList; +import bangmang.ui.Ui; +import bangmang.exception.InvalidCommandException; + +/** + * Represents an abstract command that can be executed. + * Subclasses should implement the specific details of how the command is executed + * and whether it signifies an exit command. + */ + +public abstract class Command { + /** + * Executes the command based on the provided tasks, UI, and storage. + * + * @param tasks The list of tasks to be manipulated. + * @param ui The user interface for interacting with the user. + * @param storage The storage for saving/loading tasks. + * @return A String representing the result of the command execution. + * @throws InvalidCommandException If the command cannot be executed due to invalid data. + */ + public abstract String execute(TaskList tasks, Ui ui, Storage storage) throws InvalidCommandException; + + /** + * Checks if the command represents an exit command. + * + * @return True if the command is an exit command, false otherwise. + */ + public abstract boolean isExit(); +} diff --git a/src/main/java/bangmang/command/DeleteTaskCommand.java b/src/main/java/bangmang/command/DeleteTaskCommand.java new file mode 100644 index 0000000000..45f2f57049 --- /dev/null +++ b/src/main/java/bangmang/command/DeleteTaskCommand.java @@ -0,0 +1,43 @@ +package bangmang.command; + +import bangmang.storage.Storage; +import bangmang.tasks.TaskList; +import bangmang.ui.Ui; +import bangmang.exception.InvalidCommandException; +import bangmang.exception.InvalidTaskFormatException; +import bangmang.tasks.Task; + +/** + * Represents a command to delete a task from the task list. + */ + +public class DeleteTaskCommand extends Command { + private final int taskIndex; + + /** + * Constructs a DeleteTaskCommand with the specified task index. + * + * @param listIndex The task number of the task in the list to delete. + */ + public DeleteTaskCommand(int listIndex) { + this.taskIndex = listIndex - 1; // Convert to 0-based index + } + + @Override + public String execute(TaskList tasks, Ui ui, Storage storage) throws InvalidCommandException { + try { + Task task = tasks.get(taskIndex); + tasks.delete(taskIndex); + storage.save(tasks.getTasks()); + return ui.showDeletedTask(task, tasks); + + } catch (InvalidTaskFormatException e) { + throw new InvalidCommandException("Alamak, task number out of range. Please provide a valid task number."); + } + } + + @Override + public boolean isExit() { + return false; + } +} diff --git a/src/main/java/bangmang/command/ExitCommand.java b/src/main/java/bangmang/command/ExitCommand.java new file mode 100644 index 0000000000..9be5035ae8 --- /dev/null +++ b/src/main/java/bangmang/command/ExitCommand.java @@ -0,0 +1,37 @@ +/** + * Represents a command to exit the application and save the current state. + */ +package bangmang.command; + +import bangmang.storage.Storage; +import bangmang.tasks.TaskList; +import bangmang.ui.Ui; +import bangmang.exception.InvalidCommandException; + +public class ExitCommand extends Command { + + /** + * Executes the exit command, saves the current task list, and returns the exit message. + * + * @param tasks The list of tasks to save. + * @param ui The UI instance for displaying messages. + * @param storage The storage instance for saving tasks. + * @return The exit message to be displayed. + * @throws InvalidCommandException If any error occurs while saving tasks. + */ + @Override + public String execute(TaskList tasks, Ui ui, Storage storage) throws InvalidCommandException { + storage.save(tasks.getTasks()); + return ui.showExit(); + } + + /** + * Returns true to indicate that this command is an exit command. + * + * @return true + */ + @Override + public boolean isExit() { + return true; + } +} diff --git a/src/main/java/bangmang/command/FindCommand.java b/src/main/java/bangmang/command/FindCommand.java new file mode 100644 index 0000000000..e6d0098e25 --- /dev/null +++ b/src/main/java/bangmang/command/FindCommand.java @@ -0,0 +1,63 @@ +package bangmang.command; + +import bangmang.exception.InvalidTaskFormatException; +import bangmang.exception.InvalidCommandException; +import bangmang.tasks.Task; +import bangmang.tasks.TaskList; +import bangmang.ui.Ui; +import bangmang.storage.Storage; + +import java.util.ArrayList; + +/** + * Represents a command to search for tasks containing the specified keyword. + */ + +public class FindCommand extends Command { + private String searchInput; + + /** + * Constructs a FindCommand with the specified search input. + * + * @param searchInput The keyword to search for in task descriptions. + */ + public FindCommand(String searchInput) { + this.searchInput = searchInput; + } + + /** + * Executes the find command by searching for tasks that contain the specified keyword. + * + * @param tasks The list of tasks to search within. + * @param ui The UI instance for displaying messages. + * @param storage The storage instance (not used in this command). + * @return The search results message to be displayed. + * @throws InvalidCommandException If any error occurs while searching tasks. + */ + @Override + public String execute(TaskList tasks, Ui ui, Storage storage) throws InvalidCommandException { + ArrayList searchResults = new ArrayList<>(); + + try { + for (int i = 0; i < tasks.size(); i++) { + Task t = tasks.get(i); + if (t.getDescription().contains(this.searchInput)) { + searchResults.add(t); + } + } + return ui.showSearchResults(searchResults); + } catch (InvalidTaskFormatException e) { + throw new InvalidCommandException("Alamak, task number out of range. Please provide a valid task number."); + } + } + + /** + * Returns false as this command does not terminate the application. + * + * @return false + */ + @Override + public boolean isExit() { + return false; + } +} diff --git a/src/main/java/bangmang/command/HelpCommand.java b/src/main/java/bangmang/command/HelpCommand.java new file mode 100644 index 0000000000..275cd7f1eb --- /dev/null +++ b/src/main/java/bangmang/command/HelpCommand.java @@ -0,0 +1,36 @@ +package bangmang.command; + +import bangmang.storage.Storage; +import bangmang.tasks.TaskList; +import bangmang.ui.Ui; +import bangmang.exception.InvalidCommandException; + +/** + * Represents a command that displays help information to the user. + */ + +public class HelpCommand extends Command { + /** + * Executes the help command by requesting the UI to display help information. + * + * @param tasks The list of tasks (not used in this command). + * @param ui The UI instance for displaying help messages. + * @param storage The storage instance (not used in this command). + * @return The help information to be displayed. + * @throws InvalidCommandException If any error occurs while processing the command. + */ + @Override + public String execute(TaskList tasks, Ui ui, Storage storage) throws InvalidCommandException { + return ui.showHelp(); + } + + /** + * Returns false as this command does not terminate the application. + * + * @return false + */ + @Override + public boolean isExit() { + return false; + } +} diff --git a/src/main/java/bangmang/command/ListCommand.java b/src/main/java/bangmang/command/ListCommand.java new file mode 100644 index 0000000000..9c1f1301c7 --- /dev/null +++ b/src/main/java/bangmang/command/ListCommand.java @@ -0,0 +1,40 @@ +package bangmang.command; + +import bangmang.storage.Storage; +import bangmang.tasks.TaskList; +import bangmang.ui.Ui; +import bangmang.exception.InvalidCommandException; + +/** + * Represents a command that displays all tasks in the task list. + */ + +public class ListCommand extends Command { + /** + * Executes the list command by requesting the UI to display all tasks or a message indicating no tasks are present. + * + * @param tasks The list of tasks to be displayed. + * @param ui The UI instance for displaying task lists or messages. + * @param storage The storage instance (not used in this command). + * @return A string representing the task list or a message if no tasks are present. + * @throws InvalidCommandException If any error occurs while processing the command. + */ + @Override + public String execute(TaskList tasks, Ui ui, Storage storage) throws InvalidCommandException { + if (tasks.size() == 0) { + return ui.showNoTasks(); + } else { + return ui.showAllTasks(tasks.getTasks()); + } + } + + /** + * Returns false as this command does not terminate the application. + * + * @return false + */ + @Override + public boolean isExit() { + return false; + } +} diff --git a/src/main/java/bangmang/command/MarkTaskCommand.java b/src/main/java/bangmang/command/MarkTaskCommand.java new file mode 100644 index 0000000000..30ba6cbc68 --- /dev/null +++ b/src/main/java/bangmang/command/MarkTaskCommand.java @@ -0,0 +1,57 @@ +package bangmang.command; + +import bangmang.storage.Storage; +import bangmang.tasks.TaskList; +import bangmang.ui.Ui; +import bangmang.exception.InvalidCommandException; +import bangmang.exception.InvalidTaskFormatException; +import bangmang.tasks.Task; + +/** + * Represents a command to mark a specific task as done. + */ + +public class MarkTaskCommand extends Command { + private final int taskIndex; + + /** + * Constructs a MarkTaskCommand with the specified task index. + * + * @param i The task number of the task in the list to be marked. + */ + public MarkTaskCommand(int i) { + this.taskIndex = i - 1; + } + + /** + * Executes the command to mark the specified task as done, saves the updated task list, and provides feedback. + * + * @param tasks The list of tasks where the specified task will be marked. + * @param ui The UI instance for providing feedback. + * @param storage The storage instance to save the updated task list. + * @return A string indicating the task has been marked as done. + * @throws InvalidCommandException If the task index is invalid or any other error occurs. + */ + @Override + public String execute(TaskList tasks, Ui ui, Storage storage) throws InvalidCommandException { + try { + Task task = tasks.get(this.taskIndex); + tasks.markTask(this.taskIndex); + storage.save(tasks.getTasks()); + return ui.showMarkedTask(task); + + } catch (InvalidTaskFormatException e) { + throw new InvalidCommandException("Alamak, task number out of range. Please provide a valid task number."); + } + } + + /** + * Returns false as this command does not terminate the application. + * + * @return false + */ + @Override + public boolean isExit() { + return false; + } +} diff --git a/src/main/java/bangmang/command/UnmarkTaskCommand.java b/src/main/java/bangmang/command/UnmarkTaskCommand.java new file mode 100644 index 0000000000..743f278966 --- /dev/null +++ b/src/main/java/bangmang/command/UnmarkTaskCommand.java @@ -0,0 +1,57 @@ +package bangmang.command; + +import bangmang.storage.Storage; +import bangmang.tasks.TaskList; +import bangmang.ui.Ui; +import bangmang.exception.InvalidCommandException; +import bangmang.exception.InvalidTaskFormatException; +import bangmang.tasks.Task; + +/** + * Represents a command to unmark a specific task as not done. + */ + +public class UnmarkTaskCommand extends Command { + private final int taskIndex; + + /** + * Constructs an UnmarkTaskCommand with the specified task index. + * + * @param i The task number of the task in the list to be unmarked. + */ + public UnmarkTaskCommand(int i) { + this.taskIndex = i - 1; + } + + /** + * Executes the command to unmark the specified task as not done, saves the updated task list, and provides feedback. + * + * @param tasks The list of tasks where the specified task will be unmarked. + * @param ui The UI instance for providing feedback. + * @param storage The storage instance to save the updated task list. + * @return A string indicating the task has been unmarked as not done. + * @throws InvalidCommandException If the task index is invalid or any other error occurs. + */ + @Override + public String execute(TaskList tasks, Ui ui, Storage storage) throws InvalidCommandException { + try { + Task task = tasks.get(this.taskIndex); + tasks.unmarkTask(this.taskIndex); + storage.save(tasks.getTasks()); + return ui.showUnmarkedTask(task); + + } catch (InvalidTaskFormatException e) { + throw new InvalidCommandException("Alamak, task number out of range. Please provide a valid task number."); + } + } + + /** + * Returns false as this command does not terminate the application. + * + * @return false + */ + @Override + public boolean isExit() { + return false; + } +} diff --git a/src/main/java/bangmang/exception/InvalidCommandException.java b/src/main/java/bangmang/exception/InvalidCommandException.java new file mode 100644 index 0000000000..1419ef8a90 --- /dev/null +++ b/src/main/java/bangmang/exception/InvalidCommandException.java @@ -0,0 +1,6 @@ +package bangmang.exception; +public class InvalidCommandException extends Exception { + public InvalidCommandException(String message) { + super(message); + } +} diff --git a/src/main/java/bangmang/exception/InvalidTaskFormatException.java b/src/main/java/bangmang/exception/InvalidTaskFormatException.java new file mode 100644 index 0000000000..8acbee3c39 --- /dev/null +++ b/src/main/java/bangmang/exception/InvalidTaskFormatException.java @@ -0,0 +1,6 @@ +package bangmang.exception; +public class InvalidTaskFormatException extends Exception { + public InvalidTaskFormatException(String message) { + super(message); + } +} diff --git a/src/main/java/bangmang/exception/TaskNotFoundException.java b/src/main/java/bangmang/exception/TaskNotFoundException.java new file mode 100644 index 0000000000..a48876957b --- /dev/null +++ b/src/main/java/bangmang/exception/TaskNotFoundException.java @@ -0,0 +1,6 @@ +package bangmang.exception; +public class TaskNotFoundException extends Exception { + public TaskNotFoundException(String message) { + super(message); + } +} diff --git a/src/main/java/bangmang/gui/DialogBox.java b/src/main/java/bangmang/gui/DialogBox.java new file mode 100644 index 0000000000..5b074a89cc --- /dev/null +++ b/src/main/java/bangmang/gui/DialogBox.java @@ -0,0 +1,59 @@ +package bangmang.gui; + +import java.io.IOException; +import java.util.Collections; + +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.geometry.Pos; +import javafx.scene.Node; +import javafx.scene.control.Label; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.layout.HBox; + +/** + * Represents a dialog box consisting of an ImageView to represent the speaker's face + * and a label containing text from the speaker. + */ +public class DialogBox extends HBox { + @FXML + private Label dialog; + @FXML + private ImageView displayPicture; + private DialogBox(String text, Image img) { + try { + FXMLLoader fxmlLoader = new FXMLLoader(MainWindow.class.getResource("/view/DialogBox.fxml")); + fxmlLoader.setController(this); + fxmlLoader.setRoot(this); + fxmlLoader.load(); + } catch (IOException e) { + e.printStackTrace(); + } + + dialog.setText(text); + displayPicture.setImage(img); + } + + /** + * Flips the dialog box such that the ImageView is on the left and text on the right. + */ + private void flip() { + ObservableList tmp = FXCollections.observableArrayList(this.getChildren()); + Collections.reverse(tmp); + getChildren().setAll(tmp); + setAlignment(Pos.TOP_LEFT); + } + + public static DialogBox getUserDialog(String text, Image img) { + return new DialogBox(text, img); + } + + public static DialogBox getLmhDialog(String text, Image img) { + var db = new DialogBox(text, img); + db.flip(); + return db; + } +} \ No newline at end of file diff --git a/src/main/java/bangmang/gui/Launcher.java b/src/main/java/bangmang/gui/Launcher.java new file mode 100644 index 0000000000..c7e8f7653b --- /dev/null +++ b/src/main/java/bangmang/gui/Launcher.java @@ -0,0 +1,12 @@ +package bangmang.gui; + +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/bangmang/gui/Main.java b/src/main/java/bangmang/gui/Main.java new file mode 100644 index 0000000000..ce2954bf46 --- /dev/null +++ b/src/main/java/bangmang/gui/Main.java @@ -0,0 +1,34 @@ +package bangmang.gui; + +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 bangmang.BangMang; + +/** + * A GUI for Duke using FXML. + */ +public class Main extends Application { + + private BangMang bangMang = new BangMang("data/LittleMissHelpful.txt"); + + @Override + public void start(Stage stage) { + try { + FXMLLoader fxmlLoader = new FXMLLoader(Main.class.getResource("/view/MainWindow.fxml")); + AnchorPane ap = fxmlLoader.load(); + Scene scene = new Scene(ap); + stage.setScene(scene); + fxmlLoader.getController().setBangMang(bangMang); + stage.show(); + + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/bangmang/gui/MainWindow.java b/src/main/java/bangmang/gui/MainWindow.java new file mode 100644 index 0000000000..b655b87fa2 --- /dev/null +++ b/src/main/java/bangmang/gui/MainWindow.java @@ -0,0 +1,67 @@ +package bangmang.gui; + +import bangmang.BangMang; +import bangmang.ui.Ui; + +import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.scene.control.ScrollPane; +import javafx.scene.control.TextField; +import javafx.scene.image.Image; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.VBox; + +/** + * Controller for the main GUI. + */ + +public class MainWindow extends AnchorPane { + @FXML + private ScrollPane scrollPane; + @FXML + private VBox dialogContainer; + @FXML + private TextField userInput; + @FXML + private Button sendButton; + + private BangMang bangMang; + + private Image userImage = new Image(this.getClass().getResourceAsStream("/images/UserImage.png")); + private Image chatbotImage = new Image(this.getClass().getResourceAsStream("/images/ChatbotImage.png")); + + @FXML + public void initialize() { + scrollPane.vvalueProperty().bind(dialogContainer.heightProperty()); + showGreeting(); + } + + public void setBangMang(BangMang bangMang) { + this.bangMang = bangMang; + } + + /** + * Displays the greeting message from the chatbot. + */ + private void showGreeting() { + String greeting = new Ui().showWelcome(); + dialogContainer.getChildren().add( + DialogBox.getLmhDialog(greeting, chatbotImage) + ); + } + + /** + * 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 = bangMang.getResponse(input); + dialogContainer.getChildren().addAll( + DialogBox.getUserDialog(input, userImage), + DialogBox.getLmhDialog(response, chatbotImage) + ); + userInput.clear(); + } +} diff --git a/src/main/java/bangmang/parser/Parser.java b/src/main/java/bangmang/parser/Parser.java new file mode 100644 index 0000000000..1b5abc798a --- /dev/null +++ b/src/main/java/bangmang/parser/Parser.java @@ -0,0 +1,78 @@ +package bangmang.parser; + +import bangmang.command.*; +import bangmang.exception.InvalidCommandException; + +/** + * The Parser class handles the parsing of user input into specific commands. + * It reads the user input, validates it, and returns the corresponding Command object + * based on the command type (e.g., add task, mark task, delete task). + */ + +public class Parser { + /** + * Parses the full command input from the user and returns the appropriate command object. + * + * @param fullCommand The full user input string. + * @return The command corresponding to the user input. + * @throws InvalidCommandException If the input is not valid or the command is not recognized. + */ + public static Command parse(String fullCommand) throws InvalidCommandException { + String[] inputList = fullCommand.split(" ", 2); + String command = inputList[0].toLowerCase(); + + // If the command is a single word command (like "bye", "list", or "help") + if (inputList.length < 2) { + if (command.equals("bye")) { + return new ExitCommand(); + } else if (command.equals("list")) { + return new ListCommand(); + } else if (command.equals("help")) { + return new HelpCommand(); + } else { + throw new InvalidCommandException("Alamak, invalid command. Please provide a valid command."); + } + } + + // Commands with additional parameters (like "mark", "todo", "deadline") + String item = inputList[1]; + switch (command) { + case "mark": + return new MarkTaskCommand(Integer.parseInt(item)); + + case "unmark": + return new UnmarkTaskCommand(Integer.parseInt(item)); + + case "delete": + return new DeleteTaskCommand(Integer.parseInt(item)); + + case "find": + return new FindCommand(item); + + case "todo": + return new AddTodoCommand(item); + + case "deadline": + String[] deadlineParts = item.split("/by", 2); + if (deadlineParts.length < 2) { + throw new InvalidCommandException("Alamak, invalid deadline format. Use 'deadline description /by date'."); + } + String deadlineDesc = deadlineParts[0].trim(); + String deadlineBy = deadlineParts[1].trim(); + return new AddDeadlineCommand(deadlineDesc, deadlineBy); + + case "event": + String[] eventParts = item.split("/from | /to", 3); + if (eventParts.length < 3) { + throw new InvalidCommandException("Alamak, invalid event format. Use 'event description /from start /to end'."); + } + String eventDesc = eventParts[0].trim(); + String eventFrom = eventParts[1].trim(); + String eventTo = eventParts[2].trim(); + return new AddEventCommand(eventDesc, eventFrom, eventTo); + + default: + throw new InvalidCommandException("Alamak, invalid command. Please provide a valid command."); + } + } +} diff --git a/src/main/java/bangmang/storage/Storage.java b/src/main/java/bangmang/storage/Storage.java new file mode 100644 index 0000000000..177a26ba0c --- /dev/null +++ b/src/main/java/bangmang/storage/Storage.java @@ -0,0 +1,80 @@ +package bangmang.storage; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.ArrayList; + +import bangmang.exception.InvalidCommandException; +import bangmang.exception.InvalidTaskFormatException; +import bangmang.tasks.Task; + +/** + * The Storage class handles the loading and saving of task data from and to the hard drive. + * It manages reading tasks from a file, creating task objects, and saving tasks back to the file. + */ + +public class Storage { + private String filePath; + + public Storage(String filePath) { + this.filePath = filePath; + } + + /** + * Loads task data from the hard drive and returns an array list of tasks. + * + * @return ArrayList of Task objects. + * @throws InvalidCommandException if there is an error reading the file. + * @throws InvalidTaskFormatException if the task format is invalid. + */ + public ArrayList load() throws InvalidCommandException { + ArrayList list = new ArrayList<>(); + File dataFile = new File(filePath); + if (!dataFile.getParentFile().exists()) { + dataFile.getParentFile().mkdirs(); + } + if (dataFile.exists()) { + try (BufferedReader br = new BufferedReader(new FileReader(dataFile))) { + String line; + while ((line = br.readLine()) != null) { + try { + Task task = Task.readSavedTask(line); + list.add(task); + } catch (InvalidTaskFormatException e) { + System.out.println("Alamak, warning: Skipping invalid task format: " + line); + } + } + } catch (IOException e) { + throw new InvalidCommandException("Alamak, error reading the file: " + e.getMessage()); + } + } + return list; + } + + /** + * Saves task data to the hard drive. + * + * @param list The list of tasks to save. + * @throws InvalidCommandException if there is an error writing to the file. + * @throws InvalidTaskFormatException if a task cannot be saved. + */ + public void save(ArrayList list) throws InvalidCommandException { + File dataFile = new File(filePath); + try (BufferedWriter bw = new BufferedWriter(new FileWriter(dataFile))) { + for (Task task : list) { + try { + bw.write(task.writeSavedTask()); + bw.newLine(); + } catch (InvalidTaskFormatException e) { + System.out.println("Alamak, warning: Cannot write task: " + task.toString()); + } + } + } catch (IOException e) { + throw new InvalidCommandException("Alamak, error writing to the file: " + e.getMessage()); + } + } +} diff --git a/src/main/java/bangmang/tasks/Deadline.java b/src/main/java/bangmang/tasks/Deadline.java new file mode 100644 index 0000000000..0d98311785 --- /dev/null +++ b/src/main/java/bangmang/tasks/Deadline.java @@ -0,0 +1,63 @@ +package bangmang.tasks; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +/** + * Represents a Deadline task with a due date. + * Inherits from the Task class and is used for tasks that have a specific due date and time. + */ + +public class Deadline extends Task { + protected LocalDateTime by; + + /** + * Constructs a Deadline with a description and due date. + * + * @param description Description of the deadline. + * @param by Due date and time of the deadline. + */ + public Deadline(String description, LocalDateTime by) { + super(description); + this.by = by; + } + + /** + * Constructs a Deadline with a description, completion status, and due date. + * + * @param description Description of the deadline. + * @param isDone Whether the deadline is marked as done. + * @param by Due date and time of the deadline. + */ + public Deadline(String description, boolean isDone, LocalDateTime by) { + super(description, isDone); + this.by = by; + } + + /** + * Returns the string representation of the Deadline. + * Formats the due date and time based on the current date. + * + * @return A string with the format specific to Deadline tasks, including the task type and due date. + */ + @Override + public String toString() { + DateTimeFormatter sameYearFullFormatter = DateTimeFormatter.ofPattern("d MMM HH:mm"); + DateTimeFormatter diffYearFullFormatter = DateTimeFormatter.ofPattern("d MMM yyyy HH:mm"); + DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm"); + + // Format the due date based on different conditions + String byString = this.by.format(sameYearFullFormatter); + + // Different year + if (LocalDateTime.now().getYear() != this.by.getYear()) { + byString = this.by.format(diffYearFullFormatter); + + } else if (LocalDateTime.now().toLocalDate().equals(this.by.toLocalDate())) { + // Within the same day and same year + byString = "today " + this.by.format(timeFormatter); + } + + return "[D]" + super.toString() + " | " + byString; + } +} diff --git a/src/main/java/bangmang/tasks/Event.java b/src/main/java/bangmang/tasks/Event.java new file mode 100644 index 0000000000..df230c9ce3 --- /dev/null +++ b/src/main/java/bangmang/tasks/Event.java @@ -0,0 +1,75 @@ +package bangmang.tasks; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +/** + * Represents an Event task with a start and end time. + * Inherits from the Task class and is used for tasks that occur between specific times. + */ + +public class Event extends Task { + protected LocalDateTime from; + protected LocalDateTime to; + + /** + * Constructs an Event with a description, start time, and end time. + * + * @param description Description of the event. + * @param from Start time of the event. + * @param to End time of the event. + */ + public Event(String description, LocalDateTime from, LocalDateTime to) { + super(description); + this.from = from; + this.to = to; + } + + /** + * Constructs an Event with a description, completion status, start time, and end time. + * + * @param description Description of the event. + * @param isDone Whether the event is marked as done. + * @param from Start time of the event. + * @param to End time of the event. + */ + public Event(String description, boolean isDone, LocalDateTime from, LocalDateTime to) { + super(description, isDone); + this.from = from; + this.to = to; + } + + /** + * Returns the string representation of the Event. + * Formats the date and time based on the event's duration and the current date. + * + * @return A string with the format specific to Event tasks, including the task type and time range. + */ + @Override + public String toString() { + DateTimeFormatter sameYearFullFormatter = DateTimeFormatter.ofPattern("d MMM HH:mm"); + DateTimeFormatter diffYearFullFormatter = DateTimeFormatter.ofPattern("d MMM yyyy HH:mm"); + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("d MMM"); + DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm"); + + // Format the start and end times based on different conditions + String fromString = this.from.format(sameYearFullFormatter); + String toString = this.to.format(sameYearFullFormatter); + + // Different year + if (LocalDateTime.now().getYear() != this.from.getYear()) { + fromString = this.from.format(diffYearFullFormatter); + toString = this.to.format(diffYearFullFormatter); + } else if (this.from.toLocalDate().equals(this.to.toLocalDate())) { + // Within the same day and same year + toString = this.to.format(timeFormatter); + } else if (this.from.toLocalTime().equals(LocalDateTime.MIN.toLocalTime()) && + this.to.toLocalTime().equals(LocalDateTime.MIN.toLocalTime())) { + // Same year, not same day, but whole day + fromString = this.from.format(dateFormatter); + toString = this.to.format(dateFormatter); + } + + return "[E]" + super.toString() + " | " + fromString + " - " + toString; + } +} diff --git a/src/main/java/bangmang/tasks/Task.java b/src/main/java/bangmang/tasks/Task.java new file mode 100644 index 0000000000..788294b641 --- /dev/null +++ b/src/main/java/bangmang/tasks/Task.java @@ -0,0 +1,136 @@ +package bangmang.tasks; + +import java.time.LocalDateTime; +import bangmang.exception.InvalidTaskFormatException; + +/** + * Represents a task with a description and a status indicating whether it is done. + * This class also provides methods to mark, unmark, and save tasks. + */ + +public class Task { + protected String description; + protected boolean isDone; + + public Task(String description) { + this.description = description; + this.isDone = false; + } + + public Task(String description, boolean isDone) { + this.description = description; + this.isDone = isDone; + } + + /** + * Returns the description of the task. + * + * @return The task description. + */ + public String getDescription() { + return this.description; + } + + /** + * Returns the status of whether the task is done. + * + * @return true if the task is done, otherwise false. + */ + public boolean getIsDone() { + return isDone; + } + + /** + * Marks the task as done and returns the updated task. + * + * @return The updated task marked as done. + */ + public Task markTask() { + this.isDone = true; + return this; + } + + /** + * Marks the task as not done and returns the updated task. + * + * @return The updated task marked as not done. + */ + public Task unmarkTask() { + this.isDone = false; + return this; + } + + /** + * Returns the string representation of the task. + * + * @return A string showing the task status and description. + */ + public String toString() { + return (this.isDone ? "[X] " : "[ ] ") + this.description; + } + + /** + * Reads a saved task from a string and returns the corresponding Task object. + * + * @param taskString The string representing the saved task. + * @return The Task object created from the string. + * @throws InvalidTaskFormatException if the task format is invalid. + */ + public static Task readSavedTask(String taskString) throws InvalidTaskFormatException { + String[] parts = taskString.split(" \\| "); + if (parts.length < 3) { + throw new InvalidTaskFormatException("Alamak, invalid task format: " + taskString); + } + + String taskType = parts[0]; + boolean isDone = parts[1].equals("1"); + String description = parts[2]; + + switch (taskType) { + case "T": + return new Todo(description, isDone); + + case "D": + if (parts.length != 4) { + throw new InvalidTaskFormatException("Alamak, invalid Deadline format: " + taskString); + } + LocalDateTime by = LocalDateTime.parse(parts[3]); + return new Deadline(description, isDone, by); + + case "E": + if (parts.length != 5) { + throw new InvalidTaskFormatException("Alamak, invalid Event format: " + taskString); + } + LocalDateTime from = LocalDateTime.parse(parts[3]); + LocalDateTime to = LocalDateTime.parse(parts[4]); + return new Event(description, isDone, from, to); + + default: + throw new InvalidTaskFormatException("Alamak, unknown task type: " + taskType); + } + } + + /** + * Writes the task into a string format suitable for saving. + * + * @return The string representation of the task for saving. + * @throws InvalidTaskFormatException if the task cannot be written. + */ + public String writeSavedTask() throws InvalidTaskFormatException { + String spacer = " | "; + String isDone = this.isDone ? "1" : "0"; + + if (this instanceof Todo) { + return "T" + spacer + isDone + spacer + this.description; + + } else if (this instanceof Deadline d) { + return "D" + spacer + isDone + spacer + d.description + spacer + d.by; + + } else if (this instanceof Event e) { + return "E" + spacer + isDone + spacer + e.description + spacer + e.from + spacer + e.to; + + } else { + throw new InvalidTaskFormatException("Alamak, cannot write task: " + this.toString()); + } + } +} diff --git a/src/main/java/bangmang/tasks/TaskList.java b/src/main/java/bangmang/tasks/TaskList.java new file mode 100644 index 0000000000..e81d0c8631 --- /dev/null +++ b/src/main/java/bangmang/tasks/TaskList.java @@ -0,0 +1,103 @@ +package bangmang.tasks; + +import java.util.ArrayList; +import bangmang.exception.InvalidTaskFormatException; + +/** + * The TaskList class manages the list of tasks, providing methods to add, delete, + * mark as done, and retrieve tasks. + */ + +public class TaskList { + private ArrayList tasks; + + public TaskList() { + tasks = new ArrayList<>(); + } + + public TaskList(ArrayList tasks) { + this.tasks = tasks; + } + + /** + * Adds a task to the task list. + * + * @param task The task to be added. + */ + public void add(Task task) { + tasks.add(task); + } + + /** + * Deletes a task from the task list given its index. + * + * @param index The index of the task to delete. + * @throws InvalidTaskFormatException if the index is out of range. + */ + public void delete(int index) throws InvalidTaskFormatException { + if (index < 0 || index >= tasks.size()) { + throw new InvalidTaskFormatException("Alamak, task number out of range."); + } + tasks.remove(index); + } + + /** + * Returns a task from the task list given its index. + * + * @param index The index of the task to retrieve. + * @return The task at the specified index. + * @throws InvalidTaskFormatException if the index is out of range. + */ + public Task get(int index) throws InvalidTaskFormatException { + if (index < 0 || index >= tasks.size()) { + throw new InvalidTaskFormatException("Alamak, task number out of range."); + } + return tasks.get(index); + } + + /** + * Returns the number of tasks in the list. + * + * @return The size of the task list. + */ + public int size() { + return tasks.size(); + } + + /** + * Returns the ArrayList of tasks. + * + * @return The ArrayList containing all tasks. + */ + public ArrayList getTasks() { + return tasks; + } + + /** + * Marks a task as done given its index. + * + * @param index The index of the task to mark as done. + * @throws InvalidTaskFormatException if the index is out of range. + */ + public void markTask(int index) throws InvalidTaskFormatException { + if (index < 0 || index >= tasks.size()) { + throw new InvalidTaskFormatException("Alamak, task number out of range."); + } + Task t = tasks.get(index).markTask(); + tasks.set(index, t); + } + + /** + * Marks a task as undone given its index. + * + * @param index The index of the task to mark as undone. + * @throws InvalidTaskFormatException if the index is out of range. + */ + public void unmarkTask(int index) throws InvalidTaskFormatException { + if (index < 0 || index >= tasks.size()) { + throw new InvalidTaskFormatException("Alamak, task number out of range."); + } + Task t = tasks.get(index).unmarkTask(); + tasks.set(index, t); + } +} diff --git a/src/main/java/bangmang/tasks/Todo.java b/src/main/java/bangmang/tasks/Todo.java new file mode 100644 index 0000000000..4e455a5929 --- /dev/null +++ b/src/main/java/bangmang/tasks/Todo.java @@ -0,0 +1,26 @@ +/** + * Represents a Todo task. + * Inherits from the Task class and is used for tasks that do not have deadlines or specific time frames. + */ +package bangmang.tasks; + +public class Todo extends Task { + + public Todo(String description) { + super(description); + } + + public Todo(String description, boolean isDone) { + super(description, isDone); + } + + /** + * Returns the string representation of the Todo task. + * + * @return A string with the format specific to Todo tasks, including the task type. + */ + @Override + public String toString() { + return "[T]" + super.toString(); + } +} diff --git a/src/main/java/bangmang/ui/Ui.java b/src/main/java/bangmang/ui/Ui.java new file mode 100644 index 0000000000..4a47688464 --- /dev/null +++ b/src/main/java/bangmang/ui/Ui.java @@ -0,0 +1,164 @@ +package bangmang.ui; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.ArrayList; + +import bangmang.tasks.Task; +import bangmang.tasks.TaskList; + +/** + * The Ui class handles all interactions with the user. + * It provides methods to display messages, tasks, and errors, as well as read user input. + * The Ui is responsible for formatting output and providing a user-friendly interface. + */ + +public class Ui { + private static final String LINE_BREAK = "---------------------------------"; + private BufferedReader br; + + /** + * Constructor for the Ui class. + * Initializes a BufferedReader to handle user input. + */ + public Ui() { + br = new BufferedReader(new InputStreamReader(System.in)); + } + + /** + * Returns a welcome message when the chatbot starts. + * + * @return A string containing the welcome message. + */ + public String showWelcome() { + return "\nHello! I'm Ah Bang Mang.\nWhat you want sia?\n"; + } + + /** + * Returns help information containing all available commands. + * + * @return A string listing all the commands available to the user. + */ + public String showHelp() { + return "These are all the commands you can make ah:\n" + + "* List all tasks: list\n" + + "* Add a todo: todo {description}\n" + + "* Add a deadline: deadline {description} /by{date-time}\n" + + "* Add an event: event {description} /from{date-time} /to{date-time}\n" + + "* Mark a task as done: mark {task number}\n" + + "* Mark a task as undone: unmark {task number}\n" + + "* Delete a task: delete {task number}\n" + + "* Find task: find {description}\n" + + "* Exit chatbot: bye\n"; + } + + /** + * Returns an exit message when the user exits the chatbot. + * + * @return A string containing the exit message. + */ + public String showExit() { + return "\nOk, I zao first then!\n"; + } + + /** + * Returns a message indicating that there are no tasks in the task list. + * + * @return A string indicating an empty task list. + */ + public String showNoTasks() { + return "Wah shiok! No tasks at the moment!"; + } + + /** + * Displays all tasks in the task list. + * + * @param tasks The list of tasks to display. + * @return A string containing the formatted task list. + */ + public String showAllTasks(ArrayList tasks) { + StringBuilder sb = new StringBuilder(); + sb.append("Siao liao! This your current task list leh...\n"); + for (int i = 0; i < tasks.size(); i++) { + int listNumber = i + 1; + Task t = tasks.get(i); + sb.append(listNumber).append(". ").append(t.toString()).append("\n"); + } + return sb.toString(); + } + + /** + * Displays the results of a task search. + * + * @param tasks The list of tasks matching the search criteria. + * @return A string containing the formatted search results. + */ + public String showSearchResults(ArrayList tasks) { + StringBuilder sb = new StringBuilder(); + if (tasks.size() == 0) { + sb.append("Aiyo, got no matching tasks leh...\n"); + } else { + sb.append("Only got these few matching tasks ah...\n"); + for (int i = 0; i < tasks.size(); i++) { + int listNumber = i + 1; + Task t = tasks.get(i); + sb.append(listNumber).append(". ").append(t.toString()).append("\n"); + } + } + return sb.toString(); + } + + /** + * Returns a message after successfully adding a new task to the task list. + * + * @param t The task that was added. + * @param tasks The current task list. + * @return A string confirming the addition of the new task. + */ + public String showAddedNewTask(Task t, TaskList tasks) { + return "Added to list liao: " + t.toString() + + "\nSian, now got " + tasks.size() + " tasks in your list."; + } + + /** + * Returns a message after successfully marking a task as done. + * + * @param t The task that was marked as done. + * @return A string confirming the task was marked as done. + */ + public String showMarkedTask(Task t) { + return "Wah upz! You have marked this task as done: " + t.toString(); + } + + /** + * Returns a message after successfully unmarking a task. + * + * @param t The task that was unmarked. + * @return A string confirming the task was unmarked. + */ + public String showUnmarkedTask(Task t) { + return "Ok, I see you laze. You have marked this task as not done yet: " + t.toString(); + } + + /** + * Returns a message after successfully deleting a task from the task list. + * + * @param t The task that was deleted. + * @param tasks The current task list. + * @return A string confirming the deletion of the task. + */ + public String showDeletedTask(Task t, TaskList tasks) { + return "Wah shiok! This task no more liao: " + t.toString() + + "\nNow got only " + tasks.size() + " tasks left."; + } + + /** + * Returns an error message. + * + * @param message The error message to display. + * @return A string containing the error message. + */ + public String showError(String message) { + return "Alamak! " + message; + } +} diff --git a/src/main/resources/images/ChatbotImage.png b/src/main/resources/images/ChatbotImage.png new file mode 100644 index 0000000000..0532c9c2c3 Binary files /dev/null and b/src/main/resources/images/ChatbotImage.png differ diff --git a/src/main/resources/images/UserImage.png b/src/main/resources/images/UserImage.png new file mode 100644 index 0000000000..bec371ff65 Binary files /dev/null and b/src/main/resources/images/UserImage.png differ diff --git a/src/main/resources/view/DialogBox.fxml b/src/main/resources/view/DialogBox.fxml new file mode 100644 index 0000000000..fe672c90ea --- /dev/null +++ b/src/main/resources/view/DialogBox.fxml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + diff --git a/src/main/resources/view/MainWindow.fxml b/src/main/resources/view/MainWindow.fxml new file mode 100644 index 0000000000..8a3adf611e --- /dev/null +++ b/src/main/resources/view/MainWindow.fxml @@ -0,0 +1,44 @@ + + + + + + + + + + + +