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

[Wesley Teo] iP #214

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

[Wesley Teo] iP #214

wants to merge 38 commits into from

Conversation

Bisceto
Copy link

@Bisceto Bisceto commented Jan 25, 2023

Duke Chatbot

It is only when one goes through CS2103T, does a man truly know the value of time.

With Duke Chatbot, you'll be able to easily track your tasks and events! Have more time for yourself and for CS2106!

Duke is:

  • A text-based management system
  • Easy to learn
  • Intuitive to use

To get started:

  1. Download the latest release from here.
  2. Navigate to the folder using a terminal
  3. Run java -jar Duke.jar (Ensure you have java installed on your computer!)
  4. Get crazy and get productive! 🥇

Features:

  • [x]Managing tasks
  • [x]Managing deadlines
  • [ ]Reminders
    If you are a Java programmer, you can use it to practice Java too. Here's the main method:
public static void main(String[] args) {
        new Duke("../../../data/duke.txt").run();
  }

Copy link

@SeanChinJunKai SeanChinJunKai left a comment

Choose a reason for hiding this comment

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

LGTM. Just some nits to fix.


import duke.task.*;

import java.io.*;

Choose a reason for hiding this comment

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

Please list imported classes explicitly.


public void run() {
ui.showWelcomeMessage();
boolean isExit = false;

Choose a reason for hiding this comment

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

The boolean variable isExit explains the named entity to the reader accurately and at a sufficient level of detail.

protected LocalDateTime startTime;
protected LocalDateTime endTime;
protected DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm");
protected DateTimeFormatter displayFormatter = DateTimeFormatter.ofPattern("MMM dd yyyy HHmm");

Choose a reason for hiding this comment

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

Would it be good to leave an empty line between the variables and methods?


public Todo(String input, boolean isDone) {
super(input, isDone);
this.symbol = 'T';

Choose a reason for hiding this comment

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

Would it be better to include the symbol 'T' inside the super()?

return QueryType.exit;
}
String[] inputArr = input.split(" ");
if (inputArr.length == 2 && isNumeric(inputArr[1])) {

Choose a reason for hiding this comment

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

Job well done on avoiding arrowhead style of code.

Copy link

@nus-jeff nus-jeff left a comment

Choose a reason for hiding this comment

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

Overall really good code, super easy to follow and understand 👍
Only minor formatting may be needed and your code becomes even better than before!

Comment on lines 39 to 57
case list:
return new ListCommand();
case todo:
Todo todo = new Todo(fullCommand);
return new AddCommand(todo);
case deadline:
Deadline deadline = new Deadline(fullCommand);
return new AddCommand(deadline);
case event:
Event event = new Event(fullCommand);
return new AddCommand(event);
case mark:
return new MarkCommand(Integer.parseInt(fullCommandArr[1]));
case unmark:
return new UnmarkCommand(Integer.parseInt(fullCommandArr[1]));
case delete:
return new DeleteCommand(Integer.parseInt(fullCommandArr[1]));
case exit:
return new ExitCommand();
Copy link

Choose a reason for hiding this comment

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

Maybe you would like to add a break statement or fallthrough comment after each case to improve code reading?

}

static boolean isNumeric(String str) {
char[] charArray = str.toCharArray();
Copy link

Choose a reason for hiding this comment

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

Nice that you placed the array sign with the variable type 👍 , perhaps you could use a plural variable name here to represent collection of chars?

} else if (input.equals("bye")) {
return QueryType.exit;
}
String[] inputArr = input.split(" ");
Copy link

Choose a reason for hiding this comment

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

Perhaps you could use a plural variable name here to represent collection of String?

public class Storage {
protected File file;

public Storage(String fileInput) throws DukeException{
Copy link

Choose a reason for hiding this comment

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

Probably you have missed this out, but maybe you would want to have a space between DukeException and the bracket.

Suggested change
public Storage(String fileInput) throws DukeException{
public Storage(String fileInput) throws DukeException {

Files.createDirectories(Paths.get(file.getParent()));
this.file = Files.createFile(Path.of(fileInput)).toFile();
}
} catch (IOException err){
Copy link

Choose a reason for hiding this comment

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

Probably you have missed this out, but maybe you would want to have a space between the catch exception and the bracket.

Suggested change
} catch (IOException err){
} catch (IOException err) {

import duke.task.TaskList;

public class DeleteCommand extends Command {
private final int index;
Copy link

Choose a reason for hiding this comment

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

Maybe you would like to use full caps to represent index, since its a constant?

Copy link

@pangrwa pangrwa left a comment

Choose a reason for hiding this comment

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

Overall, your code is great. Generally follows the SLAP principle except for some of the tasks files. Some methods have arrow-head style code too!

Comment on lines 57 to 80
switch (inputType) {
case list:
return new ListCommand();
case todo:
Todo todo = new Todo(fullCommand);
return new AddCommand(todo);
case deadline:
Deadline deadline = new Deadline(fullCommand);
return new AddCommand(deadline);
case event:
Event event = new Event(fullCommand);
return new AddCommand(event);
case find:
return new FindCommand(fullCommandArr[1]);
case mark:
return new MarkCommand(Integer.parseInt(fullCommandArr[1]));
case unmark:
return new UnmarkCommand(Integer.parseInt(fullCommandArr[1]));
case delete:
return new DeleteCommand(Integer.parseInt(fullCommandArr[1]));
case exit:
return new ExitCommand();
default:
return new InvalidCommand();
Copy link

Choose a reason for hiding this comment

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

Neat! An example of good code quality!

Comment on lines 17 to 34
public void execute(TaskList taskList, Ui ui, Storage storage) throws DukeException {
ArrayList<Task> foundTasks = taskList.findTasks(this.InputToSearch);
if (foundTasks.size() == 0) {
ui.showMessage("We could not find any matching tasks.");
} else {
ui.showMessage("Here are the matching tasks in your list: ");
for (Task foundTask : foundTasks) {
if (foundTask instanceof Todo) {
ui.showMessage(foundTasks.indexOf(foundTask) + 1 + ". [" + foundTask.getSymbol() + "] "
+ "[" + foundTask.getStatusIcon() + "] " + foundTask.getDescription());
} else {
ui.showMessage(foundTasks.indexOf(foundTask) + 1 + ". [" + foundTask.getSymbol() + "] "
+ "[" + foundTask.getStatusIcon() + "] " + foundTask.getDescription()
+ " (" + foundTask.getDuedateString() + ")");
}
}
}
}
Copy link

Choose a reason for hiding this comment

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

Seems like an arrow-head style code, maybe perhaps the method is too long and too deeply nested. Maybe try abstracting some of the code into another method?

Comment on lines 10 to 26
public void execute(TaskList taskList, Ui ui, Storage storage) {
if (taskList.getNumTasks() == 0) {
ui.showMessage("You have no tasks due!");
} else {
ui.showMessage("Here are the tasks you have due!");
for (Task cur : taskList.getTasks()) {
if (cur instanceof Todo) {
ui.showMessage(taskList.getTasks().indexOf(cur) + 1 + ". [" + cur.getSymbol() + "] "
+ "[" + cur.getStatusIcon() + "] " + cur.getDescription());
} else {
ui.showMessage(taskList.getTasks().indexOf(cur) + 1 + ". [" + cur.getSymbol() + "] "
+ "[" + cur.getStatusIcon() + "] " + cur.getDescription()
+ " (" + cur.getDuedateString() + ")");
}
}
}
}
Copy link

Choose a reason for hiding this comment

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

This method is also quite long and deeply nested! Try abstracting the code out!

Comment on lines 21 to 28
public Deadline(String input, boolean isDone) {
super(input, isDone);
this.symbol = 'D';
String[] temp = input.split(",");
this.description = temp[0];
LocalDate inputFormatter = LocalDate.parse(temp[1]);
this.duedate = inputFormatter;
this.duedateString = inputFormatter.format(DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG));
Copy link

Choose a reason for hiding this comment

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

Seems like it's not following SLAP, but I personally don't think it's a big issue here.

Comment on lines 36 to 51
public Deadline(String input) throws DukeException {
super(input);
this.symbol = 'D';
String[] inputArr = input.split(" ", 2); //split 'deadline' from task input
if (inputArr.length == 1 || inputArr[1].isBlank()) {
throw new DukeException("Sorry, the description of a deadline cannot be empty!");
}
String[] descriptionArr = inputArr[1].split("/"); //split task from due date
if (descriptionArr.length == 1 || descriptionArr[0].isEmpty()) {
throw new DukeException("Please include a description or a deadline in the following format: '/yyyy-MM-dd'");
}
this.description = descriptionArr[0];
LocalDate inputFormatter = Parser.parseDate(descriptionArr[1]);
this.duedate = inputFormatter;
this.duedateString = inputFormatter.format(DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG));
}
Copy link

Choose a reason for hiding this comment

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

Doesn't seem like it's following SLAP too, but I personally don't think it's a big issue too.

Bisceto and others added 3 commits February 10, 2023 00:44
Assertions should be used liberally for testing to spot potential bugs quickly

Let's add assertions,
* To Duke.java to ensure that file text is loaded for loading and savings tasks.
* To AddCommand.java to ensure that task is successfully in task list
* To DeleteCommand.java to ensure that task is successfully removed from task list
* To TaskList.java to ensure that commands are successfully marked and unmarked.
No assertions are utilised in the codebase.
Bisceto and others added 11 commits February 15, 2023 11:30
Let's rectify these comments by updating their methods.
Let's remove the QueryType class to fit into the Query class
Some Command methods were unnecessarily long and cluttered.
Find functionality is case sensitive, and only matches to tasks description.

A case insensitive find is more user-friendly because users cannot be expected to remember exact case of keywords.
A find feature that matches dates is more user-friendly for users to see what events and deadlines they have on that day.

Let's,
* update the search algorithm to use case-insensitive matching
* update the search algorithm to match dates in the form <yyyy-MM-dd> or <MMM dd yyyy>
Find command: make matching case insensitive and matches to dates
Find Command contains bugs when keying in dates of different formats.

Let's,
* Update the find command so that it can take in dates <yyyy-MM-dd> or <MMM-dd-yyyy>
Added user guide for Duke chatbot, mainly the list of features that can be used as well as their formats.
…is out of bounds.

Let's,
Fix the error handling for above methods to accommodate out of bounds input.
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.

None yet

4 participants