Skip to content

[Liu Ze Hui] iP#192

Open
liuzehui03 wants to merge 39 commits into
nus-cs2113-AY2324S2:masterfrom
liuzehui03:master
Open

[Liu Ze Hui] iP#192
liuzehui03 wants to merge 39 commits into
nus-cs2113-AY2324S2:masterfrom
liuzehui03:master

Conversation

@liuzehui03

Copy link
Copy Markdown

Added Level-0, Level-1, Level-2, Level-3

@yeozhishen yeozhishen 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.

LGTM! Your code mostly seems to follow the coding standards, all but one line appears to need changing!

Comment thread src/main/java/Task.java Outdated
@@ -0,0 +1,32 @@
public class Task {
protected static String[] tasks = new String[100];
protected static boolean[] tasksCompleted = new boolean[100];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

whichTasksCompleted sounds like a better variable name as the variable name tasksCompleted sounds like an integer

@yeozhishen yeozhishen 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.

suggested extra comments for cleaner code

Comment thread src/main/java/Duke.java Outdated
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
public static void printLine() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should try to rename it to something that indicates it is also printing a newline ie)printlnLine

Comment thread src/main/java/Duke.java Outdated
public static void printLine() {
System.out.println("________________________________________");
}
public static void printShortLine() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should try to rename it to something that indicates it is also printing a newline ie)printlnShortLine

Comment thread src/main/java/Duke.java Outdated
printLine();
if (userInput.equals("list")) {
Task.printList();
} else if(userInput.matches("mark \\d+")) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

may want to set constants to identify the regex expression, as regex may not be intuitively readable

Comment thread src/main/java/Duke.java Outdated
Task.markDone(index-1);
System.out.println("Nice! I've marked this task as done:");
System.out.println(" [X] " + Task.tasks[index-1]);
} else if(userInput.matches("unmark \\d+")) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

may want to set constants to identify the regex expression, as regex may not be intuitively readable

@runxinghuan runxinghuan 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.

Generally quite good. However, I noted a few minor coding quality violations which I have recommended solutions for in the comments.

Comment thread src/main/java/Duke.java Outdated
import java.util.Scanner;
//so scanner class can be used

