Skip to content

[Zhao Luoyuang] iP#185

Open
LS-Young wants to merge 31 commits intonus-cs2113-AY2122S1:masterfrom
LS-Young:master
Open

[Zhao Luoyuang] iP#185
LS-Young wants to merge 31 commits intonus-cs2113-AY2122S1:masterfrom
LS-Young:master

Conversation

@LS-Young
Copy link
Copy Markdown

@LS-Young LS-Young commented Sep 1, 2021

No description provided.

Comment thread src/main/java/Duke.java Outdated
@@ -22,7 +22,7 @@ public static void main(String[] args) {
}else if(str.equals("list")){
Copy link
Copy Markdown

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.

Comment thread 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("_");
Copy link
Copy Markdown

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

Comment thread 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;
Copy link
Copy Markdown

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

Copy link
Copy Markdown

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)

Comment thread 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();
Copy link
Copy Markdown

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

Comment thread src/main/java/Duke.java
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
Copy link
Copy Markdown

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"

Comment thread src/main/java/Deadline.java Outdated
}
@Override
public int getLength(){
return description.length()+by.length()+12;
Copy link
Copy Markdown

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

Comment thread 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;
Copy link
Copy Markdown

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)

Comment thread 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];
Copy link
Copy Markdown

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

Comment thread src/main/java/Duke.java
printTask(t, j);
}
}
}
Copy link
Copy Markdown

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

Comment thread src/main/java/Duke.java
for(int i = 0; i < length; i++) System.out.print("_");
System.out.println("|");
}
}
Copy link
Copy Markdown

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

Comment thread 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);
Copy link
Copy Markdown

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

Comment thread src/main/java/Duke.java Outdated
Tasks[num - 1].setDone(true);
printDone(Tasks[num - 1]);
} else {
str = "not assigned yet";
Copy link
Copy Markdown

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

Copy link
Copy Markdown

@Leeyp Leeyp left a 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.

Comment thread 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];
Copy link
Copy Markdown

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.

Comment thread src/main/java/Duke.java Outdated
try {
File dukeFile = new File(file);
File directory = dukeFile.getParentFile();
if(!directory.exists()){
Copy link
Copy Markdown

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.

Comment thread src/main/java/Duke.java Outdated
if(!directory.exists()){
directory.mkdir();
}
if(!dukeFile.exists()){
Copy link
Copy Markdown

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.

Comment thread src/main/java/Duke.java
Scanner sc= new Scanner(System.in); //System.in is a standard input stream
boolean isExit = true;
int maxlength = 0;
for(; Tasks.size() < 100 && isExit;){
Copy link
Copy Markdown

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.

Comment thread src/main/java/Duke.java
boolean isExit = true;
int maxlength = 0;
for(; Tasks.size() < 100 && isExit;){
String str= sc.nextLine();
Copy link
Copy Markdown

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.

Comment thread src/main/java/Duke.java Outdated
printList(Tasks, maxlength);
} else if (str.contains("todo")) {
checkTodoString(str);
if (str.length() - 5 + 9 > maxlength)
Copy link
Copy Markdown

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?

Comment thread src/main/java/Duke.java Outdated
} catch (TypingException e) {
printString("OOPS! what do u mean?");
} catch (EmptyListException e) {
printString("OOPS! empty list");
Copy link
Copy Markdown

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.

Comment thread 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);
Copy link
Copy Markdown

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.

Comment thread src/main/java/Duke.java
}

public static void checkNum(int num, int j) throws AssignException {
if(num > j || num <= 0)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Avoid complicated expressions.
  2. Add spacebar before brackets.

Copy link
Copy Markdown

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.

Comment thread src/main/java/Duke.java
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 {
Copy link
Copy Markdown

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.

Comment thread 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();
Copy link
Copy Markdown

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.

Comment thread 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("_");
Copy link
Copy Markdown

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
Copy link
Copy Markdown

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
Copy link
Copy Markdown

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.

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.

5 participants