-
Notifications
You must be signed in to change notification settings - Fork 484
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
[butteredyakiimo] iP #525
base: master
Are you sure you want to change the base?
[butteredyakiimo] iP #525
Conversation
@@ -15,3 +15,5 @@ bin/ | |||
|
|||
/text-ui-test/ACTUAL.TXT | |||
text-ui-test/EXPECTED-UNIX.TXT | |||
|
|||
/src/main/java/*.class |
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.
Looks good to me 😄
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.
LGTM! There could be some parts that can be optimized but it's a great effort overall
src/main/java/duke/Duke.java
Outdated
if (parser.isGoodbye(input)) { | ||
break; | ||
} else { | ||
parser.parseInput(input); | ||
} |
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.
The way you check for a terminating condition is quite intuitive by checking whether the input is "bye" or not. However, this involves throwing the input into the parser twice. Would it be better to let the parser handle the case "bye" in parser.parseInput(input)
?
src/main/java/duke/Parser.java
Outdated
private static boolean isNumber(String s) { | ||
return s != null && s.matches("[0-9.]+"); | ||
} |
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 regex is used here :D
src/main/java/duke/Parser.java
Outdated
if (inputArr.length == 1) { | ||
throw new NoTaskIdException(); | ||
} else { | ||
String strIndex = inputArr[1]; | ||
if (isNumber(strIndex)) { | ||
int index = Integer.parseInt(strIndex) - 1; //because index starts from 1 | ||
if (tasks.isValidTaskId(index)) { | ||
tasks.markTask(index); | ||
} | ||
} else { | ||
throw new InvalidTaskIdException(); | ||
} | ||
} |
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.
What happens if tasks.isValidTaskId(index)
returns false? Could InvalidTaskIdException be thrown? I would write this part like this:
if (inputArr.length == 1) {
throw new NoTaskIdException();
} else {
String strIndex = inputArr[1];
if (isNumber(strIndex) && tasks.isValidTaskId(Integer.parseInt(strIndex) - 1)) {
int index = Integer.parseInt(strIndex) - 1; //because index starts from 1
tasks.markTask(index);
} else {
throw new InvalidTaskIdException();
}
}
src/main/java/duke/Parser.java
Outdated
if (inputs.length == 1) { | ||
throw new NoTaskIdException(); | ||
} else { | ||
String strIndex = inputs[1]; | ||
if (isNumber(strIndex)) { | ||
int index = Integer.parseInt(strIndex) - 1; //because index starts from 1 | ||
if (tasks.isValidTaskId(index)) { | ||
tasks.unMarkTask(index); | ||
} | ||
} else { | ||
throw new InvalidTaskIdException(); | ||
} | ||
} |
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.
Same question as mentioned above
src/main/java/duke/Parser.java
Outdated
if (inputs.length == 1) { | ||
throw new NoDescException(); | ||
} else { | ||
String afterCommand = inputs[1]; | ||
String[] details = afterCommand.split(" /by ", 2); | ||
|
||
if (details.length < 2) { | ||
throw new InvalidDeadlineException(); | ||
} else { | ||
String desc = details[0]; | ||
String date = details[1]; | ||
|
||
if (desc.isEmpty()) { | ||
throw new NoDescException(); | ||
} else { | ||
try { | ||
LocalDateTime dateTime = convertToDateTime(date); | ||
Deadline deadline = new Deadline(0, desc, dateTime); | ||
tasks.addTask(deadline); | ||
} catch (DateTimeParseException e) { | ||
ui.showInvalidDateFormat(); | ||
} | ||
} | ||
} | ||
} |
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 part is quite heavily nested. Could you try to refactor the code to make it more flatter?
src/main/java/duke/Parser.java
Outdated
public void parseEvent(String input) throws NoDescException, NoStartException, NoEndException, | ||
InvalidStartEndException, InvalidEventException { | ||
String[] inputs = input.split(" ", 2); | ||
if (inputs.length == 1) { | ||
throw new NoDescException(); | ||
} else if (inputs[1].isBlank()) { | ||
throw new NoDescException(); | ||
} else { | ||
String afterCommand = inputs[1]; | ||
String[] details = afterCommand.split(" /from ", 2); | ||
|
||
if (details[0].isBlank()) { | ||
throw new NoDescException(); | ||
} else if (details.length == 1) { | ||
throw new InvalidEventException(); | ||
} else { | ||
String task = details[0]; | ||
String start = details[1].split(" /to ", 2)[0]; | ||
|
||
if (start.isBlank()) { | ||
throw new NoStartException(); | ||
} else { | ||
String[] endDetails = afterCommand.split(" /to ", 2); | ||
|
||
if (endDetails.length == 1) { //no end date added | ||
throw new NoEndException(); | ||
} else { | ||
String end = endDetails[1]; | ||
|
||
if (end.isBlank()) { | ||
throw new NoEndException(); | ||
} else { | ||
try { | ||
LocalDateTime startDateTime = convertToDateTime(start); | ||
LocalDateTime endDateTime = convertToDateTime(end); | ||
Event event = new Event(0, task, startDateTime, endDateTime); | ||
tasks.addTask(event); | ||
} catch (DateTimeParseException e) { | ||
ui.showInvalidDateFormat(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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.
Same question with this method.
src/main/java/duke/Storage.java
Outdated
dataFile = createDataFile(); | ||
} | ||
|
||
//create a FileWriter object to write to file. Note that this overwrites the existing data! |
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 this warning for i have fallen for this so many times D:
I still don't know how FileWriters work
Assertions help to detect possible bugs, as they verify certain assumptions that the code makes. Gradle run is also configured to enable assertions.
Some methods are extremely long, and have more than one level of abstraction. Magic numbers are used to describe the task status. Let's make more methods to adhere to SLAP and avoid nested code, and also create a new Enum to make code easier to understand.
Add assertions to some classes
Modify code to adhere to code quality standards
Currently, users only have a list commmand to list all the tasks. To create reminders for upcoming tasks, users need to be able to view the tasks that are due before/within the time period. A flag can be used at the end of the list command of the format: 'list flag'. The time period for both deadline and event starts at the start of the day at 00:00. The end is determined by the flag indicated by the user. Let's add the following flags: * 'today' : lists all tasks that in the period today 00:00 to tmr 00:00 * 'week' : lists all tasks that are in the period today 00:00 to one week later 00:00 * 'fort': lists all tasks that are in the period today 00:00 to 2 weeks later 00:00
Currently, users only have a list commmand to list all the tasks. To create reminders for upcoming tasks, users need to be able to view the tasks that are due before/within the time period. A flag can be used at the end of the list command of the format: 'list flag'. The time period for both deadline and event starts at the start of the day at 00:00. The end is determined by the flag indicated by the user. Let's add the following flags: * 'today' : lists all tasks that in the period today 00:00 to tmr 00:00 * 'week' : lists all tasks that are in the period today 00:00 to one week later 00:00 * 'fort': lists all tasks that are in the period today 00:00 to 2 weeks later 00:00
BUTTER
BUTTER helps you remember what you need to do. It's,
FASTSUPER FAST to useAll you need to do is,
And it is FREE!
Features:
If you are a Java programmer, you can use it to practise Java too. Here's the
main
method: