Skip to content

Commit

Permalink
Merge pull request #3 from quelinxiao/branch-A-CodeQuality
Browse files Browse the repository at this point in the history
Improve code quality
  • Loading branch information
quelinxiao authored Feb 25, 2024
2 parents ffe7aa5 + f070266 commit 47935ed
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 64 deletions.
6 changes: 3 additions & 3 deletions src/main/java/bob/Bob.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class Bob extends Application{
private Image user = new Image(this.getClass().getResourceAsStream("/images/DaUser.png"));
private Image duke = new Image(this.getClass().getResourceAsStream("/images/DaDuke.png"));

/*
/**
* A constructor for the chatbot Bob.
*/
public Bob(String filePath) {
Expand All @@ -39,7 +39,7 @@ public Bob(String filePath) {
this.parser = new Parser(ui);
}

/*
/**
* A no argument constructor for launcher.
*/
public Bob() {
Expand All @@ -49,7 +49,7 @@ public Bob() {
this.parser = new Parser(ui);
}

/*
/**
* A method that signals the chatbot to start its processes.
*/
public void run() {
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/bob/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import java.util.Objects;

/*
/**
* This class represents an event that can be recorded in the tasklist.
*/
class Event extends Task {
protected String from;
protected String to;

/*
/**
* A constructor to create a new event task.
*/
public Event(String description, String from, String to) {
Expand All @@ -18,7 +18,7 @@ public Event(String description, String from, String to) {
this.to = to;
}

/*
/**
* A method to get from.
*
* @return The start date of the event.
Expand All @@ -27,7 +27,7 @@ public String getFrom() {
return this.from;
}

/*
/**
* A method to get to.
*
* @return The end date of the event.
Expand All @@ -36,7 +36,7 @@ public String getTo() {
return this.to;
}

/*
/**
* A method that returns the status of the task.
*
* @return A label [E] and a check-box followed by the description of the task.
Expand All @@ -46,7 +46,7 @@ public String toString() {
return "[E]" + super.toString() + " (from: " + from + " to: " + to + ")";
}

/*
/**
* A method to check if two objects are equal.
*
* @param o The object to compare to.
Expand Down
1 change: 1 addition & 0 deletions src/main/java/bob/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import javafx.scene.image.Image;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.VBox;

/**
* Controller for MainWindow. Provides the layout for the other controls.
*/
Expand Down
60 changes: 48 additions & 12 deletions src/main/java/bob/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,37 @@
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

/*
/**
* This class makes sense of the user's commands.
*/
public class Parser {
private Ui ui;

/*
/**
* A constructor that assigns a UI to the parser.
*/
public Parser(Ui ui) {
this.ui = ui;
}

/*
/**
* A method to parse the user command 'exit'.
*
* @param storage The file we want to save our task list to.
* @param taskList The list of tasks we want to save.
* @return A message indicating that the user has exited.
*/
public String parseExit(Storage storage, TaskList taskList) {
storage.saveFile(taskList);

return ui.showExitMessage();
}

/*
/**
* A method to parse the user command 'list'.
*
* @param taskList The list of tasks that we want to output.
* @return A string representing the output.
*/
public String parseList(TaskList taskList) {
int size = taskList.size();
Expand All @@ -41,17 +48,24 @@ public String parseList(TaskList taskList) {
return text;
}

/*
/**
* A method to parse the user command 'clear'.
*
* @param taskList The list of tasks that we want to clear.
* @return A string representing the output.
*/
public String parseClear(TaskList taskList) {
taskList.clearTasks();

return ui.showClearMessage();
}

/*
/**
* A method to parse the user command 'mark'.
*
* @param input A string representing the input.
* @param taskList The list of tasks that we want to mark a task.
* @return A string representing the output.
*/
public String parseMark(String input, TaskList taskList) {
try {
Expand All @@ -67,8 +81,12 @@ public String parseMark(String input, TaskList taskList) {
}
}

/*
/**
* A method to parse the user command 'unmark'.
*
* @param input A string representing the input.
* @param taskList The list of tasks that we want to unmark a task.
* @return A string representing the output.
*/
public String parseUnmark(String input, TaskList taskList) {
try {
Expand All @@ -84,8 +102,12 @@ public String parseUnmark(String input, TaskList taskList) {
}
}

/*
/**
* A method to parse the new deadline task.
*
* @param input A string representing the input.
* @param taskList The list of tasks that we want to add a task to.
* @return A string representing the output.
*/
public String parseDeadline(String input, TaskList taskList) {
try {
Expand All @@ -105,8 +127,12 @@ public String parseDeadline(String input, TaskList taskList) {
}
}

/*
/**
* A method to parse the new todo task.
*
* @param input A string representing the input.
* @param taskList The list of tasks that we want to add a task to.
* @return A string representing the output.
*/
public String parseTodo(String input, TaskList taskList) {
String taskDescription = input.substring(5);
Expand All @@ -116,8 +142,10 @@ public String parseTodo(String input, TaskList taskList) {
return ui.showTodoMessage(newTask, taskList.size());
}

/*
/**
* A method to parse the new event task.
*
* @return A string representing the output.
*/
public String parseEvent(String input, TaskList taskList) {
int fromIndex = input.indexOf("/from ");
Expand All @@ -132,8 +160,12 @@ public String parseEvent(String input, TaskList taskList) {
return ui.showEventMessage(newTask, taskList.size());
}

/*
/**
* A method to parse the user command 'delete'.
*
* @param input A string representing the input.
* @param taskList The list of tasks that we want to delete from.
* @return A string representing the output.
*/
public String parseDelete(String input, TaskList taskList) {
int index = Integer.parseInt(input.substring(7)) - 1;
Expand All @@ -143,8 +175,12 @@ public String parseDelete(String input, TaskList taskList) {
return ui.showDeleteMessage(task, taskList.size());
}

/*
/**
* A method to parse the user command 'find'.
*
* @param input A string represnting the input.
* @param taskList The list of tasks that we want to find from.
* @return A string representing the output.
*/
public String parseFind(String input, TaskList taskList) {
String keyword = input.substring(5).trim();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/bob/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/*
/**
* A class for saving and loading files from storage.
*/
public class Storage {
Expand All @@ -17,7 +17,7 @@ public Storage(String filePath) {
this.filePath = filePath;
}

/*
/**
* A method to load tasks from the specified file path.
*
* @return A TaskList parsed from the save file.
Expand Down Expand Up @@ -86,7 +86,7 @@ else if (taskType.equals("E")) {
return taskList;
}

/*
/**
* A method to save the current tasks.
*
* @param taskList An ArrayList of the current tasks.
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/bob/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,36 @@

import java.util.Objects;

/*
/**
* This class represents a task we want to record.
*/
class Task {
private final String description;
private boolean isDone;

/*
/**
* A constructor that depicts a new task.
*/
public Task(String description) {
this.description = description;
this.isDone = false;
}

/*
/**
* A method that marks a task as done.
*/
public void markAsDone() {
this.isDone = true;
}

/*
/**
* A method that will undo the mark on a task.
*/
public void markAsUndone() {
this.isDone = false;
}

/*
/**
* A method that returns the isDone boolean.
*
* @return A boolean depending on whether the task is done.
Expand All @@ -40,7 +40,7 @@ public boolean getIsDone() {
return this.isDone;
}

/*
/**
* A method that returns the description.
*
* @return A string of the task description.
Expand All @@ -49,7 +49,7 @@ public String getDescription() {
return this.description;
}

/*
/**
* A method that returns the task status as a string.
*
* @return A check-box followed by the description of the task.
Expand All @@ -59,7 +59,7 @@ public String toString() {
return "[" + (isDone ? "X" : " ") + "] " + description;
}

/*
/**
* A method to compare the contents of two task objects.
*
* @param o The object to compare to.
Expand Down
Loading

0 comments on commit 47935ed

Please sign in to comment.