Skip to content

[Liu Yishan] iP#180

Open
lys2333 wants to merge 13 commits intonus-cs2113-AY2425S2:masterfrom
lys2333:master
Open

[Liu Yishan] iP#180
lys2333 wants to merge 13 commits intonus-cs2113-AY2425S2:masterfrom
lys2333:master

Conversation

@lys2333
Copy link
Copy Markdown

@lys2333 lys2333 commented Feb 6, 2025

No description provided.

缪尔赛思\86187 added 2 commits January 31, 2025 16:14
todo, add deadline, add task
@lys2333 lys2333 changed the title [{lys2333}] iP Liu Yishan iP Feb 6, 2025
@lys2333 lys2333 changed the title Liu Yishan iP [Liu Yishan] iP Feb 6, 2025
Copy link
Copy Markdown

@Isaaclks7 Isaaclks7 left a comment

Choose a reason for hiding this comment

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

Overall good naming conventions and relevant spacings. However, you may want to place your different classes into separate files for better organisation.

@@ -1,3 +1,81 @@
import java.util.Scanner;

abstract class 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.

Correct naming convention of your class in PascalCase.

Comment on lines +12 to +18
public void markAsDone() {
this.isDone = true;
}

public void unmarkAsDone() {
this.isDone = false;
}
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 use of camelCase for methods

Comment on lines +101 to +157
if (input.equalsIgnoreCase("bye")) {
System.out.println("____________________________________________________________");
System.out.println("Bye. Hope to see you again soon!");
System.out.println("____________________________________________________________");
break;
} else if (input.equalsIgnoreCase("list")) {
System.out.println("____________________________________________________________");
System.out.println("Here are the tasks in your list:");
for (int i = 0; i < taskCount; i++) {
System.out.println((i + 1) + "." + tasks[i]);
}
System.out.println("____________________________________________________________");
} else if (words[0].equalsIgnoreCase("mark")) {
int index = Integer.parseInt(words[1]) - 1;
if (index >= 0 && index < taskCount) {
tasks[index].markAsDone();
System.out.println("____________________________________________________________");
System.out.println("Nice! I've marked this task as done:");
System.out.println(" " + tasks[index]);
System.out.println("____________________________________________________________");
}
} else if (words[0].equalsIgnoreCase("unmark")) {
int index = Integer.parseInt(words[1]) - 1;
if (index >= 0 && index < taskCount) {
tasks[index].unmarkAsDone();
System.out.println("____________________________________________________________");
System.out.println("OK, I've marked this task as not done yet:");
System.out.println(" " + tasks[index]);
System.out.println("____________________________________________________________");
}
} else if (words[0].equalsIgnoreCase("todo")) {
tasks[taskCount] = new ToDo(words[1]);
taskCount++;
System.out.println("____________________________________________________________");
System.out.println("Got it. I've added this task:");
System.out.println(" " + tasks[taskCount - 1]);
System.out.println("Now you have " + taskCount + " tasks in the list.");
System.out.println("____________________________________________________________");
} else if (words[0].equalsIgnoreCase("deadline")) {
String[] parts = words[1].split(" /by ");
tasks[taskCount] = new Deadline(parts[0], parts[1]);
taskCount++;
System.out.println("____________________________________________________________");
System.out.println("Got it. I've added this task:");
System.out.println(" " + tasks[taskCount - 1]);
System.out.println("Now you have " + taskCount + " tasks in the list.");
System.out.println("____________________________________________________________");
} else if (words[0].equalsIgnoreCase("event")) {
String[] parts = words[1].split(" /from | /to ");
tasks[taskCount] = new Event(parts[0], parts[1], parts[2]);
taskCount++;
System.out.println("____________________________________________________________");
System.out.println("Got it. I've added this task:");
System.out.println(" " + tasks[taskCount - 1]);
System.out.println("Now you have " + taskCount + " tasks in the list.");
System.out.println("____________________________________________________________");
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could consider using switch-case instead of multiple if-else statements

Comment on lines +109 to +110
for (int i = 0; i < taskCount; i++) {
System.out.println((i + 1) + "." + 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.

Could rename i to taskIndex for readability. Additionally, you can start from i = 1 instead of i = 0.

缪尔赛思\86187 added 2 commits February 13, 2025 10:08
Change the if-else statements into switch case to improve readability.
Comment on lines +103 to +109
switch (command) {
case "bye":
System.out.println("____________________________________________________________");
System.out.println("Bye. Hope to see you again soon!");
System.out.println("____________________________________________________________");
scanner.close();
return;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Do try to use the formatting for switch statements outlined in the Java coding standards for this course.

Comment on lines +124 to +141
case "mark":
case "unmark":
int index = Integer.parseInt(words[1]) - 1;
if (index < 0 || index >= taskCount) {
throw new IndexOutOfBoundsException("Invalid task number.");
}
if (command.equals("mark")) {
tasks[index].markAsDone();
System.out.println("____________________________________________________________");
System.out.println("Nice! I've marked this task as done:");
} else {
tasks[index].unmarkAsDone();
System.out.println("____________________________________________________________");
System.out.println("OK, I've marked this task as not done yet:");
}
System.out.println(" " + tasks[index]);
System.out.println("____________________________________________________________");
break;
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 job realising that the mark and unmark commands are very similar. Consider extracting the logic out to another method so that you can avoid placing the if-else block within the case block for mark and unmark, which basically does the same thing.

Comment on lines +111 to +122
case "list":
System.out.println("____________________________________________________________");
if (taskCount == 0) {
System.out.println("Your task list is empty.");
} else {
System.out.println("Here are the tasks in your list:");
for (int i = 0; i < taskCount; i++) {
System.out.println((i + 1) + "." + tasks[i]);
}
}
System.out.println("____________________________________________________________");
break;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perhaps you can extract some of the logic in your cases out into methods in order to reduce deep nesting and prevent "arrowhead code" from developing.

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