-
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
[Caesar Pang] Duke Increments #350
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)
…Cleaned up my code more.
# Conflicts: # src/main/java/Duke.class # src/main/java/Duke.java # src/main/java/Task.class # src/main/java/Task.java Have completed all merge conflicts. This is the final draft for lvl 7 and lvl 8.
…only halfway done.
# Conflicts: # src/main/java/Event.class # src/main/java/Event.java # src/main/java/Storage.java # src/main/java/Task.class # src/main/java/TaskList.class # src/main/java/Todo.class # src/main/java/Todo.java
# Conflicts: # src/main/java/Ui.class
src/main/java/Duke.java
Outdated
/** | ||
* Main method. | ||
*/ | ||
public static void main(String[] args) 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.
I think this is a bad practice. You should probably catch the IOException somewhere within your code, rather than just throw
ing it from your main
method.
src/main/java/Event.java
Outdated
*/ | ||
@Override | ||
public String toString() { | ||
String date = formatDate(when); |
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.
You may want to consider storing this formatted date as a variable, so you don't have to keep converting it all the time.
src/main/java/Storage.java
Outdated
protected static ArrayList<Task> taskList = new ArrayList<Task>(); | ||
protected static String file = "todo.txt"; | ||
|
||
public Storage(String file) { |
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.
You should consider removing this parameter, since it doesn't seem to do anything.
src/main/java/Storage.java
Outdated
protected static ArrayList<Task> taskList = new ArrayList<Task>(); | ||
protected static String file = "todo.txt"; | ||
|
||
public Storage(String file) { |
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.
You should consider removing this parameter, since it doesn't seem to do anything.
src/main/java/Storage.java
Outdated
*/ | ||
public void addToFile(String filepath, String textToAdd) throws IOException { | ||
FileWriter typer = new FileWriter(filepath, true); | ||
typer.write(textToAdd + System.lineSeparator()); |
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.
Have to say that I didn't know about this System.lineSeparator()
function. Looks like it might be useful for a cross-platform application. Good job 👍👍
src/main/java/Storage.java
Outdated
*/ | ||
public static int countLines(String filename) throws IOException { | ||
try (InputStream inputs = new BufferedInputStream(new FileInputStream(filename))) { | ||
byte[] characters = new byte[1024]; |
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 curious, is there a reason you chose to use byte
rather than char
?
src/main/java/TaskList.java
Outdated
* does not exist but cannot be created, or cannot be opened for any other reason. | ||
*/ | ||
public void deleteCommand(String text) throws IOException { | ||
int num = text.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.
Maybe this variable can be named better?
Overall, I think you did a great job with the documentation. I didn't notice any |
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.
Your code is very well-documented 👍
As mentioned, I think it would be a good idea to abstract out parsing-related functionality to the Parser class.
On another note, your printed messages were interesting and useful 😄
Implementing more tests would prevent regressions from being introduced in the future too!
src/main/java/Storage.java
Outdated
int index = task.indexOf("["); | ||
String taskType = task.substring(index + 1, index + 2); | ||
int spaceIndex = task.indexOf(" "); | ||
switch (taskType) { |
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.
There's a specific convention to follow for switch statements! https://nus-cs2103-ay1920s1.github.io/website/coding-standards/java/intermediate.html
src/main/java/TaskList.java
Outdated
@@ -0,0 +1,167 @@ | |||
import java.io.IOException; | |||
import java.sql.SQLOutput; |
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 seems like an unused import.
src/main/java/TaskList.java
Outdated
* @throws IOException If the named file exists but is a directory rather than a regular file, | ||
* does not exist but cannot be created, or cannot be opened for any other reason. | ||
*/ | ||
public void eventCommand(String text) throws DukeException, 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.
I think the parsing of the String should be moved to the Parser class, the TaskList class should be concerned with the operations on the list itself.
src/main/java/TaskList.java
Outdated
* @throws IOException If the named file exists but is a directory rather than a regular file, | ||
* does not exist but cannot be created, or cannot be opened for any other reason. | ||
*/ | ||
public void deadlineCommand(String text) throws DukeException, 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.
Similar to eventCommand
, the parsing can be abstracted out to the Parser class.
src/main/java/Ui.java
Outdated
* command based on the input. Prints out error messages as well. | ||
*/ | ||
public void nextCommand() { | ||
while (scan.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.
I think we should try to use the Parser class you have created to parse the input first! This way we can abstract out the parsing functions and so the UI class can just be concerned with the UI tasks.
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.
Hi! You might want to clean up your repository by avoiding pushing your class files or just do a repository refactor. Overall, great effort but you might want to do more javadocs and documentation because it was a bit hard to understand the intention behind your code :)
src/main/java/Command.java
Outdated
@@ -0,0 +1,15 @@ | |||
public class Command { |
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 feel that this is a plausible solution but you might want to consider abstract classes as a more efficient way of inheritance for all your other command sub-classes.
src/main/java/Command.java
Outdated
|
||
public String nextCommand(String input) { | ||
String text = input; | ||
switch () |
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.
Missing documentation and code looks incomplete. Missing a return statement as well. I'm guessing what you're trying to do here is abstract the Command class to have some form of inheritance, instead of using methods to facilitate your commands. You're on the right track, just add more to this switch statement.
src/main/java/Parser.java
Outdated
} | ||
|
||
|
||
public static String dateFormatter(String text) { |
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 definitely a plausible solution to obtaining substrings from the command. However, you might want to consider using the java String.split() method to make obtaining your data more efficient!
src/main/java/Duke.java
Outdated
import javafx.scene.image.Image; | ||
import javafx.scene.image.ImageView; | ||
|
||
public class Duke extends Application { |
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.
You might want to consider using multiple classes to facilitate your JavaFX GUI (MainWindow.java / DialogBox.java etc.)
Having all the code in your Duke.java makes it very messy and unreadable.
src/main/java/Duke.java
Outdated
ui.printIndent(); | ||
switch (text) { | ||
case "todo": | ||
throw new DukeException("☹ OOPS!!! The description of a todo 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.
Your error format can be stored in a string variable so that it's easy to reuse.
src/main/java/Task.java
Outdated
String formatted = date; | ||
if (!date.contains(")")) { | ||
try { | ||
Date d = new SimpleDateFormat("dd/MM/yyyy hhmm").parse(date); |
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.
Great effort in handling date and time!
Added assertions.
Better Code Quality.
Duke Increments