[Liu Ze Hui] iP#192
Conversation
yeozhishen
left a comment
There was a problem hiding this comment.
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]; | |||
There was a problem hiding this comment.
whichTasksCompleted sounds like a better variable name as the variable name tasksCompleted sounds like an integer
yeozhishen
left a comment
There was a problem hiding this comment.
suggested extra comments for cleaner code
| + "| | | | | | | |/ / _ \\\n" | ||
| + "| |_| | |_| | < __/\n" | ||
| + "|____/ \\__,_|_|\\_\\___|\n"; | ||
| public static void printLine() { |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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+")) { |
There was a problem hiding this comment.
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+")) { |
There was a problem hiding this comment.
may want to set constants to identify the regex expression, as regex may not be intuitively readable
runxinghuan
left a comment
There was a problem hiding this comment.
Generally quite good. However, I noted a few minor coding quality violations which I have recommended solutions for in the comments.
| import java.util.Scanner; | ||
| //so scanner class can be used | ||
|
|
||
| public class Duke { |
There was a problem hiding this comment.
Consider changing the class name to Yoj? Since you named your bot to be this.
| String[] taskIndex = userInput.split(" "); | ||
| int index = Integer.parseInt(taskIndex[1]); |
There was a problem hiding this comment.
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]); |
There was a problem hiding this comment.
Since you already have the getStatusIcon method, why not use it here?
| } 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]); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
I like the way you named your methods, which are all in camalCase. Good job!
Jai2501
left a comment
There was a problem hiding this comment.
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!
| public Deadline (String description, String by){ | ||
| super(description); | ||
| this.by = by; | ||
| } |
There was a problem hiding this comment.
Advisable to have a uniform spacing strategy, to enhance code readability.
| public Deadline (String description, String by){ | |
| super(description); | |
| this.by = by; | |
| } | |
| public Deadline (String description, String by) { | |
| super(description); | |
| this.by = by; | |
| } |
| public String getAt(){ | ||
| return at; | ||
| } | ||
|
|
||
| public String toString() { | ||
| return "[E] " + super.toString() + description + " (at: " + at + ")"; | ||
| } | ||
| } |
There was a problem hiding this comment.
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 :)
| 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 + ")"; | |
| } | |
| } |
| protected static String[] tasks = new String[100]; | ||
| protected static boolean[] tasksCompleted = new boolean[100]; |
There was a problem hiding this comment.
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.
| protected static String[] tasks = new String[100]; | ||
| protected static boolean[] tasksCompleted = new boolean[100]; |
There was a problem hiding this comment.
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); | ||
| } | ||
| } No newline at end of file |
There was a problem hiding this comment.
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+")) { |
There was a problem hiding this comment.
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.
| 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(); | ||
| } |
There was a problem hiding this comment.
This code block can be abstracted to improve the code readability. Usually, methods should not be longer than 30 Lines of Code.
# Conflicts: # src/main/java/Yoj/List.java
This reverts commit 0612989.
find task feature
Added Level-0, Level-1, Level-2, Level-3