Skip to content

[Silin Chen] iP#192

Open
silinche wants to merge 31 commits intonus-cs2113-AY2122S1:masterfrom
silinche:master
Open

[Silin Chen] iP#192
silinche wants to merge 31 commits intonus-cs2113-AY2122S1:masterfrom
silinche:master

Conversation

@silinche
Copy link

@silinche silinche commented Sep 1, 2021

No description provided.

Copy link

@kelvneo kelvneo left a comment

Choose a reason for hiding this comment

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

Nice job on the readability of the code, but the main thing to look out for is the method names.

Comment on lines +10 to +12
public void setDone() {
this.isDone = true;
}
Copy link

Choose a reason for hiding this comment

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

Good job following naming conventions, however, I think you may have to place a parameter for the boolean instead.

Comment on lines +27 to +30
if (line.equals("list")) {
for (int i = 0; i < taskNumber; i++) {
System.out.println((i + 1) + "." + tasks[i]);
}
Copy link

Choose a reason for hiding this comment

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

Good work on following bracketing conventions:
https://se-education.org/guides/conventions/java/basic.html#conditionals

Task[] tasks= new Task[100];
int taskNumber = 0;
String line;
Scanner in = new Scanner(System.in);
Copy link

Choose a reason for hiding this comment

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

Perhaps you can name the in here inputScanner instead?



public class Duke {
public static void hi() {
Copy link

Choose a reason for hiding this comment

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

The name of the method have to be a verb instead:
https://se-education.org/guides/conventions/java/basic.html#naming

System.out.println("What can I do for you?");
}

public static void bye() {
Copy link

Choose a reason for hiding this comment

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

The name of the method have to be a verb instead:
https://se-education.org/guides/conventions/java/basic.html#naming

System.out.println("Bye. Hope to see you again soon!");
}

public static void running() {
Copy link

Choose a reason for hiding this comment

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

The name of the method have to be a verb instead:
https://se-education.org/guides/conventions/java/basic.html#naming

Copy link

@AnShengLee AnShengLee left a comment

Choose a reason for hiding this comment

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

Overall, readability is there. Main issue is the long running() method that takes up multiple lines of code. Do try to keep a method within 30 lines of code.

Comment on lines +14 to +86
public static void running() {
Task[] tasks= new Task[100];
int taskNumber = 0;
String line;
Scanner in = new Scanner(System.in);
while (true) {
//new scanner
line = in.nextLine();
//if goodbye
if (line.equals("bye")) {
return;
}
//if want to list out tasks or mark as done or add items
if (line.equals("list")) {
for (int i = 0; i < taskNumber; i++) {
System.out.println((i + 1) + "." + tasks[i]);
}
} else if (line.startsWith("done")) {
int index = Integer.parseInt(line.substring(5)) - 1;
tasks[index].setDone();
System.out.println("Nice! I've marked this task as done:");
System.out.println(" " + tasks[index].getStatusIcon() + " " + tasks[index].getDescription());
} else if (line.startsWith("todo")) {
tasks[taskNumber] = new ToDo(line.substring(5));
taskNumber++;
System.out.println("Got it. I've added this task:");
System.out.println(" " + tasks[taskNumber - 1]);
System.out.println("Now you have " + taskNumber + " tasks in the list");
} else if (line.startsWith("deadline")) {
String[] words = line.split(" ");
int index = 0;
String deadlineDescription = "";
String by = "";
for (int i = 0; i < words.length; i++) {
if (words[i].equals("/by")) {
index = i;
break;
}
}
for (int i = 1; i < index; i++) {
deadlineDescription = deadlineDescription + words[i] + " ";
}
by = words[index + 1];
tasks[taskNumber] = new Deadline(deadlineDescription, by);
taskNumber++;
System.out.println("Got it. I've added this task:");
System.out.println(" " + tasks[taskNumber - 1]);
System.out.println("Now you have " + taskNumber + " tasks in the list");
} else if (line.startsWith("event")) {
String[] words = line.split(" ");
int index = 0;
String eventDescription = "";
String at = "";
for (int i = 0; i < words.length; i++) {
if (words[i].equals("/at")) {
index = i;
break;
}
}
for (int i = 1; i < index; i++) {
eventDescription = eventDescription + words[i] + " ";
}
for (int i = index + 1; i < words.length; i++) {
at = at + words[i] + " ";
}
tasks[taskNumber] = new Event(eventDescription, at);
taskNumber++;
System.out.println("Got it. I've added this task:");
System.out.println(" " + tasks[taskNumber - 1]);
System.out.println("Now you have " + taskNumber + " tasks in the list");
}
}
}

Choose a reason for hiding this comment

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

Method is over 30 lines of code. It would not fit into the computer screen making it hard to debug and read. Maybe split the method into smaller methods.

Comment on lines +1 to +14
public class Deadline extends Task {

protected String by;

public Deadline(String description, String by) {
super(description);
this.by = by;
}

@Override
public String toString() {
return "[D]" + super.toString() + "(by: " + by + ")";
}
}

Choose a reason for hiding this comment

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

Clear! Reader would not be confused.

Comment on lines +1 to +10
public class ToDo extends Task{
public ToDo(String description) {
super(description);
}

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

Choose a reason for hiding this comment

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

Clear! Reader would not be confused.

Comment on lines +1 to +26
public class Task {
protected String description;
protected boolean isDone;

public Task(String description) {
this.description = description;
this.isDone = false;
}

public void setDone() {
this.isDone = true;
}

public String getDescription() {
return this.description;
}

public String getStatusIcon() {
return (isDone ? "[X]" : "[ ]"); // mark done task with X
}

@Override
public String toString() {
return this.getStatusIcon() + " " + this.getDescription();
}
}

Choose a reason for hiding this comment

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

Clear! Reader would not be confused.

Comment on lines +27 to +84
if (line.equals("list")) {
for (int i = 0; i < taskNumber; i++) {
System.out.println((i + 1) + "." + tasks[i]);
}
} else if (line.startsWith("done")) {
int index = Integer.parseInt(line.substring(5)) - 1;
tasks[index].setDone();
System.out.println("Nice! I've marked this task as done:");
System.out.println(" " + tasks[index].getStatusIcon() + " " + tasks[index].getDescription());
} else if (line.startsWith("todo")) {
tasks[taskNumber] = new ToDo(line.substring(5));
taskNumber++;
System.out.println("Got it. I've added this task:");
System.out.println(" " + tasks[taskNumber - 1]);
System.out.println("Now you have " + taskNumber + " tasks in the list");
} else if (line.startsWith("deadline")) {
String[] words = line.split(" ");
int index = 0;
String deadlineDescription = "";
String by = "";
for (int i = 0; i < words.length; i++) {
if (words[i].equals("/by")) {
index = i;
break;
}
}
for (int i = 1; i < index; i++) {
deadlineDescription = deadlineDescription + words[i] + " ";
}
by = words[index + 1];
tasks[taskNumber] = new Deadline(deadlineDescription, by);
taskNumber++;
System.out.println("Got it. I've added this task:");
System.out.println(" " + tasks[taskNumber - 1]);
System.out.println("Now you have " + taskNumber + " tasks in the list");
} else if (line.startsWith("event")) {
String[] words = line.split(" ");
int index = 0;
String eventDescription = "";
String at = "";
for (int i = 0; i < words.length; i++) {
if (words[i].equals("/at")) {
index = i;
break;
}
}
for (int i = 1; i < index; i++) {
eventDescription = eventDescription + words[i] + " ";
}
for (int i = index + 1; i < words.length; i++) {
at = at + words[i] + " ";
}
tasks[taskNumber] = new Event(eventDescription, at);
taskNumber++;
System.out.println("Got it. I've added this task:");
System.out.println(" " + tasks[taskNumber - 1]);
System.out.println("Now you have " + taskNumber + " tasks in the list");
}

Choose a reason for hiding this comment

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

Good work on avoiding deep nested conditionals!

Copy link

@kewenlok kewenlok left a comment

Choose a reason for hiding this comment

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

In general, I think you did a great job in complying with the coding standards! I have pointed out some minor changes that you could make to enhance the quality of your code. Keep up the good work!

Comment on lines +115 to +139
while (true) {
line = in.nextLine();
if (line.equals("bye")) {
return;
}
if (line.equals("list")) {
listOut(tasks, taskNumber);
} else if (line.startsWith("done")) {
markDone(line, tasks);
} else if (line.startsWith("todo")) {
if (addTodo(line, tasks, taskNumber)) {
taskNumber++;
}
} else if (line.startsWith("deadline")) {
if (addDeadline(line, tasks, taskNumber)) {
taskNumber++;
}
} else if (line.startsWith("event")) {
if (addEvent(line, tasks, taskNumber)) {
taskNumber++;
}
} else {
System.out.println("☹ OOPS!!! I'm sorry, but I don't know what that means :-(");
}
}

Choose a reason for hiding this comment

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

You could consider splitting this functionality into another method for better readability and reusability of your code.

tasks[taskNumber] = new Event(eventDescription, at);
taskNumber++;
System.out.println("Got it. I've added this task:");
System.out.println(" " + tasks[taskNumber - 1]);

Choose a reason for hiding this comment

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

Should the magic literal 1 be declared as a constant instead so that it is easier for you and other programmers to refer to your code in the future? This applies to all magic literals across the code.

Comment on lines +44 to +69
String[] words = line.split(" ");
int index = 0;
String deadlineDescription = "";
String by = "";
for (int i = 0; i < words.length; i++) {
if (words[i].equals("/by")) {
index = i;
break;
}
}
if (index == 0) {
System.out.println("OOPS!!! The description of a deadline cannot be empty.");
return false;
}
for (int i = 1; i < index; i++) {
deadlineDescription = deadlineDescription + words[i] + " ";
}
for (int i = index + 1; i < words.length; i++) {
by = by + words[i] + " ";
}
tasks[taskNumber] = new Deadline(deadlineDescription, by);
taskNumber++;
System.out.println("Got it. I've added this task:");
System.out.println(" " + tasks[taskNumber - 1]);
System.out.println("Now you have " + taskNumber + " tasks in the list");
return true;

Choose a reason for hiding this comment

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

You may want to consider splitting this method into multiple smaller methods that do smaller tasks and call it from this method. This goes the same for the other tasks-related methods.



public class Duke {
public static void listOut(Task[] tasks, int taskNumber) {

Choose a reason for hiding this comment

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

Consider using a clearer naming convention for your method such as printTasks().

this.by = by;
}

@Override

Choose a reason for hiding this comment

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

Good use of the override statement. Well done!

@@ -0,0 +1,12 @@
package duke.task;

public class ToDo extends Task{

Choose a reason for hiding this comment

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

Do take note of the spacing for each bracket and curly braces for the consistency of the whole program.

while (true) {
line = in.nextLine();
if (line.equals("bye")) {
return;

Choose a reason for hiding this comment

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

In general, we do not use a return statement in a void function. If you want to break out of the current loop, use the "break" statement instead.

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.

4 participants