-
Notifications
You must be signed in to change notification settings - Fork 454
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
[Ming Gao Rickie Li] iP #469
base: master
Are you sure you want to change the base?
Conversation
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.
Hey, code looks acceptable to me. Gave some comments on how you could further abstract some methods, hope that will help in improving the code quality. Do note the naming of test methods as well. Otherwise good job on the project! 👍
src/main/java/duke/Deadline.java
Outdated
public class Deadline extends Task { | ||
|
||
protected String by; | ||
protected LocalDate date; |
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.
If these variables are not used in other parts of the code base consider changing the accessor to private.
src/main/java/duke/Deadline.java
Outdated
protected String by; | ||
protected LocalDate date; |
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.
Consider declaring variables as final if the attributes are not expected to change.
src/main/java/duke/Duke.java
Outdated
private Storage storage; | ||
private Ui ui; | ||
private String filePath; |
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.
Consider declaring as final.
src/main/java/duke/Event.java
Outdated
protected String at; | ||
protected LocalDate date; |
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.
Consider changing to private final.
src/main/java/duke/Parser.java
Outdated
if (input.replaceAll("\\s","").toLowerCase().equals("bye")) { | ||
return "bye"; | ||
} else if (inputLower.replaceAll("\\s", "").equals("list")) { | ||
return "list"; | ||
} else if (inputLower.length() > 3 && inputLower.substring(0, 4).equals("done")) { | ||
return "done"; | ||
} else if (inputLower.length() > 5 && inputLower.substring(0, 6).equals("delete")) { | ||
return "delete"; | ||
} else if (inputLower.length() >= 4 && inputLower.substring(0, 4).equals("todo")) { | ||
return "todo"; | ||
} else if (inputLower.length() >= 5 && inputLower.substring(0, 5).equals("event")) { | ||
return "event"; | ||
} else if (inputLower.length() >= 8 && inputLower.substring(0, 8).equals("deadline")) { | ||
return "deadline"; | ||
} else if (inputLower.length() >=4 && inputLower.substring(0, 4).equals("find")) { | ||
return "find"; | ||
} else { | ||
return "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.
Consider using case switch. Additionally, consider implementing a general remove first word method that extracts the string before the first space.
src/main/java/duke/Storage.java
Outdated
fileReader.close(); | ||
} | ||
} catch (IOException e) { | ||
System.out.println("An error occurred."); |
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.
Consider specifying the type of error. eg. error loading tasks.
src/main/java/duke/Ui.java
Outdated
System.out.println(separator); | ||
System.out.println(" You have no tasks in your list!"); |
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.
A UI component that can be abstracted to a generic method to format responses. Since these lines of code are used extensively in the run method, abstracting the method will reduce code re-write .
src/main/java/duke/Ui.java
Outdated
System.out.println(" ____________________________________________________________"); | ||
System.out.println(" Got it. I've added this task:"); | ||
System.out.println(" " + t.toString()); | ||
System.out.println(String.format(" Now you have %d tasks in the list.", list.size())); |
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.
These lines of codes are used more than twice. Consider abstracting to a method to enhance ease of readability and maintainability.
src/main/java/duke/Ui.java
Outdated
Task t = list.get(i); | ||
if (list.get(i).description.toLowerCase().contains(query)) { | ||
tasksContainingQuery.add(t); | ||
} | ||
} | ||
if (tasksContainingQuery.size() == 0) { |
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.
Logic here involves the task list. It may be more appropriate to extract into a method in a task list class. Ideally UI takes string from user to pass to pass to parser and takes string from duke and prints, since the UI is an interface between duke and user. All other logic can be defined in other classes.
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class DukeTest { |
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.
Consider following the test method naming convention featureUnderTest_testScenario_expectedBehavior()
.
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.
I like your clear code and it is esay to understand. 👍 Perhaps more comments for the class and method will be much easier to understand. 😄
src/main/java/duke/Deadline.java
Outdated
package duke; | ||
import java.time.LocalDate; | ||
import java.time.format.DateTimeFormatter; | ||
public class Deadline extends Task { |
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 need a descriptive header comments for the Parser class? 🤔
src/main/java/duke/Deadline.java
Outdated
protected String by; | ||
protected LocalDate date; | ||
|
||
public Deadline(String description, String by) { |
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 need a descriptive header comments for the Deadline method? 🤔
And I noticed the same issue in several other places below.
|
||
import java.util.Scanner; | ||
|
||
public class Duke { |
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 need a descriptive header comments for the Duke class? 🤔
private Ui ui; | ||
private String filePath; | ||
|
||
public Duke(String filePath) { |
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 need a descriptive header comments for the Duke method? 🤔
And I noticed the same issue in several other places below.
src/main/java/duke/Duke.java
Outdated
} | ||
|
||
public static void main(String[] args) { | ||
new Duke("C:\\Users\\Rickie\\Documents\\University\\Year 2\\Semester 1\\CS2103T\\ip\\Data\\taskList.txt").run(); |
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.
Should this be wrapped to next line? 🤔
src/test/java/DukeTest.java
Outdated
@Test | ||
public void uiWelcomeTest() { | ||
String separator = " ____________________________________________________________"; | ||
String message = separator + "\n" + " Hello! I'm Duke" + "\n" + " What can I do for you?" + "\n" + separator; |
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 need an empty line between description and parameter section? 🤔
src/test/java/DukeTest.java
Outdated
Duke duke = new Duke("C:\\Users\\Rickie\\Documents\\University\\Year 2\\Semester 1\\CS2103T\\ip\\Data\\taskList.txt"); | ||
|
||
@Test | ||
public void parserTest1() { |
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 need a descriptive header comments for the parserTest1 method? 🤔
And I noticed the same issue in several other places below.
src/main/java/duke/Ui.java
Outdated
} | ||
|
||
/** | ||
* Returns updated user task list and prints feedback to the user based on their input |
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 need a full stop at the end? 🤔
src/main/java/duke/Todo.java
Outdated
package duke; | ||
public class Todo extends Task { | ||
|
||
public Todo(String description) { |
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 need a descriptive header comments for the Todo method? 🤔
And I noticed the same issue in several other places below.
src/main/java/duke/Task.java
Outdated
protected String description; | ||
protected boolean isDone; | ||
|
||
public Task(String description) { |
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 need a descriptive header comments for the Task method? 🤔
And I noticed the same issue in several other places below.
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!
src/test/java/DukeTest.java
Outdated
|
||
public class DukeTest { | ||
|
||
Duke duke = new Duke("C:\\Users\\Rickie\\Documents\\University\\Year 2\\Semester 1\\CS2103T\\week 2\\ip\\Data\\taskList.txt"); |
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.
Consider using relative path instead of absolute path, incase project structure changes in the future
src/main/java/duke/Todo.java
Outdated
@@ -0,0 +1,12 @@ | |||
package duke; |
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.
Minor style issue here, but there should always be a new line after package statement
src/main/java/duke/Ui.java
Outdated
System.out.println(String.format(" %d. %s", (i + 1), item.toString())); | ||
} | ||
} | ||
} else if (parsedInput.equals("done")) { |
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 the throwing of exceptions should be done in the Parser rather than Ui handler, since the parser handles valid and invalid input
There is no code in place to indicate possible bugs. Assertion statements have been added to Duke class to ensure user input and program output are not null. The impact of assertions on performance is low and provides a safety net to ensure the user input and program output are as expected.
Branch A-Assertions
The code needs to be more readable and abstract. Further abstracting code has made the code easier to read and follow along. Abstracting shortens method length and good naming of abstracted methods allow for more readable code.
Code quality is not great.
added update function
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.
Great job overall!
Just some tweaks needed!
src/main/java/duke/Event.java
Outdated
import java.time.format.DateTimeFormatter; | ||
public class Event extends Task { | ||
|
||
protected String at; |
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.
"at" is perhaps not descriptive enough
src/main/java/duke/Event.java
Outdated
if (this.date != null) { | ||
return "[E]" + super.toString() + " (at: " | ||
+ this.date.format(DateTimeFormatter.ofPattern("MMM d yyyy")) + ")"; | ||
} else { | ||
return "[E]" + super.toString() + " (at: " + this.at + ")"; |
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.
Some use of magic literals here.
src/main/java/duke/Parser.java
Outdated
public static String parse(String input) { | ||
String inputLower = input.toLowerCase(); | ||
if (input.replaceAll("\\s", "").toLowerCase().equals("bye")) { | ||
return "bye"; | ||
} else if (inputLower.replaceAll("\\s", "").equals("list")) { | ||
return "list"; | ||
} else if (inputLower.length() > 3 && inputLower.substring(0, 4).equals("done")) { | ||
return "done"; | ||
} else if (inputLower.length() > 5 && inputLower.substring(0, 6).equals("delete")) { | ||
return "delete"; | ||
} else if (inputLower.length() >= 4 && inputLower.substring(0, 4).equals("todo")) { | ||
return "todo"; | ||
} else if (inputLower.length() >= 5 && inputLower.substring(0, 5).equals("event")) { | ||
return "event"; | ||
} else if (inputLower.length() >= 8 && inputLower.substring(0, 8).equals("deadline")) { | ||
return "deadline"; | ||
} else if (inputLower.length() >= 4 && inputLower.substring(0, 4).equals("find")) { | ||
return "find"; | ||
} else if (inputLower.length() >= 6 && inputLower.substring(0, 6).equals("update")) { | ||
return "update"; | ||
} else { | ||
return "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.
Well done, very neat, and handles commands of different cases!
src/main/java/duke/Storage.java
Outdated
} else { | ||
Event e = new Event(splitString[2], splitString[3]); | ||
if (splitString[1].equals("1")) { | ||
e.markAsDone(); |
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.
Could perhaps be SLAP-ed harder?
src/main/java/duke/Ui.java
Outdated
* @param input user input | ||
* @return updated task list | ||
*/ | ||
public String run(Storage storage, String input) 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.
This method could be SLAP-ed harder perhaps?
src/main/java/duke/Ui.java
Outdated
} | ||
} | ||
|
||
private String getDeleteTaskString(ArrayList<Task> list, String input, Storage storage) 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.
Well modularised! Great job!
2. [T][ ] read book | ||
3. [D][X] return book (by: Sunday) | ||
4. [E][ ] project meeting (at: Monday 2-4pm) | ||
____________________________________________________________ |
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 line separation definitely helps. Good job!
Duke
Duke frees your mind of having to remember things you need to do. It's,
All you need to do is,
todo
,event
ordeadline
commandsBest of all, Duke is FREE
Features:
If you're a Java programmer, you can use it to practice Java too. Here's the
main
method: