Skip to content

[Wang Chuhan] ip#179

Open
Vincent6896 wants to merge 29 commits intonus-cs2113-AY2122S1:masterfrom
Vincent6896:master
Open

[Wang Chuhan] ip#179
Vincent6896 wants to merge 29 commits intonus-cs2113-AY2122S1:masterfrom
Vincent6896:master

Conversation

@Vincent6896
Copy link
Copy Markdown

No description provided.

Comment thread src/main/java/List.java Outdated
@@ -0,0 +1,81 @@
import java.lang.String;

public class List {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I wouldn't recommend calling your class List - there's already a provided class within Java called List, and this could prove very confusing to readers. You might want to consider changing the name of this class to something else.

Comment thread src/main/java/List.java Outdated
Comment on lines +34 to +36
+ task.substring(task.indexOf(" "), task.indexOf("/"))
+ "(" + task.substring(task.indexOf("/") + 1, task.indexOf("/") + 3)
+ ": " + task.substring(task.indexOf("/") + 4) + ")";
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 section looks quite confusing - what are the +1 and +3 and +4 doing there - what do they mean? You might want to define these magic variables before using them.

Comment thread src/main/java/List.java Outdated
public static void doneTask(String task) {
task = task.trim();
String str = "";
if (task != null && !"".equals(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.

You could consider replacing "".equals(task) with task.isEmpty() - it reads more sensibly.

Comment thread src/main/java/List.java Outdated
System.out.println(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n "
+ "Here are the tasks in your list:");
for (int i = 0; i < count; i++) {
System.out.println(" " + list[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.

You could consider defining some variable to deal with the huge block of spaces inside your println.

Comment thread src/main/java/List.java Outdated
public class List {

public static String[] list = new String[100];
public static String[] done = new String[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.

Would be good to rename done to something like doneList

Comment thread src/main/java/Duke.java Outdated
+ " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
while (true) {
Scanner in = new Scanner(System.in);
String order;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

variable name order does not break the coding standard but it seems very unintuitive to me, a better name would be maybe input or task

Comment thread src/main/java/Duke.java Outdated
List.addTask(order);
if (order.equals("list")) {
List.printTask();
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can consider using case inside of multiple ifs

Comment thread src/main/java/List.java Outdated
+ task.substring(task.indexOf(" "));
}
count++;
if (count == 1) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

can consider putting this whole chunk in a method to reduce repeating statements

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 also use variables to represent the repeated print statements

Copy link
Copy Markdown

@iamabhishek98 iamabhishek98 left a comment

Choose a reason for hiding this comment

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

I have added my suggestions. Please note that although I have not repeated myself, what I have commented in one place applies to the rest of the codebase as well.

Comment thread src/main/java/duke/Duke.java Outdated
}
System.out.println(SPLIT_LINE);
System.out.println(" Got it. I've added this task:");
System.out.println(" " + list.get(list.size() - 1));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Avoid having such nested logic in print statements as the purpose of print statements is only to print and not do anything else. Seperate this out into separate lines

Comment thread src/main/java/duke/Duke.java Outdated
Comment on lines +154 to +183
if (tasks[i].contains("X")) {
Todo todo = new Todo(description);
todo.description = todo.description.replaceFirst(" ", "X");
todo.isDone = true;
list.add(todo);
} else {
list.add(new Todo(description));
}
continue;
case "D":
String by = tasks[i].substring(tasks[i].indexOf(":") + 2, tasks[i].indexOf(")"));
if (tasks[i].contains("X")) {
Deadline deadline = new Deadline(description.substring(0, description.indexOf("(") - 1), by);
deadline.description = deadline.description.replaceFirst(" ", "X");
deadline.isDone = true;
list.add(deadline);
} else {
list.add(new Deadline(description.substring(0, description.indexOf("(") - 1), by));
}
continue;
case "E":
String at = tasks[i].substring(tasks[i].indexOf(":") + 2, tasks[i].indexOf(")"));
if (tasks[i].contains("X")) {
Event event = new Event(description.substring(0, description.indexOf("(") - 1), at);
event.description = event.description.replaceFirst(" ", "X");
event.isDone = true;
list.add(event);
} else {
list.add(new Event(description.substring(0, description.indexOf("(") - 1), at));
}
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 abstracting out the logic of each switch case statement into separate functions

Comment thread src/main/java/duke/Duke.java Outdated
event.isDone = true;
list.add(event);
} else {
list.add(new Event(description.substring(0, description.indexOf("(") - 1), at));
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 mentioned before, do not use nested logic like this as it makes code extremely hard to read.

Comment thread src/main/java/duke/Duke.java Outdated
switch (tasks[i].substring(2, 3)) {
case "T":
Todo todo = new Todo(description);
todo.description = todo.description.replaceFirst(" ", "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.

Avoid magic strings like "X" - extract them out as constants and name them appropriately using proper naming conventions

Comment thread src/main/java/duke/Duke.java Outdated
}

public static void printDoneList() {
if (doneList.size() == 0) {
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 can also do something like:
if (!doneList.size()) {
}

protected boolean isDone;

public List(String description) {
this.description = "[ ] " + description;
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 mentioned earlier, avoid magic strings like "[ ] "

Comment thread src/main/java/duke/Duke.java Outdated
Comment on lines +271 to +276
if (task != null && !"".equals(task)) {
for (int i = 0; i < task.length(); i++) {
if (task.charAt(i) >= 48 && task.charAt(i) <= 57) {
str = str + task.charAt(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.

Having so many nested if statements and loops can be hard to read. Consider abstracting it out into a different function

chuhan wang added 2 commits October 1, 2021 12:14
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