@nmtuan2001 We did an automated analysis of your code to detect potential areas to improve the code quality. We are sharing the results below, to help you improve the iP code further.
IMPORTANT: Note that the script looked for just a few easy-to-detect problems only, and at-most three example are given i.e., there can be other areas/places to improve.
Aspect: Tab Usage
No easy-to-detect issues ๐
Aspect: Naming boolean variables/methods
No easy-to-detect issues ๐
Aspect: Brace Style
No easy-to-detect issues ๐
Aspect: Package Name Style
No easy-to-detect issues ๐
Aspect: Class Name Style
No easy-to-detect issues ๐
Aspect: Dead Code
No easy-to-detect issues ๐
Aspect: Method Length
Example from src/main/java/duke/Duke.java
lines 36-108
:
public String getResponse(String input) {
String[] parsedCommands;
Task task;
try {
parsedCommands = Parser.parse(input);
} catch (DukeException e) {
return e.getMessage();
}
try {
switch (parsedCommands[0]) {
case "list":
return ui.showTasks(tasks);
case "todo":
Todo todo = new Todo(parsedCommands[1]);
tasks.add(todo);
return String.format("Got it. I've added this todo:\n %s\nNow you have %d tasks in the list.",
todo, tasks.size());
case "deadline":
Deadline deadline = new Deadline(parsedCommands[1], parsedCommands[2]);
tasks.add(deadline);
return String.format("Got it. I've added this deadline:\n %s\nNow you have %d tasks in the list.",
deadline, tasks.size());
case "event":
Event event = new Event(parsedCommands[1], parsedCommands[2]);
tasks.add(event);
return String.format("Got it. I've added this event:\n %s\nNow you have %d tasks in the list.",
event, tasks.size());
case "sort":
tasks.sort();
return ui.showTasks(tasks);
case "schedule":
return ui.viewScheduleOnDate(tasks, parsedCommands[1]);
case "find":
return ui.showTasks(tasks.filter(parsedCommands[1]));
case "format":
TimedTask.setFormat(parsedCommands[1]);
return ui.showTasks(tasks);
case "mark":
task = tasks.mark(Integer.parseInt(parsedCommands[1]));
return "Nice! I've marked this task as done:\n " + task;
case "unmark":
task = tasks.unmark(Integer.parseInt(parsedCommands[1]));
return "OK, I've marked this task as not done yet:\n " + task;
case "delete":
task = tasks.delete(Integer.parseInt(parsedCommands[1]));
return String.format("Noted. I've removed this task:\n %s\nNow you have %d tasks in the list.",
task, tasks.size());
case "bye":
try {
storage.saveData(tasks);
return "Data is saved successfully.\nBye. Hope to see you again soon!";
} catch (DukeException e) {
return e.getMessage() + "\nBye. Hope to see you again soon!";
}
default:
throw new DukeException("Error encountered while processing your input.");
}
} catch (DukeException e) {
return e.getMessage();
}
}
Example from src/main/java/duke/Storage.java
lines 35-76
:
public TaskList getData() throws DukeException {
TaskList tasks = new TaskList();
Scanner sc;
try {
sc = new Scanner(file);
} catch (FileNotFoundException e) {
throw new DukeException("\u2639 OOPS!!! File not found: Unable to retrieve data.");
}
sc.useDelimiter("( \\| )|(\\n)"); // split by | or new line
while (sc.hasNext()) {
try {
String type = sc.next();
String status = sc.next();
String description = sc.next();
Task task;
switch (type) {
case "T":
task = new Todo(description);
break;
case "D":
task = new Deadline(description, sc.next());
break;
case "E":
task = new Event(description, sc.next());
break;
default:
throw new DukeException("\u2639 OOPS!!! Invalid task type: %s", type);
}
if (status.equals("1")) {
task.markAsDone();
} else if (!status.equals("0")) {
throw new DukeException("\u2639 OOPS!!! Invalid task status: %s", status);
}
tasks.add(task);
} catch (NoSuchElementException e) {
sc.close();
throw new DukeException("\u2639 OOPS!!! File content is not in the correct format.");
}
}
sc.close();
return tasks;
}
Suggestion: Consider applying SLAP (and other abstraction mechanisms) to shorten methods e.g., extract some code blocks into separate methods. You may ignore this suggestion if you think a longer method is justified in a particular case.
Aspect: Class size
No easy-to-detect issues ๐
Aspect: Header Comments
Example from src/main/java/duke/TaskList.java
lines 94-98
:
/**
* Filter tasks by keyword.
* @param keyword Keyword to search tasks by.
* @return List of tasks with the given keyword.
*/
Suggestion: Ensure method/class header comments follow the format specified in the coding standard, in particular, the phrasing of the overview statement.
Aspect: Recent Git Commit Message (Subject Only)
No easy-to-detect issues ๐
Aspect: Binary files in repo
No easy-to-detect issues ๐
โน๏ธ The bot account used to post this issue is un-manned. Do not reply to this post (as those replies will not be read). Instead, contact [email protected]
if you want to follow up on this post.