-
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
[Lyu Xingyu] iP #206
base: master
Are you sure you want to change the base?
[Lyu Xingyu] iP #206
Conversation
src/main/java/Duke.java
Outdated
if(line.equals("bye")){ | ||
// quit | ||
System.out.println(exitPrompt); | ||
break; | ||
}else{ |
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 after the conditional clause and opening brace
src/main/java/Duke.java
Outdated
try { | ||
index = Integer.parseInt(line.substring(funcIdx+1, line.length())) - 1; | ||
} catch (Exception e) { | ||
index = -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.
I like how you have added error handling
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.
New implementation I've noticed. I have not seen this before. Maybe something that I should google up. Well done~
src/main/java/Duke.java
Outdated
if(funcIdx == -1){ | ||
funcIdx = line.length(); | ||
} | ||
String func = line.substring(0, funcIdx); |
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 could give this variable a better name, as it is stored as a String
but is named func
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 agree with @lihka1202 . I'd suggest to give a variable name like commandIndex or inputIndex as it it a bit more clear for readers to understand what you are referring to.
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.
Thank you for your good suggestions! I have made corrections.
src/main/java/Duke.java
Outdated
} | ||
todoList.markItem(index, false); | ||
}else if(func.equals("todo")){ | ||
Todo todo = Todo.toTodo(instruction); |
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 could name object todo
better, as it has the same name as the class and it might get confusing!
src/main/java/Duke.java
Outdated
// mark work as done | ||
int index; | ||
try { | ||
index = Integer.parseInt(line.substring(funcIdx+1, line.length())) - 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.
Could you abstract this out to maintain SLAP
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.
Agreed. Thank you for your suggestion!
src/main/java/Duke.java
Outdated
if(funcIdx == -1){ | ||
funcIdx = line.length(); | ||
} | ||
String func = line.substring(0, funcIdx); |
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 agree with @lihka1202 . I'd suggest to give a variable name like commandIndex or inputIndex as it it a bit more clear for readers to understand what you are referring to.
src/main/java/Duke.java
Outdated
try { | ||
index = Integer.parseInt(line.substring(funcIdx+1, line.length())) - 1; | ||
} catch (Exception e) { | ||
index = -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.
New implementation I've noticed. I have not seen this before. Maybe something that I should google up. Well done~
src/main/java/Event.java
Outdated
int contentIdx = instruction.indexOf("/from"); | ||
int fromIdx = instruction.indexOf("/to"); |
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 u could use Index instead of Idx
src/main/java/Duke.java
Outdated
if(todo == null){ | ||
printError("Wrong todo format"); | ||
continue; | ||
} | ||
todoList.addItem(todo); | ||
}else if(func.equals("deadline")){ | ||
Deadline deadline = Deadline.toDeadline(instruction); | ||
if(deadline == null){ | ||
printError("Wrong deadline format"); | ||
continue; | ||
} | ||
todoList.addItem(deadline); | ||
}else if(func.equals("event")){ | ||
Event event = Event.toEvent(instruction); | ||
if(event == null){ | ||
printError("Wrong event format"); | ||
continue; | ||
} | ||
todoList.addItem(Event.toEvent(instruction)); |
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.
'switch' statement would be better since there are many cases you want to separate.
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.
Function is better to be in verb form.
src/main/java/Deadline.java
Outdated
return new Deadline(deadlineContent, deadlineBy); | ||
} | ||
|
||
public Deadline(String description, String by) { |
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.
public Deadline(String description, String by) { | |
public getDeadline(String description, String by) { |
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.
It is better to avoid deep nesting as possible as you can.
src/main/java/Duke.java
Outdated
if(todo == null){ | ||
printError("Wrong todo format"); | ||
continue; | ||
} | ||
todoList.addItem(todo); | ||
}else if(func.equals("deadline")){ | ||
Deadline deadline = Deadline.toDeadline(instruction); | ||
if(deadline == null){ | ||
printError("Wrong deadline format"); | ||
continue; | ||
} | ||
todoList.addItem(deadline); | ||
}else if(func.equals("event")){ | ||
Event event = Event.toEvent(instruction); | ||
if(event == null){ | ||
printError("Wrong event format"); | ||
continue; | ||
} | ||
todoList.addItem(Event.toEvent(instruction)); |
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.
There is deep nesting in if-else statement while every if statements inside are conducting similar calculation. There would be other way to better construct this code like declaring special function for those calculation.
src/main/java/TodoList.java
Outdated
System.out.println(SPLITTER); | ||
System.out.println(" OK, I've marked this task as not done yet:"); | ||
System.out.print(" [ ] "); | ||
} | ||
System.out.println(tasks[num].getDescription()); | ||
System.out.println(SPLITTER); | ||
System.out.println(); |
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.
So many printings, I think in if-else statement. How about just making additional function for those printing stacks?
Level-8: Dates and Times
Level-9: Find
No description provided.