-
Notifications
You must be signed in to change notification settings - Fork 193
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
[Edwin] iP #191
base: master
Are you sure you want to change the base?
[Edwin] iP #191
Conversation
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 adherence to coding standards!
src/main/java/Duke.java
Outdated
} | ||
} | ||
System.out.println(border); | ||
|
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.
May not need an extra newline here
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.
I can see some deep nesting and I think it would be good to create more methods to solve that
I also find some magic numbers, it would be good to avoid them
Overall, very good
src/main/java/Duke.java
Outdated
+ "|_____| | ||_____| \n"; | ||
private static String border = "____________________________________________________________\n"; | ||
|
||
public static void addedTaskMessage(Task task) { |
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.
does it need to be past tense?
src/main/java/Duke.java
Outdated
String line; | ||
printStartMessage(); | ||
|
||
do { |
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.
maybe can move the while loop to a new method, and call that method instead, following single level of abstraction
src/main/java/Duke.java
Outdated
int j = 1; | ||
System.out.println(border); | ||
System.out.println("Here is your list"); | ||
|
||
for (Task item : items) { | ||
if (item != null) { | ||
System.out.print(j + "."); | ||
System.out.println(item); | ||
j++; | ||
} | ||
} |
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 moving this to a new method, might look neater, and no need so many level of indentation
src/main/java/Duke.java
Outdated
} | ||
System.out.println(border); | ||
|
||
} else if (line.length() > 4 && line.substring(0,4).contains("done")) { |
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 magic number like 4
, instead store them as constants
src/main/java/duke/Duke.java
Outdated
private static final int FOUR = 4; | ||
private static final int FIVE = 5; | ||
private static final int SIX = 6;; | ||
private static final int EIGHT = 8; | ||
private static final int NINE = 9; |
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.
These string constants to refer to an integer may seem redundant and self-explanatory.
If you are working to replace them with magic numbers I would suggest more meaningful names.
src/main/java/duke/Duke.java
Outdated
System.out.println("Type bye to exit\n" + border); | ||
} | ||
public static boolean isInvalid(CommandList task, String line , String key) { | ||
if (!line.split(key)[1].trim().isEmpty()) { |
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 expression is a little complicated - calling 3 methods and a negation. See how to improve the quality of expressions here.
src/main/java/duke/Duke.java
Outdated
try { | ||
if (saveFile.createNewFile()) { | ||
System.out.println("Successfully created save file"); | ||
} else { | ||
System.out.println("Save file already exists"); | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); |
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.
How about including the previous statements in the try catch block? After all, this method is doing file related operations and the program could catch
file related exceptions.
src/main/java/duke/Duke.java
Outdated
fw.write(saveList.toString().charAt(1) + "/"); | ||
fw.write(saveList.getStatus() + "/" + saveList.getDescription()); |
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.
For the parameters to the file writer, you could have declared variables for each for them to improve readability. E.g. fileStatus = saveList.getStatus()
.
src/main/java/duke/Duke.java
Outdated
System.out.println("Save file successfully loaded"); | ||
} | ||
|
||
public static String readCommand(Scanner in, CommandList task, DukeException error) { |
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 method is parsing the command string, but it is not obvious how it is done with seemingly arbitrary constants like FOUR FIVE EIGHT
etc. You could consider a more direct way of comparing strings and checking parameters.
public void executeCommand(ArrayList<Task> items, DukeException error, String input) { | ||
String[] inputs; | ||
switch (command) { | ||
case CMD_TODO: |
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 deviates from the switch case statement layout conventions - indentation for case
is not needed.
case CMD_EVENT: | ||
inputs = input.split(AT); | ||
addEvent(items, inputs[0].trim().replace(EVENT, "").trim(), inputs[1].trim()); | ||
addTaskMessage(items.get(taskCount)); | ||
break; | ||
case CMD_DEADLINE: | ||
inputs = input.split(BY); | ||
addDeadline(items, inputs[0].trim().replace(DEADLINE, "").trim(), inputs[1].trim()); | ||
addTaskMessage(items.get(taskCount)); | ||
break; | ||
case CMD_LIST: | ||
int j = 1; | ||
System.out.println(border); | ||
System.out.println("Here are the task in your list:"); | ||
for (Task item : items) { | ||
if (item != null) { | ||
System.out.print(j + "."); | ||
System.out.println(item); | ||
j++; | ||
} | ||
} | ||
break; | ||
case CMD_DONE: | ||
int dividerPosition = input.indexOf(" ") + 1; | ||
int endPosition = input.length(); | ||
if (endPosition > FIVE) { | ||
String num = input.substring(dividerPosition, endPosition); | ||
int taskNum = Integer.parseInt(num) - 1; | ||
items.get(taskNum).markDone(); | ||
System.out.println(border + "Nice! task is done " + '\n' + border); | ||
} | ||
break; | ||
case CMD_TERMINATE: | ||
printEndMessage(); | ||
break; | ||
case CMD_DELETE: | ||
dividerPosition = input.indexOf(" ") + 1; | ||
endPosition = input.length(); | ||
if (endPosition > SEVEN) { | ||
String num = input.substring(dividerPosition, endPosition); | ||
int taskNum = Integer.parseInt(num) - 1; | ||
removeItem(items, taskNum); | ||
} | ||
break; | ||
default: | ||
printErrorMessage(error); | ||
break; | ||
} |
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.
While you have organized different procedure into separate cases, the executeCommand method is still rather long. How about trying SLAP principle here?
src/main/java/duke/Duke.java
Outdated
} | ||
} | ||
|
||
private static void readSave(CommandList task) throws FileNotFoundException { |
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.
It would be good to provide method descriptions as comments/javadocs to improve code readability.
Added Date and Time functionality
Added Find Feature
Documentation for A-JavaDoc
No description provided.