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

[Bingyuan] iP #230

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

[Bingyuan] iP #230

wants to merge 15 commits into from

Conversation

notbingsu
Copy link

Week 4 PR

Copy link

@theopin theopin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job on implementation of duke so far! Some general pointers to improve your code:

  • magic literals. Avoid passing in string/int literals into functions directly as it can be difficult for
    readers to understand your code. Do consider refactoring them into named constants
  • Main method seems to be too long. Perhaps consider trying to break it into segments and then refactoring them into seperate methods in order to better visualize its overall flow.

Comment on lines +10 to +12
public String getStatusIcon() {
return (isDone ? "X" : " "); // mark done task with X
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do consider replacing such string literals with named constants, it will help in enhancing readability of your code

Comment on lines 25 to 39
if (command.equals("mark")) {
Duke.changeTaskState(true, Integer.parseInt(phrase));
} else if (command.equals("unmark")) {
Duke.changeTaskState(false, Integer.parseInt(phrase));
} else if (command.equals("event")) {
Duke.addEvent(phrase);
} else if (command.equals("todo")) {
Duke.addTodo(phrase);
} else if (command.equals("deadline")) {
Duke.addDeadline(phrase);
} else if (command.equals("delete")) {
Duke.delete(Integer.parseInt(phrase));
} else {
System.out.println("Invalid command");
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main seems to be overloaded with a lot of functionality, perhaps consider abstracting behaviour such as parsing command (like this block) into another method?

String command = inputArgs[0];
boolean taskStatus = Boolean.parseBoolean(inputArgs[1]);
switch (command) {
case "T":
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

case line should not be tabbed (ie. on the same level as switch)


private void addFileData(String[] inputArgs) {
Task newTask;
String command = inputArgs[0];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do consider renaming inputArgs to its full form for better readability (ie. inputArguments)

Comment on lines 104 to 119
try {
if (!file.createNewFile()) {
Scanner fileData = new Scanner(file);
while (fileData.hasNext()) {
data = fileData.nextLine();
String[] inputArgs = data.split("|");
addFileData(inputArgs);
}
fileData.close();
}
} catch (IOException e) {
System.out.print("\nError getting file data");
}
System.out.println("These are the tasks from your file:\n");
list();
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try-catch should have a finally clause defined to mark the relevant section of code (in this case 117-118) that runs regardless of the outcome of try catch

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.

2 participants