-
Notifications
You must be signed in to change notification settings - Fork 186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[vimalapugazhan] iP #188
base: master
Are you sure you want to change the base?
[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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing a space between + and "\n"
src/main/java/Aragorn.java
Outdated
return; | ||
} | ||
|
||
if (userInput.equals("list")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import was explicitly listed
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can consider making the length of the task array a variable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
avoid using wildcard imports
src/main/java/main/Aragorn.java
Outdated
|
||
public class Aragorn { | ||
|
||
private static final String LINE = " __________________________________________________________\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good use of constants
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.