diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000000..386c72f40a --- /dev/null +++ b/build.gradle @@ -0,0 +1,56 @@ +plugins { + id 'java' + id 'application' + id 'com.github.johnrengelman.shadow' version '7.1.2' +} + +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("Skye.classes.Skye") +} + +shadowJar { + archiveBaseName = "skye" + archiveClassifier = null + archiveFileName = 'skye.jar' +} + +run{ + standardInput = System.in +} diff --git a/docs/README.md b/docs/README.md index 47b9f984f7..a9c572565a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,4 +1,4 @@ -# Duke User Guide +# Skye User Guide // Update the title above to match the actual product name 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/Skye/classes/Deadline.java b/src/main/java/Skye/classes/Deadline.java new file mode 100644 index 0000000000..80a1b187c0 --- /dev/null +++ b/src/main/java/Skye/classes/Deadline.java @@ -0,0 +1,30 @@ +package Skye.classes; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +public class Deadline extends Task{ + protected LocalDate dueDate; + + public Deadline(String name, LocalDate date) { + super(name); + dueDate = date; + } + + @Override + public String getTaskType() { + return "D"; + } + + @Override + public String toString() { + return String.format("[%s]%s (by: %s)" , getTaskType(), super.toString(), + dueDate.format(DateTimeFormatter.ofPattern(Task.DATE_TIME_FORMAT))); + } + + @Override + public String getTaskData() { + return String.format("%s|%s", super.getTaskData(), + dueDate.format(DateTimeFormatter.ofPattern(Task.DATE_TIME_FORMAT))); + } +} diff --git a/src/main/java/Skye/classes/Event.java b/src/main/java/Skye/classes/Event.java new file mode 100644 index 0000000000..3247583b1c --- /dev/null +++ b/src/main/java/Skye/classes/Event.java @@ -0,0 +1,33 @@ +package Skye.classes; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +public class Event extends Task{ + protected LocalDate start; + protected LocalDate end; + + public Event(String name, LocalDate startDate, LocalDate endDate) { + super(name); + start = startDate; + end = endDate; + } + + @Override + public String getTaskType() { + return "E"; + } + + @Override + public String toString() { + return String.format("[%s]%s (from: %s to: %s)" , getTaskType(), super.toString(), + start.format(DateTimeFormatter.ofPattern(Task.DATE_TIME_FORMAT)), + end.format(DateTimeFormatter.ofPattern(Task.DATE_TIME_FORMAT))); + } + + @Override + public String getTaskData() { + return String.format("%s|%s|%s", super.getTaskData(), + start.format(DateTimeFormatter.ofPattern(Task.DATE_TIME_FORMAT)), + end.format(DateTimeFormatter.ofPattern(Task.DATE_TIME_FORMAT))); + } +} diff --git a/src/main/java/Skye/classes/Skye.java b/src/main/java/Skye/classes/Skye.java new file mode 100644 index 0000000000..5290c699f3 --- /dev/null +++ b/src/main/java/Skye/classes/Skye.java @@ -0,0 +1,253 @@ +package Skye.classes; +import Skye.errors.*; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.time.format.DateTimeParseException; +import java.util.Objects; +import java.util.Scanner; +import java.util.ArrayList; +import java.time.LocalDate; + +public class Skye { + private static final String DATA_FILE_PATH = "../data.txt"; + ArrayList tasks = new ArrayList<>(); + /** + * Prints a string of characters as given + * @param line String to output + */ + public static void printString(String line) { + System.out.println(line); + } + + /** + * Adds a task to the list of tasks + * @param task The given task + */ + public void addTask(Task task) { + tasks.add(task); + printString("Got it. I've added this task:"); + printString(" " + task.toString()); + printString("Now you have " + tasks.size() + " tasks in the list."); + saveFile(); + } + + /** + * Prints the current list of tasks + */ + public void listTask() { + printString("Here are the list of tasks:"); + for (int i = 0; i < tasks.size(); i++) { + printString((i + 1) + ". " + tasks.get(i)); + } + } + + /** + * Marks a task as complete + */ + public void markTask(int number) { + Task task = tasks.get(number - 1); + task.setTaskComplete(); + printString("Well done! The task below has been completed:"); + printString(String.valueOf(task)); + saveFile(); + } + + /** + * Marks a task as incomplete + */ + public void unmarkTask(int number) { + printString("Ok, I have marked the task below as incomplete:"); + Task task = tasks.get(number - 1); + task.setTaskIncomplete(); + printString(String.valueOf(task)); + saveFile(); + } + + /** + * Deletes a task + * @param number The number of the task to delete + */ + public void deleteTask(int number) { + Task task = tasks.get(number - 1); + tasks.remove(number - 1); + printString("Got it. I have deleted this task:"); + printString(String.valueOf(task)); + printString("Now you have " + tasks.size() + " tasks in the list."); + saveFile(); + } + + /** + * Finds the list of tasks that contain a given string, and prints them + * @param find A string to search for + */ + public void findTask(String find) { + for (int i = 0; i < tasks.size(); i++) { + Task task = tasks.get(i); + if (task.containName(find)) { + printString((i + 1) + ". " + task); + } + } + } + + /** + * Read the contents of saved file + */ + private void readFile() { + File myFile = new File(DATA_FILE_PATH); + try (Scanner myReader = new Scanner(myFile)) { + while (myReader.hasNextLine()) { + String rawData = myReader.nextLine(); + String[] data = rawData.split("\\|"); + if (Objects.equals(data[0], "T")) { + Task task = new ToDo(data[2]); + if (Objects.equals(data[1], "Y")) { + task.setTaskComplete(); + } + addTask(task); + } else if (Objects.equals(data[0], "D")) { + LocalDate dateBy = LocalDate.parse(data[3]); + Deadline task = new Deadline(data[2], dateBy); + if (Objects.equals(data[1], "Y")) { + task.setTaskComplete(); + } + addTask(task); + } else if (Objects.equals(data[0], "E")) { + LocalDate dateFrom = LocalDate.parse(data[3]); + LocalDate dateBy = LocalDate.parse(data[4]); + Event task = new Event(data[2], dateFrom, dateBy); + if (Objects.equals(data[1], "Y")) { + task.setTaskComplete(); + } + addTask(task); + } + } + } catch (FileNotFoundException e) { + printString("No previous data file found."); + } catch (IndexOutOfBoundsException | DateTimeParseException e) { + printString("Data file seems to be corrupted! Not using data file."); + tasks.clear(); + } + } + + /** + * Save the current task list into a file + */ + private void saveFile() { + try (FileWriter myWriter = new FileWriter(DATA_FILE_PATH)) { + for (Task task : tasks) { + myWriter.write(task.getTaskData()+"\n"); + } + } catch (IOException e) { + printString("Unable to write to file"); + } + } + + /** + * Exits the program + */ + public static void exitProgram() { + System.out.println("Goodbye. Hope to see you again soon!"); + System.exit(0); + } + + public static void main(String[] args) { + Skye inst = new Skye(); + Scanner scanner = new Scanner(System.in); + inst.readFile(); + String logo = " ____ _ \n" + + "/ ___|| | ___ _ ___ \n" + + "\\___ \\| |/ / | | |/ _ \\\n" + + " ___) | <| |_| | __/\n" + + "|____/|_|\\_\\\\__, |\\___|\n" + + " |___/ \n"; + System.out.println("Hello from\n" + logo); + + while (scanner.hasNextLine()) { + try { + String userInput = scanner.nextLine(); + String[] userInputContent = userInput.split(" ", 2); + if (userInput.equals("bye")) { + exitProgram(); + } else if (userInput.equals("list")) { + inst.listTask(); + } else if (userInput.startsWith("unmark")) { + if (userInputContent.length < 2) { + throw new IncompleteCommandException("unmark"); + } + int number = Integer.parseInt(userInputContent[1]); + inst.unmarkTask(number); + } else if (userInput.startsWith("mark")) { + if (userInputContent.length < 2) { + throw new IncompleteCommandException("mark"); + } + int number = Integer.parseInt(userInputContent[1]); + inst.markTask(number); + } else if (userInput.startsWith("delete")) { + if (userInputContent.length < 2) { + throw new IncompleteCommandException("delete"); + } + int number = Integer.parseInt(userInputContent[1]); + inst.deleteTask(number); + } else if (userInput.startsWith("todo")) { + if (userInputContent.length < 2) { + throw new MissingFieldException("todo", "description"); + } + inst.addTask(new ToDo(userInputContent[1])); + } else if (userInput.startsWith("deadline")) { + if (userInputContent.length < 2) { + throw new MissingFieldException("deadline", "description"); + } + String[] content = userInputContent[1].split(" /by "); + if (content.length == 1) { + throw new MissingFieldException("deadline", "by"); + } + LocalDate dateBy; + try { + dateBy = LocalDate.parse(content[1]); + } catch (DateTimeParseException e) { + throw new ErrorFieldException("deadline", "by"); + } + inst.addTask(new Deadline(content[0], dateBy)); + } else if (userInput.startsWith("event")) { + if (userInputContent.length < 2) { + throw new MissingFieldException("event", "description"); + } + String[] eventDetails = userInputContent[1].split(" /from "); + if (eventDetails.length == 1) { + throw new MissingFieldException("event", "from"); + } + String[] time = eventDetails[1].split(" /to "); + if (time.length == 1) { + throw new MissingFieldException("event", "to"); + } + LocalDate dateFrom, dateBy; + try { + dateFrom = LocalDate.parse(time[0]); + } catch (DateTimeParseException e) { + throw new ErrorFieldException("event", "from"); + } + try { + dateBy = LocalDate.parse(time[0]); + } catch (DateTimeParseException e) { + throw new ErrorFieldException("event", "by"); + } + inst.addTask(new Event(eventDetails[0], dateFrom, dateBy)); + } else if (userInput.startsWith("find")) { + if (userInputContent.length < 2) { + throw new MissingFieldException("find", "description"); + } + inst.findTask(userInputContent[1]); + } else { + throw new UnknownCommandException(); + } + } catch (NumberFormatException e) { + System.out.println("Invalid task number!"); + } catch (SkyeException e) { + System.out.println(e.getMessage()); + } + } + } +} diff --git a/src/main/java/Skye/classes/Task.java b/src/main/java/Skye/classes/Task.java new file mode 100644 index 0000000000..086b855f9b --- /dev/null +++ b/src/main/java/Skye/classes/Task.java @@ -0,0 +1,49 @@ +package Skye.classes; +public class Task { + protected String taskName; + protected boolean isComplete; + protected static final String DATE_TIME_FORMAT = "MMM dd yyyy"; + + public Task(String name) { + taskName = name; + isComplete = false; + } + + public void setTaskComplete() { + isComplete = true; + } + + public void setTaskIncomplete() { + isComplete = false; + } + + public String getStatusIcon() { + return (isComplete ? "X" : " "); + } + + public String getTaskType() { + return " "; + } + + @Override + public String toString() { + return String.format("[%s] %s", getStatusIcon(), taskName); + } + + /** + * Gets the string for writing into data file + * @return String of the correct format for data file write + */ + public String getTaskData() { + return String.format("%s|%s|%s", getTaskType(), (isComplete ? "Y" : "N"), taskName); + } + + /** + * Check if the task name contains the given string + * @param name given string to check against + * @return boolean + */ + public boolean containName(String name){ + return taskName.contains(name); + } +} diff --git a/src/main/java/Skye/classes/ToDo.java b/src/main/java/Skye/classes/ToDo.java new file mode 100644 index 0000000000..35b2eaf82a --- /dev/null +++ b/src/main/java/Skye/classes/ToDo.java @@ -0,0 +1,17 @@ +package Skye.classes; +public class ToDo extends Task{ + + public ToDo(String name) { + super(name); + } + + @Override + public String getTaskType() { + return "T"; + } + + @Override + public String toString() { + return "[" + getTaskType() + "]" + super.toString(); + } +} diff --git a/src/main/java/Skye/errors/ErrorFieldException.java b/src/main/java/Skye/errors/ErrorFieldException.java new file mode 100644 index 0000000000..2f5c34cde1 --- /dev/null +++ b/src/main/java/Skye/errors/ErrorFieldException.java @@ -0,0 +1,13 @@ +package Skye.errors; + +public class ErrorFieldException extends SkyeException{ + + /** + * Throws an error about error in field content + * @param fieldType Type of the field, eg. task + * @param fieldName Name of the field, eg. description + */ + public ErrorFieldException(String fieldType, String fieldName) { + super(String.format("The input %s of %s is incorrect!", fieldName, fieldType)); + } +} diff --git a/src/main/java/Skye/errors/IncompleteCommandException.java b/src/main/java/Skye/errors/IncompleteCommandException.java new file mode 100644 index 0000000000..e733d138b4 --- /dev/null +++ b/src/main/java/Skye/errors/IncompleteCommandException.java @@ -0,0 +1,7 @@ +package Skye.errors; + +public class IncompleteCommandException extends SkyeException{ + public IncompleteCommandException(String command) { + super(String.format("The %s command is incomplete!", command)); + } +} diff --git a/src/main/java/Skye/errors/MissingFieldException.java b/src/main/java/Skye/errors/MissingFieldException.java new file mode 100644 index 0000000000..d78f008221 --- /dev/null +++ b/src/main/java/Skye/errors/MissingFieldException.java @@ -0,0 +1,13 @@ +package Skye.errors; + +public class MissingFieldException extends SkyeException{ + + /** + * Throws an error about missing fields + * @param fieldType Type of the field, eg. task + * @param fieldName Name of the field, eg. description + */ + public MissingFieldException(String fieldType, String fieldName) { + super(String.format("The '%s' field of a %s cannot be empty!", fieldName, fieldType)); + } +} diff --git a/src/main/java/Skye/errors/SkyeException.java b/src/main/java/Skye/errors/SkyeException.java new file mode 100644 index 0000000000..b880849e66 --- /dev/null +++ b/src/main/java/Skye/errors/SkyeException.java @@ -0,0 +1,7 @@ +package Skye.errors; + +public class SkyeException extends Exception { + public SkyeException(String message) { + super("Skye has encountered an error! " + message); // Differentiate Skye's internal exceptions + } +} diff --git a/src/main/java/Skye/errors/UnknownCommandException.java b/src/main/java/Skye/errors/UnknownCommandException.java new file mode 100644 index 0000000000..7e84a0382e --- /dev/null +++ b/src/main/java/Skye/errors/UnknownCommandException.java @@ -0,0 +1,7 @@ +package Skye.errors; + +public class UnknownCommandException extends SkyeException{ + public UnknownCommandException() { + super("This Command is not known!"); + } +} diff --git a/src/test/java/Skye/classes/EventTest.java b/src/test/java/Skye/classes/EventTest.java new file mode 100644 index 0000000000..d85cf0fa25 --- /dev/null +++ b/src/test/java/Skye/classes/EventTest.java @@ -0,0 +1,14 @@ +package Skye.classes; + +import java.time.LocalDate; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class EventTest { + @Test + public void event_testStringConversion(){ + Event test = new Event("Exchange Guest", LocalDate.parse("2025-10-01"), + LocalDate.parse("2025-10-07")); + assertEquals("[E][ ] Exchange Guest (from: Oct 01 2025 to: Oct 07 2025)", test.toString()); + } +} diff --git a/src/test/java/Skye/classes/ToDoTest.java b/src/test/java/Skye/classes/ToDoTest.java new file mode 100644 index 0000000000..3f6dab7bb9 --- /dev/null +++ b/src/test/java/Skye/classes/ToDoTest.java @@ -0,0 +1,13 @@ +package Skye.classes; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class ToDoTest { + @Test + public void todo_testStringConversion(){ + ToDo test = new ToDo("a"); + assertEquals("[T][ ] a", test.toString()); + } + +} diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 657e74f6e7..a03bf1de1a 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,7 +1,23 @@ Hello from - ____ _ -| _ \ _ _| | _____ -| | | | | | | |/ / _ \ -| |_| | |_| | < __/ -|____/ \__,_|_|\_\___| + ____ _ +/ ___|| | ___ _ ___ +\___ \| |/ / | | |/ _ \ + ___) | <| |_| | __/ +|____/|_|\_\\__, |\___| + |___/ +Got it. I've added this task: + [T][ ] borrow book +Now you have 1 tasks in the list. +Got it. I've added this task: + [D][ ] return book (by: Sunday) +Now you have 2 tasks in the list. +Got it. I've added this task: + [E][ ] project meeting (from: Mon 2pm to: 4pm) +Now you have 3 tasks in the list. +Here are the list of tasks: +1. [T][ ] borrow book +2. [D][ ] return book (by: Sunday) +3. [E][ ] project meeting (from: Mon 2pm to: 4pm) +Well done! The task below has been completed: +[T][X] borrow book \ No newline at end of file diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index e69de29bb2..dadcb4404d 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -0,0 +1,5 @@ +todo borrow book +deadline return book /by Sunday +event project meeting /from Mon 2pm /to 4pm +list +mark 1 \ No newline at end of file diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 0873744649..fe98738ed7 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -15,7 +15,7 @@ IF ERRORLEVEL 1 ( REM no error here, errorlevel == 0 REM run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT -java -classpath ..\bin Duke < input.txt > ACTUAL.TXT +java -classpath ..\bin Skye < input.txt > ACTUAL.TXT REM compare the output to the expected output FC ACTUAL.TXT EXPECTED.TXT diff --git a/text-ui-test/runtest.sh b/text-ui-test/runtest.sh old mode 100644 new mode 100755