Skip to content
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

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open

Conversation

hongyijie06
Copy link

No description provided.

Copy link

@mihirheda02 mihirheda02 left a 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 👌




while (!line.equals("bye")){

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 ++) {

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


System.out.println((i + 1) + ". " + list[i]);
}
}else {

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

System.out.println("Hello! I'm apple");
System.out.println("What can I do for you?");

int index = 0;

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

Comment on lines 35 to 38




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

+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
String list[] = new String[100];

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"?

Copy link
Author

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!

Copy link

@a-wild-chocolate a-wild-chocolate left a 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.

+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
Task[] list = new Task[100];

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

}

}
System.out.println("Bye. Hope to see you again soon!");

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.

Copy link

@nichyjt nichyjt left a 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!

  1. Throughout your program, there is heavy use of magic literals. This is not permissible by the course's coding quality metrics.
  2. Some of your variable names could be named better (especially those single letter ones)
  3. 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.
  4. 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. :)

Comment on lines 6 to 21
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());
}
}
Copy link

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!

@@ -0,0 +1,13 @@
public class Deadline extends Task{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting error here!

Comment on lines 1 to 2
public class EmptyLineException extends Exception{
}
Copy link

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?

public static void main(String[] args) throws UnexpectedCommandException, EmptyLineException, IOException {
ArrayList<Task> tasks = new ArrayList<Task>();

//greeting
Copy link

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!

}
}

public static void main(String[] args) throws UnexpectedCommandException, EmptyLineException, IOException {
Copy link

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!

Comment on lines 8 to 9
}
@Override
Copy link

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!

Comment on lines 23 to 32
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++;
Copy link

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?

Comment on lines 115 to 119
private void handleUnexpectedCommand(boolean isValidCommand) throws UnexpectedCommandException {
if (!isValidCommand) {
throw new UnexpectedCommandException();
}
}
Copy link

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?

}
}

public ManageInputs(ArrayList<Task> tasks, int index, String line) throws IOException, UnexpectedCommandException {
Copy link

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...

  1. What parts of the code is repetitive? i.e. virtually the same for each if/else block you have
  2. 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?)


if (inputs[0].equals("mark")) {//mark as done
isValidCommand = true;
int idx = Integer.parseInt(inputs[1]);
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants