diff --git a/build.gradle b/build.gradle new file mode 100644 index 00000000..9710c77c --- /dev/null +++ b/build.gradle @@ -0,0 +1,57 @@ +plugins { + id 'java' + id 'application' + id 'com.github.johnrengelman.shadow' version '5.1.0' +} + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.junit.jupiter:junit-jupiter:5.8.1' + implementation 'org.junit.jupiter:junit-jupiter:5.8.1' + implementation 'org.junit.jupiter:junit-jupiter:5.8.1' + implementation 'org.junit.jupiter:junit-jupiter:5.8.1' + testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.5.0' + testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.5.0' +} +sourceSets { + test { + java { + srcDirs = ['src/test/java'] + } + } +} +test { + useJUnitPlatform() + + testLogging { + events "passed", "skipped", "failed" + + showExceptions true + exceptionFormat "full" + showCauses true + showStackTraces true + showStandardStreams = false + } +} + +dependencies { + testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.5.0' + testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.5.0' +} + +application { + mainClassName = "com.tic2002.duke.Duke" +} + +shadowJar { + archiveBaseName = "duke" + archiveClassifier = null +} + +run{ + standardInput = System.in + enableAssertions = true +} diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml new file mode 100644 index 00000000..2400e011 --- /dev/null +++ b/config/checkstyle/checkstyle.xml @@ -0,0 +1,415 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..f3d88b1c 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 00000000..b7c8c5db --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 00000000..2fe81a7d --- /dev/null +++ b/gradlew @@ -0,0 +1,183 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 00000000..62bd9b9c --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,103 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/src/main/.gradle/7.1/dependencies-accessors/dependencies-accessors.lock b/src/main/.gradle/7.1/dependencies-accessors/dependencies-accessors.lock new file mode 100644 index 00000000..e2260131 Binary files /dev/null and b/src/main/.gradle/7.1/dependencies-accessors/dependencies-accessors.lock differ diff --git a/src/main/.gradle/7.1/dependencies-accessors/gc.properties b/src/main/.gradle/7.1/dependencies-accessors/gc.properties new file mode 100644 index 00000000..e69de29b diff --git a/src/main/.gradle/7.1/fileChanges/last-build.bin b/src/main/.gradle/7.1/fileChanges/last-build.bin new file mode 100644 index 00000000..f76dd238 Binary files /dev/null and b/src/main/.gradle/7.1/fileChanges/last-build.bin differ diff --git a/src/main/.gradle/7.1/fileHashes/fileHashes.lock b/src/main/.gradle/7.1/fileHashes/fileHashes.lock new file mode 100644 index 00000000..2cfd1fe1 Binary files /dev/null and b/src/main/.gradle/7.1/fileHashes/fileHashes.lock differ diff --git a/src/main/.gradle/7.1/gc.properties b/src/main/.gradle/7.1/gc.properties new file mode 100644 index 00000000..e69de29b diff --git a/src/main/.gradle/checksums/checksums.lock b/src/main/.gradle/checksums/checksums.lock new file mode 100644 index 00000000..d897e6af Binary files /dev/null and b/src/main/.gradle/checksums/checksums.lock differ diff --git a/src/main/.gradle/vcs-1/gc.properties b/src/main/.gradle/vcs-1/gc.properties new file mode 100644 index 00000000..e69de29b diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java deleted file mode 100644 index 5d313334..00000000 --- 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/com/tic2002/app/DukeException.java b/src/main/java/com/tic2002/app/DukeException.java new file mode 100644 index 00000000..ad76b212 --- /dev/null +++ b/src/main/java/com/tic2002/app/DukeException.java @@ -0,0 +1,8 @@ +package com.tic2002.app; + +/** + * Creates class exception as DukeException to handle errors + */ +public class DukeException extends Exception { + +} diff --git a/src/main/java/com/tic2002/app/Parser.java b/src/main/java/com/tic2002/app/Parser.java new file mode 100644 index 00000000..4887f669 --- /dev/null +++ b/src/main/java/com/tic2002/app/Parser.java @@ -0,0 +1,205 @@ +package com.tic2002.app; + +import com.tic2002.task.TaskCommands; + +import java.time.LocalDate; +import java.time.LocalTime; +import java.time.format.DateTimeParseException; + +import static com.tic2002.task.DateTime.isValidDate; +import static com.tic2002.task.DateTime.isValidTime; +import static com.tic2002.task.DateTime.toDate; +import static com.tic2002.task.DateTime.toTime; +import static com.tic2002.task.Find.findWord; +import static com.tic2002.task.Priority.isValidPriority; +import static com.tic2002.task.TaskCommands.addEvent; +import static com.tic2002.task.TaskCommands.addTodo; +import static com.tic2002.task.TaskCommands.addDeadline; +import static com.tic2002.task.TaskCommands.updatePriority; + +public class Parser { + /** + * Set enumerations of valid commands + */ + public enum validCommands { + LIST, DONE, UNDONE, DELETE, HELP, BYE, TODO, EVENT, DEADLINE, ON, PRIORITY, FIND + } + + /** + * To check if user input String check is valid + * @param checkCommand takes user input as String + * check if checkCommand matches enum + * @return true if match, false if doesn't match + */ + public static boolean isValidInput (String checkCommand) { + for (validCommands a : validCommands.values()) { + if(a.name().equals(checkCommand)) { + return true; + } + } + return false; + } + + /** + * Takes in input from user and makes sense of input for Event + */ + public static void eventParse(String userEntry, String description){ + String timeDescription = userEntry.split("/at ")[1]; + if(description.equals("")) { + System.out.println("include /at"); + } + else { + description = description.split(" /")[0]; + addEvent(description,timeDescription); + } + } + + /** + * Takes in input from user and makes sense of input for Deadline + */ + public static void deadlineParse(String userEntry, String description){ + String timeDescription = userEntry.split("/by ")[1]; + description = description.split(" /")[0]; + String date = timeDescription.split(", ")[0]; + String time = timeDescription.split(", ")[1]; + + if(description.equals("")) { + System.out.println("include /by"); + } + else if(!isValidDate(date) || !isValidTime(time)) { + System.out.println("Please use an exact date time, yyyy-mm-dd, hh:mm"); + } + else{ + try { + LocalDate dateDate = toDate(date); + LocalTime timeTime = toTime(time); + addDeadline(description, dateDate, timeTime); + } catch (DateTimeParseException e) { + System.out.println("Please enter in yyyy-mm-dd, hh:mm"); + } + } + } + + public static void priorityParse(String description){ + int ref = Integer.parseInt(description.split(" ")[0]); + int priority = Integer.parseInt(description.split(" ")[1]); + if(isValidPriority(priority)) { + updatePriority(ref-1, priority); + } + } + + public static boolean isNumber(String input) { + try { + Integer.parseInt(input); + return true; + } catch (NumberFormatException e) { + return false; + } catch (ArrayIndexOutOfBoundsException e) { + return false; + } + } + /** + * Takes user input as String and parse input + * @param userEntry Takes user entry as String + * Creates String timeDescription for Deadline & Event cases + * Creates String description to store description of task + * Creates String command to store first word of String userEntry, which is the command + * Create int size to check length of String userEntry + * String commandUpper to change String command to upper case + * check if user entered only command without description, except for LIST & BYE + * Check if matches validCommands + * @throws DukeException when error occurs + * switch for commandUpper + * done - Set task as done + * undone - Set task as not done + * delete - delete a task + * help - prints out instructions + * bye - ends Duke + * todo - creates todo task + * event - creates event + * deadline - creates task with deadline + * on - returns task with matching date + * priority - sets task priority + * find - find tasks that matches user input + */ + public static void parseCommand(String userEntry) throws DukeException { + String description; + String command = userEntry.split(" ")[0]; + description = userEntry.replaceFirst(command + " ", ""); + int size = userEntry.length(); + String commandUpper = command.toUpperCase(); + if(size == 1 && !commandUpper.equals("LIST") && !commandUpper.equals("BYE")) { + throw new DukeException(); + } + if(!isValidInput(commandUpper)) { + throw new DukeException(); + } + + switch (commandUpper) { + case "LIST": + TaskCommands.printList(); + break; + + case"DONE": + int ref = Integer.parseInt(description); + TaskCommands.setDone(ref-1); + break; + + case"UNDONE": + ref = Integer.parseInt(description); + TaskCommands.setUnDone(ref-1); + break; + + case"DELETE": + ref = Integer.parseInt(description); + TaskCommands.deleteTask(ref-1); + break; + + case"HELP": + UI.instructions(); + break; + + case"BYE": + UI.endDuke(); + break; + + case"TODO": + addTodo(description); + break; + + case"EVENT": + eventParse(userEntry, description); + break; + + case"DEADLINE": + deadlineParse(userEntry, description); + break; + + case"ON": + if(isValidDate(description) || (!description.equals(""))) { + LocalDate checkDate = toDate(description); + TaskCommands.printDateList(checkDate); + } + break; + + case"PRIORITY": + try { + priorityParse(description); + } catch (NumberFormatException e) { + throw new DukeException(); + } + break; + + case"FIND": + findWord(description); + break; + + default: + throw new DukeException(); + } + } +} + + + + diff --git a/src/main/java/com/tic2002/app/Storage.java b/src/main/java/com/tic2002/app/Storage.java new file mode 100644 index 00000000..01a68bcc --- /dev/null +++ b/src/main/java/com/tic2002/app/Storage.java @@ -0,0 +1,187 @@ +package com.tic2002.app; + +import com.tic2002.task.Event; +import com.tic2002.task.Task; +import com.tic2002.task.Todo; +import com.tic2002.task.Deadline; +import com.tic2002.task.List; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.time.LocalDate; +import java.time.LocalTime; +import java.time.format.DateTimeParseException; +import java.util.ArrayList; + +import static com.tic2002.task.DateTime.*; +import static com.tic2002.app.Parser.isNumber; + +public class Storage extends List { + + private static ArrayList Load = new ArrayList<>(); + + /** + * Method to load listing from Duke.txt + * Get path for user hom + * Get path for duke.txt + * run duke.txt over switch to store as tasks in List + */ + public static void loadList() { + String home = System.getProperty("user.home"); + Path path = Paths.get(home, "data", "duke.txt"); + + boolean directoryExists = Files.exists(path); + String description; + if(directoryExists) { + try (BufferedReader br = new BufferedReader(new FileReader(path + ""))) { + String sCurrentLine; + int i = 0; + + while ((sCurrentLine = br.readLine()) != null) { + String line = sCurrentLine.split(",")[0]; + String priorityString = sCurrentLine.split(",")[1]; + assert isNumber(priorityString) : "Error in file: " + sCurrentLine; + int priority = Integer.parseInt(priorityString); + String [] words = line.split("\\|"); + String type = words[0]; + boolean isDone = Boolean.parseBoolean(words[1]); + + switch (type) { + case "T": + description = words[2]; + Load.add(new Todo(description)); + Load.get(i).priority(priority); + if (isDone) { + Load.get(i).setDone(); + } + i++; + break; + + case "D": + description = words[2]; + String date = words[3]; + String time = words[4]; + try { + LocalDate byDate = toDate(date); + LocalTime byTime = toTime(time); + Load.add(new Deadline(description, byDate, byTime)); + + if(isDone){ + Load.get(i).setDone(); + Load.get(i).priority(0); + } + + if(!isDone) { + if (isWithinThreeDays(byDate)) { + Load.get(i).priority(3); + } else if (isOverDue(byDate)) { + Load.get(i).priority(4); + } else { + Load.get(i).priority(priority); + } + } + + } catch (DateTimeParseException e) { + System.out.println("Error in file: " + sCurrentLine ); + break; + } + if(isDone){ + Load.get(i).setDone(); + } + i++; + break; + + case "E": + description = words[2]; + Load.add(new Event(description, words[3])); + Load.get(i).priority(priority); + if(isDone){ + Load.get(i).setDone(); + } + i++; + break; + } + } + } catch (IOException e) { + e.printStackTrace(); + } + List.setList(Load); + } + } + + /** + * Method to save current listing + * Copy ArrayList List to ArrayList Load + * get user home path + * Get path of Duke.txt + * print tasks to Duke.txt based on Task variable + */ + public static void saveList() { + Load = List.getList(); + String home = System.getProperty("user.home"); + java.nio.file.Path path = Paths.get(home, "data", "duke.txt"); + + boolean directoryExists = java.nio.file.Files.exists(path); + + if (!directoryExists) { + try { + System.out.println("File created at : " + path); + Files.createDirectory(Paths.get(home,"data")); + Files.createFile(path); + } catch (IOException e) { + System.out.println("Error saving file"); + e.printStackTrace(); + } + } + String save = ""; + for (Task task : Load) { + String type = task.getType(); + try { + switch (type) { + case "T": + save += task.getType() + "|" + + task.getDone() + "|" + + task.getDescription() + "," + + task.getPriority() + + System.lineSeparator(); + break; + + case "E": + save += task.getType() + "|" + + task.getDone() + "|" + + task.getDescription() + "|" + + task.getTiming() + "," + + task.getPriority() + + System.lineSeparator(); + break; + + case "D": + save += task.getType() + "|" + + task.getDone() + "|" + + task.getDescription() + "|" + task.getDate() + "|" + + task.getTime() + "," + + task.getPriority() + + System.lineSeparator(); + break; + + default: + break; + } + writeToFile(path + "", save); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + private static void writeToFile(String filePath, String textToAdd) throws IOException { + FileWriter fw = new FileWriter(filePath); + fw.write(textToAdd); + fw.close(); + } +} diff --git a/src/main/java/com/tic2002/app/UI.java b/src/main/java/com/tic2002/app/UI.java new file mode 100644 index 00000000..671e59a5 --- /dev/null +++ b/src/main/java/com/tic2002/app/UI.java @@ -0,0 +1,116 @@ +package com.tic2002.app; + +import java.util.Scanner; + +import static com.tic2002.app.Storage.loadList; + +public class UI { + private Parser parser; + + /** Main function of UI to run program + * dukeLogo - Calling the logo + * loadList - Calling the Storage function to load duke.txt + * line - Creates a String to store user input + * Scanner in - to scan and read user input + * while(true) - while there is input from the user + * newLine() - Calls a line break + * command Split user line to the first word + * commandUpper Convert user input String to uppercase + * parser.validInput(commandUpper) passes command String to check boolean + * catch(NullPointerException e) catches null in String + * println tells user to input accurately + * instructions() print instructions to use Duke + * parser.parseCommand(line) passes command String to Parser to do command + * catch(NullPointerException e) catches null in String + * println tells user to input accurately + * instructions() print instructions to use Duke + * catch(ArrayIndexOutOfBoundsException e) catches array out of bounds in String + * catch(IndexOutOfBoundsException e) catches index out of bounds in String + */ + public void run(){ + dukeLogo(); + loadList(); + String line; + Scanner in = new Scanner(System.in); + parser = new Parser(); + + while(true) { + line = in.nextLine(); + newLine(); + String command = line.split(" ")[0]; + String commandUpper = command.toUpperCase(); + + try { + assert commandUpper != null : "Please enter valid input\n"; + parser.isValidInput(commandUpper); + } catch (NullPointerException e){ + System.out.println("Please enter a valid input\n"); + instructions(); + } + try { + assert line != null: "Please enter a valid input\n"; + parser.parseCommand(line); + } catch (DukeException e) { + System.out.println("Please enter a valid input\n"); + instructions(); + } catch (NullPointerException e){ + System.out.println("Please enter a valid input\n"); + instructions(); + } catch (ArrayIndexOutOfBoundsException e){ + System.out.println("Please enter a valid input\n"); + instructions(); + } catch (IndexOutOfBoundsException e) { + System.out.println("Please enter a valid input\n"); + instructions(); + } + newLine(); + } + } + + private static void dukeLogo () { + String logo = " ____ _ \n" + + "| _ \\ _ _| | _____ \n" + + "| | | | | | | |/ / _ \\\n" + + "| |_| | |_| | < __/\n" + + "|____/ \\__,_|_|\\_\\___|\n"; + System.out.println("Hello from\n" + logo); + //Hello command + System.out.println("Hello, I'm Duke\n" + "What tasks can I serve you?"); + newLine(); + } + + /** + * to end program + * Storage.saveList() - call Storage to save list to duke.txt + * System.exit() - exit system safely + */ + public static void endDuke () { + System.out.println("\tBye! Thanks for visiting The Duke!"); + Storage.saveList(); + System.exit(0); + } + + /** + * newLine() - Prints a new line break + */ + public static void newLine () { + System.out.println("________________________________________________"); + } + + /** + * Prints out instructions to use Duke + */ + public static void instructions () { + System.out.println("DUKE helps you organise your tasks efficiently, please enter as follows:" + + "\n\tevent [description] /at [time]\n\t" + + "todo [description]\n\t" + + "deadline [description] /by yyyy-mm-dd, hh:mm\n\t" + + "done [number] - to mark task as completed\n\t" + + "list - to show all tasks\n\t" + + "delete [number] - to delete a task\n\t" + + "on yyyy-mm-dd - to check if tasks match date given\n\t" + + "priority [index] [0(TO REMOVE) / 1(LOW) / 2(MED) / 3(HIGH)] - to set priority\n\t" + + "find [word] - To search for a word\n\t" + + "bye - to end DUKE"); + } +} \ No newline at end of file diff --git a/src/main/java/com/tic2002/duke/Duke.java b/src/main/java/com/tic2002/duke/Duke.java new file mode 100644 index 00000000..d4d1da24 --- /dev/null +++ b/src/main/java/com/tic2002/duke/Duke.java @@ -0,0 +1,20 @@ +package com.tic2002.duke; + +import com.tic2002.app.UI; + +public class Duke { + + private static UI ui; + + /** @param args to create program to run + * Creating a new UI in main Duke & running + */ + public static void main(String[] args) { + ui = new UI(); + ui.run(); + } + +} + + + diff --git a/src/main/java/com/tic2002/task/DateTime.java b/src/main/java/com/tic2002/task/DateTime.java new file mode 100644 index 00000000..b11b77be --- /dev/null +++ b/src/main/java/com/tic2002/task/DateTime.java @@ -0,0 +1,95 @@ +package com.tic2002.task; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; + +public class DateTime { + /** + * To validate user input String date + * @param date Takes a String input date + * verifying if date matches "yyyy-mm-dd" format + * @return returns true if matches accurate format + * returns false if does not match accurate format + * parse date with format + * must be exact with format + * if true, set + * return valid as true + */ + public static boolean isValidDate (String date) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + boolean valid; + try { + sdf.parse(date); + sdf.setLenient(false); + valid = true; + } catch (ParseException e){ + valid = false; + System.out.println("Please use an exact date: yyyy-mm-dd"); + } + return valid; + } + + /** + * To valid user input String time + * @param time takes a String input time + * verifying if time matches "hh:mm" format + * @return true if matches format, false if does not match format + * parse date with format + * must be exact with format + * if true, set & return + */ + public static boolean isValidTime (String time) { + SimpleDateFormat sdf = new SimpleDateFormat("HH:mm"); + boolean valid; + try { + sdf.parse(time); + sdf.setLenient(false); + valid = true; + } catch (ParseException e){ + valid = false; + } + return valid; + } + + /** + * Takes user input String date and returns as LocalDate + * @param date parses to LocalDate + * @return date as LocalDate + */ + public static LocalDate toDate(String date) { + return LocalDate.parse(date); + } + + /** + * Takes user input String time and returns as LocalTime + * @param time parses to LocalTime + * @return time as LocalTime + */ + public static LocalTime toTime(String time) { + return LocalTime.parse(time); + } + + /** + * Takes LocalDate date and returns in a new format + * formatter to format date to "dd MMM yyyy" + * @return new date format + */ + public static String toNewDateFormat (LocalDate date) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd MMM yyyy"); + return date.format(formatter); + } + + public static boolean isWithinThreeDays(LocalDate taskDate) { + LocalDate yesterday = LocalDate.now().minusDays(1); + LocalDate threeDaysAfter = LocalDate.now().plusDays(3); + return taskDate.isAfter(yesterday) && taskDate.isBefore(threeDaysAfter); + } + + public static boolean isOverDue(LocalDate taskDate) { + LocalDate today = LocalDate.now(); + return taskDate.isBefore(today); + } +} diff --git a/src/main/java/com/tic2002/task/Deadline.java b/src/main/java/com/tic2002/task/Deadline.java new file mode 100644 index 00000000..d4729d13 --- /dev/null +++ b/src/main/java/com/tic2002/task/Deadline.java @@ -0,0 +1,45 @@ +package com.tic2002.task; + +import java.time.LocalDate; +import java.time.LocalTime; + +import static com.tic2002.task.DateTime.*; + + +/** + * Deadline is inheriting from Task + */ +public class Deadline extends Task { + /** + * Deadline takes in input of String description, LocalDate dDate and LocalTime dTime + * @param description description from Parser that user entered + * @param dDate date from Parser + * @param dTime time from Parser + * The Deadline method stores these tasks in Task + * super.type - Assigns type "D" + * super.isDone - Assigns false to done + * @Override - print task in deadline format + */ + public Deadline(String description, LocalDate dDate, LocalTime dTime) { + super(description); + super.type("D"); + super.date = dDate; + super.time = dTime; + super.isDone = false; + super.priority = 0; + if(isWithinThreeDays(dDate)){ + super.priority = 3; + } + else if(isOverDue(dDate)){ + super.priority = 4; + } + else{ + super.priority = 0; + } + } + + @Override + public String printTask() { + return super.printTask() + " (by: " + toNewDateFormat(super.date) + ", " + super.time + ")"; + } +} diff --git a/src/main/java/com/tic2002/task/Event.java b/src/main/java/com/tic2002/task/Event.java new file mode 100644 index 00000000..e4687a90 --- /dev/null +++ b/src/main/java/com/tic2002/task/Event.java @@ -0,0 +1,24 @@ +package com.tic2002.task; + +public class Event extends Task { + /** + * Deadline takes in input of String description, String at + * @param description description from Parser that user entered + * super.type - Assigns type "E" + * super.timing - Stores String at in task timing + * super.isDone - Assigns false to done + * @Override - print task in Event format + */ + public Event(String description, String at) { + super(description); + super.type("E"); + super.timing(at); + super.isDone = false; + super.priority = 0; + } + + @Override + public String printTask() { + return super.printTask() + " (at: " + super.timing + ")"; + } +} diff --git a/src/main/java/com/tic2002/task/Find.java b/src/main/java/com/tic2002/task/Find.java new file mode 100644 index 00000000..de2289be --- /dev/null +++ b/src/main/java/com/tic2002/task/Find.java @@ -0,0 +1,28 @@ +package com.tic2002.task; + +import java.util.ArrayList; + +public class Find { + + public static void findWord(String input){ + String description; + String checkWord = input.toLowerCase(); + ArrayList Check = new ArrayList<>(); + ArrayList Temp = List.getList(); + for(int i=0; i List = new ArrayList<>(); + + /** + * To allow other ArrayList in other classes to set into main ArrayList List + * @param Other references other ArrayList + */ + public static void setList(ArrayList Other) { + List = Other; + } + + /** + * To return ArrayList List to other ArrayList in other classes + * @return ArrayList List + */ + public static ArrayList getList(){ + return List; + } + + /** + * Method to add Task to list + * using ArrayList.add() method + * Print line to note task has been added + * Print number of items in list + * Saves list into storage + * @param t - Tasks + */ + public static void addList(Task t) { + List.add(t); + System.out.println("\tGot it. I've added this task:"); + printCount(); + Storage.saveList(); + } + + /** + * Method to return List size in int + * @return int size of List + */ + public static int getSize(){ + return List.size(); + } +} + diff --git a/src/main/java/com/tic2002/task/Priority.java b/src/main/java/com/tic2002/task/Priority.java new file mode 100644 index 00000000..f4f6b76f --- /dev/null +++ b/src/main/java/com/tic2002/task/Priority.java @@ -0,0 +1,31 @@ +package com.tic2002.task; + +public class Priority extends Task { + private enum validPriority {LOW, MEDIUM, HIGH, OVERDUE; } + + /** + * Check if user input is within 1 to 3 + * @param input user input + * @return true and false + */ + public static boolean isValidPriority(int input) { + if(input >= 0 && input <=3){ + return true; + } + return false; + } + + public static String printPriority(int value) { + switch(value) { + case 1: + return "[" + validPriority.LOW + "]"; + case 2: + return "[" + validPriority.MEDIUM + "]"; + case 3: + return "[" + validPriority.HIGH + "]"; + case 4: + return "[" + validPriority.OVERDUE + "]"; + } + return ""; + } +} diff --git a/src/main/java/com/tic2002/task/Task.java b/src/main/java/com/tic2002/task/Task.java new file mode 100644 index 00000000..3ad026e7 --- /dev/null +++ b/src/main/java/com/tic2002/task/Task.java @@ -0,0 +1,133 @@ +package com.tic2002.task; + +import java.time.LocalDate; +import java.time.LocalTime; + +import static com.tic2002.task.Priority.printPriority; + +/** + * Creates what is in a Task + * creates String description - description of task + * creates boolean isDone - if the task is done + * creates String type - what type of task is it (Todo, Deadline, Event) + * creates LocalDate date - stores date for Deadline + * creates LocalTime time - stores time for Deadline + */ +public class Task { + protected String description; + protected boolean isDone; + protected String type; + protected String timing; + protected LocalDate date; + protected LocalTime time; + protected int priority; + + public Task(){} + + /** + * Modify basic Task + * @param description description of the task + */ + public Task(String description) { + this.description = description; + } + + /** + * Modify type of task + * @param type type of task assigned + */ + public void type(String type){ + this.type = type; + } + /** + * Modify timing of Event + * @param timing timing of Event + */ + public void timing (String timing){ + this.timing = timing; + } + /** + * Modify status of task + * @param isDone if task is completed + */ + public void isDone(Boolean isDone) {this.isDone = isDone; } + + public void priority (int priority) {this.priority = priority; } + /** + * Modify date of task to be completed by + * @param date date of task to be completed by + */ + public void date (LocalDate date){this.date = date; } + /** + * Modify time of task to be completed by + * @param time date of task to be completed by + */ + public void time (LocalTime time){this.time = time; } + + /** + * Method to set task as done + */ + public void setDone() { + this.isDone = true; + } + + public void setUnDone() {this.isDone = false; } + + + /** + * Method to get status of isDone + * @return "X" if true, "" if false + */ + public String getStatusIcon() { + return (isDone ? "X" : " "); // mark done task with X + } + + /** + * Retrieve done status of isDone + * @return true or false + */ + public String getDone() { return (isDone ? "true" : "false");} + + /** + * Retrieve description + * @return description of task + */ + public String getDescription() { + return description; + } + + /** + * retrieve type of Task + * @return type of task + */ + public String getType() { return type; } + /** + * retrieve Timing of Event + * @return timing + */ + public String getTiming() {return timing; } + /** + * retrieve Date of Deadline + * @return date + */ + public LocalDate getDate() { return date; } + /** + * retrieve Time of Deadline + * @return time + */ + public LocalTime getTime() { return time; } + + /** + * Get priority number + * @return priority number + */ + public int getPriority() {return priority; } + + /** + * prints tasks out + * @return format of task with type, status and description of Task + */ + public String printTask() { + return "[" + getType() + "]" + "[" + getStatusIcon() + "]" + printPriority(priority) + " " + getDescription(); + } +} diff --git a/src/main/java/com/tic2002/task/TaskCommands.java b/src/main/java/com/tic2002/task/TaskCommands.java new file mode 100644 index 00000000..dbc969cf --- /dev/null +++ b/src/main/java/com/tic2002/task/TaskCommands.java @@ -0,0 +1,198 @@ +package com.tic2002.task; + +import java.time.LocalDate; +import java.time.LocalTime; +import java.util.ArrayList; + +import static com.tic2002.task.DateTime.*; + +/** + * TaskCommands inherits from Task + */ +public class TaskCommands extends Task { + /** + * Creates a Temporary ArrayList + */ + private ArrayList Temp = new ArrayList<>(); + + /** + * Method to add to Todo + * @param description takes String description and adds to Todo + */ + public static void addTodo(String description) { + List.addList(new Todo(description)); + } + /** + * Method to add to Event + * @param description takes String description and adds to Event + * @param at Takes String at and adds to Event (timing) + */ + public static void addEvent(String description, String at) { + List.addList(new Event(description, at)); + } + /** + * Method to add to Deadline + * @param description takes description and adds to Deadline + * @param byDate takes LocalDate date and adds to Deadline (date of deadline) + * @param byTime takes LocalDate time and adds to Deadline (time of deadline) + */ + public static void addDeadline(String description, LocalDate byDate, LocalTime byTime) { + List.addList(new Deadline(description, byDate, byTime)); + } + + /** + * prints out number of tasks in list + */ + public static void printCount() { + ArrayList Temp = List.getList(); + int ref = -1; + ref += Temp.size(); + System.out.println("\t\t" + Temp.get(ref).printTask() + + "\n\tNow you have " + List.getSize() + " tasks in the list."); + } + + /** + * Method prints out list + * if list size is empty, print out error + * return + * + * print out tasks in list line + * print out tasks using a loop, number the list items + */ + public static void printList() { + ArrayList Temp = List.getList(); + if(Temp.size() == 0){ + System.out.println("\tThere are no items in your list"); + return; + } + System.out.println("\tHere are the tasks in your list:"); + for (int i=0; i Temp = List.getList(); + ArrayList Placeholder = new ArrayList<>(); + LocalDate listDate; + if(Temp.size() == 0){ + System.out.println("\tThere are no items in your list"); + return; + } + for (Task task : Temp) { + if (task.getType().equals("D")) { + listDate = task.getDate(); + int result = checkDate.compareTo(listDate); + if (result == 0) { + Placeholder.add(task); + } + } + } + if(Placeholder.size() == 0) { + System.out.println("\tThere are no items in your list that matches " + + toNewDateFormat(checkDate)); + return; + } + + System.out.println("\tThere are " + Placeholder.size() + + " tasks in your list that matches " + + toNewDateFormat(checkDate) + ": " ); + + for (int i=0; i Temp = List.getList(); + Temp.get(ref).setDone(); + Temp.get(ref).priority(0); + System.out.println("\tNice! I've marked this task as done:"); + System.out.println("\t\t" + Temp.get(ref).printTask()); + List.setList(Temp); + } + + /** + * Method to set Task as done + * @param ref gets index from user + * Retrieve Task from List and set as not done + * Print out line to set as not done + * Print out Task that is set as not done + * Update main ArrayList List in List class + */ + public static void setUnDone(int ref) { + ArrayList Temp = List.getList(); + Temp.get(ref).setUnDone(); + System.out.println("\tOk! I've marked this task as not done:"); + System.out.println("\t\t" + Temp.get(ref).printTask()); + List.setList(Temp); + } + + /** + * Method to delete Task + * @param ref gets index from user + * Print delete statement + * Copy ArrayList List from List class to ArrayList Temp + * Print Task to be removed from Temp ArrayList + * Delete Task from Temp + * Update main ArrayList List in List class + */ + public static void deleteTask(int ref) { + System.out.println("\tNoted. I've removed this task: "); + ArrayList Temp = List.getList(); + System.out.println("\t\t" + Temp.get(ref).printTask()); + Temp.remove(ref); + List.setList(Temp); + } + + /** + * To update a priority in a task + * @param ref index of task location in list + * @param priority set priority value + */ + public static void updatePriority(int ref, int priority) { + ArrayList Temp = List.getList(); + Temp.get(ref).priority = priority; + if(priority == 0) { + System.out.println("\tOk! I've removed the priority"); + } + else { + System.out.println("\tOk! I've updated the priority"); + } + System.out.println("\t\t" + Temp.get(ref).printTask()); + List.setList(Temp); + } +} + diff --git a/src/main/java/com/tic2002/task/Todo.java b/src/main/java/com/tic2002/task/Todo.java new file mode 100644 index 00000000..c913a6b6 --- /dev/null +++ b/src/main/java/com/tic2002/task/Todo.java @@ -0,0 +1,25 @@ +package com.tic2002.task; + +/** + * Todo is inheriting from Task + */ +public class Todo extends Task { + /** + * Deadline takes in input of String description + * @param description description from Parser that user entered + * super.type - Assigns type "T" + * super.isDone - Assigns false to done + * @Override - print task in Todo format + */ + public Todo(String description) { + super(description); + super.type("T"); + super.isDone = false; + super.priority = 0; + } + + @Override + public String printTask() { + return super.printTask(); + } +} diff --git a/src/main/out/production/main/Deadline.class b/src/main/out/production/main/Deadline.class new file mode 100644 index 00000000..8097a06a Binary files /dev/null and b/src/main/out/production/main/Deadline.class differ diff --git a/src/main/out/production/main/Duke.class b/src/main/out/production/main/Duke.class new file mode 100644 index 00000000..d5c3f68f Binary files /dev/null and b/src/main/out/production/main/Duke.class differ diff --git a/src/main/out/production/main/DukeException.class b/src/main/out/production/main/DukeException.class new file mode 100644 index 00000000..17cc5018 Binary files /dev/null and b/src/main/out/production/main/DukeException.class differ diff --git a/src/main/out/production/main/Event.class b/src/main/out/production/main/Event.class new file mode 100644 index 00000000..737d2c84 Binary files /dev/null and b/src/main/out/production/main/Event.class differ diff --git a/src/main/out/production/main/List.class b/src/main/out/production/main/List.class new file mode 100644 index 00000000..809f5901 Binary files /dev/null and b/src/main/out/production/main/List.class differ diff --git a/src/main/out/production/main/Task.class b/src/main/out/production/main/Task.class new file mode 100644 index 00000000..0b77790b Binary files /dev/null and b/src/main/out/production/main/Task.class differ diff --git a/src/main/out/production/main/Todo.class b/src/main/out/production/main/Todo.class new file mode 100644 index 00000000..d339d2c9 Binary files /dev/null and b/src/main/out/production/main/Todo.class differ diff --git a/src/main/out/production/main/app/DateTime.class b/src/main/out/production/main/app/DateTime.class new file mode 100644 index 00000000..25d64fac Binary files /dev/null and b/src/main/out/production/main/app/DateTime.class differ diff --git a/src/main/out/production/main/app/DukeException.class b/src/main/out/production/main/app/DukeException.class new file mode 100644 index 00000000..a4c05669 Binary files /dev/null and b/src/main/out/production/main/app/DukeException.class differ diff --git a/src/main/out/production/main/app/Parser$validCommands.class b/src/main/out/production/main/app/Parser$validCommands.class new file mode 100644 index 00000000..c340b89b Binary files /dev/null and b/src/main/out/production/main/app/Parser$validCommands.class differ diff --git a/src/main/out/production/main/app/Parser.class b/src/main/out/production/main/app/Parser.class new file mode 100644 index 00000000..3409639d Binary files /dev/null and b/src/main/out/production/main/app/Parser.class differ diff --git a/src/main/out/production/main/app/Storage.class b/src/main/out/production/main/app/Storage.class new file mode 100644 index 00000000..749d2612 Binary files /dev/null and b/src/main/out/production/main/app/Storage.class differ diff --git a/src/main/out/production/main/app/UI.class b/src/main/out/production/main/app/UI.class new file mode 100644 index 00000000..3e9c2fb3 Binary files /dev/null and b/src/main/out/production/main/app/UI.class differ diff --git a/src/main/out/production/main/task/Deadline.class b/src/main/out/production/main/task/Deadline.class new file mode 100644 index 00000000..c6b0983d Binary files /dev/null and b/src/main/out/production/main/task/Deadline.class differ diff --git a/src/main/out/production/main/task/Event.class b/src/main/out/production/main/task/Event.class new file mode 100644 index 00000000..381a5c2c Binary files /dev/null and b/src/main/out/production/main/task/Event.class differ diff --git a/src/main/out/production/main/task/List.class b/src/main/out/production/main/task/List.class new file mode 100644 index 00000000..5eefa95e Binary files /dev/null and b/src/main/out/production/main/task/List.class differ diff --git a/src/main/out/production/main/task/Task.class b/src/main/out/production/main/task/Task.class new file mode 100644 index 00000000..675a3024 Binary files /dev/null and b/src/main/out/production/main/task/Task.class differ diff --git a/src/main/out/production/main/task/TaskCommands.class b/src/main/out/production/main/task/TaskCommands.class new file mode 100644 index 00000000..4d260e72 Binary files /dev/null and b/src/main/out/production/main/task/TaskCommands.class differ diff --git a/src/main/out/production/main/task/Todo.class b/src/main/out/production/main/task/Todo.class new file mode 100644 index 00000000..0ee30885 Binary files /dev/null and b/src/main/out/production/main/task/Todo.class differ diff --git a/src/main/text-ui-test/ACTUAL.TXT b/src/main/text-ui-test/ACTUAL.TXT new file mode 100644 index 00000000..99ca25ab --- /dev/null +++ b/src/main/text-ui-test/ACTUAL.TXT @@ -0,0 +1,30 @@ +Hello from + ____ _ +| _ \ _ _| | _____ +| | | | | | | |/ / _ \ +| |_| | |_| | < __/ +|____/ \__,_|_|\_\___| + +Hello, I'm Duke +What can I do for you? + +________________________________________________ + +Got it. I've added this task: + [null][ ] dance + +Got it. I've added this task: + [null][ ] sing + +Got it. I've added this task: + [null][ ] act +Here are the tasks in your list: +1. [null][ ] dance +2. [null][ ] sing +3. [null][ ] act +Nice! I've marked this task as done: + [X] sing + +Got it. I've added this task: + [null][ ] done 2 + Bye! Thanks for visiting The Duke! diff --git a/src/main/text-ui-test/EXPECTED-UNIX.TXT b/src/main/text-ui-test/EXPECTED-UNIX.TXT new file mode 100644 index 00000000..4e400a3c --- /dev/null +++ b/src/main/text-ui-test/EXPECTED-UNIX.TXT @@ -0,0 +1,23 @@ +Hello from + ____ _ +| _ \ _ _| | _____ +| | | | | | | |/ / _ \ +| |_| | |_| | < __/ +|____/ \__,_|_|\_\___| + +Hello, I'm Duke +What can I do for you? +________________________________________________ +added: dance +________________________________________________ +added: sing +________________________________________________ +added: act +________________________________________________ +Here are the tasks in your list: +1. [ ] dance +2. [ ] sing +3. [ ] act +Nice! I've marked this task as done: + [X] sing + Bye! Thanks for visiting The Duke! diff --git a/src/main/text-ui-test/EXPECTED.txt b/src/main/text-ui-test/EXPECTED.txt new file mode 100644 index 00000000..4e400a3c --- /dev/null +++ b/src/main/text-ui-test/EXPECTED.txt @@ -0,0 +1,23 @@ +Hello from + ____ _ +| _ \ _ _| | _____ +| | | | | | | |/ / _ \ +| |_| | |_| | < __/ +|____/ \__,_|_|\_\___| + +Hello, I'm Duke +What can I do for you? +________________________________________________ +added: dance +________________________________________________ +added: sing +________________________________________________ +added: act +________________________________________________ +Here are the tasks in your list: +1. [ ] dance +2. [ ] sing +3. [ ] act +Nice! I've marked this task as done: + [X] sing + Bye! Thanks for visiting The Duke! diff --git a/src/main/text-ui-test/input.txt b/src/main/text-ui-test/input.txt new file mode 100644 index 00000000..3596387c --- /dev/null +++ b/src/main/text-ui-test/input.txt @@ -0,0 +1,6 @@ +dance +sing +act +list +done 2 +bye \ No newline at end of file diff --git a/src/main/text-ui-test/runtest.sh b/src/main/text-ui-test/runtest.sh new file mode 100644 index 00000000..b86ef4fe --- /dev/null +++ b/src/main/text-ui-test/runtest.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +# create bin directory if it doesn't exist +if [ ! -d "../bin" ] +then + mkdir ../bin +fi + +# delete output from previous run +if [ -e "./ACTUAL.TXT" ] +then + rm ACTUAL.TXT +fi + +# compile the code into the bin folder, terminates if error occurred +if ! javac -cp /Users/mwhy/duke/src/main/java -Xlint:none -d ../bin /Users/mwhy/duke/src/main/java/*.java +then + echo "********** BUILD FAILURE **********" + exit 1 +fi + +# 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 + +# convert to UNIX format +cp EXPECTED.TXT EXPECTED-UNIX.TXT +dos2unix ACTUAL.TXT EXPECTED-UNIX.TXT + +# compare the output to the expected output +diff ACTUAL.TXT EXPECTED-UNIX.TXT +if [ $? -eq 0 ] +then + echo "Test result: PASSED" + exit 0 +else + echo "Test result: FAILED" + exit 1 +fi diff --git a/src/test/java/app/DateTimeTest.java b/src/test/java/app/DateTimeTest.java new file mode 100644 index 00000000..e3a2f783 --- /dev/null +++ b/src/test/java/app/DateTimeTest.java @@ -0,0 +1,44 @@ +package app; + +import com.tic2002.task.DateTime; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.RepeatedTest; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class DateTimeTest { + DateTime dateTime; + String date = "2021-11-11"; + String time = "05:00"; + + @BeforeEach + void setUp() { + dateTime = new DateTime(); + } + @org.junit.jupiter.api.Test + @DisplayName("Dates should return true") + void testIsValidDate() { + assertEquals(true, dateTime.isValidDate(date), + "Correct date should work"); + } + + @org.junit.jupiter.api.Test + @DisplayName("Time should return true") + void isValidTime() { + assertEquals(true, dateTime.isValidTime(time), + "Correct time should work"); + } + + @org.junit.jupiter.api.Test + void toDate() { + } + + @org.junit.jupiter.api.Test + void toTime() { + } + + @org.junit.jupiter.api.Test + void toNewDateFormat() { + } +} \ No newline at end of file diff --git a/src/test/java/production/main/com/tic2002/app/DateTime.class b/src/test/java/production/main/com/tic2002/app/DateTime.class new file mode 100644 index 00000000..4155fcb9 Binary files /dev/null and b/src/test/java/production/main/com/tic2002/app/DateTime.class differ diff --git a/src/test/java/production/main/com/tic2002/app/DukeException.class b/src/test/java/production/main/com/tic2002/app/DukeException.class new file mode 100644 index 00000000..eefc6031 Binary files /dev/null and b/src/test/java/production/main/com/tic2002/app/DukeException.class differ diff --git a/src/test/java/production/main/com/tic2002/app/Parser$validCommands.class b/src/test/java/production/main/com/tic2002/app/Parser$validCommands.class new file mode 100644 index 00000000..7a6319fc Binary files /dev/null and b/src/test/java/production/main/com/tic2002/app/Parser$validCommands.class differ diff --git a/src/test/java/production/main/com/tic2002/app/Parser.class b/src/test/java/production/main/com/tic2002/app/Parser.class new file mode 100644 index 00000000..3b662e15 Binary files /dev/null and b/src/test/java/production/main/com/tic2002/app/Parser.class differ diff --git a/src/test/java/production/main/com/tic2002/app/Storage.class b/src/test/java/production/main/com/tic2002/app/Storage.class new file mode 100644 index 00000000..eff2e6dd Binary files /dev/null and b/src/test/java/production/main/com/tic2002/app/Storage.class differ diff --git a/src/test/java/production/main/com/tic2002/app/UI.class b/src/test/java/production/main/com/tic2002/app/UI.class new file mode 100644 index 00000000..fe5f21a3 Binary files /dev/null and b/src/test/java/production/main/com/tic2002/app/UI.class differ diff --git a/src/test/java/production/main/com/tic2002/duke/Duke.class b/src/test/java/production/main/com/tic2002/duke/Duke.class new file mode 100644 index 00000000..7f8b91a0 Binary files /dev/null and b/src/test/java/production/main/com/tic2002/duke/Duke.class differ diff --git a/src/test/java/production/main/com/tic2002/task/Deadline.class b/src/test/java/production/main/com/tic2002/task/Deadline.class new file mode 100644 index 00000000..de44c47b Binary files /dev/null and b/src/test/java/production/main/com/tic2002/task/Deadline.class differ diff --git a/src/test/java/production/main/com/tic2002/task/Event.class b/src/test/java/production/main/com/tic2002/task/Event.class new file mode 100644 index 00000000..c3a0c6c0 Binary files /dev/null and b/src/test/java/production/main/com/tic2002/task/Event.class differ diff --git a/src/test/java/production/main/com/tic2002/task/Find.class b/src/test/java/production/main/com/tic2002/task/Find.class new file mode 100644 index 00000000..38afce6c Binary files /dev/null and b/src/test/java/production/main/com/tic2002/task/Find.class differ diff --git a/src/test/java/production/main/com/tic2002/task/List.class b/src/test/java/production/main/com/tic2002/task/List.class new file mode 100644 index 00000000..203c1f37 Binary files /dev/null and b/src/test/java/production/main/com/tic2002/task/List.class differ diff --git a/src/test/java/production/main/com/tic2002/task/Priority$validPriority.class b/src/test/java/production/main/com/tic2002/task/Priority$validPriority.class new file mode 100644 index 00000000..57bc120e Binary files /dev/null and b/src/test/java/production/main/com/tic2002/task/Priority$validPriority.class differ diff --git a/src/test/java/production/main/com/tic2002/task/Priority.class b/src/test/java/production/main/com/tic2002/task/Priority.class new file mode 100644 index 00000000..82eafe89 Binary files /dev/null and b/src/test/java/production/main/com/tic2002/task/Priority.class differ diff --git a/src/test/java/production/main/com/tic2002/task/Task.class b/src/test/java/production/main/com/tic2002/task/Task.class new file mode 100644 index 00000000..9e8f4818 Binary files /dev/null and b/src/test/java/production/main/com/tic2002/task/Task.class differ diff --git a/src/test/java/production/main/com/tic2002/task/TaskCommands.class b/src/test/java/production/main/com/tic2002/task/TaskCommands.class new file mode 100644 index 00000000..d0cfcd3e Binary files /dev/null and b/src/test/java/production/main/com/tic2002/task/TaskCommands.class differ diff --git a/src/test/java/production/main/com/tic2002/task/Todo.class b/src/test/java/production/main/com/tic2002/task/Todo.class new file mode 100644 index 00000000..be19aa6c Binary files /dev/null and b/src/test/java/production/main/com/tic2002/task/Todo.class differ diff --git a/src/test/java/task/TodoTest.java b/src/test/java/task/TodoTest.java new file mode 100644 index 00000000..71630c87 --- /dev/null +++ b/src/test/java/task/TodoTest.java @@ -0,0 +1,25 @@ +package task; + +import com.tic2002.task.Todo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class TodoTest { + + Todo todo; + String description = "having lunch"; + + @BeforeEach + void setUp(){ + todo = new Todo(description); + } + @Test + @DisplayName("Should print correct entries") + void printTask() { + assertEquals("[T][ ] having lunch", todo.printTask(), + "should match output"); + } +} \ No newline at end of file diff --git a/src/test/java/test/test/app/DateTimeTest.class b/src/test/java/test/test/app/DateTimeTest.class new file mode 100644 index 00000000..e7cb54bc Binary files /dev/null and b/src/test/java/test/test/app/DateTimeTest.class differ diff --git a/src/test/java/test/test/task/TodoTest.class b/src/test/java/test/test/task/TodoTest.class new file mode 100644 index 00000000..8f80259f Binary files /dev/null and b/src/test/java/test/test/task/TodoTest.class differ diff --git a/text-ui-test/runtest.sh b/text-ui-test/runtest.sh old mode 100644 new mode 100755