Conversation
| @@ -0,0 +1,81 @@ | |||
| import java.lang.String; | |||
|
|
|||
| public class List { | |||
There was a problem hiding this comment.
I wouldn't recommend calling your class List - there's already a provided class within Java called List, and this could prove very confusing to readers. You might want to consider changing the name of this class to something else.
| + task.substring(task.indexOf(" "), task.indexOf("/")) | ||
| + "(" + task.substring(task.indexOf("/") + 1, task.indexOf("/") + 3) | ||
| + ": " + task.substring(task.indexOf("/") + 4) + ")"; |
There was a problem hiding this comment.
This section looks quite confusing - what are the +1 and +3 and +4 doing there - what do they mean? You might want to define these magic variables before using them.
| public static void doneTask(String task) { | ||
| task = task.trim(); | ||
| String str = ""; | ||
| if (task != null && !"".equals(task)) { |
There was a problem hiding this comment.
You could consider replacing "".equals(task) with task.isEmpty() - it reads more sensibly.
| System.out.println(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n " | ||
| + "Here are the tasks in your list:"); | ||
| for (int i = 0; i < count; i++) { | ||
| System.out.println(" " + list[i]); |
There was a problem hiding this comment.
You could consider defining some variable to deal with the huge block of spaces inside your println.
| public class List { | ||
|
|
||
| public static String[] list = new String[100]; | ||
| public static String[] done = new String[100]; |
There was a problem hiding this comment.
Would be good to rename done to something like doneList
| + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); | ||
| while (true) { | ||
| Scanner in = new Scanner(System.in); | ||
| String order; |
There was a problem hiding this comment.
variable name order does not break the coding standard but it seems very unintuitive to me, a better name would be maybe input or task
| List.addTask(order); | ||
| if (order.equals("list")) { | ||
| List.printTask(); | ||
| } |
There was a problem hiding this comment.
Can consider using case inside of multiple ifs
| + task.substring(task.indexOf(" ")); | ||
| } | ||
| count++; | ||
| if (count == 1) { |
There was a problem hiding this comment.
can consider putting this whole chunk in a method to reduce repeating statements
There was a problem hiding this comment.
Could also use variables to represent the repeated print statements
iamabhishek98
left a comment
There was a problem hiding this comment.
I have added my suggestions. Please note that although I have not repeated myself, what I have commented in one place applies to the rest of the codebase as well.
| } | ||
| System.out.println(SPLIT_LINE); | ||
| System.out.println(" Got it. I've added this task:"); | ||
| System.out.println(" " + list.get(list.size() - 1)); |
There was a problem hiding this comment.
Avoid having such nested logic in print statements as the purpose of print statements is only to print and not do anything else. Seperate this out into separate lines
| if (tasks[i].contains("X")) { | ||
| Todo todo = new Todo(description); | ||
| todo.description = todo.description.replaceFirst(" ", "X"); | ||
| todo.isDone = true; | ||
| list.add(todo); | ||
| } else { | ||
| list.add(new Todo(description)); | ||
| } | ||
| continue; | ||
| case "D": | ||
| String by = tasks[i].substring(tasks[i].indexOf(":") + 2, tasks[i].indexOf(")")); | ||
| if (tasks[i].contains("X")) { | ||
| Deadline deadline = new Deadline(description.substring(0, description.indexOf("(") - 1), by); | ||
| deadline.description = deadline.description.replaceFirst(" ", "X"); | ||
| deadline.isDone = true; | ||
| list.add(deadline); | ||
| } else { | ||
| list.add(new Deadline(description.substring(0, description.indexOf("(") - 1), by)); | ||
| } | ||
| continue; | ||
| case "E": | ||
| String at = tasks[i].substring(tasks[i].indexOf(":") + 2, tasks[i].indexOf(")")); | ||
| if (tasks[i].contains("X")) { | ||
| Event event = new Event(description.substring(0, description.indexOf("(") - 1), at); | ||
| event.description = event.description.replaceFirst(" ", "X"); | ||
| event.isDone = true; | ||
| list.add(event); | ||
| } else { | ||
| list.add(new Event(description.substring(0, description.indexOf("(") - 1), at)); | ||
| } |
There was a problem hiding this comment.
Consider abstracting out the logic of each switch case statement into separate functions
| event.isDone = true; | ||
| list.add(event); | ||
| } else { | ||
| list.add(new Event(description.substring(0, description.indexOf("(") - 1), at)); |
There was a problem hiding this comment.
As mentioned before, do not use nested logic like this as it makes code extremely hard to read.
| switch (tasks[i].substring(2, 3)) { | ||
| case "T": | ||
| Todo todo = new Todo(description); | ||
| todo.description = todo.description.replaceFirst(" ", "X"); |
There was a problem hiding this comment.
Avoid magic strings like "X" - extract them out as constants and name them appropriately using proper naming conventions
| } | ||
|
|
||
| public static void printDoneList() { | ||
| if (doneList.size() == 0) { |
There was a problem hiding this comment.
You can also do something like:
if (!doneList.size()) {
}
| protected boolean isDone; | ||
|
|
||
| public List(String description) { | ||
| this.description = "[ ] " + description; |
There was a problem hiding this comment.
As mentioned earlier, avoid magic strings like "[ ] "
| if (task != null && !"".equals(task)) { | ||
| for (int i = 0; i < task.length(); i++) { | ||
| if (task.charAt(i) >= 48 && task.charAt(i) <= 57) { | ||
| str = str + task.charAt(i); | ||
| } | ||
| } |
There was a problem hiding this comment.
Having so many nested if statements and loops can be hard to read. Consider abstracting it out into a different function
merge PR for findCommand
Merge PR for java doc
No description provided.