Skip to content
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

[YFshadaow] ip #80

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open

Conversation

YFshadaow
Copy link

No description provided.

@@ -5,11 +5,12 @@
public class CommandHandler {

private final XiaoAiBot bot;

Choose a reason for hiding this comment

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

I like the naming of the robot!

Comment on lines 31 to 39
case "todo": {
Todo todo;
try {
todo = Todo.parseTodo(args);
} catch (Exception e) {
bot.sendMessage("Error parsing task");
e.printStackTrace();
break;
}

Choose a reason for hiding this comment

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

Good use of try-catch function!

Comment on lines 46 to 74
case "deadline": {
Deadline deadline;
try {
deadline = Deadline.parseDeadline(args);
} catch (Exception e) {
bot.sendMessage("Error parsing task");
e.printStackTrace();
break;
}
bot.getTasks().add(deadline);
bot.sendMessageWithoutSplit("Got it. I've added this task:");
bot.sendMessageWithoutSplit(deadline.toStringWithIsDone());
bot.sendMessage("Now you have " + bot.getTasks().size() + " tasks in the list.");
break;
}
case "event": {
Event event;
try {
event = Event.parseEvent(args);
} catch (Exception e) {
bot.sendMessage("Error parsing task");
e.printStackTrace();
break;
}
bot.getTasks().add(event);
bot.sendMessageWithoutSplit("Got it. I've added this task:");
bot.sendMessageWithoutSplit(event.toStringWithIsDone());
bot.sendMessage("Now you have " + bot.getTasks().size() + " tasks in the list.");
break;

Choose a reason for hiding this comment

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

Good use of switch-case statements!


private String by;

public Deadline(String name, String by) {

Choose a reason for hiding this comment

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

Good use of constructor!

this.bot = bot;
}

public void handleCommand(String command) {

Choose a reason for hiding this comment

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

Very clear naming of the methods. Makes it readable and easy to understand.

case "todo": {
Todo todo;
try {
todo = Todo.parseTodo(args);

Choose a reason for hiding this comment

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

Is it better to handle the exception more gracefully rather than printing the stack trace and breaking the switch block? For example, could we log the error and send a user-friendly message instead?

bot.sendMessage("No command detected!");
return;
}
String[] args = new String[splitCommand.length - 1];

Choose a reason for hiding this comment

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

Could it be clearer to use Arrays.copyOfRange() here? It might make the code more readable.

break;
}
bot.sendMessageWithoutSplit("OK, I've marked this task as not done yet:");
bot.sendMessage(bot.getTasks().get(index - 1).toStringWithIsDone());

Choose a reason for hiding this comment

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

Would it be more efficient to store the result of bot.getTasks().get(index - 1) in a variable before sending it as a message? This way, we wouldn't need to retrieve it twice.

Copy link
Author

Choose a reason for hiding this comment

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

Usually I do that for variables that are used three times or more. For variables that are used twice I might just leave it as that.

@@ -0,0 +1,132 @@
package cn.yfshadaow.cs2113.ip;

Choose a reason for hiding this comment

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

Hi Zhengdao! Hope your health got better over the holidays!

Copy link

@maanyos maanyos left a comment

Choose a reason for hiding this comment

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

Good adherence with coding standards and use of exceptions.

Comment on lines 7 to 15
public String getBy() {
return by;
}

public void setBy(String by) {
this.by = by;
}

private String by;
Copy link

Choose a reason for hiding this comment

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

easier to read f you declare first and use later


private boolean shouldQuit = false;

private void initialize() {
Copy link

Choose a reason for hiding this comment

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

dont put unfinished code in a pr

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