diff --git a/README.md b/README.md index 8715d4d915..745a1842e8 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,31 @@ -# Duke project template - -This is a project template for a greenfield Java project. It's named after the Java mascot _Duke_. Given below are instructions on how to use it. - -## Setting up in Intellij - -Prerequisites: JDK 11, update Intellij to the most recent version. - -1. Open Intellij (if you are not in the welcome screen, click `File` > `Close Project` to close the existing project first) -1. Open the project into Intellij as follows: - 1. Click `Open`. - 1. Select the project directory, and click `OK`. - 1. If there are any further prompts, accept the defaults. -1. Configure the project to use **JDK 11** (not other versions) as explained in [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk).
- In the same dialog, set the **Project language level** field to the `SDK default` option. -3. After that, locate the `src/main/java/Duke.java` file, right-click it, and choose `Run Duke.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output: - ``` - Hello from - ____ _ - | _ \ _ _| | _____ - | | | | | | | |/ / _ \ - | |_| | |_| | < __/ - |____/ \__,_|_|\_\___| - ``` +# DukePro + +DukePro frees your mind of having to remember things you need to do. It's, + +- easy to learn +- ~~FAST~~ _SUPER FAST_ to use + +All you need to do is, + +download it from [here](https://github.com/yulonglim/ip/archive/refs/heads/master.zip). +1. click load. +2. add your tasks. +3. let it manage your tasks for you 😉 +And it is FREE! + +Features: + + - [x] Managing tasks + - [ ] Managing deadlines + - [ ] Reminders + + +If you Java programmer, you can use it to practice Java too. Here's the `main` method: + +```java +public class Main { + public static void main(String[] args) { + Application.launch(MainApp.class, args); + } +} +``` diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000000..36e22cda19 --- /dev/null +++ b/build.gradle @@ -0,0 +1,62 @@ +plugins { + id 'java' + id 'application' + id 'com.github.johnrengelman.shadow' version '5.1.0' +} + +group 'org.example' +version '1.0-SNAPSHOT' + +repositories { + mavenCentral() +} + + + +test { + useJUnitPlatform() + + testLogging { + events "passed", "skipped", "failed" + + showExceptions true + exceptionFormat "full" + showCauses true + showStackTraces true + showStandardStreams = false + } +} + +dependencies { + implementation 'org.junit.jupiter:junit-jupiter:5.7.0' + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.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' +} + +application { + mainClassName = "duke.Launcher" +} + +shadowJar { + archiveBaseName = "duke" + archiveClassifier = null +} + +run{ + standardInput = System.in +} \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index 8077118ebe..bed7faea1b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2,28 +2,106 @@ ## Features -### Feature-ABC +### Add Task -Description of the feature. +Add your task to the list with the inputs you give -### Feature-XYZ +### Complete Task -Description of the feature. +Mark task that have been completed + +### Find Task + +Filter your list for specific tasks + +### Update Task + +Made an error? no worries simply update the task through the update tab + +### Delete Task + +Easily delete any task that have expired/done ## Usage -### `Keyword` - Describe action +### `Gui Based` - No long commands needed to add items + +This bot allows for simple entries in the correct text field + +### Example of add Task: + +type: `T` + +description: `Cook Lunch` + +date: + +Expected outcome: + +Todo task of description cook lunch added to the list + +``` +Here are the tasks in your list: +1. [T][ ] Cook Lunch +``` +### Example of Complete Task: + +index: `1` + +Expected outcome: + +Task marked with 1 marked as completed -Describe the action and its outcome. +``` +Here are the tasks in your list: +1. [T][X] Cook Lunch +``` +### Example of find Task: + +filter word: `cook` -Example of usage: +Expected outcome: -`keyword (optional arguments)` +list will now only show task with "cook" in it (Case-insensitive + +``` +Here are the matching tasks in your list: +1. [T][X] Cook Lunch +Press load to go back! +``` +### Example of Update Task: + +index: `1` + +new description: `Eat Lunch` + +new date: Expected outcome: -Description of the outcome. +Task at index 1 has been updated, and marked as undone. ``` -expected output +Here are the tasks in your list: +1. [T][ ] Eat Lunch ``` +### Example of Delete Task: + +index: `1` + +Expected outcome: + +Task 1 in the list will be deleted + +``` +There are no task in your list +``` +## FAQ + +What if I want to change the type of task? + +`As changing the type of task is a large change I believe that user should delete the task completely and add a new one!` + +How will I know if I entered some fields wrongly? + +`The GUI will automatically show error fields if there are errors in the input!` \ No newline at end of file diff --git a/docs/Ui.png b/docs/Ui.png new file mode 100644 index 0000000000..971bb69664 Binary files /dev/null and b/docs/Ui.png differ diff --git a/duke.txt b/duke.txt new file mode 100644 index 0000000000..595ce7633b --- /dev/null +++ b/duke.txt @@ -0,0 +1,26 @@ +true|T|123 +false|T|123 +false|T|72 +false|T|3525253 +true|D|123414|2021-10-21 +false|D|twe|2021-10-15 +false|D|123414|2021-10-21 +false|T|asffa +false|T|asffa +false|T|asffa +false|T|asffa +true|T|34 +false|T|34 +false|T|34 +false|E|12515|2021-10-21 +false|E|12515|2021-10-21 +false|E|12515|2021-10-21 +false|E|12515|2021-10-21 +false|E|12515|2021-10-21 +false|D|12515|2021-10-21 +true|D|12515|2021-10-21 +false|D|12515|2021-10-21 +false|D|12515|2021-10-21 +false|T|12515 +false|T|12515 +false|T|12515 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000..e708b1c023 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..be52383ef4 --- /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.7-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000000..4f906e0c81 --- /dev/null +++ b/gradlew @@ -0,0 +1,185 @@ +#!/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..107acd32c4 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@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 execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="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/JarFolder/Duke.jar b/src/JarFolder/Duke.jar new file mode 100644 index 0000000000..c965d936fb Binary files /dev/null and b/src/JarFolder/Duke.jar differ diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java deleted file mode 100644 index 5d313334cc..0000000000 --- a/src/main/java/Duke.java +++ /dev/null @@ -1,10 +0,0 @@ -public class Duke { - public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - } -} diff --git a/src/main/java/duke/Controller.java b/src/main/java/duke/Controller.java new file mode 100644 index 0000000000..c837ec0132 --- /dev/null +++ b/src/main/java/duke/Controller.java @@ -0,0 +1,216 @@ +package duke; + +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.DatePicker; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; + +import java.io.IOException; +import java.net.URL; +import java.util.ResourceBundle; + +import static duke.Parser.taskParse; + + +public class Controller implements Initializable { + + private static Storage storage; + private static TaskList tasks; + + @FXML + private Label listLabel; + + @FXML + private Label deleteError; + + @FXML + private TextField deleteText; + + @FXML + private TextField taskType; + + @FXML + private TextField taskDescription; + + @FXML + private DatePicker taskDate; + + @FXML + private Label addTaskError; + + @FXML + private TextField doneText; + + @FXML + private Label doneError; + + @FXML + private TextField findText; + + @FXML + private TextField updateIndex; + + @FXML + private TextField updateDescription; + + @FXML + private Label updateError; + + @FXML + private DatePicker updateDate; + + @Override + public void initialize(URL location, ResourceBundle resources) { + storage = new Storage("duke.txt"); + this.load(); + } + + /** + * Loads the tasklist when the load button is pressed + * + * @param a action of pressing load button + */ + public void load(ActionEvent a) { + try { + tasks = new TaskList(storage.load()); + } catch (IOException | DukeException e) { + tasks = new TaskList(); + } + listLabel.setText(tasks.toString()); + } + + /** + * Loads updated tasklist when other buttons are pressed + */ + public void load() { + try { + tasks = new TaskList(storage.load()); + } catch (IOException | DukeException e) { + tasks = new TaskList(); + } + listLabel.setText(tasks.toString()); + addTaskError.setText(""); + deleteError.setText(""); + doneError.setText(""); + updateError.setText(""); + } + + /** + * Saves tasklist to storage when any actions are carried out + */ + public void save() { + try { + storage.save(tasks); + } catch (IOException e) { + storage = new Storage("duke.txt"); + this.save(); + } + listLabel.setText(tasks.toString()); + addTaskError.setText(""); + deleteError.setText(""); + doneError.setText(""); + updateError.setText(""); + } + + /** + * Adds a task to the list when add button is pressed + * + * @param a action of pressing add button + */ + public void add(ActionEvent a) { + if (taskType.getText().equalsIgnoreCase("T")) { + tasks.addTask(taskParse(taskType.getText(), taskDescription.getText(), "")); + this.save(); + assert addTaskError.getText().equals(""); + } else if (taskType.getText().equalsIgnoreCase("D") + || taskType.getText().equalsIgnoreCase("E")) { + if (taskDate.getValue() == null) { + addTaskError.setText("Add a Date!"); + } else { + tasks.addTask(taskParse(taskType.getText(), + taskDescription.getText(), + taskDate.getValue().toString())); + this.save(); + assert addTaskError.getText().equals(""); + } + } else { + addTaskError.setText("Task type to be T, D or E"); + } + + } + + /** + * Marks a task as done on the list when the done button is pressed + * + * @param a action of press done button + */ + public void done(ActionEvent a) { + try { + int doneIndex = Integer.parseInt(doneText.getText()) - 1; + if (doneIndex > tasks.size() - 1 || doneIndex < 0) { + doneError.setText("Please enter a number in the list"); + } else { + tasks.markAsDone(doneIndex); + this.save(); + assert doneError.getText().equals(""); + } + } catch (NumberFormatException e) { + doneError.setText("Please enter integer"); + } + } + + /** + * Deletes a task to the list when delete button is pressed + * + * @param a action of press delete button + */ + public void delete(ActionEvent a) { + try { + int deleteIndex = Integer.parseInt(deleteText.getText()) - 1; + if (deleteIndex > tasks.size() - 1 || deleteIndex < 0) { + deleteError.setText("Please enter a number in the list"); + } else { + tasks.removeTask(deleteIndex); + this.save(); + assert deleteError.getText().equals(""); + } + } catch (NumberFormatException e) { + deleteError.setText("Please enter integer"); + } + } + + + /** + * Updates task in tasklist given user input + * + * @param a action of press update button + */ + public void update(ActionEvent a) { + try { + int index = Integer.parseInt(updateIndex.getText()) - 1; + if (index > tasks.size() - 1 || index < 0) { + updateError.setText("Please enter a number in the list"); + } else { + tasks.updateTask(index, updateDescription.getText(), updateDate.getValue()); + this.save(); + assert updateError.getText().equals(""); + } + } catch (NumberFormatException e) { + updateError.setText("Please enter integer"); + } + } + + + /** + * Displays a filtered tasklist given a string to find + * + * @param a action of press find button + */ + public void find(ActionEvent a) { + listLabel.setText(tasks.findTask(findText.getText()) + "Press load to go back!"); + } + + +} diff --git a/src/main/java/duke/Deadline.java b/src/main/java/duke/Deadline.java new file mode 100644 index 0000000000..51877ae65b --- /dev/null +++ b/src/main/java/duke/Deadline.java @@ -0,0 +1,27 @@ +package duke; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +/** + * class that extends task + * labelled with an extra [D] when called + * stores the date which task should be done by + */ +public class Deadline extends Task { + protected LocalDate date; + + public Deadline(String description, String by) { + super(description); + date = Parser.dateParse(by); + } + + public void changeDate(LocalDate date) { + this.date = date; + } + + @Override + public String toString() { + return "[D]" + super.toString() + " (by: " + date.format(DateTimeFormatter.ofPattern("MMM d yyyy")) + ")"; + } +} diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java new file mode 100644 index 0000000000..0c2ec60c59 --- /dev/null +++ b/src/main/java/duke/Duke.java @@ -0,0 +1,35 @@ +package duke; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; + +/** + * Duke class + * Uses storage class to gather data from text file + * When run, parses input into parser class which utilizes ui class to give an output + * After each command it saves to the storage text file + */ +public class Duke extends Application { + + public Duke() { + } + + /** + * Start function for duke GUI + * + * @param stage + * @throws Exception + */ + @Override + public void start(Stage stage) throws Exception { + Parent root = FXMLLoader.load(Duke.class.getResource("/duke.fxml")); + Scene scene = new Scene(root); // Setting the scene to be our Label + + stage.setTitle("Duke Bot"); + stage.setScene(scene); // Setting the stage to show our screen + stage.show(); // Render the stage. + } +} diff --git a/src/main/java/duke/DukeException.java b/src/main/java/duke/DukeException.java new file mode 100644 index 0000000000..6f617e550b --- /dev/null +++ b/src/main/java/duke/DukeException.java @@ -0,0 +1,9 @@ +package duke; + +public class DukeException extends Exception { + private final String description; + + DukeException(String description) { + this.description = description; + } +} diff --git a/src/main/java/duke/Event.java b/src/main/java/duke/Event.java new file mode 100644 index 0000000000..df68da23e1 --- /dev/null +++ b/src/main/java/duke/Event.java @@ -0,0 +1,27 @@ +package duke; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +/** + * class that extends task + * labelled with an extra [E] when called + * stores the date which task should occur + */ +public class Event extends Task { + protected LocalDate date; + + public Event(String description, String at) { + super(description); + this.date = Parser.dateParse(at); + } + + public void changeDate(LocalDate date) { + this.date = date; + } + + @Override + public String toString() { + return "[E]" + super.toString() + " (at: " + date.format(DateTimeFormatter.ofPattern("MMM d yyyy")) + ")"; + } +} diff --git a/src/main/java/duke/Launcher.java b/src/main/java/duke/Launcher.java new file mode 100644 index 0000000000..e1fd4e06cc --- /dev/null +++ b/src/main/java/duke/Launcher.java @@ -0,0 +1,12 @@ +package duke; + +import javafx.application.Application; + +/** + * Launcher class to launch duke GUI + */ +public class Launcher { + public static void main(String[] args) { + Application.launch(Duke.class, args); + } +} diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java new file mode 100644 index 0000000000..059c2eb2da --- /dev/null +++ b/src/main/java/duke/Parser.java @@ -0,0 +1,82 @@ +package duke; + +import java.time.LocalDate; +import java.util.ArrayList; + +/** + * Class which converts user command to functions + */ +public class Parser { + + public Parser() { + } + + /** + * Parses input given by user into a Task + * + * @param type of the task T, D or E + * @param description description of task + * @param dateTime for D,E to track time + * @return Task of the specific specifications + */ + public static Task taskParse(String type, String description, String dateTime) { + if (type.equalsIgnoreCase("T")) { + return new Todo(description); + } else if (type.equalsIgnoreCase("D")) { + return new Deadline(description, dateTime); + } else if (type.equalsIgnoreCase("E")) { + return new Event(description, dateTime); + } else { + return null; + } + } + + /** + * Parses input given by storage during initialization of duke + * + * @param storageData string passed in after reading from storage file + * @return Arraylist of task to be passed into a task list during initialization of duke + */ + public static ArrayList storageParse(String storageData) { + ArrayList tasks = new ArrayList<>(); + if (storageData.equals("")) { + return tasks; + } + for (String i : storageData.split("\n")) { + Task newTask; + String[] inputs = i.split("\\|"); + + if (inputs.length < 4) { + newTask = taskParse(inputs[1], inputs[2], null); + } else { + newTask = taskParse(inputs[1], inputs[2], inputs[3]); + } + + if (inputs[0].equals("true")) { + assert newTask != null; + newTask.markAsDone(); + } + tasks.add(newTask); + } + return tasks; + } + + /** + * Parses date related inputs and produce LocalDate object for duke + * + * @param dateString input to be parsed in + * @return LocalDate object requested + */ + public static LocalDate dateParse(String dateString) { + LocalDate date; + if (dateString.contains("/")) { + String[] inputs = dateString.split("/"); + date = LocalDate.parse(inputs[2] + "-" + inputs[1] + "-" + + (Integer.parseInt(inputs[0]) < 10 ? "0" + inputs[0] : + inputs[0])); + } else { + date = LocalDate.parse(dateString); + } + return date; + } +} diff --git a/src/main/java/duke/Storage.java b/src/main/java/duke/Storage.java new file mode 100644 index 0000000000..8417266dba --- /dev/null +++ b/src/main/java/duke/Storage.java @@ -0,0 +1,65 @@ +package duke; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Scanner; + +/** + * Class which reads and write to a .txt file to persist data + */ +public class Storage { + + private final String filepath; + + public Storage(String filepath) { + this.filepath = filepath; + } + + + /** + * Reads the file and produces the last used list of tasks + * + * @return ArrayList of Tasks, Tasks saved in the file + * @throws IOException + */ + protected ArrayList load() throws IOException { + File dukeItems = new File(filepath); + String data = ""; + if (dukeItems.createNewFile()) { + System.out.println("File created: " + dukeItems.getName()); + } else { + Scanner myReader = new Scanner(dukeItems); + while (myReader.hasNextLine()) { + data += myReader.nextLine() + "\n"; + } + myReader.close(); + } + + return Parser.storageParse(data); + } + + /** + * Writes to the file with the give TaskList + * + * @param list the list of task needed to be saved + * @throws IOException + */ + protected void save(TaskList list) throws IOException { + String result = ""; + FileWriter myWriter = new FileWriter(filepath); + for (int i = 0; i < list.size(); i++) { + Task t = list.getTask(i); + if (t instanceof Todo) { + result += t.isDone + "|" + "T" + "|" + t.description + "\n"; + } else if (t instanceof Deadline) { + result += t.isDone + "|" + "D" + "|" + t.description + "|" + ((Deadline) t).date + "\n"; + } else if (t instanceof Event) { + result += t.isDone + "|" + "E" + "|" + t.description + "|" + ((Event) t).date + "\n"; + } + } + myWriter.write(result); + myWriter.close(); + } +} diff --git a/src/main/java/duke/Task.java b/src/main/java/duke/Task.java new file mode 100644 index 0000000000..6ebd7c13ce --- /dev/null +++ b/src/main/java/duke/Task.java @@ -0,0 +1,52 @@ +package duke; + +/** + * Task class used by the duke class + * Stores a description of task and whether it is done + */ +public class Task { + protected String description; + protected boolean isDone; + + public Task(String description) { + this.description = description; + this.isDone = false; + } + + /** + * Get status on the task and returns appropriate icon + * + * @return String "X" if task is done & " " if not done + */ + public String getStatusIcon() { + return (isDone ? "X" : " "); // mark done task with X + } + + /** + * Marks task as done + */ + public void markAsDone() { + this.isDone = true; + } + + /** + * Marks task as not done + */ + public void markUndone() { + this.isDone = false; + } + + /** + * Changes description of task + * + * @param description to change into + */ + public void changeDescription(String description) { + this.description = description; + } + + @Override + public String toString() { + return String.format("[%s] %s", this.getStatusIcon(), this.description); + } +} \ No newline at end of file diff --git a/src/main/java/duke/TaskList.java b/src/main/java/duke/TaskList.java new file mode 100644 index 0000000000..9a65a60bb5 --- /dev/null +++ b/src/main/java/duke/TaskList.java @@ -0,0 +1,126 @@ +package duke; + +import java.time.LocalDate; +import java.util.ArrayList; + +public class TaskList { + + private final ArrayList list; + + public TaskList(ArrayList list) throws DukeException { + if (list.isEmpty()) { + throw new DukeException("Task list is empty!"); + } + this.list = list; + } + + public TaskList() { + this.list = new ArrayList<>(); + } + + /** + * Adds task to tasklist + * + * @param task to be added in + */ + public void addTask(Task task) { + this.list.add(task); + } + + /** + * Removes task from tasklist on specified index + * + * @param index of task to be removed + */ + public void removeTask(int index) { + this.list.remove(index); + } + + /** + * Marks task in list to done given index + * + * @param index of task to be marked + */ + public void markAsDone(int index) { + this.list.get(index).markAsDone(); + } + + /** + * Getter for task at specific index + * + * @param index of task requested + * @return Task at the specific index + */ + public Task getTask(int index) { + return this.list.get(index); + } + + /** + * Edits task at specific index + * + * @param index of task to be edited + * @param description new description for the task chosen + * @param date new date for task chosen + */ + public void updateTask(int index, String description, LocalDate date) { + this.list.get(index).markUndone(); + if (!description.equalsIgnoreCase("")) { + this.getTask(index).changeDescription(description); + } + if (date != null) { + if (this.list.get(index) instanceof Event) { + ((Event) this.list.get(index)).changeDate(date); + } else if (this.list.get(index) instanceof Deadline) { + ((Deadline) this.list.get(index)).changeDate(date); + } + } + } + + /** + * Get size of current task list + * + * @return size of task list + */ + public int size() { + return this.list.size(); + } + + /** + * Find task given a search word + * + * @param find string to be searched using + * @return formatted string to be displayed + */ + public String findTask(String find) { + ArrayList result = new ArrayList<>(); + for (Task t : this.list) { + if (t.toString().toLowerCase().contains(find.toLowerCase())) { + result.add(t); + } + } + return TaskListToString(result); + } + + /** + * Given an ArrayList of Task returns the String to be displayed in duke + * + * @return String to be displayed + */ + public String TaskListToString(ArrayList taskArrayList) { + if (taskArrayList.size() == 0) { + return "There are no matching task in your list!\n"; + } + String listContent = "Here are the matching tasks in your list:\n"; + for (int i = 0; i < taskArrayList.size(); i++) { + listContent += (i + 1) + ". " + taskArrayList.get(i).toString() + "\n"; + } + return listContent; + + } + + @Override + public String toString() { + return TaskListToString(this.list); + } + +} diff --git a/src/main/java/duke/Todo.java b/src/main/java/duke/Todo.java new file mode 100644 index 0000000000..205621a38e --- /dev/null +++ b/src/main/java/duke/Todo.java @@ -0,0 +1,16 @@ +package duke; + +/** + * class that extends task + * labelled with an extra [T] when called + */ +public class Todo extends Task { + public Todo(String description) { + super(description); + } + + @Override + public String toString() { + return "[T]" + super.toString(); + } +} diff --git a/src/main/resources/duke.fxml b/src/main/resources/duke.fxml new file mode 100644 index 0000000000..8eb25a0269 --- /dev/null +++ b/src/main/resources/duke.fxml @@ -0,0 +1,88 @@ + + + + + + + + + + + + +