Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Shawn Tan Jinhui] iP #56

Open
wants to merge 27 commits into
base: master
Choose a base branch
from

Conversation

GitPancaked
Copy link

No description provided.

Copy link

@bdthanh bdthanh left a comment

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

+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";

static String logo = " ____ _ \n"
Copy link

@bdthanh bdthanh Aug 31, 2022

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

System.out.println(linebreak);
}

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

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

Copy link

@abhityakrishnaraj abhityakrishnaraj 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 job, but I think some things are overcomplicated

else if (result[0].equals("event")) {
newEvent = new Event(result3[0].substring(6), result3[1]);
Tasks.add(newEvent);
}

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 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);
}

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.

int count = 1;
for (Task i : Tasks) {
System.out.println(String.valueOf(count) + "." + "[" + i.getStatusIcon() + "] " + i.getDescription());
System.out.println(String.valueOf(count) + "." + i);

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

@@ -30,4 +30,8 @@ public void setNotDone() {
public void setDescription(String description) {
this.description = description;
}

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.

You can just use description instead of this.getDescription

Copy link

@joshuan98 joshuan98 left a comment

Choose a reason for hiding this comment

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

Good job so far!

+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";

static String logo = " ____ _ \n"

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.

+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
static String linebreak = "____________________________________________________________";

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"

line = in.nextLine();

while (!line.equals("bye")) {
if (line.length() > 3 && line.substring(0, 4).equals("mark")) {

Choose a reason for hiding this comment

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

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")) {

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 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);
}

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

Copy link

@okkhoy okkhoy left a comment

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.

@@ -0,0 +1,14 @@
public class Deadline extends Task {
Copy link

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

@@ -0,0 +1,14 @@
public class Deadline extends Task {

protected String by;
Copy link

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

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)

@@ -0,0 +1,2 @@
public abstract class DukeExceptions {
Copy link

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 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 + ")";
}
}
Copy link

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

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

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 on lines 18 to 20
String[] result = text.split(" ");
String[] result2 = text.split("/by ");
String[] result3 = text.split("/at ");
Copy link

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.

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

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