Skip to content

[Sng Jia Ming Fadi Faris] Duke Increments#345

Open
fadisng wants to merge 45 commits intonus-cs2103-AY1920S1:masterfrom
fadisng:master
Open

[Sng Jia Ming Fadi Faris] Duke Increments#345
fadisng wants to merge 45 commits intonus-cs2103-AY1920S1:masterfrom
fadisng:master

Conversation

@fadisng
Copy link
Copy Markdown

@fadisng fadisng commented Sep 2, 2019

No description provided.

Comment thread src/main/java/Parser.java Outdated
c = new DeleteCommand(Integer.parseInt(arr[1]) - 1);
break;
default:
c = new AddCommand(arr);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread src/main/java/AddCommand.java Outdated
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.");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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. :)

Comment thread src/main/java/AddCommand.java Outdated
}
}
} else {
throw new UnknownTaskException("☹ OOPS!!! I'm sorry, but I don't know what that means :-(");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It may be a little easier to have the message already in toString() method of UnknownTaskException :)

Comment thread src/main/java/AddCommand.java Outdated
t = new Todos(description.trim());
} else if (next.equals("deadline")) {
int index = description.indexOf("/");
String byWhen = description.substring(index + 4);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good idea! Another idea to split your string by "...".split("/by") instead so you would not need to care about the index:)

Comment thread src/main/java/AddCommand.java Outdated
String desc = description.substring(1, index - 1);
t = new Deadline(desc, byWhen);
} else {
int index = description.indexOf("/");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is a smart idea! You can also split the string by "...".split("/at") so you would not need to count the index. :)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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()) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Using Scanner is a good idea!

fw.write(textToAdd);
fw.close();
} catch (IOException e) {
System.out.println("File not found.");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread src/main/java/Ui.java Outdated
}

public String readCommand() {
Scanner sc = new Scanner(System.in);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It may not be necessary to create a new Scanner object everytime readCommand() is called.


public class ParserTest {
@Test
public void parseTest() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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"));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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!

Copy link
Copy Markdown

@Q-gabe Q-gabe left a comment

Choose a reason for hiding this comment

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

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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread src/main/java/AddCommand.java Outdated
String desc = description.substring(1, index - 1);
t = new Deadline(desc, byWhen);
} else {
int index = description.indexOf("/");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.
*/
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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. 😉

Comment thread src/main/java/Ui.java
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.");
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice attention to detail here. 👍

public void testToString() {
assertEquals("[T][\u2713] play basketball", new Todos("play basketball", true).toString());
}
} No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Very neat and well written code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants