[azfarulmatin] IP#70
Conversation
ryanlohyr
left a comment
There was a problem hiding this comment.
Overall great job but some improvements to work on:)
| // Check for any inputs with '/' | ||
| int checkSlash = userInput.indexOf("/"); | ||
| if (checkSlash != -1) { | ||
| description = userInput.substring(type.length() + 1, checkSlash).trim(); |
There was a problem hiding this comment.
Could this be refactored into a function? As we repeat it twice
| userInput = scanner.nextLine(); | ||
| System.out.println(LINE); | ||
|
|
||
| if (userInput.equals("bye")) { |
There was a problem hiding this comment.
could this be refactored into a switch statement for better readability?
| String by = bracketInfo.replace("/by", "").trim(); | ||
| tasks[count] = new Deadline(description, by); | ||
| } else if (type.equals("Event")) { | ||
| String from = bracketInfo.split("/from")[1].split("/to")[0].trim(); |
There was a problem hiding this comment.
The code is relatively concise, but it might benefit from some additional comments or variable names to make it more self-explanatory. For example, you could define variables with more descriptive names for the split values.
| @Override | ||
| public String toString() { | ||
| return "[D]" | ||
| + super.toString() |
There was a problem hiding this comment.
The code uses string concatenation to build the final string for the object's representation. While this approach works, it can be a bit less readable, especially when dealing with multiple string elements. Consider using String.format() for improved readability and performance.
janelleenqi
left a comment
There was a problem hiding this comment.
Overall, GOOD JOB! There are some minor changes you can make for readability and organisation (using a switch statement sounds good!). You did well commenting each function and following the naming conventions!
| this.description = description; | ||
| this.isDone = false; | ||
| } | ||
| public void markAsDone() { |
There was a problem hiding this comment.
you can consider spacing out (added new lines between) your functions for better readability
| } | ||
| } | ||
|
|
||
| class Deadline extends Task { |
There was a problem hiding this comment.
having a new file for each class can keep your code more organised (abstraction)
| } | ||
| public void markAsUndone() { | ||
| isDone = false; | ||
| } |
There was a problem hiding this comment.
you can consider combining this to become a setter method like "void setFound(boolean isFound);"
|
|
||
| class Task { | ||
| protected String description; | ||
| protected boolean isDone; |
There was a problem hiding this comment.
You did well in following the naming conventions (PascalCase for class and camelCase for variables)!!
| } | ||
| } | ||
|
|
||
| // Mark a task as done |
There was a problem hiding this comment.
Great job in explicitly commenting on the purpose of functions you added!
NaychiMin
left a comment
There was a problem hiding this comment.
Overall, your coding quality is very good, just small minor suggestions, not errors! Keep it up! 💯
| return "[X] " | ||
| + description; |
There was a problem hiding this comment.
Any reason for separating it on different lines? It's a rather short line :)
| // Create a task of a specific type to the tasks array | ||
| private static void addTask(String userInput, Task[] tasks, int count, String type) { | ||
| String description; | ||
| String bracketInfo; |
There was a problem hiding this comment.
Perhaps there might be a better more suggestive naming of the variable?
| String description; | ||
| String bracketInfo; | ||
|
|
||
| // Check for any inputs with '/' |
There was a problem hiding this comment.
I like how you added comments for easier readability! 👍
| + LINE); | ||
|
|
||
| Scanner scanner = new Scanner(System.in); | ||
| Task[] tasks = new Task[100]; |
There was a problem hiding this comment.
Good job on always having proper naming of functions, classes and variables! 👍
YongbinWang
left a comment
There was a problem hiding this comment.
Overall good job on your ip so far. Coding standard and code quality are alright. Try to structure your classes such that it only does one specific role. For example, your exceptions should be separated from your duke class. Keep up the good work!
| public void run() { | ||
| String LINE = "__________________________________________\n"; | ||
| System.out.println(LINE | ||
| + "Hello I'm MatinBot\n" | ||
| + "What can I do for you?\n" | ||
| + LINE); | ||
|
|
||
| Scanner scanner = new Scanner(System.in); | ||
| Task[] tasks = new duke.Task[100]; | ||
| int count = 0; | ||
| String userInput; | ||
|
|
||
| while (true) { | ||
| // Get the user input first | ||
| userInput = scanner.nextLine(); | ||
| System.out.println(LINE); | ||
|
|
||
| try { | ||
| if (userInput.equals("bye")) { | ||
| break; | ||
| } else if (userInput.equals("list")) { | ||
| printTasks(tasks, count); | ||
| } else if (userInput.startsWith("mark")) { | ||
| markTask(userInput, tasks, count); | ||
| } else if (userInput.startsWith("unmark")) { | ||
| unmarkTask(userInput, tasks, count); | ||
| } else if (userInput.startsWith("todo")) { | ||
| String description = userInput.replaceFirst("todo", "").trim(); | ||
| if (description.isEmpty()) { | ||
| throw new EmptyDescriptionException("todo"); | ||
| } | ||
| addTask("todo " + description, tasks, count, "todo"); | ||
| count++; | ||
| } else if (userInput.startsWith("deadline")) { | ||
| String description = userInput.replaceFirst("deadline", "").trim(); | ||
| if (description.isEmpty()) { | ||
| throw new EmptyDescriptionException("deadline"); | ||
| } | ||
| // Check for /by in the description | ||
| if (!description.contains("/by")) { | ||
| System.out.println("☹ OOPS!!! The deadline task must include '/by' to specify the date."); | ||
| } else { | ||
| addTask("deadline " + description, tasks, count, "deadline"); | ||
| count++; | ||
| } | ||
| } else if (userInput.startsWith("event")) { | ||
| String description = userInput.replaceFirst("event", "").trim(); | ||
| if (description.isEmpty()) { | ||
| throw new EmptyDescriptionException("event"); | ||
| } | ||
| // Check for /from and /to in the description | ||
| if (!description.contains("/from") || !description.contains("to")) { | ||
| System.out.println("☹ OOPS!!! The event task must include '/from' and '/to' to specify the date range."); | ||
| } else { | ||
| addTask("event " + description, tasks, count, "event"); | ||
| count++; | ||
| } | ||
| } else { | ||
| throw new UnknownCommandException(); | ||
| } | ||
| } catch (EmptyDescriptionException e) { | ||
| System.out.println(e.getMessage()); | ||
| } catch (UnknownCommandException e) { | ||
| System.out.println(e.getMessage()); | ||
| } | ||
| System.out.println(LINE); | ||
| } | ||
|
|
||
| System.out.println("Bye. Hope to see you again soon!\n" + LINE); | ||
| scanner.close(); | ||
| } |
There was a problem hiding this comment.
Consider abstracting away some of the heavy logic to reduce long methods. Generally more than 30 lines is too long.
|
|
||
| Scanner scanner = new Scanner(System.in); | ||
| Task[] tasks = new duke.Task[100]; | ||
| int count = 0; |
There was a problem hiding this comment.
Consider using a more suitable variable name to keep track of your number of tasks.
| switch (type) { | ||
| case "todo": |
There was a problem hiding this comment.
Violation of coding standard here, there should not be an indentation for the case clause.
… to a string format to save
# Conflicts: # src/main/java/duke/Duke.java
No description provided.