-
Notifications
You must be signed in to change notification settings - Fork 187
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
base: master
Are you sure you want to change the base?
[Liu Ze Hui] iP #192
Conversation
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.
LGTM! Your code mostly seems to follow the coding standards, all but one line appears to need changing!
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]; |
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.
whichTasksCompleted sounds like a better variable name as the variable name tasksCompleted sounds like an integer
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.
suggested extra comments for cleaner code
src/main/java/Duke.java
Outdated
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
public static void printLine() { |
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.
Should try to rename it to something that indicates it is also printing a newline ie)printlnLine
src/main/java/Duke.java
Outdated
public static void printLine() { | ||
System.out.println("________________________________________"); | ||
} | ||
public static void printShortLine() { |
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.
Should try to rename it to something that indicates it is also printing a newline ie)printlnShortLine
src/main/java/Duke.java
Outdated
printLine(); | ||
if (userInput.equals("list")) { | ||
Task.printList(); | ||
} else if(userInput.matches("mark \\d+")) { |
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.
may want to set constants to identify the regex expression, as regex may not be intuitively readable
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+")) { |
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.
may want to set constants to identify the regex expression, as regex may not be intuitively readable
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.
Generally quite good. However, I noted a few minor coding quality violations which I have recommended solutions for in the comments.
src/main/java/Duke.java
Outdated
@@ -1,10 +1,58 @@ | |||
import java.util.Scanner; | |||
//so scanner class can be used | |||
|
|||
public class 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.
Consider changing the class name to Yoj
? Since you named your bot to be this.
src/main/java/Duke.java
Outdated
String[] taskIndex = userInput.split(" "); | ||
int index = Integer.parseInt(taskIndex[1]); |
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.
Consider changing these two lines to a method? So that you can use again in "unmark" condition as well.
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]); |
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.
Since you already have the getStatusIcon
method, why not use it here?
src/main/java/Duke.java
Outdated
} 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.
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.
src/main/java/Task.java
Outdated
taskNumber = 0; | ||
} | ||
|
||
public static void addTask(String userInput) { |
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 the way you named your methods, which are all in camalCase. Good job!
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.
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!
src/main/java/Deadline.java
Outdated
public Deadline (String description, String by){ | ||
super(description); | ||
this.by = by; | ||
} |
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.
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; | |
} |
src/main/java/Event.java
Outdated
public String getAt(){ | ||
return at; | ||
} | ||
|
||
public String toString() { | ||
return "[E] " + super.toString() + description + " (at: " + at + ")"; | ||
} | ||
} |
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.
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 + ")"; | |
} | |
} |
src/main/java/Task.java
Outdated
protected static String[] tasks = new String[100]; | ||
protected static boolean[] tasksCompleted = new boolean[100]; |
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.
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.
src/main/java/Task.java
Outdated
protected static String[] tasks = new String[100]; | ||
protected static boolean[] tasksCompleted = new boolean[100]; |
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.
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;
src/main/java/ToDo.java
Outdated
|
||
System.out.println("] " + description); | ||
} | ||
} |
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 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
.
src/main/java/Yoj.java
Outdated
printLine(); | ||
if (userInput.equals("list")) { | ||
Task.printList(); | ||
} else if(userInput.matches("mark \\d+")) { |
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 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.
src/main/java/Yoj.java
Outdated
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.
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.
# Conflicts: # src/main/java/Yoj/List.java
This reverts commit 0612989.
find task feature
Added Level-0, Level-1, Level-2, Level-3