Skip to content
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

Open
wants to merge 35 commits into
base: master
Choose a base branch
from

Conversation

cheunggalen
Copy link

No description provided.

# 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
Comment on lines 72 to 78
} else {
if (onesHour.equals(0)) {
end += "12:";
} else {
end += onesHour.toString() + ":";
}
}
Copy link

@noelmathewisaac noelmathewisaac Feb 4, 2021

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.

Copy link
Author

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.

+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
new Duke("./data/duke.txt").run();

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 👍

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks :)

*
* @param statement The new response that will replace the current one.
*/
public void replace(String statement) {

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.

Copy link
Author

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.

Comment on lines 56 to 69
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] + " ";
}
}
Copy link

@noelmathewisaac noelmathewisaac Feb 4, 2021

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.

Copy link
Author

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!

* @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) {

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.

Comment on lines 35 to 49
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 = "";

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will take note, thanks.

Comment on lines 80 to 95
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;
}

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?

Copy link
Author

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!

Copy link

@noelmathewisaac noelmathewisaac left a 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.

Copy link

@gycc7253 gycc7253 left a 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!

Integer taskNum = i + 1;
ui.replace(taskNum.toString() + "." + taskList.getTask(i).toString());
}
} else if (command.contains("todo")) {
Copy link

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?

Copy link
Author

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.

year += yearArr[i];
}
date = inputArr[lastIndex - 3] +
" " + inputArr[lastIndex - 2] + " " + year;
Copy link

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.

Copy link
Author

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;
Copy link

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

import java.io.FileWriter;
import java.io.IOException;

public class Storage {
Copy link

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.

* A type of Task.
*/
public class Event extends Task {
public Event(String description, String date, String time) {
Copy link

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted, thanks.

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.io.IOException;
Copy link

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will correct it, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants