-
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
[Cui Minjing] iP #13
base: master
Are you sure you want to change the base?
[Cui Minjing] iP #13
Conversation
src/main/java/Duke.java
Outdated
public class Duke { | ||
public static void main(String[] args) { | ||
|
||
public static final String Line = " ____________________________________________________________"; |
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 refactor this attribute name as fully capitalized. All constants' names should be capitalized.
src/main/java/Task.java
Outdated
@@ -0,0 +1,21 @@ | |||
public class Task { | |||
protected String content; | |||
protected boolean Done; |
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.
Done
could be renamed to sound like a boolean. For example, isDone
src/main/java/Duke.java
Outdated
String[] number = command.split(" "); | ||
int taskIndex = Integer.parseInt(number[1]) - 1; | ||
tasks[taskIndex].complete(); | ||
System.out.println(Line + "\n" + " Nice! I've marked this task as done:" + "\n " + tasks[taskIndex].toString() + "\n" + Line); |
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 make this line shorter to improve readability. The same can be done for other long lines in this method.
src/main/java/Duke.java
Outdated
System.out.println(" What can I do for you?"); | ||
System.out.println(Line); | ||
} | ||
public static void main(String[] args) { |
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 implementation for this method is quite long. Perhaps it could be refactored further? For example, the handling of each task (todo / deadline / event) could be made different methods. You may also consider making the "happy path" more prominent.
src/main/java/Duke.java
Outdated
for(int i=0; i<taskSum; i++){ | ||
now = tasks[i]; | ||
System.out.println(" " + (i+1) + "." + now.toString()); |
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 might like to insert spaces before and after arithmetic operators too improve readability
src/main/java/Duke.java
Outdated
break; | ||
case "bye": | ||
break; | ||
default: |
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.
In the default
case, you could either use an explicit //Fallthrough
comment or include a break
statement for consistent style
Apart from refactoring the |
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.
First PR done.
src/main/java/Duke.java
Outdated
@@ -2,24 +2,24 @@ | |||
|
|||
public class Duke { | |||
|
|||
public static final String Line = " ____________________________________________________________"; | |||
private static Task[] tasks = new Task[110]; | |||
private static int taskSum = 0; | |||
|
|||
public static void printList() { | |||
Task now; |
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.
Could use a more appropriate variable name like task instead of now
src/main/java/Duke.java
Outdated
int first = command.indexOf(" "); | ||
String item = command.substring(first,command.length()); | ||
tasks[taskSum] = new Todo(item); | ||
taskSum = taskSum + 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.
Could be simplified to taskSum++;
src/main/java/Duke.java
Outdated
} | ||
System.out.println("____________________________________________________________"); | ||
System.out.println(Line); | ||
} | ||
public static void bye() { |
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.
Correct use of casing for method bye
src/main/java/Task.java
Outdated
@@ -14,4 +14,8 @@ public void complete(){ | |||
public String getInformation() { |
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.
Correct use of camelCase.
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 good job! Please consider using more SLAP to make the code better to understand and simply some of the logic (Practice KISSing) if possible.
src/main/java/Duke/Duke.java
Outdated
Task now; | ||
System.out.println(Line); | ||
System.out.println(" Here are the tasks in your list:"); | ||
for(int i=0; i<taskSum; i++){ |
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 spacing between the brackets ( and { in the for statement. The same concept applies to the rest of the code.
src/main/java/Duke/Duke.java
Outdated
if(command.contains("done")){ | ||
String[] number = command.split(" "); | ||
int taskIndex = Integer.parseInt(number[1]) - 1; | ||
tasks.get(taskIndex).complete(); | ||
System.out.println(Line + "\n" + " Nice! I've marked this task as done:" + "\n " + tasks.get(taskIndex).toString() + "\n" + Line); | ||
} | ||
else if(command.contains("delete")){ | ||
String[] number = command.split(" "); | ||
int taskIndex = Integer.parseInt(number[1]) - 1; | ||
Task temp = tasks.get(taskIndex); | ||
System.out.println(Line + "\n" + " Noted. I've removed this task: " + "\n " + tasks.get(taskIndex).toString() + "\n" + " Now you have " + taskSum + " tasks in the list"); | ||
System.out.println(Line); | ||
tasks.remove(taskIndex); | ||
taskSum--; | ||
} | ||
else if(command.contains("todo")){ | ||
int first = command.indexOf(" "); | ||
int check = command.indexOf("d"); | ||
if(check == command.length()-2){ | ||
System.out.println(Line); | ||
System.out.println(" ☹ OOPS!!! The description of a todo cannot be empty."); | ||
System.out.println(Line); | ||
continue; | ||
} | ||
String item = command.substring(first,command.length()); | ||
Task temp = new Todo(item); | ||
tasks.add(temp); | ||
taskSum++; | ||
System.out.println(Line + "\n" + " Got it. I've added this task: " + "\n" + " [T][ ] " + item + "\n" + " Now you have " + taskSum + " tasks in the list"); | ||
System.out.println(Line); | ||
|
||
} | ||
else if(command.contains("deadline")){ | ||
int first = command.indexOf(" "); | ||
int check = command.indexOf("deadline"); | ||
if(check == command.length()-8){ | ||
System.out.println(Line); | ||
System.out.println(" ☹ OOPS!!! The description of a deadline cannot be empty."); | ||
System.out.println(Line); | ||
continue; | ||
} | ||
int itemEnd = command.indexOf("/"); | ||
String item = command.substring(first,itemEnd); | ||
String by = command.substring(itemEnd + 1,command.length()); | ||
Task temp = new Deadline(item,by); | ||
tasks.add(temp); | ||
taskSum++; | ||
System.out.println(Line + "\n" + " Got it. I've added this task: " + "\n" + " [D][ ] " + item + " (" + by + ")" + "\n" + " Now you have " + taskSum + " tasks in the list"); | ||
System.out.println(Line); | ||
} | ||
else if(command.contains("event")){ | ||
int first = command.indexOf(" "); | ||
int check = command.indexOf("event"); | ||
if(check == command.length()-5){ | ||
System.out.println(Line); | ||
System.out.println(" ☹ OOPS!!! The description of a event cannot be empty."); | ||
System.out.println(Line); | ||
continue; | ||
} | ||
int itemEnd = command.indexOf("/"); | ||
String item = command.substring(first,itemEnd); | ||
String at = command.substring(itemEnd + 1,command.length()); | ||
Task temp = new Event(item,at); | ||
tasks.add(temp); | ||
taskSum++; | ||
System.out.println(Line + "\n" + " Got it. I've added this task: " + "\n" + " [E][ ] " + item + " (" + at + ")" + "\n" + " Now you have " + taskSum + " tasks in the list"); | ||
System.out.println(Line); | ||
} | ||
else{ | ||
switch (command){ | ||
case "list": | ||
printList(); | ||
break; | ||
case "bye": | ||
break; | ||
default: | ||
System.out.println(Line); | ||
System.out.println(" ☹ OOPS!!! I'm sorry, but I don't know what that means :-("); | ||
System.out.println(Line); | ||
} | ||
} | ||
}while(!command.equals("bye")); | ||
bye(); | ||
} | ||
} |
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 logic can be further broken down into simpler function, therefore, consider using more SLAP.
Can consider using the switch (instead of if-else) statement too to simplify the code.
Function is too bulky and long (more than 30 LOC), consider breaking it down into smaller parts.
Can consider making the happy path prominent (i.e. make the successful execution path obvious).
src/main/java/Duke/Todo.java
Outdated
|
||
public Todo(String content) { | ||
super(content); | ||
|
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.
Remove unnecessary whitespace within the code
src/main/java/Duke/Duke.java
Outdated
greeting(); | ||
String command; | ||
Scanner in = new Scanner(System.in); | ||
String f = "data/lines.txt"; |
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 the string is a constant, the variable name must be all uppercase (and underscore to separate the words) instead. A better variable name would also make understanding the code easier.
src/main/java/Duke/Duke.java
Outdated
try { | ||
writeToFile(f); | ||
} catch (IOException e) { | ||
System.out.println("Something went wrong: " + e.getMessage()); |
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 the use of magic strings. In this case, the error message can be extracted into a constant variable with a suitable name.
src/main/java/Duke/Duke.java
Outdated
} | ||
else if(command.contains("delete")){ | ||
String[] number = command.split(" "); | ||
int taskIndex = Integer.parseInt(number[1]) - 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.
Avoid the use of magic literals. Using a suitable variable name for the constant numbers (which describes the value) would help the understanding of the program.
src/main/java/Duke/Duke.java
Outdated
int first = command.indexOf(" "); | ||
int check = command.indexOf("deadline"); |
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 better variable name that is more descriptive. e.g. indexOfDeadline
src/main/java/Duke/Duke.java
Outdated
} | ||
else{ | ||
switch (command){ | ||
case "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.
Case/default clauses must be on the same indentation as the switch statement.
src/main/java/Duke/Duke.java
Outdated
System.out.println(Line); | ||
} | ||
} | ||
}while(!command.equals("bye")); |
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 spacing between the bracket } and while clause
src/main/java/Duke/Duke.java
Outdated
Task temp = new Todo(item); | ||
tasks.add(temp); | ||
taskSum++; | ||
System.out.println(Line + "\n" + " Got it. I've added this task: " + "\n" + " [T][ ] " + item + "\n" + " Now you have " + taskSum + " tasks in the 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.
Line is too long. Consider separating the line into multiple lines.
No description provided.