-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TJ-Hoo] iP #190
base: master
Are you sure you want to change the base?
[TJ-Hoo] iP #190
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
src/main/java/Duke.java
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(not coding standard related but) Since you are using contains and not equals, do you think contains(unmark) is necessary?
src/main/java/Duke.java
Outdated
} | ||
} 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
src/main/java/Duke.java
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plural form should be used for collection of objects, so perhaps using names such as tasks would be better
src/main/java/Duke.java
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for your function .get, perhaps be clearer about what you are getting, such using as getStatus or getName.
src/main/java/Duke.java
Outdated
if(userInput.equals("bye")){ | ||
break; | ||
} | ||
if(userInput.equals("list")){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason why you did not continue with else if?
src/main/java/Duke.java
Outdated
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); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like how you avoided deep-nesting
src/main/java/Duke.java
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps you can leave a space between your round bracket and curly bracket, so that your formatting looks consistent
|
||
String userInput; | ||
while(in.hasNext()){ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this space can be removed
src/main/java/Duke.java
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can consider refactoring this portion of code into a method as it is repeated multiple times in the if-else statements
src/main/java/Duke.java
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use noun for variable. Perhaps dueDate is a better name for it.
src/main/java/Duke.java
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps name is a better naming for the variable instead of info
src/main/java/Duke.java
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider changing to a more meaningful name such as phrases
src/main/java/Duke.java
Outdated
String userInput; | ||
while(in.hasNext()){ | ||
userInput = in.nextLine(); | ||
if(userInput.equals("bye")){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leave a space before the open curly bracket
src/main/java/Duke.java
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider creating a method for this since it is used a few times in the code
src/main/java/Duke.java
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can still use normal int data type
src/main/java/Duke.java
Outdated
String [] listArray = userInput.split("/",3); | ||
String description = listArray[0]; | ||
String startTime = listArray[1]; | ||
String endTime = listArray[2]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.