Skip to content

Commit

Permalink
Add javadocs and align code towards the coding standards
Browse files Browse the repository at this point in the history
  • Loading branch information
RiyaMehta2211 committed Sep 19, 2023
1 parent 33e31eb commit 3035324
Show file tree
Hide file tree
Showing 16 changed files with 151 additions and 37 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ test {
showStandardStreams = false
}
}
run {
enableAssertions = true
}

application {
mainClass.set("duke.Launcher")
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

public class Duke{
TaskList tasks = Storage.loadTasks("src/data/Duke.txt");

/**
* Initiates interaction with the Duke application.
* This method prompts the user and parses their input.
*/
public void dukeInteraction() {
Ui.printHello();
Scanner scanner = new Scanner(System.in);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/duke/Launcher.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package duke;

import javafx.application.Application;

public class Launcher {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/duke/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package duke;

import duke.ui.MainWindow;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
Expand All @@ -15,6 +16,10 @@ public class Main extends Application {

private Duke duke = new Duke();

/**
* Initializes and starts the JavaFX application.
* @param stage The primary stage for this application, representing the main window.
*/
@Override
public void start(Stage stage) {
assert duke != null;
Expand Down
26 changes: 24 additions & 2 deletions src/main/java/duke/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private static void updateList(String str, TaskList tasks) throws InvalidInputEx
for (int i = 0; i < tasks.getSize(); i++) {
tasks.markDone(i);
}
temp = Ui.printAllDone();
temp = Ui.printAllDone(tasks);
}
else {
String num = str.substring(5);
Expand All @@ -60,7 +60,7 @@ private static void updateList(String str, TaskList tasks) throws InvalidInputEx
for (int i = 0; i < tasks.getSize(); i++) {
tasks.markNotDone(i);
}
temp = Ui.printAllNotDone();
temp = Ui.printAllNotDone(tasks);
} else {
String num = str.substring(7);
int number = Integer.valueOf(num);
Expand Down Expand Up @@ -112,6 +112,12 @@ else if (str.equals("list")) {
temp = Ui.listTasks(tasks);
}
}
/**
* Adds the tasks of type ToDo into tasklist based on the input string.
* @param str The input string.
* @param tasks The TaskList to process tasks.
* @throws ToDoCommandUseException
*/
private static void addToDo(String str, TaskList tasks) throws ToDoCommandUseException {
String todo = str.substring(4);
//remove any leading and trailing whitespace characters and
Expand All @@ -125,6 +131,12 @@ private static void addToDo(String str, TaskList tasks) throws ToDoCommandUseExc
tasks.addTask(task);
temp = Ui.printAddTask(task, tasks);
}
/**
* Adds the tasks of type Deadline into tasklist based on the input string.
* @param str The input string.
* @param tasks The TaskList to process tasks.
* @throws DeadlineCommandUseException
*/
private static void addDeadline(String str, TaskList tasks) throws DeadlineCommandUseException {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm");
if (!str.contains("/by ")) {
Expand All @@ -143,6 +155,12 @@ private static void addDeadline(String str, TaskList tasks) throws DeadlineComma
temp = Ui.printAddTask(task, tasks);
}
}
/**
* Adds the tasks of type Event into tasklist based on the input string.
* @param str The input string.
* @param tasks The TaskList to process tasks.
* @throws EventCommandUseException
*/
private static void addEvent(String str, TaskList tasks) throws EventCommandUseException {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm");
if (!str.contains("/from")) {
Expand Down Expand Up @@ -205,18 +223,22 @@ public static String chat(String str, TaskList tasks) {
return Ui.printBye();
}
else if (str.equals("help")) {
Storage.saveTasks("src/data/Duke.txt", tasks);
return Ui.printHelp();
}
else if (str.startsWith("mark ") || str.startsWith("unmark ")
|| str.startsWith("delete ")) {
updateList(str, tasks);
Storage.saveTasks("src/data/Duke.txt", tasks);
}
else if (str.startsWith("todo") || str.startsWith("deadline")
|| str.startsWith("event")) {
addTasks(str, tasks);
Storage.saveTasks("src/data/Duke.txt", tasks);
}
else if (str.equals("list") || str.startsWith("find ")) {
returnList(str, tasks);
Storage.saveTasks("src/data/Duke.txt", tasks);
} else {
throw new InvalidInputException(str);
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/duke/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.FileWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import java.nio.file.Files;
import java.nio.file.FileSystems;
import java.nio.file.Path;

import java.time.LocalDateTime;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* It provides methods for adding, removing, and retrieving tasks from the list.
*/
public class TaskList{
private List<Task> tasks = new ArrayList<>();
private final List<Task> tasks = new ArrayList<>();
/**
* Default constructor to initialize an empty TaskList.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/task/Event.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package duke.task;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.LocalDateTime;

/**
* This class inherits from the Task class and represents an Event task type
Expand Down
25 changes: 23 additions & 2 deletions src/main/java/duke/ui/DialogBox.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
package duke.ui;
import java.io.IOException;
import java.util.Collections;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
Expand All @@ -13,6 +11,9 @@
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;

import java.io.IOException;
import java.util.Collections;

/**
* An example of a custom control using FXML.
* This control represents a dialog box consisting of an ImageView to represent the speaker's face and a label
Expand All @@ -24,6 +25,12 @@ public class DialogBox extends HBox {
@FXML
private ImageView displayPicture;

/**
* Constructs a new DialogBox instance with the specified text and image.
*
* @param text The text to be displayed in the dialog.
* @param img The image to be displayed alongside the text in the dialog.
*/
private DialogBox(String text, Image img) {
try {
FXMLLoader fxmlLoader = new FXMLLoader(MainWindow.class.getResource("/view/DialogBox.fxml"));
Expand All @@ -48,10 +55,24 @@ private void flip() {
setAlignment(Pos.TOP_LEFT);
}

/**
* Creates and returns a DialogBox instance representing a user's dialog message.
*
* @param text The text of the user's message to be displayed in the dialog.
* @param img The image to be displayed alongside the user's message in the dialog.
* @return A DialogBox instance representing the user's message with the specified text and image.
*/
public static DialogBox getUserDialog(String text, Image img) {
return new DialogBox(text, img);
}

/**
* Creates and returns a new DialogBox instance representing Duke's dialog.
*
* @param text The text to be displayed in Duke's dialog.
* @param img The image to be displayed alongside the text in Duke's dialog.
* @return A new DialogBox instance representing Duke's dialog.
*/
public static DialogBox getDukeDialog(String text, Image img) {
var db = new DialogBox(text, img);
db.flip();
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/duke/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public class MainWindow extends AnchorPane {
private Image userImage = new Image(this.getClass().getResourceAsStream("/images/Muggle.png"));
private Image dukeImage = new Image(this.getClass().getResourceAsStream("/images/Duke.png"));

/**
* Initializes the JavaFX controller when the associated FXML file is loaded.
* This method sets up the scroll pane and adds the initial Duke's dialog to the dialog container.
*/
@FXML
public void initialize() {
scrollPane.vvalueProperty().bind(dialogContainer.heightProperty());
Expand Down
Loading

0 comments on commit 3035324

Please sign in to comment.