[Shawn Tan Jinhui] iP#56
Conversation
bdthanh
left a comment
There was a problem hiding this comment.
Looks good! You should check the names of constants
| + "| |_| | |_| | < __/\n" | ||
| + "|____/ \\__,_|_|\\_\\___|\n"; | ||
|
|
||
| static String logo = " ____ _ \n" |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
This function should be writen in class Task
abhityakrishnaraj
left a comment
There was a problem hiding this comment.
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); | ||
| } |
There was a problem hiding this comment.
Have an else statement to catch any incorrect inputs here
| 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); | ||
| } |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
You don't need valueOf, you can just do count+"."+i
| } | ||
|
|
||
| public String toString() { | ||
| return "[" + this.getStatusIcon() + "] " + this.getDescription(); |
There was a problem hiding this comment.
You can just use description instead of this.getDescription
| + "| |_| | |_| | < __/\n" | ||
| + "|____/ \\__,_|_|\\_\\___|\n"; | ||
|
|
||
| static String logo = " ____ _ \n" |
There was a problem hiding this comment.
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 = "____________________________________________________________"; |
There was a problem hiding this comment.
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")) { |
There was a problem hiding this comment.
You should avoid complicated expressions as per https://nus-cs2113-ay2223s1.github.io/website/se-book-adapted/chapters/codeQuality.html
| 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")) { |
There was a problem hiding this comment.
You can consider removing the magic number 4 and making it a named constant
| 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); | ||
| } |
There was a problem hiding this comment.
You may want to adhere to SLAP and shift this to a new class
okkhoy
left a comment
There was a problem hiding this comment.
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 { | |||
There was a problem hiding this comment.
Consider adding header comments to non-trivial classes and methods
| @@ -0,0 +1,14 @@ | |||
| public class Deadline extends Task { | |||
|
|
|||
| protected String by; | |||
| 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(); |
There was a problem hiding this comment.
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 { | |||
There was a problem hiding this comment.
Hmmm... just a DukeExceptions may not mean anything much. If you are intending to write custom exceptions, consider extending the Exceptions class.
| 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 |
| } | ||
| 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"); |
There was a problem hiding this comment.
if ... else and try ... catch violate our coding standards
| 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]); |
There was a problem hiding this comment.
You can try to extract out parsing things to a separate method and improve SLAP here
| String[] result = text.split(" "); | ||
| String[] result2 = text.split("/by "); | ||
| String[] result3 = text.split("/at "); |
There was a problem hiding this comment.
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]); |
There was a problem hiding this comment.
always better to have clean, named variables for things you are passing as parameters; try to improve readability.
branch-A-JavaDoc
…nputted by the user
No description provided.