-
Notifications
You must be signed in to change notification settings - Fork 193
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
[Zhao Luoyuang] iP #185
base: master
Are you sure you want to change the base?
[Zhao Luoyuang] iP #185
Conversation
src/main/java/Duke.java
Outdated
@@ -22,7 +22,7 @@ public static void main(String[] args) { | |||
}else if(str.equals("list")){ |
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 have a space before and after the "else if" statements.
src/main/java/Duke.java
Outdated
String str = "Nice! I've marked this task as done: "; | ||
int length = Math.max(t.getLength(), str.length()); | ||
System.out.print(" "); | ||
for(int i = 0; i < length; i++) System.out.print("_"); |
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 loop should not be one-line
src/main/java/Duke.java
Outdated
System.out.println(greetings); | ||
Task[] Tasks = new Task[100]; | ||
Scanner sc= new Scanner(System.in); //System.in is a standard input stream | ||
boolean flag = true; |
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.
Boolean variables should have boolean form, flag doesn't explain the variable
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.
Agree with Matt. Consider using a name such as isExit, to indicate whether Duke should continue running or terminate. (if isExit is used, do remember to initialise isExit to false and change flag = true on line 21)
src/main/java/Duke.java
Outdated
|
||
public static void printList(Task[] list, int num){ | ||
String listing = "Here are the tasks in your list:"; | ||
if(listing.length() > num) num = listing.length(); |
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.
if statement should not be a single line
String greetings = " Hello! I'm Duke\n" + " What can I do for you?\n"; | ||
System.out.println(greetings); | ||
Task[] Tasks = new Task[100]; | ||
Scanner sc= new Scanner(System.in); //System.in is a standard input stream |
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 find a better name for the variable instead of "sc"
src/main/java/Deadline.java
Outdated
} | ||
@Override | ||
public int getLength(){ | ||
return description.length()+by.length()+12; |
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 leaving a space - description.length() + by.length() + 12
Also consider using a constant to define what 12 means
src/main/java/Duke.java
Outdated
System.out.println(greetings); | ||
Task[] Tasks = new Task[100]; | ||
Scanner sc= new Scanner(System.in); //System.in is a standard input stream | ||
boolean flag = true; |
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.
Agree with Matt. Consider using a name such as isExit, to indicate whether Duke should continue running or terminate. (if isExit is used, do remember to initialise isExit to false and change flag = true on line 21)
src/main/java/Duke.java
Outdated
System.out.println("Hello from\n" + logo);*/ | ||
String greetings = " Hello! I'm Duke\n" + " What can I do for you?\n"; | ||
System.out.println(greetings); | ||
Task[] Tasks = new Task[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.
Consider using a constant such as private static final int MAX_TASK = 100 to represent 100. Similarly, try replacing all other magic numbers later on with constants
printTask(t, j); | ||
} | ||
} | ||
} |
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 code in each of the if-else blocks out to new methods that describe what check/extraction is being done
System.out.println("|"); | ||
System.out.print(" |"); | ||
for(int i = 0; i < length; i++) System.out.print("_"); | ||
System.out.println("|"); | ||
} | ||
} |
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.
Overall, the code is fairly decent to follow. One general comment is that a lot of the methods can be extracted out to make it easier for somebody else to follow quickly. Single line if loops and for loops should still follow the format of:
if (CONDITION) {
// write code here
}
Consider using descriptive names for variables (exp: instead of str or str2, use errorMessage or helpMessage)
Tip: Try using CTRL+ALT+L if you are on windows to automatically indent your code in IntellIJ
src/main/java/Duke.java
Outdated
System.out.print(" "); | ||
for(int i = 0; i < length; i++) System.out.print("_"); | ||
System.out.println(""); | ||
System.out.print(" |" + str); |
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.
Considering that the indentation at the start of each string happens to always be " |", could try defining that particular string as a constant instead such as TAB
src/main/java/Duke.java
Outdated
Tasks[num - 1].setDone(true); | ||
printDone(Tasks[num - 1]); | ||
} else { | ||
str = "not assigned yet"; |
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.
The reuse of the str String variable may be non-intuitive - it initially refers to the command input by the user, and after re-assignment, it became the message back to the user. Consider using separate String names such as userCommand and returnMessage. Otherwise, just parse "not assigned yet" into printString()
* branch-Level-5: Use exceptions and edit code according to comments
* branch-A-Packages: use package to group exceptions and tasks
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.
Good job on the code's logic and flow.
Do be careful about the requirements for coding standards and code quality. I recommend that you do a double check of your code for violations before the final submission.
src/main/java/Duke.java
Outdated
int MAX_TASK = 100; | ||
String greetings = " Hello! I'm Duke\n" + " What can I do for you?\n"; | ||
System.out.println(greetings); | ||
//Task[] Tasks = new Task[MAX_TASK]; |
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.
There should not be commented code at this stage of the project.
src/main/java/Duke.java
Outdated
try { | ||
File dukeFile = new File(file); | ||
File directory = dukeFile.getParentFile(); | ||
if(!directory.exists()){ |
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.
Coding standard violation: add spacebar after 'if' statement.
src/main/java/Duke.java
Outdated
if(!directory.exists()){ | ||
directory.mkdir(); | ||
} | ||
if(!dukeFile.exists()){ |
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.
Coding standard violation: add spacebar after 'if' statement.
Additionally, consider abstracting this and the above into an external method.
Scanner sc= new Scanner(System.in); //System.in is a standard input stream | ||
boolean isExit = true; | ||
int maxlength = 0; | ||
for(; Tasks.size() < 100 && isExit;){ |
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.
Coding standard violation: add spacebar before bracket.
For loop should also follow Egyptian style brackets.
boolean isExit = true; | ||
int maxlength = 0; | ||
for(; Tasks.size() < 100 && isExit;){ | ||
String str= sc.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.
There should be a spacebar after '=' sign.
src/main/java/Duke.java
Outdated
printList(Tasks, maxlength); | ||
} else if (str.contains("todo")) { | ||
checkTodoString(str); | ||
if (str.length() - 5 + 9 > maxlength) |
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.
Avoid magic numbers. Is there any way to make this statement more legible?
src/main/java/Duke.java
Outdated
} catch (TypingException e) { | ||
printString("OOPS! what do u mean?"); | ||
} catch (EmptyListException e) { | ||
printString("OOPS! empty list"); |
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.
Try to add more enter key lines with this large else if statement for legibility.
Also, consider changing else if statements to a switch case statement.
src/main/java/Duke.java
Outdated
switch (str.substring(0,1)) { | ||
case "T": | ||
String[] strT = str.split(" \\| "); | ||
for(String st: strT) System.out.println(st); |
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.
The loop body should be wrapped by curly brackets irrespective of how many lines there are in the body.
} | ||
|
||
public static void checkNum(int num, int j) throws AssignException { | ||
if(num > j || num <= 0) |
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.
- Avoid complicated expressions.
- Add spacebar before brackets.
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.
Same issue with the functions below.
public class Duke { | ||
public static void main(String[] args) { | ||
String logo = " ____ _ \n" | ||
public static void main(String[] args) throws AssignException, TypingException, FormatException, EventStringException, DeadlineStringException, TodoStringException, IOException { |
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 main method is too long (>30 LoC). You may want to abstract out certain blocks of code within into methods and extend the SLAP principle to each task.
src/main/java/Duke.java
Outdated
for(int i = 0; i < Tasks.size(); i++){ | ||
switch (Tasks.get(i).getType()){ | ||
case TODO: | ||
textToAdd += "T | " + (Tasks.get(i).isDone() ? "1" : "0") + " | " + Tasks.get(i).getDescription() + System.lineSeparator(); |
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 line exceeds the conventional length of <120 characters per line. There are a few lines that are also doing the same thing. Perhaps reformatting the string with Java String format() method would help.
src/main/java/Duke.java
Outdated
public static void printString(String str){ | ||
int length = str.length(); | ||
System.out.print(" "); | ||
for(int i = 0; i < length; i++) System.out.print("_"); |
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.
The single line for
statement is missing the curly brackets and line breaks required to meet the coding standard, which is at least 3 separate lines - they make code easier to read.
package duke.exception; | ||
|
||
public class TodoStringException extends Exception { | ||
//no other code needed |
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 could leave out this comment (and similar ones elsewhere) if it is not describing a method.
return isDone; | ||
} | ||
public String getStatusIcon() { | ||
return (isDone ? "X" : " "); // mark done task with X |
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.
The comments could be placed on a separate line with same indentation. Refer to the Java coding standard for examples.
Branch level 9
Revert "Branch level 9"
No description provided.