Skip to content

[YFshadaow] ip#80

Open
YFshadaow wants to merge 27 commits into
nus-cs2113-AY2324S1:masterfrom
YFshadaow:master
Open

[YFshadaow] ip#80
YFshadaow wants to merge 27 commits into
nus-cs2113-AY2324S1:masterfrom
YFshadaow:master

Conversation

@YFshadaow

Copy link
Copy Markdown

No description provided.

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

private final XiaoAiBot bot;

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 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;
}

Copy link
Copy Markdown

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;

Copy link
Copy Markdown

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) {

Copy link
Copy Markdown

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) {

Copy link
Copy Markdown

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);

Copy link
Copy Markdown

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];

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 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());

Copy link
Copy Markdown

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
Copy Markdown
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;

Copy link
Copy Markdown

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!

@maanyos maanyos 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.

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
Copy Markdown

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
Copy Markdown

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