-
Notifications
You must be signed in to change notification settings - Fork 437
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
[Tan Jia Qi] iP #249
base: master
Are you sure you want to change the base?
[Tan Jia Qi] iP #249
Conversation
# Conflicts: # src/main/java/Deadline.java # src/main/java/Duke.java # src/main/java/Event.java
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 think your code is very well-organized and clean in general! Nice one 👍 Just left my comments on some small coding standard and code quality issues :)
src/main/java/DukeException.java
Outdated
if (this.type.equals("other")) { | ||
return "\uD83D\uDE41" + " OOPS!!! I'm sorry, but I don't know what that means :-("; | ||
} else if (this.type.equals("done")) { | ||
return "\uD83D\uDE41" + " OOPS!!! Please indicate the numbering of task that has to be marked as done."; | ||
} else if (this.type.equals("delete")) { | ||
return "\uD83D\uDE41" + " OOPS!!! Please indicate the numbering of task that has to be deleted."; | ||
} else if (this.type.equals("date")) { | ||
return "\uD83D\uDE41" + "Please format the time in YYYY-MM-DD."; | ||
} | ||
return "\uD83D\uDE41" + " OOPS!!! The description of a " + this.type + " cannot be empty."; |
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 like how you have defined the error messages in a single place: it makes it much easier to change!
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.
Thank you!
* @param duke Duke object. | ||
* @return Duke response message. | ||
*/ | ||
public String parse(String userInput, Duke duke) { |
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 think you can consider shortening this method (as it seems quite long) by creating other private methods as helper functions! 👍
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 agree that it's quite long hahaha I'll work on it! thanks :))
src/main/java/Parser.java
Outdated
return duke.getUi().printDeleteTask(t, duke.getTasks()); | ||
} else { | ||
if (strArr[0].equals("todo")) { | ||
String sd = ""; |
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.
Perhaps you can use a more descriptive variable name :) I notice this in other places too in this method
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.
Alright!
src/main/java/Storage.java
Outdated
@@ -0,0 +1,65 @@ | |||
import java.io.*; |
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.
You can consider listing explicitly the classes that you are importing!
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.
Okay!
src/main/java/Ui.java
Outdated
* Prints bye message to user. | ||
* @return Duke response message for bye. | ||
*/ | ||
public String bye() { |
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 you can name this as "printBye"? I think it will be more consistent with the rest of the method names, and it also sounds slightly more like an action :)
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.
Ohh seems like I missed out this. Alright, I'll edit it! thanks!
src/main/java/Duke.java
Outdated
import javafx.scene.shape.Rectangle; | ||
import javafx.stage.Stage; | ||
|
||
import java.io.*; |
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 think you can consider explicitly listing all the classes you are importing! :)
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.
OK!
src/main/java/Storage.java
Outdated
import java.io.*; | ||
import java.time.LocalDate; | ||
import java.util.ArrayList; |
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 agree with shermz-lim, try to configure your IntelliJ so that it will remove this problem going forward
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.
Okay!
@Test | ||
public void testDoneState(){ | ||
assertEquals(0, new Task("read book").doneState()); | ||
} |
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 include the expected result in the method name
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.
Ohh okayy I'll take note of that! thanks :))
this.isDone = done.equals("1"); | ||
} | ||
|
||
public String toString() { |
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.
Missing @OverRide, your other task subclass have.
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.
Oopss okayy I'll change this.
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 think if you use checkstyle will have some error at the import statement cause they will have a fixed order.
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.
In general, LGTM. The parse(String userInput, Duke duke)
under the Parser class goes against having long methods and deep nesting. Some readiblity issues here and there with variables (like others mentioned) and complicated expessions that can be easily fixed.
/** | ||
* Represents a task entered by user. | ||
*/ | ||
public class 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.
Maybe making Task class abstract is better so that there is no need for default methods and not every one of the subclasses need to use @Override
for saveString()
or any other possible future overlapping methods that are implemented differently across the different subclasses.
src/main/java/Parser.java
Outdated
String[] strArr = userInput.split(" "); | ||
try { | ||
check(strArr); | ||
if (userInput.equals("bye")) { | ||
return duke.getUi().bye(); | ||
//System.exit(0); | ||
} else if (userInput.equals("list")) { | ||
return duke.getUi().printTaskList(duke.getTasks()); | ||
} else if (strArr[0].equals("done")) { | ||
duke.getTasks().getTask(Integer.parseInt(strArr[1]) - 1).markAsDone(); | ||
duke.getStorage().writeFile(duke.getTasks().getTaskList()); | ||
return duke.getUi().printDoneTask(duke.getTasks().getTask(Integer.parseInt(strArr[1]) - 1)); | ||
} else if (strArr[0].equals("delete")) { | ||
int i = Integer.parseInt(strArr[1]) - 1; | ||
Task t = duke.getTasks().getTask(Integer.parseInt(strArr[1]) - 1); | ||
duke.getTasks().deleteTask(i); | ||
duke.getStorage().writeFile(duke.getTasks().getTaskList()); | ||
return duke.getUi().printDeleteTask(t, duke.getTasks()); | ||
} else { |
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.
Feels really messy. Since strArr already has the command string in the 0 position. Can consider using a switch statement to check for command for readibility purposes. Instead of a mix of userInput.equals
and strArr[0].equals
. The logic after each else if/else block (or switch statement if u choose to use it) can be broken out into private methods like others mentioned for readibility.
src/main/java/Parser.java
Outdated
public void check(String[] arr) throws DukeException { | ||
if (arr.length == 1 && (arr[0].equals("todo") || arr[0].equals("deadline") || arr[0].equals("event") || | ||
arr[0].equals("done") || arr[0].equals("delete") || arr[0].equals("find"))) { | ||
throw new DukeException(arr[0]); | ||
} else if (!arr[0].equals("todo") && !arr[0].equals("deadline") && !arr[0].equals("event") && | ||
!arr[0].equals("list") && !arr[0].equals("bye") && !arr[0].equals("done") | ||
&& !arr[0].equals("delete") && !arr[0].equals("find")) { | ||
throw new DukeException("other"); |
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.
Readiblity is quite poor here :(
Switching the if else checks around would allow you to skip && (arr[0].equals("todo") || arr[0].equals("deadline") || arr[0].equals("event") || arr[0].equals("done") || arr[0].equals("delete") || arr[0].equals("find"))
just checking for length instead.
So:
if statement 1) command I don't understand? (ignoring description)
if statement 2) command without description? (all commands here would be understood)
Instead of:
if statement 1) command without description? && command I understand?
if statement 2) command with description but I don't understand?
Comments would be nice to describe what is being checked at each if statement.
Do also consider using the logic under public String parse(String userInput, Duke duke)
to avoid doing checks on the command string twice to keep maintaining simple (ie don't have to update 2 places when commands change).
public String getStatusIcon() { | ||
return (isDone ? "\u2713" : "\u2718"); | ||
} |
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 assume these two values are the 'tick' and 'cross'. Consider using a named constant as part of keeping code quality, avoiding magic numbers.
Use Assertions
Improve Code Quality
No description provided.