Skip to content

[zavsky] iP#197

Open
zavsky wants to merge 32 commits intonus-cs2113-AY2425S2:masterfrom
zavsky:master
Open

[zavsky] iP#197
zavsky wants to merge 32 commits intonus-cs2113-AY2425S2:masterfrom
zavsky:master

Conversation

@zavsky
Copy link
Copy Markdown

@zavsky zavsky commented Feb 9, 2025

No description provided.

@zavsky zavsky changed the title zavsky iP [zavsky] iP Feb 9, 2025
Copy link
Copy Markdown

@TVageesan TVageesan left a comment

Choose a reason for hiding this comment

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

Overall really well done. It's clear you've had some experience coding before (or you actually watch the lectures) as your code is clean, readable and easy to reason about. I've made some nitpicks about readability as well as a additional (optional) note you can consider to even further improve it.

Comment on lines +24 to +54
switch (command) {
case "list":
case "l":
return new ListCommand(taskManager, ui);
case "add":
case "a":
return parseAddCommand(arguments);
case "mark":
case "m":
return parseMarkCommand(arguments, true);
case "unmark":
case "u":
return parseMarkCommand(arguments, false);
case "delete":
case "d":
return parseDeleteCommand(arguments);
//case "undo":
//case "x":
// implement undo last functionality
case "help":
case "h":
return new HelpCommand(ui);
case "exit":
case "e":
//bb.greetGoodbye();
return new ExitCommand();
default:
System.out.println("Unknown command.");
return new HelpCommand(ui);
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Like the initiative to do short form commands for each command. However, these are considered magic strings. Perhaps you could put them in a constant EXIT_COMMAND/EXIT_COMMAND_SHORT or use a enum to represent the commands.

Comment on lines +79 to +91
// System.out.println(randomEnum(TaskType.class).name());
// return new Command();
}

/**
* Taken from stackoverflow.com/questions/1972392/pick-a-random-value-from-an-enum
* from users Eldelshell and zuddduz.
* @return
*/
public static <T extends Enum<?>> T randomEnum(Class<T> clazz) {
int x = random.nextInt(clazz.getEnumConstants().length);
return clazz.getEnumConstants()[x];
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

As it is, this function does not seem to serve any functionality. Consider removing it in your final version of IP.

Comment on lines +93 to +97
enum TaskType {
DEADLINE, D,
EVENT, E,
TODO, T
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider putting this in its own file. Enums, like classes, should have a dedicated file. You could then even share it across multiple classes for consistency.

} catch (IndexOutOfBoundsException e) {
ui.showError(e.getMessage());
}
// String userInput = getUserInput();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If the following section of code is no longer used, consider deleting it. Trust your version control tools to keep track of old versions of your code you want to reference instead of keeping dead code around.

}

private static Event createEvent(String details) throws IllegalTaskParameterException {
String[] parts = details.split("/from|/to|/f|/t", 3);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The .split pattern here can be put into a constant i.e. EVENT_ARG_PATTERN for better readability. This principle applies for the other create functions as well.

Comment on lines +25 to +27
public List<Task> getTasks() {
return Collections.unmodifiableList(tasks);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good idea to generate a copy of your list instead of directly returning a reference to your list! It's clear you understand the importance of protecting our private data within classes.

(This part is optional, does not affect code quality if you leave it as is)
You could even further improve on this by defining specific access methods for specific use cases instead of a generic getTasks(). Looking at your code, you currently use getTasks() to 1) print out the current tasks you have in your list 2) get the size of the list. Could we define specific methods getSize() to return the number of tasks and toString() to format the list into a printable string? This way our raw "tasks" data never gets passed out from the class.

Comment on lines +8 to +17
setBy(by);
}

public String getBy() {
return by;
}

public void setBy(String by) {
this.by = by;
}
Copy link
Copy Markdown

@TVageesan TVageesan Feb 15, 2025

Choose a reason for hiding this comment

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

do setBy() and getBy() serve a purpose in your overall program? In this scenario, simply this.by = by; will actually be more succinct. getters and setters should only be implemented as and when necessary. This will help reduce class length. You can apply this to your other tasks files as well.

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.

2 participants