Skip to content
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

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open

Conversation

LS-Young
Copy link

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

No description provided.

@@ -22,7 +22,7 @@ public static void main(String[] args) {
}else if(str.equals("list")){

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.

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("_");

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

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;

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

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)


public static void printList(Task[] list, int num){
String listing = "Here are the tasks in your list:";
if(listing.length() > num) num = listing.length();

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

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"

}
@Override
public int getLength(){
return description.length()+by.length()+12;
Copy link

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

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

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)

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

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);
}
}
}
Copy link

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("|");
}
}
Copy link

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

System.out.print(" ");
for(int i = 0; i < length; i++) System.out.print("_");
System.out.println("");
System.out.print(" |" + str);
Copy link

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

Tasks[num - 1].setDone(true);
printDone(Tasks[num - 1]);
} else {
str = "not assigned yet";
Copy link

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

@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.

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

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.

try {
File dukeFile = new File(file);
File directory = dukeFile.getParentFile();
if(!directory.exists()){
Copy link

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.

if(!directory.exists()){
directory.mkdir();
}
if(!dukeFile.exists()){
Copy link

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;){
Copy link

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

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.

printList(Tasks, maxlength);
} else if (str.contains("todo")) {
checkTodoString(str);
if (str.length() - 5 + 9 > maxlength)
Copy link

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?

} catch (TypingException e) {
printString("OOPS! what do u mean?");
} catch (EmptyListException e) {
printString("OOPS! empty list");
Copy link

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.

switch (str.substring(0,1)) {
case "T":
String[] strT = str.split(" \\| ");
for(String st: strT) System.out.println(st);
Copy link

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

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

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 {

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.

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

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.

public static void printString(String str){
int length = str.length();
System.out.print(" ");
for(int i = 0; i < length; i++) System.out.print("_");

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

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

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