Conversation
ElonKoh
left a comment
There was a problem hiding this comment.
Overall, I found your code easy to read with the correct syntaxes and your variables are named appropriately. I made some minor notes to improve readability, best practice suggestions, and consistency issues. Good work!
src/main/java/David.java
Outdated
| Scanner scanner = new Scanner(System.in); | ||
| String input = scanner.nextLine(); | ||
| int i = 0; | ||
| char taskType = input.charAt(input.indexOf("[") + 1); |
There was a problem hiding this comment.
Could this variable (taskType) be better named to indicate it being a part of the user input?
src/main/java/David.java
Outdated
| + "added: " + input + "\n" + LINE_SEPERATOR); | ||
| task[i] = new Task(input); | ||
| i++; | ||
| } |
There was a problem hiding this comment.
I like how readable this code logic for your while loop is, abstracting out all the print methods :)
src/main/java/David.java
Outdated
| System.out.println(LINE_SEPERATOR + "\n" + "[" + task[index].getStatusIcon() + "] " + task[index].getDescription() + "\n" + LINE_SEPERATOR); | ||
| } | ||
|
|
||
| public static int getIndex(String marking, String find) { |
There was a problem hiding this comment.
I like that you abstracted this bit of code and named your variables well with a verb and camelCase to make the main method really readable
src/main/java/Task.java
Outdated
| } | ||
|
|
||
| public String getStatusIcon() { | ||
| return (isDone ? "X" : " "); // mark done task with X |
There was a problem hiding this comment.
I like how you write comments to explain code 🤌🏻
but it could be better to explain why instead of what the code is doing
src/main/java/David.java
Outdated
| import java.util.Scanner; | ||
|
|
||
| public class David { | ||
| public static final String LINE_SEPERATOR = "____________________________________________________________"; |
There was a problem hiding this comment.
I like how you named this static final variable in ALL_CAPS
src/main/java/Task.java
Outdated
|
|
||
| @Override | ||
| public String toString() { | ||
| return "[" + getStatusIcon() + "]"; // You can customize this string as needed |
There was a problem hiding this comment.
what is the message you intend to convey with this comment?
H-ZhanHao
left a comment
There was a problem hiding this comment.
Overall nice and understandable code! Just some nits to fix to make it even better.
src/main/java/David.java
Outdated
| + "| |_| | |_| | < __/\n" | ||
| + "|____/ \\__,_|_|\\_\\___|\n"; | ||
| System.out.println("Hello from\n" + logo); | ||
| Task[] task = new Task[100]; |
There was a problem hiding this comment.
Magic number. Perhaps a constant would be more suitable?
src/main/java/David.java
Outdated
| System.out.println(printTaskType(task, i)); | ||
| i++; | ||
| } else if (input.startsWith("event")) { | ||
| task[i] = new Event((input.substring(getIndex(input, " ") + 1, getIndex(input, "/") - 1)), input.substring(getIndex(input, "from") + 5, getIndex(input, "to") - 2), input.substring(getIndex(input, "to") + 3)); |
There was a problem hiding this comment.
Seems like the string filtering takes up a lot of space. Maybe abstracting it into a separate method would make this more readable.
src/main/java/David.java
Outdated
| import java.util.Scanner; | ||
|
|
||
| public class David { | ||
| public static final String LINE_SEPERATOR = "____________________________________________________________"; |
There was a problem hiding this comment.
Great idea to make the line a constant.
src/main/java/David.java
Outdated
| } | ||
| } else if (input.startsWith("mark")) { | ||
| markTask(task, Integer.parseInt(input.split(" ")[1]) - 1); | ||
| printMark(task, Integer.parseInt(input.split(" ")[1]) - 1); |
There was a problem hiding this comment.
markTask and printMark both take the same arguments. Could it be better to combine the two?
This reverts commit f9fc435.
sevenseasofbri
left a comment
There was a problem hiding this comment.
Good job so far! You can improve readability by reducing deep indentation and refactoring long methods into smaller ones.
src/main/java/David.java
Outdated
|
|
||
| Scanner scanner = new Scanner(System.in); | ||
| String input = scanner.nextLine(); | ||
| int i = task.size(); |
There was a problem hiding this comment.
Avoid naming non-loop iterator variables names such as i since this is not inuitive. Rather name this variable something like numTasks
src/main/java/David.java
Outdated
| Scanner scanner = new Scanner(System.in); | ||
| String input = scanner.nextLine(); | ||
| int i = task.size(); | ||
| char input_type = input.charAt(input.indexOf("[") + 1); |
There was a problem hiding this comment.
Avoid the use of magic literals by storing them in variables or consts
src/main/java/David.java
Outdated
| public class David { | ||
| public static final String LINE_SEPERATOR = "____________________________________________________________"; | ||
|
|
||
| public static void main(String[] args) { |
There was a problem hiding this comment.
This main function is quite long, >30 LOC. Consider breaking it into parts and put them in different functions.
src/main/java/David.java
Outdated
| if (input.equals("list")) { | ||
| System.out.println(LINE_SEPERATOR + "\nHere are the tasks in your list:\n"); | ||
| for (int j = 0; j < task.size(); j++) { | ||
| System.out.println((j + 1) + "." + task.get(j).toString() + "\n" + LINE_SEPERATOR); | ||
| } | ||
| } |
There was a problem hiding this comment.
This is 4 levels of indentation, so this can be deemed arrowhead code. Try to refactor the inner levels into methods.
src/main/java/David.java
Outdated
| else if (input.startsWith("mark")) { | ||
| markTask(task, Integer.parseInt(input.split(" ")[1]) - 1); | ||
| printMark(task, Integer.parseInt(input.split(" ")[1]) - 1); | ||
| StorageManager.saveTasks(task); | ||
| } else if (input.startsWith("unmark")) { | ||
| unmarkTask(task, Integer.parseInt(input.split(" ")[1]) - 1); | ||
| printUnmark(task, Integer.parseInt(input.split(" ")[1]) - 1); | ||
| StorageManager.saveTasks(task); |
There was a problem hiding this comment.
Good job keeping a consistent level of abstraction here.
src/main/java/David.java
Outdated
|
|
||
| } | ||
| else if (input.startsWith("delete")) { | ||
| deleteTask(task, Integer.parseInt(input.split(" ")[1]) - 1); | ||
| StorageManager.saveTasks(task); | ||
| i--; | ||
| } | ||
|
|
||
| else { | ||
| throw new IllegalArgumentException(LINE_SEPERATOR + System.lineSeparator() + " Sorry... I don't know what you mean by that? Could you try again?" + System.lineSeparator() + LINE_SEPERATOR); | ||
| } | ||
| } | ||
| catch (IllegalArgumentException e) { |
There was a problem hiding this comment.
if-else conditionals should be of the form (layout-wise):
if (condition) {
statements;
} else if (condition) {
statements;
} else {
statements;
}
src/main/java/David.java
Outdated
| } | ||
| private static String printTaskType(ArrayList<Task> task, int i) { |
There was a problem hiding this comment.
try to have atleast 1 line space between methods.
| static { | ||
| File folder = new File("data"); | ||
| if (!folder.isDirectory() && !folder.mkdirs()) { | ||
| System.err.println("Failed to create directory: " + folder.getAbsolutePath()); | ||
| } | ||
| } |
There was a problem hiding this comment.
Since this is a class-level member, this means every instance of StorageManager will access the same data folder. Theoretically speaking, it is ok for this application. But it might make more sense for each instance of this StorageManager to access their own folders. Just a thought, consider looking into the textbook sections on OOP and class-level members.
| } | ||
|
|
||
| public static ArrayList<Task> loadTasks() { | ||
| File file = new File(FILE_PATH); // create a File for the given file path |
There was a problem hiding this comment.
No need to add a comment if it is obvious through the code.
| try (BufferedReader reader = new BufferedReader(new FileReader(file))) { | ||
| String line; | ||
| while ((line = reader.readLine()) != null) { | ||
| String[] parts = line.split(" \\| "); | ||
| if (parts.length < 3) { | ||
| System.out.println("Skipping invalid task entry: " + line); | ||
| continue; |
There was a problem hiding this comment.
this is ~3 levels of indentation, consider refactoring inner indents to another method
Level 9. Find
* branch-A-JavaDoc: A-JavaDoc : Add JavaDoc Comments # Conflicts: # src/main/java/David/Parser.java # src/main/java/David/TaskList.java
A-UserGuide: User Guide
No description provided.