-
Notifications
You must be signed in to change notification settings - Fork 200
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
base: master
Are you sure you want to change the base?
[Bingyuan] iP #230
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 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.
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.
Do consider replacing such string literals with named constants, it will help in enhancing readability of your code
src/main/java/Main.java
Outdated
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"); | ||
} |
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.
Main seems to be overloaded with a lot of functionality, perhaps consider abstracting behaviour such as parsing command (like this block) into another method?
src/main/java/Duke.java
Outdated
String command = inputArgs[0]; | ||
boolean taskStatus = Boolean.parseBoolean(inputArgs[1]); | ||
switch (command) { | ||
case "T": |
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.
case line should not be tabbed (ie. on the same level as switch)
src/main/java/Duke.java
Outdated
|
||
private void addFileData(String[] inputArgs) { | ||
Task newTask; | ||
String command = inputArgs[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.
Do consider renaming inputArgs to its full form for better readability (ie. inputArguments)
src/main/java/Duke.java
Outdated
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(); | ||
} |
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.
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
Week 4 PR