diff --git a/.gitignore b/.gitignore index f69985ef1f..d7ced6fa9f 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ bin/ /text-ui-test/ACTUAL.txt text-ui-test/EXPECTED-UNIX.TXT +/data/saveFile.txt \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000000..d03b2948d6 --- /dev/null +++ b/build.gradle @@ -0,0 +1,63 @@ +plugins { + id 'java' + id 'application' + id 'checkstyle' + id 'com.github.johnrengelman.shadow' version '5.1.0' + id 'org.openjfx.javafxplugin' version '0.0.10' +} + +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 = '12' + + 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.Duke" +} + +shadowJar { + archiveBaseName = "duke" + archiveClassifier = null +} + +run{ + standardInput = System.in + enableAssertions = true +} + +checkstyle { + toolVersion = '10.2' +} diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml new file mode 100644 index 0000000000..fb88cedfc2 --- /dev/null +++ b/config/checkstyle/checkstyle.xml @@ -0,0 +1,434 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/config/checkstyle/suppressions.xml b/config/checkstyle/suppressions.xml new file mode 100644 index 0000000000..135ea49ee0 --- /dev/null +++ b/config/checkstyle/suppressions.xml @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index 8077118ebe..5ff74a9d16 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,29 +1,195 @@ # User Guide +## About +Duke is a desktop app designed for task management, optimized for use via +a Command-Line interface (CLI) while still having the benefits of a +Graphical-User Interface (GUI). If you can type fast, Duke is an efficient +program to manage all your tasks. + ## Features +- todo +- deadline +- event +- list +- mark +- unmark +- delete +- find +- bye + +## Adding Tasks + +There are 3 types of tasks that can be added to Duke + +1. Todo +2. Deadline +3. Event + +A task is formatted as follows: + +`[T][ ] TASK_ITEM` + +The first box `[T]` indicates the type of task, while the second `[ ]` indicates whether the task has been marked as completed. + +### `todo` - Adds a Todo task to Duke list +Command format: `todo TODO_ITEM` + +This adds a todo task to Duke list, along with a short note corresponding to `TODO_ITEM`. + +#### Example of Usage: + +Input: +``` +todo sweep the floor +``` + +Output: +``` +Got it. I've added this task: +[T][ ] sweep the floor +Now you have 2 tasks in the list. +``` +### `deadline` - Adds a Deadline task to Duke list +Command format: `deadline DEADLINE_ITEM /by DATE TIME` + +This adds a deadline task to Duke list, that is to be done by `DATE` and at time `TIME`. +Note that `DATE` is of the format `YYYY-MM-DD` and `TIME` is of the format `hh:mm:ss`. + +#### Example of Usage: + +Input: +``` +deadline finish ip /by 2022-09-19 23:59:59 +``` + +Output: +``` +Got it. I've added this task: +[D][ ] finish ip (by: Sep 19 2022 23:59:59) +Now you have 2 tasks in the list. +``` + +### `event` - Adds an Event task to Duke list +Command format: `event EVENT_ITEM /at DATE START_TIME END_TIME` + +This adds an event task to Duke list, that occurs on `DATE` from `START_TIME` to `END_TIME`. + +Note that `DATE` is of the format `YYYY-MM-DD` and both `START_TIME` and `END_TIME` are of the format `hh:mm:ss`. + +#### Example of Usage: + +Input: +``` +event cs2100 midterm /at 2022-10-08 09:00:00 10:30:00 +``` + +Output: +``` +Got it. I've added this task: +[E][ ] finish ip (at: Oct 8 2022 09:00:00 - 10:30:00) +Now you have 2 tasks in the list. +``` -### Feature-ABC +## Managing Tasks +### `list` - List all tasks in Duke list +Command format: `list` -Description of the feature. +Returns a list of all tasks currently in Duke list. -### Feature-XYZ +#### Example of Usage: -Description of the feature. +Input: +``` +list +``` + +Output: +``` +Here are the tasks in your list: +1. [T][ ] sweep the floor +2. [D][ ] finish ip (by: Sep 19 2022 23:59:59) +3. [E][ ] finish ip (at: Oct 8 2022 09:00:00 - 10:30:00) +``` +### `mark` - Marks a specified task as completed +Command format: `mark INDEX` + +Marks the task stored at `INDEX` in Duke list as completed. + +#### Example of Usage: + +Input: +``` +mark 1 +``` + +Output: +``` +Nice! I've marked this task as done: + [T][X] sweep the floor +``` +### `unmark` - Unmarks a specified task as incomeplete +Command format: `unmark INDEX` + +Unmarks the task stored at `INDEX` in Duke list as incomplete. + +#### Example of Usage: + +Input: +``` +unmark 1 +``` -## Usage +Output: +``` +OK, I've marked this task as not done yet: + [T][ ] sweep the floor +``` +### `delete` - Deletes a specified task from Duke list +Command format: `delete INDEX` -### `Keyword` - Describe action +Deletes the task stored at `INDEX` in Duke list. -Describe the action and its outcome. +#### Example of Usage: -Example of usage: +Input: +``` +delete 3 +``` -`keyword (optional arguments)` +Output: +``` +Noted, I've removed this task: + [E][ ] finish ip (at: Oct 8 2022 09:00:00 - 10:30:00) +Now you have 2 tasks in the list. +``` +### `find` - Searches for tasks that match a given string +Command format: `find SEARCH_STRING` -Expected outcome: +Searches for all tasks that match `SEARCH_STRING` -Description of the outcome. +#### Example of Usage: +Input: ``` -expected output +find sweep +``` + +Output: ``` +1. [T][ ] sweep the floor +``` +### `bye` - Exits the application and saves all tasks in Duke list +Command format: `bye` + +Exits the application and saves all tasks currently within Duke list. + +#### Example of Usage: + +Input: +``` +bye +``` + +Output: + +The application terminates and the window closes. \ No newline at end of file diff --git a/docs/Ui.png b/docs/Ui.png new file mode 100644 index 0000000000..227faca266 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/command/AddTaskCommand.java b/src/main/java/command/AddTaskCommand.java new file mode 100644 index 0000000000..56a27df7bc --- /dev/null +++ b/src/main/java/command/AddTaskCommand.java @@ -0,0 +1,44 @@ +package command; + +import task.Task; +import tasklist.TaskList; +import util.Storage; +import util.Ui; + +/** + * Represents a command to be executed that adds a task to the internal duke list. + * + * @author Bryan Lim Jing Xiang + */ +public class AddTaskCommand extends Command { + private final Task taskItem; + + public AddTaskCommand(Task taskItem) { + this.taskItem = taskItem; + } + + /** + * {@inheritDoc} + */ + @Override + public void execute(TaskList list, Storage storage) { + Task task = list.addTask(this.taskItem); + if (task == null) { + setOutputMessage(Ui.formatLinesIntoParagraph( + "This task has already been added to the list previously." + )); + return; + } + assert task != null; + String taskDescription = " " + task.toString(); + String startLine = "Got it. I've added this task:"; + String endLine = String.format( + "Now you have %d tasks in the list.", + list.getTaskCount()); + setOutputMessage(Ui.formatLinesIntoParagraph( + startLine, + taskDescription, + endLine + )); + } +} diff --git a/src/main/java/command/AddTaskFromStorageCommand.java b/src/main/java/command/AddTaskFromStorageCommand.java new file mode 100644 index 0000000000..5987ab4264 --- /dev/null +++ b/src/main/java/command/AddTaskFromStorageCommand.java @@ -0,0 +1,29 @@ +package command; + +import task.Task; +import tasklist.TaskList; +import util.Storage; + +/** + * Represents a command to be executed that adds a task based on input from save file. + * + * @author Bryan Lim Jing Xiang + */ +public class AddTaskFromStorageCommand extends Command { + private final Task taskItem; + + /** + * @param taskItem Task to be added to internal duke list + */ + public AddTaskFromStorageCommand(Task taskItem) { + this.taskItem = taskItem; + } + + /** + * {@inheritDoc} + */ + @Override + public void execute(TaskList list, Storage storage) { + list.addTask(this.taskItem); + } +} diff --git a/src/main/java/command/Command.java b/src/main/java/command/Command.java new file mode 100644 index 0000000000..354ef244c1 --- /dev/null +++ b/src/main/java/command/Command.java @@ -0,0 +1,40 @@ +package command; + +import tasklist.TaskList; +import util.Storage; + +/** + * Represents a command generated from the internal save file or input from the + * command line. + * + * @author Bryan Lim Jing Xiang + */ +public abstract class Command { + private boolean isTerminated = false; + + private String outputMessage = ""; + + /** + * Executes a specific command + * + * @param list Duke list that stores all current tasks + * @param storage Storage that handles all storage related functionalities + */ + public abstract void execute(TaskList list, Storage storage); + + public String getOutputMessage() { + return this.outputMessage; + } + + protected void setOutputMessage(String outputMessage) { + this.outputMessage = outputMessage; + } + + public boolean getIsTerminated() { + return isTerminated; + } + + public void setIsTerminated(boolean isTerminated) { + this.isTerminated = isTerminated; + } +} diff --git a/src/main/java/command/DeleteTaskCommand.java b/src/main/java/command/DeleteTaskCommand.java new file mode 100644 index 0000000000..b125b012d0 --- /dev/null +++ b/src/main/java/command/DeleteTaskCommand.java @@ -0,0 +1,40 @@ +package command; + +import tasklist.TaskList; +import util.Storage; +import util.Ui; + +/** + * Represents a task to be executed that deletes a specific task from internal + * duke list based on given index. + * + * @author Bryan Lim Jing Xiang + */ +public class DeleteTaskCommand extends Command { + private final int index; + + /** + * @param index Index of the element to be deleted within the + * internal duke list + */ + public DeleteTaskCommand(int index) { + this.index = index; + } + + /** + * {@inheritDoc} + */ + @Override + public void execute(TaskList list, Storage storage) { + String deletedItem = " " + list.deleteItem(index); + String deleteText = "Noted. I've removed this task:"; + String endLine = String.format( + "Now you have %d tasks in the list.", + list.getTaskCount()); + setOutputMessage(Ui.formatLinesIntoParagraph( + deleteText, + deletedItem, + endLine + )); + } +} diff --git a/src/main/java/command/FindSearchTextCommand.java b/src/main/java/command/FindSearchTextCommand.java new file mode 100644 index 0000000000..37d098c71e --- /dev/null +++ b/src/main/java/command/FindSearchTextCommand.java @@ -0,0 +1,46 @@ +package command; + +import java.util.ArrayList; + +import tasklist.TaskList; +import util.Storage; +import util.Ui; + +/** + * Represents a task to be executed that searches and returns a task in the internal + * duke list based on search text + * + * @author Bryan Lim Jing Xiang + */ +public class FindSearchTextCommand extends Command { + private final String searchText; + + /** + * @param searchText Searches duke list for any tasks that contains the + * search text + */ + public FindSearchTextCommand(String searchText) { + this.searchText = searchText; + } + + /** + * {@inheritDoc} + */ + @Override + public void execute(TaskList list, Storage storage) { + ArrayList matchedTasks = list.find(searchText); + + if (matchedTasks.size() == 0) { + System.out.println(Ui.formatLinesIntoParagraph( + "Sorry but there is no matching task in the list!" + )); + return; + } + + StringBuilder res = new StringBuilder(); + for (String match : matchedTasks) { + res.append(Ui.formatLine(match)); + } + setOutputMessage(res.toString()); + } +} diff --git a/src/main/java/command/ListAllTasksCommand.java b/src/main/java/command/ListAllTasksCommand.java new file mode 100644 index 0000000000..9714332a34 --- /dev/null +++ b/src/main/java/command/ListAllTasksCommand.java @@ -0,0 +1,22 @@ +package command; + +import tasklist.TaskList; +import util.Storage; + +/** + * Represents a command to be executed that lists all current tasks in the + * internal duke list. + * + * @author Bryan Lim Jing Xiang + */ +public class ListAllTasksCommand extends Command { + /** + * {@inheritDoc} + */ + @Override + public void execute(TaskList list, Storage storage) { + setOutputMessage( + list.toString() + ); + } +} diff --git a/src/main/java/command/MarkTaskCommand.java b/src/main/java/command/MarkTaskCommand.java new file mode 100644 index 0000000000..cb55584298 --- /dev/null +++ b/src/main/java/command/MarkTaskCommand.java @@ -0,0 +1,34 @@ +package command; + +import tasklist.TaskList; +import util.Storage; +import util.Ui; + +/** + * Represents a task to be executed that marks a specific task in the + * internal duke list based on given index + */ +public class MarkTaskCommand extends Command { + private final int index; + + /** + * @param index Index of the element to be marked within the + * internal duke list + */ + public MarkTaskCommand(int index) { + this.index = index; + } + + /** + * {@inheritDoc} + */ + @Override + public void execute(TaskList list, Storage storage) { + String markedItem = " " + list.markItem(index); + String markedText = "Nice! I've marked this task as done:"; + setOutputMessage(Ui.formatLinesIntoParagraph( + markedText, + markedItem + )); + } +} diff --git a/src/main/java/command/TerminateCommand.java b/src/main/java/command/TerminateCommand.java new file mode 100644 index 0000000000..0d79e23515 --- /dev/null +++ b/src/main/java/command/TerminateCommand.java @@ -0,0 +1,20 @@ +package command; + +import tasklist.TaskList; +import util.Storage; + +/** + * Represents a command that to be executed that terminates the program + * + * @author Bryan Lim Jing Xiang + */ +public class TerminateCommand extends Command { + /** + * {@inheritDoc} + */ + @Override + public void execute(TaskList list, Storage storage) { + setIsTerminated(true); + storage.saveAllTasks(list); + } +} diff --git a/src/main/java/command/UnmarkTaskCommand.java b/src/main/java/command/UnmarkTaskCommand.java new file mode 100644 index 0000000000..20caef255d --- /dev/null +++ b/src/main/java/command/UnmarkTaskCommand.java @@ -0,0 +1,36 @@ +package command; + +import tasklist.TaskList; +import util.Storage; +import util.Ui; + +/** + * Represents a task to be executed that unmarks a specific task within the + * internal duke list based on given index + * + * @author Bryan Lim Jing Xiang + */ +public class UnmarkTaskCommand extends Command { + private final int index; + + /** + * @param index Index of the element to be unmarked within the + * internal duke list + */ + public UnmarkTaskCommand(int index) { + this.index = index; + } + + /** + * {@inheritDoc} + */ + @Override + public void execute(TaskList list, Storage storage) { + String unmarkedItem = " " + list.unmarkItem(index); + String unmarkedText = "OK, I've marked this task as not done yet:"; + setOutputMessage(Ui.formatLinesIntoParagraph( + unmarkedText, + unmarkedItem + )); + } +} diff --git a/src/main/java/date/Date.java b/src/main/java/date/Date.java new file mode 100644 index 0000000000..79daa3ae18 --- /dev/null +++ b/src/main/java/date/Date.java @@ -0,0 +1,50 @@ +package date; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; + +/** + * Stores a representation of Date based on ISO-8601 + * + * @author Bryan Lim Jing Xiang + */ +public abstract class Date { + private LocalDate date; + + public Date(String date) throws DateTimeParseException { + this.date = LocalDate.parse(date); + } + + /** + * {@inheritDoc} + * + * @return Date formatted in terms of "month day year", e.g Jan 1 2000 + */ + @Override + public String toString() { + return date.format(DateTimeFormatter.ofPattern("MMM d yyyy")); + } + + /** + * @return A string encoding of the stored date + */ + public String encode() { + return date.toString(); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o instanceof Date) { + Date other = (Date) o; + return other.date.equals(this.date); + } + return false; + } +} diff --git a/src/main/java/date/DeadlineDateTime.java b/src/main/java/date/DeadlineDateTime.java new file mode 100644 index 0000000000..4d3e200e27 --- /dev/null +++ b/src/main/java/date/DeadlineDateTime.java @@ -0,0 +1,93 @@ +package date; + +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; + +import exception.DukeException; + +/** + * Stores a representation of a data and a time based on ISO-8601 + * + * @author Bryan Lim Jing Xiang + */ +public class DeadlineDateTime extends Date { + private LocalTime time; + + private DeadlineDateTime(String date, String time) throws DateTimeParseException { + super(date); + this.time = LocalTime.parse(time); + } + + /** + * Parses a given string and returns an object storing the Date and Time given + * + * @param dateTime A string with a date and time as per ISO-8601 format, + * delimited by a space + * @return DeadlineDateTime object that stores the Date and Time passed in + * @throws DukeException If the dateTime passed in cannot be parsed + */ + public static DeadlineDateTime parseDate(String dateTime) throws DukeException { + String[] splitted = dateTime.split("\\s+", 2); + if (splitted.length < 2 || splitted[0].strip().equals("") || splitted[1].strip().equals("")) { + throw new DukeException(DukeException.ErrorCode.INVALID_DEADLINE_DATETIME_FORMAT); + } + assert splitted.length >= 2 : "Date time not formatted properly"; + try { + return new DeadlineDateTime(splitted[0], splitted[1]); + } catch (DateTimeParseException e) { + throw new DukeException(DukeException.ErrorCode.INVALID_DEADLINE_DATETIME_FORMAT); + } + } + + /** + * Parses date from encoded data in save file + * + * @param storedDateTime An encoding of DeadlineDateTime stored in the save file + * @return DeadlineDateTime object that stores the Date and Time + * @throws DukeException If the storedDateTime cannot be parsed + */ + public static DeadlineDateTime parseDateFromStorage(String storedDateTime) throws DukeException { + String[] dateTime = storedDateTime.split("\\|", 2); + try { + return new DeadlineDateTime(dateTime[0], dateTime[1]); + } catch (DateTimeParseException e) { + throw new DukeException(DukeException.ErrorCode.INVALID_DEADLINE_DATETIME_FORMAT); + } + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + String timeColonPattern = "HH:mm:ss"; + String formattedTime = time.format(DateTimeFormatter.ofPattern(timeColonPattern)); + return super.toString() + ' ' + formattedTime; + } + + /** + * {@inheritDoc} + */ + @Override + public String encode() { + String timeColonPattern = "HH:mm:ss"; + String formattedTime = time.format(DateTimeFormatter.ofPattern(timeColonPattern)); + return super.encode() + '|' + formattedTime; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o instanceof DeadlineDateTime) { + DeadlineDateTime other = (DeadlineDateTime) o; + return super.equals(o) && other.time.equals(this.time); + } + return false; + } +} diff --git a/src/main/java/date/EventDateTime.java b/src/main/java/date/EventDateTime.java new file mode 100644 index 0000000000..4b59869d7f --- /dev/null +++ b/src/main/java/date/EventDateTime.java @@ -0,0 +1,102 @@ +package date; + +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; + +import exception.DukeException; + +/** + * Stores a representation of a data, start time and end time based on ISO-8601 + * + * @author Bryan Lim Jing Xiang + */ +public class EventDateTime extends Date { + private LocalTime startTime; + private LocalTime endTime; + + private EventDateTime(String date, String startTime, String endTime) throws DateTimeParseException { + super(date); + this.startTime = LocalTime.parse(startTime); + this.endTime = LocalTime.parse(endTime); + } + + /** + * Parses a given string and returns an object storing the Date and Time given + * + * @param dateTime A string with a date, start time and end time as per + * ISO-8601 format, delimited by a space + * @return EventDateTime object that stores the Date and Time passed in + * @throws DukeException If the dateTime passed in cannot be parsed + */ + public static EventDateTime parseDate(String dateTime) throws DukeException { + String[] splitted = dateTime.split("\\s+", 3); + if (splitted.length < 3 + || splitted[0].strip().equals("") + || splitted[1].strip().equals("") + || splitted[2].strip().equals("")) { + throw new DukeException(DukeException.ErrorCode.INVALID_EVENT_DATETIME_FORMAT); + } + assert splitted.length >= 3 : "Date time not properly formatted"; + try { + return new EventDateTime(splitted[0], splitted[1], splitted[2]); + } catch (DateTimeParseException e) { + throw new DukeException(DukeException.ErrorCode.INVALID_EVENT_DATETIME_FORMAT); + } + } + + /** + * Parses date from encoded data in save file + * + * @param storedDateTime An encoding of EventDateTime stored in the save file + * @return EventDateTime object that stores the Date and Time + * @throws DukeException If the storedDateTime cannot be parsed + */ + public static EventDateTime parseDateFromStorage(String storedDateTime) throws DukeException { + String[] dateTime = storedDateTime.split("\\|", 3); + try { + return new EventDateTime(dateTime[0], dateTime[1], dateTime[2]); + } catch (DateTimeParseException e) { + throw new DukeException(DukeException.ErrorCode.INVALID_EVENT_DATETIME_FORMAT); + } + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + String timeColonPattern = "HH:mm:ss"; + String formattedStartTime = startTime.format(DateTimeFormatter.ofPattern(timeColonPattern)); + String formattedEndTime = endTime.format(DateTimeFormatter.ofPattern(timeColonPattern)); + return super.toString() + ' ' + formattedStartTime + " - " + formattedEndTime; + } + + /** + * {@inheritDoc} + */ + @Override + public String encode() { + String timeColonPattern = "HH:mm:ss"; + String formattedStartTime = startTime.format(DateTimeFormatter.ofPattern(timeColonPattern)); + String formattedEndTime = endTime.format(DateTimeFormatter.ofPattern(timeColonPattern)); + return super.encode() + '|' + formattedStartTime + '|' + formattedEndTime; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o instanceof EventDateTime) { + EventDateTime other = (EventDateTime) o; + return super.equals(o) + && other.startTime.equals(this.startTime) + && other.endTime.equals(this.endTime); + } + return false; + } +} diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java new file mode 100644 index 0000000000..8cff787d56 --- /dev/null +++ b/src/main/java/duke/Duke.java @@ -0,0 +1,47 @@ +package duke; + +import command.Command; +import exception.DukeException; +import gui.DukeGui; +import javafx.application.Application; +import javafx.application.Platform; +import tasklist.TaskList; +import util.Parser; +import util.Storage; + +/** + * Entry point of the application that initialises and run the app. + * + * @author Bryan Lim Jing Xiang + */ +public class Duke { + private TaskList dukelist = new TaskList(); + private Storage storage; + + /** + * @param filePath File path of the internal save file + */ + public Duke(String filePath) { + storage = Storage.initialize(filePath); + storage.load(dukelist); + } + + public String getResponse(String input) { + try { + Command cmd = Parser.parseInputLine(input); + cmd.execute(dukelist, storage); + if (cmd.getIsTerminated()) { + Platform.exit(); + } + return cmd.getOutputMessage(); + } catch (DukeException e) { + return e.errorMessage(); + } catch (Exception e) { + return e.getMessage(); + } + } + + public static void main(String[] args) { + Application.launch(DukeGui.class, args); + } +} diff --git a/src/main/java/exception/DukeException.java b/src/main/java/exception/DukeException.java new file mode 100644 index 0000000000..53c686adc5 --- /dev/null +++ b/src/main/java/exception/DukeException.java @@ -0,0 +1,60 @@ +package exception; + +/** + * Represents exceptions that occur from Duke operations. Uses an error code + * to represent and differentiate between different types of exception. + * + * @author Bryan Lim Jing Xiang + */ +public class DukeException extends Exception { + private final ErrorCode errorCode; + + /** + * @param errorCode Represents the type of exception that occurred + */ + public DukeException(ErrorCode errorCode) { + this.errorCode = errorCode; + } + + /** + * @return Error message pertaining to the exception + */ + public String errorMessage() { + String errorMsg; + switch (errorCode) { + case UNKNOWN_CMD: + errorMsg = "OOPS!!! I'm sorry, but I don't know what that means :-("; + break; + case MISSING_TODO_ITEM: + errorMsg = "OOPS!!! The description of a todo cannot be empty."; + break; + case UNKNOWN_TASK_ENCODING: + errorMsg = "OOPS!!! Unable to parse one of the saved tasks. This task will be skipped."; + break; + case INVALID_DEADLINE_DATETIME_FORMAT: + String dateFormat = "\t Please ensure date time is of the " + + "following format: yyyy-mm-dd hh:mm:ss"; + errorMsg = "OOPS!!! Unable to parse date time for deadline.\n" + dateFormat; + break; + case INVALID_EVENT_DATETIME_FORMAT: + dateFormat = "\t Please ensure date time is of the " + + "following format: yyyy-mm-dd hh:mm:ss hh:mm:ss"; + errorMsg = "OOPS!!! Unable to parse date time for event.\n" + dateFormat; + break; + default: + errorMsg = "OOPS!!! Unknown duke error occurred. :-("; + } + return errorMsg; + } + + /** + * A representation of possible exceptions that occur from Duke operations + */ + public enum ErrorCode { + UNKNOWN_CMD, + MISSING_TODO_ITEM, + UNKNOWN_TASK_ENCODING, + INVALID_DEADLINE_DATETIME_FORMAT, + INVALID_EVENT_DATETIME_FORMAT + } +} diff --git a/src/main/java/gui/DialogBox.java b/src/main/java/gui/DialogBox.java new file mode 100644 index 0000000000..bb6ab3f310 --- /dev/null +++ b/src/main/java/gui/DialogBox.java @@ -0,0 +1,68 @@ +package gui; + +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.geometry.Pos; +import javafx.scene.Node; +import javafx.scene.control.Label; +import javafx.scene.image.ImageView; +import javafx.scene.layout.HBox; + +/** + * DialogBox serves as the layout where the user interacts with the Duke + * + * @author Bryan Lim Jing Xiang + */ +public class DialogBox extends HBox { + + private Label text; + private ImageView displayPicture; + + /** + * @param l Label or text to be displayed + * @param iv Avatar of the current speaker + */ + public DialogBox(Label l, ImageView iv) { + text = l; + displayPicture = iv; + + text.setWrapText(true); + displayPicture.setFitWidth(100.0); + displayPicture.setFitHeight(100.0); + + l.setAlignment(Pos.BASELINE_LEFT); + + this.setAlignment(Pos.TOP_RIGHT); + this.getChildren().addAll(text, displayPicture); + } + + /** + * Flips the dialog box such that the ImageView is on the left and text on the right. + */ + private void flip() { + this.setAlignment(Pos.TOP_LEFT); + ObservableList tmp = FXCollections.observableArrayList(this.getChildren()); + FXCollections.reverse(tmp); + this.getChildren().setAll(tmp); + } + + /** + * @param l Command or text entered by user + * @param iv Avatar of the user + * @return A dialog box for the user + */ + public static DialogBox getUserDialog(Label l, ImageView iv) { + return new DialogBox(l, iv); + } + + /** + * @param l Response returned by Duke + * @param iv Avatar of Duke + * @return A dialog box for Duke + */ + public static DialogBox getDukeDialog(Label l, ImageView iv) { + var db = new DialogBox(l, iv); + db.flip(); + return db; + } +} diff --git a/src/main/java/gui/DukeGui.java b/src/main/java/gui/DukeGui.java new file mode 100644 index 0000000000..4d40ca38ad --- /dev/null +++ b/src/main/java/gui/DukeGui.java @@ -0,0 +1,109 @@ +package gui; + +import duke.Duke; +import javafx.application.Application; +import javafx.scene.Scene; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.control.ScrollPane; +import javafx.scene.control.TextField; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.Region; +import javafx.scene.layout.VBox; +import javafx.stage.Stage; +import util.Ui; + +/** + * Handles the main logic for the graphical user interface for Duke + * + * @author Bryan Lim Jing Xiang + */ +public class DukeGui extends Application { + private final Duke dukeApp = new Duke("data/saveFile.txt"); + + private Image user = new Image(this.getClass().getResourceAsStream("/images/DaUser.png")); + private Image duke = new Image(this.getClass().getResourceAsStream("/images/DaDuke.png")); + + private ScrollPane scrollPane; + private VBox dialogContainer; + private TextField userInput; + private Button sendButton; + private Scene scene; + + /** + * {@inheritDoc} + */ + @Override + public void start(Stage stage) { + scrollPane = new ScrollPane(); + dialogContainer = new VBox(); + scrollPane.setContent(dialogContainer); + + displayIntroMessage(); + + userInput = new TextField(); + sendButton = new Button("Send"); + + AnchorPane mainLayout = new AnchorPane(); + mainLayout.getChildren().addAll(scrollPane, userInput, sendButton); + + scene = new Scene(mainLayout); + + stage.setScene(scene); + stage.show(); + + stage.setTitle("Duke"); + stage.setResizable(false); + stage.setMinHeight(600.0); + stage.setMinWidth(400.0); + + mainLayout.setPrefSize(400.0, 600.0); + + scrollPane.setPrefSize(385, 535); + scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); + scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS); + + scrollPane.setVvalue(1.0); + scrollPane.setFitToWidth(true); + + dialogContainer.setPrefHeight(Region.USE_COMPUTED_SIZE); + + userInput.setPrefWidth(325.0); + + sendButton.setPrefWidth(55.0); + + AnchorPane.setTopAnchor(scrollPane, 1.0); + + AnchorPane.setBottomAnchor(sendButton, 1.0); + AnchorPane.setRightAnchor(sendButton, 1.0); + + AnchorPane.setLeftAnchor(userInput , 1.0); + AnchorPane.setBottomAnchor(userInput, 1.0); + + sendButton.setOnMouseClicked((event) -> { + handleUserInput(); + }); + + userInput.setOnAction((event) -> { + handleUserInput(); + }); + } + + private void handleUserInput() { + String dukeResponse = dukeApp.getResponse(userInput.getText()); + Label userText = new Label(userInput.getText()); + Label dukeText = new Label(dukeResponse); + dialogContainer.getChildren().addAll( + DialogBox.getUserDialog(userText, new ImageView(user)), + DialogBox.getDukeDialog(dukeText, new ImageView(duke)) + ); + userInput.clear(); + } + + private void displayIntroMessage() { + Label introText = new Label(Ui.getIntroMessage()); + dialogContainer.getChildren().add(DialogBox.getDukeDialog(introText, new ImageView(duke))); + } +} diff --git a/src/main/java/task/Deadline.java b/src/main/java/task/Deadline.java new file mode 100644 index 0000000000..616bc7406a --- /dev/null +++ b/src/main/java/task/Deadline.java @@ -0,0 +1,55 @@ +package task; + +import date.DeadlineDateTime; + +/** + * Represents a task with a deadline + * + * @author Bryan Lim Jing Xiang + */ +public class Deadline extends Task { + private final DeadlineDateTime deadline; + + /** + * {@inheritDoc} + * + * @param deadline Deadline of the task + */ + public Deadline(String taskItem, DeadlineDateTime deadline) { + super(taskItem); + this.deadline = deadline; + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + String deadlineDisplay = String.format(" (by: %s)", this.deadline); + return "[D]" + super.toString() + deadlineDisplay; + } + + /** + * {@inheritDoc} + */ + @Override + public String encode() { + int markedStatus = getIsMarked() ? 1 : 0; + return String.format("D,%d,%s,%s\n", markedStatus, getTaskItem(), deadline.encode()); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o instanceof Deadline) { + Deadline other = (Deadline) o; + return super.equals(o) && other.deadline.equals(this.deadline); + } + return false; + } +} diff --git a/src/main/java/task/Event.java b/src/main/java/task/Event.java new file mode 100644 index 0000000000..31abe8884e --- /dev/null +++ b/src/main/java/task/Event.java @@ -0,0 +1,55 @@ +package task; + +import date.EventDateTime; + +/** + * Represents an event task + * + * @author Bryan Lim Jing Xiang + */ +public class Event extends Task { + private final EventDateTime eventTiming; + + /** + * {@inheritDoc} + * + * @param eventTiming Date and time of the event + */ + public Event(String taskItem, EventDateTime eventTiming) { + super(taskItem); + this.eventTiming = eventTiming; + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + String eventTimingDisplay = String.format(" (at: %s)", this.eventTiming); + return "[E]" + super.toString() + eventTimingDisplay; + } + + /** + * {@inheritDoc} + */ + @Override + public String encode() { + int markedStatus = getIsMarked() ? 1 : 0; + return String.format("E,%d,%s,%s\n", markedStatus, getTaskItem(), eventTiming.encode()); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o instanceof Event) { + Event other = (Event) o; + return super.equals(o) && other.eventTiming.equals(this.eventTiming); + } + return false; + } +} diff --git a/src/main/java/task/Task.java b/src/main/java/task/Task.java new file mode 100644 index 0000000000..5ac79b03d1 --- /dev/null +++ b/src/main/java/task/Task.java @@ -0,0 +1,62 @@ +package task; + +/** + * Represents the tasks that are stored within the internal duke list + * + * @author Bryan Lim Jing Xiang + */ +public abstract class Task { + private final String taskItem; + private boolean isMarked; + + /** + * @param taskItem Task to be stored + */ + public Task(String taskItem) { + this.taskItem = taskItem; + this.isMarked = false; + } + + /** + * {@inheritDoc} + * + * @return String representation of the task including its markStatus and type + */ + @Override + public String toString() { + String checkbox = isMarked ? "[X] " : "[ ] "; + return checkbox + this.taskItem; + } + + public void setIsMarked(boolean status) { + isMarked = status; + } + + protected boolean getIsMarked() { + return isMarked; + } + + protected String getTaskItem() { + return taskItem; + } + + /** + * @return A string encoding of the task to be stored in the save file + */ + public abstract String encode(); + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o instanceof Task) { + Task other = (Task) o; + return other.taskItem.strip().equals(this.taskItem.strip()); + } + return false; + } +} diff --git a/src/main/java/task/Todo.java b/src/main/java/task/Todo.java new file mode 100644 index 0000000000..048f4f5ae2 --- /dev/null +++ b/src/main/java/task/Todo.java @@ -0,0 +1,61 @@ +package task; + +import exception.DukeException; + +/** + * Represents a task to be done + * + * @author Bryan Lim Jing Xiang + */ +public class Todo extends Task { + /** + * {@inheritDoc} + */ + public Todo(String taskItem) { + super(taskItem); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return "[T]" + super.toString(); + } + + /** + * Validates the input line that represents a command + * to create a Todo object. + * + * @param input Input command to create a Todo + * @throws DukeException If input is invalid + */ + public static void validateInput(String[] input) throws DukeException { + if (input.length < 2 || input[1].strip().equals("")) { + throw new DukeException(DukeException.ErrorCode.MISSING_TODO_ITEM); + } + } + + /** + * {@inheritDoc} + */ + @Override + public String encode() { + int markedStatus = getIsMarked() ? 1 : 0; + return String.format("T,%d,%s\n", markedStatus, getTaskItem()); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o instanceof Todo) { + return super.equals(o); + } + return false; + } +} diff --git a/src/main/java/tasklist/TaskList.java b/src/main/java/tasklist/TaskList.java new file mode 100644 index 0000000000..e970ef5b10 --- /dev/null +++ b/src/main/java/tasklist/TaskList.java @@ -0,0 +1,111 @@ +package tasklist; + +import java.util.ArrayList; + +import task.Task; +import util.Ui; + +/** + * A list that that handles the storing of tasks + * + * @author Bryan Lim Jing Xiang + */ +public class TaskList { + private final ArrayList list = new ArrayList<>(); + + /** + * Adds a given task item to the list + * + * @param taskItem Task to be added + * @return The same task that is passed in + */ + public Task addTask(Task taskItem) { + if (this.list.contains(taskItem)) { + return null; + } + this.list.add(taskItem); + return taskItem; + } + + /** + * {@inheritDoc} + * + * @return A string representation of all tasks within the list + * formatted properly to be printed out as output + */ + @Override + public String toString() { + StringBuilder res = new StringBuilder(Ui.formatLine("Here are the tasks in your list:")); + for (int i = 0; i < this.list.size(); i++) { + String nextListItem = String.format("%d.%s", i + 1, this.list.get(i)); + res.append(Ui.formatLine(nextListItem)); + } + return res.toString(); + } + + /** + * @param index Index of the task to be marked, based on 1-index + * @return Task that is marked + */ + public Task markItem(int index) { + Task taskItem = this.list.get(index - 1); + taskItem.setIsMarked(true); + return taskItem; + } + + /** + * @param index Index of the task to be unmarked, based on 1-index + * @return Task that is unmarked + */ + public Task unmarkItem(int index) { + Task taskItem = this.list.get(index - 1); + taskItem.setIsMarked(false); + return taskItem; + } + + /** + * @param index Index of the task to be removed from list, based on 1-index + * @return Task that is deleted + */ + public Task deleteItem(int index) { + Task taskItem = this.list.get(index - 1); + this.list.remove(index - 1); + return taskItem; + } + + /** + * @param index Index of the task to be retrieved, based on 1-index + * @return Task that is retrieved + */ + public Task getItem(int index) { + return this.list.get(index - 1); + } + + /** + * @return Number of tasks within the list currently + */ + public int getTaskCount() { + return this.list.size(); + } + + /** + * @param searchText Text to be searched + * @return A list of tasks that matches the searchText + */ + public ArrayList find(String searchText) { + ArrayList res = new ArrayList<>(); + + if (searchText.strip().equals("")) { + return res; + } + + for (int i = 0; i < list.size(); i++) { + Task t = list.get(i); + if (t.toString().contains(searchText)) { + String searchedResult = String.format("%d.%s", i + 1, t.toString()); + res.add(searchedResult); + } + } + return res; + } +} diff --git a/src/main/java/util/Parser.java b/src/main/java/util/Parser.java new file mode 100644 index 0000000000..e308f7bf27 --- /dev/null +++ b/src/main/java/util/Parser.java @@ -0,0 +1,120 @@ +package util; + +import command.AddTaskCommand; +import command.AddTaskFromStorageCommand; +import command.Command; +import command.DeleteTaskCommand; +import command.FindSearchTextCommand; +import command.ListAllTasksCommand; +import command.MarkTaskCommand; +import command.TerminateCommand; +import command.UnmarkTaskCommand; +import date.DeadlineDateTime; +import date.EventDateTime; +import exception.DukeException; +import task.Deadline; +import task.Event; +import task.Task; +import task.Todo; + +/** + * Parses all input lines from command line or save file and generates commands + * to be executed + * + * @author Bryan Lim Jing Xiang + */ +public class Parser { + /** + * Parses a single line of input from the command line + * + * @param inputLine Input from the command line containing a command + * and its arguments + * @return A command to be executed + * @throws DukeException If inputLine cannot be parsed successfully + */ + public static Command parseInputLine(String inputLine) throws DukeException { + String[] splitted = inputLine.split("\\s+", 2); + String command = splitted[0]; + Command cmd; + switch (command) { + case "bye": + cmd = new TerminateCommand(); + break; + case "list": + cmd = new ListAllTasksCommand(); + break; + case "mark": + int index = Integer.parseInt(splitted[1]); + cmd = new MarkTaskCommand(index); + break; + case "unmark": + index = Integer.parseInt(splitted[1]); + cmd = new UnmarkTaskCommand(index); + break; + case "delete": + index = Integer.parseInt(splitted[1]); + cmd = new DeleteTaskCommand(index); + break; + case "todo": + Todo.validateInput(splitted); + assert splitted.length >= 2 : "No of arguments should be more than 1."; + Task todo = new Todo(splitted[1]); + cmd = new AddTaskCommand(todo); + break; + case "deadline": + // Regex "\\s+/" matches one or more space followed by a /by, + // followed by one or more space + String[] taskArgs = splitted[1].split("\\s+/by\\s+", 2); + DeadlineDateTime deadlineDateTime = DeadlineDateTime.parseDate(taskArgs[1]); + Task deadline = new Deadline(taskArgs[0], deadlineDateTime); + cmd = new AddTaskCommand(deadline); + break; + case "event": + // Regex "\s+/at\s+" matches one or more space followed by a /at, + // followed by one or more space + taskArgs = splitted[1].split("\\s+/at\\s+", 2); + EventDateTime eventDateTime = EventDateTime.parseDate(taskArgs[1]); + Task event = new Event(taskArgs[0], eventDateTime); + cmd = new AddTaskCommand(event); + break; + case "find": + String searchText = splitted[1]; + cmd = new FindSearchTextCommand(searchText); + break; + default: + throw new DukeException(DukeException.ErrorCode.UNKNOWN_CMD); + } + return cmd; + } + + /** + * Parses a single line of input from the save file + * + * @param encodedTask Encoding from a task saved in the save file + * @return A command to be executed + * @throws DukeException If encoded task cannot be parsed successfully + */ + public static Command parseEncodedTask(String encodedTask) throws DukeException { + String[] splitted = encodedTask.split(",", 4); + String taskType = splitted[0]; + Task taskItem; + + switch (taskType) { + case "T": + taskItem = new Todo(splitted[2]); + break; + case "E": + EventDateTime eventDateTime = EventDateTime.parseDateFromStorage(splitted[3]); + taskItem = new Event(splitted[2], eventDateTime); + break; + case "D": + DeadlineDateTime deadlineDateTime = DeadlineDateTime.parseDateFromStorage(splitted[3]); + taskItem = new Deadline(splitted[2], deadlineDateTime); + break; + default: + throw new DukeException(DukeException.ErrorCode.UNKNOWN_TASK_ENCODING); + } + taskItem.setIsMarked(splitted[1].equals("1")); + return new AddTaskFromStorageCommand(taskItem); + } +} diff --git a/src/main/java/util/Storage.java b/src/main/java/util/Storage.java new file mode 100644 index 0000000000..f713d2e25d --- /dev/null +++ b/src/main/java/util/Storage.java @@ -0,0 +1,85 @@ +package util; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +import command.Command; +import exception.DukeException; +import task.Task; +import tasklist.TaskList; + +/** + * Handles the any storage related functionality related to the save file + * + * @author Bryan Lim Jing Xiang + */ +public class Storage { + private final File saveFile; + + private Storage(File saveFile) { + this.saveFile = saveFile; + } + + /** + * Initialises the save file, creates one if needed + * + * @param storagePathName Relative path of the save file + * @return Storage object that handles operations to the save file + */ + public static Storage initialize(String storagePathName) { + File saveFile = new File(storagePathName); + try { + saveFile.getParentFile().mkdirs(); + if (saveFile.createNewFile()) { + Ui.formatLinesIntoParagraph("Successfully created save file for storage!"); + } + } catch (IOException e) { + String errorMsg = "☹ OOPS!!! Error opening/creating saved storage."; + System.out.println(Ui.formatLinesIntoParagraph(errorMsg)); + } + + return new Storage(saveFile); + } + + /** + * Loads and stores all saved tasks into the current duke list + * + * @param list Duke list of the current running instance of the app + */ + public void load(TaskList list) { + try (Scanner sc = new Scanner(this.saveFile)) { + while (sc.hasNext()) { + try { + Command cmd = Parser.parseEncodedTask(sc.nextLine()); + cmd.execute(list, this); + } catch (DukeException e) { + System.out.println(Ui.formatLinesIntoParagraph(e.errorMessage())); + } + } + String successMsg = "Successfully loaded tasks from saved storage!"; + System.out.println(Ui.formatLinesIntoParagraph(successMsg)); + } catch (FileNotFoundException e) { + System.out.println(Ui.formatLinesIntoParagraph(e.getMessage())); + } + } + + /** + * Saves all tasks from the current duke list into the save file + * + * @param list Duke list of the current running instance of the app + */ + public void saveAllTasks(TaskList list) { + try (FileWriter fileWriter = new FileWriter(this.saveFile, false)) { + for (int i = 1; i <= list.getTaskCount(); i++) { + Task task = list.getItem(i); + String encodedTask = task.encode(); + fileWriter.write(encodedTask); + } + } catch (IOException e) { + System.out.println(Ui.formatLinesIntoParagraph(e.getMessage())); + } + } +} diff --git a/src/main/java/util/Ui.java b/src/main/java/util/Ui.java new file mode 100644 index 0000000000..062d063950 --- /dev/null +++ b/src/main/java/util/Ui.java @@ -0,0 +1,54 @@ +package util; + +/** + * A collection of all Ui related utilities + * + * @author Bryan Lim Jing Xiang + */ +public class Ui { + /** + * Formats a single line of text + * + * @param input String to be formatted + * @return Formatted string to be printed + */ + public static String formatLine(String input) { + return input + "\n"; + } + + /** + * Adds Ui elements to prettify a block or paragraph of text + * + * @param paragraph Paragraph of formatted text to be prettified + * @return Prettified block of text to be printed + */ + public static String formatParagraph(String paragraph) { + String divider = "\t____________________________________________________________\n"; + return divider + paragraph + divider; + } + + /** + * Formats and prettifies lines of text to be printed + * + * @param lines Lines of text to be formatted and prettified + * @return Prettified block of text to be printed + */ + public static String formatLinesIntoParagraph(String... lines) { + StringBuilder res = new StringBuilder(); + for (String line : lines) { + res.append(formatLine(line)); + } + + return res.toString(); + } + + /** + * Prints the introduction message when starting the app + */ + public static String getIntroMessage() { + String introParagraph = Ui.formatLine("Hello! I'm duke.") + + Ui.formatLine("What can I do for you?"); + + return introParagraph; + } +} diff --git a/src/main/resources/images/DaDuke.png b/src/main/resources/images/DaDuke.png new file mode 100644 index 0000000000..d893658717 Binary files /dev/null and b/src/main/resources/images/DaDuke.png differ diff --git a/src/main/resources/images/DaUser.png b/src/main/resources/images/DaUser.png new file mode 100644 index 0000000000..3c82f45461 Binary files /dev/null and b/src/main/resources/images/DaUser.png differ diff --git a/src/test/java/task/DeadlineTest.java b/src/test/java/task/DeadlineTest.java new file mode 100644 index 0000000000..b5ca882876 --- /dev/null +++ b/src/test/java/task/DeadlineTest.java @@ -0,0 +1,40 @@ +package task; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import date.DeadlineDateTime; +import exception.DukeException; + +class DeadlineTest { + + @Test + @DisplayName("Test for toString() method of unmarked deadline") + void test_unmarked_deadline() throws DukeException { + DeadlineDateTime date = DeadlineDateTime.parseDate("2022-01-01 00:00:00"); + Deadline test = new Deadline("Testing!", date); + String expected = "[D][ ] Testing! (by: Jan 1 2022 00:00:00)"; + assertEquals(expected, test.toString()); + } + + @Test + @DisplayName("Test for toString() method of marked deadline") + void test_marked_deadline() throws DukeException { + DeadlineDateTime date = DeadlineDateTime.parseDate("2022-01-01 00:00:00"); + Deadline test = new Deadline("Testing!", date); + test.setIsMarked(true); + String expected = "[D][X] Testing! (by: Jan 1 2022 00:00:00)"; + assertEquals(expected, test.toString()); + } + + @Test + @DisplayName("Test for encode() method of deadline") + void encode() throws DukeException { + DeadlineDateTime date = DeadlineDateTime.parseDate("2022-01-01 00:00:00"); + Deadline test = new Deadline("Testing!", date); + String expected = "D,0,Testing!,2022-01-01|00:00:00\n"; + assertEquals(expected, test.encode()); + } +} diff --git a/src/test/java/task/EventTest.java b/src/test/java/task/EventTest.java new file mode 100644 index 0000000000..9f13aa8023 --- /dev/null +++ b/src/test/java/task/EventTest.java @@ -0,0 +1,40 @@ +package task; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import date.EventDateTime; +import exception.DukeException; + +class EventTest { + + @Test + @DisplayName("Test for toString() method of unmarked event") + void test_unmarked_event() throws DukeException { + EventDateTime date = EventDateTime.parseDate("2022-01-01 00:00:00 12:00:00"); + Event test = new Event("Testing!", date); + String expected = "[E][ ] Testing! (at: Jan 1 2022 00:00:00 - 12:00:00)"; + assertEquals(expected, test.toString()); + } + + @Test + @DisplayName("Test for toString() method of marked event") + void test_marked_event() throws DukeException { + EventDateTime date = EventDateTime.parseDate("2022-01-01 00:00:00 12:00:00"); + Event test = new Event("Testing!", date); + test.setIsMarked(true); + String expected = "[E][X] Testing! (at: Jan 1 2022 00:00:00 - 12:00:00)"; + assertEquals(expected, test.toString()); + } + + @Test + @DisplayName("Test for encode() method of event") + void encode() throws DukeException { + EventDateTime date = EventDateTime.parseDate("2022-01-01 00:00:00 12:00:00"); + Event test = new Event("Testing!", date); + String expected = "E,0,Testing!,2022-01-01|00:00:00|12:00:00\n"; + assertEquals(expected, test.encode()); + } +} diff --git a/src/test/java/task/TodoTest.java b/src/test/java/task/TodoTest.java new file mode 100644 index 0000000000..0dfc3aa013 --- /dev/null +++ b/src/test/java/task/TodoTest.java @@ -0,0 +1,56 @@ +package task; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import exception.DukeException; + +class TodoTest { + + @Test + @DisplayName("Test for toString() method of unmarked todo") + void test_unmarked_todo() { + Todo test = new Todo("Testing!"); + String expected = "[T][ ] Testing!"; + assertEquals(expected, test.toString()); + } + + @Test + @DisplayName("Test validateInput throws exception when task item is not given") + void validateInput_throws_exception() { + String[] inputLengthLessThanOne = new String[] {"Testing!"}; + assertThrows( + DukeException.class, () -> Todo.validateInput(inputLengthLessThanOne)); + } + + @Test + @DisplayName("Test validateInput throws exception when task item is whitespace") + void validateInput_throws_exception2() { + String[] secondStringIsWhitespace = new String[] { + "Testing!", + " ", + }; + assertThrows( + DukeException.class, () -> Todo.validateInput(secondStringIsWhitespace)); + } + + @Test + @DisplayName("Test for encode() method of unmarked todo") + void encode_unmarked_todo() { + Todo test = new Todo("Testing!"); + String expected = "T,0,Testing!\n"; + assertEquals(expected, test.encode()); + } + + @Test + @DisplayName("Test for encode() method of marked todo") + void encode_marked_todo() { + Todo test = new Todo("Testing!"); + test.setIsMarked(true); + String expected = "T,1,Testing!\n"; + assertEquals(expected, test.encode()); + } +} diff --git a/src/test/java/task/stub/MarkedTaskStub.java b/src/test/java/task/stub/MarkedTaskStub.java new file mode 100644 index 0000000000..18d33adc25 --- /dev/null +++ b/src/test/java/task/stub/MarkedTaskStub.java @@ -0,0 +1,23 @@ +package task.stub; + +/** + * A task stub that is marked + * + * @author Bryan Lim Jing Xiang + */ +public class MarkedTaskStub extends TaskStub { + @Override + protected boolean getIsMarked() { + return true; + } + + /** + * Overrides the Task encoding to always return a marked task's encoding + * + * @return Encoding of a marked Task stub + */ + @Override + public String encode() { + return "[X] " + this.getTaskItem(); + } +} diff --git a/src/test/java/task/stub/TaskStub.java b/src/test/java/task/stub/TaskStub.java new file mode 100644 index 0000000000..1b3fa690e5 --- /dev/null +++ b/src/test/java/task/stub/TaskStub.java @@ -0,0 +1,47 @@ +package task.stub; + +import task.Task; + +/** + * A stub for the Task class + * + * @author Bryan Lim Jing Xiang + */ +public class TaskStub extends Task { + public TaskStub() { + super("Testing!"); + } + + /** + * {@inheritDoc} + */ + @Override + public String encode() { + return this.toString(); + } + + /** + * {@inheritDoc} + * Compares two stubs for equality for testing convenience + */ + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + + if (o instanceof TaskStub) { + return this.getIsMarked() == ((TaskStub) o).getIsMarked(); + } + + return false; + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return "Testing!"; + } +} diff --git a/src/test/java/task/stub/UnmarkedTaskStub.java b/src/test/java/task/stub/UnmarkedTaskStub.java new file mode 100644 index 0000000000..867766dba1 --- /dev/null +++ b/src/test/java/task/stub/UnmarkedTaskStub.java @@ -0,0 +1,23 @@ +package task.stub; + +/** + * A task stub that is unmarked + * + * @author Bryan Lim Jing Xiang + */ +public class UnmarkedTaskStub extends TaskStub { + @Override + protected boolean getIsMarked() { + return false; + } + + /** + * Overrides the Task encoding to always return a unmarked task's encoding + * + * @return Encoding of an unmarked Task stub + */ + @Override + public String encode() { + return "[ ] " + this.getTaskItem(); + } +} diff --git a/src/test/java/tasklist/TaskListTest.java b/src/test/java/tasklist/TaskListTest.java new file mode 100644 index 0000000000..9a49292388 --- /dev/null +++ b/src/test/java/tasklist/TaskListTest.java @@ -0,0 +1,101 @@ +package tasklist; + +import static org.junit.jupiter.api.Assertions.assertAll; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import task.Task; +import task.stub.MarkedTaskStub; +import task.stub.TaskStub; +import task.stub.UnmarkedTaskStub; + +class TaskListTest { + + @Test + @DisplayName("Testing addTask()") + void addTask() { + TaskList test = new TaskList(); + Task stub = new TaskStub(); + Task returnedStub = test.addTask(stub); + assertAll(() -> assertSame(returnedStub, stub), () -> assertSame(stub, test.getItem(1)) + ); + } + + @Test + @DisplayName("Testing toString() when list is empty") + void test_empty_list() { + TaskList test = new TaskList(); + String expected = "Here are the tasks in your list:" + "\n"; + assertEquals(expected, test.toString()); + } + + @Test + @DisplayName("Testing toString() when list is not empty") + void test_nonempty_list() { + TaskList test = new TaskList(); + Task stub = new TaskStub(); + test.addTask(stub); + + String taskItemString = String.format("1.%s\n", stub.toString()); + String expected = "Here are the tasks in your list:" + "\n" + + taskItemString; + assertEquals(expected, test.toString()); + } + + @Test + @DisplayName("Testing markItem()") + void markItem() { + TaskList test = new TaskList(); + Task stub = new TaskStub(); + test.addTask(stub); + Task markedStub = test.markItem(1); + + Task expectedStub = new MarkedTaskStub(); + expectedStub.setIsMarked(true); + + assertEquals(expectedStub, markedStub); + } + + @Test + @DisplayName("Testing unmarkItem()") + void unmarkItem() { + TaskList test = new TaskList(); + Task stub = new TaskStub(); + test.addTask(stub); + test.markItem(1); + Task actualStub = test.unmarkItem(1); + Task expectedStub = new UnmarkedTaskStub(); + assertEquals(actualStub, expectedStub); + } + + @Test + @DisplayName("Testing deleteItem()") + void deleteItem_resulting_emptyList() { + TaskList test = new TaskList(); + Task stub = new TaskStub(); + test.addTask(stub); + test.deleteItem(1); + + String expected = "Here are the tasks in your list:" + "\n"; + assertEquals(expected, test.toString()); + } + + @Test + @DisplayName("Testing getTaskCount() when list is empty") + void getTaskCount_empty_list() { + TaskList test = new TaskList(); + assertEquals(test.getTaskCount(), 0); + } + + @Test + @DisplayName("Testing getTaskCount() when list has one task") + void getTaskCount_nonempty_list() { + TaskList test = new TaskList(); + Task stub = new TaskStub(); + test.addTask(stub); + assertEquals(test.getTaskCount(), 1); + } +} diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 657e74f6e7..0b90c575b3 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,7 +1,49 @@ -Hello from - ____ _ -| _ \ _ _| | _____ -| | | | | | | |/ / _ \ -| |_| | |_| | < __/ -|____/ \__,_|_|\_\___| + ____________________________________________________________ + Hello! I'm Duke + What can I do for you? + ____________________________________________________________ + + ____________________________________________________________ + Got it. I've added this task: + [T][ ] borrow book + Now you have 1 tasks in the list. + ____________________________________________________________ + + ____________________________________________________________ + Got it. I've added this task: + [D][ ] return book (by: by Sunday) + Now you have 2 tasks in the list. + ____________________________________________________________ + + ____________________________________________________________ + Got it. I've added this task: + [D][ ] project meeting (at: at Mon 2-4pm) + Now you have 3 tasks in the list. + ____________________________________________________________ + + ____________________________________________________________ + Nice! I've marked this task as done: + [T][X] borrow book + ____________________________________________________________ + + ____________________________________________________________ + Nice! I've marked this task as done: + [D][X] return book (by: by Sunday) + ____________________________________________________________ + + ____________________________________________________________ + OK, I've marked this task as not done yet: + [T][ ] borrow book + ____________________________________________________________ + + ____________________________________________________________ + Here are the tasks in your list: + 1.[T][ ] borrow book + 2.[D][X] return book (by: by Sunday) + 3.[D][ ] project meeting (at: at Mon 2-4pm) + ____________________________________________________________ + + ____________________________________________________________ + Bye. Hope to see you again soon! + ____________________________________________________________ diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index e69de29bb2..7ca60fcd68 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -0,0 +1,8 @@ +todo borrow book +deadline return book /by Sunday +event project meeting /at Mon 2-4pm +mark 1 +mark 2 +unmark 1 +list +bye diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 0873744649..0c79b0b7c6 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -19,3 +19,5 @@ java -classpath ..\bin Duke < input.txt > ACTUAL.TXT REM compare the output to the expected output FC ACTUAL.TXT EXPECTED.TXT + +pause \ No newline at end of file diff --git a/text-ui-test/runtest.sh b/text-ui-test/runtest.sh old mode 100644 new mode 100755