diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000000..bae8d3c7fe --- /dev/null +++ b/build.gradle @@ -0,0 +1,57 @@ +plugins { + id 'java' + id 'application' + id 'checkstyle' + id 'com.github.johnrengelman.shadow' version '5.1.0' +} + +checkstyle { + toolVersion = '8.23' +} + +shadowJar { + archiveBaseName = "duke" + archiveVersion = "0.2" + archiveClassifier = null + archiveAppendix = null +} + +group 'duke' +version '0.1.0' + +repositories { + mavenCentral() +} + +application { + // Change this to your main class. + mainClassName = "Duke" +} + +run { + standardInput = System.in +} + +dependencies { + String javaFxVersion = '11.0.1' + 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' + + testImplementation 'org.junit.jupiter:junit-jupiter:5.5.0' +} + +test { + useJUnitPlatform() +} + +mainClassName = 'Launcher' \ No newline at end of file diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml new file mode 100644 index 0000000000..b1a57ba6c0 --- /dev/null +++ b/config/checkstyle/checkstyle.xml @@ -0,0 +1,257 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/duke.txt b/data/duke.txt new file mode 100644 index 0000000000..a368f923a8 --- /dev/null +++ b/data/duke.txt @@ -0,0 +1,3 @@ +D , y , CS2103 iP , 30/09/2019 2359 +D , y , Celebrate end of mid-terms , 05/10/2019 1300 +T , n , test diff --git a/docs/README.md b/docs/README.md index fd44069597..c1c2d0c41d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2,19 +2,205 @@ ## Features -### Feature 1 -Description of feature. +### List Tasks +Displays a list of existing tasks + +### Add Task +Adds a new task to the list of tasks. Task can be in the form of a Todo, a Deadline, or an Event + +### Find Tasks +Displays a list of tasks matching the given keyword + +### Complete Task +Marks a task as done + +### Delete Task +Deletes a task + +### Undo +Undoes the previous action if it modified the list of tasks + +### Display Help +Displays a list of available commands ## Usage -### `Keyword` - Describe action +### `list` - Displays a list of existing tasks + +Displays a list of existing tasks + +Format: `list` + +Example of usage: `list` + +Expected outcome: + +``` +Here are the tasks in your list nya: + 1.[T][n] CS2100 revision + 2.[D][n] CS2103 iP (by: 30/09/2019 2359) + 3.[E][n] Celebrate end of mid-terms (at: 05/10/2019 1300) +``` + +### `todo` - Adds a new Todo task to the list of tasks + +Adds a new Todo task tagged with a name to the list of tasks. + +Format: `todo [name]` + +Example of usage: `todo CS2103 tP` + +Expected outcome: + +``` +Meow! Got it~ I've added this task nya: + [T][n] CS2103 tP +Now you have 4 tasks in the list nya~ +``` + +### `deadline` - Adds a new Deadline task to the list of tasks + +Adds a new Deadline task tagged with a name and due date to the list of tasks. + +Format: `deadline [name] /by [dd/mm/yyyy hhmm]` + +Example of usage: `deadline iP user guide /by 30/09/2019 2359` + +Expected outcome: + +``` +Meow! Got it~ I've added this task nya: + [D][n] iP user guide (by: 30/09/2019 2359) +Now you have 5 tasks in the list nya~ +``` + +### `event` - Adds a new Event task to the list of tasks + +Adds a new Event task tagged with a name and date to the list of tasks. + +Format: `event [name] /at [dd/mm/yyyy hhmm]` + +Example of usage: `event Celebrate completion of iP /at 30/09/2019 2359` + +Expected outcome: + +``` +Meow! Got it~ I've added this task nya: + [E][n] Celebrate completion of iP (by: 30/09/2019 2359) +Now you have 6 tasks in the list nya~ +``` + +### `find` - Displays a list of tasks matching the given keyword + +Displays a list of tasks matching the given keyword. + +Format: `find [keyword]` + +Example of usage: `find iP` + +Expected outcome: + +``` +Here are the matching tasks in your list nya: + 1.[D][n] CS2103 iP (by: 30/09/2019 2359) + 2.[D][n] iP user guide (by: 30/09/2019 2359) + 3.[E][n] Celebrate completion of iP (at: 30/09/2019 2359) +``` + +### `done` - Marks a task as done + +Marks the task at the specified index in the list of tasks as done. + +Format: `done [index]` + +Example of usage: `done 5` + +Expected outcome: + +``` +Nice nya! I've marked this task as done nya: + [D][y] iP user guide (by: 30/09/2019 2359) +``` + +### `delete` - Deletes a task + +Marks the task at the specified index in the list of tasks. + +Format: `delete [index]` + +Example of usage: `delete 6` + +Expected outcome: + +``` +Meow! Noted~ I've removed this task nya: + [E][n] Celebrate completion of iP (at: 30/09/2019 2359) +Now you have 5 tasks in the list nya~ +``` + +### `undo` - Undoes the previous action if it modified the list of tasks + +Undoes the previous action if it modified the list of tasks. + +Format: `undo` + +Example of usage: `undo` + +Expected outcome: + +``` +Meow! Noted~ Your previous command has been undone. Here are the tasks in your list nya: + 1.[T][n] CS2100 revision + 2.[D][n] CS2103 iP (by: 30/09/2019 2359) + 3.[E][n] Celebrate end of mid-terms (at: 05/10/2019 1300) + 4.[T][n] CS2103 tP + 5.[D][y] iP user guide (by: 30/09/2019 2359) + 6.[E][n] Celebrate completion of iP (at: 30/09/2019 2359) +``` + +### `help` - Displays a list of available commands + +Displays a list of available commands. + +Format: `help` + +Example of usage: `help` + +Expected outcome: + +``` +Here are the commands available nya :3 +- list -> returns the current list of tasks nya + +- todo [name] -> creates a Todo nya + +- deadline [name] /by [dd/mm/yyyy hhmm] -> creates a Deadline nya + +- event [name] /at [dd/mm/yyyy hhmm] -> creates an Event nya + +- find [keyword] -> returns tasks matching the keyword given nya + +- done [index] -> marks the task at the index as done nya + +- delete [index] -> deletes the task at the index nya + +- undo -> undoes your previous action nya + +- bye -> saves your task list and ends the program nya~ bye bye! + +You can also type 'more help' for other interesting commands nya! +``` + +### `bye` - Exits the program -Describe action and its outcome. +Saves the current list of tasks and exits the program. -Example of usage: +Format: `bye` -`keyword (optional arguments)` +Example of usage: `bye` Expected outcome: -`outcome` +``` +Bye bye! Hope to see you again soon nya! :3 :3 :3 +``` \ No newline at end of file diff --git a/docs/Ui.png b/docs/Ui.png new file mode 100644 index 0000000000..b63bdf2bb8 Binary files /dev/null and b/docs/Ui.png differ diff --git a/docs/_config.yml b/docs/_config.yml new file mode 100644 index 0000000000..c4192631f2 --- /dev/null +++ b/docs/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-cayman \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000..87b738cbd0 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..f584ba21ae --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Tue Sep 10 00:41:03 SGT 2019 +distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-all.zip +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStorePath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew new file mode 100755 index 0000000000..af6708ff22 --- /dev/null +++ b/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## 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"' + +# 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, switch paths to Windows format before running java +if $cygwin ; 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=$((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" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000000..6d57edc706 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,84 @@ +@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 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" + +@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/settings.gradle b/settings.gradle new file mode 100644 index 0000000000..d1e92fe5db --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'duke' diff --git a/src/main/java/Deadline.class b/src/main/java/Deadline.class new file mode 100644 index 0000000000..5155206446 Binary files /dev/null and b/src/main/java/Deadline.class differ diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java new file mode 100644 index 0000000000..a013f1d9d6 --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,69 @@ +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * Encapsulates a deadline to be stored in Duke. + */ +public class Deadline extends Task { + private String name; + private boolean done; + private Date by; + private SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy kkmm"); + + /** + * Creates a Deadline object tagged with name, whether it is completed, and task deadline. + * + * @param name Name of event. + * @param by Deadline by when task is due. + */ + public Deadline(String name, String by) throws ParseException { + super(name); + this.by = format.parse(by); + } + + /** + * Returns name of deadline. + * + * @return Name of deadline. + */ + public String getName() { + return super.getName(); + } + + /** + * Returns "y" or "n" based on completion of deadline. + * + * @return String "y" or "n". + */ + public String isDone() { + return super.isDone(); + } + + /** + * Returns deadline of task. + * + * @return Deadline of task in String format. + */ + public String getBy() { + return format.format(by); + } + + /** + * Marks deadline as done. + */ + public void setDone() { + super.setDone(); + } + + /** + * Overrides the original toString method. + * Returns description of deadline as `[D][isDone] name (by: date)`. + * + * @return Formatted description of deadline. + */ + @Override + public String toString() { + return String.format("[D]%s (by: %s)", super.toString(), format.format(by)); + } +} diff --git a/src/main/java/DialogBox.java b/src/main/java/DialogBox.java new file mode 100644 index 0000000000..0b8e7a9ffc --- /dev/null +++ b/src/main/java/DialogBox.java @@ -0,0 +1,58 @@ +import java.io.IOException; +import java.util.Collections; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.geometry.Pos; +import javafx.scene.Node; +import javafx.scene.control.Label; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.layout.HBox; + +/** + * An example of a custom control using FXML. + * This control represents a dialog box consisting of an ImageView to represent the speaker's face and a label + * containing text from the speaker. + */ +public class DialogBox extends HBox { + @FXML + private Label dialog; + @FXML + private ImageView displayPicture; + + private DialogBox(String text, Image img) { + try { + FXMLLoader fxmlLoader = new FXMLLoader(MainWindow.class.getResource("/view/DialogBox.fxml")); + fxmlLoader.setController(this); + fxmlLoader.setRoot(this); + fxmlLoader.load(); + } catch (IOException e) { + e.printStackTrace(); + } + + dialog.setText(text); + displayPicture.setImage(img); + } + + /** + * Flips the dialog box such that the ImageView is on the left and text on the right. + */ + private void flip() { + ObservableList tmp = FXCollections.observableArrayList(this.getChildren()); + Collections.reverse(tmp); + getChildren().setAll(tmp); + setAlignment(Pos.TOP_LEFT); + } + + public static DialogBox getUserDialog(String text, Image img) { + return new DialogBox(text, img); + } + + public static DialogBox getDukeDialog(String text, Image img) { + var db = new DialogBox(text, img); + db.flip(); + return db; + } +} \ No newline at end of file diff --git a/src/main/java/Duke.class b/src/main/java/Duke.class new file mode 100644 index 0000000000..1535ea9209 Binary files /dev/null and b/src/main/java/Duke.class differ diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5d313334cc..578df9afca 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,10 +1,187 @@ -public class Duke { - public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.text.ParseException; +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.layout.AnchorPane; +import javafx.scene.layout.Region; +import javafx.scene.layout.VBox; +import javafx.stage.Stage; + +/** + * Encapsulates a Duke object for the execution of the Duke program. + */ +public class Duke extends Application { + + private Storage storage; + private TaskList tasks; + public Ui ui; + private ScrollPane scrollPane; + private VBox dialogContainer; + private TextField userInput; + private Button sendButton; + private Scene scene; + private Image user = new Image(this.getClass().getResourceAsStream("/images/User.jpg")); + private Image duke = new Image(this.getClass().getResourceAsStream("/images/Duke.jpg")); + private boolean isExit; + private InputStream inputStream; + + /** + * Creates a Duke object tagged with ui, storage and list of tasks. + * + */ + public Duke() { + ui = new Ui(); + isExit = false; + try { + storage = new Storage(); + } catch (FileNotFoundException e) { + ui.showError("filepath"); + return; + } catch (IOException e) { + ui.showError("filepath"); + } + try { + tasks = new TaskList(storage.load()); + } catch (IOException e) { + ui.showError("load"); + tasks = new TaskList(); + } catch (ParseException e) { + e.printStackTrace(); + } + } + + /** + * Runs the Duke program. + */ + public String run(String command) { + String message = ""; + try { + message = ui.execute(command, tasks); + } catch (ParseException e) { + e.printStackTrace(); + } + isExit = ui.isExit(); + if (isExit) { + try { + storage.store(); + } catch (IOException e) { + ui.showError("store"); + } + return ui.exit(); + } else { + return message; + } + } + + public boolean isExit() { + return isExit; + } + + @Override + public void start(Stage stage) { + //Step 1. Setting up required components + + //The container for the content of the chat to scroll. + scrollPane = new ScrollPane(); + dialogContainer = new VBox(); + scrollPane.setContent(dialogContainer); + + 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(); + + //Step 2. Formatting the window to look as expected + 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); + + // You will need to import `javafx.scene.layout.Region` for this. + 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); + + //Step 3. Add functionality to handle user input. + sendButton.setOnMouseClicked((event) -> { + handleUserInput(); + }); + + userInput.setOnAction((event) -> { + handleUserInput(); + }); + + //Scroll down to the end every time dialogContainer's height changes. + dialogContainer.heightProperty().addListener((observable) -> scrollPane.setVvalue(1.0)); + } + + /** + * Iteration 1: + * Creates a label with the specified text and adds it to the dialog container. + * @param text String containing text to add + * @return a label with the specified text that has word wrap enabled. + */ + private Label getDialogLabel(String text) { + // You will need to import `javafx.scene.control.Label`. + Label textToAdd = new Label(text); + textToAdd.setWrapText(true); + + return textToAdd; + } + + /** + * Iteration 2: + * Creates two dialog boxes, one echoing user input and the other containing Duke's reply and then appends them to + * the dialog container. Clears the user input after processing. + */ + private void handleUserInput() { + Label userText = new Label(userInput.getText()); + Label dukeText = new Label(getResponse(userInput.getText())); + dialogContainer.getChildren().addAll( + DialogBox.getUserDialog(userInput.getText(), user), + DialogBox.getDukeDialog(getResponse(userInput.getText()), duke) + ); + userInput.clear(); + } + + /** + * Returns formatted string input. + * + * @return String input in the format of "Duke heard: *input*" + */ + public String getResponse(String input) { + return "Duke heard: " + input; } } diff --git a/src/main/java/Event.class b/src/main/java/Event.class new file mode 100644 index 0000000000..4a72535e1d Binary files /dev/null and b/src/main/java/Event.class differ diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 0000000000..3461e7248b --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,65 @@ +import java.text.ParseException; +import java.text.SimpleDateFormat; + +import java.util.Date; + +/** + * Encapsulates an event to be stored in Duke. + */ +public class Event extends Task { + private String name; + private boolean done; + private Date at; + private SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy kkmm"); + + /** + * Creates an Event object tagged with name, whether it is completed, and event time. + * + * @param name Name of event. + * @param at Date of event. + */ + public Event(String name, String at) throws ParseException { + super(name); + this.at = format.parse(at); + } + + public String getName() { + return super.getName(); + } + + /** + * Returns "y" or "n" based on completion of event. + * + * @return String "y" or "n". + */ + public String isDone() { + return super.isDone(); + } + + /** + * Returns date of event. + * + * @return Date of event in String format. + */ + public String getAt() { + return format.format(at); + } + + /** + * Marks event as done. + */ + public void setDone() { + super.setDone(); + } + + /** + * Overrides the original toString method. + * Returns description of event as `[E][isDone] name (at: date)`. + * + * @return Formatted description of event. + */ + @Override + public String toString() { + return String.format("[E]%s (at: %s)", super.toString(), format.format(at)); + } +} diff --git a/src/main/java/Launcher.java b/src/main/java/Launcher.java new file mode 100644 index 0000000000..43d64c26fb --- /dev/null +++ b/src/main/java/Launcher.java @@ -0,0 +1,10 @@ +import javafx.application.Application; + +/** + * A launcher class to workaround classpath issues. + */ +public class Launcher { + public static void main(String[] args) { + Application.launch(Main.class, args); + } +} diff --git a/src/main/java/Main.java b/src/main/java/Main.java new file mode 100644 index 0000000000..710f460445 --- /dev/null +++ b/src/main/java/Main.java @@ -0,0 +1,31 @@ +import java.io.FileInputStream; +import java.io.InputStream; +import java.io.IOException; +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Scene; +import javafx.scene.layout.AnchorPane; +import javafx.stage.Stage; + +/** + * A GUI for Duke using FXML. + */ +public class Main extends Application { + + //private Duke duke = new Duke(Main.class.getResourceAsStream("/data/duke.txt")); + private Duke duke = new Duke(); + + @Override + public void start(Stage stage) { + try { + FXMLLoader fxmlLoader = new FXMLLoader(Main.class.getResource("/view/MainWindow.fxml")); + AnchorPane ap = fxmlLoader.load(); + Scene scene = new Scene(ap); + stage.setScene(scene); + fxmlLoader.getController().setDuke(duke); + stage.show(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/MainWindow.java b/src/main/java/MainWindow.java new file mode 100644 index 0000000000..a8b4c9d83b --- /dev/null +++ b/src/main/java/MainWindow.java @@ -0,0 +1,61 @@ +import javafx.animation.PauseTransition; +import javafx.application.Platform; +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; +import javafx.util.Duration; + +/** + * Controller for MainWindow. Provides the layout for the other controls. + */ +public class MainWindow extends AnchorPane { + @FXML + private ScrollPane scrollPane; + @FXML + private VBox dialogContainer; + @FXML + private TextField userInput; + @FXML + private Button sendButton; + + private Duke duke; + + private Image userImage = new Image(this.getClass().getResourceAsStream("/images/User.jpg")); + private Image dukeImage = new Image(this.getClass().getResourceAsStream("/images/Duke.jpg")); + + @FXML + public void initialize() { + scrollPane.vvalueProperty().bind(dialogContainer.heightProperty()); + dialogContainer.getChildren().addAll( + DialogBox.getDukeDialog(new Ui().showWelcome(), dukeImage) + ); + } + + public void setDuke(Duke d) { + duke = d; + } + + /** + * Creates two dialog boxes, one echoing user input and the other containing Duke's reply and then appends them to + * the dialog container. Clears the user input after processing. + */ + @FXML + private void handleUserInput() { + String input = userInput.getText(); + String response = duke.run(input); + dialogContainer.getChildren().addAll( + DialogBox.getUserDialog(input, userImage), + DialogBox.getDukeDialog(response, dukeImage) + ); + if (duke.isExit()) { + PauseTransition delay = new PauseTransition(Duration.seconds(1)); + delay.setOnFinished( event -> Platform.exit()); + delay.play(); + } + userInput.clear(); + } +} \ No newline at end of file diff --git a/src/main/java/Parser.class b/src/main/java/Parser.class new file mode 100644 index 0000000000..ce754d19e5 Binary files /dev/null and b/src/main/java/Parser.class differ diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java new file mode 100644 index 0000000000..4112453c0c --- /dev/null +++ b/src/main/java/Parser.java @@ -0,0 +1,23 @@ +/** + * Encapsulates a parser used to understand user commands. + */ +public class Parser { + private String[] commands; + + /** + * Creates a Parser object. + */ + public Parser() { + } + + /** + * Returns user commands parsed as a String array. + * + * @param command Command from user input. + * @return String array of split commands. + */ + public String[] parse(String command) { + commands = command.split(" "); + return commands; + } +} diff --git a/src/main/java/Storage.class b/src/main/java/Storage.class new file mode 100644 index 0000000000..126c9fc0b9 Binary files /dev/null and b/src/main/java/Storage.class differ diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java new file mode 100644 index 0000000000..a505887426 --- /dev/null +++ b/src/main/java/Storage.java @@ -0,0 +1,87 @@ +import java.io.*; +import java.text.ParseException; +import java.util.ArrayList; + +/** + * Encapsulates a Storage object to load and save tasks from and to file. + */ +public class Storage { + private static String filePath = "../duke/data/duke.txt"; + private static String dirPath = "../duke/data"; + private FileReader reader; + private BufferedReader bufferedReader; + private ArrayList tasks; + public static boolean isInitiated = false; + + /** + * Creates a Storage object tagged with path of file, file reader, buffered reader, and list of tasks. + * + * @throws FileNotFoundException If file is not found at specified location. + */ + public Storage() throws FileNotFoundException, IOException{ + File duke = new File(filePath); + File dukeDir = new File(dirPath); + if (!duke.isFile()) { + dukeDir.mkdir(); + duke.createNewFile(); + } + this.reader = new FileReader(this.filePath); + this.bufferedReader = new BufferedReader(reader); + this.tasks = new ArrayList<>(); + } + + /** + * Returns ArrayList of tasks loaded from file. + * + * @return ArrayList of tasks. + * @throws IOException If tasks failed to be retrieved. + */ + public ArrayList load() throws IOException, ParseException { + String line = bufferedReader.readLine(); + while (! (line == null)) { + String[] words = line.split(" , "); + Task task; + if (words[0].equals("T")) { + task = new Todo(words[2]); + } else if (words[0].equals("D")) { + task = new Deadline(words[2], words[3]); + } else { + task = new Event(words[2], words[3]); + } + + if (words[1].equals("y")) { + task.setDone(); + } + + tasks.add(task); + line = bufferedReader.readLine(); + } + + return tasks; + } + + /** + * Stores tasks in file. + * + * @throws IOException If tasks failed to be stored. + */ + public void store() throws IOException { + FileWriter writer = new FileWriter(filePath, false); + //FileWriter writer = new FileWriter(this.getClass().getResource("../duke/data/duke.txt").getPath()); + BufferedWriter bufferedWriter = new BufferedWriter(writer); + + for (Task item : tasks) { + if (item instanceof Todo) { + bufferedWriter.write(String.format("T , %s , %s", item.isDone(), item.getName())); + } else if (item instanceof Deadline) { + bufferedWriter.write(String.format("D , %s , %s , %s", item.isDone(), item.getName(), ((Deadline) item) + .getBy())); + } else { + bufferedWriter.write(String.format("D , %s , %s , %s", item.isDone(), item.getName(), ((Event) item) + .getAt())); + } + bufferedWriter.newLine(); + } + bufferedWriter.close(); + } +} diff --git a/src/main/java/Task.class b/src/main/java/Task.class new file mode 100644 index 0000000000..451480d3d5 Binary files /dev/null and b/src/main/java/Task.class differ diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 0000000000..528b983680 --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,57 @@ +/** + * Encapsulates a task to be stored in Duke. + */ +public abstract class Task { + private String name; + private boolean isDone; + + /** + * Creates a Task object tagged with name and whether it is completed. + * + * @param name Name of task. + */ + public Task(String name) { + this.name = name; + this.isDone = false; + } + + /** + * Returns "y" or "n" based on completion of task. + * + * @return String "y" or "n". + */ + public String isDone() { + if (isDone) { + return "y"; + } else { + return "n"; + } + } + + /** + * Returns name of task. + * + * @return Name of task. + */ + public String getName() { + return name; + } + + /** + * Marks task as done. + */ + public void setDone() { + isDone = true; + } + + /** + * Overrides the original toString method. + * Returns description of task as `[isDone] name`. + * + * @return Formatted description of task. + */ + @Override + public String toString() { + return String.format("[%s] %s", isDone(), name); + } +} diff --git a/src/main/java/TaskList.class b/src/main/java/TaskList.class new file mode 100644 index 0000000000..a9dbd6fc44 Binary files /dev/null and b/src/main/java/TaskList.class differ diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java new file mode 100644 index 0000000000..3b7c8ae122 --- /dev/null +++ b/src/main/java/TaskList.java @@ -0,0 +1,61 @@ +import java.util.ArrayList; + +/** + * Encapsulates a list for storing tasks in Duke. + */ +public class TaskList { + private ArrayList tasks; + + /** + * Creates a TaskList object tagged with an ArrayList of tasks. + * + * @param tasks ArrayList of Task objects. + */ + public TaskList(ArrayList tasks) { + this.tasks = tasks; + } + + /** + * Creates an empty TaskList with no tasks. + */ + public TaskList() { + this.tasks = new ArrayList<>(); + } + + /** + * Adds task to list of tasks. + * Task is added to back of the current list. + * + * @param task Task to be added into the list. + */ + public void add(Task task) { + tasks.add(task); + } + + /** + * Deletes the task at the corresponding index in the list. + * + * @param index Index of task to be deleted from list. + */ + public void delete(int index) { + tasks.remove(index); + } + + /** + * Marks task with corresponding index as completed. + * + * @param index Index of tasks to be marked completed in list. + */ + public void done(int index) { + tasks.get(index).setDone(); + } + + /** + * Retrieves tasks available in list. + * + * @return tasks ArrayList of tasks. + */ + public ArrayList getTasks() { + return tasks; + } +} diff --git a/src/main/java/Todo.class b/src/main/java/Todo.class new file mode 100644 index 0000000000..527ffae7c0 Binary files /dev/null and b/src/main/java/Todo.class differ diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java new file mode 100644 index 0000000000..1aa95e8e55 --- /dev/null +++ b/src/main/java/Todo.java @@ -0,0 +1,52 @@ +/** + * Encapsulates a todo to be stored in Duke. + */ +public class Todo extends Task { + private String name; + private boolean done; + + /** + * Creates a Todo object tagged with name and whether it is completed. + * + * @param name Name of todo. + */ + public Todo(String name) { + super(name); + } + + /** + * Returns name of todo. + * + * @return Name of todo. + */ + public String getName() { + return super.getName(); + } + + /** + * Returns "y" or "n" based on completion of todo. + * + * @return String "y" or "n". + */ + public String isDone() { + return super.isDone(); + } + + /** + * Marks todo as done. + */ + public void setDone() { + super.setDone(); + } + + /** + * Overrides the original toString method. + * Returns description of todo as `[T][isDone] name`. + * + * @return Formatted description of todo. + */ + @Override + public String toString() { + return String.format("[T]%s", super.toString()); + } +} diff --git a/src/main/java/Ui.class b/src/main/java/Ui.class new file mode 100644 index 0000000000..cd33ba2a6a Binary files /dev/null and b/src/main/java/Ui.class differ diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java new file mode 100644 index 0000000000..da62380f24 --- /dev/null +++ b/src/main/java/Ui.java @@ -0,0 +1,330 @@ +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Scanner; + +/** + * Encapsulates a Ui to deal with user interactions. + */ +public class Ui { + Scanner scanner; + private boolean isExit; + private Parser parser; + private StringBuilder string; + private TaskList undoneTasks; + private int meowCount; + private int purrCount; + + /** + * Creates a Ui object tagged with scanner, whether the program is exited, and parser. + */ + public Ui() { + scanner = new Scanner(System.in); + isExit = false; + parser = new Parser(); + undoneTasks = new TaskList(); + meowCount = 0; + purrCount = 0; + } + + /** + * Displays a welcome message. + */ + public String showWelcome() { + return "Meow! I'm Duke :3\nWhat can I do for you nya?\nType 'help' for more info nya nya!"; + } + + /** + * Executes the given user commands. + * + * @param tasks Tasks to mark as completed, add to, delete, or view based on user commands. + */ + public String execute(String command, TaskList tasks) throws ParseException { + string = new StringBuilder(); + if (!command.equals("undo")) { + undoneTasks = new TaskList(); + for (Task task : tasks.getTasks()) { + Task addTask; + if (task instanceof Todo) { + addTask = new Todo(task.getName()); + } else if (task instanceof Event) { + addTask = new Event(task.getName(), ((Event) task).getAt()); + } else { + addTask = new Deadline(task.getName(), ((Deadline) task).getBy()); + } + if (task.isDone().equals("y")) { + addTask.setDone(); + } + undoneTasks.add(addTask); + } + } + + switch (command) { + case "help": + string.append("Here are the commands available nya :3\n"); + string.append("- list -> returns the current list of tasks nya\n" + + "\n- todo [name] -> creates a Todo nya\n" + + "\n- deadline [name] /by [dd/mm/yyyy hhmm] -> creates a Deadline nya\n" + + "\n- event [name] /at [dd/mm/yyyy hhmm] -> creates an Event nya\n" + + "\n- find [keyword] -> returns tasks matching the keyword given nya\n" + + "\n- done [index] -> marks the task at the index as done nya\n" + + "\n- delete [index] -> deletes the task at the index nya\n" + + "\n- undo -> undoes your previous action nya\n" + + "\n- bye -> saves your task list and ends the program nya~ bye bye!\n" + + "\nYou can also type 'more help' for other interesting commands nya!"); + break; + + case "more help": + string.append("You can also try these commands nya~\n" + + "- meow -> meow?\n" + + "\n- pet -> meow meow?\n"); + break; + + case "bye": + isExit = true; + break; + case "list": + string.append("Here are the tasks in your list nya:\n"); + for (int i = 0; i < tasks.getTasks().size(); i++) { + string.append(String.format(" %d.%s\n", i + 1, tasks.getTasks().get(i).toString())); + } + break; + case "meow": + meowCount += 1; + if (meowCount >= 3) { + string.append("Nya!!! Give me a useful command!! >:3"); + meowCount = 0; + } else { + for (int i = 0; i < meowCount; i++) { + string.append("Meow~~~ "); + } + } + break; + case "pet": + purrCount += 1; + if (purrCount == 3) { + string.append("Nya!!! Stop petting or I will scratch you *hiss* >:3"); + } else if (purrCount > 3) { + string.append("HISS!!! *scratch* *angry cat noises*"); + purrCount = 0; + } else { + for (int i = 0; i < purrCount; i++) { + string.append("Purr~~~ "); + } + } + break; + case "": + string.append("Meow? Please say something!"); + break; + case "undo": + string.append("Meow! Noted~ Your previous command has been undone. Here are the tasks in your list nya:\n"); + while(!tasks.getTasks().isEmpty()) { + tasks.delete(0); + } + for (Task task : undoneTasks.getTasks()) { + tasks.add(task); + } + + for (int i = 0; i < tasks.getTasks().size(); i++) { + string.append(String.format(" %d.%s\n", i + 1, tasks.getTasks().get(i).toString())); + } + break; + default: + String[] commands = parser.parse(command); + String com = commands[0]; + int index; + switch (com) { + case "delete": + if (commands.length < 2) { + string.append("Nya? There is no index given nya *confused cat noises"); + } else if (commands.length != 2) { + string.append("Nya? Your delete instruction is wrong nya *confused cat noises"); + } else { + try { + index = Integer.valueOf(commands[1]) - 1; + if (tasks.getTasks().isEmpty()) { + string.append("Nya? There is nothing to remove nya *confused cat noises*"); + } else if (index >= tasks.getTasks().size() || index < 0) { + string.append(String.format("Nya? There are no tasks at (%d) nya *confused cat noises*", + index + 1)); + } else { + string.append("Meow! Noted~ I've removed this task nya:\n"); + Task deletedTask = tasks.getTasks().get(index); + string.append(" " + deletedTask.toString() + "\n"); + tasks.delete(index); + boolean isMatching = false; + for (Task task : tasks.getTasks()) { + if (deletedTask.equals(task)) { + isMatching = true; + } + } + assert isMatching : "the task at this index should have been deleted nya"; + string.append(String.format("Now you have %d tasks in the list nya~", + tasks.getTasks().size())); + } + } catch (NumberFormatException e) { + string.append("Nya? The index given is not a number nya *confused cat noises"); + } + } + break; + case "done": + if (commands.length < 2) { + string.append("Nya? There is no index given nya *confused cat noises"); + } else if (commands.length != 2) { + string.append("Nya? Your done instruction is wrong nya *confused cat noises"); + } else { + try { + index = Integer.valueOf(commands[1]) - 1; + if (index >= tasks.getTasks().size() || index < 0) { + string.append(String.format("Nya? There are no tasks at (%d) nya *confused cat noises*", + index + 1)); + } else { + Task t = tasks.getTasks().get(index); + if (t.isDone().equals("y")) { + string.append("Nya? The task is already done nya *confused cat noises*"); + } else { + tasks.done(index); + String isDone = t.isDone(); + assert isDone.equals("y") : "the task should be marked done nya"; + string.append("Nice nya! I've marked this task as done nya:\n"); + string.append(" " + t.toString() + "\n"); + } + } + } catch (NumberFormatException e) { + string.append("Nya? The index given is not a number nya *confused cat noises"); + } + } + break; + case "find": + if (commands.length == 1) { + string.append("Nya? The search criteria cannot be empty nya *confused cat noises*"); + } else if (commands.length > 2) { + string.append("Nya? Your search instruction is wrong nya *confused cat noises*"); + } else { + ArrayList results = new ArrayList<>(); + for (Task task : tasks.getTasks()) { + if (task.getName().contains(commands[1])) { + results.add(task); + } + } + if (results.isEmpty()) { + string.append("There were no matching tasks nya."); + } else { + string.append("Here are the matching tasks in your list nya:\n"); + for (int i = 0; i < results.size(); i++) { + string.append(String.format(" %d.%s\n", i + 1, results.get(i).toString())); + } + } + } + break; + default: + String taskName = ""; + for (int j = 1; j < commands.length; j++) { + if (j != commands.length - 1) { + taskName += commands[j] + " "; + } else { + taskName += commands[j]; + } + } + + Task task; + boolean isError = false; + if (commands[0].equals("todo") || commands[0].equals("deadline") || commands[0].equals("event")) { + if (commands.length == 1) { + if (commands[0].equals("event")) { + string.append("Nya? The description of an event cannot be empty nya *confused cat noises*"); + } else { + string.append(String.format("Nya? The description of a %s cannot be empty nya " + + "*confused cat noises*", commands[0])); + } + } else { + if (commands[0].equals("todo")) { + task = new Todo(taskName); + } else if (commands[0].equals("deadline")) { + String[] details = taskName.split(" /by "); + if (details.length != 2) { + string.append("Nya? There is no deadline given nya *confused cat noises*"); + isError = true; + task = new Deadline("dummy", "10/10/1000 1000"); + } else { + try { + task = new Deadline(details[0], details[1]); + } catch (ParseException e) { + string.append("Nya? The format of the deadline is wrong nya *confused cat noises*"); + isError = true; + task = new Deadline("dummy", "10/10/1000 1000"); + } + } + } else { + String[] details = taskName.split(" /at "); + if (details.length != 2) { + string.append("Nya? There is no event date given nya *confused cat noises*"); + isError = true; + task = new Event("dummy", "10/10/1000 1000"); + } else { + try { + task = new Event(details[0], details[1]); + } catch (ParseException e) { + string.append("Nya? The format of the event is wrong nya *confused cat noises*"); + isError = true; + task = new Event("dummy", "10/10/1000 1000"); + } + } + } + + if(!isError) { + int taskSize = tasks.getTasks().size(); + tasks.add(task); + string.append("Meow! Got it~ I've added this task nya:\n"); + string.append(" " + task.toString() + "\n"); + if (tasks.getTasks().size() == 1) { + string.append("Now you have 1 task in the list nya~\n"); + + } else { + string.append(String.format("Now you have %d tasks in the list nya~\n", tasks.getTasks() + .size())); + } + + int newTaskSize = tasks.getTasks().size(); + assert newTaskSize == taskSize + 1 : "the list should have increased by 1 task nya"; + } + } + + } else { + string.append("Nya? I'm sorry, but I don't know what that means nya :,3\n"); + } + } + } + return string.toString(); + } + + /** + * Displays error messages. + * + * @param error Name of error. + */ + public void showError(String error) { + if (error.equals("load")) { + string.append("Nya? The list of tasks cannot be loaded nya *confused cat noises*"); + } else if (error.equals("filepath")) { + string.append("Nya? There is something wrong with the filepath nya *confused cat noises*"); + } else if (error.equals("store")) { + string.append("Nya? There is something wrong with the file nya *confused cat noises*"); + } + } + + /** + * Returns if program is to be exited. + * + * @return Boolean depending on whether program is to be exited. + */ + public boolean isExit() { + return isExit; + } + + /** + * Shows exit message for stopping program. + */ + public String exit() { + return "Bye bye! Hope to see you again soon nya! :3 :3 :3\n"; + } +} diff --git a/src/main/resources/images/Banner.jpg b/src/main/resources/images/Banner.jpg new file mode 100644 index 0000000000..5982879b25 Binary files /dev/null and b/src/main/resources/images/Banner.jpg differ diff --git a/src/main/resources/images/Duke.jpg b/src/main/resources/images/Duke.jpg new file mode 100644 index 0000000000..bb6d761da3 Binary files /dev/null and b/src/main/resources/images/Duke.jpg differ diff --git a/src/main/resources/images/User.jpg b/src/main/resources/images/User.jpg new file mode 100644 index 0000000000..c86eb564d8 Binary files /dev/null and b/src/main/resources/images/User.jpg differ diff --git a/src/main/resources/view/DialogBox.fxml b/src/main/resources/view/DialogBox.fxml new file mode 100644 index 0000000000..835d127966 --- /dev/null +++ b/src/main/resources/view/DialogBox.fxml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + +
+ + + + + +
+
+
+ + + +
diff --git a/src/main/resources/view/MainWindow.fxml b/src/main/resources/view/MainWindow.fxml new file mode 100644 index 0000000000..26a957874c --- /dev/null +++ b/src/main/resources/view/MainWindow.fxml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/java/DeadlineTest.java b/src/test/java/DeadlineTest.java new file mode 100644 index 0000000000..bbb0aeb663 --- /dev/null +++ b/src/test/java/DeadlineTest.java @@ -0,0 +1,9 @@ +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class DeadlineTest { + @Test + public void testStringConversion() { + assertEquals("[D][n] return book (by: 01/01/2019 1500)", new Deadline("return book","01/01/2019 1500").toString()); + } +} diff --git a/src/test/java/DukeTest.java b/src/test/java/DukeTest.java new file mode 100644 index 0000000000..135ede24d1 --- /dev/null +++ b/src/test/java/DukeTest.java @@ -0,0 +1,10 @@ +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + + +public class DukeTest { + @Test + public void dummyTest(){ + assertEquals(2, 2); + } +} diff --git a/src/test/java/ParserTest.java b/src/test/java/ParserTest.java new file mode 100644 index 0000000000..b221d8122b --- /dev/null +++ b/src/test/java/ParserTest.java @@ -0,0 +1,12 @@ +import org.junit.jupiter.api.Test; + +import java.util.Arrays; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class ParserTest { + @Test + public void stringSplit_string_stringArray() { + assertEquals("[todo, return, book]", Arrays.toString(new Parser().parse("todo return book"))); + } +} diff --git a/src/test/java/TodoTest.java b/src/test/java/TodoTest.java new file mode 100644 index 0000000000..f10c039876 --- /dev/null +++ b/src/test/java/TodoTest.java @@ -0,0 +1,9 @@ +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class TodoTest { + @Test + public void testStringConversion() { + assertEquals("[T][n] return book", new Todo("return book").toString()); + } +}