Skip to content

Commit

Permalink
Implement Find, add JavaDoc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
GraceZhuXY committed Feb 28, 2023
1 parent 6d31636 commit ecad58b
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 8 deletions.
4 changes: 0 additions & 4 deletions data/duke.txt
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
T|X|coffee
T| |coffee 2
D| |coffee /by: 2pm
E| |coffee again /from: 1pm /by: 2pm
9 changes: 5 additions & 4 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
public class Deadline extends Todo {
protected String by;

/** Creates a deadline-type task, which contains a description and completion timing */
public Deadline(String description, String by) {
super(description);
setBy(by);
}

/** Sets the completion timing of the task */
public void setBy(String by) {
this.by = by;
}

public String getBy() {
return this.by;
}

/** Returns type of task (deadline) */
@Override
public String getType() {
return "deadline";
}

/** Returns completion timing of task */
@Override
public String getTimings() {
return this.by;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
public class Event extends Task{
protected String start;
protected String end;

/** Creates an event-type task, which contains a description and start and end timing */
public Event(String description, String start, String end) {
super(description);
setStartEnd(start, end);
}

/** Sets the start and end timing of the task */
public void setStartEnd (String start, String end) {
this.start = start;
this.end = end;
}

/** Returns type of task (event) */
@Override
public String getType() {
return "event";
}

/** Returns start and end timing as a single string, separated by a slash */
@Override
public String getTimings() {
return this.start + "/" + this.end;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public class Parser {

/** Parses user command and calls relevant functions */
public static void parseCommand(String taskInfo, ArrayList<Task> tasks) {
if (taskInfo.equals("list")) {
getList(tasks);
Expand Down Expand Up @@ -53,12 +54,14 @@ public static void parseCommand(String taskInfo, ArrayList<Task> tasks) {
}
}

/** Prints list of all tasks */
public static void getList(ArrayList<Task> tasks) {
for (int i = 0; i < tasks.size(); i++) {
System.out.println((i + 1) + "." + Ui.printTask(tasks.get(i)));
}
}

/** Finds tasks based on a specific keyword */
public static void findTask(ArrayList<Task> tasks, String taskDescription) {
int taskNo = 0;
for (Task task: tasks) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
public class Storage {
private static final String FILEPATH = "data/duke.txt";

/** Writes tasks to file after user exits */
static void writeToFile(ArrayList<Task> tasks) throws IOException {
Files.createDirectories(Paths.get("./data"));
try {
Expand Down Expand Up @@ -48,6 +49,7 @@ static void writeToFile(ArrayList<Task> tasks) throws IOException {

}

/** Loads tasks from previous save files when starting Duke */
static ArrayList<Task> loadFromFile() {
ArrayList<Task> tasks = new ArrayList<Task>();

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,34 @@ public abstract class Task {
protected boolean isDone;
protected String type;

/** Creates a task, which must contain a description */
public Task(String description) {
this.description = description;
this.isDone = false;
}

/** Returns whether a task is complete or incomplete */
public String getStatusIcon() {
// mark done task with X
return (isDone ? "X" : " ");
}

/** Marks a task as done */
public void markAsDone(){
isDone = true;
}

/** Marks a task as not done */
public void unmarkAsDone(){
isDone = false;
}

/** Returns type of task */
public String getType() {
return null;
}

/** Returns relevant timings of task, if any */
public String getTimings() {
return null;
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/Tasklist.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ public class Tasklist {
private static final int FROM_LEN = 6;
private static final int BY_LEN = 4;

/** Adds a todo-type task */
static void addTodo(ArrayList<Task> tasks, String taskDescription) {
Task newTodo = new Todo(taskDescription);
tasks.add(newTodo);
System.out.println("Created todo: " + Ui.printTask(newTodo));
}

/** Adds a deadline-type task */
static void addDeadline(ArrayList<Task> tasks, String taskDescription) {
int deadlineByIndex = taskDescription.indexOf("/");

Expand All @@ -22,6 +24,7 @@ static void addDeadline(ArrayList<Task> tasks, String taskDescription) {
System.out.println("Created deadline: " + Ui.printTask(newDeadline));
}

/** Adds an event-type task */
static void addEvent(ArrayList<Task> tasks, String taskDescription) {
int eventStartIndex = taskDescription.indexOf("/");
int eventEndIndex = taskDescription.lastIndexOf("/");
Expand All @@ -36,14 +39,17 @@ static void addEvent(ArrayList<Task> tasks, String taskDescription) {

}

/** Mark a task as complete */
static void markTask(ArrayList<Task> tasks, int taskNo) {
tasks.get(taskNo).markAsDone();
}

/** Mark a task as incomplete */
static void unmarkTask(ArrayList<Task> tasks, int taskNo) {
tasks.get(taskNo).unmarkAsDone();
}

/** Delete a task by task number */
static void deleteTask(ArrayList<Task> tasks, int taskNo) {
if (tasks.size() > 0) {
System.out.println("Got it! This task will be removed:");
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/Todo.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
public class Todo extends Task {
protected boolean isDone;

/** Creates a todo-type task, which contains a description */
public Todo(String description) {
super(description);
isDone = false;
}

/** Returns type of task (todo) */
@Override
public String getType() {
return "todo";
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public class Ui {

/** Display message when loading previously saved tasks */
static void loadDataMessage() {
System.out.println(("Loading previous save data..."));
}
Expand All @@ -15,11 +16,13 @@ static void goodbyeMessage() {
System.out.println("Bye! :D");
}

/** Reads the next user command */
static String readCommand() {
Scanner reader = new Scanner(System.in);
return reader.nextLine();
}

/** Format printing of task by task type */
static String printTask(Task task) {
String taskType = task.getType();
String formattedTask;
Expand Down

0 comments on commit ecad58b

Please sign in to comment.