Skip to content

Commit

Permalink
Merge pull request #2 from brianchoon/branch-A-CodeQuality
Browse files Browse the repository at this point in the history
Improve Code Quality
  • Loading branch information
brianchoon authored Sep 12, 2024
2 parents 8ec2fab + 64547f7 commit 17ac8f0
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/main/java/devon/Devon.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
public class Devon {

protected Scanner scanner = new Scanner(System.in);
private TaskList tasks = new TaskList();
private Storage storage = new Storage();
private Parser parser = new Parser();
private Ui ui = new Ui();
private final TaskList tasks = new TaskList();
private final Storage storage = new Storage();
private final Parser parser = new Parser();
private final Ui ui = new Ui();

/**
* Enum to represent the various commands the user can input.
Expand Down Expand Up @@ -76,7 +76,6 @@ private String goodbye() {
*/
protected String getResponse(String input) {
Command command = Command.fromStringToEnum(parser.extractCommand(input));
String response;

try {
switch (command) {
Expand Down Expand Up @@ -134,6 +133,7 @@ private String markAction(String input) throws DevonInvalidTaskNumberException {
*/
private String unmarkAction(String input) throws DevonInvalidTaskNumberException {
int taskIndex;

try {
taskIndex = parser.extractTaskIndex(input) - 1;
} catch (NumberFormatException e) {
Expand All @@ -142,6 +142,7 @@ private String unmarkAction(String input) throws DevonInvalidTaskNumberException
if (taskIndex < 0 || taskIndex >= tasks.getNumberOfTasks()) {
throw new DevonInvalidTaskNumberException();
}

return markAsUndone(taskIndex);
}

Expand Down Expand Up @@ -218,6 +219,7 @@ private String deleteAction(String input) throws DevonInvalidTaskNumberException
} catch (NumberFormatException e) {
throw new DevonInvalidTaskNumberException();
}

if (taskIndex < 0 || taskIndex >= tasks.getNumberOfTasks()) {
throw new DevonInvalidTaskNumberException();
}
Expand Down Expand Up @@ -274,8 +276,7 @@ private String getListAsString() {
* @param taskIndex The index of the task to mark as done.
*/
private String markAsDone(int taskIndex) {
String textResponse = tasks.markAsDone(taskIndex);
return textResponse;
return tasks.markAsDone(taskIndex);
}

/**
Expand All @@ -284,8 +285,7 @@ private String markAsDone(int taskIndex) {
* @param taskIndex The index of the task to mark as undone.
*/
private String markAsUndone(int taskIndex) {
String textResponse = tasks.markAsUndone(taskIndex);
return textResponse;
return tasks.markAsUndone(taskIndex);
}

/**
Expand Down

0 comments on commit 17ac8f0

Please sign in to comment.