-
Notifications
You must be signed in to change notification settings - Fork 315
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
base: master
Are you sure you want to change the base?
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.
src/main/java/Parser.java
Outdated
c = new DeleteCommand(Integer.parseInt(arr[1]) - 1); | ||
break; | ||
default: | ||
c = new AddCommand(arr); |
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.
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.
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."); |
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.
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. :)
src/main/java/AddCommand.java
Outdated
} | ||
} | ||
} else { | ||
throw new UnknownTaskException("☹ OOPS!!! I'm sorry, but I don't know what that means :-("); |
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.
It may be a little easier to have the message already in toString() method of UnknownTaskException :)
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); |
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.
Good idea! Another idea to split your string by "...".split("/by") instead so you would not need to care about the index:)
src/main/java/AddCommand.java
Outdated
String desc = description.substring(1, index - 1); | ||
t = new Deadline(desc, byWhen); | ||
} else { | ||
int index = description.indexOf("/"); |
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 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.
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()) { |
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.
Using Scanner is a good idea!
fw.write(textToAdd); | ||
fw.close(); | ||
} catch (IOException e) { | ||
System.out.println("File not found."); |
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 used some helper methods like updateText(int taskNum), deleteText(int taskNum) to help me execute 'done' , 'delete' and more commands. I would recommend that.
src/main/java/Ui.java
Outdated
} | ||
|
||
public String readCommand() { | ||
Scanner sc = new Scanner(System.in); |
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.
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.
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")); |
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 I ask why is the command DoneCommand(2) instead of DoneCommand(3) ? As the attribute name in constructor DoneCommand is called taskNum. Thank you!
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 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.
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.
src/main/java/AddCommand.java
Outdated
String desc = description.substring(1, index - 1); | ||
t = new Deadline(desc, byWhen); | ||
} else { | ||
int index = description.indexOf("/"); |
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.
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; | ||
} | ||
} | ||
} |
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 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.
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."); | ||
} |
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.
Nice attention to detail here. 👍
This reverts commit 615cda1.
# Conflicts: # src/main/java/Ui.java
public void testToString() { | ||
assertEquals("[T][\u2713] play basketball", new Todos("play basketball", true).toString()); | ||
} | ||
} |
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.
Very neat and well written code
No description provided.