Skip to content

[Bingyuan] iP#230

Open
notbingsu wants to merge 15 commits into
nus-cs2113-AY2223S2:masterfrom
notbingsu:master
Open

[Bingyuan] iP#230
notbingsu wants to merge 15 commits into
nus-cs2113-AY2223S2:masterfrom
notbingsu:master

Conversation

@notbingsu

Copy link
Copy Markdown

Week 4 PR

@theopin theopin left a comment

Copy link
Copy Markdown

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 thread src/main/java/Task.java
Comment on lines +10 to +12
public String getStatusIcon() {
return (isDone ? "X" : " "); // mark done task with X
}

Copy link
Copy Markdown

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 thread src/main/java/Main.java
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
Copy Markdown

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?

Comment thread src/main/java/Duke.java Outdated
String command = inputArgs[0];
boolean taskStatus = Boolean.parseBoolean(inputArgs[1]);
switch (command) {
case "T":

Copy link
Copy Markdown

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)

Comment thread src/main/java/Duke.java Outdated

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

Copy link
Copy Markdown

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 thread src/main/java/Duke.java Outdated
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
Copy Markdown

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