-
Notifications
You must be signed in to change notification settings - Fork 77
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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
src/main/java/Duke.java
Outdated
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
|
||
static String logo = " ____ _ \n" |
There was a problem hiding this comment.
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
src/main/java/Duke.java
Outdated
System.out.println(linebreak); | ||
} | ||
|
||
static void markTasks(ArrayList<Task> Tasks, String text) { |
There was a problem hiding this comment.
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
There was a problem hiding this 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
src/main/java/Duke.java
Outdated
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.
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
src/main/java/Duke.java
Outdated
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.
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.
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); |
There was a problem hiding this comment.
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
src/main/java/Task.java
Outdated
@@ -30,4 +30,8 @@ public void setNotDone() { | |||
public void setDescription(String description) { | |||
this.description = description; | |||
} | |||
|
|||
public String toString() { | |||
return "[" + this.getStatusIcon() + "] " + this.getDescription(); |
There was a problem hiding this comment.
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
There was a problem hiding this 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!
src/main/java/Duke.java
Outdated
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
|
||
static String logo = " ____ _ \n" |
There was a problem hiding this comment.
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.
src/main/java/Duke.java
Outdated
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
static String linebreak = "____________________________________________________________"; |
There was a problem hiding this comment.
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"
src/main/java/Duke.java
Outdated
line = in.nextLine(); | ||
|
||
while (!line.equals("bye")) { | ||
if (line.length() > 3 && line.substring(0, 4).equals("mark")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should avoid complicated expressions as per https://nus-cs2113-ay2223s1.github.io/website/se-book-adapted/chapters/codeQuality.html
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")) { |
There was a problem hiding this comment.
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
src/main/java/Duke.java
Outdated
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.
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
There was a problem hiding this 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.
src/main/java/Deadline.java
Outdated
@@ -0,0 +1,14 @@ | |||
public class Deadline extends Task { |
There was a problem hiding this comment.
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
src/main/java/Deadline.java
Outdated
@@ -0,0 +1,14 @@ | |||
public class Deadline extends Task { | |||
|
|||
protected String by; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this protected?
src/main/java/Duke.java
Outdated
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.
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)
src/main/java/DukeExceptions.java
Outdated
@@ -0,0 +1,2 @@ | |||
public abstract class DukeExceptions { |
There was a problem hiding this comment.
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.
src/main/java/Event.java
Outdated
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 + ")"; | ||
} | ||
} |
There was a problem hiding this comment.
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
src/main/java/TaskManager.java
Outdated
} | ||
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.
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
src/main/java/TaskManager.java
Outdated
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.
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
src/main/java/TaskManager.java
Outdated
String[] result = text.split(" "); | ||
String[] result2 = text.split("/by "); | ||
String[] result3 = text.split("/at "); |
There was a problem hiding this comment.
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.
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]); |
There was a problem hiding this comment.
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.
branch-A-JavaDoc
…nputted by the user
No description provided.