diff --git a/.gitignore b/.gitignore index 99712178bf..f10c06736f 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,9 @@ src/main/resources/docs/ .DS_Store *.iml bin/ +src/.idea/$PRODUCT_WORKSPACE_FILE$ +src/.idea/.gitignore +src/.idea/misc.xml +src/.idea/modules.xml +src/.idea/vcs.xml +src/out/production/main/Duke.class diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000000..b11746a5d5 --- /dev/null +++ b/build.gradle @@ -0,0 +1,36 @@ +plugins { + id 'java' + id 'application' + + id 'org.openjfx.javafxplugin' version '0.0.7' +} + +javafx { + version = "11.0.2" + modules = [ 'javafx.controls', 'javafx.fxml' ] +} + +group 'seedu.duke' +version '0.1.0' + +repositories { + mavenCentral() +} + +dependencies { + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1' +} + +application { + // Change this to your main class. + mainClassName = "Duke" +} + +run { + standardInput = System.in +} + +test { + useJUnitPlatform() +} \ 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/docs/README.md b/docs/README.md index fd44069597..f0dfc00dca 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,20 +1,83 @@ # User Guide +## 1. Introduction + +Duke is a GUI (Graphical User Interface) application that lets you set reminders for tasks. The user interacts with the application through the Command Line Interface (CLI). + +## 2. Quick Start + +1. Ensure that you have Java 11 or above installed in your Computer. + +2. Download the latest duke.jar [here](https://github.com/eizon05/duke/releases). + +3. Copy the file to the folder you want to use as the home folder for your Duke. + +4. Double-click the file to start the app. The GUI should appear in a few seconds. + ## Features -### Feature 1 -Description of feature. +### 3.1 Adding a Task + +Adds (and saves) a task to Duke. There are 3 kinds of tasks: + +#### 3.1.1 Todo + +Format: "todo {description}" + +#### 3.1.2 Deadline + +Format: "deadline {description} /by {date}" + +Note: Slash used must be a forward slash + +#### 3.1.3 Event + +Format: "event {description} /at {date)" + +Note: Slash used must be a forward slash + +### 3.2 Listing all Tasks + +Format: "list" + +Lists all the tasks that are saved in Duke (in order of time saved) + +### 3.3 Deleting a Task + +Format: "delete {index}" + +Deletes a task from the list which is at the index, "{index}" + +### 3.4 Marking a Task as Done + +Format: "done {index}" + +Marks the task at the index, "{index}", (in the list) as done + +### 3.5 Finding a Task that contains a specific string + +Format: "find {string}" + +Shows the tasks that contains a specific string + +### 3.6 Archiving a Task + +Format: "archive {index}" + +Archives the task at the index, "{index}", of the list. -## Usage +Note: All archived tasks can be seen in 'data/archive.txt' -### `Keyword` - Describe action -Describe action and its outcome. +### 3.7 Bye -Example of usage: +Format: "bye" -`keyword (optional arguments)` +Terminates the application -Expected outcome: +## Additional Information -`outcome` +1. Duke saves the entire list of tasks whenever you add, delete or mark a task as done. +2. When typing commands with index numbers, please make sure to type the index number that correlates to the number in the list of tasks +3. Whenever a task is archived, it will be removed from the list of tasks +4. Archived tasks can be accessed from the data folder which is located in the same directory as the application. diff --git a/docs/Ui.png b/docs/Ui.png new file mode 100644 index 0000000000..1fdd64a60f 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..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..4b7e1f3d38 --- /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-5.5.1-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists 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/.idea/artifacts/src_jar.xml b/src/.idea/artifacts/src_jar.xml new file mode 100644 index 0000000000..7aadf97768 --- /dev/null +++ b/src/.idea/artifacts/src_jar.xml @@ -0,0 +1,8 @@ + + + $PROJECT_DIR$/out/artifacts/src_jar + + + + + \ No newline at end of file diff --git a/src/.idea/uiDesigner.xml b/src/.idea/uiDesigner.xml new file mode 100644 index 0000000000..e96534fb27 --- /dev/null +++ b/src/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/AddCommand.java b/src/main/java/AddCommand.java new file mode 100644 index 0000000000..e2d067dab8 --- /dev/null +++ b/src/main/java/AddCommand.java @@ -0,0 +1,36 @@ +import java.io.IOException; + +/** + * This class is initiased and its execute method is called whenever you want to add something to the task list. + */ +public class AddCommand extends Command { + + private Task task; + + /** + * Intialise this class with a task + * @param task The Task + */ + public AddCommand (Task task) { + this.task = task; + } + + + /** + * Add the task to the task list + * @param taskList T + * @param ui + * @param storage + * @throws IOException + * @return + */ + @Override + public String execute(TaskList taskList, Ui ui, Storage storage) throws DukeException { + + taskList.add(task); + + storage.save(taskList.list); + + return ui.add(taskList.list); + } +} diff --git a/src/main/java/Command.java b/src/main/java/Command.java new file mode 100644 index 0000000000..d0d6547719 --- /dev/null +++ b/src/main/java/Command.java @@ -0,0 +1,24 @@ +import java.io.IOException; + +/** + * Represents a command that has to be carried out + */ +public abstract class Command { + + /** + * Executes the Command + * @param taskList + * @param ui + * @param storage + * @throws IOException + */ + public abstract String execute (TaskList taskList, Ui ui, Storage storage) throws DukeException; + + /** + * Checks whether the command is to exit the program + * @return + */ + public boolean isExit() { + return false; + } +} diff --git a/src/main/java/DateClass.java b/src/main/java/DateClass.java new file mode 100644 index 0000000000..0996d8ba07 --- /dev/null +++ b/src/main/java/DateClass.java @@ -0,0 +1,31 @@ +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * Class that converts strings to dates + */ +public class DateClass { + + /** + * Converts String object to Date object + * @param string The String + * @return The Date + */ + public static Date stringToDate (String string) { + + assert string.isBlank() : "String should not be Blank"; + + SimpleDateFormat format = new SimpleDateFormat("d/MM/yyyy HHmm"); + + Date date = null; + + try { + date = format.parse(string); + } catch (ParseException e) { + + } + + return date; + } +} diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java new file mode 100644 index 0000000000..62effe5e67 --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,42 @@ +import java.util.Date; + +/** + * Represents a type of task + */ +public class Deadline extends Task { + + protected String by; + + protected Date date; + + /** + * Initialises the Deadline Class with the description of the deadline and when it is due + * @param description Description of the Deadline + * @param by When it is due + */ + public Deadline(String description, String by) { + super(description); + this.by = by; + + this.date = DateClass.stringToDate(by); + } + + /** + * Returns user-readable string + * @return User-readable String + */ + @Override + public String toString() { + return "[D]" + super.toString() + " (by: " + by + ")"; + } + + /** + * Returns formatted string used while saving + * @return Formatted String + */ + @Override + public String saveFormat() { + return String.format("D | %d | %s | %s", this.isDone ? 1 : 0, this.description, this.by); + } + +} diff --git a/src/main/java/DeleteCommand.java b/src/main/java/DeleteCommand.java new file mode 100644 index 0000000000..b0df83a099 --- /dev/null +++ b/src/main/java/DeleteCommand.java @@ -0,0 +1,35 @@ +import java.io.IOException; + +/** + * This class is initiased and its execute method is called whenever you want to delete something from the task list. + */ +public class DeleteCommand extends Command { + + private int index; + + /** + * Intialise this class with an index + * @param index The Index + */ + public DeleteCommand (int index) { + this.index = index; + } + + + /** + * Deletes the Task in the task list for the given index + * @param taskList + * @param ui + * @param storage + * @throws IOException + */ + @Override + public String execute(TaskList taskList, Ui ui, Storage storage) throws DukeException { + + Task task = taskList.delete(index); + + storage.save(taskList.list); + + return ui.delete(taskList.list, task); + } +} diff --git a/src/main/java/DialogBox.java b/src/main/java/DialogBox.java new file mode 100644 index 0000000000..60636ac988 --- /dev/null +++ b/src/main/java/DialogBox.java @@ -0,0 +1,59 @@ +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/DoneCommand.java b/src/main/java/DoneCommand.java new file mode 100644 index 0000000000..b0409b821e --- /dev/null +++ b/src/main/java/DoneCommand.java @@ -0,0 +1,35 @@ +import java.io.IOException; + +/** + * This class is initiased and its execute method is called whenever you want to change the done status of a task in the task list. + */ +public class DoneCommand extends Command { + + private int index; + + /** + * Intialises this class with an index + * @param index The Index + */ + public DoneCommand (int index) { + this.index = index; + } + + + /** + * Changes the done status of the task in the task list found from the given index + * @param taskList + * @param ui + * @param storage + * @throws IOException + */ + @Override + public String execute(TaskList taskList, Ui ui, Storage storage) throws DukeException { + + Task task = taskList.done(this.index); + + storage.save(taskList.list); + + return ui.done(task); + } +} diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5d313334cc..b7cb101ddb 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,10 +1,90 @@ +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 java.io.FileNotFoundException; +import java.io.IOException; + +/** + * Class where the main logic is executed + */ public class Duke { - public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); + + private Storage storage; + private TaskList tasks; + private Ui ui; + + private Duke duke; + + private ScrollPane scrollPane; + private VBox dialogContainer; + private TextField userInput; + private Button sendButton; + private Scene scene; + + private Image userImage = new Image(this.getClass().getResourceAsStream("/images/DaUser.png")); + private Image dukeImage = new Image(this.getClass().getResourceAsStream("/images/DaDuke.png")); + + private boolean isExit = false; + + public Duke() { + this("data/duke.txt", "data"); } + + /** + * Intialises all the classes needed to run this Application. + * It also retrieves the previous tasks saved in the last session. + * @param filePath File Path of duke.txt + * @param folderPath Folder Path in which duke.txt is saved + */ + public Duke(String filePath, String folderPath) { + ui = new Ui(); + storage = new Storage(filePath, folderPath); + try { + tasks = new TaskList(storage.retrieve()); + } catch (FileNotFoundException e) { + + try { + storage.makeDirectory(folderPath); + tasks = new TaskList(); + } catch (IOException ex) { + ui.abort(); + System.exit(0); + } + } + } + + /** + * Runs the main logic of the application + */ + public String run (String fullCommand) { + + try { + Command c = Parser.parse(fullCommand); + this.isExit = c.isExit(); + return c.execute(tasks, ui, storage); + } catch (DukeException e) { + return ui.showError(e.getMessage()); + } + + } + + /** + * You should have your own function to generate a response to user input. + * Replace this stub with your completed method. + */ + public String getResponse(String input) { + return this.run(input); + } + + } diff --git a/src/main/java/Duke.java.orig b/src/main/java/Duke.java.orig new file mode 100644 index 0000000000..9969d9a20f --- /dev/null +++ b/src/main/java/Duke.java.orig @@ -0,0 +1,71 @@ +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Scanner; + +/** + * Class where the main logic is executed + */ +public class Duke { + + private Storage storage; + private TaskList tasks; + private Ui ui; + + /** + * Intialises all the classes needed to run this Application. + * It also retrieves the previous tasks saved in the last session. + * @param filePath File Path of duke.txt + * @param folderPath Folder Path in which duke.txt is saved + */ + public Duke(String filePath, String folderPath) { + ui = new Ui(); + storage = new Storage(filePath, folderPath); + try { + tasks = new TaskList(storage.retrieve()); + } catch (FileNotFoundException e) { + + try { + storage.makeDirectory(folderPath); + tasks = new TaskList(); + } catch (IOException ex) { + ui.abort(); + System.exit(0); + } + } + } + + /** + * Runs the main logic of the application + */ + public void run() { + ui.greeting(); + boolean isExit = false; + while (!isExit) { + try { + String fullCommand = ui.readCommand(); + // ui.showLine(); // show the divider line ("_______") + Command c = Parser.parse(fullCommand); + c.execute(tasks, ui, storage); + isExit = c.isExit(); + } catch (DukeException | IOException e) { + ui.showError(e.getMessage()); + } finally { + //ui.showLine(); + } + } + } + +<<<<<<< HEAD + /** + * This is the starting point of the application + * @param args + * @throws DukeException + * @throws IOException + */ +======= +>>>>>>> branch-A-CodingStandard + public static void main(String[] args) throws DukeException, IOException { + new Duke("../data/duke.txt", "../data").run(); + } + +} diff --git a/src/main/java/DukeException.java b/src/main/java/DukeException.java new file mode 100644 index 0000000000..1e9c6f064e --- /dev/null +++ b/src/main/java/DukeException.java @@ -0,0 +1,29 @@ +/** + * Deal with errors such as incorrect inputs entered by the user. + */ +public class DukeException extends Exception { + + /** + * Initialises DukeException with the error message + * @param message The Error Message + */ + public DukeException (String message) { + super(message); + } + + /** + * Returns a DukeException indicating that the description is empty + * @return The DukeException + */ + public static DukeException emptyDescription () { + return new DukeException("☹ OOPS!!! The description of a todo cannot be empty."); + } + + public static DukeException outOfBounds () { + return new DukeException("☹ OOPS!!! The number you inputted is out of bounds \uD83D\uDE22"); + } + + public static DukeException couldNotSave () { + return new DukeException("☹ OOPS!!! Your task could not be saved/updated/deleted \uD83D\uDE22"); + } +} diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 0000000000..7f2237e30a --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,37 @@ +import java.util.Date; + +/** + * Represents a type of task + */ +public class Event extends Task { + + protected String at; + + protected Date date; + + public Event(String description, String at) { + super(description); + this.at = at; + + this.date = DateClass.stringToDate(at); + } + + /** + * Returns user-readable string + * @return User-readable string + */ + @Override + public String toString() { + return "[E]" + super.toString() + " (at: " + at + ")"; + } + + /** + * Returns formatted string used while saving + * @return Formatted String + */ + @Override + public String saveFormat() { + return String.format("E | %d | %s | %s", this.isDone ? 1 : 0, this.description, this.at); + } + +} diff --git a/src/main/java/ExitCommand.java b/src/main/java/ExitCommand.java new file mode 100644 index 0000000000..867d32ce8b --- /dev/null +++ b/src/main/java/ExitCommand.java @@ -0,0 +1,28 @@ +import java.io.IOException; + +/** + * This class is initiased and its execute method is called whenever you want to exit from the application. + */ +public class ExitCommand extends Command { + + /** + * Bids farewell to the user + * @param taskList + * @param ui + * @param storage + * @throws IOException + */ + @Override + public String execute(TaskList taskList, Ui ui, Storage storage) throws DukeException { + return ui.bye(); + } + + /** + * Marks isExit as true to exit the program + * @return + */ + @Override + public boolean isExit() { + return true; + } +} diff --git a/src/main/java/FindCommand.java b/src/main/java/FindCommand.java new file mode 100644 index 0000000000..05e4f898b8 --- /dev/null +++ b/src/main/java/FindCommand.java @@ -0,0 +1,19 @@ +import java.io.IOException; + +public class FindCommand extends Command { + + String text; + + public FindCommand(String text) { + this.text = text; + } + + + @Override + public String execute(TaskList taskList, Ui ui, Storage storage) throws DukeException { + + Task[] matchedTasks = taskList.find(text); + + return ui.find(matchedTasks); + } +} diff --git a/src/main/java/Launcher.java b/src/main/java/Launcher.java new file mode 100644 index 0000000000..fd31fedf59 --- /dev/null +++ b/src/main/java/Launcher.java @@ -0,0 +1,12 @@ +import javafx.application.Application; + +public class Launcher { + + /** + * This is the starting point of the application + * @param args + */ + public static void main (String[] args) { + Application.launch(Main.class, args); + } +} diff --git a/src/main/java/ListCommand.java b/src/main/java/ListCommand.java new file mode 100644 index 0000000000..f2b21b98c6 --- /dev/null +++ b/src/main/java/ListCommand.java @@ -0,0 +1,21 @@ +import java.io.IOException; + +/** + * This class is initiased and its execute method is called whenever you want get all the tasks in the task list. + */ +public class ListCommand extends Command { + + + /** + * Lists all the tasks in the task list + * @param taskList + * @param ui + * @param storage + * @throws IOException + */ + @Override + public String execute(TaskList taskList, Ui ui, Storage storage) throws DukeException { + + return ui.list(taskList.list); + } +} diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..d2ffd5b4d2 --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: Duke + diff --git a/src/main/java/Main.java b/src/main/java/Main.java new file mode 100644 index 0000000000..0d8d97f0cc --- /dev/null +++ b/src/main/java/Main.java @@ -0,0 +1,30 @@ + +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(); + + @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(); + } + } +} \ No newline at end of file diff --git a/src/main/java/MainWindow.java b/src/main/java/MainWindow.java new file mode 100644 index 0000000000..25f3ea0f80 --- /dev/null +++ b/src/main/java/MainWindow.java @@ -0,0 +1,56 @@ +import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.scene.control.ScrollPane; +import javafx.scene.control.TextField; +import javafx.scene.image.Image; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.VBox; +/** + * Controller for MainWindow. Provides the layout for the other controls. + */ +public class MainWindow extends AnchorPane { + @FXML + private ScrollPane scrollPane; + @FXML + private VBox dialogContainer; + @FXML + private TextField userInput; + @FXML + private Button sendButton; + + private Duke duke; + + private Image userImage = new Image(this.getClass().getResourceAsStream("/images/DaUser.png")); + private Image dukeImage = new Image(this.getClass().getResourceAsStream("/images/DaDuke.png")); + + @FXML + public void initialize() { + scrollPane.vvalueProperty().bind(dialogContainer.heightProperty()); + } + + public void setDuke(Duke d) { + duke = d; + greetUser(); + } + + private void greetUser() { + dialogContainer.getChildren().addAll( + DialogBox.getDukeDialog(Ui.greeting(), dukeImage) + ); + } + + /** + * Creates two dialog boxes, one echoing user input and the other containing Duke's reply and then appends them to + * the dialog container. Clears the user input after processing. + */ + @FXML + private void handleUserInput() { + String input = userInput.getText(); + String response = duke.getResponse(input); + dialogContainer.getChildren().addAll( + DialogBox.getUserDialog(input, userImage), + DialogBox.getDukeDialog(response, dukeImage) + ); + userInput.clear(); + } +} \ No newline at end of file diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java new file mode 100644 index 0000000000..101830370f --- /dev/null +++ b/src/main/java/Parser.java @@ -0,0 +1,186 @@ +import java.util.DuplicateFormatFlagsException; + +/** + * This class deals with making sense of the user command + */ +public class Parser { + + /** + * Parses the input given by the user + * @param command The inputted text + * @return + * @throws DukeException + */ + public static Command parse (String command) throws DukeException { + + String[] words = command.split(" ", 2); + + Task task = null; + int index; + String text; + + switch (words[0]) { + case "todo": + task = Parser.parsesAdd(command, TaskType.TODO); + return new AddCommand(task); + case "deadline": + task = Parser.parsesAdd(command, TaskType.DEADLINE); + return new AddCommand(task); + case "event": + task = Parser.parsesAdd(command, TaskType.EVENT); + return new AddCommand(task); + case "done": + index = Parser.parsesDone(command); + return new DoneCommand(index); + case "delete": + index = Parser.parsesDelete(command); + return new DeleteCommand(index); + case "find": + text = Parser.parsesFind(command); + return new FindCommand(text); + + } + + switch (command) { + case "list": + return new ListCommand(); + case "bye": + return new ExitCommand(); + } + + throw new DukeException("☹ OOPS!!! I'm sorry, but I don't know what that means :-("); + + } + + /** + * Parses the done string and returns the index of the done task + * @param command done string + * @return index of done task + * @throws DukeException + */ + + private static String parsesFind(String command) throws DukeException { + + String[] words = command.split(" ", 2); + + if (words.length == 1) throw DukeException.emptyDescription(); + + if (words[1].isBlank()) throw DukeException.emptyDescription(); + + String text = words[1]; + + return text; + } + + /** + * parses the delete string to get the index of the Task to be deleted + * @param command delete string + * @return index of the task to be deleted + * @throws DukeException + */ + public static int parsesDelete (String command) throws DukeException { + + String[] words = command.split(" ", 2); + + if (words.length == 1) throw DukeException.emptyDescription(); + + if (words[1].isBlank()) throw DukeException.emptyDescription(); + + int index = Integer.valueOf(words[1]) - 1; + + return index; + + } + + public static int parsesDone (String command) throws DukeException { + + String[] words = command.split(" ", 2); + + if (words.length == 1) { + throw DukeException.emptyDescription(); + } + + if (words[1].isBlank()) { + throw DukeException.emptyDescription(); + } + + int index = Integer.valueOf(words[1]) - 1; + + return index; + + } + + /** + * Parses the add string and returns the task + * @param command add string + * @param taskType type of task (todo, event, deadline) + * @return The Task to be added + * @throws DukeException + */ + public static Task parsesAdd (String command, TaskType taskType) throws DukeException { + + String[] words = command.split(" ", 2); + + if (words.length == 1) { + throw DukeException.emptyDescription(); + } + + Task task = null; + + String description; + + switch (taskType) { + case TODO: + description = words[1]; + + if (description.isBlank()) { + throw DukeException.emptyDescription(); + } + + task = new Todo(description); + + break; + + case DEADLINE: + String[] split = words[1].split(" /by ", 2); + + if (split.length == 1) { + throw DukeException.emptyDescription(); + } + + description = split[0]; + String by = split[1]; + + if (description.isBlank() || by.isBlank()) { + throw DukeException.emptyDescription(); + } + + task = new Deadline(description, by); + + break; + + case EVENT: + split = words[1].split(" /at ", 2); + + if (split.length == 1) { + throw DukeException.emptyDescription(); + } + + description = split[0]; + String at = split[1]; + + if (description.isBlank() || at.isBlank()) { + throw DukeException.emptyDescription(); + } + + task = new Event(description, at); + + break; + + } + + return task; + + } + +} diff --git a/src/main/java/Parser.java.orig b/src/main/java/Parser.java.orig new file mode 100644 index 0000000000..101830370f --- /dev/null +++ b/src/main/java/Parser.java.orig @@ -0,0 +1,186 @@ +import java.util.DuplicateFormatFlagsException; + +/** + * This class deals with making sense of the user command + */ +public class Parser { + + /** + * Parses the input given by the user + * @param command The inputted text + * @return + * @throws DukeException + */ + public static Command parse (String command) throws DukeException { + + String[] words = command.split(" ", 2); + + Task task = null; + int index; + String text; + + switch (words[0]) { + case "todo": + task = Parser.parsesAdd(command, TaskType.TODO); + return new AddCommand(task); + case "deadline": + task = Parser.parsesAdd(command, TaskType.DEADLINE); + return new AddCommand(task); + case "event": + task = Parser.parsesAdd(command, TaskType.EVENT); + return new AddCommand(task); + case "done": + index = Parser.parsesDone(command); + return new DoneCommand(index); + case "delete": + index = Parser.parsesDelete(command); + return new DeleteCommand(index); + case "find": + text = Parser.parsesFind(command); + return new FindCommand(text); + + } + + switch (command) { + case "list": + return new ListCommand(); + case "bye": + return new ExitCommand(); + } + + throw new DukeException("☹ OOPS!!! I'm sorry, but I don't know what that means :-("); + + } + + /** + * Parses the done string and returns the index of the done task + * @param command done string + * @return index of done task + * @throws DukeException + */ + + private static String parsesFind(String command) throws DukeException { + + String[] words = command.split(" ", 2); + + if (words.length == 1) throw DukeException.emptyDescription(); + + if (words[1].isBlank()) throw DukeException.emptyDescription(); + + String text = words[1]; + + return text; + } + + /** + * parses the delete string to get the index of the Task to be deleted + * @param command delete string + * @return index of the task to be deleted + * @throws DukeException + */ + public static int parsesDelete (String command) throws DukeException { + + String[] words = command.split(" ", 2); + + if (words.length == 1) throw DukeException.emptyDescription(); + + if (words[1].isBlank()) throw DukeException.emptyDescription(); + + int index = Integer.valueOf(words[1]) - 1; + + return index; + + } + + public static int parsesDone (String command) throws DukeException { + + String[] words = command.split(" ", 2); + + if (words.length == 1) { + throw DukeException.emptyDescription(); + } + + if (words[1].isBlank()) { + throw DukeException.emptyDescription(); + } + + int index = Integer.valueOf(words[1]) - 1; + + return index; + + } + + /** + * Parses the add string and returns the task + * @param command add string + * @param taskType type of task (todo, event, deadline) + * @return The Task to be added + * @throws DukeException + */ + public static Task parsesAdd (String command, TaskType taskType) throws DukeException { + + String[] words = command.split(" ", 2); + + if (words.length == 1) { + throw DukeException.emptyDescription(); + } + + Task task = null; + + String description; + + switch (taskType) { + case TODO: + description = words[1]; + + if (description.isBlank()) { + throw DukeException.emptyDescription(); + } + + task = new Todo(description); + + break; + + case DEADLINE: + String[] split = words[1].split(" /by ", 2); + + if (split.length == 1) { + throw DukeException.emptyDescription(); + } + + description = split[0]; + String by = split[1]; + + if (description.isBlank() || by.isBlank()) { + throw DukeException.emptyDescription(); + } + + task = new Deadline(description, by); + + break; + + case EVENT: + split = words[1].split(" /at ", 2); + + if (split.length == 1) { + throw DukeException.emptyDescription(); + } + + description = split[0]; + String at = split[1]; + + if (description.isBlank() || at.isBlank()) { + throw DukeException.emptyDescription(); + } + + task = new Event(description, at); + + break; + + } + + return task; + + } + +} diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java new file mode 100644 index 0000000000..f885b81586 --- /dev/null +++ b/src/main/java/Storage.java @@ -0,0 +1,121 @@ +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Scanner; + +/** + * This class deals with loading tasks from the file and saving tasks in the file + */ +public class Storage { + + public String folderPath; + public String filePath; + + /** + * Initialises a Storage Class with a filePath and a folderPath + * @param filePath + * @param folderPath + */ + public Storage(String filePath, String folderPath) { + this.filePath = filePath; + this.folderPath = folderPath; + + } + + /** + * Makes the directory of the folder if it didn't exist before + * @param the folder path to make the directory + * @throws IOException + */ + public void makeDirectory (String folderPath) throws IOException { + File file = new File(folderPath); + file.mkdirs(); + } + + /** + * Saves the file in the specified filePath + * @param filePath specified filePath + * @param textToAdd the data (text) to save inside the file + * @throws IOException + */ + public void writeToFile(String filePath, String textToAdd) throws IOException { + FileWriter fw = new FileWriter(filePath); + fw.write(textToAdd); + fw.close(); + } + + /** + * Retrives the preivously saved tasks form the filePath + * @return Previously saved tasks + * @throws FileNotFoundException + */ + public ArrayList retrieve () throws FileNotFoundException { + + ArrayList list = new ArrayList<>(); + + File f = new File(filePath); // create a File for the given file path + Scanner s = new Scanner(f); // create a Scanner using the File as the source + + + while (s.hasNext()) { + String text = s.nextLine(); + + String[] split = text.split(" \\| "); + + String description = split[2]; + + Task t = null; + + switch (split[0]) { + case "T": + t = new Todo(description); + break; + case "D": + t = new Deadline(description, split[3]); + break; + case "E": + t = new Event(description, split[3]); + break; + } + + boolean isDone = split[1].equals("1"); + + if (t != null) { + t.isDone = isDone; + list.add(t); + } + } + + assert list.isEmpty() : "LIST SHOULD NOT BE EMPTY"; + + return list; + } + + /** + * Saves the Tasks in a file + * @param list The list of tasks to save + * @throws DukeException + */ + public void save (ArrayList list) throws DukeException { + + assert list.isEmpty() : "LIST SHOULD NOT BE EMPTY"; + + try { + + String s = ""; + + for (Task t : list) { + s += t.saveFormat() + System.lineSeparator(); + } + + this.writeToFile(filePath, s); + + } catch (IOException e) { + throw DukeException.couldNotSave(); + } + + } + +} \ No newline at end of file diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 0000000000..647f97e169 --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,49 @@ +/** + * Represents a task that the user has to do/attend + */ +public abstract class Task { + + protected String description; + protected boolean isDone; + + /** + * Initialises a Task object with a description + * @param description + */ + public Task(String description) { + this.description = description; + this.isDone = false; + } + + /** + * Gets the done status of the task + * @return + */ + public String getStatusIcon() { + return (isDone ? "\u2713" : "\u2718"); //return tick or X symbols + } + + /** + * Returns user-readable string of the task + * @return user-readable string + */ + @Override + public String toString () { + return "[" + getStatusIcon() + "]" + " " + this.description; + } + + /** + * Marks the current task's done status as true + */ + public void markAsDone () { + this.isDone = true; + } + + /** + * Formats the string so that it can be saved + * @return + */ + public abstract String saveFormat(); + + //... +} diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java new file mode 100644 index 0000000000..1858346923 --- /dev/null +++ b/src/main/java/TaskList.java @@ -0,0 +1,78 @@ +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.*; + +/** + * This class contains the task list e.g., it has operations to add/delete tasks in the list + */ +public class TaskList { + + protected ArrayList list; + + public TaskList (ArrayList list) { + this.list = list; + } + + public TaskList() { + this.list = new ArrayList(); + } + + /** + * Adds the task to the task list + * @param task The Task + */ + public void add (Task task) { + + assert task != null : "TASK SHOULD BE NON-NULL"; + + list.add(task); + } + + /** + * Marks the task as done + * @param index The Index of the Task + * @return + */ + public Task done (int index) throws DukeException { + + assert index >= 0 : "INDEX SHOULD BE GREATER THAN ZERO"; + + if (index < 0 || index > list.size()) throw DukeException.outOfBounds(); + + Task task = list.get(index); + task.markAsDone(); + + return task; + } + + /** + * Deletes a task + * @param index The index of the task + * @return The deleted task + */ + public Task delete (int index) throws DukeException { + + if (index < 0 || index > list.size()) throw DukeException.outOfBounds(); + + assert index >= 0 : "INDEX SHOULD BE GREATER THAN ZERO"; + + Task task = list.remove(index); + return task; + } + + public Task[] find(String text) { + + assert text.isBlank() : "TEXT SHOULD NOT BE BLANK"; + + ArrayList tasks = new ArrayList<>(); + + for (Task task : list) { + if (task.description.toLowerCase().contains(text.toLowerCase())) { + tasks.add(task); + } + } + + return tasks.toArray(new Task[tasks.size()]); + } +} diff --git a/src/main/java/TaskType.java b/src/main/java/TaskType.java new file mode 100644 index 0000000000..c06c49eedb --- /dev/null +++ b/src/main/java/TaskType.java @@ -0,0 +1,6 @@ +/** + * Represents different types of tasks + */ +public enum TaskType { + TODO, DEADLINE, EVENT; +} diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java new file mode 100644 index 0000000000..39fe509bf6 --- /dev/null +++ b/src/main/java/Todo.java @@ -0,0 +1,27 @@ +/** + * Represents a type of task + */ +public class Todo extends Task { + + public Todo (String description) { + super(description); + } + + /** + * Returns user-readable string + * @return user-readable string + */ + @Override + public String toString() { + return "[T]" + super.toString(); + } + + /** + * Returns formatted string used while saving + * @return formatted string + */ + @Override + public String saveFormat() { + return String.format("T | %d | %s", this.isDone ? 1 : 0, this.description); + } +} diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java new file mode 100644 index 0000000000..eb18bfdb8e --- /dev/null +++ b/src/main/java/Ui.java @@ -0,0 +1,94 @@ +import java.util.ArrayList; +import java.util.Scanner; + +/** + * This class deals with interactions with the user + */ +public class Ui { + + /** + * Greets the user + */ + public static String greeting () { + + return "Hello! I'm Duke\nWhat can I do for you?"; + } + + /** + * Bids farewell to the user + */ + public static String bye() { + return "Bye. Hope to see you again soon!"; + } + + + /** + * Lists all the Tasks to the user + */ + public String list (ArrayList list) { + + String text = "Here are the tasks in your list:\n"; + + for (int i = 0; i < list.size(); i++) { + text += i+1 + "." + list.get(i) +"\n"; + } + + return text; + } + + + /** + * Notifies user that a Task was added to the tasks list + * @param list + */ + public String add (ArrayList list) { + + return "Got it. I've added this task:\n" + list.get(list.size() - 1) + "\n" + String.format("Now you have %d tasks in the list.\n", list.size()); + } + + + /** + * Notifies the user that a task was deleted from the task list + * @param task list + * @param task Task that was deleted + */ + public String delete(ArrayList list, Task task) { + + return task + "\n" + String.format("Now you have %d tasks in the list.\n", list.size()); + } + + /** + * Notifies user that a task was completed (done status changed to true) + * @param task Task that was completed + */ + public String done(Task task) { + + return "Nice! I've marked this task as done:\n" + task; + } + + /** + * Shows an error to the user + * @param message The error message + */ + public String showError(String message) { + return message; + } + + /** + * Aborts the application + */ + public static String abort() { + return "SORRY SOMETHING WENT SERIOUSLY WRONG! \nGoodbye!"; + } + + public String find(Task[] matchedTasks) { + + String text = "Here are the matching tasks in your list:\n"; + + for (Task task : matchedTasks) { + text += task + "\n"; + } + + return text; + } +} diff --git a/src/main/java/Ui.java.orig b/src/main/java/Ui.java.orig new file mode 100644 index 0000000000..e006a6b72e --- /dev/null +++ b/src/main/java/Ui.java.orig @@ -0,0 +1,95 @@ +import java.util.ArrayList; +import java.util.Scanner; + +/** + * This class deals with interactions with the user + */ +public class Ui { + + private Scanner scanner = new Scanner(System.in); + + /** + * Greets the user + */ + public void greeting () { + System.out.println("Hello! I'm Duke\nWhat can I do for you?"); + } + + /** + * Bids farewell to the user + */ + public void bye() { + System.out.println("Bye. Hope to see you again soon!"); + } + + + /** + * Lists all the Tasks to the user + */ + public void list () { + System.out.println("Here are the tasks in your list:"); + } + + + /** + * Notifies user that a Task was added to the tasks list + * @param list + */ + public void add (ArrayList list) { + + System.out.println("Got it. I've added this task:"); + + System.out.println(list.get(list.size() - 1)); + + System.out.printf("Now you have %d tasks in the list.\n", list.size()); + + } + + + /** + * Notifies the user that a task was deleted from the task list + * @param task list + * @param task Task that was deleted + */ + public void delete(ArrayList list, Task task) { + + System.out.println(task); + + System.out.printf("Now you have %d tasks in the list.\n", list.size()); + } + + /** + * Notifies user that a task was completed (done status changed to true) + * @param task Task that was completed + */ + public void done(Task task) { + + System.out.println("Nice! I've marked this task as done:"); + + System.out.println(task); + } + + /** + * Shows an error to the user + * @param message The error message + */ + public void showError(String message) { + System.out.println(message); + } + + /** + * Reads input from the user + * @return The input read from the user + */ + public String readCommand() { + + return scanner.nextLine(); + } + + /** + * Aborts the application + */ + public void abort() { + System.out.println("SORRY SOMETHING WENT SERIOUSLY WRONG! \nGoodbye!"); + } +} 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/main/resources/view/DialogBox.fxml b/src/main/resources/view/DialogBox.fxml new file mode 100644 index 0000000000..e84aa9b73d --- /dev/null +++ b/src/main/resources/view/DialogBox.fxml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + diff --git a/src/main/resources/view/MainWindow.fxml b/src/main/resources/view/MainWindow.fxml new file mode 100644 index 0000000000..435f3ce0d8 --- /dev/null +++ b/src/main/resources/view/MainWindow.fxml @@ -0,0 +1,19 @@ + + + + + + + + + + + +