-
Notifications
You must be signed in to change notification settings - Fork 364
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
base: master
Are you sure you want to change the base?
[Wesley Teo] iP #214
Conversation
…ine.java. Separated queries in to Query.java
… tasks or invalid commands
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.
LGTM. Just some nits to fix.
src/main/java/duke/Storage.java
Outdated
|
||
import duke.task.*; | ||
|
||
import java.io.*; |
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.
Please list imported classes explicitly.
|
||
public void run() { | ||
ui.showWelcomeMessage(); | ||
boolean isExit = false; |
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.
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"); |
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.
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'; |
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.
Would it be better to include the symbol 'T' inside the super()?
src/main/java/duke/Query.java
Outdated
return QueryType.exit; | ||
} | ||
String[] inputArr = input.split(" "); | ||
if (inputArr.length == 2 && isNumeric(inputArr[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.
Job well done on avoiding arrowhead style of code.
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.
Overall really good code, super easy to follow and understand 👍
Only minor formatting may be needed and your code becomes even better than before!
src/main/java/duke/Parser.java
Outdated
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(); |
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.
Maybe you would like to add a break statement or fallthrough comment after each case to improve code reading?
src/main/java/duke/Query.java
Outdated
} | ||
|
||
static boolean isNumeric(String str) { | ||
char[] charArray = str.toCharArray(); |
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.
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?
src/main/java/duke/Query.java
Outdated
} else if (input.equals("bye")) { | ||
return QueryType.exit; | ||
} | ||
String[] inputArr = input.split(" "); |
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 use a plural variable name here to represent collection of String?
src/main/java/duke/Storage.java
Outdated
public class Storage { | ||
protected File file; | ||
|
||
public Storage(String fileInput) throws DukeException{ |
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.
Probably you have missed this out, but maybe you would want to have a space between DukeException and the bracket.
public Storage(String fileInput) throws DukeException{ | |
public Storage(String fileInput) throws DukeException { |
src/main/java/duke/Storage.java
Outdated
Files.createDirectories(Paths.get(file.getParent())); | ||
this.file = Files.createFile(Path.of(fileInput)).toFile(); | ||
} | ||
} catch (IOException err){ |
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.
Probably you have missed this out, but maybe you would want to have a space between the catch exception and the bracket.
} catch (IOException err){ | |
} catch (IOException err) { |
import duke.task.TaskList; | ||
|
||
public class DeleteCommand extends Command { | ||
private final int index; |
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.
Maybe you would like to use full caps to represent index, since its a constant?
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.
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!
src/main/java/duke/Parser.java
Outdated
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(); |
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.
Neat! An example of good code quality!
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() + ")"); | ||
} | ||
} | ||
} | ||
} |
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.
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?
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() + ")"); | ||
} | ||
} | ||
} | ||
} |
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.
This method is also quite long and deeply nested! Try abstracting the code out!
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)); |
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.
Seems like it's not following SLAP, but I personally don't think it's a big issue here.
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)); | ||
} |
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.
Doesn't seem like it's following SLAP too, but I personally don't think it's a big issue too.
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.
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.
Duke Chatbot
With Duke Chatbot, you'll be able to easily track your tasks and events! Have more time for yourself and for CS2106!
Duke is:
To get started:
java -jar Duke.jar
(Ensure you have java installed on your computer!)Features:
If you are a Java programmer, you can use it to practice Java too. Here's the main method: