[Zhao Yuqing] iP#67
Conversation
shxr3f
left a comment
There was a problem hiding this comment.
Well written code based on Coding Statndards.
Got to take a look at switch statements.
| private static void showList() { | ||
| System.out.println(" ____________________________________________________________"); | ||
| System.out.println(" Here are the tasks in your list:"); | ||
| for (int i = 0; i < descriptions.size(); i++) { |
There was a problem hiding this comment.
Spacing is always present in loops and conditional statements.
| switch (type) { | ||
| case "T": | ||
| Todo todo = new Todo(description); | ||
| System.out.println(todo.toString(isDone)); | ||
| break; | ||
| case "D": | ||
| Deadline deadline = new Deadline(description, date); | ||
| System.out.println(deadline.toString(isDone)); | ||
| break; | ||
| case "E": | ||
| Event event = new Event(description, date); | ||
| System.out.println(event.toString(isDone)); | ||
| break; | ||
| default: | ||
| System.out.println(" Unknown Type"); | ||
| } |
There was a problem hiding this comment.
No indentation for case clauses under switch statements
There was a problem hiding this comment.
Thank you for pointing it out, I will work on it!
| switch (type) { | ||
| case "T": | ||
| Todo todo = new Todo(description); | ||
| System.out.println(" " + todo.toString(true)); | ||
| break; | ||
| case "D": | ||
| Deadline deadline = new Deadline(description, date); | ||
| System.out.println(" " + deadline.toString(true)); | ||
| break; | ||
| case "E": | ||
| Event event = new Event(description, date); | ||
| System.out.println(" " + event.toString(true)); | ||
| break; | ||
| default: | ||
| System.out.println(" Unknown Type"); | ||
| } |
There was a problem hiding this comment.
No indentation for case clauses under switch statements
There was a problem hiding this comment.
Thank you for pointing it out, I will work on it!
| private static ArrayList<String> descriptions = new ArrayList<>(); | ||
| private static ArrayList<Boolean> dones = new ArrayList<>(); | ||
| private static ArrayList<String> types = new ArrayList<>(); | ||
| private static ArrayList<String> dates = new ArrayList<>(); | ||
|
|
There was a problem hiding this comment.
Following plural form for Arrays! Good naming conventions used throughout.
| System.out.println("____________________________________________________________"); | ||
| System.out.println(exits); | ||
| System.out.println("____________________________________________________________"); | ||
| greeting(); |
| @@ -0,0 +1,14 @@ | |||
| public class Deadline extends Task { | |||
|
|
|||
| protected String by; | |||
There was a problem hiding this comment.
The variable name might not be meaningful enough, maybe change to "deadline"
| } | ||
|
|
||
| private static void echo() { | ||
| String line; |
There was a problem hiding this comment.
The meaning of “line” is a bit unclear, maybe consider change it into "input"
| System.out.println(" ____________________________________________________________"); | ||
| System.out.println(" Here are the tasks in your list:"); | ||
| for (int i = 0; i < descriptions.size(); i++) { | ||
| System.out.println(i+1 + "." + descriptions.get(i)); |
There was a problem hiding this comment.
There should always be spaces before and after +
There was a problem hiding this comment.
Thank you for pointing it out, I will work on it!
| int number = Integer.parseInt(line.substring(line.length() - 1)); | ||
| markAsDone(number); | ||
| line = in.nextLine(); | ||
| continue; |
There was a problem hiding this comment.
Thank you for pointing it out, I will work on it!
| @@ -0,0 +1,14 @@ | |||
| public class Deadline extends Task { | |||
|
|
|||
| protected String by; | |||
There was a problem hiding this comment.
The variable name might not be meaningful enough, maybe change to "deadline"
| + "|____/ \\__,_|_|\\_\\___|\n"; | ||
| System.out.println("Hello from\n" + logo); | ||
| greeting(); | ||
| getCommand(); |
| } | ||
|
|
||
| private static void getCommand() { | ||
| String line; |
There was a problem hiding this comment.
The meaning of “line” is a bit unclear, maybe consider change it into "input"
| int number = Integer.parseInt(line.substring(line.length() - 1)); | ||
| markAsDone(number); | ||
| line = in.nextLine(); | ||
| continue; |
| @@ -0,0 +1,14 @@ | |||
| public class Event extends Task { | |||
|
|
|||
| protected String at; | |||
There was a problem hiding this comment.
You might want to reconsider the variable name "at" also, it's unclear about the meaning
| Todo todo = new Todo(description); | ||
| System.out.println(todo.toString(isDone)); | ||
| break; | ||
| case "D": |
There was a problem hiding this comment.
No indentation required for case statement
There was a problem hiding this comment.
Thanks for pointing it out, I will fix it.
warrencxw
left a comment
There was a problem hiding this comment.
Code was generally well done. There are just a few potential areas for improvement to help readability and code quality to consider.
| String logo = " ____ _ \n" | ||
| + "| _ \\ _ _| | _____ \n" | ||
| + "| | | | | | | |/ / _ \\\n" | ||
| + "| |_| | |_| | < __/\n" | ||
| + "|____/ \\__,_|_|\\_\\___|\n"; |
There was a problem hiding this comment.
Consider making this logo a constant instead, as it would not be changed.
| System.out.println(" ____________________________________________________________"); | ||
| System.out.println(" Bye. Hope to see you again soon!"); | ||
| System.out.println(" ____________________________________________________________"); |
There was a problem hiding this comment.
Consider making the String here a constant with perhaps a name of FAREWELL_MESSAGE, so that it is clear that you are printing a closing message at the end.
| private static void markAsDone(int number) { | ||
| System.out.println(" ____________________________________________________________"); | ||
| System.out.println(" Nice! I've marked this task as done:"); | ||
| int index = number - 1; |
There was a problem hiding this comment.
Consider naming the variable as something that may be more easily understood at one glance, e.g. taskNumber, taskIndex
There was a problem hiding this comment.
Thank you for pointing it out, I will work on it!
| System.out.println(" ____________________________________________________________"); | ||
| } | ||
|
|
||
| private static void greeting() { |
There was a problem hiding this comment.
Consider renaming greeting to a verb to make it clearer what this method does.
There was a problem hiding this comment.
Thank you for pointing it out, I will work on it!
| dones.add(false); | ||
| if (line.startsWith("todo")) { | ||
| types.add("T"); | ||
| description = line.substring(5); |
There was a problem hiding this comment.
Consider extracting out this magic literal '5' into a constant to make it clearer why this substring is made.
There was a problem hiding this comment.
Thank you for pointing it out, I will work on it!
laiisaac
left a comment
There was a problem hiding this comment.
There are some good practices overall, but I think using more Single Level Abstraction could make the code more readable
| Scanner in = new Scanner(System.in); | ||
| // get user input | ||
| line = in.nextLine(); |
There was a problem hiding this comment.
Maybe a method of getUserInput would increase readability?
| System.out.println(" ____________________________________________________________"); | ||
| } | ||
|
|
||
| private static void handleCommand(String line) { |
There was a problem hiding this comment.
handleCommand method looks a little long, perhaps adding methods for adding different events can increase readability?
| line = in.nextLine(); | ||
| continue; | ||
| } | ||
| // Command is valid, handle the command |
There was a problem hiding this comment.
I like the occasional comments which clarify parts of the code
| } | ||
| } | ||
|
|
||
| private static void showList() { |
There was a problem hiding this comment.
I like methods like this where the name makes the intention obvious, would love to see more of such methods.
| continue; | ||
| } | ||
| if (input.startsWith("done")) { | ||
| int number = Integer.parseInt(input.substring(input.length() - 1)); |
There was a problem hiding this comment.
Create a separate variable for input.substring(input.length() - 1) to make the code more readable
| continue; | ||
| } | ||
| if (input.startsWith("delete")) { | ||
| int number = Integer.parseInt(input.substring(input.length() - 1)); |
There was a problem hiding this comment.
Do the parseInt in deleteTask function to maintain SLAP
| } | ||
| } | ||
|
|
||
| private static void loadTasks() { |
There was a problem hiding this comment.
You can create a separate class for things that have to do with the storing of information into a text file, instead of including it all in Duke
|
|
||
| private static void markAsDone(int number) { | ||
| System.out.println(" ____________________________________________________________"); | ||
| System.out.println(" Nice! I've marked this task as done:"); |
| System.out.println(" ____________________________________________________________"); | ||
| System.out.println(" Nice! I've marked this task as done:"); | ||
| int index = number - 1; | ||
| String description = tasks.get(index); |
There was a problem hiding this comment.
Can consider creating an exception for if the task with that index doesnt exist. E.g. if your tasks length is only 2 and someone inputs 5 as the index
Add Find method
Add JavaDoc comments
No description provided.