[Xinran] iP#86
Conversation
Add the ability to mark tasks as done. Optionally, add the ability to change the status back to not done.
Add support for tracking three types of tasks: ToDos: tasks without any date/time attached to it e.g., visit new theme park Deadlines: tasks that need to be done before a specific date/time e.g., submit report by 11/10/2019 5pm Events: tasks that start at a specific time and ends at a specific time e.g., team project meeting on 2/10/2019 2-4pm
| } | ||
| } | ||
|
|
||
| //this.description = description.substring(0, description.lastIndexOf("/") + 4); No newline at end of file |
| System.out.println(bye); | ||
| break; | ||
| } | ||
| else if(userInput.equals("list")){//show list |
There was a problem hiding this comment.
Your comments should be above the line you are commenting
There was a problem hiding this comment.
Thanks for the reminder! I will make corresponding changes.
| for(int i = 0; i<count ; i++) | ||
| System.out.println(i+1 + "." + tasks[i]); | ||
| } | ||
| else if(userInput.split(" ")[0].equals("mark")){//mark task |
There was a problem hiding this comment.
under the coding standards, your else if should be written right next to the bracket above
There was a problem hiding this comment.
I see. Didn't notice that! thanks:)
| } | ||
| else if(input.equals("list")){ | ||
| else if(userInput.equals("list")){//show list | ||
| System.out.println("Here are the tasks in your list:"); |
There was a problem hiding this comment.
Perhaps you could wrap your list function in a method? Additionally, I think the comment can be indented relative to its position in the code (I noticed this in other parts of the code) :)
There was a problem hiding this comment.
Thanks for the reminder! I will make corresponding changes.
| System.out.println(i+1 + "." + tasks[i]); | ||
| } | ||
| else if(input.split(" ")[0].equals("mark")){ | ||
| else if(userInput.split(" ")[0].equals("mark")){//mark task |
There was a problem hiding this comment.
Perhaps you can consider using a boolean to reduce the complexity of this if condition? I think this can apply for the other if conditions within this while loop :)
| //get the integer k in the string | ||
| System.out.println("Nice! I've marked this task as done:"); | ||
| int k = Integer.parseInt(input.split(" ")[1]); | ||
| int k = Integer.parseInt(userInput.split(" ")[1]); |
There was a problem hiding this comment.
Perhaps you can consider renaming the variable name k with a different name that brings across what k represents?
There was a problem hiding this comment.
That has a point:) thanks for the suggestion.
ElaineQT
left a comment
There was a problem hiding this comment.
Maybe some parts can be refactored, but generally the code is clear and compact. Good job!
| + "| |_| | |_| | < __/\n" | ||
| + "|____/ \\__,_|_|\\_\\___|\n"; | ||
| System.out.println("Hello from\n" + logo); | ||
| Task[] tasks = new Task[100]; |
There was a problem hiding this comment.
Perhaps the "100" should be set as a constant?
| String toDoDescription = userInput.split("todo")[1].trim(); | ||
| Task t = new ToDo(toDoDescription); | ||
| tasks[count] = t; | ||
| count++; | ||
| System.out.println("Got it! I've added this task: "); | ||
| System.out.println(t); | ||
| System.out.println("Now you have " + count + " tasks in the list."); |
There was a problem hiding this comment.
Would it be better to extract this part as a method? Similarly for adding deadlines and events.
| System.out.println("Got it! I've added this task: "); | ||
| System.out.println(d); | ||
| System.out.println("Now you have " + count + " tasks in the list."); |
There was a problem hiding this comment.
This printing part is used repeatedly. Maybe it can be written as a separate method so that it can be reused.
There was a problem hiding this comment.
sure, I think that would be better also.
| String by = new String(); | ||
| String at = new String(); |
There was a problem hiding this comment.
These two variables are used only in certain situations. Maybe you can consider adding some utility methods?
References: https://refactoring.guru/smells/temporary-field
Mick609
left a comment
There was a problem hiding this comment.
Clean code with some naming convention issues.
|
|
||
| private static ArrayList<Task> tasks = new ArrayList<>(); | ||
|
|
||
| private static void greeting() { |
There was a problem hiding this comment.
Maybe you should consider using a verb as the name of a method, like "greet"?
| + "What can I do for you?\n" | ||
| + "----------------------------------------------\n"; | ||
| String bye = "Bye. Hope to see you again soon!\n"; | ||
| System.out.println(greeting); |
There was a problem hiding this comment.
I assume you would want to print the String bye here?
| System.out.println(tasks.get(taskIndex-1)); | ||
| } | ||
|
|
||
| private static void addTask(Task t) { |
There was a problem hiding this comment.
Maybe you can use a more descriptive name for the argument, like "task"?
| } | ||
|
|
||
| private static void startBot() { | ||
| Scanner sc = new Scanner(System.in); |
There was a problem hiding this comment.
Maybe you can name the Scanner as "scanner"?
| } | ||
| else if(choice.equals("todo")) { | ||
| String toDoDescription = userInput.split("todo")[1].trim(); | ||
| Task t = new ToDo(toDoDescription); |
There was a problem hiding this comment.
Maybe you can use a name like "task" for the object?
…o get user input.
Level-9: Give users a way to find a task by searching for a keyword. used Ui t…
…tatement error bug by try and catch block.
No description provided.