Conversation
Teanweijun
left a comment
There was a problem hiding this comment.
Overall the code looks nice. Just have a few misc improvements that could be made. Keep it up!
| String command = line.split(" ")[0]; | ||
| while (!command.equals("bye")) { | ||
| switch (command) { | ||
| case "list": | ||
| printList(tasks); | ||
| break; | ||
| case "unmark": | ||
| unmarkTask(line, tasks); | ||
| break; | ||
| case "mark": | ||
| markTask(line, tasks); | ||
| break; | ||
| case "todo": | ||
| addToDo(line, tasks); | ||
| break; | ||
| case "deadline": | ||
| addDeadline(line, tasks); | ||
| break; | ||
| case "event": | ||
| addEvent(line, tasks); | ||
| break; | ||
| default: | ||
| addTask(line, tasks); | ||
| break; | ||
| } | ||
| line = in.nextLine(); | ||
| command = line.split(" ")[0]; | ||
| } |
There was a problem hiding this comment.
Consider extracting this section into a separate method? It could make your main more readable.
| + "|____/ \\__,_|_|\\_\\___|\n"; | ||
| System.out.println("Hello from\n" + logo); | ||
| final int MAX_TASK = 100; | ||
| Task[] tasks = new Task[MAX_TASK]; |
There was a problem hiding this comment.
tasks here is a global variable... Is there a reason you have to pass them explicitly into your methods such as unmarkTask?
| + "| ) | (___) | | | | ) ( | | | | (___) || ) \\ | \n" | ||
| + "|/ (_______) )_( |/ \\| )_( (_______)|/ )_) \n"; | ||
|
|
||
| System.out.println("_____________________________________________\n" |
There was a problem hiding this comment.
Since you use this line a lot, you could consider creating a static String to print this line instead of copying it all the time?
|
|
||
| @Override | ||
| public String toString() { | ||
| return ("[D]" + super.toString() + " (at: " + getPeriod() + ")"); |
There was a problem hiding this comment.
This method exists inside the Events class already. It might be better if you printed period instead of calling getPeriod. Similar improvements can be made throughout the code.
| } | ||
|
|
||
| private static void addEvent(String line, Task[] tasks) { | ||
| String arg = line.split(" ", 2)[1]; |
There was a problem hiding this comment.
This line.split by space is repeated throughout your adds. I think it'd be better if you could handle this before passing it into the function!
| System.out.println("_____________________________________________\n" | ||
| + "Got it. I've added this task: \n" | ||
| + t + "\n" | ||
| + "Now you have " + (t.getTaskCount() - 1) + " tasks in the list." + "\n" | ||
| + "_____________________________________________\n" | ||
| ); |
There was a problem hiding this comment.
I like how your print statements all end with "\n", makes it very readable!
| String eventDate = arg.split("/at ", 2)[1]; | ||
| Task t = new Events(event, eventDate); | ||
| tasks[t.getTaskCount() - 1] = t; | ||
| System.out.println("_____________________________________________\n" |
There was a problem hiding this comment.
Maybe can make the line a constant variable since you use it a lot.
| String logo = "_______ _______ _________ _______ _________ _______ _\n" | ||
| + "( ____ )( ___ )\\__ __/( ___ )\\__ __/( ___ )( ( /|\n" | ||
| + "| ( )|| ( ) | ) ( | ( ) | ) ( | ( ) || \\ ( |\\\n" | ||
| + "| (____)|| | | | | | | (___) | | | | | | || \\ | |\n" | ||
| + "| _____)| | | | | | | ___ | | | | | | || (\\ \\) | \n" | ||
| + "| ( | | | | | | | ( ) | | | | | | || | \\ | \n" | ||
| + "| ) | (___) | | | | ) ( | | | | (___) || ) \\ | \n" | ||
| + "|/ (_______) )_( |/ \\| )_( (_______)|/ )_) \n"; | ||
|
|
||
| System.out.println("_____________________________________________\n" | ||
| + logo + "\n" | ||
| + "Hello! I'm Duke\n" | ||
| + "What can I do for you?\n" | ||
| + "_____________________________________________\n" | ||
| ); |
There was a problem hiding this comment.
it's really readable to change a new line when you add \n
| System.out.println("_____________________________________________\n" | ||
| + "OK, I've marked this task as not done yet:\n" | ||
| + tasks[taskNum] + "\n" | ||
| + "_____________________________________________\n" |
There was a problem hiding this comment.
since you have use this print method in many classes maybe can consider making it as a method that every class can use
| case "list": | ||
| printList(tasks); | ||
| break; | ||
| case "unmark": |
… last week but did not tag and commit properly)
# Conflicts: # src/main/java/duke/Duke.java
| String eventDate = arg.split(" \\(at: ", 2)[1].split("\\)")[0]; | ||
| Task t = new Events(event, eventDate); | ||
| tasks.add(t); | ||
| System.out.println("_____________________________________________\n" |
There was a problem hiding this comment.
You have several println statements with line headers like this. How about shortening the print statements by declaring a header variable and reusing it?
| public static final String FILE_MISSING_MESSAGE = "File does not exist. Creating file."; | ||
| public static final String FILE_FOUND_MESSAGE = "File found. Loading file into database."; | ||
|
|
||
| public static void main(String[] args) throws IOException { |
| String arg = line.split("] ", 2)[1]; | ||
| String task = arg.split(" \\(by: ", 2)[0]; | ||
| String dueDate = arg.split(" \\(by: ", 2)[1].split("\\)")[0]; |
There was a problem hiding this comment.
2 appears to be a magic number which you could avoid. How about trying named constants?
| import java.util.ArrayList; | ||
| import java.util.Scanner; | ||
|
|
||
| public class Potaton { |
There was a problem hiding this comment.
You have little or no javadoc comments. Including them in this class would greatly help the reader quickly understand what some of the methods are doing.
| try { | ||
| addToDo(line, tasks); | ||
| } catch (IndexOutOfBoundsException e) { | ||
| // Refactor this later | ||
| System.out.println("_____________________________________________\n" | ||
| + "Error: The description of a todo cannot be empty." + "\n" | ||
| + "_____________________________________________\n" | ||
| ); | ||
| } |
There was a problem hiding this comment.
This block of code could be refactored so as to ensure SLAP.
Level-8 and minor change
Level-9 and minor changes
Added A-Javadoc
Completed until Week 3 (Level 3, then A- Coding Standard)