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

[kevinz420] iP #62

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

Conversation

kevinz420
Copy link

No description provided.

@kevinz420 kevinz420 changed the title kevinz420 iP [kevinz420] iP Sep 4, 2023

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

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

src/main/java/Duke.java Outdated Show resolved Hide resolved
src/main/java/Duke.java Outdated Show resolved Hide resolved
Copy link

@wendelinwemhoener wendelinwemhoener 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 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 on lines 14 to 22
if (line.equals("bye")) {
break;
}

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

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 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;
}

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


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.");

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?

src/main/java/Duke.java Outdated Show resolved Hide resolved
src/main/java/Duke.java Outdated Show resolved Hide resolved
Copy link

@charkty charkty left a comment

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!

private static HashMap<String, String> parseParameters(String line) {
HashMap<String, String> fieldToValue = new HashMap<>();

int startDescription = line.indexOf(" ");
Copy link

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

src/main/java/Duke.java Outdated Show resolved Hide resolved
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

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

src/main/java/Duke.java Outdated Show resolved Hide resolved
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