diff --git a/README.md b/README.md index 8715d4d915..6b3a03bfa2 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,34 @@ -# 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 - ____ _ - | _ \ _ _| | _____ - | | | | | | | |/ / _ \ - | |_| | |_| | < __/ - |____/ \__,_|_|\_\___| - ``` +# DukeProMax + +"Always give your 100% in everything, except when donating blood" - some dude + +DukeProMax allows you to store your daily tasks so you can always give your 100% on a day to day basis. It is + +- SUPER easy to use +- USER Friendly +- SUPER Fast to use + +# SUS for short :+1: + +1. Download it from [here](https://github.com/Gavzzz/ip) +2. Double-click it. +3. Chat with it to add you tasks +4. Let it manage your tasks for you + + +The best part? It is absolutely + +# FREE!! + +Features include but not limited to + +- [x] Managing tasks +- [x] Managing events +- [x] Finding tasks +- [ ] More extensions coming soon + + +So what are you waiting for??? +# USE IT NOW!!!! + + diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000000..68b2d884fc --- /dev/null +++ b/build.gradle @@ -0,0 +1,59 @@ +plugins { + id 'java' + id 'application' + id 'com.github.johnrengelman.shadow' version '5.1.0' +} + +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.gui.Launcher" +} + +shadowJar { + archiveBaseName = "duke" + archiveClassifier = null +} + +run { + standardInput = System.in +} diff --git a/database/duke.txt b/database/duke.txt new file mode 100644 index 0000000000..0ccc450a48 --- /dev/null +++ b/database/duke.txt @@ -0,0 +1 @@ +T | 0 | borrow diff --git a/docs/README.md b/docs/README.md index 8077118ebe..5434151d5f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,29 +1,135 @@ -# User Guide +# User Guide for DukeMaxPro ## Features -### Feature-ABC +### Add Tasks -Description of the feature. +Add up to 3 different types of tasks! -### Feature-XYZ +[todo] + +A todo task denoted by [T] + +input format: "todo" + task description + +[deadline] + +A deadline task denoted by [D] + +A deadline task with a deadline to be input, denoted by [D] + +Input format: "deadline" + task description + "/by" + deadline + +[Event] + +An event task with a time of event, denoted by [E] + +Input format: "event" + task description + "/at" + time of event + +### Mark / Unmark tasks as done + +Marks tasks as done with an "X" or undone without an "X" and with an empty box [ ] +to keep track of task completion. + +### View task list + +Displays the entire task list + +### Detect duplicates + +Detects duplicate tasks inside the task lists and alerts the user about which +task is duplicated and how many tasks are duplicated -Description of the feature. ## Usage -### `Keyword` - Describe action +### `list` - Displays current task list + + +Example of usage: + +`list` + +Expected outcome: + +``` +[T][X] Borrow book +[D][ ] Return Book (by: Monday 2pm) +[E][ ] Meeting (at: Monday 2pm-4pm) +``` + +### `todo` - Adds a todo task to the task list -Describe the action and its outcome. Example of usage: -`keyword (optional arguments)` +`todo` + Expected outcome: -Description of the outcome. +``` +[T][X] Borrow book +``` + +### `deadline` - Adds a deadline task to the task list + + +Example of usage: + +`deadline` + + +Expected outcome: ``` -expected output +[D][ ] Return Book (by: Monday 2pm) ``` + +### `event` - Adds a event task to the task list + + +Example of usage: + +`event` + + +Expected outcome: + +``` +[E][ ] Meeting (at: Monday 2pm-4pm) +``` + +### `mark` - Marks a task as done in the task list + + +Example of usage: + +`mark 1` + + +Expected outcome: + +``` +[E][X] Meeting (at: Monday 2pm-4pm) +``` + +### `unmark` - Unarks a task as not done in the task list + + +Example of usage: + +`unmark 1` + + +Expected outcome: + +``` +[E][ ] Meeting (at: Monday 2pm-4pm) +``` + + + + + + diff --git a/docs/Ui.png b/docs/Ui.png new file mode 100644 index 0000000000..6564495a27 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/Duke.java b/src/main/java/duke/Duke.java new file mode 100644 index 0000000000..1c3cee8c6d --- /dev/null +++ b/src/main/java/duke/Duke.java @@ -0,0 +1,42 @@ +package duke; + +import java.io.FileNotFoundException; +import java.util.ArrayList; + +/* Inspiration taken from Bag Devesh Kumar and Zizheng ip to solve some prevalent issues + */ +public class Duke { + + private Storage storage; + private TaskList tasks; + private Ui ui; + + public Duke() { + this.ui = new Ui(); + this.storage = new Storage(System.getProperty("user.dir") + "/database/duke.txt"); + try { + tasks = new TaskList(storage.load()); + tasks.list(); + } catch (FileNotFoundException e) { + tasks = new TaskList(); + } + } + + /** + * 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) { + try { + if (input.equals("bye")) { + ArrayList data = tasks.bye(); + storage.save(data); + return ui.printBye(); + } else { + return Parser.parse(input, tasks, ui, storage); + } + } catch (DukeException e) { + return e.getMessage(); + } + } +} diff --git a/src/main/java/duke/DukeException.java b/src/main/java/duke/DukeException.java new file mode 100644 index 0000000000..eb61260aee --- /dev/null +++ b/src/main/java/duke/DukeException.java @@ -0,0 +1,18 @@ +package duke; + +public class DukeException extends Exception { + private String message; + + public DukeException(String message) { + super(message); + } + + + /** + * Returns the message of the exception. + * @return Message of the exception. + */ + public String toString() { + return message; + } +} diff --git a/src/main/java/duke/IllegalCommandException.java b/src/main/java/duke/IllegalCommandException.java new file mode 100644 index 0000000000..fbbc626fc1 --- /dev/null +++ b/src/main/java/duke/IllegalCommandException.java @@ -0,0 +1,8 @@ +package duke; + +public class IllegalCommandException extends Exception { + + public IllegalCommandException(String message) { + super(message); + } +} diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java new file mode 100644 index 0000000000..df44533230 --- /dev/null +++ b/src/main/java/duke/Parser.java @@ -0,0 +1,64 @@ +package duke; + + +/** + * Parser to parse user inputs + * + * @author Gavin Cho + * @version CS2103T AY22/23 Sem 1 + */ +public class Parser { + + /** + * Parses the input with the tasks, ui and storage + * @param input Input of the user + * @param tasks TaskList of which input is to be stored + * @param ui Ui needed for the input + * @param storage Storage needed for the input + * @return True if program should continue, false otherwise + * @throws DukeException If the user input is invalid + */ + public static String parse(String input, TaskList tasks, Ui ui, Storage storage) + throws DukeException { + if (!isValidCommand(input)) { + throw new DukeException("Sorry! I don't Understand what you are saying."); + } else { + if (input.equals("list")) { + return tasks.list(); + } else if (input.startsWith("delete")) { + return tasks.delete(input); + } else if (input.startsWith("find")) { + return tasks.find(input); + } else if (input.startsWith("unmark")) { + return tasks.unmarkTask(input); + } else if (input.startsWith("mark")) { + return tasks.markTask(input); + } else if (input.startsWith("deadline")) { + return tasks.deadline(input); + } else if (input.startsWith("event")) { + return tasks.event(input); + } else if (input.startsWith("todo")) { + return tasks.todo(input); + } else if (input.startsWith("tag")) { + return tasks.tag(input); + } else if (input.startsWith("listtag")) { + return tasks.listTags(input); + } else { + throw new UnknownCommandException(); + } + } + } + + + /** + * Returns true if input is within scope of the Keywords. + * + * @param input Input of the user. + * @return True if input is within scope of the program, false otherwise. + */ + public static boolean isValidCommand(String input) { + return (input.startsWith("list") || input.startsWith("mark") || input.startsWith("unmark") || input.startsWith("deadline") + || input.startsWith("event") || input.startsWith("todo") || input.startsWith("delete") || input.startsWith("find") + || input.startsWith("tag") || input.startsWith("listtags")); + } +} diff --git a/src/main/java/duke/Storage.java b/src/main/java/duke/Storage.java new file mode 100644 index 0000000000..e75a3a4bf2 --- /dev/null +++ b/src/main/java/duke/Storage.java @@ -0,0 +1,65 @@ +package duke; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Scanner; + +/** + * Storage is used to handle data saved. + */ +public class Storage { + private final String filePath; + + /** + * Constructs Storage. + * @param filePath filepath containing input from previous session. + */ + public Storage(String filePath) { + this.filePath = filePath; + } + + /** + * Loads the list containing input from previous session. + * @return List containing input from previous session. + * @throws FileNotFoundException If file does not exist. + */ + public ArrayList load() throws FileNotFoundException { + ArrayList list = new ArrayList<>(); + File f = new File(filePath); + Scanner s = new Scanner(f); + + while (s.hasNext()) { + String in = s.nextLine(); + list.add(in); + } + s.close(); + if (list.isEmpty()) { + throw new FileNotFoundException(); + } + + return list; + } + + /** + * Saves the input for next session. + * @param list List of input to be saved for next session. + */ + public void save(ArrayList list) { + try { + new File(filePath).getParentFile().mkdirs(); + FileWriter fw = new FileWriter(System.getProperty("user.dir") + + "/database/duke.txt"); + + for (String tasks : list) { + fw.write(String.format("%s%n", tasks)); + } + fw.close(); + } catch (IOException e) { + System.out.println("Oops: " + e.getMessage()); + } + } + +} \ 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..7c3a36496a --- /dev/null +++ b/src/main/java/duke/TaskList.java @@ -0,0 +1,313 @@ +package duke; +import java.time.LocalDate; +import java.util.ArrayList; + +import duke.tasks.Deadline; +import duke.tasks.Event; +import duke.tasks.Task; +import duke.tasks.Todo; + +public class TaskList { + private ArrayList tasks; + private int size; + + /** + * Constructs the TaskList. + */ + public TaskList() { + this.tasks = new ArrayList<>(); + this.size = 0; + } + + /** + * Constructs the TaskList with previous inputs. + * + * @param dataList Previous input data. + */ + public TaskList(ArrayList dataList) { + this.tasks = new ArrayList<>(); + for (String data : dataList) { + tasks.add(Task.loadTask(data)); + } + this.size = tasks.size(); + } + + /** + * Saves the TaskList after user input bye. + * + * @return ArrayList of the input that has been saved. + */ + public ArrayList bye() { + return saveTasks(); + } + + /** + * Saves the TaskList. + * + * @return ArrayList of the input that has been saved. + */ + public ArrayList saveTasks() { + ArrayList list = new ArrayList<>(); + for (Task task : tasks) { + list.add(task.saveTask()); + } + return list; + } + + /** + * Marks a task. + * + * @param input Input of the user. + * @return Message for user. + */ + public String markTask(String input) { + char n = input.charAt(5); + int number = Character.getNumericValue(n) - 1; + assert number >= 0 : "index should be >= 0"; + Task t = tasks.get(number); + t.mark(); + String line1 = "Nice! I've marked this task as done:"; + String line2 = t.toString(); + String mark = line1 + "\n" + line2; + return mark; + } + + /** + * Unmarks a task. + * + * @param input Input of the user. + * @return Message for user. + */ + public String unmarkTask(String input) { + char n = input.charAt(7); + int number = Character.getNumericValue(n) - 1; + assert number >= 0 : "index should be >= 0"; + Task t = tasks.get(number); + t.markAsNotDone(); + String line1 = "OK, I've marked this task as not done yet:"; + String line2 = t.toString(); + String unmark = line1 + "\n" + line2; + return unmark; + } + + /** + * Lists the inputs of the user. + * + * @return Message for user. + */ + public String list() { + int count = 1; + String list = "Here are the tasks in your list:" + "\n"; + for (Task task : tasks) { + String newLine = count + ". " + task.toString() + "\n"; + list += newLine; + count += 1; + } + if (count == 1) { + String empty = "Your list is empty."; + return empty; + } else { + return list; + } + } + + /** + * Deletes a task. + * + * @param input Input of the user. + * @return Message for user. + */ + public String delete(String input) { + char n = input.charAt(7); + int number = Character.getNumericValue(n) - 1; + assert number >= 0 : "index should be 0 or larger"; + String line1 = "I've removed this task:"; + String line2 = " " + tasks.get(number).toString(); + tasks.remove(number); + size -= 1; + String line3 = "Now you have " + size + " tasks in the list"; + String message = line1 + "\n" + line2 + "\n" + line3; + return message; + } + + /** + * Returns a message for deadline input. + * + * @param in Input of the user. + * @return Message for user. + * @throws DukeException An exception unique to duke.Duke. + */ + public String deadline(String in) throws DukeException { + String deadLine = in.replaceFirst("deadline", ""); + if (deadLine.trim().isEmpty()) { + throw new DukeException("Yo! The description of a deadline cannot be empty!"); + } else { + return addDeadline(deadLine); + } + } + + /** + * Adds a deadline event to the list. + * + * @param deadLine Input of the user. + * @return Message for user. + */ + public String addDeadline(String deadLine) { + String[] result = deadLine.split("/by ", 2); + String desc = result[0]; + String by = result[1]; + Deadline d = new Deadline(desc, LocalDate.parse(by)); + tasks.add(d); + size += 1; + String line1 = "Got it. I've added this task:"; + String line2 = " " + d.toString(); + String line3 = "Now you have " + size + " tasks in the list"; + String message = line1 + "\n" + line2 + "\n" + line3; + return message; + } + + /** + * Returns a message for event input. + * + * @param input Input of the user. + * @return Message for the user. + * @throws DukeException An exception unique to duke.Duke. + */ + public String event(String input) throws DukeException { + String event = input.replaceFirst("event", ""); + if (event.trim().isEmpty()) { + throw new DukeException("Yo! The description of an event cannot be empty."); + } else { + return addEvent(event); + } + } + + /** + * Adds an event task to the list. + * + * @param event Input of the user. + * @return Message for the user. + */ + public String addEvent(String event) { + String[] result = event.split("/at ", 2); + String desc = result[0]; + String by = result[1]; + Event e = new Event(desc, LocalDate.parse(by)); + tasks.add(e); + size += 1; + String line1 = "I've added this task:"; + String line2 = " " + e.toString(); + String line3 = "Now you have " + size + " tasks in the list"; + String message = line1 + "\n" + line2 + "\n" + line3; + return message; + } + + /** + * Adds a to-do task to the list. + * + * @param input Input of the user. + * @return message for user + * @throws DukeException An exception unique to duke.Duke. + */ + public String todo(String input) throws DukeException { + String todo = input.replaceFirst("todo", ""); + if (todo.trim().isEmpty()) { + throw new DukeException("Yo! The description of a deadline cannot be empty."); + } else { + Todo t = new Todo(todo); + tasks.add(t); + size += 1; + String line1 = "Got it. I've added this task:"; + String line2 = " " + t.toString(); + String line3 = "Now you have " + size + " tasks in the list"; + String message = line1 + "\n" + line2 + "\n" + line3; + return message; + } + } + + /** + * Finds tasks in list. + * + * @param input Input of the user. + * @return Message for user. + * @throws DukeException If there is an error in the input. + */ + public String find(String input) throws DukeException { + String toBeFound = input.replaceFirst("find", ""); + if (toBeFound.trim().isEmpty()) { + throw new DukeException("Yo! The description of the task you want cannot be empty."); + } else { + assert toBeFound.length() > 0 : "The keywords should not be empty"; + int count = 1; + String find = "Here is the task that you are looking for in your list:" + "\n"; + for (Task task : tasks) { + if (task.getDescription().contains(toBeFound.trim())) { + String newLine = count + ". " + task.toString() + "\n"; + count += 1; + find += newLine; + } + } + return find; + } + } + + + public boolean isValidTaskNumber(int input) { + if (input > 0 && input < tasks.size()) { + return true; + } else { + return false; + } + } + + /** + * Tags a task in the list. + * + * @param input Input of the user. + * @return Message for the user. + * @throws DukeException If there is an error in the input. + */ + public String tag(String input) throws DukeException { + String tag = input.replaceFirst("tag", ""); + if (tag.trim().isEmpty()) { + throw new DukeException("Yo! The description of your tag cannot be empty."); + } else { + return addTag(tag.trim()); + } + } + + /** + * Adds a tag to a task. + * @param tag Input of user. + * @return Message for user. + */ + public String addTag(String tag) { + char n = tag.charAt(0); + int number = Character.getNumericValue(n) - 1; + assert number >= 0 : "Index should be more or equal to 0"; + Task task = tasks.get(number); + String[] result = tag.split("#", 2); + String desc = result[1]; + task.tagWith(desc); + String line1 = "Got it. I've tagged this task:"; + String line2 = " " + task.toString(); + String line3 = "with #" + desc; + String message = line1 + "\n" + line2 + "\n" + line3; + return message; + } + + /** + * Lists the tags for a task. + * + * @param input Input of user. + * @return Message for user. + * @throws DukeException If there is an error in the input. + */ + public String listTags(String input) throws DukeException { + char n = input.charAt(8); + int number = Character.getNumericValue(n) - 1; + assert number >= 0 : "Index should be more or equal to 0"; + Task task = tasks.get(number); + return task.listTheTags(); + } +} diff --git a/src/main/java/duke/Ui.java b/src/main/java/duke/Ui.java new file mode 100644 index 0000000000..ec29230251 --- /dev/null +++ b/src/main/java/duke/Ui.java @@ -0,0 +1,21 @@ +package duke; + +import java.util.Scanner; + +public class Ui { + + private final Scanner sc; + + + + public Ui() { + this.sc = new Scanner(System.in); + } + + public String printBye() { + return ("Bye. Hope to see you again soon!"); + } + +} + + diff --git a/src/main/java/duke/UnknownCommandException.java b/src/main/java/duke/UnknownCommandException.java new file mode 100644 index 0000000000..9141c45d64 --- /dev/null +++ b/src/main/java/duke/UnknownCommandException.java @@ -0,0 +1,25 @@ +package duke; + +/** + * An exception for when an unknown command is entered with user-facing messages that sound like Drake. + */ +public class UnknownCommandException extends DukeException { + private String message; + + /** + * Constructor with the Drake-sounding exception for an unknown command. + */ + public UnknownCommandException() { + super("Oops! I don't know what that means!"); + } + + + /** + * Returns the message of the exception. + * @return Message of the exception. + */ + @Override + public String toString() { + return 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..40f2c10658 --- /dev/null +++ b/src/main/java/duke/gui/DialogBox.java @@ -0,0 +1,57 @@ +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; + +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/Launcher.java b/src/main/java/duke/gui/Launcher.java new file mode 100644 index 0000000000..f681771829 --- /dev/null +++ b/src/main/java/duke/gui/Launcher.java @@ -0,0 +1,10 @@ +package duke.gui; + +import javafx.application.Application; + +public class Launcher { + + public static void main(String[] args) { + Application.launch(Main.class, args); + } +} diff --git a/src/main/java/duke/gui/Main.java b/src/main/java/duke/gui/Main.java new file mode 100644 index 0000000000..5ba1fd781e --- /dev/null +++ b/src/main/java/duke/gui/Main.java @@ -0,0 +1,36 @@ +package duke.gui; + +import java.io.IOException; +import duke.*; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Scene; +import javafx.scene.layout.AnchorPane; +import javafx.stage.Stage; + +public class Main extends Application { + + private Duke duke = new Duke(); + + + public Main() {} + + + @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("DukeProMax"); + fxmlLoader.getController().setDuke(duke); + fxmlLoader.getController().showWelcome(); + stage.show(); + + } catch (IOException e) { + System.out.println(e.getMessage()); + } + } +} diff --git a/src/main/java/duke/gui/MainWindow.java b/src/main/java/duke/gui/MainWindow.java new file mode 100644 index 0000000000..9f3a7c833b --- /dev/null +++ b/src/main/java/duke/gui/MainWindow.java @@ -0,0 +1,72 @@ +package duke.gui; + +import java.io.IOException; + +import 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; + +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.png")); + private Image dukeImage = new Image(this.getClass().getResourceAsStream("/images/DaDuke.png")); + + + @FXML + public void initialize() { + scrollPane.vvalueProperty().bind(dialogContainer.heightProperty()); + } + + public void setDuke(Duke d) { + duke = d; + } + + + public void showWelcome() { + String logo = "MyDuke"; + String welcome = "Hello from\n" + "DUKEPROMAX!"; + dialogContainer.getChildren().addAll( + DialogBox.getDukeDialog(welcome, dukeImage) + ); + } + + + + + /** + * Creates two dialog boxes, one echoing user input and the other containing duke's reply and then appends them to + * the dialog container. + */ + @FXML + private void handleUserInput() throws DukeException, IOException { + 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/tasks/Deadline.java b/src/main/java/duke/tasks/Deadline.java new file mode 100644 index 0000000000..6adc703ac1 --- /dev/null +++ b/src/main/java/duke/tasks/Deadline.java @@ -0,0 +1,48 @@ +package duke.tasks; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + + + +public class Deadline extends Task { + + protected final LocalDate by; + + public Deadline(String description, LocalDate by) { + super(description); + this.by = by; + } + + public Deadline(String description, boolean isDone, LocalDate by) { + super(description); + this.by = by; + this.isDone = isDone; + } + + /** + * Formats the time to a string. + * + * @param time time of the Deadline. + * @return String notation of the time. + */ + public String formatTime(LocalDate time) { + return time.format(DateTimeFormatter.ofPattern("MMM d yyyy")); + } + + + /** + * Shows the Deadline task description and the date it is due by. + * + * @return String with the Deadline task description and date it is due by. + */ + @Override + public String toString() { + return "[D]" + super.toString() + " (by: " + formatTime(by) + ")"; + } + + @Override + public String saveTask() { + return String.format("D | %s | %s", super.saveTask(), by); + } +} diff --git a/src/main/java/duke/tasks/Event.java b/src/main/java/duke/tasks/Event.java new file mode 100644 index 0000000000..a7522d2540 --- /dev/null +++ b/src/main/java/duke/tasks/Event.java @@ -0,0 +1,41 @@ +package duke.tasks; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +public class Event extends Task { + + protected final LocalDate at; + + public Event(String description, LocalDate at) { + super(description); + this.at = at; + } + + public Event(String description, boolean isDone, LocalDate at) { + super(description); + this.at = at; + this.isDone = isDone; + } + + public String formatTime(LocalDate time) { + return time.format(DateTimeFormatter.ofPattern("MMM d yyyy")); + } + + + /** + * Shows the Event task description and the date it occurs at. + * + * @return String with the Event task description and the date it occurs at. + */ + @Override + public String toString() { + return "[E]" + super.toString() + " (at: " + formatTime(at) + ")"; + } + + @Override + public String saveTask() { + return String.format("E | %s | %s", super.saveTask(), at); + } +} + diff --git a/src/main/java/duke/tasks/Task.java b/src/main/java/duke/tasks/Task.java new file mode 100644 index 0000000000..f149efeea3 --- /dev/null +++ b/src/main/java/duke/tasks/Task.java @@ -0,0 +1,96 @@ +package duke.tasks; + +import java.time.LocalDate; +import java.util.ArrayList; + +public class Task { + protected ArrayList tags; + protected String description; + protected boolean isDone; + + public Task(String description) { + this.description = description; + this.isDone = false; + } + + /** + * Gets the status of the task. + * + * @return The status of the task. + */ + public String getStatusIcon() { + return (isDone ? "X" : " "); // mark done task with X + } + + /** + * Marks task as done. + */ + public void mark() { + this.isDone = true; + } + + /** + * Marks task as not done. + */ + public void markAsNotDone() { + isDone = false; + } + + /** + * Returns the description of the task. + * + * @return Description of the task. + */ + public String getDescription() { + return this.description; + } + + /** + * Loads the task. + * @param data the data to be loaded + * @return Tasks that have been loaded + */ + public static Task loadTask(String data) { + String[] input = data.split( " \\| ", 4); + char c = input[0].charAt(0); + boolean isDone = input[1].equals("1"); + String description = input[2]; + LocalDate time = input.length == 3 ? LocalDate.parse(input[2]) : null; + + if (c == 'D') { + return new Deadline(description, isDone, time); + } else if (c == 'E') { + return new Event(description, isDone, time); + } else { + return new Todo(description, isDone); + } + } + + public void tagWith(String input) { + tags.add(input); + } + + public String listTheTags() { + int count = 1; + String list = "Here are the tags of this task:" + "\n"; + for (String tag : tags) { + String newLine = count + ". " + "#" + tag + "\n"; + list += newLine; + count += 1; + } + return list; + } + + /** + * Saves the task + * @return The string message of the saved task + */ + public String saveTask() { + return String.format("%d | %s", isDone ? 1 : 0, description); + } + + @Override + public String toString() { + return "[" + this.getStatusIcon() + "] " + description; + } +} \ No newline at end of file diff --git a/src/main/java/duke/tasks/Todo.java b/src/main/java/duke/tasks/Todo.java new file mode 100644 index 0000000000..b44499c306 --- /dev/null +++ b/src/main/java/duke/tasks/Todo.java @@ -0,0 +1,29 @@ +package duke.tasks; + + +public class Todo extends Task { + + public Todo(String description) { + super(description); + } + + public Todo(String description, boolean isDone) { + super(description); + this.isDone = isDone; + } + + /** + * Shows the todo task description. + * + * @return String with the todo task description. + */ + @Override + public String toString() { + return "[T]" + super.toString(); + } + + @Override + public String saveTask() { + return String.format("T | %s", super.saveTask()); + } +} diff --git a/src/main/resources/images/DaDuke.png b/src/main/resources/images/DaDuke.png new file mode 100644 index 0000000000..c50fcf9c98 Binary files /dev/null and b/src/main/resources/images/DaDuke.png differ diff --git a/src/main/resources/images/DaUser.png b/src/main/resources/images/DaUser.png new file mode 100644 index 0000000000..90a4f0105b Binary files /dev/null and b/src/main/resources/images/DaUser.png differ diff --git a/src/main/resources/view/DialogBox.fxml b/src/main/resources/view/DialogBox.fxml new file mode 100644 index 0000000000..e433809947 --- /dev/null +++ b/src/main/resources/view/DialogBox.fxml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/view/MainWindow.fxml b/src/main/resources/view/MainWindow.fxml new file mode 100644 index 0000000000..de92974e28 --- /dev/null +++ b/src/main/resources/view/MainWindow.fxml @@ -0,0 +1,19 @@ + + + + + + + + + + + +