-
Notifications
You must be signed in to change notification settings - Fork 228
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
[Galen Cheung] iP #238
base: master
Are you sure you want to change the base?
[Galen Cheung] iP #238
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like how you used a relative path here 👍
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.
Thanks :)
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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 will change it, thanks.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
Will take note, thanks.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted, thanks for sharing the link!
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.
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.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think public constructor needs a documentation also
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.
Noted, thanks.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe import of java.io should be in front of java.nio/util coz of lexicographic order
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.
Will correct it, thanks.
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.