diff --git a/.gitignore b/.gitignore index 2873e189e1..5189d1d3c1 100644 --- a/.gitignore +++ b/.gitignore @@ -13,5 +13,7 @@ src/main/resources/docs/ *.iml bin/ +/data/ + /text-ui-test/ACTUAL.TXT text-ui-test/EXPECTED-UNIX.TXT diff --git a/README.md b/README.md index 8715d4d915..7d02921820 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,187 @@ -# 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 11, 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 11** (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 - ____ _ - | _ \ _ _| | _____ - | | | | | | | |/ / _ \ - | |_| | |_| | < __/ - |____/ \__,_|_|\_\___| - ``` +# Lite User Guide + +Lite is a user-friendly chatbot, especially designed towards +forgetful students to keep track of their ToDos, Events, and Deadlines. +Lite will be able to keep track the dates and status of completion of tasks, +allowing better planning for your future tasks. + +## Downloading and running the file +Prerequisite: Ensure that java and JDK 11 is downloaded on your computer + +1. Go to Releases > iP v0.2 > lite.jar +2. Run lite.jar by typing ./lite.jar or java -jar lite.jar in the Terminal + +## List of Features + +- [x] Adding ToDo task +- [x] Adding Event task +- [x] Adding Deadline task +- [x] Mark tasks as done +- [x] Unmark tasks as undone +- [x] Keep track and list out all of the added tasks +- [x] Delete tasks from the list +- [x] Find a task using a keyword +- [x] Close the program +- [ ] Reminder (Coming soon) + + +## Adding Todo task + +Allows users to add a ToDo task that has no date. + +Format: todo [description] + +Example: `todo return a book` + +Expected output: + +``` +Got it. I've added this task: +[T][] return a book +Now you have tasks in the list +``` + +## Adding Deadline Task + +Allows users to add a Deadline task that has a due date. + +Format: deadline [DESCRIPTION] /by [DATE]. +- The date has to be in the format of YYYY-MM-DD, and a time from 00:00 to 23:59. + +Example: deadline 2103T Assignment /by 2024-02-20 23:59 + + +Expected output: + +``` +Got it. I've added this task: +[D][] 2103T Assignment (by: FEBRUARY 20 2024 23:59) +Now you have tasks in the list +``` + + +## Adding Event Task + +Allows users to add a Event task that has a start date and end date. + +Format:event [DESCRIPTION] /from [DATE] /to [DATE] +- The date has to be in the format of YYYY-MM-DD, and a time from 00:00 to 23:59. + +Example: event 2101 group meeting /from 2024-02-20 17:30 /to 2024-02-20 18:30 + + +Expected output: + +``` +Got it. I've added this task: +[E][] 2101 group meeting (from: FEBRUARY 20 2024 17:30 to: +FEBRUARY 20 2024 18:30) +Now you have tasks in the list +``` + +## Mark Tasks as Done + +Allow users to mark their tasks as completed + +Format: mark INDEX + +Example: mark 1 + +Assuming that the very first task you added was the ToDo task of returning a book, +this is the expected output: + +``` +This task has been marked as done! +[T][X] return a book +``` + +## Unmark Tasks + +Similarly, you can also unmark your tasks to undo it. This is mainly to undo +if you incorrectly marked your task as done. + +Format: unmark INDEX + +Example: unmark 1 + +Assuming that the very first task you added was the ToDo task of returning a book, +this is the expected output: + +``` +This task has been unmarked! +[T][] return a book +``` + +## List out all the tasks added + +Allow users to see the list of tasks that they have added so far. +It also keeps track of the tasks that may have been added before + +Format: list + +Assuming that you had added a todo, deadline, and event task in that respective order, +this is the expected output: + +``` +1. [T][] return a book +2. [D][] 2103T Assignment (by: FEBRUARY 20 2024 23:59) +3. [E][] 2101 group meeting (from: FEBRUARY 20 2024 17:30 to: +FEBRUARY 20 2024 18:30) +``` + + +## Delete Tasks + +Allow users to delete the tasks that are in the list + +Format: delete INDEX + +Example: delete 1 + +Assuming that the very first task you added was the ToDo task of returning a book, +this is the expected output: + +``` +Noted. I've removed this task: +[T][] return a book +Now you have tasks in the list +``` + +Also note that if you delete a task, all the index after that task will drop by 1. +So if you had added all a todo, deadline, event tasks all in order, calling list will result in this output: + +``` +Here are the tasks in your list: +1. [D][] 2103T Assignment (by: FEBRUARY 20 2024 23:59) +2. [E][] 2101 group meeting (from: FEBRUARY 20 2024 17:30 to: +FEBRUARY 20 2024 18:30) +``` + +## Finding a task using a keyword +Allow users to find a task that contains a specified word + +Format: find [KEYWORD] +- The search is case-sensitive e.g book will not find Book +- The search uses partial search e.g gro will find group + + +Example: find Assignment + +Expected output: +``` +Here are the matching tasks in your list: +1. [D][] 2103T Assignment (by: FEBRUARY 20 2024 23:59) +``` + + +## Terminating the program +Aside from clicking the X button on the top right, you can also provide +a command to close the app. This command is "bye" (without the " ") + +Format: bye + + +Note that it is case-sensitive, so it must be exactly the same as bye + + + diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000000..662372d3c8 --- /dev/null +++ b/build.gradle @@ -0,0 +1,57 @@ +plugins { + id 'java' + id 'application' + id 'com.github.johnrengelman.shadow' version '7.1.2' +} + + +repositories { + mavenCentral() +} + +dependencies { + 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' + 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("lite.Lite") +} + +shadowJar { + archiveBaseName = "lite" + archiveClassifier = null + dependsOn("distZip", "distTar") +} + +run{ + standardInput = System.in +} diff --git a/docs/README.md b/docs/README.md index 8077118ebe..10432121b9 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,29 +1,181 @@ -# User Guide +# Lite User Guide -## Features +Lite is a user-friendly chatbot, especially designed towards +forgetful students to keep track of their ToDos, Events, and Deadlines. +Lite will be able to keep track the dates and status of completion of tasks, +allowing better planning for your future tasks. -### Feature-ABC +## List of Features -Description of the feature. +- [x] Adding ToDo task +- [x] Adding Event task +- [x] Adding Deadline task +- [x] Mark tasks as done +- [x] Unmark tasks as undone +- [x] Keep track and list out all of the added tasks +- [x] Delete tasks from the list +- [x] Find a task using a keyword +- [x] Close the program +- [ ] Reminder (Coming soon) -### Feature-XYZ -Description of the feature. +## Adding Todo task -## Usage +Allows users to add a ToDo task that has no date. -### `Keyword` - Describe action +Format: todo [description] -Describe the action and its outcome. +Example: `todo return a book` -Example of usage: +Expected output: -`keyword (optional arguments)` +``` +Got it. I've added this task: +[T][] return a book +Now you have tasks in the list +``` + +## Adding Deadline Task + +Allows users to add a Deadline task that has a due date. + +Format: deadline [DESCRIPTION] /by [DATE]. +- The date has to be in the format of YYYY-MM-DD, and a time from 00:00 to 23:59. + +Example: deadline 2103T Assignment /by 2024-02-20 23:59 + + +Expected output: + +``` +Got it. I've added this task: +[D][] 2103T Assignment (by: FEBRUARY 20 2024 23:59) +Now you have tasks in the list +``` + + +## Adding Event Task + +Allows users to add a Event task that has a start date and end date. + +Format:event [DESCRIPTION] /from [DATE] /to [DATE] +- The date has to be in the format of YYYY-MM-DD, and a time from 00:00 to 23:59. + +Example: event 2101 group meeting /from 2024-02-20 17:30 /to 2024-02-20 18:30 + + +Expected output: + +``` +Got it. I've added this task: +[E][] 2101 group meeting (from: FEBRUARY 20 2024 17:30 to: +FEBRUARY 20 2024 18:30) +Now you have tasks in the list +``` + +## Mark Tasks as Done + +Allow users to mark their tasks as completed + +Format: mark INDEX + +Example: mark 1 + +Assuming that the very first task you added was the ToDo task of returning a book, +this is the expected output: + +``` +This task has been marked as done! +[T][X] return a book +``` + +## Unmark Tasks + +Similarly, you can also unmark your tasks to undo it. This is mainly to undo +if you incorrectly marked your task as done. + +Format: unmark INDEX + +Example: unmark 1 -Expected outcome: +Assuming that the very first task you added was the ToDo task of returning a book, +this is the expected output: -Description of the outcome. +``` +This task has been unmarked! +[T][] return a book +``` + +## List out all the tasks added + +Allow users to see the list of tasks that they have added so far. +It also keeps track of the tasks that may have been added before + +Format: list + +Assuming that you had added a todo, deadline, and event task in that respective order, +this is the expected output: ``` -expected output +1. [T][] return a book +2. [D][] 2103T Assignment (by: FEBRUARY 20 2024 23:59) +3. [E][] 2101 group meeting (from: FEBRUARY 20 2024 17:30 to: +FEBRUARY 20 2024 18:30) +``` + + +## Delete Tasks + +Allow users to delete the tasks that are in the list + +Format: delete INDEX + +Example: delete 1 + +Assuming that the very first task you added was the ToDo task of returning a book, +this is the expected output: + +``` +Noted. I've removed this task: +[T][] return a book +Now you have tasks in the list +``` + +Also note that if you delete a task, all the index after that task will drop by 1. +So if you had added all a todo, deadline, event tasks all in order, calling list will result in this output: + ``` +Here are the tasks in your list: +1. [D][] 2103T Assignment (by: FEBRUARY 20 2024 23:59) +2. [E][] 2101 group meeting (from: FEBRUARY 20 2024 17:30 to: +FEBRUARY 20 2024 18:30) +``` + +## Finding a task using a keyword +Allow users to find a task that contains a specified word + +Format: find [KEYWORD] +- The search is case-sensitive e.g book will not find Book +- The search uses partial search e.g gro will find group + + +Example: find Assignment + +Expected output: +``` +Here are the matching tasks in your list: +1. [D][] 2103T Assignment (by: FEBRUARY 20 2024 23:59) +``` + + +## Terminating the program +Aside from clicking the X button on the top right, you can also provide +a command to close the app. This command is "bye" (without the " ") + +Format: bye + + +Note that it is case-sensitive, so it must be exactly the same as bye + + + diff --git a/docs/Ui.png b/docs/Ui.png new file mode 100644 index 0000000000..c78103093d 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/lite.txt b/lite.txt new file mode 100644 index 0000000000..3780fd48ec --- /dev/null +++ b/lite.txt @@ -0,0 +1,2 @@ +D!0!2103T Assignment!by 2024-02-20 23:59 +E!0!2101 group meeting!from 2024-02-20 17:30!to 2024-02-20 18:30 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/lite/Chatbot.java b/src/main/java/lite/Chatbot.java new file mode 100644 index 0000000000..2990d9b29c --- /dev/null +++ b/src/main/java/lite/Chatbot.java @@ -0,0 +1,40 @@ +package lite; +import java.io.IOException; +import java.util.Scanner; + +import lite.task.TaskList; +import lite.util.LiteException; +import lite.util.Printer; + + +public class Chatbot { + private TaskList tasks; + + + public Chatbot() { + this.tasks = new TaskList(); + } + + /** + * Starts the chatbot + */ + public void start() { + try { + this.tasks = new TaskList(Storage.load()); + } catch (IOException e) { + LiteException.loadFileException(); + } + } + + /** + * Gets the response from the given input + * @param input Input given by user + * @return Response from the chatBot + */ + public String getResponse(String input) { + Ui ui = new Ui(input); + return ui.executeCommand(tasks); + } + + +} diff --git a/src/main/java/lite/Storage.java b/src/main/java/lite/Storage.java new file mode 100644 index 0000000000..2e51570903 --- /dev/null +++ b/src/main/java/lite/Storage.java @@ -0,0 +1,61 @@ +package lite; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.ArrayList; + +import lite.task.Task; +import lite.task.TaskList; +import lite.util.FileParseInput; +import lite.util.LiteException; +public class Storage { + // Usage inspired from 0-yibai + private static final String PATH = "./lite.txt"; + + /** + * Saves the TaskList into a file + * @param tasks TaskList to be saved + */ + public static void save(TaskList tasks) { + try { + File file = new File(PATH); + if (!file.exists()) { + file.createNewFile(); + } + + BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file)); + for (int i = 0; i < tasks.size(); i++) { + bufferedWriter.write(tasks.get(i).saveToFile()); + } + bufferedWriter.close(); + } catch (IOException e) { + LiteException.saveException(e); + } + } + + /** + * Loads the saved tasks into the chatbot + * @return The TaskList + * @throws IOException Error message if failed to read from file + */ + public static ArrayList load() throws IOException { + ArrayList tasks = new ArrayList<>(); + File file = new File(PATH); + + if (!file.exists()) { + return tasks; + } + + BufferedReader bufferedReader = new BufferedReader(new FileReader(file)); + String s = bufferedReader.readLine(); + while(s != null) { + tasks.add(FileParseInput.parse(s)); + s = bufferedReader.readLine(); + } + return tasks; + } +} diff --git a/src/main/java/lite/Ui.java b/src/main/java/lite/Ui.java new file mode 100644 index 0000000000..d070d985b0 --- /dev/null +++ b/src/main/java/lite/Ui.java @@ -0,0 +1,161 @@ +package lite; + +import lite.task.Deadline; +import lite.task.Event; +import lite.task.Todo; +import lite.task.Task; +import lite.task.TaskList; + +import lite.util.Parser; +import lite.util.Printer; +import lite.util.LiteException; + +public class Ui { + private String input; + + public Ui (String input) { + this.input = input; + } + + /** + * Returns a command based on the input + * @param tasks List of tasks + * @return True if it is a bye (terminating condition) + */ + public String executeCommand(TaskList tasks) { + return Parser.parse(this.input, tasks, this); + } + + public String findTask(String instruction[], TaskList tasks) { + String description = instruction[1]; + TaskList availableTasks = new TaskList(); + boolean isContains = false; + for (int i = 0; i < tasks.size(); i++) { + if (tasks.contains(i, description)) { + availableTasks.add(tasks.get(i)); + isContains = true; + } + } + + if (isContains) { + return Printer.printFound(availableTasks); + } else { + return Printer.printNotFound(); + } + } + + + /** + * Deletes a task from the taskList + * @param instruction Parsed input + * @param tasks List of tasks + */ + public String deleteTask(String instruction[], TaskList tasks) { + try { + int index = Integer.parseInt(instruction[1]) - 1; + String output = Printer.printRemoveTask(tasks, index); + int size = tasks.size(); + tasks.remove(index); + assert tasks.size() == size - 1 : "size of array decreased by 1"; + return output; + } catch (NullPointerException | IndexOutOfBoundsException e){ + return LiteException.deleteException(tasks); + } + } + + /** + * Creates a new ToDo Event + * @param instruction Parsed input + * @param tasks List of tasks + */ + public String addToDoTask(String instruction[], TaskList tasks) { + try { + String description = instruction[1]; + Task todo = new Todo(description); + int size = tasks.size(); + boolean isDuplicate = tasks.add(todo); + if (isDuplicate) { + return Printer.printDuplicateFound(); + } + assert tasks.size() == size + 1 : "size of array increased by 1"; + return Printer.printTask(tasks, todo); + } catch (IndexOutOfBoundsException e) { + return LiteException.toDoException(); + } + } + + /** + * Creates a new Deadline Task + * @param instruction Parsed input + * @param tasks List of tasks + */ + public String addDeadlineTask(String instruction[], TaskList tasks) { + try { + String splits[] = instruction[1].split("/"); + String description = splits[0]; + String due = splits[1]; + Task deadline = new Deadline(description, due); + int size = tasks.size(); + boolean isDuplicate = tasks.add(deadline); + if (isDuplicate) { + return Printer.printDuplicateFound(); + } + assert tasks.size() == size + 1 : "size of array increased by 1"; + return Printer.printTask(tasks, deadline); + } catch (IndexOutOfBoundsException e) { + return LiteException.deadlineException(); + } + } + + /** + * Creates a new Event Task + * @param instruction Parsed input + * @param tasks List of tasks + */ + public String addEventTask(String[] instruction, TaskList tasks) { + try { + String splits[] = instruction[1].split("/"); + String description = splits[0]; + String start = splits[1]; + String end = splits[2]; + Task event = new Event(description, start, end); + int size = tasks.size(); + boolean isDuplicate = tasks.add(event); + if (isDuplicate) { + return Printer.printDuplicateFound(); + } + assert tasks.size() == size + 1 : "size of array increased by 1"; + return Printer.printTask(tasks, event); + } catch (IndexOutOfBoundsException e) { + return LiteException.eventException(); + } + } + + /** + * Unmarks a task to be undone + * @param instruction Parsed input + * @param tasks List of tasks + */ + public String unmarkTask(String instruction[], TaskList tasks) { + try { + int index = Integer.parseInt(instruction[1]) - 1; + return Printer.printUnmark(tasks.get(index)); + } catch (NullPointerException | ArrayIndexOutOfBoundsException e) { + return LiteException.unmarkException(tasks); + } + } + + /** + * Marks a task to be done + * @param instruction Parsed input + * @param tasks List of tasks + */ + public String markTask(String instruction[], TaskList tasks) { + try { + int index = Integer.parseInt(instruction[1]) - 1; + return Printer.printMark(tasks.get(index)); + } catch (NullPointerException | ArrayIndexOutOfBoundsException e) { + return LiteException.markException(tasks); + } + } +} diff --git a/src/main/java/lite/gui/DialogBox.java b/src/main/java/lite/gui/DialogBox.java new file mode 100644 index 0000000000..6420a955dc --- /dev/null +++ b/src/main/java/lite/gui/DialogBox.java @@ -0,0 +1,60 @@ +package lite.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; + +/** + * An example of a custom control using FXML. + * This control represents a dialog box consisting of an ImageView to represent the speaker's face and a label + * containing text from the speaker. + */ +public class DialogBox extends HBox { + @FXML + private Label dialog; + @FXML + private ImageView displayPicture; + + private DialogBox(String text, Image img) { + try { + FXMLLoader fxmlLoader = new FXMLLoader(MainWindow.class.getResource("/view/DialogBox.fxml")); + fxmlLoader.setController(this); + fxmlLoader.setRoot(this); + fxmlLoader.load(); + } catch (IOException e) { + e.printStackTrace(); + } + + dialog.setText(text); + displayPicture.setImage(img); + } + + /** + * Flips the dialog box such that the ImageView is on the left and text on the right. + */ + private void flip() { + ObservableList tmp = FXCollections.observableArrayList(this.getChildren()); + Collections.reverse(tmp); + getChildren().setAll(tmp); + setAlignment(Pos.TOP_LEFT); + } + + public static DialogBox getUserDialog(String text, Image img) { + return new DialogBox(text, img); + } + + public static DialogBox getDukeDialog(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/lite/gui/Launcher.java b/src/main/java/lite/gui/Launcher.java new file mode 100644 index 0000000000..38e5f373ae --- /dev/null +++ b/src/main/java/lite/gui/Launcher.java @@ -0,0 +1,11 @@ +package lite.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/lite/gui/Lite.java b/src/main/java/lite/gui/Lite.java new file mode 100644 index 0000000000..17a7a68668 --- /dev/null +++ b/src/main/java/lite/gui/Lite.java @@ -0,0 +1,18 @@ +package lite.gui; + + +import lite.Chatbot; + +public class Lite { + private Chatbot chatbot; + public Lite() { + this.chatbot = new Chatbot(); + chatbot.start(); + } + /** + * Outputs the LITE logo + */ + public String getResponse(String input) { + return chatbot.getResponse(input); + } +} \ No newline at end of file diff --git a/src/main/java/lite/gui/Main.java b/src/main/java/lite/gui/Main.java new file mode 100644 index 0000000000..b7e23d7e63 --- /dev/null +++ b/src/main/java/lite/gui/Main.java @@ -0,0 +1,39 @@ +package lite.gui; +import java.io.IOException; + +import javafx.application.Application; +import javafx.application.Platform; +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 Lite lite = new Lite(); + + @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().setLite(this.lite); + fxmlLoader.getController().greetings(); + stage.show(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * Terminates the program when user inputs "bye" + */ + public static void exit() { + Platform.exit(); + System.exit(0); + } +} \ No newline at end of file diff --git a/src/main/java/lite/gui/MainWindow.java b/src/main/java/lite/gui/MainWindow.java new file mode 100644 index 0000000000..03488545da --- /dev/null +++ b/src/main/java/lite/gui/MainWindow.java @@ -0,0 +1,61 @@ +package lite.gui; + +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 lite.util.Printer; + +/** + * Controller for MainWindow. Provides the layout for the other controls. + */ +public class MainWindow extends AnchorPane { + @FXML + private ScrollPane scrollPane; + @FXML + private VBox dialogContainer; + @FXML + private TextField userInput; + @FXML + private Button sendButton; + + private Lite lite; + + private Image userImage = new Image(this.getClass().getResourceAsStream("/images/DaUser.png")); + private Image dukeImage = new Image(this.getClass().getResourceAsStream("/images/DaDuke.png")); + + @FXML + public void initialize() { + scrollPane.vvalueProperty().bind(dialogContainer.heightProperty()); + } + + public void setLite(Lite d) { + this.lite = d; + } + + public void greetings() { + dialogContainer.getChildren().add(DialogBox.getDukeDialog(Printer.printGreetings(), dukeImage)); + } + + /** + * 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(); + if (input.equals("bye")) { + Main.exit(); + } + String response = this.lite.getResponse(input); + dialogContainer.getChildren().addAll( + DialogBox.getUserDialog(input, userImage), + DialogBox.getDukeDialog(response, dukeImage) + ); + userInput.clear(); + } +} \ No newline at end of file diff --git a/src/main/java/lite/task/Deadline.java b/src/main/java/lite/task/Deadline.java new file mode 100644 index 0000000000..1f95cafcb3 --- /dev/null +++ b/src/main/java/lite/task/Deadline.java @@ -0,0 +1,38 @@ +package lite.task; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +public class Deadline extends Task { + private LocalDateTime due; + private String timeDescription; + + public Deadline(String description, String due) { + super(description); + this.timeDescription = due; + String time = due.split("by ")[1]; + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); + this.due = LocalDateTime.parse(time, formatter); + } + + /** + * {@inheritDoc} + * + * Date is displayed in the format: Monday 2pm + * + */ + @Override + public String toString() { + return "[D]" + super.toString() + " (by: " + due.getMonth() + " " + + due.getDayOfMonth() + " " + due.getYear() + " " + + due.getHour() + ":" + due.getMinute() + ")"; + + } + + /** + * {@inheritDoc} + */ + @Override + public String saveToFile() { + return "D!" + super.saveToFile() + "!" + timeDescription + "\n"; + } +} diff --git a/src/main/java/lite/task/Event.java b/src/main/java/lite/task/Event.java new file mode 100644 index 0000000000..fd05e69f9b --- /dev/null +++ b/src/main/java/lite/task/Event.java @@ -0,0 +1,44 @@ +package lite.task; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +public class Event extends Task { + private String start; + private String end; + private LocalDateTime from; + private LocalDateTime to; + + + public Event(String description, String start, String end) { + super(description); + this.start = start.trim(); + this.end = end.trim(); + String startTime = start.split("from ")[1].trim(); + String endTime = end.split("to ")[1].trim(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); + this.from = LocalDateTime.parse(startTime, formatter); + this.to = LocalDateTime.parse(endTime, formatter); + } + + /** + * {@inheritDoc} + * + * Date is displayed in format: (from: Monday 2pm to: Tuesday 4pm) + */ + @Override + public String toString() { + return "[E]" + super.toString() + " (from: " + from.getMonth() + " " + + from.getDayOfMonth() + " " + from.getYear() + " " + + from.getHour() + ":" + from.getMinute() + " to: " + + to.getMonth() + " " + to.getDayOfMonth() + " " + to.getYear() + " " + + to.getHour() + ":" + to.getMinute() + ")"; + } + /** + * {@inheritDoc} + */ + @Override + public String saveToFile() { + return "E!" + super.saveToFile() + "!" + this.start + "!" + this.end + "\n"; + } +} diff --git a/src/main/java/lite/task/Task.java b/src/main/java/lite/task/Task.java new file mode 100644 index 0000000000..b7c0f84614 --- /dev/null +++ b/src/main/java/lite/task/Task.java @@ -0,0 +1,92 @@ +package lite.task; + +public class Task { + private String description; + private boolean isDone; + + public Task(String description) { + this.description = description.trim(); + this.isDone = false; + } + + /** + * Returns true if input is within description + * @param input + * @return + */ + public boolean contains (String input) { + return this.description.contains(input); + } + + /** + * Returns string representation of Task + */ + public String getStatusIcon() { + String done = (this.isDone ? "X" : ""); + return "[" + done + "] "; + } + + /** + * Outputs a marked notification and outputs the string representation + * @return Task string representation + */ + public String mark() { + setDone(); + System.out.println("Nice! I've marked this lite.task as done:"); + return this.toString(); + } + + /** + * To set the Task to done + */ + public void setDone() { + this.isDone = true; + } + + /** + * Outputs an unmarked notification and outputs the string representation + * @return Task string representation + */ + public String unmark() { + System.out.println("OK, I've marked this lite.task as not done yet:"); + setUndone(); + return this.toString(); + } + + /** + * To set the Task to undone + */ + public void setUndone() { + this.isDone = false; + } + + /** + * Returns string representation of Task + */ + @Override + public String toString() { + return getStatusIcon() + this.description; + } + + + /** + * Returns string representation when it is saved in a file + */ + public String saveToFile() { + return (this.isDone ? "1" : "0") + + "!" + this.description; + } + + /** + * Check if two tasks are equal based on their toString representation + * @param obj Task being compared to + * @return Equality of two tasks + */ + @Override + public boolean equals (Object obj) { + Task task = (Task) obj; + System.out.println(this.toString()); + System.out.println(task.toString()); + return this.toString().equals(task.toString()); + } +} diff --git a/src/main/java/lite/task/TaskList.java b/src/main/java/lite/task/TaskList.java new file mode 100644 index 0000000000..6d7af92ad5 --- /dev/null +++ b/src/main/java/lite/task/TaskList.java @@ -0,0 +1,87 @@ +package lite.task; + +import lite.Storage; +import lite.util.Printer; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Set; + +public class TaskList { + private ArrayList tasks; + + public TaskList() { + this.tasks = new ArrayList<>(); + } + + public TaskList(ArrayList tasks) { + this.tasks = tasks; + } + + /** + * Returns the size of the array list + */ + public int size() { + return tasks.size(); + } + + /** + * Returns true if input is within i-th task's input + * @param i Index we are looking for + * @param input Given input + */ + public boolean contains(int i, String input) { + return tasks.get(i).contains(input); + } + + /** + * Returns the task at index i + * @param i The index to get from + */ + public Task get(int i) { + return tasks.get(i); + } + + /** + * Adds a task to the array list + * @param task Task to be added + */ + public boolean add (Task task) { + if (tasks.contains(task)) { + return true; + } + this.tasks.add(task); + return false; + } + + /** + * Removes a task from the array list + * @param i Index of the task to be removed + */ + public Task remove(int i) { + return this.tasks.remove(i); + } + + /** + * Outputs the string representation of the TaskList when prompted with "list" + */ + public String outputTasks() { + String output = "Here are the tasks in your taskList:\n"; + for (int i = 0; i < this.tasks.size(); i++) { + output += (i + 1) + ". " + this.tasks.get(i) + "\n"; + } + return output; + } + + /** + * Outputs the string representation of the TaskList + */ + public String taskString() { + String output = ""; + for (int i = 0; i < this.tasks.size(); i++) { + output += (i+1) + ". " + this.tasks.get(i) + "\n"; + } + return output; + } + +} diff --git a/src/main/java/lite/task/Todo.java b/src/main/java/lite/task/Todo.java new file mode 100644 index 0000000000..5052bd7014 --- /dev/null +++ b/src/main/java/lite/task/Todo.java @@ -0,0 +1,24 @@ +package lite.task; + +public class Todo extends Task { + + public Todo(String description) { + super(description); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return "[T]" + super.toString(); + } + + /** + * {@inheritDoc} + */ + @Override + public String saveToFile() { + return "T!" + super.saveToFile() + "\n"; + } +} diff --git a/src/main/java/lite/util/FileParseInput.java b/src/main/java/lite/util/FileParseInput.java new file mode 100644 index 0000000000..9662a9cfd8 --- /dev/null +++ b/src/main/java/lite/util/FileParseInput.java @@ -0,0 +1,62 @@ +package lite.util; + +import lite.task.Deadline; +import lite.task.Event; +import lite.task.Task; +import lite.task.Todo; + +public class FileParseInput { + //Usage inspired by 0-yibai + + /** + * Returns a Task based on the input given + * @param input Input string given + * @return Task corresponding to the input + */ + public static Task parse(String input) { + String[] instruction = input.split("!"); + if (instruction[0].equals("T")) { + return parseTodo(instruction); + } else if (instruction[0].equals("E")) { + return parseEvent(instruction); + } else { + return parseDeadline(instruction); + } + } + + /** + * Returns a Todo Task + * @param instruction The Todo description and status + */ + public static Todo parseTodo(String[] instruction) { + Todo todo = new Todo(instruction[2]); + if (instruction[1].equals("1")) { + todo.setDone(); + } + return todo; + } + + /** + * Returns an Event Task + * @param instruction The Event description, start, end, and status + */ + public static Event parseEvent(String[] instruction) { + Event event = new Event(instruction[2], instruction[3],instruction[4]); + if (instruction[1].equals("1")) { + event.setDone(); + } + return event; + } + + /** + * Returns a deadline task + * @param instruction The Deadline description and due date + */ + public static Deadline parseDeadline(String[] instruction) { + Deadline deadline = new Deadline(instruction[2], instruction[3]); + if (instruction[1].equals("1")) { + deadline.setDone(); + } + return deadline; + } +} diff --git a/src/main/java/lite/util/LiteException.java b/src/main/java/lite/util/LiteException.java new file mode 100644 index 0000000000..1f113cd810 --- /dev/null +++ b/src/main/java/lite/util/LiteException.java @@ -0,0 +1,89 @@ +package lite.util; + +import lite.task.TaskList; + +import java.io.IOException; + +public class LiteException extends Exception{ + public LiteException(String error) { + super(error); + } + /** + * Outputs an error message when an invalid input is given + */ + public static String invalidInput() { + return "Invalid input .\n" + + "Please begin your input with either one of these keywords: \n" + + "todo, list, deadline, event, mark, unmark, delete, find, bye"; + + } + + /** + * Outputs an error message when a file fails to load + */ + public static String loadFileException() { + return "Unable to load data from local file\n" + "File may be corrupted"; + } + + /** + * Outputs an error messagae when a file fails to save + * @param e Error message corresponding to the error + */ + public static String saveException(IOException e) { + return "Failed to save to a local file \n" + e; + } + + /** + * Prints an error message when delete does not meet the input format + * @param tasks List of tasks + */ + public static String deleteException(TaskList tasks) { + return "Please input a valid index. \n" + + "The correct format is delete . \n" + + "The minimum index is 1 and the maximum index is " + tasks.size(); + } + + /** + * Prints an error message when ToDo task does not meet input format + */ + public static String toDoException() { + return "Please give a name for the todo lite.task. \n +" + + "The correct format is todo "; + } + + /** + * Prints an error message when Event task does not meet input format + */ + public static String eventException() { + return "Invalid input. \n" + + "Please follow the format: event /from /to "; + } + + /** + * Prints an error message when Deadline task does not meet input format + */ + public static String deadlineException() { + return "Invalid input. \n" + + "Please follow the format of: deadline /by "; + } + + /** + * Prints an error message when unmark does not meet the input format + * @param tasks List of tasks + */ + public static String unmarkException(TaskList tasks) { + return "Please input a valid index. \n" + + "The correct format is unmark . \n" + + "The minimum index is 1 and the maximum index is " + tasks.size(); + } + + /** + * Prints an error message when mark does not meet the input format + * @param tasks List of tasks + */ + public static String markException(TaskList tasks) { + return "Please input a valid index. \n" + + "The correct format is mark . \n" + + "The minimum index is 1 and the maximum index is " + tasks.size(); + } +} diff --git a/src/main/java/lite/util/Parser.java b/src/main/java/lite/util/Parser.java new file mode 100644 index 0000000000..a483403bea --- /dev/null +++ b/src/main/java/lite/util/Parser.java @@ -0,0 +1,43 @@ +package lite.util; + +import lite.Storage; +import lite.Ui; +import lite.task.TaskList; +import lite.util.LiteException; + +public class Parser { + + /** + * Executes a command based on the input given + * @param input Input given by user + * @param tasks List of tasks + * @param ui List of instructions available + * @return A corresponding task based on the input + */ + public static String parse(String input, TaskList tasks, Ui ui) { + if (input.equals("list")) { + return tasks.outputTasks(); + } + String output; + String instruction[] = input.split(" ", 2); // It only splits the first " " + if (instruction[0].equals("mark")) { + output = ui.markTask(instruction, tasks); + } else if (instruction[0].equals("unmark")){ + output = ui.unmarkTask(instruction, tasks); + } else if (instruction[0].equals("delete")) { + output = ui.deleteTask(instruction, tasks); + } else if (instruction[0].equals("todo")) { + output = ui.addToDoTask(instruction, tasks); + } else if (instruction[0].equals("deadline")) { + output = ui.addDeadlineTask(instruction, tasks); + } else if (instruction[0].equals("event")) { + output = ui.addEventTask(instruction, tasks); + } else if (instruction[0].equals("find")) { + output = ui.findTask(instruction, tasks); + } else { + return LiteException.invalidInput(); + } + Storage.save(tasks); + return output; + } +} diff --git a/src/main/java/lite/util/Printer.java b/src/main/java/lite/util/Printer.java new file mode 100644 index 0000000000..14200319d0 --- /dev/null +++ b/src/main/java/lite/util/Printer.java @@ -0,0 +1,76 @@ +package lite.util; + +import lite.task.Task; +import lite.task.TaskList; + +public class Printer { + + /** + * Prints a message notifying that a task has been removed + * @param tasks List of tasks + * @param index Index of task to remove from + */ + public static String printRemoveTask(TaskList tasks, int index) { + return "Noted. I've removed this task:\n" + + tasks.get(index) + "\n" + + "Now you have " + (tasks.size() - 1) + " tasks in the list."; + } + + + /** + * Prints a message notifying that a task has been added + * @param tasks List of tasks + * @param task Task to be added + */ + public static String printTask(TaskList tasks, Task task) { + return "Got it. I've added this task: \n" + + task + "\n" + "Now you have " + tasks.size() + " tasks in the list"; + } + + /** + * Prints out a message notifying that a task has been unmarked + * @param task Task being unmarked + */ + public static String printUnmark(Task task) { + String output = "This task has been unmarked!\n" + task.unmark(); + return output; + } + + + /** + * Prints out a message notifying that a task has been marked + * @param task Task being marked + */ + public static String printMark(Task task) { + String output = "This task has been marked as done!\n" + task.mark(); + return output; + } + + /** + * Prints out all the tasks that contains the input + * @param tasks List of tasks + */ + public static String printFound(TaskList tasks) { + String output = "Here are the matching tasks in your list:\n"; + output += tasks.taskString(); + return output; + } + + /** + * Prints out a message if no tasks contains the input + */ + public static String printNotFound() { + return "There are no tasks that correspond with your input"; + } + + /** + * Prints out a message if the task is already in the list + */ + public static String printDuplicateFound() { + return "This task is already in your Task List."; + } + + public static String printGreetings() { + return "Hi this is Lite! How can I help you?"; + } +} diff --git a/src/main/resources/images/DaDuke.png b/src/main/resources/images/DaDuke.png new file mode 100644 index 0000000000..d893658717 Binary files /dev/null and b/src/main/resources/images/DaDuke.png differ diff --git a/src/main/resources/images/DaUser.png b/src/main/resources/images/DaUser.png new file mode 100644 index 0000000000..3c82f45461 Binary files /dev/null and b/src/main/resources/images/DaUser.png differ diff --git a/src/main/resources/view/DialogBox.fxml b/src/main/resources/view/DialogBox.fxml new file mode 100644 index 0000000000..430e2ffb16 --- /dev/null +++ b/src/main/resources/view/DialogBox.fxml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + diff --git a/src/main/resources/view/MainWindow.fxml b/src/main/resources/view/MainWindow.fxml new file mode 100644 index 0000000000..220104372a --- /dev/null +++ b/src/main/resources/view/MainWindow.fxml @@ -0,0 +1,19 @@ + + + + + + + + + + + +