Conversation
# Conflicts: # src/main/java/Deadline.java # src/main/java/DeadlineException.java # src/main/java/DukeException.java # src/main/java/Event.java # src/main/java/EventException.java # src/main/java/Todo.java # src/main/java/TodoException.java # src/main/java/UnknownException.java
# Conflicts: # src/main/java/Parser.java
src/main/java/Event.java
Outdated
| } else { | ||
| if (onesHour.equals(0)) { | ||
| end += "12:"; | ||
| } else { | ||
| end += onesHour.toString() + ":"; | ||
| } | ||
| } |
There was a problem hiding this comment.
Perhaps you can consider using else if and else statements here instead of a nested if-else to improve code readability? I noticed the same in other places too.
There was a problem hiding this comment.
I will check and correct them, thanks.
src/main/java/Duke.java
Outdated
| + "| |_| | |_| | < __/\n" | ||
| + "|____/ \\__,_|_|\\_\\___|\n"; | ||
| System.out.println("Hello from\n" + logo); | ||
| new Duke("./data/duke.txt").run(); |
There was a problem hiding this comment.
I like how you used a relative path here 👍
src/main/java/Ui.java
Outdated
| * | ||
| * @param statement The new response that will replace the current one. | ||
| */ | ||
| public void replace(String statement) { |
There was a problem hiding this comment.
Should this function be renamed to 'replaceResponse' or 'newResponse' to make the intent of the function clearer? I wasn't sure what 'replace; did when I encountered the function in the Parser.java file.
src/main/java/Parser.java
Outdated
| String[] line = command.split(" "); | ||
| int length = line.length; | ||
| if (length == 1) { | ||
| throw new IncompleteException("The description for Todo cannot be empty."); | ||
| } | ||
| ui.replace("Got it. I've added this task:"); | ||
| String description = ""; | ||
| for (int i = 1; i < length; i++) { | ||
| if (i + 1 == length) { | ||
| description += line[i]; | ||
| } else { | ||
| description += line[i] + " "; | ||
| } | ||
| } |
There was a problem hiding this comment.
Should the logic used extract out the description be simplified to make it more understandable? Perhaps instead of splitting on spaces and combing all the words after todo, you can simply remove the word 'todo' from the String? This will make require only a single line of code and is much more compact.
Something like:
String description = line.replace("todo", "").strip() //.strip() is to remove trailing spaces
The same can be applied in other parts of your code for descriptions of deadlines and events.
There was a problem hiding this comment.
Ah yes, that will make it a lot easier, thanks!
src/main/java/TaskList.java
Outdated
| * @param index Position of the to-be-replaced task in the list. | ||
| * @oaram task The new task that will replace the current one. | ||
| */ | ||
| public void replaceTask(int index, Task task) { |
There was a problem hiding this comment.
I like the intuitive naming of all the functions in this class.
src/main/java/Storage.java
Outdated
| BufferedReader br = new BufferedReader(new FileReader(this.filePath)); | ||
| String input = br.readLine(); | ||
| String type = ""; | ||
| int length = 0; | ||
| int lastIndex = 0; | ||
| String timeWithBracket = ""; | ||
| int twbLength = 0; | ||
| int twbLastIndex = 0; | ||
| String year = ""; | ||
| String yearLine = ""; | ||
| int descLastIndex = 0; | ||
| Task task = null; | ||
| String description = ""; | ||
| String date = ""; | ||
| String time = ""; |
There was a problem hiding this comment.
Perhaps you can consider abstracting away the formatting/extraction of dates/times by creating a separate class for functions related to these? There are a lot of variables declared here and abstracting these details will make the code easier to understand.
src/main/java/Task.java
Outdated
| public void formatTime() { | ||
| String copy = this.time; | ||
| char[] cArr = copy.toCharArray(); | ||
| Integer tensHour = cArr[0] - '0'; | ||
| Integer onesHour = cArr[1] - '0'; | ||
| Integer tensMin = cArr[2] - '0'; | ||
| Integer onesMin = cArr[3] - '0'; | ||
| String formattedTime = ""; | ||
| boolean isAfternoon = false; | ||
| if (!tensHour.equals(0)) { | ||
| Integer combinedHour = tensHour * 10 + onesHour; | ||
| if (combinedHour >= 12) { | ||
| isAfternoon = true; | ||
| if (combinedHour >= 13) { | ||
| combinedHour -= 12; | ||
| } |
There was a problem hiding this comment.
Should you leverage the LocalDate or some other library to convert the date and time format? I feel that doing so will make the code less cluttered and save you the trouble of writing everything from scratch. This can also be applied to all the classes which inherit from Task.
Maybe consider something along the lines of this tutorial?
There was a problem hiding this comment.
Noted, thanks for sharing the link!
noelmathewisaac
left a comment
There was a problem hiding this comment.
Overall I think that the code largely adheres to the coding standards. Making the changes mentioned by abstracting out more functions and using a library for date/time conversions/formatting will improve the readability and maintainability of the code.
gycc7253
left a comment
There was a problem hiding this comment.
haha nice reviewing your code, good work buddy!
src/main/java/Parser.java
Outdated
| Integer taskNum = i + 1; | ||
| ui.replace(taskNum.toString() + "." + taskList.getTask(i).toString()); | ||
| } | ||
| } else if (command.contains("todo")) { |
There was a problem hiding this comment.
If i have a command
'event todo a task /by tmr'
this string contains 'todo' but it is actually event...
i think testing prefix maybe safer?
There was a problem hiding this comment.
Noted, will change it, thanks.
src/main/java/Storage.java
Outdated
| year += yearArr[i]; | ||
| } | ||
| date = inputArr[lastIndex - 3] + | ||
| " " + inputArr[lastIndex - 2] + " " + year; |
There was a problem hiding this comment.
i think over here, by coding standard, the + should be the start of the preceding line hh,
same mistake made bro.
There was a problem hiding this comment.
Oh yes, thanks for pointing it out.
| @@ -0,0 +1,18 @@ | |||
| import org.junit.jupiter.api.Test; | |||
| import static org.junit.jupiter.api.Assertions.assertEquals; | |||
There was a problem hiding this comment.
could you please double check if static import needs to be imported before non-static, i think so but i am not 100% sure haha
src/main/java/Storage.java
Outdated
| import java.io.FileWriter; | ||
| import java.io.IOException; | ||
|
|
||
| public class Storage { |
There was a problem hiding this comment.
public class and methods undocumented bro, small issue, maybe u will do it later haha.
src/main/java/Event.java
Outdated
| * A type of Task. | ||
| */ | ||
| public class Event extends Task { | ||
| public Event(String description, String date, String time) { |
There was a problem hiding this comment.
i think public constructor needs a documentation also
src/main/java/Duke.java
Outdated
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
| import java.io.IOException; |
There was a problem hiding this comment.
maybe import of java.io should be in front of java.nio/util coz of lexicographic order
Add branch-A-Assertions to master
* 'master' of https://github.com/cheunggalen/ip: Add A-Assertions
# Conflicts: # src/main/java/Parser.java
Add branch-A-CodeQuality to master
* 'master' of https://github.com/cheunggalen/ip: Add A-CodeQuality
Add C-DetectDuplicates
* 'master' of https://github.com/cheunggalen/ip: Add C-DetectDuplicates
* 'master' of https://github.com/cheunggalen/ip: Set theme jekyll-theme-midnight
* 'master' of https://github.com/cheunggalen/ip: Set theme jekyll-theme-cayman
No description provided.