Skip to content
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

[Sng Jia Ming Fadi Faris] Duke Increments #345

Open
wants to merge 45 commits into
base: master
Choose a base branch
from

Conversation

fadisng
Copy link

@fadisng fadisng commented Sep 2, 2019

No description provided.

c = new DeleteCommand(Integer.parseInt(arr[1]) - 1);
break;
default:
c = new AddCommand(arr);

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.

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.");

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

}
}
} else {
throw new UnknownTaskException("☹ OOPS!!! I'm sorry, but I don't know what that means :-(");

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

t = new Todos(description.trim());
} else if (next.equals("deadline")) {
int index = description.indexOf("/");
String byWhen = description.substring(index + 4);

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

String desc = description.substring(1, index - 1);
t = new Deadline(desc, byWhen);
} else {
int index = description.indexOf("/");

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

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()) {

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.");

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.

}

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

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() {

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"));

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

@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

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.

String desc = description.substring(1, index - 1);
t = new Deadline(desc, byWhen);
} else {
int index = description.indexOf("/");
Copy link

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;
}
}
}
Copy link

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

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

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

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());
}
}

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