public class Duke {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider changing the class name to Yoj? Since you named your bot to be this.

Comment thread src/main/java/Duke.java Outdated
Comment on lines +40 to +41
String[] taskIndex = userInput.split(" ");
int index = Integer.parseInt(taskIndex[1]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider changing these two lines to a method? So that you can use again in "unmark" condition as well.

Comment thread src/main/java/Duke.java Outdated
int index = Integer.parseInt(taskIndex[1]);
Task.markDone(index-1);
System.out.println("Nice! I've marked this task as done:");
System.out.println(" [X] " + Task.tasks[index-1]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since you already have the getStatusIcon method, why not use it here?

Comment thread src/main/java/Duke.java Outdated
Comment on lines +39 to +50
} else if(userInput.matches("mark \\d+")) {
String[] taskIndex = userInput.split(" ");
int index = Integer.parseInt(taskIndex[1]);
Task.markDone(index-1);
System.out.println("Nice! I've marked this task as done:");
System.out.println(" [X] " + Task.tasks[index-1]);
} else if(userInput.matches("unmark \\d+")) {
String[] taskIndex = userInput.split(" ");
int index = Integer.parseInt(taskIndex[1]);
Task.markUndone(index-1);
System.out.println("OK, I've marked this task as not done yet:");
System.out.println(" [ ] " + Task.tasks[index-1]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider extracting these lines to a method called markTask? So that you can have the same level of abstraction within a code fragment.

Comment thread src/main/java/Task.java Outdated
taskNumber = 0;
}

public static void addTask(String userInput) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I like the way you named your methods, which are all in camalCase. Good job!

@Jai2501 Jai2501 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.

Hi Ze Hui!

Good job on the work done so far!

I have reviewed your code and have left some comments. Please go through them and get back to me for any clarifications.

Thanks!

Comment thread src/main/java/Deadline.java Outdated
Comment on lines +4 to +7
public Deadline (String description, String by){
super(description);
this.by = by;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Advisable to have a uniform spacing strategy, to enhance code readability.

Suggested change
public Deadline (String description, String by){
super(description);
this.by = by;
}
public Deadline (String description, String by) {
super(description);
this.by = by;
}

Comment thread src/main/java/Event.java Outdated
Comment on lines +11 to +18
public String getAt(){
return at;
}

public String toString() {
return "[E] " + super.toString() + description + " (at: " + at + ")";
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It is usually a practise to use this.method() or this.variable when that method or variable belongs to the Class.

This change can be made at other places as well :)

Suggested change
public String getAt(){
return at;
}
public String toString() {
return "[E] " + super.toString() + description + " (at: " + at + ")";
}
}
public String getAt(){
return this.at;
}
public String toString() {
return "[E] " + super.toString() + this.description + " (at: " + this.at + ")";
}
}

Comment thread src/main/java/Task.java Outdated
Comment on lines +2 to +3
protected static String[] tasks = new String[100];
protected static boolean[] tasksCompleted = new boolean[100];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please avoid the use of Magic Numbers. Instead declare a constant with the value you deem is right, and use that constant.

Or better, you may choose to use ArrayList which dynamically resizes as per need, and you may not require such constants. However, everything comes at a tradeoff, so you may do some research into Array vs ArrayList and choose what fits the best for your needs.

Reference: https://nus-cs2113-ay2324s2.github.io/website/se-book-adapted/chapters/codeQuality.html#avoid-magic-numbers

Comment thread src/main/java/Task.java Outdated
Comment on lines +2 to +3
protected static String[] tasks = new String[100];
protected static boolean[] tasksCompleted = new boolean[100];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

For this line, I may suggest you to refactor Task Class to have a boolean variable isDone. As a new Task is created, that isDone variable is unique to that task and may be updated as required. This is also efficient as you don't have to maintain an extra Array.

Sometimes it may happen that, you delete a Task and you may forget to update it in this other Array, making your code fragile and more bug prone.

    protected boolean isTaskDone;

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

System.out.println("] " + description);
}
} No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing EOF. Add an extra empty line at the end of file (EOF), as this indicates the end of the file.

You may configure IntelliJ to add this automatically for you when hit CTRL/CMD + S.

Comment thread src/main/java/Yoj.java Outdated
printLine();
if (userInput.equals("list")) {
Task.printList();
} else if(userInput.matches("mark \\d+")) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You may want to declare all the regex expressions being used as constants. This also allows you to just update the constant and reuse that at multiple places, without needing to update it at every place you declared it initially.

Comment thread src/main/java/Yoj.java Outdated
Comment on lines +33 to +55
while(!userInput.equals("bye")) {
printShortLine();
System.out.println("added: " + userInput);
printLine();
if (userInput.equals("list")) {
Task.printList();
} else if(userInput.matches("mark \\d+")) {
String[] taskIndex = userInput.split(" ");
int index = Integer.parseInt(taskIndex[1]);
Task.markDone(index-1);
System.out.println("Nice! I've marked this task as done:");
System.out.println(" [X] " + Task.tasks[index-1]);
} else if(userInput.matches("unmark \\d+")) {
String[] taskIndex = userInput.split(" ");
int index = Integer.parseInt(taskIndex[1]);
Task.markUndone(index-1);
System.out.println("OK, I've marked this task as not done yet:");
System.out.println(" [ ] " + Task.tasks[index-1]);
} else {
Task.addTask(userInput);
}
userInput = in.nextLine();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This code block can be abstracted to improve the code readability. Usually, methods should not be longer than 30 Lines of Code.

Reference: https://nus-cs2113-ay2324s2.github.io/website/se-book-adapted/chapters/codeQuality.html#avoid-long-methods

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.

4 participants