diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000000..20c0521cc7 --- /dev/null +++ b/build.gradle @@ -0,0 +1,46 @@ +plugins { + id 'java' + id 'application' + id 'checkstyle' + id 'com.github.johnrengelman.shadow' version '5.1.0' +} + +repositories { + mavenCentral() +} + +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' +} + +test { + useJUnitPlatform() + + testLogging { + events "passed", "skipped", "failed" + + showExceptions true + exceptionFormat "full" + showCauses true + showStackTraces true + showStandardStreams = false + } +} + +application { + mainClassName = "seedu.duke.Duke" +} + +shadowJar { + archiveBaseName = "duke" + archiveClassifier = null +} + +checkstyle { + toolVersion = '8.29' +} + +run{ + standardInput = System.in +} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000..f3d88b1c2f 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..b7c8c5dbf5 --- /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 0000000000..2fe81a7d95 --- /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 0000000000..62bd9b9cce --- /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/java/Deadlines.java b/src/main/java/Deadlines.java new file mode 100644 index 0000000000..26b601f76f --- /dev/null +++ b/src/main/java/Deadlines.java @@ -0,0 +1,33 @@ +/** + * Deadlines is a task that have a deadline which is a string. + * @author Dominic Siew Zhen Yu + * + */ + +public class Deadlines extends Task{ + private String deadline; + String TASKINDICATOR = "[D]"; + + /** + * The constructor for the Deadlines class with the userInput (which refers to the name of the task) + * and the deadline parameter which is the deadline of the deadlines task. + * + * @param userInput the name of the deadlines + * @param deadline the time you have to complete the Deadlines + */ + + public Deadlines(String userInput, String deadline) { + super(userInput); + this.deadline = deadline; + } + + /** + * the printName() method prints the name of the deadlines task. + * + * @return the string representation of the deadlines + */ + + public String printName() { + return TASKINDICATOR + " " + super.printName() + " (by: " + this.deadline + " )"; + } +} \ No newline at end of file diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5d313334cc..565de75a12 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,10 +1,137 @@ +/** + * Duke is a chatbot that takes in tasks, which includes todos, deadlines and events, and compiles them + * in a list. Tasks can be removed from the list and be marked as completed. + * + * @author Dominic Siew Zhen Yu + * + */ + +import java.io.*; +import java.util.Scanner; + public class Duke { - public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" + + public enum Tasks { + DEADLINE, + EVENT, + TODO + } + + public static void main(String[] args) throws IOException { + String logo = " ____ _\n" + + "| _ \\ _ _| | _____\n" + "| | | | | | | |/ / _ \\\n" + "| |_| | |_| | < __/\n" + "|____/ \\__,_|_|\\_\\___|\n"; System.out.println("Hello from\n" + logo); + System.out.println("____________________________________________________________\nHello! I'm Duke\nWhat can I do for you?\n____________________________________________________________"); + + boolean isEnded = false; + List taskList = null; + taskList = new List(); + + File file = new File("src/main/memory.txt"); + + if (!(file.exists())){ + System.out.println("processing!"); + try { + PrintWriter writer = new PrintWriter("src/main/memory.txt"); + writer.print(""); + writer.close(); + + } catch (IOException e) { + e.printStackTrace(); + } + } else { + + + + File updated = new File("src/main/updated.txt"); + BufferedReader reader = new BufferedReader(new FileReader("src/main/memory.txt")); + BufferedWriter writer = new BufferedWriter(new FileWriter(updated)); + String currentLine = ""; + int numberAdded = 1; + + + + while ((currentLine = reader.readLine()) != null) { + String[] seperate1 = currentLine.toString().split(" ", 2); + String taskTypeText = seperate1[0]; + String taskType; + + String[] seperate2 = seperate1[1].toString().split(" ", 2); + boolean isCompleted = (seperate2[0].equals("[✓]"))? true: false; + String eventInfo = seperate2[1]; + + switch(taskTypeText) { + case "[T]": + String eventname = eventInfo; + taskList.addTodo(eventname, false); + break; + case "[D]": + String[] seperateAgain = seperate2[1].split(" \\(by: ", 2); + String eventName = seperateAgain[0]; + String deadline = seperateAgain[1].split(" ", 2)[0]; + taskList.addDeadline(eventName, deadline, false); + break; + case "[E]": + String[] seperateAgaining = seperate2[1].split(" \\(at: ", 2); + String event = seperateAgaining[0]; + String timeline = seperateAgaining[1].split(" ", 2)[0]; + taskList.addDeadline(event, timeline, false); + break; + } + + if (isCompleted){ + taskList.updateTaskStatus(numberAdded, false); + } + numberAdded++; + } + + } + + + + + Scanner sc= new Scanner(System.in); + + while(!isEnded) { + String userInput = sc.nextLine(); + System.out.println("____________________________________________________________"); + String[] parsedInput = userInput.split(" ", 2); + + + if (parsedInput[0].equals("todo")) { + if (parsedInput.length == 1 ) { + throw new DukeException("empty"); + } + taskList.addTodo(parsedInput[1], true); + + } else if (parsedInput[0].equals("deadline")) { + String[] furtherParsed = parsedInput[1].split(" /by ", 2); + taskList.addDeadline(furtherParsed[0], furtherParsed[1], true); + } else if (parsedInput[0].equals("event")){ + String[] furtherParsed = parsedInput[1].split(" /at ",2); + taskList.addEvent(furtherParsed[0],furtherParsed[1], true); + } else if(userInput.equals("bye")){ + System.out.println("Bye. Hope to see you again soon!"); + isEnded = true; + } else if (userInput.equals("list")){ + taskList.printList(); + } else if (parsedInput[0].equals("done")) { + int itemRank = Integer.parseInt(parsedInput[1]); + taskList.updateTaskStatus(itemRank, true); + + } else if (parsedInput[0].equals("remove")){ + int itemRank = Integer.parseInt(parsedInput[1]); + taskList.removeTask(itemRank - 1 ); + } else { + System.out.println("Please give an appropriate response."); + throw new DukeException("generic"); + } + System.out.println("____________________________________________________________"); + } + + } } diff --git a/src/main/java/DukeException.java b/src/main/java/DukeException.java new file mode 100644 index 0000000000..73e6ea831c --- /dev/null +++ b/src/main/java/DukeException.java @@ -0,0 +1,32 @@ +/** + * DukeException is an ArrayIndexOutOfBoundsException that are caused by errors in the Duke program. + */ +public class DukeException extends ArrayIndexOutOfBoundsException { + private String cause; + + /** + * this is a constructor for the DukeException class; it contains a message parameter + * that specifies the error message to be displayed. + * + * @param message a String that is used to specify the error message to be produced + */ + + DukeException(String message) { + this.cause = message; + } + + /** + * the toString() method of the class that returns a string representation of the + * error produced in the program Duke. + * + * @return a string representation of the error produced + */ + @Override + public String toString() { + if (this.cause.equals("empty")) { + return "OOPS!!! The description of a todo cannot be empty."; + } else { + return "OOPS!!! I'm sorry, but I don't know what that means :-("; + } + } +} diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 0000000000..a9bdb81d6a --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,29 @@ +/** + * Events are tasks that have a timeline. + * + * @author Dominic Siew Zhen Yu + */ +public class Event extends Task{ + private String timeline; + String TASKINDICATOR = "[E]"; + + /** + * The constructor of the events class. + * + * @param userInput the name of the task + * @param timeline the period of which the event is taking place + */ + public Event(String userInput, String timeline) { + super(userInput); + this.timeline = timeline; + } + + /** + * printName() method returns the name and the task indicator of the Event object. + * + * @return a string representation of a Event object + */ + public String printName() { + return TASKINDICATOR + " " + super.printName() + " (at: " + this.timeline + " )"; + } +} \ No newline at end of file diff --git a/src/main/java/List.java b/src/main/java/List.java new file mode 100644 index 0000000000..d22f664565 --- /dev/null +++ b/src/main/java/List.java @@ -0,0 +1,219 @@ + +/** + * List refers to a task list that is used in the Duke program. + * An List object contains the tasks and several methods that work on the task. + * + * @author Dominic Siew Zhen Yu + */ + +import java.io.*; +import java.util.ArrayList; + +public class List { + private ArrayList taskList; + private FileWriter taskFile; + private boolean isFirstTimeOpening; + + /** + * The constructor for the List class that instantiates a List object. + */ + + public List() throws IOException { + this.taskList = new ArrayList(); + File file = new File("src/main/memory.txt"); +// System.out.println(file.exists()); +// if (!(file.exists())){ +// PrintWriter writer = new PrintWriter("src/main/memory.txt"); +// writer.print(""); +// writer.close(); +// } else { + } + + /** + * the addTask() places generic tasks into the list (which was used in level 1-3). + * + * @param userInput + */ + + public void addTask(String userInput) { + taskList.add(new Task(userInput)); + } + + /** + * the printList() method prints out the String representation of the tasks + * in the List object. + */ + + public void printList() { + int numb = 1; + System.out.println("Here are the tasks in your list:"); + for(Task task: taskList) { + System.out.println(numb + ". " + task.printName()); + numb++; + } + } + + /** + * the updateTaskStatus() method marks a task to be as completed. + * + * @param userInput the rank of the task in a list + */ + + public void updateTaskStatus(int userInput, boolean isInput) { + if (userInput > taskList.size()) { + System.out.println("please enter a number that's between 1 and " + taskList.size()); + return ; + } + Task task = taskList.get(userInput - 1); + + String lineToRemove = task.printName(); + task.toggleComplete(); + + if (isInput) { + System.out.println("Nice! I've marked this task as done:"); + System.out.println(task.printName()); + + try { + File input = new File("src/main/memory.txt"); + File updated = new File("src/main/updated.txt"); + + BufferedReader reader = new BufferedReader(new FileReader(input)); + BufferedWriter writer = new BufferedWriter(new FileWriter(updated)); + + String currentLine = ""; + + while ((currentLine = reader.readLine()) != null) { + + if (currentLine.equals(lineToRemove)) { + writer.write(task.printName() + "\n"); + continue; + } + writer.write(currentLine + "\n"); + } + writer.close(); + reader.close(); + + boolean successful = updated.renameTo(input); + + } catch (IOException e) { + e.printStackTrace(); + } + } + + + } + + /** + * the addTodo() method adds todos task into the list object + * + * @param userInput the name of the todo task + */ + + public void addTodo(String userInput, boolean isInput) { + Task task = new Todos(userInput); + taskList.add(task); + + if (isInput) { + System.out.println("Got it. I've added this task:"); + System.out.println(task.printName()); + System.out.println("Now you have " + taskList.size() + " tasks in the list."); + try { + FileWriter fw = new FileWriter("src/main/memory.txt", true); + fw.write(task.printName() + "\n"); + fw.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } else { + + } + + } + /** + * the addEvent() method adds Events task into the list object. + * + * @param name the name of the event + * @param timeline the period that the event is taking place + */ + public void addEvent(String name, String timeline, boolean isInput) { + Task task = new Event(name, timeline); + taskList.add(task); + if (isInput) { + System.out.println("Got it. I've added this task:"); + System.out.println(task.printName()); + System.out.println("Now you have " + taskList.size() + " tasks in the list."); + + try { + FileWriter fw = new FileWriter("src/main/memory.txt", true); + fw.write(task.printName() + "\n"); + fw.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + } + /** + * the addDeadline() method adds Events task into the list object. + * + * @param name the name of the deadline + * @param deadline the deadline of the deadline task + */ + public void addDeadline(String name, String deadline, boolean isInput) { + Task task = new Deadlines(name, deadline); + taskList.add(task); + + if (isInput) { + System.out.println("Got it. I've added this task:"); + System.out.println(task.printName()); + System.out.println("Now you have " + taskList.size() + " tasks in the list."); + try { + FileWriter fw = new FileWriter("src/main/memory.txt", true); + fw.write(task.printName() + "\n"); + fw.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + /** + * the removeTask() method removes the task from the list object. + * + * @param userInput the rank of the task in a list + */ + public void removeTask(int userInput) { + Task task = taskList.get(userInput); + System.out.println("Noted. I've removed the task:"); + System.out.println(task.printName()); + taskList.remove(userInput); + System.out.println("Now you have " + taskList.size() + " tasks in the list."); + + String lineToRemove = task.printName(); + + try { + File input = new File("src/main/memory.txt"); + File updated = new File("src/main/updated.txt"); + + BufferedReader reader = new BufferedReader(new FileReader(input)); + BufferedWriter writer = new BufferedWriter(new FileWriter(updated)); + + String currentLine = ""; + + while ((currentLine = reader.readLine()).equals(null)) { + + if (currentLine.equals(lineToRemove)) { + continue; + } + writer.write(currentLine + "\n"); + } + writer.close(); + reader.close(); + + boolean successful = updated.renameTo(input); + + } catch (IOException e) { + e.printStackTrace(); + } + } + +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 0000000000..f917dc1a71 --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,45 @@ +/** + * Task are work that has a name (that's a string) and a boolean which is true when a task is completed. + * + * @author Dominic Siew Zhen Yu + */ +public class Task { + private String name; + private boolean completed; + + private String COMPLETED = "[✓]"; + private String UNCOMPLETED = "[✕]"; + + /** + * the constructor of the Task class. + * + * @param name the name of the task + */ + + public Task(String name) { + this.name = name; + completed = false; + } + + /** + * printName() method returns the name of the Task object, and whether the task is completed or not. + * + * @return a string representation of a Task object + */ + + public String printName() { + String completionStatus = completed? COMPLETED: UNCOMPLETED; + return completionStatus + " " + this.name; + } + + /** + * the toggleComplete() method toggles the boolean "completed" when the task is completed, + * or if the user wishes to indicate that a task is incompleted if it is indicated as + * otherwise. + * + */ + + public void toggleComplete() { + completed = !completed; + } +} diff --git a/src/main/java/Todos.java b/src/main/java/Todos.java new file mode 100644 index 0000000000..3b46b44dc5 --- /dev/null +++ b/src/main/java/Todos.java @@ -0,0 +1,29 @@ +/** + * Todos are generic tasks, with a "Todo" indicator. + * + * @author Dominic Siew Zhen Yu + */ +public class Todos extends Task{ + String TASKINDICATOR = "[T]"; + + /** + * the constructor of the Todos object + * + * @param userInput the name of the object + */ + + public Todos (String userInput) { + super(userInput); + } + + /** + * printName() method returns the name of the Todos object, and an indication that it + * is a todos task. + * + * @return a string representation of a Task object + */ + + public String printName() { + return TASKINDICATOR + " " + super.printName(); + } +} \ No newline at end of file diff --git a/src/main/memory.txt b/src/main/memory.txt new file mode 100644 index 0000000000..00ae5715e5 --- /dev/null +++ b/src/main/memory.txt @@ -0,0 +1,5 @@ +[T] [✓] homework +[D] [✕] yay (by: yay ) +[T] [✕] helo me +[T] [✕] i hate cs +[D] [✕] help (by: today ) diff --git a/src/main/updated.txt b/src/main/updated.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 657e74f6e7..99d638f1a9 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,7 +1,49 @@ Hello from - ____ _ -| _ \ _ _| | _____ + ____ _lis +| _ \ _ _| | _____ | | | | | | | |/ / _ \ | |_| | |_| | < __/ |____/ \__,_|_|\_\___| +____________________________________________________________ +Hello! I'm Duke +What can I do for you? +____________________________________________________________ +____________________________________________________________ +Got it. I've added this task: +[T][UNCOMPLETED]meeting +Now you have 1 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Got it. I've added this task: +[D][UNCOMPLETED]application(by: 4th August) +Now you have 2 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Got it. I've added this task: +[E][UNCOMPLETED]carnival(at: January 4-5pm) +Now you have 3 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Here are the tasks in your list: +1. [T][UNCOMPLETED]meeting +2. [D][UNCOMPLETED]application(by: 4th August) +3. [E][UNCOMPLETED]carnival(at: January 4-5pm) +____________________________________________________________ +____________________________________________________________ +Noted. I've removed the task: +[E][UNCOMPLETED]carnival(at: January 4-5pm) +Now you have 2 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Here are the tasks in your list: +1. [T][UNCOMPLETED]meeting +2. [D][UNCOMPLETED]application(by: 4th August) +____________________________________________________________ +____________________________________________________________ +Nice! I've marked this task as done: +[D][COMPLETED]application(by: 4th August) +____________________________________________________________ +____________________________________________________________ +Bye. Hope to see you again soon! +____________________________________________________________ diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index e69de29bb2..2c21dbaa64 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -0,0 +1,8 @@ +todo meeting +deadline application /by 4th August +event carnival /at January 4-5pm +list +remove 3 +list +done 2 +bye \ No newline at end of file diff --git a/text-ui-test/runtest.sh b/text-ui-test/runtest.sh old mode 100644 new mode 100755 index e169618a34..c9ec870033 --- a/text-ui-test/runtest.sh +++ b/text-ui-test/runtest.sh @@ -13,7 +13,7 @@ then fi # compile the code into the bin folder, terminates if error occurred -if ! javac -cp ../src -Xlint:none -d ../bin ../src/main/java/Duke.java +if ! javac -cp ../src/main/java -Xlint:none -d ../bin ../src/main/java/*.java then echo "********** BUILD FAILURE **********" exit 1