Conversation
mihirheda02
left a comment
There was a problem hiding this comment.
Overall, I think the code is very easy to understand and read. I think just focus on cleaning up the code a bit 👌
src/main/java/Duke.java
Outdated
|
|
||
|
|
||
|
|
||
| while (!line.equals("bye")){ |
There was a problem hiding this comment.
I tried to look through the coding standard to see if there should be a space. There wasn't anything that specifically mentioned it, but all the examples had a space. It might be worth making this change throughout your code to keep it consistent.
|
|
||
| if (line.equals("list")){ | ||
| for (int i = 0; i < index; i ++) { | ||
|
|
There was a problem hiding this comment.
I think you can clean up random newlines like this
src/main/java/Duke.java
Outdated
|
|
||
| System.out.println((i + 1) + ". " + list[i]); | ||
| } | ||
| }else { |
There was a problem hiding this comment.
I think adding a space between the "}" and "else" will follow coding standard more and keep the style of your code more consistent
src/main/java/Duke.java
Outdated
| System.out.println("Hello! I'm apple"); | ||
| System.out.println("What can I do for you?"); | ||
|
|
||
| int index = 0; |
There was a problem hiding this comment.
I think there should be one more space here for a 4 tab space
src/main/java/Duke.java
Outdated
|
|
||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
Additionally, I think you can clean up these new lines
src/main/java/Duke.java
Outdated
| + "| |_| | |_| | < __/\n" | ||
| + "|____/ \\__,_|_|\\_\\___|\n"; | ||
| System.out.println("Hello from\n" + logo); | ||
| String list[] = new String[100]; |
There was a problem hiding this comment.
Do you think it would be more beneficial to have a more descriptive name like "tasks"?
There was a problem hiding this comment.
That might be better! Thank you!
a-wild-chocolate
left a comment
There was a problem hiding this comment.
Good job! You follows the code rule and the code quality is high. Keep well in the following levels.
src/main/java/Duke.java
Outdated
| + "| |_| | |_| | < __/\n" | ||
| + "|____/ \\__,_|_|\\_\\___|\n"; | ||
| System.out.println("Hello from\n" + logo); | ||
| Task[] list = new Task[100]; |
There was a problem hiding this comment.
You can try to use Arraylist which is more convenient in java
src/main/java/Duke.java
Outdated
| } | ||
|
|
||
| } | ||
| System.out.println("Bye. Hope to see you again soon!"); |
There was a problem hiding this comment.
you can try to use more methods e.g. sayBey() to make the program more extendable for the future levels.
nichyjt
left a comment
There was a problem hiding this comment.
Hi Yi Jie,
I think this is good work. There are various ways we can further stretch your code to adhere to better code quality principles, and I hope you consider them!
- Throughout your program, there is heavy use of magic literals. This is not permissible by the course's coding quality metrics.
- Some of your variable names could be named better (especially those single letter ones)
- There is an opportunity to improve the code structure. Consider logically grouping your code by functionality and putting them into folders, rather than putting them into one file.
- There is an opportunity to improve the level of abstraction in your program. Some functionality is repetitive and could be abstracted out in a function, which can help you make your codebase smaller and neater!
Try and work on my comments before the next tutorial!
Also for your consideration: There is a way to autoformat your code automatically every time you Ctrl-S on intellij which will save you much pain. :)
src/main/java/CreateFile.java
Outdated
| File f = new File("TaskList.txt"); | ||
| if (!f.exists()) { | ||
| try { | ||
| if (f.createNewFile()) { | ||
| System.out.println("File created: " + f.getAbsolutePath()); | ||
| } else { | ||
| System.out.println("File creation failed."); | ||
| } | ||
| } catch (IOException e) { | ||
| System.out.println("An error occurred."); | ||
| e.printStackTrace(); | ||
| } | ||
| } else { | ||
| System.out.println("File already exists: " + f.getAbsolutePath()); | ||
| } | ||
| } |
There was a problem hiding this comment.
Do use more descriptive names for your exceptions and files.
Avoid using magic values (the strings) as well!
src/main/java/Deadline.java
Outdated
| @@ -0,0 +1,13 @@ | |||
| public class Deadline extends Task{ | |||
| public class EmptyLineException extends Exception{ | ||
| } |
There was a problem hiding this comment.
Formatting error for Exception{. Also, I'm not sure why your exception class is empty?
src/main/java/Duke.java
Outdated
| public static void main(String[] args) throws UnexpectedCommandException, EmptyLineException, IOException { | ||
| ArrayList<Task> tasks = new ArrayList<Task>(); | ||
|
|
||
| //greeting |
There was a problem hiding this comment.
Your comment could be more descriptive!
src/main/java/Duke.java
Outdated
| } | ||
| } | ||
|
|
||
| public static void main(String[] args) throws UnexpectedCommandException, EmptyLineException, IOException { |
There was a problem hiding this comment.
Do refactor out your magic string values!
| } | ||
| @Override |
There was a problem hiding this comment.
You can consider adding a newline between line 8 & 9 to avoid making it look too squashed!
src/main/java/ManageInputs.java
Outdated
| while (s.hasNext()) { | ||
| String sLine = s.nextLine(); | ||
| if (sLine.contains("[E]")) { | ||
| dealWithEvent(tasks, index, sLine); | ||
| } else if (sLine.contains("[D]")) { | ||
| dealWithDeadline(tasks, index, sLine); | ||
| } else if (sLine.contains("[T]")) { | ||
| dealWithTodo(tasks, index, sLine); | ||
| } | ||
| index++; |
There was a problem hiding this comment.
This is a good application of SLAP! But perhaps the variable sLine could be renamed to make it clearer what this means?
src/main/java/ManageInputs.java
Outdated
| private void handleUnexpectedCommand(boolean isValidCommand) throws UnexpectedCommandException { | ||
| if (!isValidCommand) { | ||
| throw new UnexpectedCommandException(); | ||
| } | ||
| } |
There was a problem hiding this comment.
I'm not sure what this abstraction is supposed to do. Is this necessary? If a command is invalid, is it possible to just throw the exception straight?
src/main/java/ManageInputs.java
Outdated
| } | ||
| } | ||
|
|
||
| public ManageInputs(ArrayList<Task> tasks, int index, String line) throws IOException, UnexpectedCommandException { |
There was a problem hiding this comment.
This function is doing quite a fair bit of heavy lifting.
It's very long, which usually indicates that perhaps you could apply SLAP more here.
To aid you in achieving SLAP, here are some guiding questions...
- What parts of the code is repetitive? i.e. virtually the same for each if/else block you have
- What part of the code does a particular function that can be isolated into a function? (like printing tasks, or doing something to the file?)
src/main/java/ManageInputs.java
Outdated
|
|
||
| if (inputs[0].equals("mark")) {//mark as done | ||
| isValidCommand = true; | ||
| int idx = Integer.parseInt(inputs[1]); |
There was a problem hiding this comment.
index and idx are being used in the code but seem to be referring to different things. It's not too clear what they really mean! Do consider how you could make this function more readable!
add javadoc
No description provided.