[Sng Jia Ming Fadi Faris] Duke Increments#345
[Sng Jia Ming Fadi Faris] Duke Increments#345fadisng wants to merge 45 commits intonus-cs2103-AY1920S1:masterfrom
Conversation
Add toolVersion block in to Gradle code sample to prevent errors.
Change file mode on `gradle` to be executable (nus-cs2103-AY1920S1#9)
# Conflicts: # src/main/java/Parser.java
This reverts commit 9e36be2.
| c = new DeleteCommand(Integer.parseInt(arr[1]) - 1); | ||
| break; | ||
| default: | ||
| c = new AddCommand(arr); |
There was a problem hiding this comment.
It may be more easier to specify the deadline, description, whether it is done and other attributes inside the constructor of AddCommand, since the String input is already split.
| try { | ||
| if (next.equals("todo") || next.equals("deadline") || next.equals("event")) { | ||
| if (arr.length == 1) { | ||
| throw new EmptyDescriptionException("☹ OOPS!!! The description of a " + next + " cannot be empty."); |
There was a problem hiding this comment.
It may be a little easier to have the message already in toString() method of EmptyDescriptionException, so you only have take in the type as a parameter. E.g throw new EmptyDescriptionException("todo"). Since you will be throwing this exception frequently, you won't need to type the message everytime. :)
| } | ||
| } | ||
| } else { | ||
| throw new UnknownTaskException("☹ OOPS!!! I'm sorry, but I don't know what that means :-("); |
There was a problem hiding this comment.
It may be a little easier to have the message already in toString() method of UnknownTaskException :)
| t = new Todos(description.trim()); | ||
| } else if (next.equals("deadline")) { | ||
| int index = description.indexOf("/"); | ||
| String byWhen = description.substring(index + 4); |
There was a problem hiding this comment.
Good idea! Another idea to split your string by "...".split("/by") instead so you would not need to care about the index:)
| String desc = description.substring(1, index - 1); | ||
| t = new Deadline(desc, byWhen); | ||
| } else { | ||
| int index = description.indexOf("/"); |
There was a problem hiding this comment.
This is a smart idea! You can also split the string by "...".split("/at") so you would not need to count the index. :)
There was a problem hiding this comment.
Just to add on, if you use the indexOf("/"), this might not have the intended effect when you have a deadline task initialised with the following command as an example:
deadline todo/or not to do that is the question /by 12/12/12 12:12
You can split as @Joanna-YJA suggested, and check if there is more than 2 items in the resulting String array. From there you may proceed to throw the appropriate DukeExceptions.
| File f = new File(file); | ||
| Scanner sc = new Scanner(f); | ||
| Task t; | ||
| while (sc.hasNext()) { |
| fw.write(textToAdd); | ||
| fw.close(); | ||
| } catch (IOException e) { | ||
| System.out.println("File not found."); |
There was a problem hiding this comment.
I used some helper methods like updateText(int taskNum), deleteText(int taskNum) to help me execute 'done' , 'delete' and more commands. I would recommend that.
| } | ||
|
|
||
| public String readCommand() { | ||
| Scanner sc = new Scanner(System.in); |
There was a problem hiding this comment.
It may not be necessary to create a new Scanner object everytime readCommand() is called.
|
|
||
| public class ParserTest { | ||
| @Test | ||
| public void parseTest() { |
There was a problem hiding this comment.
I would recommend using this naming standard to name your test methods: featureUnderTest_testScenario_expectedBehavior()
| public class ParserTest { | ||
| @Test | ||
| public void parseTest() { | ||
| assertEquals(new DoneCommand(2), Parser.parse("done 3")); |
There was a problem hiding this comment.
Could I ask why is the command DoneCommand(2) instead of DoneCommand(3) ? As the attribute name in constructor DoneCommand is called taskNum. Thank you!
Q-gabe
left a comment
There was a problem hiding this comment.
I think you did a good job! Aside from some possible bugs that may be missed in terms of parsing the input and other more graceful methods of implementation, it looks pretty solid. LGTM!
| */ | ||
|
|
||
| import java.text.ParseException; | ||
|
|
There was a problem hiding this comment.
I think it's custom to have the class's javadoc comments to be directly above the declaration of the class, after any relevant import statements.
| String desc = description.substring(1, index - 1); | ||
| t = new Deadline(desc, byWhen); | ||
| } else { | ||
| int index = description.indexOf("/"); |
There was a problem hiding this comment.
Just to add on, if you use the indexOf("/"), this might not have the intended effect when you have a deadline task initialised with the following command as an example:
deadline todo/or not to do that is the question /by 12/12/12 12:12
You can split as @Joanna-YJA suggested, and check if there is more than 2 items in the resulting String array. From there you may proceed to throw the appropriate DukeExceptions.
| return "D @ 0 @ " + this.description + " @ " + this.by; | ||
| } | ||
| } | ||
| } No newline at end of file |
There was a problem hiding this comment.
Consider adding newlines at the end of your files, as it is a general convention. It doesn't really cause any issues beside making GitHub and checkstyle whine, but there is a reason behind doing so, https://stackoverflow.com/questions/729692/why-should-text-files-end-with-a-newline. Hope this gives some insight!
| /** | ||
| * Rewrites the file with the new arraylist of tasks. | ||
| * @param list arraylist of tasks that are updated after every command given to Duke. | ||
| */ |
There was a problem hiding this comment.
Perhaps it may be a more computationally-efficient approach to have writeFile run the moment an exit command runs as the purpose of storage is only for data-permanence through starting and exiting Duke. We need not actually track every manipulation of the task list with every command. 😉
| System.out.println(" " + t + "\nNow you have " + count + " task in the list."); | ||
| } else { | ||
| System.out.println(" " + t + "\nNow you have " + count + " tasks in the list."); | ||
| } |
This reverts commit 615cda1.
# Conflicts: # src/main/java/Ui.java
| public void testToString() { | ||
| assertEquals("[T][\u2713] play basketball", new Todos("play basketball", true).toString()); | ||
| } | ||
| } No newline at end of file |
No description provided.