diff --git a/.gitignore b/.gitignore index 2873e189e1..228682ae2b 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ bin/ /text-ui-test/ACTUAL.TXT text-ui-test/EXPECTED-UNIX.TXT +duke.txt diff --git a/README.md b/README.md index 8715d4d915..a78847e3ba 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,29 @@ -# Duke project template +## Duke -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. +> “Your mind is for having ideas, not holding them.” – David Allen ([source](https://dansilvestre.com/productivity-quotes)) -## Setting up in Intellij +Duke is a simple reminder app that helps you to remember things you need to do. It's, +- text-based +- easy to learn +- ~FAST~ *SUPER FAST* to use -Prerequisites: JDK 11, update Intellij to the most recent version. +All you need to do is, +1. download it from [here](https://github.com/Gibson0918/ip/releases). +2. double-click it. +3. add your tasks. +4. let it manage your tasks for you 😁 -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 - ____ _ - | _ \ _ _| | _____ - | | | | | | | |/ / _ \ - | |_| | |_| | < __/ - |____/ \__,_|_|\_\___| - ``` +And it is **FREE**! + +Features: +- [x] Adding ToDo task +- [x] Adding task with deadline +- [x] Adding Event with deadline + +if you are a Java programmer, you can use it to practice Java too. Here's the main method: +```public class Launcher { + public static void main(String[] args) { + Application.launch(Main.class, args); + } +} +``` diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000000..b863613fee --- /dev/null +++ b/build.gradle @@ -0,0 +1,62 @@ +plugins { + id 'java' + id 'application' + id 'com.github.johnrengelman.shadow' version '5.1.0' + id 'checkstyle' +} + +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 = '11' + + implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'linux' + implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'linux' + implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'linux' + implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'linux' +} + +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 + enableAssertions = true +} + +checkstyle { + toolVersion = '10.2' +} \ No newline at end of file diff --git a/config/checkstyle.xml b/config/checkstyle.xml new file mode 100644 index 0000000000..e8ee76467b --- /dev/null +++ b/config/checkstyle.xml @@ -0,0 +1,429 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/config/suppressions.xml b/config/suppressions.xml new file mode 100644 index 0000000000..135ea49ee0 --- /dev/null +++ b/config/suppressions.xml @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index 8077118ebe..063c5836f6 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,29 +1,91 @@ # User Guide +Duke is a desktop app that reminds you of all the tasks that you have to carry out!! + ## Features +1. Adding tasks + - Todo + - Deadline + - Event +2. Viewing tasks +3. Editing task +4. Locating task +5. Deleting task +6. Marking task +7. Unmarking task +8. Exiting the program + +### Adding a task +Adds a task to Duke + +Format: ```{task} {description} {startDate} {endDate}``` + +- task: either todo deadline/event +- description: description of the task +- startDate: start date of the task +- endDate: end date of the task + +*{startDate} and {endDate} is optional for ToDo task.* + +*{startDate} is required and {endDate} is optional for Deadline task.* + +*{startDate} and {endDate} is required for Event task.* + +### Viewing task +View all task stored in Duke + +Format: ```list``` + +### Editing task +Updating an existing task in Duke + +Format: ```update {index} {description} {startDate} {endDate}``` + +- index: index of the task +- description: description of the task +- startDate: start date of the task +- endDate: end date of the task + +*{startDate} and {endDate} is optional for ToDo task.* + +*{startDate} is required and {endDate} is optional for Deadline task.* + +*{startDate} and {endDate} is required for Event task.* + +### Locating task +Finds any task that has a description that matches given keyword + +Format: ```find {keyword}``` + +- keyword: keyword to be located in task's description + + +### Delete task +Delete task from Duke + +Format: ```delete {index} ``` + +- index: index of the task -### Feature-ABC +### Mark task +Mark an existing task in Duke as completed -Description of the feature. +Format: ```mark {index}``` -### Feature-XYZ +- index: index of the task -Description of the feature. +### Unmark task +Unmark an existing task in Duke as incomplete -## Usage +Format: ```Unmark {index}``` -### `Keyword` - Describe action +- index: index of the task -Describe the action and its outcome. +### Killing the program +Terminating Duke -Example of usage: +Format: ```Bye``` -`keyword (optional arguments)` -Expected outcome: -Description of the outcome. -``` -expected output -``` diff --git a/docs/Ui.png b/docs/Ui.png new file mode 100644 index 0000000000..4f67eb1fdd Binary files /dev/null and b/docs/Ui.png differ diff --git a/duke.txt b/duke.txt new file mode 100644 index 0000000000..a548c4dc4a --- /dev/null +++ b/duke.txt @@ -0,0 +1,4 @@ +T | 0 | borrow book +D | 0 | return book | 2020-05-12 1800 +E | 0 | project meeting | 2020-12-20 2000 | 2020-12-25 2200 +T | 1 | go library 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/META-INF/MANIFEST.MF b/src/main/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..120c87e906 --- /dev/null +++ b/src/main/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: duke.Launcher + 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/Deadline.java b/src/main/java/duke/Deadline.java new file mode 100644 index 0000000000..906089d168 --- /dev/null +++ b/src/main/java/duke/Deadline.java @@ -0,0 +1,35 @@ +package duke; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +public class Deadline extends Task { + + protected LocalDateTime by; + + public Deadline(String description, String by) { + super(description); + this.by = LocalDateTime.parse(by, DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm")); + } + + @Override + public String toString() { + String formattedByDate = this.by.format(DateTimeFormatter.ofPattern("MMM dd yyyy HH:mm")); + return "[D]" + super.toString() + " (by: " + formattedByDate + ")"; + } + + @Override + public String formatForFile() { + String formattedByDate = this.by.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm")); + if (this.isDone) { + return "D | " + 1 + " | " + description + " | " + formattedByDate + "\n"; + } else { + return "D | " + 0 + " | " + description + " | " + formattedByDate + "\n"; + } + } + + @Override + public Type getType() { + return Type.DEADLINE; + } +} diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java new file mode 100644 index 0000000000..fb3d0d55ce --- /dev/null +++ b/src/main/java/duke/Duke.java @@ -0,0 +1,45 @@ +package duke; + +import java.io.FileNotFoundException; + +import duke.command.Command; +import duke.exception.DukeException; +import duke.parser.Parser; +import duke.storage.Storage; +import duke.ui.Ui; + +/** + * Duke's main class + */ +public class Duke { + + private static TaskList tasks; + private Ui ui; + private final String filePath = "duke.txt"; + private Storage storage; + + /** + * Constructor for Duke + */ + public Duke() { + ui = new Ui(); + storage = new Storage(filePath); + try { + tasks = new TaskList(storage.loadFile()); + } catch (FileNotFoundException e) { + tasks = new TaskList(); + } + ui.displayTaskList(tasks); + } + + public String getResponse(String command) { + try { + Command c = Parser.parse(command); + return c.initCommand(tasks, ui, storage); + } catch (DukeException e) { + return e.getMessage(); + } catch (IllegalArgumentException e) { + return e.getMessage(); + } + } +} diff --git a/src/main/java/duke/Event.java b/src/main/java/duke/Event.java new file mode 100644 index 0000000000..971d905e07 --- /dev/null +++ b/src/main/java/duke/Event.java @@ -0,0 +1,47 @@ +package duke; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +/** + * Event class to handle all event task + */ +public class Event extends Task { + protected LocalDateTime startDate; + protected LocalDateTime endDate; + + /** + * Constructor for Event + * @param description + * @param startDate + * @param endDate + */ + public Event(String description, String startDate, String endDate) { + super(description); + this.startDate = LocalDateTime.parse(startDate, DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm")); + this.endDate = LocalDateTime.parse(endDate, DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm")); + } + + @Override + public String toString() { + String formattedStartDate = startDate.format(DateTimeFormatter.ofPattern("MMM dd yyyy HH:mm")); + String formattedEndDate = endDate.format(DateTimeFormatter.ofPattern("MMM dd yyyy HH:mm")); + return "[E]" + super.toString() + " (from: " + formattedStartDate + " to: " + formattedEndDate + ")"; + } + + @Override + public String formatForFile() { + String formattedStartDate = startDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm")); + String formattedEndDate = endDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm")); + if (this.isDone) { + return "E | " + 1 + " | " + description + " | " + formattedStartDate + " | " + formattedEndDate + "\n"; + } else { + return "E | " + 0 + " | " + description + " | " + formattedStartDate + " | " + formattedEndDate + "\n"; + } + } + + @Override + public Type getType() { + return Type.EVENT; + } +} diff --git a/src/main/java/duke/Launcher.java b/src/main/java/duke/Launcher.java new file mode 100644 index 0000000000..e4ef6b4628 --- /dev/null +++ b/src/main/java/duke/Launcher.java @@ -0,0 +1,12 @@ +package duke; + +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/duke/Main.java b/src/main/java/duke/Main.java new file mode 100644 index 0000000000..584be25967 --- /dev/null +++ b/src/main/java/duke/Main.java @@ -0,0 +1,35 @@ +package duke; + +import java.io.IOException; + +import duke.gui.MainWindow; +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 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); + fxmlLoader.getController().setDuke(duke); + stage.show(); + stage.setOnCloseRequest(e-> Platform.exit()); + + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/duke/Task.java b/src/main/java/duke/Task.java new file mode 100644 index 0000000000..41ddb47e71 --- /dev/null +++ b/src/main/java/duke/Task.java @@ -0,0 +1,58 @@ +package duke; + +/** + * Represents the abstract Task class which serves as a base template to handle all possible Tasks + */ +public abstract class Task { + + protected String description; + protected boolean isDone; + + /** + * Constructor method for Task + * @param description description of the task + */ + public Task(String description) { + this.description = description; + this.isDone = false; + } + + /** + * get the status of the task + * @return an X if the task is completed + */ + public String getStatusIcon() { + return (isDone ? "X" : " "); + } + + /** + * Sets the status of the task to completed + */ + public void marked() { + this.isDone = true; + } + + /** + * Sets the status of the task to incomplete + */ + public void unmarked() { + this.isDone = false; + } + + /** + * Prints out the description of the task + * @return formatted description of the task + */ + @Override + public String toString() { + return "[" + this.getStatusIcon() + "] " + this.description; + } + + /** + * Abstract method to be implemented by child classes for formatting output when saving data to file + * @return formatted string + */ + public abstract String formatForFile(); + + public abstract Type getType(); +} diff --git a/src/main/java/duke/TaskList.java b/src/main/java/duke/TaskList.java new file mode 100644 index 0000000000..8c11f80478 --- /dev/null +++ b/src/main/java/duke/TaskList.java @@ -0,0 +1,117 @@ +package duke; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +/** + * TaskList class to handle all operations relating to tasks. + */ +public class TaskList extends ArrayList { + private List taskList; + + /** + * Constructor for TaskList + */ + public TaskList() { + taskList = new ArrayList(); + } + + /** + * Constructor for TaskList. + * @param taskList a list of tasks + */ + public TaskList(List taskList) { + this.taskList = taskList; + } + + /** + * Retrieves the task within the list. + * @param taskID index of the task to be retrieved. + * @return task retrieved + */ + public Task getTask(int taskID) { + assert taskID < taskList.size() : "taskID given should be less than taskList size"; + return taskList.get(--taskID); + } + + /** + * Add the task to the list. + * @param task task to be added. + */ + public void addTask(Task task) { + assert task != null : "Task cannot be null"; + this.taskList.add(task); + } + + /** + * Delete the task from the list. + * @param taskID index of task to be deleted. + * @return task removed from the list. + */ + public Task deleteTask(int taskID) { + assert taskID < taskList.size() : "taskID to be deleted must be within tasklist"; + Task task = taskList.remove(--taskID); + return task; + } + + /** + * Gets the size of the list + * @return size of list + */ + @Override + public int size() { + return taskList.size(); + } + + /** + * Determine if list is empty + * @return true if empty, false otherwise + */ + @Override + public boolean isEmpty() { + return taskList.isEmpty(); + } + + /** + * Find any task with the given keyword + * @param keyword + * @return a list of task + */ + public List find(String keyword) { + assert keyword != null : "Keyword should not be empty"; + return this.taskList.stream().filter(x -> x.description.contains(keyword)).collect(Collectors.toList()); + } + + /** + * replace the tasks with another at the given index + * @param index index of the element to replace + * @param task element to be stored at the specified position + * @return the new task replaced + */ + public Task set(int index, Task task) { + assert index < taskList.size() : "index provided should be less than taskList size"; + taskList.set(index, task); + return task; + } + + /** + * Prints out all tasks in the list + * @return String representation of all tasks in the list + */ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + if (!taskList.isEmpty()) { + sb.append("Here are the tasks in your list: \n"); + int count = 1; + for (Task t : taskList) { + sb.append(count++); + sb.append("." + t.toString() + "\n"); + } + } else { + sb.append("You have no tasks"); + } + return sb.toString(); + } +} diff --git a/src/main/java/duke/Todo.java b/src/main/java/duke/Todo.java new file mode 100644 index 0000000000..b96b67056a --- /dev/null +++ b/src/main/java/duke/Todo.java @@ -0,0 +1,41 @@ +package duke; + +/** + * Todo class to handle Todo task + */ +public class Todo extends Task { + /** + * Constructor method for Todo + * @param description task's description + */ + public Todo(String description) { + super(description); + } + + /** + * Overridden method for print Todo task + * @return String output of the task + */ + @Override + public String toString() { + return "[T]" + super.toString(); + } + + /** + * Formats the task's details for saving to file + * @return formatted task's details + */ + @Override + public String formatForFile() { + if (this.isDone) { + return "T | " + 1 + " | " + this.description + "\n"; + } else { + return "T | " + 0 + " | " + this.description + "\n"; + } + } + + @Override + public Type getType() { + return Type.TODO; + } +} diff --git a/src/main/java/duke/Type.java b/src/main/java/duke/Type.java new file mode 100644 index 0000000000..57bc0546d9 --- /dev/null +++ b/src/main/java/duke/Type.java @@ -0,0 +1,8 @@ +package duke; + +/** + * Enumeration for all possible task + */ +public enum Type { + DEADLINE, EVENT, TODO +} diff --git a/src/main/java/duke/command/AddCommand.java b/src/main/java/duke/command/AddCommand.java new file mode 100644 index 0000000000..e43475fbcf --- /dev/null +++ b/src/main/java/duke/command/AddCommand.java @@ -0,0 +1,35 @@ +package duke.command; + +import duke.Task; +import duke.TaskList; +import duke.storage.Storage; +import duke.ui.Ui; + +/** + * Handles the appropriate tasks when performing an AddCommand by Duke. + */ +public class AddCommand extends Command { + private Task task; + + /** + * Constructor for AddCommand. + * @param task Task provided by the user. + */ + public AddCommand(Task task) { + this.task = task; + } + + /** + * Overridden method to handle the specific tasks to be carried out when adding tasks. + * @param tasks a list of tasks. + * @param ui Ui class to handle display messages. + * @param storage Storage to handle saving/loading of data to/from the list of task. + * @return Duke's response message + */ + @Override + public String initCommand(TaskList tasks, Ui ui, Storage storage) { + tasks.addTask(this.task); + storage.saveData(tasks); + return ui.displayAddTaskMessage(task, tasks); + } +} diff --git a/src/main/java/duke/command/Command.java b/src/main/java/duke/command/Command.java new file mode 100644 index 0000000000..4ebba80b83 --- /dev/null +++ b/src/main/java/duke/command/Command.java @@ -0,0 +1,21 @@ +package duke.command; + +import duke.TaskList; +import duke.exception.DukeException; +import duke.storage.Storage; +import duke.ui.Ui; + +/** + * Represents the abstract Command class which serves as a base template to handle all possible commands by Duke. + */ +public abstract class Command { + + /** + * Abstract init method for command class. + * @param tasks a list of tasks. + * @param ui Ui class to handle display messages. + * @param storage Storage to handle saving/loading of data to/from the list of task. + * @return duke's response message. + */ + public abstract String initCommand(TaskList tasks, Ui ui, Storage storage) throws DukeException; +} diff --git a/src/main/java/duke/command/DeleteCommand.java b/src/main/java/duke/command/DeleteCommand.java new file mode 100644 index 0000000000..f1d60a462e --- /dev/null +++ b/src/main/java/duke/command/DeleteCommand.java @@ -0,0 +1,41 @@ +package duke.command; + +import duke.Task; +import duke.TaskList; +import duke.storage.Storage; +import duke.ui.Ui; + +/** + * Handles the appropriate tasks when performing a DeleteCommand by Duke. + */ +public class DeleteCommand extends Command { + private int taskID; + + /** + * Constructor for DeleteCommand. + * @param taskID integer identifier to identify the index of the task to be deleted from the list of tasks. + */ + public DeleteCommand(int taskID) { + this.taskID = taskID; + } + + /** + * Overridden method to handle the specific tasks to be carried out when performing deletion + * @param tasks a list of tasks. + * @param ui Ui class to handle display messages. + * @param storage Storage to handle saving/loading of data to/from the list of task. + * @return Duke's response message + */ + @Override + public String initCommand(TaskList tasks, Ui ui, Storage storage) { + if (tasks.size() >= taskID && !tasks.isEmpty()) { + Task currentTask = tasks.getTask(taskID); + tasks.deleteTask(taskID); + storage.saveData(tasks); + return ui.displayDeleteTaskMessage(currentTask, tasks); + + } else { + return ui.displayMsg("Invalid taskID entered!"); + } + } +} diff --git a/src/main/java/duke/command/ExitCommand.java b/src/main/java/duke/command/ExitCommand.java new file mode 100644 index 0000000000..3996509d9f --- /dev/null +++ b/src/main/java/duke/command/ExitCommand.java @@ -0,0 +1,26 @@ +package duke.command; + +import duke.TaskList; +import duke.storage.Storage; +import duke.ui.Ui; +import javafx.application.Platform; + +/** + * Handles the appropriate tasks when performing an ExitCommand by Duke. + */ +public class ExitCommand extends Command { + + /** + * Overridden method to handle the specific tasks to be carried out when performing deletion + * @param tasks a list of tasks. + * @param ui Ui class to handle display messages. + * @param storage Storage to handle saving/loading of data to/from the list of task. + * @return Duke's response message + */ + @Override + public String initCommand(TaskList tasks, Ui ui, Storage storage) { + storage.saveData(tasks); + Platform.exit(); + return ui.displayGoodbyeMessage(); + } +} diff --git a/src/main/java/duke/command/FindCommand.java b/src/main/java/duke/command/FindCommand.java new file mode 100644 index 0000000000..97537ecc07 --- /dev/null +++ b/src/main/java/duke/command/FindCommand.java @@ -0,0 +1,46 @@ +package duke.command; + +import java.util.List; + +import duke.Task; +import duke.TaskList; +import duke.storage.Storage; +import duke.ui.Ui; + +/** + * Handles the appropriate tasks when performing a FindCommand by Duke. + */ +public class FindCommand extends Command { + + private String keyword; + + /** + * Constructor for FindCommand + * @param keyword keyword to be filtered by + */ + public FindCommand(String keyword) { + this.keyword = keyword; + } + /** + * Overridden method to handle the specific tasks to be carried out when performing deletion. + * @param tasks a list of tasks. + * @param ui Ui class to handle display messages. + * @param storage Storage to handle saving/loading of data to/from the list of task. + * @return Duke's response message. + */ + @Override + public String initCommand(TaskList tasks, Ui ui, Storage storage) { + List matchingTasks = tasks.find(keyword); + if (matchingTasks.isEmpty()) { + return "No matching tasks, please try again!"; + } else { + StringBuilder sb = new StringBuilder(); + sb.append("Here are the matching tasks in your list:\n"); + int count = 1; + for (Task t : matchingTasks) { + sb.append(count++ + "." + t.toString() + "\n"); + } + return sb.toString(); + } + } +} diff --git a/src/main/java/duke/command/ListCommand.java b/src/main/java/duke/command/ListCommand.java new file mode 100644 index 0000000000..38dbe46143 --- /dev/null +++ b/src/main/java/duke/command/ListCommand.java @@ -0,0 +1,22 @@ +package duke.command; + +import duke.TaskList; +import duke.storage.Storage; +import duke.ui.Ui; + +/** + * Handles the appropriate tasks when performing a ListCommand by Duke. + */ +public class ListCommand extends Command { + /** + * Overridden method to handle the specific tasks to be carried out when listing out all tasks from the Duke's list. + * @param tasks a list of tasks. + * @param ui Ui class to handle display messages. + * @param storage Storage to handle saving/loading of data to/from the list of task. + * @return Duke's response message + */ + @Override + public String initCommand(TaskList tasks, Ui ui, Storage storage) { + return ui.displayTaskList(tasks); + } +} diff --git a/src/main/java/duke/command/MarkCommand.java b/src/main/java/duke/command/MarkCommand.java new file mode 100644 index 0000000000..5b770f2e6a --- /dev/null +++ b/src/main/java/duke/command/MarkCommand.java @@ -0,0 +1,42 @@ +package duke.command; + +import duke.Task; +import duke.TaskList; +import duke.storage.Storage; +import duke.ui.Ui; + +/** + * Handles the appropriate tasks when performing a MarkCommand by Duke. + */ +public class MarkCommand extends Command { + + private int taskID; + + /** + * Constructor for MarkCommand. + * @param taskID index of the task to be marked within the list. + */ + public MarkCommand(int taskID) { + this.taskID = taskID; + } + + /** + * Overridden method to handle the specific tasks to be carried out when marking task as done in the list. + * @param tasks a list of tasks. + * @param ui Ui class to handle display messages. + * @param storage Storage to handle saving/loading of data to/from the list of task. + * @return Duke's response message + */ + @Override + public String initCommand(TaskList tasks, Ui ui, Storage storage) { + if (tasks.size() >= taskID && !tasks.isEmpty()) { + Task currentTask = tasks.getTask(taskID); + currentTask.marked(); + storage.saveData(tasks); + return ui.displayMarkMessage(currentTask); + + } else { + return ui.displayMsg("Invalid taskID entered!"); + } + } +} diff --git a/src/main/java/duke/command/UnmarkCommand.java b/src/main/java/duke/command/UnmarkCommand.java new file mode 100644 index 0000000000..d5c1838208 --- /dev/null +++ b/src/main/java/duke/command/UnmarkCommand.java @@ -0,0 +1,41 @@ +package duke.command; + +import duke.Task; +import duke.TaskList; +import duke.storage.Storage; +import duke.ui.Ui; + +/** + * Handles the appropriate tasks when performing a unMarkCommand by Duke. + */ +public class UnmarkCommand extends Command { + private int taskID; + + /** + * Constructor for UnmarkCommand. + * @param taskID index of the task to be unmark within the list. + */ + public UnmarkCommand(int taskID) { + this.taskID = taskID; + } + + /** + * Overridden method to handle the specific tasks to be carried out when unmarking task from the list. + * @param tasks a list of tasks. + * @param ui Ui class to handle display messages. + * @param storage Storage to handle saving/loading of data to/from the list of task. + * @return Duke's response message + */ + @Override + public String initCommand(TaskList tasks, Ui ui, Storage storage) { + if (tasks.size() >= taskID && !tasks.isEmpty()) { + Task currentTask = tasks.getTask(taskID); + currentTask.unmarked(); + storage.saveData(tasks); + return ui.displayUnmarkedMessage(currentTask); + + } else { + return ui.displayMsg("Invalid taskID entered!"); + } + } +} diff --git a/src/main/java/duke/command/UpdateCommand.java b/src/main/java/duke/command/UpdateCommand.java new file mode 100644 index 0000000000..1d3fb5caf4 --- /dev/null +++ b/src/main/java/duke/command/UpdateCommand.java @@ -0,0 +1,66 @@ +package duke.command; + +import duke.Deadline; +import duke.Event; +import duke.Task; +import duke.TaskList; +import duke.Todo; +import duke.Type; +import duke.exception.DukeException; +import duke.storage.Storage; +import duke.ui.Ui; + +/** + * Handles the appropriate tasks when performing a UpdateCommand by Duke. + */ +public class UpdateCommand extends Command { + + private String details; + + public UpdateCommand(String details) { + this.details = details; + } + /** + * @param tasks a list of tasks. + * @param ui Ui class to handle display messages. + * @param storage Storage to handle saving/loading of data to/from the list of task. + * @return duke's response message. + */ + @Override + public String initCommand(TaskList tasks, Ui ui, Storage storage) throws DukeException { + String[] splitDetails = this.details.split(" ", 2); + int index = Integer.parseInt(splitDetails[0]); + String description = splitDetails[1]; + Task toBeReplacedTask = tasks.getTask(index); + Type taskType = toBeReplacedTask.getType(); + switch (taskType) { + case TODO: + Todo newToDo = new Todo(description); + tasks.set(--index, newToDo); + return ui.displayUpdateMessage(newToDo); + case DEADLINE: + String[] deadlineFormatter = description.split(" /by "); + if (deadlineFormatter.length < 2) { + throw new DukeException("Either the description or deadline of the task is missing"); + } else { + Deadline newDeadline = new Deadline(deadlineFormatter[0], deadlineFormatter[1]); + tasks.set(--index, newDeadline); + return ui.displayUpdateMessage(newDeadline); + } + case EVENT: + // update 2 project meeting /from 2020-12-20 2000 /to 2020-12-25 2200 + String[] details = description.split(" /", 3); + if (details.length < 3) { + throw new IllegalArgumentException("Either the description or dates (from/to) of the task is missing"); + } else { + String[] eventFormatter = description.split(" /from "); + String[] startEndDate = eventFormatter[1].split(" /to "); + Event event = new Event(eventFormatter[0], startEndDate[0], startEndDate[1]); + tasks.set(--index, event); + return ui.displayUpdateMessage(event); + } + default: + throw new DukeException("Please try again"); + } + } +} diff --git a/src/main/java/duke/exception/DukeException.java b/src/main/java/duke/exception/DukeException.java new file mode 100644 index 0000000000..26f04ac6e2 --- /dev/null +++ b/src/main/java/duke/exception/DukeException.java @@ -0,0 +1,14 @@ +package duke.exception; + +/** + * Duke's exception class. + */ +public class DukeException extends Exception { + /** + * Constructor for Duke's own exception class. + * @param message appropriate message to be displayed. + */ + public DukeException(String message) { + super(message); + } +} diff --git a/src/main/java/duke/gui/DialogBox.java b/src/main/java/duke/gui/DialogBox.java new file mode 100644 index 0000000000..a0a8b68d3d --- /dev/null +++ b/src/main/java/duke/gui/DialogBox.java @@ -0,0 +1,61 @@ +package duke.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; + } +} diff --git a/src/main/java/duke/gui/MainWindow.java b/src/main/java/duke/gui/MainWindow.java new file mode 100644 index 0000000000..47bec14394 --- /dev/null +++ b/src/main/java/duke/gui/MainWindow.java @@ -0,0 +1,52 @@ +package duke.gui; + +import duke.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/DaUser.jpg")); + private Image dukeImage = new Image(this.getClass().getResourceAsStream("/images/DaDuke.jpg")); + + @FXML + public void initialize() { + scrollPane.vvalueProperty().bind(dialogContainer.heightProperty()); + } + + public void setDuke(Duke d) { + duke = d; + } + + /** + * 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) + ); + userInput.clear(); + } +} diff --git a/src/main/java/duke/parser/Parser.java b/src/main/java/duke/parser/Parser.java new file mode 100644 index 0000000000..7b359b5bbd --- /dev/null +++ b/src/main/java/duke/parser/Parser.java @@ -0,0 +1,75 @@ +package duke.parser; + +import duke.Deadline; +import duke.Event; +import duke.Todo; +import duke.command.AddCommand; +import duke.command.Command; +import duke.command.DeleteCommand; +import duke.command.ExitCommand; +import duke.command.FindCommand; +import duke.command.ListCommand; +import duke.command.MarkCommand; +import duke.command.UnmarkCommand; +import duke.command.UpdateCommand; +import duke.exception.DukeException; + +/** + * Represents Duke's parser to parse all userInputs and validate them before performing appropriate actions. + */ +public class Parser { + /** + * Enumeration for all possible commands. + */ + public enum ValidCommands { + LIST, TODO, DEADLINE, EVENT, MARK, UNMARK, DELETE, BYE, FIND, UPDATE + } + + /** + * Parse the userInput/commmand and returns the appropriate command for execution + * @param command Input/command given by the user. + * @return The appropriate command to be executed if valid + * @throws DukeException if the command is invalid + */ + public static Command parse(String command) throws DukeException { + String[] output = command.split(" ", 2); + ValidCommands validCommands = ValidCommands.valueOf(output[0].toUpperCase()); + switch (validCommands) { + case LIST: + return new ListCommand(); + case BYE: + return new ExitCommand(); + case TODO: + return new AddCommand(new Todo(output[1])); + case DEADLINE: + String[] deadlineFormatter = output[1].split(" /by "); + if (deadlineFormatter.length < 2) { + throw new DukeException("Either the description or deadline of the task is missing"); + } else { + return new AddCommand(new Deadline(deadlineFormatter[0], deadlineFormatter[1])); + } + case EVENT: + String[] details = output[1].split(" /", 3); + String[] eventFormatter = output[1].split(" /from "); + System.out.println(eventFormatter[0]); + if (details.length < 3) { + throw new IllegalArgumentException("Either the description or dates (from/to) of the task is missing"); + } else { + String[] startEndDate = eventFormatter[1].split(" /to "); + return new AddCommand(new Event(eventFormatter[0], startEndDate[0], startEndDate[1])); + } + case MARK: + return new MarkCommand(Integer.parseInt(output[1])); + case UNMARK: + return new UnmarkCommand(Integer.parseInt(output[1])); + case DELETE: + return new DeleteCommand(Integer.parseInt(output[1])); + case FIND: + return new FindCommand(output[1]); + case UPDATE: + return new UpdateCommand(output[1]); + default: + throw new DukeException("OOPS!!! I'm sorry, but I don't know what that means :-("); + } + } +} diff --git a/src/main/java/duke/storage/Storage.java b/src/main/java/duke/storage/Storage.java new file mode 100644 index 0000000000..125b7be4d8 --- /dev/null +++ b/src/main/java/duke/storage/Storage.java @@ -0,0 +1,100 @@ +package duke.storage; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +import duke.Deadline; +import duke.Event; +import duke.Task; +import duke.TaskList; +import duke.Todo; + +/** + * Storage class to handle all files related activities such as creation of duke.txt, + * loading and saving data from duke.txt. + */ +public class Storage { + private String filePath; + + /** + * Constructor method for Storage. + * @param filePath path to duke.txt + */ + public Storage(String filePath) { + this.filePath = filePath; + checkFile(filePath); + } + + /** + * check if duke.txt exists, creates it otherwise + * @param filePath relative/absolute path to duke.txt + */ + private void checkFile(String filePath) { + File file = new File(filePath); + if (!file.isFile()) { + try { + file.createNewFile(); + } catch (IOException e) { + System.out.println(e); + } + } + } + + /** + * Handles the saving of data from the list of tasks to duke.txt + * @param taskList the list of tasks + */ + public void saveData(TaskList taskList) { + try { + FileWriter fileWriter = new FileWriter(filePath); + for (int i = 0; i < taskList.size(); i++) { + Task t = taskList.getTask(i + 1); + fileWriter.write(t.formatForFile()); + } + fileWriter.close(); + } catch (IOException e) { + System.out.println(e); + } + } + + /** + * Handles the loading of data from duke.txt to the list of tasks + * @return a list of tasks + * @throws FileNotFoundException if the file does not exist in the filePath given + */ + public List loadFile() throws FileNotFoundException { + List taskList = new ArrayList<>(); + File file = new File(filePath); + if (file.isFile()) { + Scanner sc = new Scanner(file); + while (sc.hasNext()) { + String[] data = sc.nextLine().split(" \\| "); + Task task = null; + switch (data[0]) { + case "T": + task = new Todo(data[2]); + break; + case "D": + task = new Deadline(data[2], data[3]); + break; + case "E": + task = new Event(data[2], data[3], data[4]); + break; + default: + task = null; + } + if (data[1].equals("1")) { + task.marked(); + } + taskList.add(task); + } + sc.close(); + } + return taskList; + } +} diff --git a/src/main/java/duke/ui/Ui.java b/src/main/java/duke/ui/Ui.java new file mode 100644 index 0000000000..c8b52bc1f8 --- /dev/null +++ b/src/main/java/duke/ui/Ui.java @@ -0,0 +1,93 @@ +package duke.ui; + +import duke.TaskList; +import duke.Task; + +public class Ui { + /** + * Ui class to handle Duke's output + */ + + /** + * Prints out all of Duke's tasks. + * @param tasks list of tasks. + */ + public String displayTaskList(TaskList tasks) { + return tasks.toString(); + } + + /** + * Prints out the appropriate message when adding task to the list + * @param task task to be added + * @param taskList list of task + * @return Duke's response message + */ + public String displayAddTaskMessage(Task task, TaskList taskList) { + StringBuilder sb = new StringBuilder(); + sb.append("Got it. I've added this task:\n"); + sb.append(task.toString()); + sb.append("\nNow you have " + taskList.size() + " tasks in the list.\n"); + return sb.toString(); + } + + /** + * Prints out the appropriate message when adding task to the list + * @param task task to be added + * @param taskList list of task + * @return Duke's response message + */ + public String displayDeleteTaskMessage(Task task, TaskList taskList) { + StringBuilder sb = new StringBuilder(); + sb.append("Noted. I've removed this task:\n"); + sb.append(task.toString()); + sb.append("\nNow you have " + taskList.size() + " tasks in the list.\n"); + return sb.toString(); + } + + /** + * Prints out the appropriate message when adding task to the list + * @param task task to be added + * @return Duke's response message + */ + public String displayMarkMessage(Task task) { + StringBuilder sb = new StringBuilder(); + sb.append("Nice! I've marked this task as done:\n"); + sb.append(task.toString()); + return sb.toString(); + } + + /** + * Prints out the appropriate message when unmarking a task + * @param task task to be added + * @return Duke's response message + */ + public String displayUnmarkedMessage(Task task) { + StringBuilder sb = new StringBuilder(); + sb.append("OK, I've marked this task as not done yet:\n"); + sb.append(task.toString()); + return sb.toString(); + } + + /** + * Prints out Duke's goodbye message + * @return Duke's response message + */ + public String displayGoodbyeMessage() { + return "Bye. Hope to see you again soon!"; + } + + /** + * Prints out the appropriate misc message + * @return Duke's response message + */ + public String displayMsg(String output) { + return output; + } + + public String displayUpdateMessage(Task task) { + StringBuilder sb = new StringBuilder(); + sb.append("Task has been updated\n"); + sb.append(task.toString()); + return sb.toString(); + } +} diff --git a/src/main/resources/images/DaDuke.jpg b/src/main/resources/images/DaDuke.jpg new file mode 100644 index 0000000000..45d2212c36 Binary files /dev/null and b/src/main/resources/images/DaDuke.jpg differ diff --git a/src/main/resources/images/DaUser.jpg b/src/main/resources/images/DaUser.jpg new file mode 100644 index 0000000000..c5f1f5f1ac Binary files /dev/null and b/src/main/resources/images/DaUser.jpg differ diff --git a/src/main/resources/view/DialogBox.fxml b/src/main/resources/view/DialogBox.fxml new file mode 100644 index 0000000000..5f34eb5790 --- /dev/null +++ b/src/main/resources/view/DialogBox.fxml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/view/MainWindow.fxml b/src/main/resources/view/MainWindow.fxml new file mode 100644 index 0000000000..d340ac5fb9 --- /dev/null +++ b/src/main/resources/view/MainWindow.fxml @@ -0,0 +1,19 @@ + + + + + + + + + + + +