[Sim Jia Ming] iP#316
Conversation
tyanhan
left a comment
There was a problem hiding this comment.
Good job overall, I did not notice any basic styling errors. You can improve your code by breaking down long parts into separate functions. All the best!
| } | ||
|
|
||
| @Override | ||
| String getSym() { |
There was a problem hiding this comment.
I would opt for a more intuitive name rather than sym.
There was a problem hiding this comment.
I would opt for a more intuitive name rather than sym.
Maybe you can change it to a more descriptive name such as symbol?
| String phrase = sc.nextLine(); | ||
| System.out.println(DASH); | ||
|
|
||
| if (phrase.equals("list")) { |
There was a problem hiding this comment.
Perhaps you can consider using a switch statement instead?
There was a problem hiding this comment.
The code here is pretty long, but you will get to break it down later as you progress with the iP. Consider doing the printing in separate functions and get your switch statement to invoke those print functions instead.
| String noOfTask = String.format("Now you have %d tasks in the list.", arrlst.size()); | ||
| System.out.println(noOfTask); | ||
| } | ||
| } catch (ArrayIndexOutOfBoundsException aioobe) { // echo |
There was a problem hiding this comment.
You can consider changing the parameter name to just e instead.
| @@ -0,0 +1,45 @@ | |||
| public class Task { | |||
There was a problem hiding this comment.
It is possible to change Task to an abstract class?
| @@ -0,0 +1,35 @@ | |||
| import java.util.ArrayList; | |||
|
|
|||
| public class Action { | |||
| } | ||
|
|
||
| @Override | ||
| String getSym() { |
There was a problem hiding this comment.
I would opt for a more intuitive name rather than sym.
Maybe you can change it to a more descriptive name such as symbol?
| System.out.println("Hello from\n" + logo); | ||
| Scanner sc = new Scanner(System.in); | ||
| ArrayList<Task> arrlst = new ArrayList<>(); | ||
| String DASH = "____________________________________________________________"; |
There was a problem hiding this comment.
This works too, but UI can be separated into a class for cleanliess
jetrz
left a comment
There was a problem hiding this comment.
Generally clean code, well documented, styled, and easy to understand. Only minor nitpicks in terms of documentation and code logic here and there. Well done!
| public Task(String description) { | ||
| this.description = description; | ||
| this.isDone = false; | ||
| this.sym = " "; | ||
| } | ||
|
|
||
| public Task(String description, String sym) { | ||
| this.description = description; | ||
| this.isDone = false; | ||
| this.sym = sym; | ||
| } | ||
|
|
||
| public String getStatusIcon() { | ||
| return (isDone ? "X" : " "); // mark done task with X | ||
| } | ||
|
|
||
| public void markAsDone() { | ||
| this.isDone = true; | ||
| System.out.println("Nice! I've marked this task as done:"); | ||
| String output = String.format(" [%s][%s] %s", this.sym, this.getStatusIcon(), this.description); | ||
| System.out.println(output); | ||
| } | ||
|
|
||
| public void markAsNotDone() { | ||
| this.isDone = false; | ||
| System.out.println("OK, I've marked this task as not done yet:"); | ||
| String output = String.format(" [%s] %s", this.getStatusIcon(), this.description); | ||
| System.out.println(output); | ||
| } | ||
|
|
||
| String getSym() { | ||
| return this.sym; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return String.format("added: %s", description); | ||
| } |
There was a problem hiding this comment.
Could use some javadocs documentation as Task is the parent class.
| for (int i = 1; i < arrWords.length; i++) { | ||
| if (arrWords[i].equals("/at")) { | ||
| for (int j = i + 1; j < arrWords.length; j++) { | ||
| dayAndTime = dayAndTime + " " + arrWords[j]; | ||
| } | ||
| break; | ||
| } else { | ||
| remainingWords = remainingWords + " " + arrWords[i]; | ||
| } | ||
| } |
There was a problem hiding this comment.
Could use comments in places like these to explain what the code is doing (i.e. splitting up the user input) as it may not be apparent on first sight.
| void showList(ArrayList<Task> arrlst) { | ||
| System.out.println("Here are the tasks in your list:"); | ||
| for (int i = 0; i < arrlst.size(); i++) { | ||
| String output = String.format("%d.[%s][%s]%s\n", i + 1, arrlst.get(i).sym, | ||
| arrlst.get(i).getStatusIcon(), arrlst.get(i).description); | ||
| System.out.println(output); | ||
| } | ||
| } |
| @Override | ||
| String getSym() { | ||
| return this.sym; | ||
| } |
There was a problem hiding this comment.
May I check what is the purpose of this override? Same with deadline and todo classes. Seems redundant as the getSym() in Task is the same.
| @@ -0,0 +1,45 @@ | |||
| public class Task { | |||
| protected String description; | |||
There was a problem hiding this comment.
While protected may appear sufficient, these attributes can still be accessible by other functions once you start putting them into packages. Consider changing your attributes to private
|
|
||
| @Override | ||
| public String toString() { | ||
| return String.format("added: %s", description); |
There was a problem hiding this comment.
I think you should change your toString() method to print out the sym, isDone and description instead of this message. This can reduce code duplication in your children classes as I observed that they are using attributes in Task to form the string.
| System.out.println(output); | ||
| } | ||
|
|
||
| String getSym() { |
There was a problem hiding this comment.
Missing public keyword at function signature
|
Good effort overall. Some improvements to consider:
|
# Conflicts: # src/main/java/duke/Parser.java
Assert that isDone must be false to get " " from getStatusIcon() method.
Add update into help function
Duke frees your mind of having to remember things you need to do. It's,
FASTSUPER FAST to useAll you need to do is,
its FREE
tasklist:
Here's the main method: