Skip to content

Commit

Permalink
Merge branch 'branch-Level-10'
Browse files Browse the repository at this point in the history
  • Loading branch information
ChanWeiJie committed Jan 30, 2022
2 parents a176dd1 + edda1cd commit c7dbf78
Show file tree
Hide file tree
Showing 22 changed files with 405 additions and 135 deletions.
13 changes: 13 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,26 @@ plugins {
id 'application'
id 'checkstyle'
id 'com.github.johnrengelman.shadow' version '5.1.0'
id 'org.openjfx.javafxplugin' version '0.0.10'
}

javafx {
version = "11.0.2"
modules = [ 'javafx.controls' ]
}

repositories {
mavenCentral()
}

dependencies {
String javaFxVersion = '11'

implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'win'
implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'win'
implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'win'
implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'win'

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'
}
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/duke/command/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ public AddCommand(Task task) {
}

/**
* Returns nothing, but adds the specified task in the taskList in TaskList class.
* Returns a string which contains the message after adding the task to the list.
* @param tasks an object of TaskList, used to access public methods in TaskList class.
* @return crafted message after adding task to list.
*/
@Override
public void execute(TaskList tasks) {
public String execute(TaskList tasks) {
String message = "Got it. I've added this task:\n";
tasks.addToList(super.task);
return message + super.task.toString() + "\nNow you have " + tasks.getListSize() + " tasks in the list.";
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/duke/command/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ public Command(Task task, Integer number, String word) {
}

/**
* Returns nothing, but used to execute the respective methods in TaskList class.
* Returns a string, after the execution of the respective methods in TaskList class.
* @param tasks an object of TaskList, used to access public methods in TaskList class.
* @return a String representing the respective messages after the execution of the methods in TaskList class.
*/
public abstract void execute(TaskList tasks);
public abstract String execute(TaskList tasks);

/**
* Returns a boolean depending on the input command of the user.
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/duke/command/DeleteCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package duke.command;

import duke.functionality.TaskList;
import duke.task.Task;

/**
* Represents the delete command. A <code>DeleteCommand</code> object corresponds to deleting that specified task
Expand All @@ -17,12 +18,16 @@ public DeleteCommand(Integer number) {
}

/**
* Returns nothing, but deletes the specified task in the taskList in TaskList class.
* Returns a string which contains the message after deleting the task from the list.
* @param tasks an object of TaskList, used to access public methods in TaskList class.
* @return crafted message after deleting task from list.
*/
@Override
public void execute(TaskList tasks) {
tasks.deleteTask(super.index);
public String execute(TaskList tasks) {
Task deletedTask = tasks.deleteTask(super.index);
String message = "Noted. I've removed this task:\n";
return message + deletedTask.toString() + "\n"
+ "Now you have " + tasks.getListSize() + " tasks in the list.";
}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/duke/command/ExitCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ public ExitCommand() {
}

/**
* Returns nothing & does not execute anything.
* Returns a string which contains the message to stop the execution of Duke.
* @param tasks an object of TaskList, used to access public methods in TaskList class.
* @return crafted message to signify the end of execution.
*/
@Override
public void execute(TaskList tasks) { }
public String execute(TaskList tasks) {
return "Bye. Hope to see you again soon!";
}

/**
* Returns true as the Command is an ExitCommand.
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/duke/command/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,24 @@ public FindCommand(String word) {
}

/**
* Returns nothing, but finds all task that share the same word in the taskList in TaskList class.
* Returns a string which contains all the task after the execution of findWord in the TaskList class.
* @param tasks an object of TaskList, used to access public methods in TaskList class.
* @return crafted message after calling findword in the TaskList class.
*/
@Override
public void execute(TaskList tasks) {
tasks.findWord(super.word);
public String execute(TaskList tasks) {
TaskList newTaskList = tasks.findWord(super.word);
String message = "Here are the matching tasks in your list:\n";
int counter = 1;
for (int i = 0; i < newTaskList.getListSize(); i++) {
String output = counter + "." + newTaskList.getTask(i);
counter++;
message += output + "\n";
}
if (counter == 1) {
message = "OOPS!, there are no matching task with the word provided." + "\n";
}
return message;
}

/**
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/duke/command/MarkCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package duke.command;

import duke.functionality.TaskList;
import duke.task.Task;

/**
* Represents the mark command. A <code>MarkCommand</code> object allows users to set the corresponding task as done.
Expand All @@ -16,12 +17,15 @@ public MarkCommand(Integer number) {
}

/**
* Returns nothing, but marks the corresponding task in the taskList in TaskList class as done.
* Returns a string which contains the message after marking the task from the list.
* @param tasks an object of TaskList, used to access public methods in TaskList class.
* @return crafted message after marking task from the list.
*/
@Override
public void execute(TaskList tasks) {
tasks.markTask(super.index);
public String execute(TaskList tasks) {
Task markedTask = tasks.markTask(super.index);
String message = "Nice! I've marked this task as done:\n";
return message + markedTask;
}

/**
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/duke/command/PrintCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ public PrintCommand() {
}

/**
* Returns nothing, but prints out all the task in the taskList in TaskList class.
* Returns a string which contains all the task after the execution of printList in the TaskList class.
* @param tasks an object of TaskList, used to access public methods in TaskList class.
* @return crafted message after calling printList in the TaskList class.
*/
@Override
public void execute(TaskList tasks) {
tasks.printList();
public String execute(TaskList tasks) {
return tasks.printList();
}

/**
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/duke/command/UnmarkCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package duke.command;

import duke.functionality.TaskList;
import duke.task.Task;

/**
* Represents the unmark command. A <code>UnmarkCommand</code> object allows users to set the corresponding task as
Expand All @@ -17,12 +18,15 @@ public UnmarkCommand(Integer number) {
}

/**
* Returns nothing, but marks the corresponding task in the taskList in TaskList class as not done.
* Returns a string which contains the message after unmarking the task from the list.
* @param tasks an object of TaskList, used to access public methods in TaskList class.
* @return crafted message after unmarking task from the list.
*/
@Override
public void execute(TaskList tasks) {
tasks.unMarkTask(super.index);
public String execute(TaskList tasks) {
String message = "OK, I've marked this task as not done yet:\n";
Task unMarkedTask = tasks.unMarkTask(super.index);
return message + unMarkedTask;
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/duke/functionality/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import duke.command.MarkCommand;
import duke.command.PrintCommand;
import duke.command.UnmarkCommand;
import duke.exception.BlankCommandException;
import duke.exception.DukeException;
import duke.exception.IncompleteCommandException;
import duke.exception.InvalidCommandException;
Expand Down Expand Up @@ -113,7 +114,7 @@ public static Command parse(String input) throws DukeException {
date = formatDate(splitDuration[0]);
time = formatTime(splitDuration[1]);
} catch (DateTimeParseException e) {
throw new DukeException("The expected input form is deadline ____ /by yyyy-mm-dd hhmm");
throw new DukeException("The expected input form is deadline xxx /by yyyy-mm-dd hhmm");
}

return new AddCommand(new Deadline(description, date, time));
Expand All @@ -136,7 +137,7 @@ public static Command parse(String input) throws DukeException {
startTime = formatTime(splitDuration[1]);
endTime = formatTime(splitDuration[2]);
} catch (DateTimeParseException e) {
throw new DukeException("The expected input form is event ____ /at yyyy-mm-dd hhmm hhmm");
throw new DukeException("The expected input form is event xxx /at yyyy-mm-dd hhmm hhmm");
}

return new AddCommand(new Event(description, date, startTime, endTime));
Expand All @@ -153,6 +154,9 @@ public static Command parse(String input) throws DukeException {
} else if (command.equals("find")) {
return new FindCommand(inputSplit[1]);

} else if (command.equals("")) {
throw new BlankCommandException();

} else {
throw new InvalidCommandException();
}
Expand Down
53 changes: 26 additions & 27 deletions src/main/java/duke/functionality/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,17 @@ public Storage(String pwd, String path) {
Storage.path = path;
}

/**
* Returns nothing, but stores the specified task into the taskList in TaskList class.
* @param task the task created in Parser class.
*/
public static void storeToList(Task task) { //same as addToList but no printing
TaskList.taskList.add(task);
TaskList.numOfTask++;
}

/**
* Returns nothing, but stores all task into the text file specified by path.
* @param path path to "/data/TaskData.txt".
* @param taskList the tasklist to be written.
* @throws IOException if the text file is missing.
*/
public static void writeToFile(String path) throws IOException {
public static void writeToFile(String path, TaskList taskList) throws IOException {
FileWriter fw = new FileWriter(path);
for (int i = 0; i < TaskList.numOfTask; i++) {
Task task = TaskList.taskList.get(i);
for (int i = 0; i < taskList.getListSize(); i++) {
Task task = taskList.getTask(i);
fw.write(craftOutput(task));
fw.write(System.lineSeparator());
}
Expand All @@ -56,21 +49,24 @@ public static void writeToFile(String path) throws IOException {
/**
* Returns nothing, but calls writeToFile to update the text file.
*/
public static void updateTextFile() {
public static void updateTextFile(TaskList taskList) {
try {
writeToFile(Storage.pwd + Storage.path);
writeToFile(Storage.pwd + Storage.path, taskList);
} catch (IOException e) {
System.out.println("Something happened to the text file !" + e.getMessage());
}
}

/**
* Returns nothing, but reads the input from the specified file and stores them in the taskList in TaskList class.
* Returns a new Tasklist object that is the saved taskList which consist of all the data read
* from the file provided.
* @param file the text file that stores all tasks.
* @return a TaskList object representing the saved taskList.
* @throws FileNotFoundException if the file is missing.
*/
public static void readFileDataAndStoreInList(File file) throws FileNotFoundException {
public TaskList readFileDataAndStoreInList(File file) throws FileNotFoundException {
Scanner sc = new Scanner(file);
TaskList newTaskList = new TaskList();
while ((sc.hasNextLine())) {
String input = sc.nextLine();
String[] inputSplit = input.split("\\|"); //split input by |
Expand All @@ -81,23 +77,24 @@ public static void readFileDataAndStoreInList(File file) throws FileNotFoundExce
if (mark == 1) {
tempTask.setTaskDone();
}
storeToList(tempTask);
newTaskList.addToList(tempTask);
} else if (task.equals("D")) {
Deadline tempTask = new Deadline(inputSplit[2], Parser.formatDate(inputSplit[3]),
Parser.formatTime(inputSplit[4]));
if (mark == 1) {
tempTask.setTaskDone();
}
storeToList(tempTask);
newTaskList.addToList(tempTask);
} else if (task.equals("E")) {
Event tempTask = new Event(inputSplit[2], Parser.formatDate(inputSplit[3]) ,
Parser.formatTime(inputSplit[4]), Parser.formatTime(inputSplit[5]));
if (mark == 1) {
tempTask.setTaskDone();
}
storeToList(tempTask);
newTaskList.addToList(tempTask);
}
}
return newTaskList;
}

/**
Expand Down Expand Up @@ -137,18 +134,20 @@ public static String craftOutput(Task task) {
}

/**
* Returns nothing, but loads all tasks from the specified path.
* @throws IOException if the file is missing.
* Returns a TaskList object after loading all tasks from the specified path.
* @return a TaskList object representing the saved taskList.
* @throws IOException if the file or directory is missing.
*/
public void load() throws IOException {
public TaskList load() throws IOException {
File directory = new File(pwd + "/data");
File inputFile = new File(pwd + path);
if (directory.mkdir()) {
System.out.println("You do not have the Directory, do not worry! I will create the directory for you");
}
if (inputFile.createNewFile()) {
System.out.println("You do not have the file, do not worry! I will create the file for you");
if (directory.mkdir() && inputFile.createNewFile()) {
throw new IOException("Do not worry! I will create the directory & file for you");

} else if (inputFile.createNewFile()) {
throw new IOException("Do not worry! I will create the file for you");
}
readFileDataAndStoreInList(inputFile);

return readFileDataAndStoreInList(inputFile);
}
}
Loading

0 comments on commit c7dbf78

Please sign in to comment.