Skip to content

[kevinz420] iP#62

Open
kvn-zhang wants to merge 16 commits into
nus-cs2113-AY2324S1:masterfrom
kvn-zhang:master
Open

[kevinz420] iP#62
kvn-zhang wants to merge 16 commits into
nus-cs2113-AY2324S1:masterfrom
kvn-zhang:master

Conversation

@kvn-zhang

Copy link
Copy Markdown

No description provided.

@kvn-zhang kvn-zhang changed the title kevinz420 iP [kevinz420] iP Sep 4, 2023
Comment thread src/main/java/Duke.java Outdated

Scanner in = new Scanner(System.in);
String line;
while (in.hasNextLine()) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe can check "bye" condition here

Comment thread src/main/java/Duke.java Outdated
Comment thread src/main/java/Duke.java Outdated

@wendelinwemhoener wendelinwemhoener left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Overall, I really like your pull request.

You abided by the coding standard and structured your code in a readable and modular way.

Maybe consider adding Javadoc comments to your more complex methods: I know that it is somewhat annoying at first, but it can really help in the long term and makes it easier for other people to understand what is going on.

Comment thread src/main/java/Duke.java Outdated
Comment on lines +14 to +22
if (line.equals("bye")) {
break;
}

if (line.equals("list")) {
printTasks();
} else {
handleCommand(line);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What do you think about refactoring this into an "if - else if - else" statement instead of having a separate "if" statement and another "if - else" statement?

Comment thread src/main/java/Duke.java Outdated
Comment on lines +69 to +87
private static HashMap<String, String> parseParameters(String line) {
HashMap<String, String> fieldToValue = new HashMap<>();

int startDescription = line.indexOf(" ");
int endOfDescription = line.indexOf(" /");
fieldToValue.put("description", line.substring(startDescription + 1, endOfDescription));

String[] splitParams = line.split(" /");
for (int i = 1; i < splitParams.length; i++) {
String rawParam = splitParams[i];
int divider = rawParam.indexOf(" ");

String field = rawParam.substring(0, divider);
String value = rawParam.substring(divider + 1);
fieldToValue.put(field, value);
}

return fieldToValue;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I love that you factored this out into a separate method!
However, what do you think about adding a small Javadoc comment? It took me a bit to figure out how exactly the HashMap you return is structured, and I think that just documenting this in a small comment might make it easier for future contributors

Comment thread src/main/java/Duke.java Outdated

tasks[numTasks] = task;
numTasks++;
System.out.println("Got it. I've added this task:\n" + task.getFormattedTask() + "\nNow you have " + numTasks + " tasks in the list.");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

That line seems a bit long (although in the GitHub Web Interface I unfortunately can't see its exact length); what do you think about breaking it into two lines?

Comment thread src/main/java/Duke.java Outdated
Comment thread src/main/java/Duke.java Outdated

@charkty charkty left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I like your very neat code. Good job on the naming!

Comment thread src/main/java/Duke.java Outdated
private static HashMap<String, String> parseParameters(String line) {
HashMap<String, String> fieldToValue = new HashMap<>();

int startDescription = line.indexOf(" ");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

for consistency, can rename to startOfDescription

Comment thread src/main/java/Duke.java Outdated
Comment thread src/main/java/Duke.java Outdated
Comment on lines +30 to +53
if (line.contains("mark")) {
int idx = Integer.parseInt(line.substring(divider + 1)) - 1;
if (idx < 0 || tasks[idx] == null) {
System.out.println("Sorry! That's not a valid task");
return;
}

markTask(idx, line.startsWith("mark"));
return;
}
if (line.startsWith("todo")){
addTask(new Todo(line.substring(divider + 1)));
return;
}

HashMap<String, String> parameters = parseParameters(line);
String description = parameters.get("description");
if (description == null) {
System.out.println("Sorry! Please provide a valid description");
return;
}
if (line.startsWith("deadline")) {
String by = parameters.get("by");
if (by == null) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

you should consider using if-else statements instead of all if statements. Another alternative if using switch-case statements

Comment thread src/main/java/Duke.java Outdated
Comment thread src/main/java/duke/Duke.java
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.

6 participants