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

[Lee Zhi Zhong Moses] iP #227

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

Conversation

moseslee9012
Copy link

No description provided.

@moseslee9012 moseslee9012 changed the title iP [Lee Zhi Zhong Moses] iP Feb 15, 2023
Copy link

@wcwy wcwy left a comment

Choose a reason for hiding this comment

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

Well done in catching up in the past one week! Keep the spirit up! So far most of your code follows well in terms of coding standards and coding quality. You might want to consider extracting methods out more often whenever appropriate to prevent one single method to be too long and to avoid issues such as arrow code. Below are some suggestions on the possible things you can look out for. All the best for further levels!

Comment on lines 9 to 11
String exitCommand = "bye";
String toDo = "list";
String checkAsDone = "mark";
Copy link

Choose a reason for hiding this comment

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

You might want to consider converting them into named constants instead of a variables since it is unlikely for them to be changed.
E.g. public static final String EXIT_COMMAND = "bye";

private static Scanner in = new Scanner(System.in);
private static final Task[] tasks = new Task[100];

public static void command(String line) {
Copy link

Choose a reason for hiding this comment

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

A better naming practices for methods is to start it with a verb. For example, you can call this executeCommand or something better here. (While the word command can be a verb too, it doesn't suit your usage very well)

String[] tokens = line.split(" ", 2);
String command = tokens[0];

while (!command.equals(exitCommand)) {
Copy link

Choose a reason for hiding this comment

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

Currently, this entire method is too long. You can try to keep a method short by extracting its content out to other methods whenever appropriate.


for (int i = 0; i < numberOfTasks; ++i) {
System.out.format("%d. ", (i + 1));
System.out.println(tasks[i]);
Copy link

Choose a reason for hiding this comment

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

This is a good use of polymorphism here. You can apply a similar concept when dealing with similar scenarios in further levels.


@Override
public String toString() {
return "[T]" + super.toString();
Copy link

Choose a reason for hiding this comment

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

Arguably, strings like [T] can be seen as a magic strings. You might want to consider extracting strings like this into a named constants. Sometimes, you could also use enums to achieve similar effect. There could be other magic strings/numbers/literals in your other code too that you might want to look out for them.

String task = tokens[1];
switch(command) {
case "todo":
Task t = new ToDo(task);
Copy link

Choose a reason for hiding this comment

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

We want to avoid using a single character as the name of a variable (with some exceptions such as i, j, k in a for loop). Try to think if another name for this

public class Duke {

private static Scanner in = new Scanner(System.in);
private static final Task[] tasks = new Task[100];
Copy link

Choose a reason for hiding this comment

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

For program scalability, you might want to consider using ArrayList instead of setting a maximum number of tasks user can have here.

}

public String getStatus() {
return (isDone ? "[X]" : "[ ]"); // mark done task with X
Copy link

Choose a reason for hiding this comment

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

You might want to capitalise the first character in your comment.

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