[Ming Gao Rickie Li] iP#469
Conversation
Justinhoejj
left a comment
There was a problem hiding this comment.
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! 👍
| public class Deadline extends Task { | ||
|
|
||
| protected String by; | ||
| protected LocalDate date; |
There was a problem hiding this comment.
If these variables are not used in other parts of the code base consider changing the accessor to private.
| protected String by; | ||
| protected LocalDate date; |
There was a problem hiding this comment.
Consider declaring variables as final if the attributes are not expected to change.
| private Storage storage; | ||
| private Ui ui; | ||
| private String filePath; |
| protected String at; | ||
| protected LocalDate date; |
There was a problem hiding this comment.
Consider changing to private final.
| 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.
Consider using case switch. Additionally, consider implementing a general remove first word method that extracts the string before the first space.
| fileReader.close(); | ||
| } | ||
| } catch (IOException e) { | ||
| System.out.println("An error occurred."); |
There was a problem hiding this comment.
Consider specifying the type of error. eg. error loading tasks.
| System.out.println(separator); | ||
| System.out.println(" You have no tasks in your list!"); |
There was a problem hiding this comment.
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 .
| 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.
These lines of codes are used more than twice. Consider abstracting to a method to enhance ease of readability and maintainability.
| 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.
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.
Consider following the test method naming convention featureUnderTest_testScenario_expectedBehavior().
HolmesJJ
left a comment
There was a problem hiding this comment.
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. 😄
| package duke; | ||
| import java.time.LocalDate; | ||
| import java.time.format.DateTimeFormatter; | ||
| public class Deadline extends Task { |
There was a problem hiding this comment.
Perhaps need a descriptive header comments for the Parser class? 🤔
| protected String by; | ||
| protected LocalDate date; | ||
|
|
||
| public Deadline(String description, String by) { |
There was a problem hiding this comment.
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.
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.
Perhaps need a descriptive header comments for the Duke method? 🤔
And I noticed the same issue in several other places below.
| } | ||
|
|
||
| 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.
Should this be wrapped to next line? 🤔
| @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.
Perhaps need an empty line between description and parameter section? 🤔
| 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.
Perhaps need a descriptive header comments for the parserTest1 method? 🤔
And I noticed the same issue in several other places below.
| } | ||
|
|
||
| /** | ||
| * Returns updated user task list and prints feedback to the user based on their input |
There was a problem hiding this comment.
Perhaps need a full stop at the end? 🤔
| package duke; | ||
| public class Todo extends Task { | ||
|
|
||
| public Todo(String description) { |
There was a problem hiding this comment.
Perhaps need a descriptive header comments for the Todo method? 🤔
And I noticed the same issue in several other places below.
| protected String description; | ||
| protected boolean isDone; | ||
|
|
||
| public Task(String description) { |
There was a problem hiding this comment.
Perhaps need a descriptive header comments for the Task method? 🤔
And I noticed the same issue in several other places below.
|
|
||
| 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.
Consider using relative path instead of absolute path, incase project structure changes in the future
| @@ -0,0 +1,12 @@ | |||
| package duke; | |||
There was a problem hiding this comment.
Minor style issue here, but there should always be a new line after package statement
| System.out.println(String.format(" %d. %s", (i + 1), item.toString())); | ||
| } | ||
| } | ||
| } else if (parsedInput.equals("done")) { |
There was a problem hiding this comment.
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
ramapriyan912001
left a comment
There was a problem hiding this comment.
Great job overall!
Just some tweaks needed!
| import java.time.format.DateTimeFormatter; | ||
| public class Event extends Task { | ||
|
|
||
| protected String at; |
There was a problem hiding this comment.
"at" is perhaps not descriptive enough
| 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.
Some use of magic literals here.
| 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.
Well done, very neat, and handles commands of different cases!
| } else { | ||
| Event e = new Event(splitString[2], splitString[3]); | ||
| if (splitString[1].equals("1")) { | ||
| e.markAsDone(); |
There was a problem hiding this comment.
Could perhaps be SLAP-ed harder?
| * @param input user input | ||
| * @return updated task list | ||
| */ | ||
| public String run(Storage storage, String input) throws DukeException { |
There was a problem hiding this comment.
This method could be SLAP-ed harder perhaps?
| } | ||
| } | ||
|
|
||
| private String getDeleteTaskString(ArrayList<Task> list, String input, Storage storage) throws DukeException { |
| 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.
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,eventordeadlinecommandsBest of all, Duke is FREE
Features:
If you're a Java programmer, you can use it to practice Java too. Here's the
mainmethod: