[Shyun Yin] iP#66
Conversation
…through extract method
GlendonNotGlen
left a comment
There was a problem hiding this comment.
Overall a great job with the tidy code, could use some renaming for some of the methods to make it clearer. Do consider shifting some of your methods in Eliz.java to the classes instead!
| public class Eliz { | ||
| public static void printTasks(Task[] tasks) { | ||
| for (int i = 0; i < tasks.length; i++) { | ||
| int numToPrint = i + 1; |
There was a problem hiding this comment.
Can consider changing numToPrint to something else, like taskIndex
| } | ||
| } | ||
|
|
||
| public static void markATask(String line, Task[] tasks) { |
There was a problem hiding this comment.
Consider using markOneTask instead?
| + tasks[taskNumInt - 1].description); | ||
| } | ||
|
|
||
| public static Task createTask(String line) { |
There was a problem hiding this comment.
Can change this to a method in your Task.java class instead? so that your main.java will not be as convoluted
| System.out.println("What can I do for you?"); | ||
| } | ||
|
|
||
| public static void markOrUnmark(String line, Task[] tasks, int taskCounter) { |
There was a problem hiding this comment.
Consider using toggleMarkStatus or toggle as ur method name instead?
yanjie1017
left a comment
There was a problem hiding this comment.
Great work in overall. May need to make some modifications to achieve Single Level of Abstraction so that your code is more readable.
| @@ -0,0 +1,18 @@ | |||
| public class Deadline extends Task{ | |||
| private String taskType; | |||
There was a problem hiding this comment.
Can make it as a constant (static variable).
|
|
||
| public static Task createEvent(String taskType, String line) { | ||
| String newDescription = line; | ||
| if (line.contains("/")) { |
There was a problem hiding this comment.
Can consider abstracting these lines out as a new method.
|
|
||
| public static Task createDeadline(String taskType, String line) { | ||
| String newDescription = line; | ||
| if (line.contains("/")) { |
There was a problem hiding this comment.
Can consider abstracting these lines out as a new method.
| unmarkATask(line, Arrays.copyOf(tasks, taskCounter)); | ||
| } else { | ||
| System.out.println("Nice! I've marked this task as done:"); | ||
| markATask(line, Arrays.copyOf(tasks, taskCounter)); |
There was a problem hiding this comment.
Can consider creating a TaskList class to store the tasks and the relevant methods so that you don't have to keep passing the tasks around.
| /** add line to todo, deadline, or event by creating the respective object */ | ||
| Task t = createTask(line); | ||
| tasks[taskCounter] = t; | ||
| taskCounter++; |
There was a problem hiding this comment.
Can abstract these lines out as addTask method.
| t = createEvent(taskType, splitTwoSections[1]); | ||
| break; | ||
| default: | ||
| return null; |
There was a problem hiding this comment.
May cause errors when you have other functions trying to access it.
Debug logic in getInput() method Add a help function that displays the commands for users to input
# Conflicts: # README.md # src/main/java/Eliz/Eliz.java
| if ((breakTaskNames.length < 2)){ | ||
| String firstWord = breakTaskNames[0]; | ||
| switch (firstWord) { | ||
| case "list" : printTasks(tasks); |
There was a problem hiding this comment.
You could begin statements for each case in a new line. See coding standard switch case layout.
| // if (line.substring(line.length() - 1) == " ") { //in the case that the last character is a space | ||
| // breakTaskNames[0] = line; | ||
| // breakTaskNames[1] = null; | ||
| // } else { | ||
| // breakTaskNames = line.split(" ", 2); | ||
| // } |
There was a problem hiding this comment.
You could delete unused code blocks and lines across your files to increase overall code quality.
| Task t = createTask(line); | ||
| tasks.add(t); | ||
| System.out.println("Got it. I've added this task "); | ||
| System.out.println(t); | ||
| System.out.println("Now you have " + tasks.size() + " tasks in the list."); | ||
| /*every time an object is added or edited, append to file*/ | ||
| try { | ||
| writeToFile(filePath, tasks.get(tasks.size()-1).getTaskType() + "|" | ||
| + tasks.get(tasks.size()-1).getStatusIcon() + "|" | ||
| + tasks.get(tasks.size()-1).getDescription() + System.lineSeparator()); | ||
| } catch (IOException e) { | ||
| System.out.println("Something went wrong: " + e.getMessage()); | ||
| } |
There was a problem hiding this comment.
These lines could be refactored further to ensure SLAP.
| System.out.println("Now you have " + tasks.size() + " tasks in the list."); | ||
| /*every time an object is added or edited, append to file*/ | ||
| try { | ||
| writeToFile(filePath, tasks.get(tasks.size()-1).getTaskType() + "|" |
There was a problem hiding this comment.
This line of code has too many parameters that decrease the code readability. How about passing in a Task object as a parameter and letting the method unpack its values?
| } | ||
| } | ||
| } | ||
| // if (breakTaskNames[0].equalsIgnoreCase("todo") || breakTaskNames[0].equalsIgnoreCase("deadline") |
There was a problem hiding this comment.
Omit unused code blocks to increase code quality.
| File f = new File(filePath); //helps to create a file for the give file path | ||
| Scanner s = new Scanner(f); //create scanner using file as a source |
There was a problem hiding this comment.
You could inserted comments on separate line with same indentation relative to the code. This will not break the logical structure of the code. See commenting conventions.
| Scanner in = new Scanner(System.in); | ||
| botIntroduction(); //calls the introduction of the bot | ||
| line = in.nextLine(); | ||
| String filePath = "./task_list.txt"; |
There was a problem hiding this comment.
You could define this file path as a constant if it is not being further modified anywhere.
| System.out.println("unmark [TASK_LIST_NUMBER]"); | ||
| } | ||
|
|
||
| public static void delete(String line, ArrayList<Task> tasks) { |
There was a problem hiding this comment.
It would help to add javadoc comments here to explain what is deleted.
Include find function to find tasks with same name
Include javadocs to all classes and most methods
No description provided.