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

[Liu Ze Hui] iP #192

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

Conversation

liuzehui03
Copy link

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

Copy link

@yeozhishen yeozhishen left a comment

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!

@@ -0,0 +1,32 @@
public class Task {
protected static String[] tasks = new String[100];
protected static boolean[] tasksCompleted = new boolean[100];

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

Copy link

@yeozhishen yeozhishen left a comment

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

+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
public static void printLine() {

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

public static void printLine() {
System.out.println("________________________________________");
}
public static void printShortLine() {

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

printLine();
if (userInput.equals("list")) {
Task.printList();
} else if(userInput.matches("mark \\d+")) {

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

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

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

Copy link

@runxinghuan runxinghuan left a comment

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.

@@ -1,10 +1,58 @@
import java.util.Scanner;
//so scanner class can be used

public class Duke {

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 on lines 40 to 41
String[] taskIndex = userInput.split(" ");
int index = Integer.parseInt(taskIndex[1]);

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.

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]);

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 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]);

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.

taskNumber = 0;
}

public static void addTask(String userInput) {

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!

Copy link

@Jai2501 Jai2501 left a comment

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 on lines 4 to 7
public Deadline (String description, String by){
super(description);
this.by = by;
}
Copy link

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 on lines 11 to 18
public String getAt(){
return at;
}

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

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 on lines 2 to 3
protected static String[] tasks = new String[100];
protected static boolean[] tasksCompleted = new boolean[100];
Copy link

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 on lines 2 to 3
protected static String[] tasks = new String[100];
protected static boolean[] tasksCompleted = new boolean[100];
Copy link

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;


System.out.println("] " + description);
}
}
Copy link

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.

printLine();
if (userInput.equals("list")) {
Task.printList();
} else if(userInput.matches("mark \\d+")) {
Copy link

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

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