-
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
[Michelle] Duke Increments #482
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)
Gradle defaults to an empty stdin which results in runtime exceptions when attempting to read from `System.in`. Let's add some sensible defaults for students who may still need to work with the standard input stream.
Add configuration for console applications
src/main/java/Duke.java
Outdated
String command = parser.getCommand(commandArr); | ||
if (command.equals("todo")) { | ||
try { | ||
if (text.length() <= 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 guard clause!
src/main/java/Duke.java
Outdated
String text = parser.nextCommand(); | ||
String[] commandArr = parser.breakDownCommand(text); | ||
String command = parser.getCommand(commandArr); | ||
if (command.equals("todo")) { |
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.
Maybe you can try to abstract out the handler methods, and make use of switch
?
src/main/java/Duke.java
Outdated
} else if (command.equals("deadline")) { | ||
try { | ||
if (text.length() <= 8) { | ||
throw new DukeException(); |
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.
Shall we consider specifying the error occurred here?
src/main/java/Duke.java
Outdated
} | ||
} else if (command.equals("deadline")) { | ||
try { | ||
if (text.length() <= 8) { |
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.
Maybe avoid using magic number here. Instead, you could use command.split(" ")[0].equals("deadline")
.
src/main/java/Duke.java
Outdated
ui.printTaskAdded(deadline, taskList.getSize()); | ||
storage.appendTaskToFile(deadline); | ||
} catch (DukeException e) { | ||
ui.printDeadlineError(); |
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.
Try adding in the error message inside the DukeException
class, and just call e.printMessage
. Same for the rest of the code.
src/main/java/Parser.java
Outdated
* @return The todo. | ||
*/ | ||
public Todo getTodo(String line) { | ||
String task = line.substring(5); |
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.
Since you have already split the command by breakDownCommand
, maybe try making use of that abstraction?
* @return The task in a string format. | ||
*/ | ||
private String convertTaskToFileFormat(Task task) { | ||
StringBuffer textToAdd = new StringBuffer(); |
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 use of StringBuffer
to avoid extra overhead.
* @param list The list of tasks to be updated to the file. | ||
* @throws IOException If an input or output exception occurred. | ||
*/ | ||
public void updateTaskInFile(ArrayList<Task> list) throws IOException { |
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.
Try using List
instead of ArrayList
, as programming to interface is a good practice.
* Contains the task list and updates tasks in the list. | ||
*/ | ||
public class TaskList { | ||
ArrayList<Task> list = new ArrayList<Task>(); |
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 should be done in the class constructor.
* commit '70fca0a3806f662f70821dbcbd7b57c4765aa2c1': Set theme jekyll-theme-cayman
No description provided.