[vimalapugazhan] iP#188
Conversation
src/main/java/Aragorn.java
Outdated
| index = Integer.parseInt(userInput.substring(5)) - 1; | ||
| list[index].markAsDone(); | ||
| System.out.println(LINE + TAB + "Nice! I've marked this task as done:\n" + TAB + | ||
| " [X] " + list[index].getDescription() +"\n" + LINE); |
src/main/java/Aragorn.java
Outdated
| return; | ||
| } | ||
|
|
||
| if (userInput.equals("list")) { |
There was a problem hiding this comment.
Consider refactoring the code to reduce the length in void main
src/main/java/Aragorn.java
Outdated
| continue; | ||
| } | ||
|
|
||
| else if (userInput.contains("mark")) { |
There was a problem hiding this comment.
else if should be placed on the same line as on 42
src/main/java/Aragorn.java
Outdated
| @@ -0,0 +1,58 @@ | |||
| import java.util.Scanner; | |||
src/main/java/Aragorn.java
Outdated
| String userInput = in.nextLine(); | ||
|
|
||
| if (userInput.equals("bye")) { | ||
| System.out.println(LINE + TAB + EXIT + LINE); |
There was a problem hiding this comment.
consider using multiple print statements to make the code more readable
src/main/java/Task.java
Outdated
| } | ||
|
|
||
| public String getStatusIcon() { | ||
| return (isDone ? "X" : " "); // mark done task with X |
There was a problem hiding this comment.
ideal to refer to all instance parameters with the this keyword, e.g. this.isDone
src/main/java/Task.java
Outdated
| } | ||
|
|
||
| public String getStatusIcon() { | ||
| return (isDone ? "X" : " "); // mark done task with X |
There was a problem hiding this comment.
good use of ternary statements, though brackets are not needed to evaluate them
src/main/java/Aragorn.java
Outdated
| " What can I do for you?\n"; | ||
| String EXIT = " Bye. Hope to see you again soon!\n"; | ||
| String TAB = " "; | ||
| Task[] list = new Task[100]; |
There was a problem hiding this comment.
can consider making the length of the task array a variable
sevenseasofbri
left a comment
There was a problem hiding this comment.
well done, i've pointed out a few things that can improve the readability and quality of your code. 👍🏽
|
|
||
| import exceptions.AragornException; | ||
|
|
||
| public class inputParser { |
There was a problem hiding this comment.
Class/enum names must be nouns and written in PascalCase. So in your case, it should be InputParser instead.
| import exceptions.AragornException; | ||
|
|
||
| public class inputParser { | ||
| private String[] splitInput = new String[3]; |
There was a problem hiding this comment.
avoid using magic literals in the code, consider storing it in a constant (static final)
| public inputParser(String userInput, String commandType) throws AragornException { | ||
| String[] splitDeadline; | ||
| String[] splitEvent; | ||
| String LINE = " __________________________________________________________\n"; |
There was a problem hiding this comment.
good, but maybe this can be a constant at the class-level
| public class inputParser { | ||
| private String[] splitInput = new String[3]; | ||
|
|
||
| public inputParser(String userInput, String commandType) throws AragornException { |
There was a problem hiding this comment.
this function is quite long (30+ LOC). consider abstracting out the code into multiple functions
| case "MARK": | ||
| this.splitInput[0] = String.valueOf(Integer.parseInt(userInput.substring(5).trim()) - 1); | ||
| this.splitInput[1] = null; | ||
| this.splitInput[2] = null; | ||
| break; | ||
|
|
||
| case "UNMARK": | ||
| this.splitInput[0] = String.valueOf(Integer.parseInt(userInput.substring(7).trim()) - 1); | ||
| this.splitInput[1] = null; | ||
| this.splitInput[2] = null; | ||
| break; | ||
|
|
||
| case "TODO": | ||
| try { | ||
| this.splitInput[0] = userInput.substring(4); | ||
| if (this.splitInput[0].trim().isEmpty()){ | ||
| throw new AragornException(LINE + " Task description is empty!\n" + LINE); | ||
| } | ||
| this.splitInput[1] = null; | ||
| this.splitInput[2] = null; | ||
| } catch (AragornException e) { | ||
| System.out.println(e.getMessage()); | ||
| } | ||
| break; | ||
|
|
||
| case "DEADLINE": |
There was a problem hiding this comment.
the command types can perhaps be stored as constants or you could probably use enums to avoid the usage of magic literals.
src/main/java/main/Aragorn.java
Outdated
|
|
||
| import exceptions.AragornException; | ||
| import commands.inputParser; | ||
| import tasks.*; |
src/main/java/main/Aragorn.java
Outdated
|
|
||
| public class Aragorn { | ||
|
|
||
| private static final String LINE = " __________________________________________________________\n"; |
src/main/java/main/Aragorn.java
Outdated
| while(true) { | ||
| String userInput = in.nextLine(); | ||
| String commandType = inputParser.commandIdentifier(userInput); | ||
| try { | ||
| inputParser input = new inputParser(userInput.trim(), commandType); | ||
|
|
||
|
|
||
| switch (commandType) { | ||
| case "LIST": | ||
| if (listLength == 0) { |
There was a problem hiding this comment.
this is 4 levels of nesting, it makes the code hard to read and debug if any problems arise. consider refactoring this to multiple methods.
| "\n" + | ||
| " \"bye\": Closes the program.\n"; | ||
|
|
||
| public static void main(String[] args) throws AragornException { |
There was a problem hiding this comment.
this function is also very long (>30 LOC)
src/main/java/tasks/Deadline.java
Outdated
| public class Deadline extends Task { | ||
|
|
||
| public String deadline; | ||
| //public static String taskType = "D"; |
There was a problem hiding this comment.
avoid leaving in commented-out code. it can reduce readability
# Conflicts (resolved): # src/main/java/tasks/Deadline.java
This reverts commit 2b44a52.
branch-Level-9
No description provided.