[JonathanOngJoe] iP#175
Conversation
Li-JunXian
left a comment
There was a problem hiding this comment.
Great work overall, your code has a very clear logic chain. It feels very smooth reading it.
src/main/java/BobChat.java
Outdated
| class Task { | ||
| private final String description; | ||
| private boolean isDone; | ||
|
|
||
| public Task(String description) { | ||
| this.description = description; | ||
| this.isDone = false; | ||
| } | ||
|
|
||
| public void markAsDone() { | ||
| isDone = true; | ||
| } | ||
|
|
||
| public void markAsNotDone() { | ||
| isDone = false; | ||
| } | ||
|
|
||
| public String getStatusIcon() { | ||
| return (isDone ? "[X] " : "[ ] ") + description; | ||
| } | ||
| } |
There was a problem hiding this comment.
Well coded! Simple and straight forward, maybe perhaps we can try creating a separate class file for "Task" so everything is not placed in one single java file.
src/main/java/BobChat.java
Outdated
| private int taskCount = 0; | ||
|
|
||
| public void start() { | ||
| System.out.println("____________________________________________________________"); |
There was a problem hiding this comment.
Perhaps the horizontal lines can be assigned to a variable for easier reference and usage in the future as compared to inputting it every time.
src/main/java/BobChat.java
Outdated
| } | ||
| System.out.println("____________________________________________________________"); | ||
| } else if (input.startsWith("mark ")) { | ||
| int index = Integer.parseInt(input.substring(5)) - 1; |
There was a problem hiding this comment.
I think it will be much more clearer to include comments on the meaning of "input.substring(5)) - 1" statement so that when looking back on the code in the future, everyone will understand the significance of the "- 1" for instance.
src/main/java/BobChat.java
Outdated
| tasks[index].markAsNotDone(); | ||
| System.out.println("____________________________________________________________"); | ||
| System.out.println(" OK, I've marked this task as not done yet:"); | ||
| System.out.println(" " + tasks[index].getStatusIcon()); |
There was a problem hiding this comment.
I think it is best not to start a System.out.printlin with a space or a tab, perhaps you can place the space and tab at the previous print statement's tail.
src/main/java/BobChat.java
Outdated
| System.out.println("____________________________________________________________"); | ||
| } else if (input.startsWith("mark ")) { | ||
| int index = Integer.parseInt(input.substring(5)) - 1; | ||
| if (index >= 0 && index < taskCount) { |
There was a problem hiding this comment.
I think this line appears quite often, perhaps we could position this line with the higher-up if statement so that it can be checked earlier for the program to determine if it is a valid input or not and then execute the correct corresponding actions without doing any redundant work.
Deanson-Choo
left a comment
There was a problem hiding this comment.
Good Job Overall! A few touchups will do!
src/main/java/BobChat.java
Outdated
| @@ -0,0 +1,97 @@ | |||
| import java.util.Scanner; | |||
|
|
|||
| class Task { | |||
There was a problem hiding this comment.
Maybe you can consider defining your classes such as Task in a separate file.
| while (true) { | ||
| input = scanner.nextLine(); | ||
|
|
||
| if (input.equalsIgnoreCase("bye")) { | ||
| break; | ||
| } else if (input.equalsIgnoreCase("list")) { | ||
| System.out.println("____________________________________________________________"); | ||
| System.out.println(" Here are the tasks in your list:"); | ||
| if (taskCount == 0) { | ||
| System.out.println(" No tasks added yet."); | ||
| } else { | ||
| for (int i = 0; i < taskCount; i++) { | ||
| System.out.println((i + 1) + ". " + tasks[i].getStatusIcon()); | ||
| } | ||
| } | ||
| System.out.println("____________________________________________________________"); | ||
| } else if (input.startsWith("mark ")) { | ||
| int index = Integer.parseInt(input.substring(5)) - 1; | ||
| if (index >= 0 && index < taskCount) { | ||
| tasks[index].markAsDone(); | ||
| System.out.println("____________________________________________________________"); | ||
| System.out.println(" Nice! I've marked this task as done:"); | ||
| System.out.println(" " + tasks[index].getStatusIcon()); | ||
| System.out.println("____________________________________________________________"); | ||
| } | ||
| } else if (input.startsWith("unmark ")) { | ||
| int index = Integer.parseInt(input.substring(7)) - 1; | ||
| if (index >= 0 && index < taskCount) { | ||
| tasks[index].markAsNotDone(); | ||
| System.out.println("____________________________________________________________"); | ||
| System.out.println(" OK, I've marked this task as not done yet:"); | ||
| System.out.println(" " + tasks[index].getStatusIcon()); | ||
| System.out.println("____________________________________________________________"); | ||
| } | ||
| } else { | ||
| if (taskCount < 100) { | ||
| tasks[taskCount++] = new Task(input); | ||
| System.out.println("____________________________________________________________"); | ||
| System.out.println(" added: " + input); | ||
| System.out.println("____________________________________________________________"); | ||
| } else { | ||
| System.out.println(" Task list is full!"); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Perhaps you can consider adding another class to manage your tasks to neaten the code
src/main/java/BobChat.java
Outdated
| public void markAsDone() { | ||
| isDone = true; | ||
| } | ||
|
|
||
| public void markAsNotDone() { | ||
| isDone = false; | ||
| } | ||
|
|
||
| public String getStatusIcon() { | ||
| return (isDone ? "[X] " : "[ ] ") + description; | ||
| } | ||
| } |
There was a problem hiding this comment.
Perhaps you can consider combining markAsNotDone and markAsDone under a single function such as setStatus. Also, should there be a getter function for description and isDone?
src/main/java/BobChat.java
Outdated
| private int taskCount = 0; | ||
|
|
||
| public void start() { | ||
| System.out.println("____________________________________________________________"); |
There was a problem hiding this comment.
Perhaps considering assigning the horizontal line to a variable for easier usage
| while (true) { | ||
| input = scanner.nextLine(); | ||
|
|
||
| if (input.equalsIgnoreCase("bye")) { | ||
| break; | ||
| } else if (input.equalsIgnoreCase("list")) { | ||
| System.out.println("____________________________________________________________"); | ||
| System.out.println(" Here are the tasks in your list:"); | ||
| if (taskCount == 0) { | ||
| System.out.println(" No tasks added yet."); | ||
| } else { | ||
| for (int i = 0; i < taskCount; i++) { | ||
| System.out.println((i + 1) + ". " + tasks[i].getStatusIcon()); | ||
| } | ||
| } | ||
| System.out.println("____________________________________________________________"); | ||
| } else if (input.startsWith("mark ")) { | ||
| int index = Integer.parseInt(input.substring(5)) - 1; | ||
| if (index >= 0 && index < taskCount) { | ||
| tasks[index].markAsDone(); | ||
| System.out.println("____________________________________________________________"); | ||
| System.out.println(" Nice! I've marked this task as done:"); | ||
| System.out.println(" " + tasks[index].getStatusIcon()); | ||
| System.out.println("____________________________________________________________"); | ||
| } | ||
| } else if (input.startsWith("unmark ")) { | ||
| int index = Integer.parseInt(input.substring(7)) - 1; | ||
| if (index >= 0 && index < taskCount) { | ||
| tasks[index].markAsNotDone(); | ||
| System.out.println("____________________________________________________________"); | ||
| System.out.println(" OK, I've marked this task as not done yet:"); | ||
| System.out.println(" " + tasks[index].getStatusIcon()); | ||
| System.out.println("____________________________________________________________"); | ||
| } | ||
| } else { | ||
| if (taskCount < 100) { | ||
| tasks[taskCount++] = new Task(input); | ||
| System.out.println("____________________________________________________________"); | ||
| System.out.println(" added: " + input); | ||
| System.out.println("____________________________________________________________"); | ||
| } else { | ||
| System.out.println(" Task list is full!"); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Perhaps you can consider adding comments to each of your conditions too!
src/main/java/BobChat.java
Outdated
| try { | ||
| switch (command) { | ||
| case "bye": | ||
| System.out.println("____________________________________________________________"); |
There was a problem hiding this comment.
Since this line of code is repeating at multiple instances, you might want to save it in a variable or make it a function which you can reference.
src/main/java/BobChat.java
Outdated
| private final Scanner scanner = new Scanner(System.in); | ||
| private final ArrayList<Task> tasks = new ArrayList<>(); | ||
|
|
||
| public void start() throws InputExceptions { |
There was a problem hiding this comment.
Avoid lengthy methods. try to keep each method to about 30 lines of code.
Branch level 7
Merging A-Assertions
Merge A-Code-Quality
Branch level 9 + Java Docs
A-UserGuide
editted A-UserGuide
Branch level 9
minor changes to JavaDoc
No description provided.