-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[hongyijie06] iP #179
base: master
Are you sure you want to change the base?
[hongyijie06] iP #179
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it would be more beneficial to have a more descriptive name like "tasks"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That might be better! Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can try to use more methods e.g. sayBey() to make the program more extendable for the future levels.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting error here!
public class EmptyLineException extends Exception{ | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do refactor out your magic string values!
src/main/java/Event.java
Outdated
} | ||
@Override |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.