Skip to content
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

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open

[Edwin] iP #191

wants to merge 36 commits into from

Conversation

yzhedwin
Copy link

@yzhedwin yzhedwin commented Sep 1, 2021

No description provided.

Copy link

@astralum astralum left a 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!

}
}
System.out.println(border);

Copy link

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

Copy link

@huien77 huien77 left a 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

+ "|_____| | ||_____| \n";
private static String border = "____________________________________________________________\n";

public static void addedTaskMessage(Task task) {
Copy link

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?

String line;
printStartMessage();

do {
Copy link

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

Comment on lines 61 to 71
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++;
}
}
Copy link

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

}
System.out.println(border);

} else if (line.length() > 4 && line.substring(0,4).contains("done")) {
Copy link

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

Comment on lines 15 to 19
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;

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.

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()) {

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.

Comment on lines 77 to 84
try {
if (saveFile.createNewFile()) {
System.out.println("Successfully created save file");
} else {
System.out.println("Save file already exists");
}
} catch (IOException e) {
e.printStackTrace();

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.

Comment on lines 94 to 95
fw.write(saveList.toString().charAt(1) + "/");
fw.write(saveList.getStatus() + "/" + saveList.getDescription());

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().

System.out.println("Save file successfully loaded");
}

public static String readCommand(Scanner in, CommandList task, DukeException error) {

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:

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.

Comment on lines 101 to 148
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;
}

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?

}
}

private static void readSave(CommandList task) throws FileNotFoundException {

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants