Skip to content

[Shawn Tan Jinhui] iP#56

Open
GitPancaked wants to merge 27 commits into
nus-cs2113-AY2223S1:masterfrom
GitPancaked:master
Open

[Shawn Tan Jinhui] iP#56
GitPancaked wants to merge 27 commits into
nus-cs2113-AY2223S1:masterfrom
GitPancaked:master

Conversation

@GitPancaked

Copy link
Copy Markdown

No description provided.

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

Looks good! You should check the names of constants

Comment thread src/main/java/Duke.java Outdated
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";

static String logo = " ____ _ \n"

@bdthanh bdthanh Aug 31, 2022

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should add private to be clearer and constant name should be writen in uppercase LOGO

Comment thread src/main/java/Duke.java Outdated
System.out.println(linebreak);
}

static void markTasks(ArrayList<Task> Tasks, String text) {

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 function should be writen in class Task

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

Overall good job, but I think some things are overcomplicated

Comment thread src/main/java/Duke.java Outdated
else if (result[0].equals("event")) {
newEvent = new Event(result3[0].substring(6), result3[1]);
Tasks.add(newEvent);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Have an else statement to catch any incorrect inputs here

Comment thread src/main/java/Duke.java Outdated
Comment on lines +48 to +56
if (result[0].equals("todo")) {
System.out.println(newTodo);
}
else if (result[0].equals("deadline")) {
System.out.println(newDeadline);
}
else if (result[0].equals("event")) {
System.out.println(newEvent);
}

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 should be able to just print out tasks using a to string method instead of rechecking.

Comment thread src/main/java/Duke.java Outdated
int count = 1;
for (Task i : Tasks) {
System.out.println(String.valueOf(count) + "." + "[" + i.getStatusIcon() + "] " + i.getDescription());
System.out.println(String.valueOf(count) + "." + 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 don't need valueOf, you can just do count+"."+i

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

public String toString() {
return "[" + this.getStatusIcon() + "] " + this.getDescription();

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 just use description instead of this.getDescription

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

Good job so far!

Comment thread src/main/java/Duke.java Outdated
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";

static String logo = " ____ _ \n"

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 may want to consider setting the logo to be of type private static final. Constant names should be in capital letters.

Comment thread src/main/java/Duke.java Outdated
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
static String linebreak = "____________________________________________________________";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same as above for this, you can consider making the type private static final and capitalise "linebreak"

Comment thread src/main/java/Duke.java Outdated
line = in.nextLine();

while (!line.equals("bye")) {
if (line.length() > 3 && line.substring(0, 4).equals("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.

Comment thread src/main/java/Duke.java Outdated
while (!line.equals("bye")) {
if (line.length() > 3 && line.substring(0, 4).equals("mark")) {
markTasks(Tasks, line);
} else if (line.length() > 4 && line.substring(0, 6).equals("unmark")) {

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 consider removing the magic number 4 and making it a named constant

Comment thread src/main/java/Duke.java Outdated
Comment on lines +27 to +46
static void storeTasks(ArrayList<Task> Tasks, String text) {
System.out.println(linebreak);
String[] result = text.split(" ");
String[] result2 = text.split("/by ");
String[] result3 = text.split("/at ");
Todo newTodo = null;
Deadline newDeadline = null;
Event newEvent = null;
if (result[0].equals("todo")) {
newTodo = new Todo(result[1]);
Tasks.add(newTodo);
}
else if (result[0].equals("deadline")) {
newDeadline = new Deadline(result2[0].substring(9), result2[1]);
Tasks.add(newDeadline);
}
else if (result[0].equals("event")) {
newEvent = new Event(result3[0].substring(6), result3[1]);
Tasks.add(newEvent);
}

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 may want to adhere to SLAP and shift this to a new class

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

There are a few issues related to coding standards and code readability as indicated in individual comments. Try to improve on those aspects.

Comment thread src/main/java/Deadline.java Outdated
@@ -0,0 +1,14 @@
public class Deadline extends 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.

Consider adding header comments to non-trivial classes and methods

Comment thread src/main/java/Deadline.java Outdated
@@ -0,0 +1,14 @@
public class Deadline extends Task {

protected String by;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why is this protected?

Comment thread src/main/java/Duke.java Outdated
Comment on lines +38 to +48
if (line.length() > 3 && line.startsWith("mark")) {

Manager.markTasks(line);
} else if (line.length() > 4 && line.startsWith("unmark")) {
Manager.unmarkTasks(line);
} else if (line.equals("list")) {
Manager.printTasks();
} else {
Manager.storeTasks(line);
}
line = in.nextLine();

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 improve SLAP here by extracting out some of the parsing to a different class (or minimally different method)

Comment thread src/main/java/DukeExceptions.java Outdated
@@ -0,0 +1,2 @@
public abstract class DukeExceptions {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hmmm... just a DukeExceptions may not mean anything much. If you are intending to write custom exceptions, consider extending the Exceptions class.

Comment thread src/main/java/Event.java Outdated
Comment on lines +1 to +14
public class Event extends Task {

protected String at;

public Event(String description, String at) {
super(description);
this.at = at;
}

@Override
public String toString() {
return "[E]" + super.toString() + "(at: " + at + ")";
}
} No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Similar comments as Deadline class

Comment thread src/main/java/TaskManager.java Outdated
Comment on lines +34 to +51
}
else if (result[0].equals("deadline")) {
try {
String x=result[1];
}
catch (IndexOutOfBoundsException e) {
System.out.println("Deadlines, that's all life's about, but you gotta tell me which!");
return;
}
newDeadline = new Deadline(result2[0].substring(9), result2[1]);
Tasks.add(newDeadline);
}
else if (result[0].equals("event")) {
try {
String x=result[1];
}
catch (IndexOutOfBoundsException e) {
System.out.println("Which event? Personally I find an uneventful life to be the key to longevity");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

if ... else and try ... catch violate our coding standards

Comment thread src/main/java/TaskManager.java Outdated
Comment on lines +24 to +32
if (result[0].equals("todo")) {
try {
String x=result[1];
}
catch (IndexOutOfBoundsException e) {
System.out.println("Much ado about nothing");
return;
}
newTodo = new Todo(result[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.

You can try to extract out parsing things to a separate method and improve SLAP here

Comment thread src/main/java/TaskManager.java Outdated
Comment on lines +18 to +20
String[] result = text.split(" ");
String[] result2 = text.split("/by ");
String[] result3 = text.split("/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.

bad SLAP here; remember the usage of specific methods in the TaskS repo used in Lecture 6? that should give you an idea how to improve SLAP.

Comment thread src/main/java/TaskManager.java Outdated
System.out.println("Deadlines, that's all life's about, but you gotta tell me which!");
return;
}
newDeadline = new Deadline(result2[0].substring(9), result2[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.

always better to have clean, named variables for things you are passing as parameters; try to improve readability.

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.

5 participants