diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000000..cabb91563f --- /dev/null +++ b/build.gradle @@ -0,0 +1,59 @@ +plugins { + id 'java' + id 'application' + id 'com.github.johnrengelman.shadow' version '7.1.2' + id 'checkstyle' +} + +repositories { + mavenCentral() +} + +dependencies { + testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.10.0' + testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.10.0' + String javaFxVersion = '17.0.7' + implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'linux' + implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'linux' + implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'linux' + implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'win' + implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'mac' + implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'linux' + +} + + + +test { + useJUnitPlatform() + + testLogging { + events "passed", "skipped", "failed" + + showExceptions true + exceptionFormat "full" + showCauses true + showStackTraces true + showStandardStreams = false + } +} + +application { + mainClass.set("bing.Launcher") +} + +shadowJar { + archiveBaseName = 'bing' + archiveClassifier = null + archiveFileName = 'bing.jar' +} + +run { + standardInput = System.in +} diff --git a/data/tasks.txt b/data/tasks.txt new file mode 100644 index 0000000000..d4a22dc4e4 --- /dev/null +++ b/data/tasks.txt @@ -0,0 +1,4 @@ +T | 0 | read book +D | 1 | return book | 2/12/2019 1800 +T | 0 | assignment +E | 0 | function | 8/12/2024 1200 | 8/12/2024 1600 diff --git a/docs/README.md b/docs/README.md index 47b9f984f7..02068c7ff6 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,30 +1,161 @@ -# Duke User Guide +# Bing User Guide -// Update the title above to match the actual product name +![Product Screenshot](Ui.png) -// Product screenshot goes here +## Introduction -// Product intro goes here +Welcome to **Bing**, your personalised task management assistant. With Bing, you can effortlessly manage your tasks, deadlines, and events. Bing's intuitive commands help you stay organized and on top of your schedule, offering a clean interface for both storing, marking and finding tasks. -## Adding deadlines -// Describe the action and its outcome. +## Features -// Give examples of usage +### Viewing Tasks +Users can view the stored tasks using the command list +Example - +``` +list +``` +Expected output - +``` +______________________________ +All tasks in your list: +1. [T][] read book +______________________________ +``` + +### Adding ToDos +Users can add a ToDo task to the list using the commmand - todo [task name] +Example - +``` +todo assignment +``` +Expected output - +``` +______________________________ +All tasks in your list: +1. [T][] read book +2. [T][] assignment +______________________________ +``` + +### Adding Deadlines +Users can add a Deadline task to the list using the commmand - deadline [task name] /by [DD/MM/YYYY HHMM] +Example - +``` +deadline return book /by 08/12/2024 1600 +``` +Expected output - +``` +______________________________ +All tasks in your list: +1. [T][] read book +2. [T][] assignment +3. [D][] return book (by: Dec 2 2019 1800) +______________________________ +``` -Example: `keyword (optional arguments)` +### Adding Events +Users can add an Event to the list using the commmand - event [event name] /from [DD/MM/YYYY HHMM] /to [DD/MM/YYYY HHMM] +Example - +``` +event function /from 08/12/2024 1200 /to 08/12/2024 1600 +``` +Expected output - +``` +______________________________ +All tasks in your list: +1. [T][] read book +2. [T][] assignment +3. [D][] return book (by: Dec 2 2019 1800) +4. [E][] function (from: Dec 8 2024 1200 to: Dec 8 2024 1600) +______________________________ +``` -// A description of the expected outcome goes here +### Finding Tasks +Users can find a task in the list using the commmand - find [keyword] +Example - +``` +find book +``` +Expected output - +``` +______________________________ +All tasks in your list: +1. [T][] read book +2. [D][] return book (by: Dec 2 2019 1800) +______________________________ +``` +### Deleting Tasks +Users can delete a task in the list using the commmand - delete [task number] +Example - +``` +delete 1 ``` -expected output +Expected output - +``` +______________________________ +All tasks in your list: +1. [T][] assignment +2. [D][] return book (by: Dec 2 2019 1800) +3. [E][] function (from: Dec 8 2024 1200 to: Dec 8 2024 1600) +______________________________ ``` -## Feature ABC +### Marking Tasks +Users can mark a task as done in the list using the commmand - mark [task number] +Example - +``` +mark 1 +``` +Expected output - +``` +______________________________ +All tasks in your list: +1. [T][X] assignment +2. [D][] return book (by: Dec 2 2019 1800) +3. [E][] function (from: Dec 8 2024 1200 to: Dec 8 2024 1600) +______________________________ +``` -// Feature details +### Unmarking Tasks +Users can unmark a task in the list using the commmand - unmark [task number] +Example - +``` +unmark 1 +``` +Expected output - +``` +______________________________ +All tasks in your list: +1. [T][] assignment +2. [D][] return book (by: Dec 2 2019 1800) +3. [E][] function (from: Dec 8 2024 1200 to: Dec 8 2024 1600) +______________________________ +``` +### View statistics +Users can see statistics such as total tasks in the list, number of marked tasks in the list and number of unmarked tasks in the list using the command - stats +Example - +``` +stats +``` +Expected output - +``` +Total tasks : 3 +Marked tasks : 0 +Unmarked tasks : 0 +``` -## Feature XYZ +### Exiting application +Users can exit the application using the command - bye +Example - +``` +bye +``` +Expected output - +``` +Bye! +Have a good day ! +``` -// Feature details \ No newline at end of file diff --git a/docs/Ui.png b/docs/Ui.png new file mode 100644 index 0000000000..85811bf0b7 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..033e24c4cd 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..66c01cfeba --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000000..fcb6fca147 --- /dev/null +++ b/gradlew @@ -0,0 +1,248 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# 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 ;; #( + MSYS* | 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 + if ! command -v java >/dev/null 2>&1 + then + 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 +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000000..6689b85bee --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 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! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java deleted file mode 100644 index 5d313334cc..0000000000 --- a/src/main/java/Duke.java +++ /dev/null @@ -1,10 +0,0 @@ -public class Duke { - public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - } -} diff --git a/src/main/java/bing/Bing.java b/src/main/java/bing/Bing.java new file mode 100644 index 0000000000..b3c4bf2cc6 --- /dev/null +++ b/src/main/java/bing/Bing.java @@ -0,0 +1,90 @@ +package bing; + +import java.io.IOException; +import java.text.ParseException; + +import bing.storage.Storage; +import bing.command.*; +import bing.task.TaskList; +import bing.ui.Ui; +import bing.parser.Parser; +import bing.command.InvalidCommand; + +/** + * Bing is the main class that initializes and runs the task management system. + * It handles interactions between the user, storage, tasks, and parser. + */ +public class Bing { + + private Storage storage; + private TaskList tasks; + private Ui ui; + private Parser parser; + + + /** + * Initializes a new Bing instance and loads tasks from the specified file. + * + * @param filePath the path to the file where tasks are stored + */ + public Bing(String filePath) { + assert filePath != null : "File path cannot be null"; + ui = new Ui(); + storage = new Storage(filePath); + parser = new Parser(); + try { + tasks = new TaskList(storage.load()); + assert tasks != null : "Task list cannot be null."; + } catch (IOException e) { + ui.showError("Failed to load tasks."); + tasks = new TaskList(); + } + } + + /** + * Starts the task management system and processes user commands + */ + public void run() throws IOException { + ui.showWelcome(); + boolean isExit = false; + while (!isExit) { + String fullCommand = ui.readCommand(); + Command command = parser.parse(fullCommand); + assert command != null : "Parsed command cannot be null."; + command.execute(tasks, ui, storage); + isExit = command.isExit(); + } + } + + public String byeResponse(String input) throws ParseException { + if (input.equals("bye")) { + assert tasks != null : "Task list cannot be null."; + assert storage != null : "Storage cannot be null."; + try { + storage.save(tasks.getTasks()); + } catch (IOException e) { + return ui.showError("An error occurred while saving the data file: " + e.getMessage()); + } + return "Bye!" + "\n" + "Have a good day !"; + } + try { + Command command = parser.parse(input); + return command.execute(tasks, ui, storage); + } catch (Exception e) { + return ui.showError(e.getMessage()); + } + } + + public String getWelcomeMessage() { + return ui.showWelcome(); + } + + /** + * Main entry point for the application. + * + * @param args command-line arguments + */ + public static void main(String[] args) throws IOException{ + new Bing("./data/tasks.txt").run(); + } +} diff --git a/src/main/java/bing/DialogBox.java b/src/main/java/bing/DialogBox.java new file mode 100644 index 0000000000..39d3ba6f2f --- /dev/null +++ b/src/main/java/bing/DialogBox.java @@ -0,0 +1,56 @@ +package bing; + +import javafx.collections.FXCollections; +import javafx.geometry.Pos; +import javafx.scene.control.Label; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.layout.HBox; +import javafx.scene.shape.Circle; + + +public class DialogBox extends HBox{ + + private Label text; + private ImageView displayPicture; + + public DialogBox(String labelText, Image img, boolean isBot) { + assert labelText != null : "Label text cannot be null."; + assert img != null : "Image cannot be null."; + + text = new Label(labelText); + displayPicture = new ImageView(img); + text.setWrapText(true); + + displayPicture.setFitWidth(50.0); + displayPicture.setFitHeight(50.0); + displayPicture.setClip(new Circle(25, 25, 25)); + + + if (isBot) { + this.getChildren().addAll(displayPicture, text); + this.setAlignment(Pos.TOP_LEFT); + } else { + this.getChildren().addAll(text, displayPicture); + this.setAlignment(Pos.TOP_RIGHT); + } + } + + public static DialogBox getUserDialog(String input) { + return createDialog(input, "/images/user.png", Pos.TOP_RIGHT, false); + } + + public static DialogBox getBingDialog(String response) { + return createDialog(response, "/images/bot.png", Pos.TOP_LEFT, true); + } + + private static DialogBox createDialog(String input, String imagePath, Pos alignment, boolean isBot) { + Image img = new Image(imagePath); + if (img.isError()) { + System.out.println("Error loading image from: " + imagePath); + } + DialogBox dialog = new DialogBox(input, img, isBot); + dialog.setAlignment(alignment); + return dialog; + } +} diff --git a/src/main/java/bing/Launcher.java b/src/main/java/bing/Launcher.java new file mode 100644 index 0000000000..f44c7709b2 --- /dev/null +++ b/src/main/java/bing/Launcher.java @@ -0,0 +1,8 @@ +package bing; + +public class Launcher { + + public static void main(String[] args) { + Main.main(args); + } +} diff --git a/src/main/java/bing/Main.java b/src/main/java/bing/Main.java new file mode 100644 index 0000000000..26bc254087 --- /dev/null +++ b/src/main/java/bing/Main.java @@ -0,0 +1,33 @@ +package bing; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Scene; +import javafx.scene.layout.AnchorPane; +import javafx.stage.Stage; +import java.io.IOException; + +public class Main extends Application { + + private Bing bing = new Bing("data/tasks.txt"); + + @Override + public void start(Stage stage) { + try { + FXMLLoader fxmlLoader = new FXMLLoader(Main.class.getResource("/view/MainLayout.fxml")); + AnchorPane ap = fxmlLoader.load(); + Scene scene = new Scene(ap); + stage.setScene(scene); + stage.setTitle("Bing Chatbot"); + MainLayout controller = fxmlLoader.getController(); + controller.setBing(bing); + stage.show(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void main(String[] args) { + launch(args); + } +} \ No newline at end of file diff --git a/src/main/java/bing/MainLayout.java b/src/main/java/bing/MainLayout.java new file mode 100644 index 0000000000..b974173b22 --- /dev/null +++ b/src/main/java/bing/MainLayout.java @@ -0,0 +1,44 @@ +package bing; + +import javafx.fxml.FXML; +import javafx.scene.control.TextField; +import javafx.scene.layout.VBox; +import javafx.scene.control.Button; +import javafx.scene.control.ScrollPane; + +public class MainLayout { + + private Bing bing; + + @FXML + private ScrollPane scrollPane; + @FXML + private VBox dialogContainer; + @FXML + private TextField userInput; + @FXML + private Button sendButton; + + @FXML + public void initialize() { + scrollPane.vvalueProperty().bind(dialogContainer.heightProperty()); + } + + public void setBing(Bing b) { + bing = b; + String welcomeMessage = bing.getWelcomeMessage(); + dialogContainer.getChildren().add(DialogBox.getBingDialog(welcomeMessage)); + } + + @FXML + private void handleUserInput() throws Exception { + String input = userInput.getText(); + assert input != null && !input.trim().isEmpty() : "User input cannot be empty."; + String response = bing.byeResponse(input); + dialogContainer.getChildren().addAll( + DialogBox.getUserDialog(input), + DialogBox.getBingDialog(response) + ); + userInput.clear(); + } +} diff --git a/src/main/java/bing/command/AddCommand.java b/src/main/java/bing/command/AddCommand.java new file mode 100644 index 0000000000..3f33243e1d --- /dev/null +++ b/src/main/java/bing/command/AddCommand.java @@ -0,0 +1,52 @@ +package bing.command; + +import bing.storage.Storage; +import bing.task.Task; +import bing.task.TaskList; +import bing.ui.Ui; + +import java.io.IOException; + + +/** + * Represents a command that adds a task to the task list. + */ +public abstract class AddCommand implements Command { + + protected final Task task; + + + /** + * Constructs an AddCommand with the given task. + * + * @param task the task to be added + */ + public AddCommand(Task task) { + this.task = task; + } + + /** + * Executes the command by adding the task, displaying the tasks, and saving them. + * + * @param tasks the list of tasks + * @param ui the user interface + * @param storage the storage for tasks + */ + @Override + public String execute(TaskList tasks, Ui ui, Storage storage) throws IOException{ + tasks.addTask(task); + storage.save(tasks.getTasks()); + return ui.showTasks(tasks); + + } + + /** + * Returns whether this command causes the application to exit (it does not). + * + * @return false + */ + @Override + public boolean isExit() { + return false; + } +} diff --git a/src/main/java/bing/command/ByeCommand.java b/src/main/java/bing/command/ByeCommand.java new file mode 100644 index 0000000000..60e10788c6 --- /dev/null +++ b/src/main/java/bing/command/ByeCommand.java @@ -0,0 +1,36 @@ +package bing.command; + +import bing.storage.Storage; +import bing.task.TaskList; +import bing.ui.Ui; + +import java.io.IOException; + +/** + * Represents a command to terminate the program. + */ +public class ByeCommand implements Command { + + /** + * Executes the command, which prints the exit message and terminates the program. + * + * @param tasks The list of tasks to operate on. + * @param ui The user interface to interact with the user. + * @param storage The storage to save or load tasks. + */ + @Override + public String execute(TaskList tasks, Ui ui, Storage storage) throws IOException { + // Print the exit message directly + return ui.showByeMessage(); + } + + /** + * Indicates that this command causes the program to terminate. + * + * @return true, as this command results in program termination. + */ + @Override + public boolean isExit() { + return true; // Indicates that the program should terminate + } +} diff --git a/src/main/java/bing/command/Command.java b/src/main/java/bing/command/Command.java new file mode 100644 index 0000000000..17bc654ba0 --- /dev/null +++ b/src/main/java/bing/command/Command.java @@ -0,0 +1,30 @@ +package bing.command; + +import bing.storage.Storage; +import bing.task.TaskList; +import bing.ui.Ui; + +import java.io.IOException; + +/** + * Represents command that can be executed in the task management system. + */ +public interface Command { + + /** + * Executes the command with the given task list, UI, and storage. + * + * @param tasks the list of tasks + * @param ui the user interface + * @param storage the storage for tasks + */ + String execute(TaskList tasks, Ui ui, Storage storage) throws IOException; + + + /** + * Returns whether this command causes the application to exit. + * + * @return true if the application should exit, false otherwise + */ + boolean isExit(); +} diff --git a/src/main/java/bing/command/DeadlineCommand.java b/src/main/java/bing/command/DeadlineCommand.java new file mode 100644 index 0000000000..451fa60468 --- /dev/null +++ b/src/main/java/bing/command/DeadlineCommand.java @@ -0,0 +1,21 @@ +package bing.command; + +import bing.task.Deadline; +import java.time.LocalDateTime; + +/** + * Represents a command to add a Deadline task. + */ +public class DeadlineCommand extends AddCommand { + + /** + * Constructs a DeadlineCommand with the given task information and deadline. + * + * @param info the task description + * @param deadline the deadline for the task + */ + public DeadlineCommand(String info, LocalDateTime deadline) { + super(new Deadline(info, deadline)); + } + +} diff --git a/src/main/java/bing/command/DeleteCommand.java b/src/main/java/bing/command/DeleteCommand.java new file mode 100644 index 0000000000..41f0a7f5b4 --- /dev/null +++ b/src/main/java/bing/command/DeleteCommand.java @@ -0,0 +1,50 @@ +package bing.command; + +import bing.storage.Storage; +import bing.task.Task; +import bing.task.TaskList; +import bing.ui.Ui; +import java.io.IOException; + + +/** + * Represents a command to delete a task from the list. + */ +public class DeleteCommand implements Command { + private int index; + + /** + * Constructs a DeleteCommand with the specified index. + * + * @param index The index of the task to delete. + */ + public DeleteCommand(int index) { + this.index = index; + } + + /** + * Executes the command by deleting the task at the specified index, + * updating the user interface, and saving the changes to storage. + * + * @param tasks The list of tasks to operate on. + * @param ui The user interface to interact with the user. + * @param storage The storage to save or load tasks. + */ + @Override + public String execute(TaskList tasks, Ui ui, Storage storage) throws IOException { + Task task = tasks.get(index); + tasks.deleteTask(index); + storage.save(tasks.getTasks()); + return ui.showTasks(tasks); + } + + /** + * Indicates that this command does not cause the program to terminate. + * + * @return false, as this command does not result in program termination. + */ + @Override + public boolean isExit() { + return false; + } +} diff --git a/src/main/java/bing/command/EventCommand.java b/src/main/java/bing/command/EventCommand.java new file mode 100644 index 0000000000..9a5210e8a3 --- /dev/null +++ b/src/main/java/bing/command/EventCommand.java @@ -0,0 +1,21 @@ +package bing.command; + +import bing.task.Event; +import java.time.LocalDateTime; + +/** + * Represents a command to add an Event task. + */ +public class EventCommand extends AddCommand { + + /** + * Constructs an EventCommand with the specified information, start time, and end time. + * + * @param info The description of the event. + * @param from The start time of the event. + * @param to The end time of the event. + */ + public EventCommand(String info, LocalDateTime from, LocalDateTime to) { + super(new Event(info, from, to)); + } +} diff --git a/src/main/java/bing/command/FindCommand.java b/src/main/java/bing/command/FindCommand.java new file mode 100644 index 0000000000..a40f053294 --- /dev/null +++ b/src/main/java/bing/command/FindCommand.java @@ -0,0 +1,27 @@ +package bing.command; + +import bing.storage.Storage; +import bing.task.TaskList; +import bing.ui.Ui; + +import java.io.IOException; + +public class FindCommand implements Command { + + private String keyword; + + public FindCommand(String keyword) { + this.keyword = keyword; + } + + @Override + public String execute(TaskList tasks, Ui ui, Storage storage) throws IOException { + TaskList matchingTasks = tasks.findTasksByKeyword(keyword); + return ui.showTasks(matchingTasks); + } + + @Override + public boolean isExit() { + return false; + } +} diff --git a/src/main/java/bing/command/InvalidCommand.java b/src/main/java/bing/command/InvalidCommand.java new file mode 100644 index 0000000000..850dffa8e8 --- /dev/null +++ b/src/main/java/bing/command/InvalidCommand.java @@ -0,0 +1,35 @@ +package bing.command; + +import bing.storage.Storage; +import bing.task.TaskList; +import bing.ui.Ui; + +import java.io.IOException; + +/** + * Represents a command that indicates an invalid command input. + */ +public class InvalidCommand implements Command { + + /** + * Executes the command by displaying an error message for invalid commands. + * + * @param tasks The list of tasks to operate on. + * @param ui The user interface to interact with the user. + * @param storage The storage to save or load tasks. + */ + @Override + public String execute(TaskList tasks, Ui ui, Storage storage) throws IOException { + return ui.showError("Invalid command!"); + } + + /** + * Indicates that this command does not cause the program to terminate. + * + * @return false, as this command does not result in program termination. + */ + @Override + public boolean isExit() { + return false; + } +} diff --git a/src/main/java/bing/command/ListCommand.java b/src/main/java/bing/command/ListCommand.java new file mode 100644 index 0000000000..d798b8e7d9 --- /dev/null +++ b/src/main/java/bing/command/ListCommand.java @@ -0,0 +1,35 @@ +package bing.command; + +import bing.storage.Storage; +import bing.task.TaskList; +import bing.ui.Ui; + +import java.io.IOException; + +/** + * Represents a command to list all tasks. + */ +public class ListCommand implements Command { + + /** + * Executes the command by displaying the list of tasks. + * + * @param tasks The list of tasks to operate on. + * @param ui The user interface to interact with the user. + * @param storage The storage to save or load tasks. + */ + @Override + public String execute(TaskList tasks, Ui ui, Storage storage) throws IOException { + return ui.showTasks(tasks); + } + + /** + * Indicates that this command does not cause the program to terminate. + * + * @return false, as this command does not result in program termination. + */ + @Override + public boolean isExit() { + return false; + } +} diff --git a/src/main/java/bing/command/MarkCommand.java b/src/main/java/bing/command/MarkCommand.java new file mode 100644 index 0000000000..f7744e4470 --- /dev/null +++ b/src/main/java/bing/command/MarkCommand.java @@ -0,0 +1,50 @@ +package bing.command; + +import bing.storage.Storage; +import bing.task.Task; +import bing.task.TaskList; +import bing.task.TaskStatus; +import bing.ui.Ui; +import java.io.IOException; + +/** + * Represents a command to mark a task as done. + */ +public class MarkCommand implements Command { + private int index; + + /** + * Constructs a MarkCommand with the specified index. + * + * @param index The index of the task to mark as done. + */ + public MarkCommand(int index) { + this.index = index; + } + + /** + * Executes the command by marking the task at the specified index as done, + * updating the user interface, and saving the changes to storage. + * + * @param tasks The list of tasks to operate on. + * @param ui The user interface to interact with the user. + * @param storage The storage to save or load tasks. + */ + @Override + public String execute(TaskList tasks, Ui ui, Storage storage) throws IOException{ + Task task = tasks.get(index); + task.setStatus(TaskStatus.DONE); + storage.save(tasks.getTasks()); + return ui.showTasks(tasks); + } + + /** + * Indicates that this command does not cause the program to terminate. + * + * @return false, as this command does not result in program termination. + */ + @Override + public boolean isExit() { + return false; + } +} diff --git a/src/main/java/bing/command/StatsCommand.java b/src/main/java/bing/command/StatsCommand.java new file mode 100644 index 0000000000..36ff7e376a --- /dev/null +++ b/src/main/java/bing/command/StatsCommand.java @@ -0,0 +1,18 @@ +package bing.command; + +import bing.ui.*; +import bing.storage.*; +import bing.task.*; + +public class StatsCommand implements Command { + + @Override + public String execute(TaskList tasks, Ui ui, Storage storage) { + return ui.showStatistics(tasks); + } + + @Override + public boolean isExit() { + return false; + } +} diff --git a/src/main/java/bing/command/ToDoCommand.java b/src/main/java/bing/command/ToDoCommand.java new file mode 100644 index 0000000000..2bf5cb800f --- /dev/null +++ b/src/main/java/bing/command/ToDoCommand.java @@ -0,0 +1,18 @@ +package bing.command; + +import bing.task.ToDo; + +/** + * Represents a command to add a ToDo task. + */ +public class ToDoCommand extends AddCommand { + + /** + * Constructs a ToDoCommand with the specified task information. + * + * @param info The description of the ToDo task. + */ + public ToDoCommand(String info) { + super(new ToDo(info)); + } +} diff --git a/src/main/java/bing/command/UnmarkCommand.java b/src/main/java/bing/command/UnmarkCommand.java new file mode 100644 index 0000000000..ff287ae696 --- /dev/null +++ b/src/main/java/bing/command/UnmarkCommand.java @@ -0,0 +1,51 @@ +package bing.command; + +import bing.storage.Storage; +import bing.task.Task; +import bing.task.TaskList; +import bing.task.TaskStatus; +import bing.ui.Ui; +import java.io.IOException; + + +/** + * Represents a command to unmark a task as undone. + */ +public class UnmarkCommand implements Command { + private int index; + + /** + * Constructs an UnmarkCommand with the specified index. + * + * @param index The index of the task to unmark as undone. + */ + public UnmarkCommand(int index) { + this.index = index; + } + + /** + * Executes the command by marking the task at the specified index as undone, + * updating the user interface, and saving the changes to storage. + * + * @param tasks The list of tasks to operate on. + * @param ui The user interface to interact with the user. + * @param storage The storage to save or load tasks. + */ + @Override + public String execute(TaskList tasks, Ui ui, Storage storage) throws IOException { + Task task = tasks.get(index); + task.setStatus(TaskStatus.UNDONE); + storage.save(tasks.getTasks()); + return ui.showTasks(tasks); + } + + /** + * Indicates that this command does not cause the program to terminate. + * + * @return false, as this command does not result in program termination. + */ + @Override + public boolean isExit() { + return false; + } +} diff --git a/src/main/java/bing/parser/Parser.java b/src/main/java/bing/parser/Parser.java new file mode 100644 index 0000000000..838443a0b9 --- /dev/null +++ b/src/main/java/bing/parser/Parser.java @@ -0,0 +1,123 @@ +package bing.parser; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; +import bing.command.*; +import java.util.Arrays; + +/** + * Parses user input commands into appropriate Command objects. + */ +public class Parser { + + private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("d/M/yyyy HHmm"); + + /** + * Parses the input string and returns the corresponding Command object. + * + * @param input The user input string to be parsed. + * @return A Command object representing the user's command. Returns an InvalidCommand + * if the command type is unknown or if parsing fails. + */ + public Command parse(String input) { + String[] tokens = input.split(" ", 2); // Split into command and rest + String commandType = tokens[0]; + String details = tokens.length > 1 ? tokens[1] : ""; + + switch (commandType) { + case "bye": + return new ByeCommand(); + case "list": + return new ListCommand(); + case "mark": + try { + int markIndex = Integer.parseInt(details) - 1; + return new MarkCommand(markIndex); + } catch (NumberFormatException e) { + return new InvalidCommand(); + } + case "unmark": + try { + int unmarkIndex = Integer.parseInt(details) - 1; + return new UnmarkCommand(unmarkIndex); + } catch (NumberFormatException e) { + return new InvalidCommand(); + } + case "delete": + try { + int deleteIndex = Integer.parseInt(details) - 1; + return new DeleteCommand(deleteIndex); + } catch (NumberFormatException e) { + return new InvalidCommand(); + } + case "todo": + return new ToDoCommand(details.trim()); // Extract task info + case "deadline": + return parseDeadline(details); + case "event": + return parseEvent(details); + case "find": + return new FindCommand(details.trim()); + case "stats": + return new StatsCommand(); + default: + return new InvalidCommand(); + } + } + + /** + * Parses the details of a deadline command and returns a DeadlineCommand object. + * + * @param details The details string for the deadline command, expected to contain + * task description and deadline. + * @return A DeadlineCommand object representing the deadline task. Returns an + * InvalidCommand if the details are malformed or parsing fails. + */ + private Command parseDeadline(String details) { + String[] parts = details.split(" /by "); + if (parts.length < 2) { + return new InvalidCommand(); + } + String taskInfo = parts[0].trim(); + String dateStr = parts[1].trim(); + + try { + LocalDateTime deadline = LocalDateTime.parse(dateStr, DATE_TIME_FORMATTER); + return new DeadlineCommand(taskInfo, deadline); + } catch (DateTimeParseException e) { + return new InvalidCommand(); + } + } + + /** + * Parses the details of an event command and returns an EventCommand object. + * + * @param details The details string for the event command, expected to contain + * task description, start time, and end time. + * @return An EventCommand object representing the event task. Returns an InvalidCommand + * if the details are malformed or parsing fails. + */ + private Command parseEvent(String details) { + String[] parts = details.split(" /from "); + if (parts.length < 2) { + return new InvalidCommand(); + } + String taskInfo = parts[0].trim(); + String[] dateParts = parts[1].split(" /to "); + if (dateParts.length < 2) { + return new InvalidCommand(); + } + String fromStr = dateParts[0].trim(); + String toStr = dateParts[1].trim(); + + try { + LocalDateTime from = LocalDateTime.parse(fromStr, DATE_TIME_FORMATTER); + LocalDateTime to = LocalDateTime.parse(toStr, DATE_TIME_FORMATTER); + return new EventCommand(taskInfo, from, to); + } catch (DateTimeParseException e) { + return new InvalidCommand(); + } + } + +} diff --git a/src/main/java/bing/storage/Storage.java b/src/main/java/bing/storage/Storage.java new file mode 100644 index 0000000000..70b1198b33 --- /dev/null +++ b/src/main/java/bing/storage/Storage.java @@ -0,0 +1,104 @@ +package bing.storage; + +import bing.task.*; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.Scanner; + +/** + * Handles the loading and saving of tasks to a file. + */ +public class Storage { + private String filePath; + + /** + * Constructs a Storage object with the specified file path. + * + * @param filePath the path of the file where tasks will be stored + */ + public Storage(String filePath) { + this.filePath = filePath; + } + + /** + * Loads tasks from the file. + * + * @return the list of tasks loaded from the file + * @throws IOException if an error occurs while reading the file + */ + public ArrayList load() throws IOException { + ArrayList tasks = new ArrayList<>(); + File file = new File(filePath); + if (!file.exists()) { + file.getParentFile().mkdirs(); + return tasks; + } + + Scanner scanner = new Scanner(file); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d/M/yyyy HHmm"); + + while (scanner.hasNextLine()) { + String line = scanner.nextLine(); + String[] parts = line.split(" \\| "); + + // Check if the line has at least 3 parts + if (parts.length < 3) { + continue; // Skip lines that don't have enough parts + } + + String taskType = parts[0]; + String status = parts[1]; + String info = parts[2]; + + Task task; + + switch (taskType) { + case "T": + task = new ToDo(info); + break; + case "D": + if (parts.length < 4) { + continue; // Skip lines that don't have enough parts for Deadline tasks + } + LocalDateTime deadline = LocalDateTime.parse(parts[3], formatter); + task = new Deadline(info, deadline); + break; + case "E": + if (parts.length < 5) { + continue; // Skip lines that don't have enough parts for Event tasks + } + LocalDateTime from = LocalDateTime.parse(parts[3], formatter); + LocalDateTime to = LocalDateTime.parse(parts[4], formatter); + task = new Event(info, from, to); + break; + default: + continue; // Skip lines with invalid task type + } + + task.setStatus(status.equals("1") ? TaskStatus.DONE : TaskStatus.UNDONE); + tasks.add(task); + } + + scanner.close(); + return tasks; + } + + /** + * Saves the list of tasks to the file. + * + * @param tasks the list of tasks to be saved + * @throws IOException if an error occurs while writing to the file + */ + public void save(ArrayList tasks) throws IOException { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d/M/yyyy HHmm"); + FileWriter writer = new FileWriter(filePath); + for (Task task : tasks) { + writer.write(task.toFileFormat(formatter) + "\n"); + } + writer.close(); + } +} diff --git a/src/main/java/bing/task/Deadline.java b/src/main/java/bing/task/Deadline.java new file mode 100644 index 0000000000..58f4b5dcc0 --- /dev/null +++ b/src/main/java/bing/task/Deadline.java @@ -0,0 +1,47 @@ +package bing.task; + +import bing.task.Task; +import bing.task.TaskStatus; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +/** + * Represents a task with a deadline. + */ +public class Deadline extends Task { + private LocalDateTime deadline; + + /** + * Constructs a Deadline task with the specified information and deadline. + * + * @param info The description of the task. + * @param deadline The deadline for the task. + */ + public Deadline(String info, LocalDateTime deadline) { + super(info); + this.deadline = deadline; + } + + /** + * Returns a string representation of the Deadline task. + * + * @return A string that describes the Deadline task in a human-readable format, + * including its status, description, and deadline. + */ + @Override + public String toString() { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM d yyyy HHmm"); + return "[D]" + "[" + getStatus().getStatusSymbol() + "]" + " " + getInfo() + " (by: " + deadline.format(formatter) + ")"; + } + + /** + * Returns a string representation of the Deadline task in a format suitable for file storage. + * + * @param formatter The DateTimeFormatter used to format the deadline. + * @return A string that represents the Deadline task in a format suitable for saving to a file. + */ + @Override + public String toFileFormat(DateTimeFormatter formatter) { + return "D | " + (getStatus() == TaskStatus.DONE ? "1" : "0") + " | " + getInfo() + " | " + deadline.format(formatter); + } +} diff --git a/src/main/java/bing/task/Event.java b/src/main/java/bing/task/Event.java new file mode 100644 index 0000000000..6517a3d05b --- /dev/null +++ b/src/main/java/bing/task/Event.java @@ -0,0 +1,50 @@ +package bing.task; + +import bing.task.Task; +import bing.task.TaskStatus; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +/** + * Represents a task with a time period between a start and end time. + */ +public class Event extends Task { + private LocalDateTime from; + private LocalDateTime to; + private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM d yyyy HHmm"); + + /** + * Constructs an Event task with the specified information, start time, and end time. + * + * @param info The description of the task. + * @param from The start time of the event. + * @param to The end time of the event. + */ + public Event(String info, LocalDateTime from, LocalDateTime to) { + super(info); + this.from = from; + this.to = to; + } + + /** + * Returns a string representation of the Event task. + * + * @return A string that describes the Event task in a human-readable format, + * including its status, description, and time period. + */ + @Override + public String toString() { + return "[E]" + "[" + getStatus().getStatusSymbol() + "]" + " " + getInfo() + " (from: " + from.format(formatter) + " to: " + to.format(formatter) + ")"; + } + + /** + * Returns a string representation of the Event task in a format suitable for file storage. + * + * @param formatter The DateTimeFormatter used to format the start and end times. + * @return A string that represents the Event task in a format suitable for saving to a file. + */ + @Override + public String toFileFormat(DateTimeFormatter formatter) { + return "E | " + (getStatus() == TaskStatus.DONE ? "1" : "0") + " | " + getInfo() + " | " + from.format(formatter) + " | " + to.format(formatter); + } +} diff --git a/src/main/java/bing/task/Task.java b/src/main/java/bing/task/Task.java new file mode 100644 index 0000000000..7142cbafdb --- /dev/null +++ b/src/main/java/bing/task/Task.java @@ -0,0 +1,64 @@ +package bing.task; + +import java.time.format.DateTimeFormatter; + +/** + * Represents a task with a description and status (done or not done). + */ +public abstract class Task { + private String info; + private TaskStatus isDone; + + + /** + * Constructs a Task with the given description. + * + * @param info the description of the task + */ + public Task(String info) { + this.info = info; + this.isDone = TaskStatus.UNDONE; + } + + /** + * Returns the description of the task. + * + * @return the task description + */ + public String getInfo() { + return info; + } + + /** + * Returns the status of the task (done or not done). + * + * @return the task status + */ + public TaskStatus getStatus() { + return isDone; + } + + /** + * Sets the status of the task to done or not done. + * + * @param status the new task status + */ + public void setStatus(TaskStatus status) { + this.isDone = status; + } + + /** + * Returns a string representation of the task. + * + * @return the task as a string + */ + public abstract String toString(); + + /** + * Returns the task in a format suitable for saving to a file. + * + * @param formatter the DateTimeFormatter for formatting date and time + * @return the task in file format + */ + public abstract String toFileFormat(DateTimeFormatter formatter); +} diff --git a/src/main/java/bing/task/TaskList.java b/src/main/java/bing/task/TaskList.java new file mode 100644 index 0000000000..6b9d7a29a7 --- /dev/null +++ b/src/main/java/bing/task/TaskList.java @@ -0,0 +1,134 @@ +package bing.task; + +import java.util.ArrayList; +import bing.task.Task; +import bing.task.TaskStatus; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * Represents a list of tasks. + */ +public class TaskList { + + private ArrayList tasks; + + /** + * Constructs an empty TaskList. + */ + public TaskList() { + tasks = new ArrayList<>(); + } + + + /** + * Constructs a TaskList with a list of tasks. + * + * @param tasks the list of tasks to initialize the TaskList with + */ + public TaskList(ArrayList tasks) { + this.tasks = tasks; + } + + + /** + * Adds a task to the list. + * + * @param task the task to be added + */ + public void addTask(Task task) { + tasks.add(task); + } + + + /** + * Returns the task at the specified index. + * + * @param index the index of the task + * @return the task at the specified index + */ + public Task get(int index) { + return tasks.get(index); + } + + + /** + * Deletes the task at the specified index. + * + * @param index the index of the task to be deleted + */ + public void deleteTask(int index) { + tasks.remove(index); + } + + + /** + * Returns the number of tasks in the list. + * + * @return the size of the task list + */ + public int size() { + return tasks.size(); + } + + + /** + * Returns the list of tasks. + * + * @return the list of tasks + */ + public ArrayList getTasks() { + return tasks; + } + + public TaskList findTasksByKeyword(String keyword) { + ArrayList matchingTasks = new ArrayList<>(); + for (Task task : tasks) { + if (task.getInfo().contains(keyword)) { + matchingTasks.add(task); + } + } + return new TaskList(matchingTasks); + } + + public String getTotalTasks() { + return String.valueOf(tasks.size()); + } + + public String getUnmarkedTasks() { + int count = 0; + for (Task task : tasks) { + if (task.getStatus() == TaskStatus.DONE) { + count++; + } + } + return String.valueOf(count); + } + + public String getMarkedTasks() { + int count = 0; + for (Task task : tasks) { + if (task.getStatus() == TaskStatus.UNDONE) { + count++; + } + } + return String.valueOf(count); + } + + public Map getTaskBreakdownByType() { + return tasks.stream().collect(Collectors.groupingBy( + task -> { + if (task instanceof ToDo) { + return "ToDo"; + } else if (task instanceof Deadline) { + return "Deadline"; + } else if (task instanceof Event) { + return "Event"; + } + return "Unknown"; + }, + Collectors.counting() + )); + } +} diff --git a/src/main/java/bing/task/TaskStatus.java b/src/main/java/bing/task/TaskStatus.java new file mode 100644 index 0000000000..acd32f0089 --- /dev/null +++ b/src/main/java/bing/task/TaskStatus.java @@ -0,0 +1,33 @@ +package bing.task; + +/** + * Represents the status of a task (done or not done). + */ +public enum TaskStatus { + DONE("X"), + UNDONE(" "); + + private String StatusSymbol; + + + /** + * Constructs a TaskStatus with the corresponding status symbol. + * + * @param StatusSymbol the symbol representing the task's status + */ + TaskStatus(String StatusSymbol) { + this.StatusSymbol = StatusSymbol; + } + + + /** + * Returns the symbol representing the task's status. + * + * @return the status symbol + */ + public String getStatusSymbol() { + return this.StatusSymbol; + } + + +} diff --git a/src/main/java/bing/task/ToDo.java b/src/main/java/bing/task/ToDo.java new file mode 100644 index 0000000000..8c5b60d95e --- /dev/null +++ b/src/main/java/bing/task/ToDo.java @@ -0,0 +1,41 @@ +package bing.task; + +import bing.task.Task; +import bing.task.TaskStatus; + +import java.time.format.DateTimeFormatter; +/** + * Represents a ToDo task. + */ +public class ToDo extends Task { + + /** + * Constructs a ToDo task with the given description. + * + * @param info the description of the task + */ + public ToDo(String info) { + super(info); + } + + /** + * Returns the string representation of the ToDo task. + * + * @return the ToDo task as a string + */ + @Override + public String toString() { + return "[T]" + "[" + getStatus().getStatusSymbol() + "]" + " " + getInfo(); + } + + /** + * Returns the ToDo task in a format suitable for saving to a file. + * + * @param formatter the DateTimeFormatter (not used for ToDo tasks) + * @return the ToDo task in file format + */ + @Override + public String toFileFormat(DateTimeFormatter formatter) { + return "T | " + (getStatus() == TaskStatus.DONE ? "1" : "0") + " | " + getInfo(); + } +} \ No newline at end of file diff --git a/src/main/java/bing/ui/Ui.java b/src/main/java/bing/ui/Ui.java new file mode 100644 index 0000000000..ba4fbe49dd --- /dev/null +++ b/src/main/java/bing/ui/Ui.java @@ -0,0 +1,88 @@ +package bing.ui; + +import java.util.Scanner; +import bing.task.TaskList; +import java.util.Map; + + +/** + * Handles interactions with the user. + */ +public class Ui { + + private Scanner scanner = new Scanner(System.in); + + /** + * Reads and returns the next command from the user. + * + * @return the command entered by the user + */ + public String readCommand() { + return scanner.nextLine(); + } + + /** + * Displays a welcome message to the user. + */ + + Boolean run_once = false; + + public String showWelcome() { + + return "______________________________" + "\n" + + "Hi! My name is Bing" + "\n" + + "How can I help you?" + "\n" + + "______________________________"; + } + + /** + * Displays a goodbye message to the user. + */ + public String showBye() { + return "______________________________" + "\n" + + "Bye. Have a good day." + "\n" + + "______________________________"; + } + + /** + * Displays a goodbye message to the user. + */ + public String showByeMessage() { + return "______________________________\n" + + "Bye. Have a good day.\n" + + "______________________________\n"; + } + + /** + * Displays all tasks in the task list. + * + * @param taskList the list of tasks to display + */ + public String showTasks(TaskList taskList) { + String ans = ""; + ans = ans + "______________________________\n"; + ans = ans + "All tasks in your list:\n"; + for (int i = 0; i < taskList.size(); i++) { + ans = ans + (i + 1) + ". " + taskList.get(i).toString() + "\n"; + } + ans = ans + "______________________________"; + return ans; + } + + /** + * Displays an error message. + * + * @param message the error message to display + */ + public String showError(String message) { + return "Error: " + message; + } + + public String showStatistics(TaskList tasks) { + return "Total tasks: " + tasks.getTotalTasks() + "\n" + + "Marked tasks: " + tasks.getMarkedTasks() + "\n" + + "Unmarked tasks: " + tasks.getUnmarkedTasks(); + + } + +} diff --git a/src/main/resources/images/bot.png b/src/main/resources/images/bot.png new file mode 100644 index 0000000000..240675671b Binary files /dev/null and b/src/main/resources/images/bot.png differ diff --git a/src/main/resources/images/user.png b/src/main/resources/images/user.png new file mode 100644 index 0000000000..c2a0db919b Binary files /dev/null and b/src/main/resources/images/user.png differ diff --git a/src/main/resources/view/MainLayout.fxml b/src/main/resources/view/MainLayout.fxml new file mode 100644 index 0000000000..261a9932d1 --- /dev/null +++ b/src/main/resources/view/MainLayout.fxml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + +