diff --git a/README.md b/README.md index 8715d4d915..0f2208ab64 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Duke project template +# duke.Duke project template This is a project template for a greenfield Java project. It's named after the Java mascot _Duke_. Given below are instructions on how to use it. @@ -13,7 +13,7 @@ Prerequisites: JDK 11, update Intellij to the most recent version. 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: +3. After that, locate the `src/main/java/duke.Duke.java` file, right-click it, and choose `Run duke.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 ____ _ diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000000..655feb8a0a --- /dev/null +++ b/build.gradle @@ -0,0 +1,70 @@ +plugins { + id 'checkstyle' + id 'java' + id 'application' + id 'com.github.johnrengelman.shadow' version '5.1.0' +} + +checkstyle { + toolVersion = '10.2' +} + +jar { + manifest { + attributes( + 'Main-Class': 'com.mypackage.MyClass' + ) + } +} + +repositories { + mavenCentral() +} + +dependencies { + testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.5.0' + testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.5.0' + + String javaFxVersion = '19' + + implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'linux' + implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'linux' + implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'linux' + implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'linux' + +} + +test { + useJUnitPlatform() + + testLogging { + events "passed", "skipped", "failed" + + showExceptions true + exceptionFormat "full" + showCauses true + showStackTraces true + showStandardStreams = false + } +} + +application { + mainClassName = "duke.Launcher" +} + +shadowJar { + archiveBaseName = "duke" + archiveClassifier = null +} + +run{ + standardInput = System.in +} diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml new file mode 100644 index 0000000000..e8ee76467b --- /dev/null +++ b/config/checkstyle/checkstyle.xml @@ -0,0 +1,429 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/config/checkstyle/suppressions.xml b/config/checkstyle/suppressions.xml new file mode 100644 index 0000000000..135ea49ee0 --- /dev/null +++ b/config/checkstyle/suppressions.xml @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/data/dukeTask.txt b/data/dukeTask.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/README.md b/docs/README.md index 8077118ebe..9d051b52ef 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,29 +1,209 @@ # User Guide +BearyBear serves as your personal task tracker that manages different +tasks for you! You do not have to keep track of the tasks manually anymore, BearyBear does it all for you! + +You can add or delete different tasks (todo, deadline, events), mark the tasks as done/undone. +With BearyBear, you can also view the entire list of task and find tasks with certain keywords! + ## Features -### Feature-ABC +### Record tasks + +Able to record three types of tasks (todo, deadline, event) and find and list the tasks -Description of the feature. +### Update tasks -### Feature-XYZ +Able to update completion status of tasks and able to delete tasks from the task list -Description of the feature. +### Save tasks + +Tasks will be saved in hard disk at [directory where JAR file is]/data/dukeTask.txt even after the application is closed. +Tasks previously saved can be retrieved the next time you start this application. ## Usage -### `Keyword` - Describe action +**Please take note of the following:** +- Enter date in this format: **YYYY-MM-DD** (eg. 2023-02-10) +- All the command words are to be typed in **lower case** + (eg. only `list` is recognized, `LIST` is not recognized) + +----------------------------------------------------------- + +### `todo` - Add a task to be done -Describe the action and its outcome. +The task will be added to the list of tasks and saved locally + +Format: `todo (task description)` Example of usage: -`keyword (optional arguments)` +`todo read book` + +Expected outcome: + +The 'read book' todo task will be added to the list of tasks. +'T' in the first square bracket means it is a todo task. +Second square bracket is empty because this task is not completed yet. + +``` +Wow! I've added this task: + [T][ ] read book +Now you have 1 tasks in the list. +``` + +-------------------------------------------- + +### `deadline` - Add a task with deadline + +Add a task with a specified deadline to the task list. + +Format: `deadline (task description) /by (deadline date) ` + +Example of usage: + +`deadline return book /by 2023-10-10` + +Expected outcome: + +The 'return book' deadline task will be added to the task list and deadline will be shown beside the task description. +'D' in the first square bracket means it is a deadline task. +Second square bracket is empty because this task is not completed yet. + +``` +Wow! I've added this task: + [D][ ] return book ( by: Oct 10 2023 ) +Now you have 2 tasks in the list. +``` + +---------------------------------------- + + +### `event` - Add an event task with time period + +Add an event task with the starting date and ending date into the task list. + +Format: `event (task description) /from (start date) /to (end date)` + + +Example of usage: + +`event write book /from 2023-10-10 /to 2024-11-11` Expected outcome: -Description of the outcome. +The 'write book' event task will be added to the task list and starting date & ending date will be shown beside the task description. +'E' in the first square bracket means it is an event task. +Second square bracket is empty because this task is not completed yet. ``` -expected output +Wow! I've added this task: + [E][ ] write book (Oct 10 2023 to Nov 11 2024) +Now you have 3 tasks in the list. +``` + +--------------------------------------------- + + +### `mark` - Mark a task as completed + +Reference to a task using task number and mark this task as completed. + +Format: + +`mark (task number)` + +Example of usage: + +`mark 1` + +Expected outcome: + +The first task will be marked as completed and the second square bracket will contain a 'X'. + ``` +YAYYYY Good Job!!! +I've marked this task as done: + [T][X] read book +``` + +------------------------------------------------- + +### `unmark` - Mark a task as not completed + +Reference to a task using task number and mark this task as not completed. + +Format: + +`unmark (task number)` + +Example of usage: + +`unmark 1` + +Expected outcome: +The first task will be marked as not completed and the second square bracket will be empty. + + +``` +Okay... I've marked this task as not done yet: + [T][ ] read book +``` + +---------------------------------------------- + +### `list` - Print the current list of tasks + +Allow users to see the whole list of tasks that has been recorded so far. + +Example of usage: + +`list` + +Expected outcome: + +All the tasks and their details (type of task, completion status, deadlines and dates) in the list will be printed out. + +``` +Here are some tasks in your list: +1.[T][ ] read book +2.[D][ ] return book ( by: Oct 10 2023 ) +3.[E][ ] write book (Oct 10 2023 to Nov 11 2024) +``` + +---------------------------------------------- + +### `find` - Find tasks containing the target word + +Search and list out the matching list of tasks which has the target word that user is trying to find. + +Format: + +`find (target word)` + +Example of usage: + +`find return` + +Expected outcome: + +Search through the list of tasks to find which has 'return' in the task details. +Then print all the tasks which has 'return' in the task details. + +``` +Here are the matching tasks in your list: +1.[D][ ] return book ( by: Oct 10 2023 ) +``` + +--------------------------------------------- +### `bye` - Exit the application + +Exit and closes the application. + +Example of usage: + +`bye` + +Expected outcome: + +The application will be closed and a goodbye message will be printed in console. diff --git a/docs/Ui.png b/docs/Ui.png new file mode 100644 index 0000000000..c5f92fcbbd 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..f3d88b1c2f Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..b7c8c5dbf5 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000000..2fe81a7d95 --- /dev/null +++ b/gradlew @@ -0,0 +1,183 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000000..62bd9b9cce --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,103 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java deleted file mode 100644 index 5d313334cc..0000000000 --- a/src/main/java/Duke.java +++ /dev/null @@ -1,10 +0,0 @@ -public class Duke { - public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - } -} diff --git a/src/main/java/duke/DialogBox.java b/src/main/java/duke/DialogBox.java new file mode 100644 index 0000000000..1286339296 --- /dev/null +++ b/src/main/java/duke/DialogBox.java @@ -0,0 +1,61 @@ +package duke; + +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; + } +} diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java new file mode 100644 index 0000000000..9564cbf57e --- /dev/null +++ b/src/main/java/duke/Duke.java @@ -0,0 +1,54 @@ +package duke; + +import duke.exception.DukeException; +import duke.parser.Parser; +import duke.storage.Storage; +import duke.task.TaskList; +import duke.ui.Ui; + + + +/** + * Duke helps user to keep track of tasks + */ +public class Duke { + private Storage storage; + private TaskList tasks; + private Ui ui; + private Parser parser; + + /** + * Constructor for Duke + */ + public Duke() { + ui = new Ui(); + storage = new Storage("./data/dukeTask.txt"); + try { + tasks = new TaskList(storage.load()); + } catch (DukeException e) { + ui.showLoadError(); + tasks = new TaskList(); + } + parser = new Parser(tasks); + } + + /** + * Greet user and perform command for the tasks they entered and save tasks in file + */ + public String greet() { + return ui.greet(); + } + + /** + * You should have your own function to generate a response to user input. + * Replace this stub with your completed method. + */ + public String getResponse(String input) { + String response = ""; + response = parser.performCommand(input, ui);; + storage.save(this.tasks); + return response; + } + + +} diff --git a/src/main/java/duke/Launcher.java b/src/main/java/duke/Launcher.java new file mode 100644 index 0000000000..df2fc91df8 --- /dev/null +++ b/src/main/java/duke/Launcher.java @@ -0,0 +1,12 @@ +package duke; + +import javafx.application.Application; + +/** + * A class to launch application + */ +public class Launcher { + public static void main(String[] args) { + Application.launch(Main.class, args); + } +} diff --git a/src/main/java/duke/Main.java b/src/main/java/duke/Main.java new file mode 100644 index 0000000000..dcd0ed4d2a --- /dev/null +++ b/src/main/java/duke/Main.java @@ -0,0 +1,34 @@ +package duke; + +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 Duke duke = new Duke(); + + @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); + stage.setTitle("BearyBear"); + fxmlLoader.getController().setDuke(duke); + stage.show(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} + + diff --git a/src/main/java/duke/MainWindow.java b/src/main/java/duke/MainWindow.java new file mode 100644 index 0000000000..cdaf7594a3 --- /dev/null +++ b/src/main/java/duke/MainWindow.java @@ -0,0 +1,60 @@ +package duke; + +import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.scene.control.ScrollPane; +import javafx.scene.control.TextField; +import javafx.scene.image.Image; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.VBox; + + +/** + * Controller for 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 Duke duke; + + private Image userImage = new Image(this.getClass().getResourceAsStream("/Images/user1.png")); + private Image dukeImage = new Image(this.getClass().getResourceAsStream("/Images/Duke1.png")); + + @FXML + public void initialize() { + scrollPane.vvalueProperty().bind(dialogContainer.heightProperty()); + } + + public void setDuke(Duke d) { + duke = d; + dialogContainer.getChildren().addAll( + DialogBox.getDukeDialog(duke.greet(), 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(); + String response = duke.getResponse(input); + dialogContainer.getChildren().addAll( + DialogBox.getUserDialog(input, userImage), + DialogBox.getDukeDialog(response, dukeImage) + ); + if (response.equals("Bye!! Do visit me again! I'll always be free for you :)")) { + System.out.println(response); + System.exit(0); + } + userInput.clear(); + } +} diff --git a/src/main/java/duke/exception/DukeException.java b/src/main/java/duke/exception/DukeException.java new file mode 100644 index 0000000000..d608c351d1 --- /dev/null +++ b/src/main/java/duke/exception/DukeException.java @@ -0,0 +1,11 @@ +package duke.exception; + +/** + * Exception thrown when there is no description after the command + */ +public class DukeException extends Exception { + public DukeException(String errorMessage) { + super(errorMessage); + } + +} diff --git a/src/main/java/duke/exception/EmptyDescriptionException.java b/src/main/java/duke/exception/EmptyDescriptionException.java new file mode 100644 index 0000000000..c05fa41045 --- /dev/null +++ b/src/main/java/duke/exception/EmptyDescriptionException.java @@ -0,0 +1,16 @@ +package duke.exception; + +/** + * Exception thrown when there is no description after the command + */ +public class EmptyDescriptionException extends Exception { + + /** + * Constructor for EmptyDescriptionException + */ + public EmptyDescriptionException() { + super("OOPS!!! The description of a task cannot be empty while adding a task! " + + "\n If you want to mark/ unmark/ delete task, please enter task number after command!"); + } + +} diff --git a/src/main/java/duke/exception/WrongCommandException.java b/src/main/java/duke/exception/WrongCommandException.java new file mode 100644 index 0000000000..89f8b30c56 --- /dev/null +++ b/src/main/java/duke/exception/WrongCommandException.java @@ -0,0 +1,11 @@ +package duke.exception; + +/** + * Exception thrown when command is not recognized + */ +public class WrongCommandException extends Exception { + public WrongCommandException() { + super("OOPS!!! I'm sorry, but I don't know what that means :-("); + } + +} diff --git a/src/main/java/duke/exception/WrongFormatException.java b/src/main/java/duke/exception/WrongFormatException.java new file mode 100644 index 0000000000..e70121c9a7 --- /dev/null +++ b/src/main/java/duke/exception/WrongFormatException.java @@ -0,0 +1,15 @@ +package duke.exception; + +/** + * WrongFormatException is thrown when user does not enter inputs in the correct format with the commands + */ +public class WrongFormatException extends Exception { + + /** + * Constructor for WrongFormatException + * @param message Shows the correct format of inputs + */ + public WrongFormatException(String message) { + super("HEY!! Pleaseeee enter in a correct format: " + "'" + message + "'"); + } +} diff --git a/src/main/java/duke/parser/HandleBye.java b/src/main/java/duke/parser/HandleBye.java new file mode 100644 index 0000000000..b374b489fb --- /dev/null +++ b/src/main/java/duke/parser/HandleBye.java @@ -0,0 +1,29 @@ +package duke.parser; + +import duke.exception.WrongFormatException; +import duke.ui.Ui; + +/** + * Processes and handles bye command from user + */ +public class HandleBye { + public HandleBye() { + } + + /** + * Check the format of input and perform Bye command + * @param input Entered by user + * @param ui Ui that would generate reply for the user + * @return A String to respond to user through ui + * @throws WrongFormatException This exception is thrown when input contains more words than "bye" + */ + public static String performBye(String input, Ui ui) throws WrongFormatException { + boolean correctFormat = input.trim().equals("bye"); + + if (!correctFormat) { + throw new WrongFormatException("bye"); + } + + return ui.sayBye(); + } +} diff --git a/src/main/java/duke/parser/HandleDeadline.java b/src/main/java/duke/parser/HandleDeadline.java new file mode 100644 index 0000000000..7f263769c9 --- /dev/null +++ b/src/main/java/duke/parser/HandleDeadline.java @@ -0,0 +1,53 @@ +package duke.parser; +import java.time.LocalDate; +import java.time.format.DateTimeParseException; + +import duke.exception.DukeException; +import duke.exception.WrongFormatException; +import duke.task.Deadline; +import duke.task.Task; +import duke.task.TaskList; +import duke.ui.Ui; + +/** + * Processes and handle the deadline command + */ +public class HandleDeadline { + public HandleDeadline() { + } + + /** + * Check whether the input line to add a deadline task is valid and in the correct format or not + * Perform the adding of deadline task into task list if input is in correct format + * @param input Entered by user + * @param tasklist List of existing tasks + * @param ui Ui that would generate reply for the user + * @return A String to respond to user through ui, inform user whether task has been added or not + * @throws WrongFormatException This exception is thrown when input is not in correct format + */ + public static String performDeadline( + String input, TaskList tasklist, Ui ui) throws WrongFormatException, DukeException { + + try { + String taskString = input.substring(9, input.indexOf(" /by ")).trim(); + if (taskString.isBlank()) { + throw new DukeException("Oi! You didn't enter task description!"); + } + String deadline = input.substring(input.indexOf(" /by ") + 5); + assert input.contains("/by") : "Wrong format for deadline task!"; + if (LocalDate.parse(deadline).isBefore(java.time.LocalDate.now())) { + throw new DukeException("Noooo! You're entering a date before today!"); + } + Task taskDeadline = new Deadline(taskString, deadline); + if (tasklist.checkDuplicates(taskDeadline)) { + return ui.showError("OOPS! You have added this task before already!"); + } + tasklist.addTask(taskDeadline); + return ui.showAddTask(taskDeadline.toString(), tasklist.getSize()); + } catch (DateTimeParseException e) { + throw new DukeException("Please enter date in the correct format! YYYY-MM-DD, example: 2023-10-10"); + } catch (IndexOutOfBoundsException e) { + throw new WrongFormatException("deadline /by "); + } + } +} diff --git a/src/main/java/duke/parser/HandleDelete.java b/src/main/java/duke/parser/HandleDelete.java new file mode 100644 index 0000000000..3bbf69a7a9 --- /dev/null +++ b/src/main/java/duke/parser/HandleDelete.java @@ -0,0 +1,35 @@ +package duke.parser; + +import duke.exception.DukeException; +import duke.task.Task; +import duke.task.TaskList; +import duke.ui.Ui; + +/** + * Processes and handles the delete command + */ +public class HandleDelete { + public HandleDelete() { + } + + /** + * Perform the deletion of a task from task list if input is in correct format and task number is valid + * @param input Entered by user + * @param tasklist List of existing tasks + * @param ui Ui that would generate reply for the user + * @return A String to respond to user through ui, inform user if the task has been deleted or not + */ + public static String performDelete(String input, TaskList tasklist, Ui ui) throws DukeException { + + try { + int taskNum = Integer.parseInt(input.substring(7)) - 1; + Task taskToRemove = tasklist.getTask(taskNum); + String removedTaskStr = taskToRemove.toString(); + tasklist.deleteTask(taskNum); + return ui.showDeleteTask(removedTaskStr, tasklist.getSize()); + } catch (NumberFormatException | IndexOutOfBoundsException e) { + throw new DukeException("Please enter a valid task number!"); + } + } + +} diff --git a/src/main/java/duke/parser/HandleEvent.java b/src/main/java/duke/parser/HandleEvent.java new file mode 100644 index 0000000000..d02d663d99 --- /dev/null +++ b/src/main/java/duke/parser/HandleEvent.java @@ -0,0 +1,59 @@ +package duke.parser; +import java.time.LocalDate; +import java.time.format.DateTimeParseException; + +import duke.exception.DukeException; +import duke.exception.WrongFormatException; +import duke.task.Event; +import duke.task.Task; +import duke.task.TaskList; +import duke.ui.Ui; + +/** + * Processes and handle the event command + */ +public class HandleEvent { + public HandleEvent() { + } + + /** + * Check whether the input line to add a deadline task is valid and in the correct format or not + * Perform the addition of a task from task list if input is in correct format + * @param input Entered by user + * @param tasklist List of existing tasks + * @param ui Ui that would generate reply for the user + * @return A String to respond to user through ui, inform user whether task has been added or not + * @throws WrongFormatException This exception is thrown when input is not in correct format + */ + public static String performEvent( + String input, TaskList tasklist, Ui ui) throws WrongFormatException, DukeException { + + try { + String taskString = input.substring(6, input.indexOf(" /from")).trim(); + if (taskString.isBlank()) { + throw new DukeException("Oi! You didn't enter task description!"); + } + String startDate = input.substring(input.indexOf(" /from ") + 7, input.lastIndexOf(" /to ")); + LocalDate taskStartDate = LocalDate.parse(startDate); + String endDate = input.substring(input.indexOf(" /to ") + 5); + LocalDate taskEndDate = LocalDate.parse(endDate); + if (taskEndDate.isBefore(taskStartDate)) { + throw new DukeException("Noooo! Your end date is before start date!"); + } + if (taskStartDate.isBefore(java.time.LocalDate.now())) { + throw new DukeException("Noooo! You're entering dates before today!"); + } + assert input.contains("/from") && input.contains("/to") : "Wrong format for event task!"; + Task taskEvent = new Event(taskString, startDate, endDate); + if (tasklist.checkDuplicates(taskEvent)) { + throw new DukeException("OOPS! You have added this task before already!"); + } + tasklist.addTask(taskEvent); + return ui.showAddTask(taskEvent.toString(), tasklist.getSize()); + } catch (DateTimeParseException e) { + throw new DukeException("Please enter date in the correct format! YYYY-MM-DD, example: 2023-10-10"); + } catch (IndexOutOfBoundsException e) { + throw new WrongFormatException("event /from /to "); + } + } +} diff --git a/src/main/java/duke/parser/HandleFind.java b/src/main/java/duke/parser/HandleFind.java new file mode 100644 index 0000000000..9359854284 --- /dev/null +++ b/src/main/java/duke/parser/HandleFind.java @@ -0,0 +1,49 @@ +package duke.parser; +import java.util.ArrayList; +import java.util.List; + +import duke.exception.WrongFormatException; +import duke.task.Task; +import duke.task.TaskList; +import duke.ui.Ui; + +/** + * Processes and handle the find command + */ +public class HandleFind { + public HandleFind() { + } + + /** + * Check whether the input line to find matching tasks that contain target word is in the correct format or not + * Perform the searching of target word in task list if input is in correct format + * @param input Entered by user + * @param tasklist List of existing tasks + * @param ui Ui that would generate reply for the user + * @return A String to respond to user through ui, printing the matching tasks that contain the target word + * @throws WrongFormatException This exception is thrown when input is not in correct format + */ + public static String performFind(String input, TaskList tasklist, Ui ui) throws WrongFormatException { + boolean correctFormat = input.split(" ").length > 1; + if (!correctFormat) { + throw new WrongFormatException("find "); + } + + String targetString = input.substring(5); + List targetList = new ArrayList<>(); + for (Task t : tasklist.getTaskList()) { + if (t.getTask().contains(targetString)) { + targetList.add(t); + } + } + if (targetList.isEmpty()) { + return ui.showFindResult(false, ""); + } else { + String listFound = "Here are the matching tasks in your list:"; + for (int i = 1; i < targetList.size() + 1; i++) { + listFound = listFound + "\n" + i + "." + (targetList.get(i - 1)).toString(); + } + return ui.showFindResult(true, listFound); + } + } +} diff --git a/src/main/java/duke/parser/HandleList.java b/src/main/java/duke/parser/HandleList.java new file mode 100644 index 0000000000..4adf645946 --- /dev/null +++ b/src/main/java/duke/parser/HandleList.java @@ -0,0 +1,35 @@ +package duke.parser; + +import duke.exception.WrongFormatException; +import duke.task.TaskList; +import duke.ui.Ui; + +/** + * Processes and handle the list command + */ +public class HandleList { + public HandleList() { + } + + /** + * Check whether the input line is in correct format + * Calls function in TaskList class to generate the whole list of tasks + * @param input Entered by user + * @param tasklist List of existing tasks + * @param ui Ui that would generate reply for the user + * @return A String to respond to user through ui, printing the whole list of task + * @throws WrongFormatException This exception is thrown when input contains more words than "list" + */ + public static String performList(String input, TaskList tasklist, Ui ui) throws WrongFormatException { + boolean correctFormat = input.equals("list"); + + if (!correctFormat) { + throw new WrongFormatException("list"); + } + + return ui.showList(tasklist.printList()); + + } + + +} diff --git a/src/main/java/duke/parser/HandleMark.java b/src/main/java/duke/parser/HandleMark.java new file mode 100644 index 0000000000..fff16460ee --- /dev/null +++ b/src/main/java/duke/parser/HandleMark.java @@ -0,0 +1,32 @@ +package duke.parser; + +import duke.exception.DukeException; +import duke.task.TaskList; +import duke.ui.Ui; + +/** + * Processes and handle the mark command + */ +public class HandleMark { + public HandleMark() { + } + + /** + * Perform the marking of task in task list if input is in correct format and task number is valid + * @param input Entered by user + * @param tasklist List of existing tasks + * @param ui Ui that would generate reply for the user + * @return A String to respond to user through ui, inform user about status of task + */ + public static String performMark(String input, TaskList tasklist, Ui ui) throws DukeException { + + try { + int taskNum = Integer.parseInt(input.substring(5)) - 1; + tasklist.markTask(taskNum); + assert input.trim().split(" ").length > 1 : "There is no task to mark!"; + return ui.showMarkTask(tasklist.getTask(taskNum).toString()); + } catch (NumberFormatException | IndexOutOfBoundsException e) { + throw new DukeException("Please enter a valid task number!"); + } + } +} diff --git a/src/main/java/duke/parser/HandleToDo.java b/src/main/java/duke/parser/HandleToDo.java new file mode 100644 index 0000000000..7586ef5e15 --- /dev/null +++ b/src/main/java/duke/parser/HandleToDo.java @@ -0,0 +1,42 @@ +package duke.parser; + +import duke.exception.DukeException; +import duke.exception.WrongFormatException; +import duke.task.Task; +import duke.task.TaskList; +import duke.task.ToDo; +import duke.ui.Ui; + +/** + * Processes and handle the todo command + */ +public class HandleToDo { + public HandleToDo() { + } + + /** + * Check whether the input line to add a todo task is valid and in the correct format or not + * Perform the adding of todo task into task list if input is in correct format + * @param input Entered by user + * @param tasklist List of existing tasks + * @param ui Ui that would generate reply for the user + * @return A String to respond to user through ui, inform user whether task has been added or not + * @throws WrongFormatException This exception is thrown when input is not in correct format + */ + public static String performToDo(String input, TaskList tasklist, Ui ui) throws DukeException { + String taskString; + try { + taskString = input.trim().substring(5); + } catch (StringIndexOutOfBoundsException e) { + throw new DukeException("Oi! You didn't enter task description!"); + } + + Task taskToDo = new ToDo(taskString); + if (tasklist.checkDuplicates(taskToDo)) { + throw new DukeException("OOPS! You have added this task before already!"); + } + + tasklist.addTask(taskToDo); + return ui.showAddTask(taskToDo.toString(), tasklist.getSize()); + } +} diff --git a/src/main/java/duke/parser/HandleUnmark.java b/src/main/java/duke/parser/HandleUnmark.java new file mode 100644 index 0000000000..51ab30368b --- /dev/null +++ b/src/main/java/duke/parser/HandleUnmark.java @@ -0,0 +1,32 @@ +package duke.parser; + +import duke.exception.DukeException; +import duke.task.TaskList; +import duke.ui.Ui; + +/** + * Processes and handle the unmark command + */ +public class HandleUnmark { + public HandleUnmark() { + } + + /** + * Perform the unmarking of task in task list if input is in correct format and task number is valid + * @param input Entered by user + * @param tasklist List of existing tasks + * @param ui Ui that would generate reply for the user, inform user about status of task + * @return A String to respond to user through ui, informing user about status of task + */ + public static String performUnmark(String input, TaskList tasklist, Ui ui) throws DukeException { + + try { + int taskNum = Integer.parseInt(input.substring(7)) - 1; + tasklist.unmarkTask(taskNum); + assert input.trim().split(" ").length > 1 : "There is no task to unmark!"; + return ui.showUnmarkTask(tasklist.getTask(taskNum).toString()); + } catch (NumberFormatException | IndexOutOfBoundsException e) { + throw new DukeException("Please enter a valid task number!"); + } + } +} diff --git a/src/main/java/duke/parser/Parser.java b/src/main/java/duke/parser/Parser.java new file mode 100644 index 0000000000..3e00fdfcd8 --- /dev/null +++ b/src/main/java/duke/parser/Parser.java @@ -0,0 +1,97 @@ +package duke.parser; +import java.util.ArrayList; + +import duke.exception.DukeException; +import duke.exception.EmptyDescriptionException; +import duke.exception.WrongCommandException; +import duke.exception.WrongFormatException; +import duke.task.TaskList; +import duke.ui.Ui; + + +/** + * A parser to understand and perform user command + */ +public class Parser { + private TaskList taskList; + private ArrayList listOfCommands; + + /** + * Constructor for Parser + * @param taskList + */ + public Parser(TaskList taskList) { + this.taskList = taskList; + this.listOfCommands = new ArrayList<>() { + { + add("mark"); + add("unmark"); + add("todo"); + add("deadline"); + add("event"); + add("delete"); + add("find"); + } + }; + } + + /** + * Perform the user command and create the tasks + * @throws EmptyDescriptionException If no description of task after the command word + * @throws WrongCommandException If wrong command word is being entered + */ + public String performCommand(String input, Ui ui) { + String trimmedInput = input.trim(); + String[] arrOfString = trimmedInput.split(" ", 2); + String command = arrOfString[0]; + try { + this.checkCommand(input, command); + switch (command) { + case "bye": + return HandleBye.performBye(trimmedInput, ui); + case "list": + return HandleList.performList(trimmedInput, taskList, ui); + case "mark": + return HandleMark.performMark(trimmedInput, taskList, ui); + case "unmark": + return HandleUnmark.performUnmark(trimmedInput, taskList, ui); + case "todo": + return HandleToDo.performToDo(trimmedInput, taskList, ui); + case "deadline": + return HandleDeadline.performDeadline(trimmedInput, taskList, ui); + case "event": + return HandleEvent.performEvent(trimmedInput, taskList, ui); + case "delete": + return HandleDelete.performDelete(trimmedInput, taskList, ui); + case "find": + return HandleFind.performFind(trimmedInput, taskList, ui); + default: + assert false : "Unable to process command"; + return ui.showError("Please enter a valid command and/or task!"); + } + } catch (EmptyDescriptionException | WrongCommandException + | WrongFormatException | DukeException e) { + return ui.showError(e.getMessage()); + } + } + + /** + * Check whether the command and input is valid or invalid + * @param input Input entered by user + * @param command + * @throws EmptyDescriptionException Exception thrown when there is no description/ task number after the command + * @throws WrongCommandException Exception thrown when the command does not exist + */ + public void checkCommand(String input, String command) throws EmptyDescriptionException, WrongCommandException { + if (listOfCommands.contains(input)) { + throw new EmptyDescriptionException(); + } else if (!listOfCommands.contains(command) && !command.equals("list") && !command.equals("bye")) { + throw new WrongCommandException(); + } + } + +} + + + + diff --git a/src/main/java/duke/storage/Storage.java b/src/main/java/duke/storage/Storage.java new file mode 100644 index 0000000000..92eb193170 --- /dev/null +++ b/src/main/java/duke/storage/Storage.java @@ -0,0 +1,123 @@ +package duke.storage; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import duke.exception.DukeException; +import duke.task.Deadline; +import duke.task.Event; +import duke.task.Task; +import duke.task.TaskList; +import duke.task.ToDo; + +/** + * Storage class that manage loading of tasks from file and saving of tasks in file + */ +public class Storage { + private File taskFile; + + /** + * Constructor of Storage to create file + */ + public Storage(String filepath) { + try { + taskFile = new File(filepath); + if (!taskFile.exists()) { + checkDirectoryExist("./data/"); + checkFileExist(); + } + } catch (IOException e) { + System.out.println(e.getMessage()); + } + } + + /** + * Check if the directory of the file path exists or not, make directory if it does not exist + * @param directoryPath + */ + public void checkDirectoryExist(String directoryPath) { + File directory = new File(directoryPath); + if (!directory.exists()) { + directory.mkdirs(); + } + } + + /** + * Check if file exist, create a new text file to be stored in directory path if file does not exist + * @throws IOException + */ + public void checkFileExist() throws IOException { + if (!taskFile.exists()) { + taskFile.createNewFile(); + } + } + + /** + * Load tasks from file + * @return List of tasks + * @throws DukeException If unable to read file + */ + public List load() throws DukeException { + List taskList = new ArrayList<>(); + try { + BufferedReader myReader = new BufferedReader(new FileReader(this.taskFile)); + String line = myReader.readLine(); + while (line != null) { + // task is saved in the following format: + // taskType /// completionStatus /// taskDescription /// startDate for event or deadline /// endDate + // null will be saved if the task do not have the component + String[] str = line.split(" /// ", 5); + Task task = null; + + switch (str[0]) { + case "T": + task = new ToDo(str[2]); + break; + case "D": + task = new Deadline(str[2], str[3]); + break; + case "E": + task = new Event(str[2], str[3], str[4]); + break; + default: + break; + } + if (str[1].equals("[X]")) { + task.markTask(); + } + taskList.add(task); + line = myReader.readLine(); + } + myReader.close(); + } catch (IOException | IndexOutOfBoundsException e) { + throw new DukeException("Unable to load file"); + } + return taskList; + } + + /** + * Save the list of tasks in the file + * @param taskList List of tasks to be saved + * @throws IOException When tasks cannot be saved + */ + public void save(TaskList taskList) { + try { + BufferedWriter myWriter = new BufferedWriter(new FileWriter(this.taskFile)); + for (int i = 0; i < taskList.getSize(); i++) { + Task t = taskList.getTaskList().get(i); + myWriter.write(t.toBeSaved() + "\n"); + } + myWriter.close(); + } catch (IOException e) { + System.out.println("There is an error in saving tasks!"); + } + } + + +} diff --git a/src/main/java/duke/task/Deadline.java b/src/main/java/duke/task/Deadline.java new file mode 100644 index 0000000000..2e20251590 --- /dev/null +++ b/src/main/java/duke/task/Deadline.java @@ -0,0 +1,58 @@ +package duke.task; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +/** + * Class for task with deadline + */ +public class Deadline extends Task { + + private String taskDescription; + private LocalDate deadLine; + private String deadlineString; + + /** + * Constructor of Deadline task + * @param taskString user taskString input + * @param deadline deadline for the task + */ + + public Deadline(String taskString, String deadline) { + super(taskString); + + taskDescription = taskString; + deadLine = LocalDate.parse(deadline); + deadlineString = deadline; + } + + @Override + public String getTask() { + return this.taskDescription; + } + + @Override + public String fullDetails() { + return this.taskDescription + " " + this.getDeadline(); + } + + + /** + * Format the deadline date in the MMM d yyyy style + * @return String of a formatted deadline + */ + public String getDeadline() { + return this.deadLine.format(DateTimeFormatter.ofPattern("MMM d yyyy")); + } + + + @Override + public String toString() { + return "[D]" + super.toString() + " ( by: " + this.getDeadline() + " )"; + } + + @Override + public String toBeSaved() { + return "D" + " /// " + super.toBeSaved() + " /// " + this.deadlineString + " /// " + "null"; + } +} diff --git a/src/main/java/duke/task/Event.java b/src/main/java/duke/task/Event.java new file mode 100644 index 0000000000..404622b62d --- /dev/null +++ b/src/main/java/duke/task/Event.java @@ -0,0 +1,67 @@ +package duke.task; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +/** + * Class for tasks with specific timeline, from a date to another date + */ +public class Event extends Task { + private String taskDescription; + private LocalDate startDate; + private LocalDate endDate; + private String startDateString; + private String endDateString; + + /** + * Constructor for Event task + * @param taskString user taskString input + * @param startDateInput start date of event + * @param endDateInput end date of event + */ + public Event(String taskString, String startDateInput, String endDateInput) { + super(taskString); + + taskDescription = taskString; + startDateString = startDateInput; + startDate = LocalDate.parse(startDateInput); + endDateString = endDateInput; + endDate = LocalDate.parse(endDateInput); + } + + @Override + public String getTask() { + return this.taskDescription; + } + + @Override + public String fullDetails() { + return this.taskDescription + " " + this.getTimeline(); + } + + /** + * Get the timeline of event in a specific format ( start date to end date ) + * @return String of a formatted timeline + */ + public String getTimeline() { + return this.getStartDate() + " to " + this.getEndDate(); + } + + public String getStartDate() { + return this.startDate.format(DateTimeFormatter.ofPattern("MMM d yyyy")); + } + + public String getEndDate() { + return this.endDate.format(DateTimeFormatter.ofPattern("MMM d yyyy")); + } + + + @Override + public String toString() { + return "[E]" + super.toString() + " (" + this.getTimeline() + ")"; + } + + @Override + public String toBeSaved() { + return "E" + " /// " + super.toBeSaved() + " /// " + this.startDateString + " /// " + this.endDateString; + } +} diff --git a/src/main/java/duke/task/Task.java b/src/main/java/duke/task/Task.java new file mode 100644 index 0000000000..3203ca32a4 --- /dev/null +++ b/src/main/java/duke/task/Task.java @@ -0,0 +1,75 @@ +package duke.task; + +/** + * Parent Task class which contains details of a task + */ +public abstract class Task { + private String taskString; + private boolean isCompleted; + + /** + * Constructor of Task + * @param taskString user taskString input + */ + public Task(String taskString) { + this.taskString = taskString; + this.isCompleted = false; + } + + public abstract String getTask(); + + public abstract String fullDetails(); + + /** + * Check current status of task, whether it is marked completed or not + * @return X means completed and space means not completed + */ + public String currentTaskStatus() { + if (this.isCompleted) { + return "[X]"; + } else { + return "[ ]"; + } + } + + /** + * Mark a task is completed + */ + public void markTask() { + this.isCompleted = true; + } + + /** + * Mark a task as not completed + */ + public void unmarkTask() { + this.isCompleted = false; + } + + + /** + * Get description of task + * @return String of task description + */ + + public String toString() { + return this.currentTaskStatus() + " " + this.taskString; + } + + /** + * Check if the two task has exact same detail + * Details such as task description, deadline, event start date and event end date + * @param t Task to check with + * @return True if the two tasks has exact same details, which means this task is duplicated + */ + public boolean equals(Task t) { + if (this == t) { + return true; + } + return this.fullDetails().equals(t.fullDetails()); + }; + + public String toBeSaved() { + return this.currentTaskStatus() + " /// " + this.taskString; + } +} diff --git a/src/main/java/duke/task/TaskList.java b/src/main/java/duke/task/TaskList.java new file mode 100644 index 0000000000..16ef53112e --- /dev/null +++ b/src/main/java/duke/task/TaskList.java @@ -0,0 +1,105 @@ +package duke.task; +import java.util.ArrayList; +import java.util.List; + +import duke.exception.DukeException; + + +/** + * TaskList to contain all the tasks in a list + */ +public class TaskList { + private List taskList; + + /** + * Constructor for TaskList + */ + public TaskList() { + this.taskList = new ArrayList<>(); + } + + public TaskList(List taskListInput) throws DukeException { + this.taskList = taskListInput; + } + + + public List getTaskList() { + return this.taskList; + } + + public Task getTask(int index) { + return taskList.get(index); + } + + public int getSize() { + return taskList.size(); + } + + + /** + * Prints all the tasks in the taks list + */ + public String printList() { + if (taskList.size() == 0) { + return "There is no task in your task list!"; + } + String list = "Here are some tasks in your list:"; + for (int i = 1; i < this.taskList.size() + 1; i++) { + list = list + "\n" + i + "." + (taskList.get(i - 1)).toString(); + } + return list; + } + + /** + * Mark the task stored in the list as completed + * @param taskNum Task number of task in the list to mark as completed + */ + public void markTask(int taskNum) throws IndexOutOfBoundsException { + Task originalTask = taskList.get(taskNum); + originalTask.markTask(); + } + + /** + * Mark the task stored in the list as not completed + * @param taskNum Task number of task in the list to mark as completed + */ + public void unmarkTask(int taskNum) throws IndexOutOfBoundsException { + Task originalTask = taskList.get(taskNum); + originalTask.unmarkTask(); + } + + /** + * Add the task into the list of task + * @param task Task to be added + */ + public void addTask(Task task) { + taskList.add(task); + } + + + /** + * Delete the task from the list + * @param taskNum Task number of task in the list to be deleted + */ + public void deleteTask(int taskNum) throws IndexOutOfBoundsException { + taskList.remove(taskNum); + } + + /** + * Check if the task has exact same details with any of the existing tasks + * @param task task to be checked + * @return True if there is an existing task that has the same details as the task being checked + */ + public boolean checkDuplicates(Task task) { + for (int i = 0; i < this.taskList.size(); i++) { + if ((taskList.get(i)).equals(task)) { + return true; + } + } + return false; + } + + + + +} diff --git a/src/main/java/duke/task/ToDo.java b/src/main/java/duke/task/ToDo.java new file mode 100644 index 0000000000..68d0d9b586 --- /dev/null +++ b/src/main/java/duke/task/ToDo.java @@ -0,0 +1,41 @@ +package duke.task; + +/** + * Class for task to be done + */ +public class ToDo extends Task { + + private String taskDescription; + + /** + * Constructor for To-Do Task + * @param taskString user taskString input + */ + public ToDo(String taskString) { + super(taskString); + + taskDescription = taskString; + } + + @Override + public String getTask() { + return this.taskDescription; + } + + @Override + public String fullDetails() { + return this.taskDescription; + } + + + @Override + public String toString() { + return "[T]" + super.toString(); + } + + @Override + public String toBeSaved() { + return "T" + " /// " + super.toBeSaved() + " /// " + "null" + " /// " + "null"; + } + +} diff --git a/src/main/java/duke/ui/Ui.java b/src/main/java/duke/ui/Ui.java new file mode 100644 index 0000000000..692e4797c7 --- /dev/null +++ b/src/main/java/duke/ui/Ui.java @@ -0,0 +1,107 @@ +package duke.ui; + +/** + * Ui class to handle interactions with user + */ +public class Ui { + + public Ui() { + } + + /** + * Greet user when application is first launched + * @return String to greet user + */ + public String greet() { + return "Hello! I'm Beary Bear!! \nNice to meet you! \nWhat can I do for you?"; + } + + /** + * Say goodbye to the user before the application closes + * @return String to say goodbye to user + */ + public String sayBye() { + return "Bye!! Do visit me again! I'll always be free for you :)"; + } + + /** + * Shows error message when exception is being caught or unable to perform command + * @param errorMessage String to inform user what should be done to correct this error + * @return String to inform user about the error + */ + public String showError(String errorMessage) { + return errorMessage; + } + + /** + * Informs user that the task has been added + * @param task Task that has been added + * @param totalTaskNumber Number of task in the task list currently + * @return String to inform user that task has been added + */ + public String showAddTask(String task, int totalTaskNumber) { + return "Wow! I've added this task: \n " + task + + "\nNow you have " + totalTaskNumber + " tasks in the list."; + } + + /** + * Informs user that the task has been deleted + * @param task Task that has been deleted + * @param totalTaskNumber Number of task in the task list currently + * @return String to inform user that task has been deleted + */ + public String showDeleteTask(String task, int totalTaskNumber) { + return "Okay!! I've removed this task: \n " + task + + "\nNow you have " + totalTaskNumber + " tasks in the list."; + } + + /** + * Inform user about the result of finding the target word in the list of tasks + * @param isFound True if some matching tasks are found + * @param result String of matching tasks if isFound is true + * @return String to inform user the list of matching task found if isFound is true + * and inform user that list is not found if isFound is false + */ + public String showFindResult(Boolean isFound, String result) { + if (!isFound) { + return "Oops! :( There are no matching tasks found. Try again?"; + } + return result; + } + + /** + * Inform the user that a task has been marked + * @param task task that has been marked + * @return String to inform user that a task has been marked + */ + public String showMarkTask(String task) { + return "YAYYYY Good Job!!! \n I've marked this task as done: \n " + task; + } + + /** + * Inform the user that a task has been unmarked + * @param task task that has been unmarked + * @return String to inform user that a task has been unmarked + */ + public String showUnmarkTask(String task) { + return "Ok... I've marked this task as not done yet: \n " + task; + } + + /** + * Inform user about the list of tasks currently present in the task list + * @param list + * @return String of current tasks + */ + public String showList(String list) { + return list; + } + + /** + * Inform user that the file cannot be loaded and task list cannot be obtained from the file + */ + public void showLoadError() { + System.out.println("Oops! Unable to load file!"); + } + + +} diff --git a/src/main/resources/Images/Duke1.png b/src/main/resources/Images/Duke1.png new file mode 100644 index 0000000000..4ce595fb22 Binary files /dev/null and b/src/main/resources/Images/Duke1.png differ diff --git a/src/main/resources/Images/background-image.png b/src/main/resources/Images/background-image.png new file mode 100644 index 0000000000..675246236c Binary files /dev/null and b/src/main/resources/Images/background-image.png differ diff --git a/src/main/resources/Images/user1.png b/src/main/resources/Images/user1.png new file mode 100644 index 0000000000..98b7c2c314 Binary files /dev/null and b/src/main/resources/Images/user1.png differ diff --git a/src/main/resources/META-INF/MANIFEST.MF b/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..120c87e906 --- /dev/null +++ b/src/main/resources/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: duke.Launcher + diff --git a/src/main/resources/view/DialogBox.fxml b/src/main/resources/view/DialogBox.fxml new file mode 100644 index 0000000000..ada6907f31 --- /dev/null +++ b/src/main/resources/view/DialogBox.fxml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/view/MainWindow.fxml b/src/main/resources/view/MainWindow.fxml new file mode 100644 index 0000000000..bf6cf1cad0 --- /dev/null +++ b/src/main/resources/view/MainWindow.fxml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + +