Skip to content

[Lee Zhi Zhong Moses] iP#227

Open
moseslee9012 wants to merge 13 commits into
nus-cs2113-AY2223S2:masterfrom
moseslee9012:master
Open

[Lee Zhi Zhong Moses] iP#227
moseslee9012 wants to merge 13 commits into
nus-cs2113-AY2223S2:masterfrom
moseslee9012:master

Conversation

@moseslee9012

Copy link
Copy Markdown

No description provided.

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

@wcwy wcwy 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.

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 thread src/main/java/Duke.java
Comment on lines +9 to +11
String exitCommand = "bye";
String toDo = "list";
String checkAsDone = "mark";

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

Comment thread src/main/java/Duke.java Outdated
private static Scanner in = new Scanner(System.in);
private static final Task[] tasks = new Task[100];

public static void command(String 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.

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)

Comment thread src/main/java/Duke.java
String[] tokens = line.split(" ", 2);
String command = tokens[0];

while (!command.equals(exitCommand)) {

Copy link
Copy Markdown

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.

Comment thread src/main/java/Duke.java

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

Copy link
Copy Markdown

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.

Comment thread src/main/java/ToDo.java

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

Copy link
Copy Markdown

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.

Comment thread src/main/java/Duke.java Outdated
String task = tokens[1];
switch(command) {
case "todo":
Task t = new ToDo(task);

Copy link
Copy Markdown

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

Comment thread src/main/java/Duke.java
public class Duke {

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

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 program scalability, you might want to consider using ArrayList instead of setting a maximum number of tasks user can have here.

Comment thread src/main/java/Task.java
}

public String getStatus() {
return (isDone ? "[X]" : "[ ]"); // mark done task with 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.

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