diff --git a/.gitignore b/.gitignore index 2873e189e1..bff4c17d0a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,11 +7,24 @@ /.gradle/ /build/ src/main/resources/docs/ +caches/ +wrapper/ +daemon/ +native/ + +# Ignore compiled Java class files +*.class # MacOS custom attributes files created by Finder .DS_Store *.iml bin/ +/native/ +/caches/ +/daemon/ /text-ui-test/ACTUAL.TXT text-ui-test/EXPECTED-UNIX.TXT + +# Data files +/data/ \ No newline at end of file diff --git a/.tmp/gradle-worker-classpath9979931208124703051txt b/.tmp/gradle-worker-classpath9979931208124703051txt new file mode 100644 index 0000000000..3c3053bb46 --- /dev/null +++ b/.tmp/gradle-worker-classpath9979931208124703051txt @@ -0,0 +1,2 @@ +-cp +"C:\\Users\\Jing Chun\\Desktop\\CS2103T\\ip\\caches\\7.6.2\\workerMain\\gradle-worker.jar;C:\\Users\\Jing Chun\\Desktop\\CS2103T\\ip\\build\\classes\\java\\test;C:\\Users\\Jing Chun\\Desktop\\CS2103T\\ip\\build\\classes\\java\\main;C:\\Users\\Jing Chun\\Desktop\\CS2103T\\ip\\build\\resources\\main;C:\\Users\\Jing Chun\\Desktop\\CS2103T\\ip\\caches\\modules-2\\files-2.1\\org.openjfx\\javafx-fxml\\17.0.7\\dac7ac058b9c66a8a759dbf2d0ae4557749f3063\\javafx-fxml-17.0.7-win.jar;C:\\Users\\Jing Chun\\Desktop\\CS2103T\\ip\\caches\\modules-2\\files-2.1\\org.openjfx\\javafx-fxml\\17.0.7\\a686a637faa5c7fd95be464f75124414643b6ccd\\javafx-fxml-17.0.7-mac.jar;C:\\Users\\Jing Chun\\Desktop\\CS2103T\\ip\\caches\\modules-2\\files-2.1\\org.openjfx\\javafx-fxml\\17.0.7\\88571e5fa666c2d5bb560cc44d5b6158a7b9c8e5\\javafx-fxml-17.0.7-linux.jar;C:\\Users\\Jing Chun\\Desktop\\CS2103T\\ip\\caches\\modules-2\\files-2.1\\org.openjfx\\javafx-controls\\17.0.7\\bf1cb6a3c81e190d56fd84aeeb0fc36d44f9be70\\javafx-controls-17.0.7-win.jar;C:\\Users\\Jing Chun\\Desktop\\CS2103T\\ip\\caches\\modules-2\\files-2.1\\org.openjfx\\javafx-controls\\17.0.7\\9526295ad4cbee60dd2121802eb17a57d493e4d5\\javafx-controls-17.0.7-mac.jar;C:\\Users\\Jing Chun\\Desktop\\CS2103T\\ip\\caches\\modules-2\\files-2.1\\org.openjfx\\javafx-controls\\17.0.7\\caeb9696d8901c66c9990ff337df884e1867d5b8\\javafx-controls-17.0.7-linux.jar;C:\\Users\\Jing Chun\\Desktop\\CS2103T\\ip\\caches\\modules-2\\files-2.1\\org.openjfx\\javafx-controls\\17.0.7\\e5bc7891b9e2a389aeac4a5dcabf1130e852bf0c\\javafx-controls-17.0.7.jar;C:\\Users\\Jing Chun\\Desktop\\CS2103T\\ip\\caches\\modules-2\\files-2.1\\org.openjfx\\javafx-graphics\\17.0.7\\43ca0f3861f1e3a2cda4a6a7b8746bbf5bcbe754\\javafx-graphics-17.0.7-win.jar;C:\\Users\\Jing Chun\\Desktop\\CS2103T\\ip\\caches\\modules-2\\files-2.1\\org.openjfx\\javafx-graphics\\17.0.7\\d5463ebc0f524d0225a6613877c381abfcd81918\\javafx-graphics-17.0.7-mac.jar;C:\\Users\\Jing Chun\\Desktop\\CS2103T\\ip\\caches\\modules-2\\files-2.1\\org.openjfx\\javafx-graphics\\17.0.7\\c2029cf4a359ddb5fe0dec9d11407ea97940e06a\\javafx-graphics-17.0.7-linux.jar;C:\\Users\\Jing Chun\\Desktop\\CS2103T\\ip\\caches\\modules-2\\files-2.1\\org.openjfx\\javafx-graphics\\17.0.7\\55eca64e65d90976f9d054dceb3921f4d08f4e8b\\javafx-graphics-17.0.7.jar;C:\\Users\\Jing Chun\\Desktop\\CS2103T\\ip\\caches\\modules-2\\files-2.1\\org.openjfx\\javafx-base\\17.0.7\\2b79238d65ff33212eafb04acc6acbb7cd0a3300\\javafx-base-17.0.7-win.jar;C:\\Users\\Jing Chun\\Desktop\\CS2103T\\ip\\caches\\modules-2\\files-2.1\\org.openjfx\\javafx-base\\17.0.7\\2c983af31f7a8525a7730336295e084c42e51598\\javafx-base-17.0.7-mac.jar;C:\\Users\\Jing Chun\\Desktop\\CS2103T\\ip\\caches\\modules-2\\files-2.1\\org.openjfx\\javafx-base\\17.0.7\\9f27959208043d012b99019a0a9d53d63bf40c56\\javafx-base-17.0.7-linux.jar;C:\\Users\\Jing Chun\\Desktop\\CS2103T\\ip\\caches\\modules-2\\files-2.1\\org.openjfx\\javafx-base\\17.0.7\\5ba6d336d0e9a4134d96bb402890f5570c4562ae\\javafx-base-17.0.7.jar;C:\\Users\\Jing Chun\\Desktop\\CS2103T\\ip\\caches\\modules-2\\files-2.1\\org.junit.platform\\junit-platform-engine\\1.10.0\\276c4edcf64fabb5a139fa7b4f99330d7a93b804\\junit-platform-engine-1.10.0.jar;C:\\Users\\Jing Chun\\Desktop\\CS2103T\\ip\\caches\\modules-2\\files-2.1\\org.junit.platform\\junit-platform-commons\\1.10.0\\d533ff2c286eaf963566f92baf5f8a06628d2609\\junit-platform-commons-1.10.0.jar;C:\\Users\\Jing Chun\\Desktop\\CS2103T\\ip\\caches\\modules-2\\files-2.1\\org.junit.jupiter\\junit-jupiter-engine\\5.10.0\\90587932d718fc51a48112d33045a18476c542ad\\junit-jupiter-engine-5.10.0.jar;C:\\Users\\Jing Chun\\Desktop\\CS2103T\\ip\\caches\\modules-2\\files-2.1\\org.junit.jupiter\\junit-jupiter-api\\5.10.0\\2fe4ba3d31d5067878e468c96aa039005a9134d3\\junit-jupiter-api-5.10.0.jar;C:\\Users\\Jing Chun\\Desktop\\CS2103T\\ip\\caches\\modules-2\\files-2.1\\org.opentest4j\\opentest4j\\1.3.0\\152ea56b3a72f655d4fd677fc0ef2596c3dd5e6e\\opentest4j-1.3.0.jar" diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000000..7c1be89acb --- /dev/null +++ b/build.gradle @@ -0,0 +1,56 @@ +plugins { + id 'java' + id 'application' + id 'com.github.johnrengelman.shadow' version '7.1.2' +} + +repositories { + mavenCentral() +} + +dependencies { + String javaFxVersion = '17.0.7' + + testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.10.0' + testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.10.0' + 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("myapp.Launcher") +} + +shadowJar { + archiveBaseName = "JacobMalon" + archiveClassifier = null + archiveFileName = 'JacobMalon.jar' +} + +run{ + standardInput = System.in +} \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index 47b9f984f7..dd1db7f8b5 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,30 +1,154 @@ -# Duke User Guide +# JacobMalon Task Manager -// Update the title above to match the actual product name +A desktop task management application optimized for users who prefer typing over mouse interactions. If you can type fast, JacobMalon can help you manage tasks more efficiently than traditional GUI apps. -// Product screenshot goes here +## Quick Start -// Product intro goes here +1. Ensure you have Java 17 or above installed. +2. Download the latest `JacobMalon.jar` from [here](releases/latest). +3. Run the command: `java -jar JacobMalon.jar` -## Adding deadlines +## Features -// Describe the action and its outcome. +### Notes about Command Format +* Words in UPPER_CASE are parameters you need to provide +* Parameters can be in any order +* Dates should be in the format: `d/M/yyyy HHmm` (e.g., `2/12/2023 1800`) -// Give examples of usage +### 1. Adding Tasks +You can add three types of tasks: -Example: `keyword (optional arguments)` +a) **Todo Task** +``` +todo DESCRIPTION +todo read book +``` + +b) **Deadline Task** +``` +deadline DESCRIPTION /by DATE_TIME +deadline return book /by 2/12/2023 1800 +``` + +c) **Event Task** +``` +event DESCRIPTION /from START_DATE_TIME /to END_DATE_TIME +event team meeting /from 2/12/2023 1400 /to 2/12/2023 1600 +``` + +### 2. Viewing Tasks + +a) **List all tasks** +``` +list +``` + +b) **Find tasks by keyword** +``` +find KEYWORD +find book +``` + +### 3. Managing Tasks + +a) **Mark task as done** +``` +mark INDEX +mark 1 +``` + +b) **Mark task as not done** +``` +unmark INDEX +unmark 1 +``` -// A description of the expected outcome goes here +c) **Delete task** +``` +delete INDEX +delete 1 +``` +### 4. Exiting the Program ``` -expected output +bye ``` -## Feature ABC +## Duplicate Task Detection + +The application will warn you when you try to add a duplicate task: +* For todos: Same description +* For deadlines: Same description and deadline +* For events: Same description, start time, and end time + +## Data Storage + +* Tasks are automatically saved after each command +* Data is stored in `list.txt` in the same directory as the application +* The file is automatically loaded when you start the application + +## FAQ + +**Q: How do I transfer my tasks to another computer?** +A: Copy the `list.txt` file to the same directory as the JacobMalon.jar on the new computer. + +**Q: What happens if I enter an invalid date format?** +A: The application will show an error message. Remember to use the format: d/M/yyyy HHmm + +## Command Summary + +| Command | Format | Example | +|---------|---------|---------| +| Add todo | `todo DESCRIPTION` | `todo read book` | +| Add deadline | `deadline DESCRIPTION /by DATE_TIME` | `deadline return book /by 2/12/2023 1800` | +| Add event | `event DESCRIPTION /from START /to END` | `event meeting /from 2/12/2023 1400 /to 2/12/2023 1600` | +| List | `list` | `list` | +| Find | `find KEYWORD` | `find book` | +| Mark done | `mark INDEX` | `mark 1` | +| Mark not done | `unmark INDEX` | `unmark 1` | +| Delete | `delete INDEX` | `delete 1` | +| Exit | `bye` | `bye` | -// Feature details +## Development + +### Project Structure + +``` +src +├── main +│ ├── java +│ │ └── myapp +│ │ ├── JacobMalon.java +│ │ ├── Main.java +│ │ └── taskscommand +│ │ ├── Task.java +│ │ ├── ToDo.java +│ │ ├── Deadline.java +│ │ └── Event.java +│ └── resources +│ └── view +│ └── MainWindow.fxml +└── test + └── java + └── taskscommand + ├── TaskTest.java + └── DeadlineTest.java +``` + +### Running Tests + +```bash +./gradlew test +``` + +### Building JAR + +```bash +./gradlew shadowJar +``` +The JAR file will be created in `build/libs/JacobMalon.jar` -## Feature XYZ +## License -// Feature details \ No newline at end of file +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. \ No newline at end of file diff --git a/docs/Ui.png b/docs/Ui.png new file mode 100644 index 0000000000..3fefcec8f8 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/list.txt b/list.txt new file mode 100644 index 0000000000..53efa02aed --- /dev/null +++ b/list.txt @@ -0,0 +1,5 @@ +todo reead book +todo readbook +deadline return book /by 2/12/2023 1800 +event team meeting /from 2/12/2023 1400 /to 2/12/2023 1600 +event team meeting /from 2/12/2023 1400 /to 2/12/2023 1600 diff --git a/native/38dada09dfb8b06ba9b0570ebf7e218e3eb74d4ef43ca46872605cf95ebc2f47/windows-amd64/native-platform-file-events.dll b/native/38dada09dfb8b06ba9b0570ebf7e218e3eb74d4ef43ca46872605cf95ebc2f47/windows-amd64/native-platform-file-events.dll new file mode 100644 index 0000000000..408283d6e3 Binary files /dev/null and b/native/38dada09dfb8b06ba9b0570ebf7e218e3eb74d4ef43ca46872605cf95ebc2f47/windows-amd64/native-platform-file-events.dll differ diff --git a/native/c067742578af261105cb4f569cf0c3c89f3d7b1fecec35dd04571415982c5e48/windows-amd64/native-platform.dll b/native/c067742578af261105cb4f569cf0c3c89f3d7b1fecec35dd04571415982c5e48/windows-amd64/native-platform.dll new file mode 100644 index 0000000000..ccc4b065ad Binary files /dev/null and b/native/c067742578af261105cb4f569cf0c3c89f3d7b1fecec35dd04571415982c5e48/windows-amd64/native-platform.dll differ diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..507bb6721a --- /dev/null +++ b/src/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: myapp.JacobMalon + 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/myapp/DialogBox.java b/src/main/java/myapp/DialogBox.java new file mode 100644 index 0000000000..150a04aed7 --- /dev/null +++ b/src/main/java/myapp/DialogBox.java @@ -0,0 +1,60 @@ +package myapp; +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 getDukeDialog(String text, Image img) { + var db = new DialogBox(text, img); + db.flip(); + return db; + } +} + diff --git a/src/main/java/myapp/JacobMalon.class b/src/main/java/myapp/JacobMalon.class new file mode 100644 index 0000000000..d6d5fa705a Binary files /dev/null and b/src/main/java/myapp/JacobMalon.class differ diff --git a/src/main/java/myapp/JacobMalon.java b/src/main/java/myapp/JacobMalon.java new file mode 100644 index 0000000000..c9064f8f6d --- /dev/null +++ b/src/main/java/myapp/JacobMalon.java @@ -0,0 +1,116 @@ +package myapp; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; + +import taskscommand.Deadline; +import taskscommand.Event; +import taskscommand.TaskManager; +import taskscommand.ToDo; + +/** + * The main class for the JacobMalon chatbot application. + */ +public class JacobMalon { + private static final String CHATBOT_NAME = "Jacob"; + private final TaskManager taskManager; + public boolean isExit = false; + private static final DateTimeFormatter INPUT_FORMATTER = DateTimeFormatter.ofPattern("d/M/yyyy HHmm"); + + /** + * Constructs a new JacobMalon instance. + */ + public JacobMalon() { + this.taskManager = new TaskManager(); + } + + /** + * Processes a single input command and returns the response. + * @param input The input command. + * @return The response from the chatbot. + */ + public String getResponse(String input) { + StringBuilder response = new StringBuilder(); + try { + if (input.equals("bye")) { + response.append("Bye. Hope to see you again soon!"); + System.exit(0); + } else if (input.equals("list")) { + // CHANGED: Now using taskManager.listTasks() that returns a string instead of printing to the terminal. + response.append(taskManager.listTasks()); + } else if (input.startsWith("mark ")) { + String[] parts = input.split(" "); + if (parts.length < 2) { + throw new IllegalArgumentException("mark command must be followed by a task number."); + } + // Append the result from taskManager.markTask instead of printing. + response.append(taskManager.markTask(Integer.parseInt(parts[1]))); + } else if (input.startsWith("unmark ")) { + // Append the result from taskManager.unmarkTask. + response.append(taskManager.unmarkTask(Integer.parseInt(input.split(" ")[1]))); + } else if (input.startsWith("delete ")) { + // Append the result from taskManager.deleteTask. + response.append(taskManager.deleteTask(Integer.parseInt(input.split(" ")[1]))); + } else if (input.startsWith("todo ")) { + String taskDescription = input.substring(5).trim(); + if (taskDescription.isEmpty()) { + throw new IllegalArgumentException("The description of a todo cannot be empty."); + } + // Append the result from taskManager.addTask for a new ToDo. + response.append(taskManager.addTask(new ToDo(taskDescription))); + } else if (input.startsWith("deadline ")) { + String[] parts = input.substring(9).split(" /by ", 2); + if (parts.length < 2) { + throw new IllegalArgumentException( + "deadline command must be followed by description and date (e.g., deadline return book /by 2/12/2023 1800)"); + } + // Validate date format by trying to parse it + try { + LocalDateTime.parse(parts[1], INPUT_FORMATTER); + } catch (DateTimeParseException e) { + throw new IllegalArgumentException( + "date must be in d/M/yyyy HHmm format (e.g., 2/12/2023 1800)"); + } + response.append(taskManager.addTask(new Deadline(parts[0], parts[1]))); + } else if (input.startsWith("list date ")) { + String date = input.substring(10).trim(); + // Append the result from taskManager.listTasksByDate. + response.append(taskManager.listTasksByDate(date)); + } else if (input.startsWith("event ")) { + String[] parts = input.substring(6).split(" /from | /to ", 3); + if (parts.length < 3) { + throw new IllegalArgumentException( + "event command must be followed by description and timing (e.g., event team meeting /from 2/12/2023 1400 /to 2/12/2023 1600)"); + } + // Validate both dates + try { + LocalDateTime from = LocalDateTime.parse(parts[1], INPUT_FORMATTER); + LocalDateTime to = LocalDateTime.parse(parts[2], INPUT_FORMATTER); + if (!from.isBefore(to)) { + throw new IllegalArgumentException("Event start time must be before end time"); + } + } catch (DateTimeParseException e) { + throw new IllegalArgumentException( + "dates must be in d/M/yyyy HHmm format (e.g., 2/12/2023 1400)"); + } + response.append(taskManager.addTask(new Event(parts[0], parts[1], parts[2]))); + } else if (input.startsWith("find ")) { + String keyword = input.substring(5).trim(); + // CHANGED: Append the result from taskManager.findTasks. + response.append(taskManager.findTasks(keyword)); + } else { + throw new IllegalArgumentException("I'm sorry, but I don't understand that command."); + } + } catch (Exception e) { + response.append("Error: ").append(e.getMessage()); + } + return response.toString(); + } + + public static void main(String[] args) { + JacobMalon chatbot = new JacobMalon(); + System.out.println("Hello! I'm " + CHATBOT_NAME); + System.out.println("What can I do for you?"); + } +} diff --git a/src/main/java/myapp/Launcher.java b/src/main/java/myapp/Launcher.java new file mode 100644 index 0000000000..a774438a90 --- /dev/null +++ b/src/main/java/myapp/Launcher.java @@ -0,0 +1,12 @@ +package myapp; + +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); + } +} \ No newline at end of file diff --git a/src/main/java/myapp/Main.java b/src/main/java/myapp/Main.java new file mode 100644 index 0000000000..59055bec0e --- /dev/null +++ b/src/main/java/myapp/Main.java @@ -0,0 +1,36 @@ +package myapp; +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; + + +/** + * A GUI for Duke using FXML. + */ +public class Main extends Application { + + private JacobMalon Jacob = new JacobMalon(); + + @Override + public void start(Stage stage) { + try { + FXMLLoader fxmlLoader = new FXMLLoader(Main.class.getResource("/view/MainWindow.fxml")); + AnchorPane ap = fxmlLoader.load(); + Scene scene = new Scene(ap); + stage.setScene(scene); + fxmlLoader.getController().setDuke(Jacob); // inject the Duke instance + stage.show(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void main(String[] args) { + launch(args); + } +} + diff --git a/src/main/java/myapp/MainWindow.java b/src/main/java/myapp/MainWindow.java new file mode 100644 index 0000000000..a1ca79db34 --- /dev/null +++ b/src/main/java/myapp/MainWindow.java @@ -0,0 +1,70 @@ +package myapp; + +import javafx.animation.KeyFrame; +import javafx.animation.Timeline; +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; + +/** + * 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 JacobMalon bot; + + private Image userImage = new Image(this.getClass().getResourceAsStream("/images/user.png")); + private Image dukeImage = new Image(this.getClass().getResourceAsStream("/images/Jacob.png")); + + @FXML + public void initialize() { + scrollPane.vvalueProperty().bind(dialogContainer.heightProperty()); + dialogContainer.getChildren().addAll( + DialogBox.getDukeDialog("Hello! I'm Jacob\n" + "What can I do for you?", dukeImage) + ); + } + + /** Injects the Duke instance */ + public void setDuke(JacobMalon bot) { + this.bot = bot; + } + + /** + * 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 = bot.getResponse(input); + dialogContainer.getChildren().addAll( + DialogBox.getUserDialog(input, userImage), + DialogBox.getDukeDialog(response, dukeImage) + ); + if (bot.isExit) { + this.dialogContainer.getChildren().addAll( + DialogBox.getDukeDialog("Close in 3 seconds", dukeImage) + ); + userInput.setDisable(true); + sendButton.setDisable(true); + Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(3), event -> Platform.exit())); + timeline.play(); + } + userInput.clear(); + } +} + diff --git a/src/main/java/taskscommand/Deadline.class b/src/main/java/taskscommand/Deadline.class new file mode 100644 index 0000000000..f6fb662dee Binary files /dev/null and b/src/main/java/taskscommand/Deadline.class differ diff --git a/src/main/java/taskscommand/Deadline.java b/src/main/java/taskscommand/Deadline.java new file mode 100644 index 0000000000..0f75eccb4b --- /dev/null +++ b/src/main/java/taskscommand/Deadline.java @@ -0,0 +1,43 @@ +package taskscommand; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; + +/** + * Represents a task with a deadline. + */ +public class Deadline extends Task { + //DeadLine + protected LocalDateTime by; + private static final DateTimeFormatter INPUT_FORMATTER = DateTimeFormatter.ofPattern("d/M/yyyy HHmm"); + private static final DateTimeFormatter OUTPUT_FORMATTER = DateTimeFormatter.ofPattern("MMM d yyyy, h:mma"); + + /** + * Constructs a new Deadline task. + * @param description The task description. + * @param by The deadline date and time in d/M/yyyy HHmm format. + * @throws DateTimeParseException if the date format is invalid. + */ + public Deadline(String description, String by) throws DateTimeParseException { + super(description); + assert by != null && !by.trim().isEmpty() : "Deadline date/time cannot be null or empty"; + this.by = LocalDateTime.parse(by, INPUT_FORMATTER); + assert this.by != null : "deadline command must be followed by description and date (e.g., deadline return book /by 2/12/2023 1800)"; + } + + /** + * Returns the deadline date and time. + * @return The deadline date and time in d/M/yyyy HHmm format. + */ + public String getDeadline() { + assert by != null : "Deadline date/time should never be null"; + return by.format(INPUT_FORMATTER); + } + + @Override + public String toString() { + assert by != null : "Deadline date/time should never be null"; + return "[D]" + super.toString() + " (by: " + by.format(OUTPUT_FORMATTER) + ")"; + } +} diff --git a/src/main/java/taskscommand/Event.class b/src/main/java/taskscommand/Event.class new file mode 100644 index 0000000000..ffaf7efe0d Binary files /dev/null and b/src/main/java/taskscommand/Event.class differ diff --git a/src/main/java/taskscommand/Event.java b/src/main/java/taskscommand/Event.java new file mode 100644 index 0000000000..027fa719bf --- /dev/null +++ b/src/main/java/taskscommand/Event.java @@ -0,0 +1,49 @@ +package taskscommand; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +public class Event extends Task { + private final LocalDateTime from; + private final LocalDateTime to; + private static final DateTimeFormatter INPUT_FORMATTER = + DateTimeFormatter.ofPattern("d/M/yyyy HHmm"); + private static final DateTimeFormatter OUTPUT_FORMATTER = + DateTimeFormatter.ofPattern("MMM d yyyy, h:mma"); + + public Event(String description, String from, String to) { + super(description); + assert from != null && !from.trim().isEmpty() : "Event start time cannot be null or empty"; + assert to != null && !to.trim().isEmpty() : "Event end time cannot be null or empty"; + + this.from = LocalDateTime.parse(from, INPUT_FORMATTER); + this.to = LocalDateTime.parse(to, INPUT_FORMATTER); + + assert this.from.isBefore(this.to) : "Event start time must be before end time"; + } + + /** + * Gets the start time of the event. + * @return The start time in d/M/yyyy HHmm format + */ + public String getFrom() { + assert from != null : "Event start time should never be null"; + return from.format(INPUT_FORMATTER); + } + + /** + * Gets the end time of the event. + * @return The end time in d/M/yyyy HHmm format + */ + public String getTo() { + assert to != null : "Event end time should never be null"; + return to.format(INPUT_FORMATTER); + } + + @Override + public String toString() { + assert from != null && to != null : "Event times should never be null"; + return "[E]" + super.toString() + " (from: " + from.format(OUTPUT_FORMATTER) + + " to: " + to.format(OUTPUT_FORMATTER) + ")"; + } +} diff --git a/src/main/java/taskscommand/Task.class b/src/main/java/taskscommand/Task.class new file mode 100644 index 0000000000..77f4f1ca01 Binary files /dev/null and b/src/main/java/taskscommand/Task.class differ diff --git a/src/main/java/taskscommand/Task.java b/src/main/java/taskscommand/Task.java new file mode 100644 index 0000000000..b0ae4f5dad --- /dev/null +++ b/src/main/java/taskscommand/Task.java @@ -0,0 +1,37 @@ +package taskscommand; + +public class Task { + protected String description; + protected boolean isDone; + + public Task(String description) { + assert description != null && !description.trim().isEmpty() : "Task description cannot be null or empty"; + this.description = description; + this.isDone = false; + } + + public String getStatusIcon() { + return (isDone ? "X" : " "); + } + + @Override + public String toString() { + assert description != null : "Description should never be null"; + return "[" + this.getStatusIcon() + "] " + this.description; + } + + public String getDescription() { + assert description != null : "Description should never be null"; + return this.description; + } + + public void markAsDone() { + assert !isDone : "Task is already marked as done"; + this.isDone = true; + } + + public void markAsNotDone() { + assert isDone : "Task is already marked as not done"; + this.isDone = false; + } +} \ No newline at end of file diff --git a/src/main/java/taskscommand/TaskManager.class b/src/main/java/taskscommand/TaskManager.class new file mode 100644 index 0000000000..ac0d71249f Binary files /dev/null and b/src/main/java/taskscommand/TaskManager.class differ diff --git a/src/main/java/taskscommand/TaskManager.java b/src/main/java/taskscommand/TaskManager.java new file mode 100644 index 0000000000..5f14d1cc11 --- /dev/null +++ b/src/main/java/taskscommand/TaskManager.java @@ -0,0 +1,258 @@ +package taskscommand; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +/** + * Manages a collection of tasks, providing operations to add, delete, mark, and list tasks. + */ +public class TaskManager { + private static final String STORAGE_FILE = "list.txt"; + private static final String TASK_ADDED_MESSAGE = "Got it. I've added this task:"; + private static final String TASK_DELETED_MESSAGE = "Noted. I've removed this task:"; + private static final String TASK_MARKED_MESSAGE = "Nice! I've marked this task as done:"; + private static final String TASK_UNMARKED_MESSAGE = "Okay! I've marked this task as not done:"; + private static final String DUPLICATE_TASK_MESSAGE = "This task already exists in your list!"; + private static final String DUPLICATE_TASK_ADDED_ANYWAY = "Adding it anyway as requested."; + + private final ArrayList tasks; + private final DateTimeFormatter formatter; + + public TaskManager() { + tasks = new ArrayList<>(); + formatter = DateTimeFormatter.ofPattern("MMM dd yyyy, h:mma"); + loadFromFile(); + } + + /** + * Checks if a task is a duplicate of an existing task. + * A task is considered a duplicate if it has the same description + * and, in case of Deadline/Event tasks, the same timing. + */ + private boolean isDuplicate(Task newTask) { + return tasks.stream().anyMatch(existingTask -> { + if (!existingTask.getDescription().equals(newTask.getDescription())) { + return false; + } + + // For Deadline tasks, check the deadline timing + if (existingTask instanceof Deadline && newTask instanceof Deadline) { + return ((Deadline) existingTask).getDeadline() + .equals(((Deadline) newTask).getDeadline()); + } + + // For Event tasks, check both start and end timing + if (existingTask instanceof Event && newTask instanceof Event) { + Event existing = (Event) existingTask; + Event newEvent = (Event) newTask; + return existing.getFrom().equals(newEvent.getFrom()) + && existing.getTo().equals(newEvent.getTo()); + } + + // For Todo tasks, description equality is sufficient + return true; + }); + } + + /** + * Adds a new task to the list and saves to storage. + * If the task is a duplicate, warns the user but adds it anyway. + */ + public String addTask(Task task) { + assert task != null : "Task cannot be null"; + + StringBuilder response = new StringBuilder(); + if (isDuplicate(task)) { + response.append(DUPLICATE_TASK_MESSAGE).append("\n"); + response.append(DUPLICATE_TASK_ADDED_ANYWAY).append("\n"); + } + + tasks.add(task); + response.append(TASK_ADDED_MESSAGE).append("\n"); + response.append(task).append("\n"); + response.append("Now you have " + tasks.size() + " tasks in the list."); + saveToFile(); + return response.toString(); + } + + /** + * Deletes a task at the specified index. + */ + public String deleteTask(int index) { + validateTaskIndex(index); + + Task deletedTask = tasks.remove(index - 1); + StringBuilder response = new StringBuilder(); + response.append(TASK_DELETED_MESSAGE).append("\n"); + response.append(deletedTask); + saveToFile(); + return response.toString(); + } + + /** + * Marks a task as done at the specified index. + */ + public String markTask(int index) { + validateTaskIndex(index); + + Task task = tasks.get(index - 1); + task.markAsDone(); + StringBuilder response = new StringBuilder(); + response.append(TASK_MARKED_MESSAGE).append("\n"); + response.append(task); + saveToFile(); + return response.toString(); + } + + /** + * Marks a task as not done at the specified index. + */ + public String unmarkTask(int index) { + validateTaskIndex(index); + + Task task = tasks.get(index - 1); + task.markAsNotDone(); + StringBuilder response = new StringBuilder(); + response.append(TASK_UNMARKED_MESSAGE).append("\n"); + response.append(task); + saveToFile(); + return response.toString(); + } + + /** + * Lists all tasks in the list. + */ + public String listTasks() { + if (tasks.isEmpty()) { + return "No tasks in the list."; + } + + StringBuilder response = new StringBuilder("Here are the tasks in your list:\n"); + for (int i = 0; i < tasks.size(); i++) { + response.append(String.format("%d.%s\n", i + 1, tasks.get(i))); + } + return response.toString().trim(); + } + + /** + * Lists tasks with the specified date. + */ + public String listTasksByDate(String dateStr) { + List matchingTasks = findTasksByDate(dateStr); + + if (matchingTasks.isEmpty()) { + return "No tasks found for the specified date."; + } + + StringBuilder response = new StringBuilder("Here are the tasks for " + dateStr + ":\n"); + for (int i = 0; i < matchingTasks.size(); i++) { + response.append(String.format("%d.%s\n", i + 1, matchingTasks.get(i))); + } + return response.toString().trim(); + } + + /** + * Finds tasks containing the specified keyword. + */ + public String findTasks(String keyword) { + assert keyword != null && !keyword.trim().isEmpty() : "Search keyword cannot be empty"; + + List matchingTasks = tasks.stream() + .filter(task -> task.getDescription().toLowerCase() + .contains(keyword.toLowerCase())) + .collect(Collectors.toList()); + + return displaySearchResults(matchingTasks, keyword); + } + + // Private helper methods + private void validateTaskIndex(int index) { + if (index < 1 || index > tasks.size()) { + throw new IllegalArgumentException( + "Invalid task number. Please provide a number between 1 and " + tasks.size()); + } + } + + private List findTasksByDate(String dateStr) { + LocalDateTime searchDate = LocalDateTime.parse(dateStr, formatter); + return tasks.stream() + .filter(task -> task instanceof Deadline + && ((Deadline) task).getDeadline().equals(searchDate)) + .collect(Collectors.toList()); + } + + private String displaySearchResults(List matchingTasks, String keyword) { + if (matchingTasks.isEmpty()) { + return "No matching tasks found for: " + keyword; + } + + StringBuilder response = new StringBuilder("Here are the matching tasks in your list:\n"); + for (int i = 0; i < matchingTasks.size(); i++) { + response.append(String.format("%d.%s\n", i + 1, matchingTasks.get(i))); + } + return response.toString().trim(); + } + + // File operations + private void saveToFile() { + try (PrintWriter writer = new PrintWriter(STORAGE_FILE)) { + for (Task task : tasks) { + if (task instanceof ToDo) { + writer.println("todo " + task.getDescription()); + } else if (task instanceof Deadline) { + Deadline deadline = (Deadline) task; + writer.println("deadline " + deadline.getDescription() + " /by " + deadline.getDeadline()); + } else if (task instanceof Event) { + Event event = (Event) task; + writer.println("event " + event.getDescription() + " /from " + event.getFrom() + " /to " + event.getTo()); + } + } + } catch (IOException e) { + throw new RuntimeException("Error saving to file: " + e.getMessage()); + } + } + + private void loadFromFile() { + File file = new File(STORAGE_FILE); + if (!file.exists()) { + try { + file.createNewFile(); + } catch (IOException e) { + throw new RuntimeException("Error creating storage file: " + e.getMessage()); + } + return; + } + + try (BufferedReader reader = new BufferedReader(new FileReader(file))) { + String line; + while ((line = reader.readLine()) != null) { + if (!line.trim().isEmpty()) { + if (line.startsWith("todo ")) { + tasks.add(new ToDo(line.substring(5))); + } else if (line.startsWith("deadline ")) { + String[] parts = line.substring(9).split(" /by ", 2); + String description = parts[0]; + String date = parts[1]; + tasks.add(new Deadline(description, date)); + } else if (line.startsWith("event ")) { + String[] parts = line.substring(6).split(" /from | /to ", 3); + String description = parts[0]; + String fromDate = parts[1]; + String toDate = parts[2]; + tasks.add(new Event(description, fromDate, toDate)); + } + } + } + } catch (IOException e) { + throw new RuntimeException("Error loading from file: " + e.getMessage()); + } + } +} diff --git a/src/main/java/taskscommand/ToDo.class b/src/main/java/taskscommand/ToDo.class new file mode 100644 index 0000000000..1fb22910fe Binary files /dev/null and b/src/main/java/taskscommand/ToDo.class differ diff --git a/src/main/java/taskscommand/ToDo.java b/src/main/java/taskscommand/ToDo.java new file mode 100644 index 0000000000..12c68c6816 --- /dev/null +++ b/src/main/java/taskscommand/ToDo.java @@ -0,0 +1,12 @@ +package taskscommand; + +public class ToDo extends Task { + public ToDo(String description) { + super(description); + } + + @Override + public String toString() { + return "[T]" + super.toString(); + } +} diff --git a/src/main/resources/images/Jacob.png b/src/main/resources/images/Jacob.png new file mode 100644 index 0000000000..6175095aad Binary files /dev/null and b/src/main/resources/images/Jacob.png differ diff --git a/src/main/resources/images/user.png b/src/main/resources/images/user.png new file mode 100644 index 0000000000..d9f672c587 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..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..6af8bbfade --- /dev/null +++ b/src/main/resources/view/MainWindow.fxml @@ -0,0 +1,44 @@ + + + + + + + + + + + +