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

[Tan Jia Qi] iP #249

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

[Tan Jia Qi] iP #249

wants to merge 40 commits into from

Conversation

jiaqi20
Copy link

@jiaqi20 jiaqi20 commented Aug 23, 2020

No description provided.

Copy link

@shermz-lim shermz-lim left a 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 :)

Comment on lines 13 to 22
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.";

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!

Copy link
Author

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

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! 👍

Copy link
Author

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 :))

return duke.getUi().printDeleteTask(t, duke.getTasks());
} else {
if (strArr[0].equals("todo")) {
String sd = "";

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

Copy link
Author

Choose a reason for hiding this comment

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

Alright!

@@ -0,0 +1,65 @@
import java.io.*;

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!

Copy link
Author

Choose a reason for hiding this comment

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

Okay!

* Prints bye message to user.
* @return Duke response message for bye.
*/
public String bye() {

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 :)

Copy link
Author

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!

import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

import java.io.*;

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! :)

Copy link
Author

Choose a reason for hiding this comment

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

OK!

Comment on lines 1 to 3
import java.io.*;
import java.time.LocalDate;
import java.util.ArrayList;

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

Copy link
Author

Choose a reason for hiding this comment

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

Okay!

Comment on lines +11 to +14
@Test
public void testDoneState(){
assertEquals(0, new Task("read book").doneState());
}
Copy link

@galvinleow galvinleow Sep 2, 2020

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

Copy link
Author

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

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.

Copy link
Author

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.

Copy link

@galvinleow galvinleow left a 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.

Copy link

@LinkedInk LinkedInk left a 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 {

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.

Comment on lines 15 to 33
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 {
Copy link

@LinkedInk LinkedInk Sep 5, 2020

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.

Comment on lines 112 to 119
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");

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

Comment on lines +21 to +23
public String getStatusIcon() {
return (isDone ? "\u2713" : "\u2718");
}
Copy link

@LinkedInk LinkedInk Sep 5, 2020

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.

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.

None yet

4 participants