[TJ-Hoo] iP#190
Conversation
Stella1585
left a comment
There was a problem hiding this comment.
Looks good, you followed the coding standards quite well. Overall, you can try to find more suitable variable names that helps to get your intention across. Also the nesting is quite deep for the mark/unmark section. Lastly you can try extracting methods from main as it is quite long.
| System.out.print(i+1+"."); | ||
| System.out.println(taskList.get(i).markTask()+taskList.get(i).name); | ||
| } | ||
| } else if(userInput.contains("unmark") || userInput.contains("mark")){ |
There was a problem hiding this comment.
(not coding standard related but) Since you are using contains and not equals, do you think contains(unmark) is necessary?
| } | ||
| } else if(userInput.contains("unmark") || userInput.contains("mark")){ | ||
| Integer itemNumber = new Integer(0); | ||
| String [] IndexArr = userInput.split(" ",2); |
There was a problem hiding this comment.
this is a variable so camel case should be used, also maybe a better variable name can be used as this array contains both the command and the index.
| boolean isFinished = false; | ||
| List toDoList = new List(); | ||
| Scanner in = new Scanner(System.in); | ||
| ArrayList<Task> taskList = new ArrayList<Task>(); |
There was a problem hiding this comment.
plural form should be used for collection of objects, so perhaps using names such as tasks would be better
| if(userInput.equals("list")){ | ||
| for(int i = 0; i<taskList.size(); i++){ | ||
| System.out.print(i+1+"."); | ||
| System.out.println(taskList.get(i).markTask()+taskList.get(i).name); |
There was a problem hiding this comment.
for your function .get, perhaps be clearer about what you are getting, such using as getStatus or getName.
| if(userInput.equals("bye")){ | ||
| break; | ||
| } | ||
| if(userInput.equals("list")){ |
There was a problem hiding this comment.
any reason why you did not continue with else if?
| if(userInput.equals("bye")){ | ||
| break; | ||
| } | ||
| if(userInput.equals("list")) { | ||
| for (int i = 0; i < taskList.size(); i++) { | ||
| System.out.print(i + 1 + "."); | ||
| System.out.println(taskList.get(i).toString()); | ||
| } | ||
| } else if (userInput.contains("todo")) { | ||
| String info = userInput.substring(5).trim(); | ||
| taskList.add(new Todo(info)); | ||
| int finalTask = taskList.size() - 1; | ||
| System.out.println("Got it. I've added this task:"); | ||
| System.out.println(taskList.get(finalTask).toString()); | ||
| if (taskList.size() == 1){ | ||
| System.out.println("Now you have " +taskList.size()+" task in the list."); | ||
| } else { | ||
| System.out.println("Now you have " + taskList.size() + " tasks in the list."); | ||
| } | ||
| } else if (userInput.contains("deadline")) { | ||
| String [] listArray = userInput.split("/",2); | ||
| String description = listArray[0]; | ||
| String dueDate = listArray[1]; | ||
| String info = description.substring(8).trim(); | ||
| String due = dueDate.substring(3).trim(); | ||
| taskList.add(new Deadline(info, due)); | ||
| int finalTask = taskList.size() - 1; | ||
| System.out.println("Got it. I've added this task:"); | ||
| System.out.println(taskList.get(finalTask).toString()); | ||
| if (taskList.size() == 1){ | ||
| System.out.println("Now you have " +taskList.size()+" task in the list."); | ||
| } else { | ||
| System.out.println("Now you have " + taskList.size() + " tasks in the list."); | ||
| } | ||
| } else if (userInput.contains("event")) { | ||
| String [] listArray = userInput.split("/",3); | ||
| String description = listArray[0]; | ||
| String startTime = listArray[1]; | ||
| String endTime = listArray[2]; | ||
| String info = description.substring(6).trim(); | ||
| String start = startTime.substring(5).trim(); | ||
| String end = endTime.substring(3).trim(); | ||
| taskList.add(new Event(info, start, end)); | ||
| int finalTask = taskList.size() - 1; | ||
| System.out.println("Got it. I've added this task:"); | ||
| System.out.println(taskList.get(finalTask).toString()); | ||
| if (taskList.size() == 1){ | ||
| System.out.println("Now you have " +taskList.size()+" task in the list."); | ||
| } else { | ||
| System.out.println("Now you have " + taskList.size() + " tasks in the list."); | ||
| } | ||
| } else if(userInput.contains("unmark") || userInput.contains("mark")){ | ||
| Integer itemNumber; | ||
| String [] IndexArr = userInput.split(" ",2); | ||
| itemNumber = Integer.parseInt(IndexArr[1])-1; | ||
| if (userInput.contains("unmark")) { | ||
| System.out.println("OK, I've marked this task as not done yet:"); | ||
| taskList.get((int) itemNumber).isCompleted = false; | ||
| System.out.println(taskList.get(itemNumber).toString()); | ||
| } | ||
| else { | ||
| System.out.println("Nice! I've marked this task as done:"); | ||
| taskList.get(itemNumber).isCompleted = true; | ||
| System.out.println(taskList.get(itemNumber).toString()); | ||
| } | ||
| } else { | ||
| taskList.add(new Task(userInput,false)); | ||
| System.out.println("added: "+userInput); | ||
| } |
| int finalTask = taskList.size() - 1; | ||
| System.out.println("Got it. I've added this task:"); | ||
| System.out.println(taskList.get(finalTask).toString()); | ||
| if (taskList.size() == 1){ |
There was a problem hiding this comment.
Perhaps you can leave a space between your round bracket and curly bracket, so that your formatting looks consistent
|
|
||
| String userInput; | ||
| while(in.hasNext()){ | ||
|
|
| if (taskList.size() == 1){ | ||
| System.out.println("Now you have " +taskList.size()+" task in the list."); | ||
| } else { | ||
| System.out.println("Now you have " + taskList.size() + " tasks in the list."); | ||
| } |
There was a problem hiding this comment.
You can consider refactoring this portion of code into a method as it is repeated multiple times in the if-else statements
| System.out.println("Got it. I've added this task:"); | ||
| System.out.println(taskList.get(finalTask).toString()); | ||
| if (taskList.size() == 1){ | ||
| System.out.println("Now you have " +taskList.size()+" task in the list."); |
There was a problem hiding this comment.
Perhaps you can include spaces like this to be more consistent in your formatting
| System.out.println("Now you have " +taskList.size()+" task in the list."); | |
| System.out.println("Now you have " + taskList.size() + " task in the list."); |
slightlyharp
left a comment
There was a problem hiding this comment.
Good job in term of code standard. However there are still room for improvement for readability. Please take note of the naming of variables, improve on abstractions and remember to give comments to your code.
| @@ -0,0 +1,11 @@ | |||
| public class Deadline extends Task { | |||
| protected String due; | |||
There was a problem hiding this comment.
Use noun for variable. Perhaps dueDate is a better name for it.
| String [] listArray = userInput.split("/",2); | ||
| String description = listArray[0]; | ||
| String dueDate = listArray[1]; | ||
| String info = description.substring(8).trim(); |
There was a problem hiding this comment.
Consider avoid all these magic numbers, use named constant instead.
Perhaps use space to split up the phrase instead of hardcoding the character position.
| @@ -0,0 +1,11 @@ | |||
| public class Deadline extends Task { | |||
| protected String due; | |||
| public Deadline(String info, String due) { | |||
There was a problem hiding this comment.
Perhaps name is a better naming for the variable instead of info
| System.out.println("Now you have " + tasks.size() + " tasks in the list."); | ||
| } | ||
| } else if (userInput.contains("deadline")) { | ||
| String [] listArray = userInput.split("/",2); |
There was a problem hiding this comment.
Consider changing to a more meaningful name such as phrases
| String userInput; | ||
| while(in.hasNext()){ | ||
| userInput = in.nextLine(); | ||
| if(userInput.equals("bye")){ |
There was a problem hiding this comment.
Leave a space before the open curly bracket
| if (tasks.size() == 1) { | ||
| System.out.println("Now you have " + tasks.size() + " task in the list."); | ||
| } else { | ||
| System.out.println("Now you have " + tasks.size() + " tasks in the list."); |
There was a problem hiding this comment.
Consider creating a method for this since it is used a few times in the code
| System.out.println("Now you have " + tasks.size() + " tasks in the list."); | ||
| } | ||
| } else if(userInput.contains("mark")){ | ||
| Integer itemNumber; |
There was a problem hiding this comment.
You can still use normal int data type
| String [] listArray = userInput.split("/",3); | ||
| String description = listArray[0]; | ||
| String startTime = listArray[1]; | ||
| String endTime = listArray[2]; |
There was a problem hiding this comment.
User might not give the desired input. Consider implement some error handling taught in week 5
| public Todo (String info) { | ||
| super (info); | ||
| } | ||
| public String toString() { |
There was a problem hiding this comment.
Perhaps adding override annotation to indicate that the method is overriding a method from the parent class. Be consistent in the annotations for all the classes.
| } | ||
| } | ||
| } | ||
| } No newline at end of file |
There was a problem hiding this comment.
Relatively long and deep nested code. Consider break up the code with more abstractions. (create method for segments that are used repeatedly and a method for each command)
# Conflicts: # src/main/java/Duke.java
# Conflicts: # src/main/java/Duke.java
No description provided.