[John Nicholas S] iP#88
Conversation
| public class Brave { | ||
| public static void main(String[] args) { | ||
| String input; | ||
| String[] splitInput; |
There was a problem hiding this comment.
Plural form should be used on names representing a collection of objects - maybe use splitInputs instead?
| tasks.addTask(new Event(description, eventTime)); | ||
| break; | ||
| default: | ||
| System.out.println("Wrong input, available command are -> list/mark/unmark/todo/deadline/event"); |
| this.by = by; | ||
| } | ||
|
|
||
| @Override |
| public class Event extends Task { | ||
| private String eventTime; | ||
|
|
||
| public Event(String description, String eventTime) { | ||
| super(description); | ||
| this.eventTime = eventTime; | ||
| } | ||
|
|
||
| @Override | ||
| public String getStatusIcon() { | ||
| return "[E]" + super.getStatusIcon(); | ||
| } | ||
|
|
||
| public String getDescription() { | ||
| return super.getDescription() + String.format(" (at: %s)", this.eventTime); | ||
| } | ||
| } No newline at end of file |
There was a problem hiding this comment.
Well done, I don't think there's any violations here :-)
|
|
||
|
|
wli-linda
left a comment
There was a problem hiding this comment.
Overall good quality code, nice work! I like your way of getting rid of magic numbers
| switch (command) { | ||
| case "list": | ||
| tasks.printTaskList(); | ||
| break; | ||
| case "mark": | ||
| tasks.markTask(Integer.parseInt(splitInput[1]) - 1); // 0 indexing | ||
| break; | ||
| case "unmark": | ||
| tasks.unmarkTask(Integer.parseInt(splitInput[1]) - 1); // 0 indexing | ||
| break; | ||
| case "todo": | ||
| tasks.addTask(new Todo(splitInput[1])); | ||
| break; | ||
| case "deadline": | ||
| // To-do validate arguments~ | ||
| arguments = splitInput[1].split(" /by ", 2); | ||
| description = arguments[0]; | ||
| String by = arguments[1]; | ||
| tasks.addTask(new Deadline(description, by)); | ||
| break; | ||
| case "event": |
There was a problem hiding this comment.
The main method is a little long, maybe it'd be nice to extract this portion as a separate method?
| public void addTask(Task description) { | ||
| this.tasks[this.tasksCount] = description; | ||
| System.out.println("\t____________________________________________________________"); | ||
| System.out.println("\tYepp, I have added this task\n\t" + this.tasks[this.tasksCount].description + "\n\tYou currently have " + (this.tasksCount + 1) + " task in the list"); |
There was a problem hiding this comment.
Consider splitting this line so it's not so long?
| @@ -0,0 +1,17 @@ | |||
| public class Deadline extends Task { | |||
| public static final int MAX_TASK = 100; | ||
| private final Task[] tasks = new Task[MAX_TASK]; |
There was a problem hiding this comment.
Good way of getting rid of magic numbers!
| @Override | ||
| public String getStatusIcon() { | ||
| return "[E]" + super.getStatusIcon(); | ||
| } |
WrinklyToad
left a comment
There was a problem hiding this comment.
I only see one naming convention you could consider correcting. The readability of your code is quite nice; I appreciate how concise your 'Brave.java' is, and all of your other classes are very understandable. I added a few notes on things I thought were well done, and a few suggestions such as Javadoc comments.
| @@ -0,0 +1,44 @@ | |||
| public class TaskManager { | |||
There was a problem hiding this comment.
I think the inclusion of a TaskManager class is a very good idea; it makes the code in 'Main' much more concise
| public void addTask(Task description) { | ||
| this.tasks[this.tasksCount] = description; | ||
| System.out.println("\t____________________________________________________________"); | ||
| System.out.println("\tYepp, I have added this task\n\t" + this.tasks[this.tasksCount].description + "\n\tYou currently have " + (this.tasksCount + 1) + " task in the list"); |
There was a problem hiding this comment.
The max line length is 120 characters; maybe you could split this between two lines?
| public static final int MAX_TASK = 100; | ||
| private final Task[] tasks = new Task[MAX_TASK]; |
There was a problem hiding this comment.
Good job including a MAX_TASK constant for this; it is a common mistake to forget it (I need to fix this in my code)
| public class Task { | ||
| protected String description; | ||
| protected boolean isDone; | ||
|
|
||
| public Task(String description) { | ||
| this.description = description; | ||
| this.isDone = false; | ||
| } | ||
|
|
||
| public String getStatusIcon() { | ||
| return (isDone ? "[X]" : "[ ]"); // mark done task with X | ||
| } | ||
|
|
||
| public String getDescription() { | ||
| return description; | ||
| } | ||
|
|
||
| public void markAsDone() { | ||
| isDone = true; | ||
| } | ||
|
|
||
| public void unmarkAsDone() { | ||
| isDone = false; | ||
| } | ||
| } |
There was a problem hiding this comment.
I think your Task class and all the classes that inherit from it are coded very well. Since Task has so many child classes, you could consider Javadoc comments for convention's sake.
| public class Brave { | ||
| public static void main(String[] args) { | ||
| String input; | ||
| String[] splitInput; |
There was a problem hiding this comment.
I agree with mafpovul; perhaps a plural would be better here?
| public void unmarkTask(int taskIndex) { | ||
| this.tasks[taskIndex].unmarkAsDone(); | ||
| System.out.println("OK, I've marked this task as not done yet:"); | ||
| System.out.println(this.tasks[taskIndex].getStatusIcon() + " " + this.tasks[taskIndex].getDescription()); |
There was a problem hiding this comment.
The format is generally great and neatly following the standards. Can change lines when the text to print is too long.
|
|
||
| System.out.println("____________________________________________________________"); | ||
| System.out.println("Bye, Hope to see you again soon!"); | ||
| System.out.println("____________________________________________________________"); |
There was a problem hiding this comment.
The format is clear and neat! Maybe you can use a string object to store the seperate line, then no need to type the line every time( can secure same length)
| for (int i=0; i<tasksCount; i++) { | ||
| System.out.println(String.format("\t%d.%s %s", i+1,this.tasks[i].getStatusIcon(), this.tasks[i].getDescription() )); | ||
| for (int i = 0; i < tasksCount; i++) { | ||
| System.out.println(String.format("\t%d.%s %s", i + 1, this.tasks[i].getStatusIcon(), this.tasks[i].getDescription())); |
There was a problem hiding this comment.
Nice changes to add spaces between operation cahracters.
| break; | ||
| case "unmark": | ||
| tasks.unmarkTask(Integer.parseInt(splitInput[1]) - 1); | ||
| tasks.unmarkTask(Integer.parseInt(splitInput[1]) - 1); // 0 indexing |
There was a problem hiding this comment.
Good to see more comments. It's clear for the readers.
| public static void main(String[] args) { | ||
| String input; | ||
| String[] splitInputs; | ||
| String command; | ||
| String[] arguments; | ||
| String description; | ||
| Scanner in = new Scanner(System.in); | ||
| TaskManager tasks = new TaskManager(); | ||
| try { | ||
| tasks.initialiseTasks("data/brave.txt"); | ||
| } catch (FileNotFoundException e) { | ||
| System.out.println("File not found"); | ||
| } | ||
|
|
||
| tasks.showWelcomeMessage(); | ||
| while (true) { | ||
| input = in.nextLine(); | ||
| splitInputs = input.split(" ", 2); | ||
| command = splitInputs[0]; //e.g. mark 2 -> take the first word as the command -> "mark" | ||
|
|
||
| if (command.equals("bye")) { | ||
| tasks.showFarewellMessage(); | ||
| tasks.saveTask("data/brave.txt"); | ||
| break; | ||
| } | ||
|
|
||
| switch (command) { | ||
| case "list": | ||
| tasks.printTaskList(); | ||
| break; | ||
| case "mark": | ||
| try { | ||
| tasks.markTask(Integer.parseInt(splitInputs[1]) - 1); // 0 indexing | ||
| } catch (NumberFormatException e) { | ||
| System.out.println("Please put in integer value"); | ||
| } catch (NullPointerException | ArrayIndexOutOfBoundsException e) { | ||
| System.out.println("Please put in valid number of task"); | ||
| } | ||
| break; | ||
| case "unmark": | ||
| try { | ||
| tasks.unmarkTask(Integer.parseInt(splitInputs[1]) - 1); // 0 indexing | ||
| } catch (NumberFormatException e) { | ||
| System.out.println("Please put in integer value"); | ||
| } catch (NullPointerException | ArrayIndexOutOfBoundsException e) { | ||
| System.out.println("Please put in valid number of task"); | ||
| } | ||
| break; | ||
| case "todo": | ||
| try { | ||
| description = splitInputs[1]; | ||
| tasks.addTask(new Todo(description)); | ||
| } catch (IndexOutOfBoundsException e) { | ||
| System.out.println(" ☹ OOPS!!! The description of a todo cannot be empty."); | ||
| } | ||
| break; | ||
| case "deadline": | ||
| // To-do validate arguments~ | ||
| arguments = splitInputs[1].split(" /by ", 2); | ||
| description = arguments[0]; | ||
| String by = arguments[1]; | ||
| tasks.addTask(new Deadline(description, by)); | ||
| break; | ||
| case "event": | ||
| // To-do validate arguments~ | ||
| arguments = splitInputs[1].split(" /at ", 2); | ||
| description = arguments[0]; | ||
| String eventTime = arguments[1]; | ||
| tasks.addTask(new Event(description, eventTime)); | ||
| break; | ||
| case "delete": | ||
| try { | ||
| tasks.deleteTask(Integer.parseInt(splitInputs[1]) - 1); // 0 indexing | ||
| } catch (NumberFormatException e) { | ||
| System.out.println("Please put in integer value"); | ||
| } catch (NullPointerException | ArrayIndexOutOfBoundsException e) { | ||
| System.out.println("Please put in valid number of task"); | ||
| } | ||
| break; | ||
| default: | ||
| try { | ||
| throw new IllegalArgumentException(); | ||
| } catch (IllegalArgumentException e) { | ||
| System.out.println("☹ OOPS!!! I'm sorry, but I don't know what that means :-("); | ||
| System.out.println("Available command are -> list/mark/unmark/todo/deadline/event"); | ||
| } | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
The method is too long, perhaps you might want to SLAP it.
| if (details[1].equals("1")) { | ||
| selected_task = tasks.get(taskIndex); | ||
| selected_task.markAsDone(); | ||
| } |
There was a problem hiding this comment.
Repetative code, perhaps you can find a way to code it once only?
| Scanner in = new Scanner(System.in); | ||
| TaskManager tasks = new TaskManager(); | ||
| try { | ||
| tasks.initialiseTasks("data/brave.txt"); |
There was a problem hiding this comment.
Magic literal here, you might want to place it as a static constant.
| // public static final int MAX_TASK = 100; | ||
| public static final String LINE_SPLIT = "\t____________________________________________________________"; | ||
| private final ArrayList<Task> tasks = new ArrayList<>(); | ||
| // private final Task[] tasks = new Task[MAX_TASK]; | ||
| // private int tasksCount = 0; |
There was a problem hiding this comment.
Remember to remove unneccesary comments before you commit
| try { | ||
| throw new IllegalArgumentException(); | ||
| } catch (IllegalArgumentException e) { | ||
| System.out.println("☹ OOPS!!! I'm sorry, but I don't know what that means :-("); | ||
| System.out.println("Available command are -> list/mark/unmark/todo/deadline/event"); | ||
| } | ||
| break; |
There was a problem hiding this comment.
I don't think you need to throw a new IllegalArgumentException here, just printing will do.
Add Ui Class Add Storage Class Add Parser Class
Add find method
Implement PathOf to get Directory Path
Added JavaDoc
No description provided.