Conversation
| @@ -22,7 +22,7 @@ public static void main(String[] args) { | |||
| }else if(str.equals("list")){ | |||
There was a problem hiding this comment.
Should have a space before and after the "else if" statements.
| 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("_"); |
| 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.
Boolean variables should have boolean form, flag doesn't explain the variable
There was a problem hiding this comment.
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)
|
|
||
| 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.
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.
should find a better name for the variable instead of "sc"
| } | ||
| @Override | ||
| public int getLength(){ | ||
| return description.length()+by.length()+12; |
There was a problem hiding this comment.
Consider leaving a space - description.length() + by.length() + 12
Also consider using a constant to define what 12 means
| 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.
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)
| 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.
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.
Consider extracting code in each of the if-else blocks out to new methods that describe what check/extraction is being done
| for(int i = 0; i < length; i++) System.out.print("_"); | ||
| System.out.println("|"); | ||
| } | ||
| } |
There was a problem hiding this comment.
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
| 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.
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
| Tasks[num - 1].setDone(true); | ||
| printDone(Tasks[num - 1]); | ||
| } else { | ||
| str = "not assigned yet"; |
There was a problem hiding this comment.
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
Leeyp
left a comment
There was a problem hiding this comment.
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.
| 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.
There should not be commented code at this stage of the project.
| try { | ||
| File dukeFile = new File(file); | ||
| File directory = dukeFile.getParentFile(); | ||
| if(!directory.exists()){ |
There was a problem hiding this comment.
Coding standard violation: add spacebar after 'if' statement.
| if(!directory.exists()){ | ||
| directory.mkdir(); | ||
| } | ||
| if(!dukeFile.exists()){ |
There was a problem hiding this comment.
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.
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.
There should be a spacebar after '=' sign.
| printList(Tasks, maxlength); | ||
| } else if (str.contains("todo")) { | ||
| checkTodoString(str); | ||
| if (str.length() - 5 + 9 > maxlength) |
There was a problem hiding this comment.
Avoid magic numbers. Is there any way to make this statement more legible?
| } catch (TypingException e) { | ||
| printString("OOPS! what do u mean?"); | ||
| } catch (EmptyListException e) { | ||
| printString("OOPS! empty list"); |
There was a problem hiding this comment.
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.
| 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.
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.
- Avoid complicated expressions.
- Add spacebar before brackets.
| 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.
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.
| 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.
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.
| 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.
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.
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.
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.