Skip to content

[Lyu Xingyu] iP#206

Open
Zemdalk wants to merge 30 commits into
nus-cs2113-AY2223S2:masterfrom
Zemdalk:master
Open

[Lyu Xingyu] iP#206
Zemdalk wants to merge 30 commits into
nus-cs2113-AY2223S2:masterfrom
Zemdalk:master

Conversation

@Zemdalk

@Zemdalk Zemdalk commented Feb 1, 2023

Copy link
Copy Markdown

No description provided.

Comment thread src/main/java/Duke.java Outdated
Comment on lines +32 to +36
if(line.equals("bye")){
// quit
System.out.println(exitPrompt);
break;
}else{

Copy link
Copy Markdown

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

Comment thread src/main/java/Duke.java Outdated
Comment on lines +66 to +70
try {
index = Integer.parseInt(line.substring(funcIdx+1, line.length())) - 1;
} catch (Exception e) {
index = -1;
}

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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~

Comment thread src/main/java/Duke.java Outdated
if(funcIdx == -1){
funcIdx = line.length();
}
String func = line.substring(0, funcIdx);

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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.

Copy link
Copy Markdown
Author

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.

Comment thread src/main/java/Duke.java Outdated
}
todoList.markItem(index, false);
}else if(func.equals("todo")){
Todo todo = Todo.toTodo(instruction);

Copy link
Copy Markdown

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!

Comment thread src/main/java/Duke.java Outdated
// mark work as done
int index;
try {
index = Integer.parseInt(line.substring(funcIdx+1, line.length())) - 1;

Copy link
Copy Markdown

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

Copy link
Copy Markdown
Author

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!

Comment thread src/main/java/Duke.java Outdated
if(funcIdx == -1){
funcIdx = line.length();
}
String func = line.substring(0, funcIdx);

Copy link
Copy Markdown

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.

Comment thread src/main/java/Duke.java Outdated
Comment on lines +66 to +70
try {
index = Integer.parseInt(line.substring(funcIdx+1, line.length())) - 1;
} catch (Exception e) {
index = -1;
}

Copy link
Copy Markdown

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~

Comment thread src/main/java/Event.java Outdated
Comment on lines +7 to +8
int contentIdx = instruction.indexOf("/from");
int fromIdx = instruction.indexOf("/to");

Copy link
Copy Markdown

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

Comment thread src/main/java/Duke.java Outdated
Comment on lines +71 to +89
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));

Copy link
Copy Markdown

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.

@0nandon 0nandon left a comment

Copy link
Copy Markdown

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.

Comment thread src/main/java/Deadline.java Outdated
return new Deadline(deadlineContent, deadlineBy);
}

public Deadline(String description, String by) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public Deadline(String description, String by) {
public getDeadline(String description, String by) {

@0nandon 0nandon left a comment

Copy link
Copy Markdown

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.

Comment thread src/main/java/Duke.java Outdated
Comment on lines +71 to +89
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));

Copy link
Copy Markdown

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.

Comment thread src/main/java/TodoList.java Outdated
Comment on lines 40 to 46
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();

@0nandon 0nandon Feb 3, 2023

Copy link
Copy Markdown

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants