Skip to content

Commit

Permalink
Merge pull request #2 from NicholasChungJunJie/branch-A-JavaDoc
Browse files Browse the repository at this point in the history
Add JavaDoc comments
  • Loading branch information
chungnicholas authored Feb 18, 2023
2 parents c107a53 + 911629b commit 370431b
Show file tree
Hide file tree
Showing 11 changed files with 229 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/main/java/Command.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* Represents a command handler to execute user inputs.
*/
public class Command {

private String typeOfCommand;
Expand All @@ -13,6 +16,13 @@ public Command(String[] inputs) {
}
}

/**
* Executes the user command based on user input.
*
* @param taskList class to store list of tasks at run time.
* @param ui Ui class for interaction with user.
* @param storage class for loading and saving of tasks to memory.
*/
public void execute(TaskList taskList, Ui ui, Storage storage) {
switch (typeOfCommand) {
case "list":
Expand Down
25 changes: 24 additions & 1 deletion src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* Represents a type of task with a deadline.
*/
public class Deadline extends Task {

protected String by;
Expand All @@ -6,22 +9,42 @@ public Deadline(String description, String by) {
this.by = by;
}

/**
* Returns the letter denoting the type of task.
*
* @return "D" denoting deadline.
*/
@Override
public String getTypeOfTask() {
return "D";
}

/**
* Returns the formatted string to be displayed to user without prepended information.
*
* @return formatted deadline information for user.
*/
@Override
public String getDescription() {
return super.getDescription() + " (by: " + this.by + ")";
}

/**
* Returns the formatted string to be saved in duke.txt.
*
* @return formatted deadline information.
*/
@Override

public String getDetailsToSave() {
return super.description + " /by " + this.by;
}

/**
* Returns the formatted string to be displayed to user.
*
* @return formatted deadline information for user.
*/
@Override
public String toString() {
return " [D][ ] " + super.description + " (by: " + this.by + ")";
}
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import java.io.IOException;
import java.io.FileNotFoundException;
import java.util.ArrayList;

/**
* Represents a Personal Assistant Chat bot that helps a person to keep track of various things.
*/
public class Duke {

private Ui ui;
Expand All @@ -13,9 +17,15 @@ public class Duke {
private final String FILE_PATH = "data/duke.txt";
private final String DIR_PATH = "data";
private final String BYE = "bye";

public static void main(String[] args) {
new Duke().run();
}

/**
* Initializes the task list to store tasks, ui for interaction with user,
* and storage to store information in duke.txt file.
*/
public Duke() {
ui = new Ui();
storage = new Storage(DIR_PATH, FILE_PATH);
Expand All @@ -28,6 +38,10 @@ public Duke() {
}
}

/**
* Represents the main run time function interacting with user.
* Sends input from user to the respective classes for execution.
*/
public void run() {

ui.printLogo();
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/DukeException.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* Represents the custom exception class for Duke.
*/
public class DukeException extends Exception {

public DukeException(String message) {
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* Represents a type of task with a start time and an end time.
*/
public class Event extends Task {

protected String startTime;
Expand All @@ -9,21 +12,41 @@ public Event(String description, String startTime, String endTime) {
this.endTime = endTime;
}

/**
* Returns the letter denoting the type of task.
*
* @return "E" denoting Event.
*/
@Override
public String getTypeOfTask() {
return "E";
}

/**
* Returns the formatted string to be displayed to user without prepended information.
*
* @return formatted event information for user.
*/
@Override
public String getDescription() {
return super.getDescription() + " (from: " + this.startTime + " to: " + this.endTime + ")";
}

/**
* Returns the formatted string to be saved in duke.txt.
*
* @return formatted event information.
*/
@Override
public String getDetailsToSave() {
return super.description + " /from " + this.startTime + " /to " + this.endTime;
}

/**
* Returns the formatted string to be displayed to user.
*
* @return formatted event information for user.
*/
public String toString() {
return " [E][ ] " + super.getDescription() + " (from: " + this.startTime + " to: " + this.endTime + ")";
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/Parser.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
/**
* Represents a parser to parse user input for execution.
*/
public class Parser {

/**
* Returns the command and arguments from user input.
*
* @return c The parsed command from user input
*/
public static Command parseInput(String action) {
Command c = new Command(action.split(" ", 2));

Expand Down
30 changes: 30 additions & 0 deletions src/main/java/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import java.io.FileNotFoundException;
import java.util.ArrayList;

/**
* Represents the memory to store tasks.
*/
public class Storage {

private String dirPath;
Expand All @@ -15,6 +18,12 @@ public Storage(String dirPath, String filePath) {
this.filePath = filePath;
}

/**
* Calls private function to save list of tasks to memory.
*
* @param taskList class to store list of tasks at run time.
* @param ui Ui class for interaction with user.
*/
public void save(TaskList taskList, Ui ui) {
try {
saveTasks(taskList.tasks, filePath);
Expand All @@ -23,6 +32,13 @@ public void save(TaskList taskList, Ui ui) {
}
}

/**
* Saves list of tasks to memory.
*
* @param tasks The array of tasks.
* @param filePath The path to file to store tasks.
* @throws IOException If file is not writable.
*/
private void saveTasks(ArrayList<Task> tasks, String filePath) throws IOException {
FileWriter fw = new FileWriter(filePath);

Expand All @@ -32,6 +48,12 @@ private void saveTasks(ArrayList<Task> tasks, String filePath) throws IOExceptio
fw.close();
}

/**
* Calls private function to load list of tasks from memory.
*
* @throws DukeException If file is cannot be created or found.
* @return TaskList Class containing the list of tasks.
*/
public TaskList load() throws DukeException {
TaskList taskList = new TaskList();
taskList.isSilent = true;
Expand All @@ -55,6 +77,14 @@ public TaskList load() throws DukeException {
return taskList;
}

/**
* Loads list of tasks to memory.
*
* @param taskList class to store list of tasks at run time.
* @param filePath The path to file to store tasks.
* @throws FileNotFoundException If file is not found.
* @return TaskList Class containing the list of tasks.
*/
private TaskList loadTasks(TaskList taskList , String filePath) throws FileNotFoundException {
File f = new File(filePath);
Scanner s = new Scanner(f); // create a Scanner using the File as the source
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* Represents a task.
*/
public class Task {
protected String description;
protected boolean isDone;
Expand All @@ -7,11 +10,15 @@ public Task(String description) {
this.isDone = false;
}

/**
* Returns an icon indicating if a task is done.
*
* @return X if done
*/
public String getStatusIcon() {
return (isDone ? "X" : " "); // mark done task with X
}

//...
public String getDescription() {
return this.description;
}
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/TaskList.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import java.util.ArrayList;

/**
* Represents the list of task.
*/
public class TaskList {

protected ArrayList<Task> tasks;
Expand All @@ -12,6 +15,9 @@ public TaskList(ArrayList<Task> tasks) throws DukeException{
this.tasks = tasks;
}

/**
* Lists all tasks.
*/
public void listTask() {
System.out.println(" Here are the tasks in your list:\n");
for (int i = 0; i < tasks.size(); i = i + 1) {
Expand All @@ -23,6 +29,12 @@ public void listTask() {
}
}

/**
* Marks specified task as done if taskNumber parameter is an integer.
*
* @param taskNumber The 1th-index of task to be marked.
* @throws DukeException If taskNumber is out of bounds.
*/
public void markTask(int taskNumber) throws DukeException {

int ind = taskNumber - 1;
Expand All @@ -42,6 +54,12 @@ public void markTask(int taskNumber) throws DukeException {

}

/**
* Marks specified task as done if taskNumber parameter is a string.
*
* @param taskNumber The 1th-index of task to be marked.
* @throws DukeException If taskNumber is out of bounds.
*/
public void markTask(String taskNumber) throws DukeException {
int ind;
try {
Expand All @@ -66,6 +84,12 @@ public void markTask(String taskNumber) throws DukeException {

}

/**
* Marks specified task as not done.
*
* @param taskNumber The 1th-index of task to be marked.
* @throws DukeException If taskNumber is out of bounds.
*/
public void unmarkTask(String taskNumber) throws DukeException {

int ind;
Expand All @@ -90,6 +114,11 @@ public void unmarkTask(String taskNumber) throws DukeException {

}

/**
* Adds a todo task.
*
* @param todoTask The task to be added.
*/
public void addTodo(String todoTask) throws DukeException {

tasks.add(new Todo(todoTask));
Expand All @@ -104,6 +133,12 @@ public void addTodo(String todoTask) throws DukeException {

}

/**
* Adds a deadline task.
*
* @param todoTask The task to be added.
* @throws DukeException If incorrect arguments are provided.
*/
public void addDeadline(String todoTask) throws DukeException {

String[] taskAndDeadline = todoTask.split(" /by ");
Expand All @@ -126,6 +161,12 @@ public void addDeadline(String todoTask) throws DukeException {

}

/**
* Adds an event task.
*
* @param todoTask The task to be added.
* @throws DukeException If incorrect arguments are provided.
*/
public void addEvent(String todoTask) throws DukeException {

String[] taskAndDeadline = todoTask.split(" /from ");
Expand Down Expand Up @@ -156,6 +197,12 @@ public void addEvent(String todoTask) throws DukeException {

}

/**
* Deletes a specified task.
*
* @param input The 1-th index of the task to be deleted.
* @throws DukeException If incorrect arguments are provided or task index is out of bounds.
*/
public void deleteTask(String input) throws DukeException {
int val;
try {
Expand All @@ -179,6 +226,12 @@ public void deleteTask(String input) throws DukeException {

}

/**
* Finds all tasks containing a keyword and prints them with its respective 1th-index number.
*
* @param keyword The keywords to be found.
* @param ui Ui class for interaction with user.
*/
public void find(String keyword, Ui ui) throws DukeException {
System.out.println(" Here are the matching tasks in your list:");
for(int i = 0; i< tasks.size(); i++) {
Expand Down
Loading

0 comments on commit 370431b

Please sign in to comment.