Skip to content

Commit

Permalink
Add javadocs
Browse files Browse the repository at this point in the history
  • Loading branch information
teoks0199 committed Sep 20, 2023
1 parent 007cc3c commit c4d2251
Show file tree
Hide file tree
Showing 16 changed files with 225 additions and 25 deletions.
10 changes: 3 additions & 7 deletions data/duke.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ E | N | Finals | 2023-11-11 | 2023-11-12
T | Y | read book
T | N | return book
D | N | write book | 2023-10-10
E | N | book fair | 2000-11-11 | 2000-11-11
T | N | test
D | N | da | 2020-01-01
E | N | asdbf | 2020-10-10 | 2020-10-11
T | N | dao
T | N | dsih
T | N | dskjf
E | N | book fair | 2023-11-10 | 2023-11-11
T | Y | buy pants
D | N | project submission | 2023-11-10
Binary file added docs/Ui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 20 additions & 1 deletion src/main/java/duke/DialogBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ public class DialogBox extends HBox {
@FXML
private ImageView displayPicture;


/**
* Constructor for a DialogBox.
*
* @param text The text to be displayed.
* @param img The image to be displayed.
*/
private DialogBox(String text, Image img) {
try {
FXMLLoader fxmlLoader = new FXMLLoader(MainWindow.class.getResource("/view/DialogBox.fxml"));
Expand All @@ -51,11 +56,25 @@ private void flip() {
setAlignment(Pos.TOP_LEFT);
}

/**
* Creates a DialogBox for the user.
*
* @param text The text to be displayed.
* @param img The image to be displayed.
* @return The DialogBox.
*/
public static DialogBox getUserDialog(String text, Image img) {
var db = new DialogBox(text, img);
return db;
}

/**
* Creates a DialogBox for Duke.
*
* @param text The text to be displayed.
* @param img The image to be displayed.
* @return The DialogBox.
*/
public static DialogBox getDukeDialog(String text, Image img) {
var db = new DialogBox(text, img);
db.flip();
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
* @author Teo Kai Sheng
*/
public class Duke {
static final Path FILEPATH = Paths.get(".", "data", "duke.txt"); // Filepath: "./data/duke.txt"
private Storage storage;
private TaskList tasks;
static final Path FILEPATH = Paths.get(".", "data", "duke.txt"); // Filepath: "./data/duke.txt"

/**
* Constructor to start the program.
Expand Down Expand Up @@ -40,10 +40,19 @@ public void run() {
updateTaskList();
}

/**
* Updates the task list in the storage file.
*/
public void updateTaskList() {
storage.updateTaskList();
}

/**
* Gets the response from the parser.
*
* @param input The user input.
* @return The response from the parser.
*/
public String getResponse(String input) {
Parser parser = new Parser(tasks);
String response = parser.parse(input);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/duke/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
* A launcher class to workaround classpath issues.
*/
public class Launcher {

/**
* Launches the application.
*
* @param args The arguments passed in.
*/
public static void main(String[] args) {
Application.launch(Main.class, args);
}
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/duke/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@
* A GUI for Duke using FXML.
*/
public class Main extends Application {

private Duke duke = new Duke();

/**
* Starts the GUI.
*
* @param stage The stage to be used.
*/
@Override
public void start(Stage stage) {
stage.setTitle("Task Manager");
stage.show();
try {
FXMLLoader fxmlLoader = new FXMLLoader(Main.class.getResource("/view/MainWindow.fxml"));
AnchorPane ap = fxmlLoader.load();
Expand Down
17 changes: 13 additions & 4 deletions src/main/java/duke/MainWindow.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package duke;

import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
Expand All @@ -11,28 +10,39 @@
* Controller for MainWindow. Provides the layout for the other controls.
*/
public class MainWindow extends AnchorPane {
static final String INITIAL_RESPONSE = "Hello, I'm your task manager :)\nWhat can I do for you?";
static final String FINAL_RESPONSE = "Bye. Hope to see you again soon!";
@FXML
private ScrollPane scrollPane;
@FXML
private VBox dialogContainer;
@FXML
private TextField userInput;
private Duke duke;
static final String INITIAL_RESPONSE = "Hello, I'm your task manager :)\nWhat can I do for you?";
static final String FINAL_RESPONSE = "Bye. Hope to see you again soon!";
private Image userImage = new Image(this.getClass().getResourceAsStream("/images/DaUser.png"));
private Image dukeImage = new Image(this.getClass().getResourceAsStream("/images/DaDuke.png"));

/**
* Initializes the GUI.
*/
@FXML
public void initialize() {
scrollPane.vvalueProperty().bind(dialogContainer.heightProperty());
dialogContainer.getChildren().add(DialogBox.getDukeDialog(INITIAL_RESPONSE, dukeImage));
}

/**
* Sets the duke object.
*
* @param d The duke object.
*/
public void setDuke(Duke d) {
duke = d;
}

/**
* Gets the exit message from the duke object.
*/
public void getExitMessage() {
dialogContainer.getChildren().add(DialogBox.getDukeDialog(FINAL_RESPONSE, dukeImage));
}
Expand All @@ -49,7 +59,6 @@ private void handleUserInput() {
DialogBox.getUserDialog(input, userImage),
DialogBox.getDukeDialog(response, dukeImage)
);

userInput.clear();
}
}
33 changes: 22 additions & 11 deletions src/main/java/duke/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,40 @@ public String parse(String s) {
String command = input[0];
String output = "";
Ui.horizontalLine();
if (command.equals("list")) {
switch (command) {
case "list":
output = tasks.showList(input);
} else if (command.equals("mark")) {
break;
case "mark":
output = tasks.markTask(input);
} else if (command.equals("unmark")) {
break;
case "unmark":
output = tasks.unmarkTask(input);
} else if (command.equals("delete")) {
break;
case "delete":
output = tasks.deleteTask(input);
} else if (command.equals("deadline")) {
break;
case "deadline":
output = tasks.addDeadline(input);
} else if (command.equals("event")) {
break;
case "event":
output = tasks.addEvent(input);
} else if (command.equals("todo")) {
break;
case "todo":
output = tasks.addToDo(input);
} else if (command.equals("find")) {
break;
case "find":
output = tasks.findTasks(input);
} else if (command.equals("update")) {
break;
case "update":
output = tasks.updateTask(input);
} else if (command.equals("bye")) {
break;
case "bye":
this.isFinished = true;
output = Ui.bye();
Platform.exit();
} else {
break;
default:
output = Ui.unknownCommandErrorMessage();
}
Ui.horizontalLine();
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/duke/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ public String findTasks(String[] input) {
}
}

/**
* Updates the indicated task.
*
* @param input User input.
* @return The String representation of the output.
*/
public String updateTask(String[] input) {
try {
String[] s1 = input[1].split("/", 2);
Expand Down Expand Up @@ -257,6 +263,14 @@ public String updateTask(String[] input) {
}
}

/**
* Updates the task with the new value.
*
* @param task The task to be updated.
* @param toUpdate The field to be updated.
* @param newValue The new value.
* @throws DukeException Throws DukeException if the task type is wrong.
*/
private void updateTaskValue(Task task, String toUpdate, String newValue) throws DukeException {
switch (toUpdate) {
case "desc":
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/duke/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,72 +40,108 @@ public static String unknownCommandErrorMessage() {
return output;
}

/**
* Displays a message when the user enters an invalid command.
*/
public static String showListErrorMessage() {
String output = "Did you mean list?";
System.out.println(output);
return output;
}

/**
* Displays a message when the user enters an invalid command.
*/
public static String taskNotFoundErrorMessage() {
String output = "Task does not exist.";
System.out.println(output);
return output;
}

/**
* Displays a message when the user enters an invalid command.
*/
public static String markTaskErrorMessage() {
String output = "Please enter a number e.g., mark 1";
System.out.println(output);
return output;
}

/**
* Displays a message when the user enters an invalid command.
*/
public static String updateTaskErrorMessage() {
String output = "Format: update taskNumber /(desc, by, from, to) value, e.g. update 1 /from 2023-12-30";
System.out.println(output);
return output;
}

/**
* Displays a message when the user enters an invalid command.
*/
public static String wrongTaskTypeErrorMessage() {
String output = "This task type does not have the required field.";
System.out.println(output);
return output;
}

/**
* Displays a message when the user enters an invalid command.
*/
public static String unmarkTaskErrorMessage() {
String output = "Please enter a number e.g., unmark 1";
System.out.println(output);
return output;
}

/**
* Displays a message when the user enters an invalid command.
*/
public static String deleteTaskErrorMessage() {
String output = "Please enter a number e.g., delete 1";
System.out.println(output);
return output;
}

/**
* Displays a message when the user enters an invalid command.
*/
public static String invalidDateErrorMessage() {
String output = "Enter valid date yyyy-mm-dd";
System.out.println(output);
return output;
}

/**
* Displays a message when the user enters an invalid command.
*/
public static String addEventErrorMessage() {
String output = "Format: event description /from yyyy-mm-dd /to yyyy-mm-dd";
System.out.println(output);
return output;
}

/**
* Displays a message when the user enters an invalid command.
*/
public static String addDeadlineErrorMessage() {
String output = "Format: deadline description /by yyyy-mm-dd";
System.out.println(output);
return output;
}

/**
* Displays a message when the user enters an invalid command.
*/
public static String addToDoErrorMessage() {
String output = "OOPS!!! The description of a todo cannot be empty.";
System.out.println(output);
return output;
}

/**
* Displays a message when the user enters an invalid command.
*/
public static String findTasksErrorMessage() {
String output = "What do you want me to find?";
System.out.println(output);
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/duke/task/Deadline.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class Deadline extends Task {

/**
* Constructor to create a Deadline.
*
* @param description Description of the deadline.
* @param by Deadline of the task.
*/
Expand All @@ -29,6 +30,7 @@ public Deadline(String description, LocalDate by) {

/**
* Returns the String representation of the deadline.
*
* @return A String representing the deadline.
*/
@Override
Expand All @@ -38,6 +40,7 @@ public String toString() {

/**
* Returns the String representation of the deadline to be saved in the hard disk.
*
* @return A String representing the deadline.
*/
@Override
Expand All @@ -63,6 +66,11 @@ public boolean equals(Object o) {
return this.toString().equals(c.toString());
}

/**
* Updates the deadline of the task.
*
* @param newDate The new deadline.
*/
public void updateByDate(LocalDate newDate) {
by = newDate;
}
Expand Down
Loading

0 comments on commit c4d2251

Please sign in to comment.