Conversation
Add coding standards
Add Event.java Add ToDo.java
lamkwjonathan
left a comment
There was a problem hiding this comment.
Overall quite nicely done. Just watch out for camelCase when naming methods.
src/main/java/Duke.java
Outdated
| String input; | ||
| Scanner in = new Scanner(System.in); | ||
| int counter = 0; | ||
| Task[] list = new Task[100]; |
There was a problem hiding this comment.
Perhaps 'tasks' is a more appropriate name, since it is plural.
src/main/java/Duke.java
Outdated
| PrintGoodbyeMessage(); | ||
| } | ||
|
|
||
| private static void ActiveChat() { |
There was a problem hiding this comment.
I think 'ActiveChat' should be 'activeChat' instead, since methods should be in camelCase.
src/main/java/Duke.java
Outdated
| } | ||
| } | ||
|
|
||
| private static void CheckIsEmptyList(Task[] list) { |
There was a problem hiding this comment.
'checkIsEmptyList' for 'CheckIsEmptyList', or perhaps even just 'isEmptyList' for boolean naming.
Similar camelCase method naming issues in other places as well.
src/main/java/Duke.java
Outdated
| System.out.println("--------------------"); | ||
| System.out.println("Got it. I've added this task: "); | ||
| System.out.println("[" + task.getLetter() + "] " | ||
| + "[" + task.getStatusIcon() + "] " |
| this.description = description; | ||
| this.isDone = false; | ||
| } | ||
|
|
There was a problem hiding this comment.
Perhaps it will be cleaner to override the .toString() method to return the entire [T][ ] task name string, instead of needing separate public getLetter() and getStatusIcon() methods.
public String toString() {
String checkbox = isCompleted ? "[X]" : "[ ]";
return checkbox + " " + taskName;
}
It is also possible to further override the function in the subclasses.
Example for Deadline subclass
@Override
public String toString() {
String checkbox = isCompleted ? "[X]" : "[ ]";
return "[D]" + super.toString() + " " + "(by: " + by + ")";
}
src/main/java/Duke.java
Outdated
| } | ||
|
|
||
| private static int ProcessTasks(String input, int counter, Task[] list) { | ||
| if (input.contains("todo")) { |
There was a problem hiding this comment.
It might be cleaner to replace the strings "todo", "deadline", etc. with named constants of type static final String
src/main/java/Duke.java
Outdated
| return counter; | ||
| } | ||
|
|
||
| private static void PrintDoneMessage(Task[] list, int itemNum) { |
There was a problem hiding this comment.
Nice use of specific PrintMessage methods to keep the overall code cleaner and easier to understand
src/main/java/Duke.java
Outdated
| private static void PrintDoneMessage(Task[] list, int itemNum) { | ||
| System.out.println("--------------------"); | ||
| System.out.println("Nice! I've marked this task as done:"); | ||
| System.out.println( itemNum + ".[" + list[itemNum - 1].getStatusIcon() + "] " + list[itemNum - 1].getDescription() ); |
There was a problem hiding this comment.
Linked to the comment on overriding the .toString() method in Task. By doing so, this part of code can be simplified to
System.out.println( itemNum + "." + list[itemNum - 1])
src/main/java/Duke.java
Outdated
| int donePos = input.indexOf("/"); //finds pos of '/' | ||
| String description = input.substring(9,donePos); | ||
| String date = input.substring(donePos + 4); | ||
| Deadline newTask = new Deadline(description,date); | ||
| list[counter] = newTask; | ||
| counter += 1; | ||
| PrintAddedTaskMessage(newTask, counter); |
There was a problem hiding this comment.
It might be cleaner to refactor this into a separate method.
One way is to have additional methods in the Duke class that handles the different Task subclasses.
Another is to create a separate class TaskManager that stores the array of Tasks and has functions to add the different Task subclasses to keep the main Duke class clean. (I think this will be the best approach)
Another is to overload the subclass constructors to take in String[] or a similar data structure.
Add exceptions Improve code quality
ongweisheng
left a comment
There was a problem hiding this comment.
Generally well done, do take note if comments are unnecessary do remove them and see if you can abstract more of your code
src/main/java/duke/Duke.java
Outdated
| // Welcome Message | ||
| printWelcomeMessage(); | ||
|
|
||
| // Active Chat | ||
| activeChat(); | ||
|
|
||
| // Goodbye Message | ||
| printGoodbyeMessage(); | ||
| } |
There was a problem hiding this comment.
Note if the comments are necessary, else remove them if they are not
src/main/java/duke/Duke.java
Outdated
| private static void activeChat() { | ||
| boolean isBye = false; | ||
| String input; | ||
| Scanner in = new Scanner(System.in); | ||
| int counter = 0; | ||
| Task[] list = new Task[100]; | ||
|
|
||
| while(!isBye){ | ||
| //store input | ||
| input = in.nextLine(); | ||
| //process input | ||
| if (input.equals("bye")){ //check if bye | ||
| isBye = true; | ||
| } else if (input.equals("list")) { //check if list | ||
| processList(counter, list); | ||
| } else if (input.contains("done") ) { //check if done | ||
| processDone(input, list); | ||
| } else { | ||
| try { | ||
| counter = processTasks(input, counter, list); //process tasks | ||
| } catch ( IllegalTaskException e ) { | ||
| System.out.println("Please include /by for deadline and /at for event"); | ||
| } | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Consider implementing a Parser class to parse user inputs instead of putting everything in main/Duke
src/main/java/duke/Duke.java
Outdated
| private static void processList(int counter, Task[] list) { | ||
| if (list[0] != null){ | ||
| printListMessage(counter, list); | ||
| } else { | ||
| printListButEmptyMessage(); | ||
| } | ||
| } | ||
|
|
||
| private static void processDone(String input, Task[] list) { | ||
| int donePos = input.indexOf("done"); | ||
| if (list[0] != null) { | ||
| if (input.length() < donePos + 5) { | ||
| printDoneButNotSpecificMessage(); //when input contains done but no number | ||
| } else { | ||
| processValidDone(input, list, donePos); //when input contains done and specified number | ||
| } | ||
| } else { | ||
| printDoneButEmptyMessage(); //when input contains done but list is empty | ||
| } | ||
| } | ||
|
|
||
| private static void processValidDone(String input, Task[] list, int donePos) { | ||
| String itemNumDone = input.substring(donePos + 5, donePos + 6); | ||
| int itemNum = Integer.parseInt(itemNumDone); | ||
| list[itemNum - 1].setDone(); | ||
| printDoneMessage(list, itemNum); | ||
| } | ||
|
|
||
| private static int processTasks(String input, int counter, Task[] list) throws IllegalTaskException{ | ||
| if ( ( input.contains("deadline") || input.contains("event") ) && !input.contains("/")){ | ||
| throw new IllegalTaskException(); | ||
| } | ||
| if (input.contains("todo")) { | ||
| String description = input.substring(5); | ||
| ToDo newTask = new ToDo(description); | ||
| list[counter] = newTask; | ||
| counter += 1; | ||
| printAddedTaskMessage(newTask, counter); | ||
| } else if (input.contains("deadline")) { | ||
| int donePos = input.indexOf("/"); //finds pos of '/' | ||
| String description = input.substring(9,donePos); | ||
| if (!input.substring(donePos + 1, donePos + 3).equals("by")) { | ||
| throw new IllegalTaskException(); | ||
| } | ||
| String date = input.substring(donePos + 4); | ||
| Deadline newTask = new Deadline(description,date); | ||
| list[counter] = newTask; | ||
| counter += 1; | ||
| printAddedTaskMessage(newTask, counter); | ||
| } else if (input.contains("event")) { | ||
| int donePos = input.indexOf("/"); //finds pos of '/' | ||
| String description = input.substring(6,donePos); | ||
| if (!input.substring(donePos + 1, donePos + 3).equals("by")) { | ||
| throw new IllegalTaskException(); | ||
| } | ||
| String date = input.substring(donePos + 4); | ||
| Event newTask = new Event(description,date); | ||
| list[counter] = newTask; | ||
| counter += 1; | ||
| printAddedTaskMessage(newTask, counter); | ||
| } else { | ||
| System.out.println("Please specify tasks: todo, deadline or event"); | ||
| System.out.println("Example - type in the following: todo read book"); | ||
| } | ||
| return counter; | ||
| } |
There was a problem hiding this comment.
Consider creating TaskManger class to handle task manipulation as well as storing their data for your task list
src/main/java/duke/Duke.java
Outdated
| private static void printDoneMessage(Task[] list, int itemNum) { | ||
| System.out.println("--------------------"); | ||
| System.out.println("Nice! I've marked this task as done:"); | ||
| System.out.println( itemNum + ".[" + list[itemNum - 1].getStatusIcon() + "] " + list[itemNum - 1].getDescription() ); | ||
| System.out.println("--------------------"); | ||
| } | ||
|
|
||
| private static void printListMessage(int counter, Task[] list) { | ||
| System.out.println("--------------------"); | ||
| System.out.println("Here are the tasks in your list:"); | ||
| for(int i = 0; i < counter; i += 1){ | ||
| printListOfTaskSubMessage(list[i], i); | ||
| } | ||
| System.out.println("--------------------"); | ||
| } | ||
|
|
||
| private static void printListButEmptyMessage() { | ||
| System.out.println("--------------------"); | ||
| System.out.println("List is empty. Time to get productive!"); | ||
| System.out.println("--------------------"); | ||
| } | ||
|
|
||
| private static void printDoneButNotSpecificMessage() { | ||
| System.out.println("Please specify which task is done."); | ||
| } | ||
|
|
||
| private static void printDoneButEmptyMessage() { | ||
| System.out.println("--------------------"); | ||
| System.out.println("Unable to tick off list."); | ||
| System.out.println("List is empty. Time to get productive!"); | ||
| System.out.println("--------------------"); | ||
| } | ||
|
|
||
| private static void printAddedTaskMessage(Task task, int i) { | ||
| System.out.println("--------------------"); | ||
| System.out.println("Got it. I've added this task: "); | ||
| System.out.println("[" + task.getLetter() + "] " | ||
| + "[" + task.getStatusIcon() + "] " | ||
| + task.getDescription() | ||
| + task.getDate() ); | ||
| System.out.println("Now you have " + i + " tasks in the list."); | ||
| System.out.println("--------------------"); | ||
| } | ||
|
|
||
| private static void printListOfTaskSubMessage(Task task, int i) { | ||
| System.out.println(i + 1 | ||
| + ".[" + task.getLetter() + "] " | ||
| + "[" + task.getStatusIcon() + "] " | ||
| + task.getDescription() | ||
| + task.getDate() ); | ||
| } | ||
|
|
||
| private static void printGoodbyeMessage() { | ||
| System.out.println("--------------------"); | ||
| System.out.println("Bye. Hope to see you again soon!"); | ||
| System.out.println(" "); | ||
| System.out.println("--------------------"); | ||
| } | ||
|
|
||
| private static void printWelcomeMessage() { | ||
| String logo = " ____ _ \n" | ||
| + "| _ \\ _ _| | _____ \n" | ||
| + "| | | | | | | |/ / _ \\\n" | ||
| + "| |_| | |_| | < __/\n" | ||
| + "|____/ \\__,_|_|\\_\\___|\n"; | ||
| System.out.println("Hello from\n" + logo); | ||
|
|
||
| System.out.println("--------------------"); | ||
| System.out.println("Hello! I'm Duke"); | ||
| System.out.println("What can I do for you?"); | ||
| System.out.println(" "); | ||
| System.out.println("--------------------"); | ||
| } | ||
| } |
There was a problem hiding this comment.
Consider creating a UI class to handle your print statements instead
src/main/java/duke/Event.java
Outdated
| package duke; | ||
|
|
||
| public class Event extends Task{ | ||
|
|
||
| protected final static char LETTER = 'E'; | ||
| protected String date; | ||
|
|
||
| public Event(String description, String date) { | ||
| super(description); | ||
| this.date = date; | ||
| } | ||
|
|
||
| public String toString() { | ||
| return description; | ||
| } | ||
|
|
||
| public char getLetter() { | ||
| return LETTER; | ||
| } | ||
|
|
||
| public String getDate() { | ||
| return "(at: " + date + ")"; | ||
| } | ||
|
|
||
|
|
||
| } |
There was a problem hiding this comment.
Consider creating packages for your Event, Todo classes etc.
Add Level 7. Save
Add find functions
Add JavaDoc
Add Level 5
No description provided.