[Tze Loong] iP#213
Conversation
| import java.util.Scanner; | ||
|
|
||
| public class Duke { | ||
| public static void main(String[] args) { |
There was a problem hiding this comment.
Consistent 4 spaces indent throughout the code, good job
| greet_user(); | ||
| int counter = 0; | ||
|
|
||
| Tasks[] list_of_tasks = new Tasks[101]; // Following the assumption that there will be no more than 100 tasks |
There was a problem hiding this comment.
Perhaps you try using camelcase when naming variables. Eg. listOfTasks
| @@ -0,0 +1,23 @@ | |||
| public class Tasks { | |||
There was a problem hiding this comment.
Perhaps you could name this class as "Task" (singular) instead as it refers to one task
| System.out.println("How can i help u? \n"); | ||
| } | ||
|
|
||
| public static void echo() { |
There was a problem hiding this comment.
Good job for using a verb to name this method
SongZijin
left a comment
There was a problem hiding this comment.
In general, the code is quite clear, however, there is a lot of potential for clearer and more concise code.
| if ("list".equals(input)) { | ||
| System.out.println("Here are the tasks in your list: "); | ||
| for (int i = 0; i < counter; i++) { | ||
| System.out.println( | ||
| i + 1 + "." + " " + list_of_tasks[i].getStatusIcon() + " " + list_of_tasks[i].description); | ||
| } | ||
| } else if (input.length() >= 4 && input.substring(0, 4).equals("mark")) { | ||
| Integer index = Integer.valueOf(input.substring(5, input.length())); | ||
| list_of_tasks[index - 1].markAsDone(); | ||
| System.out.println("Nice! This task is completed"); | ||
| System.out | ||
| .println(list_of_tasks[index - 1].getStatusIcon() + " " + list_of_tasks[index - 1].description); | ||
| } else if (input.length() >= 6 && input.substring(0, 6).equals("unmark")) { | ||
| Integer index = Integer.valueOf(input.substring(7, input.length())); | ||
| list_of_tasks[index - 1].markAsUnDone(); | ||
| System.out.println("Ok, This task is still not complete"); | ||
| System.out | ||
| .println(list_of_tasks[index - 1].getStatusIcon() + " " + list_of_tasks[index - 1].description); | ||
| } else { | ||
| System.out.println("added: " + input); | ||
| list_of_tasks[counter].description = input; | ||
| list_of_tasks[counter].isDone = false; | ||
| counter++; | ||
| } | ||
| scan = new Scanner(System.in); | ||
| input = scan.nextLine(); |
There was a problem hiding this comment.
Since you abstracted the [greet_user()] function, it may be better if you maintain Single Level of Abstraction Principle (SLAP), and also extract this portion as a separate function
| greet_user(); | ||
| int counter = 0; | ||
|
|
||
| Tasks[] list_of_tasks = new Tasks[101]; // Following the assumption that there will be no more than 100 tasks |
There was a problem hiding this comment.
It may be better to avoid using a magic number (100) and instead define it at the top of the file as MAX_NUMBER_OF_TASKS
| } | ||
|
|
||
| public static void main(String[] args) { | ||
| greet_user(); |
There was a problem hiding this comment.
Good job on extracting this part as a separate function
| if ("list".equals(input)) { | ||
| System.out.println("Here are the tasks in your list: "); | ||
| for (int i = 0; i < counter; i++) { | ||
| System.out.println( | ||
| i + 1 + "." + " " + list_of_tasks[i].getStatusIcon() + " " + list_of_tasks[i].description); | ||
| } |
There was a problem hiding this comment.
It may be clearer to extract these parts as separate functions to avoid nesting loops.
cheehengk
left a comment
There was a problem hiding this comment.
Overall good effort in implementation.More work on SLAP with shorter methods, and classes will be helpful in future iP levels and tP.
| switch (command[0]) { | ||
| case "todo": |
There was a problem hiding this comment.
Switch-case should not have different indentations.
| } | ||
| } | ||
|
|
||
| public static void main(String[] args) { |
There was a problem hiding this comment.
Try keeping your main method short and have a parser to deal with interpreting user commands instead
| String d_by = d[1]; | ||
| Deadline(d_description, d_by); | ||
| break; | ||
| case "event": |
There was a problem hiding this comment.
Perhaps consider using constants instead of strings, for example, COMMAND_EVENT instead of "event"
| List(); | ||
| break; | ||
| case "mark": | ||
| Integer m_index = Integer.valueOf(command[1]); |
There was a problem hiding this comment.
m_index, u_index etc. might be easy for the original developer to understand but not for someone else reading it or another person taking over. Consider using clearer naming in this case.
| public class Duke { | ||
| public static void main(String[] args) { | ||
|
|
||
| private static Tasks[] list_of_tasks = new Tasks[101]; |
There was a problem hiding this comment.
Consider other data structures, apart from a fixed size array, to make your product more scalable, especially since we are already approaching recess week :)
| print_action(); | ||
| } | ||
|
|
||
| public static void Event(String description, String start, String end) { |
There was a problem hiding this comment.
Avoid using constructor names of other classes as method name. It can be confusing and potential source of bug. Also, consider separate classes for adding new tasks.
Added JavaDoc comments
No description provided.