@SweetPotato0213 We did an automated analysis of your code to detect potential areas to improve the code quality. We are sharing the results below, so that you can avoid similar problems in your tP code (which will be graded more strictly for code quality).
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
Example from src/main/java/duke/Deadline.java
lines 31-31
:
// this.by = LocalDate.parse(by, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
Example from src/main/java/duke/Duke.java
lines 3-3
:
//import javafx.application.Application;
Example from src/main/java/duke/Duke.java
lines 4-4
:
//import javafx.scene.Scene;
Suggestion: Remove dead code from the codebase.
Aspect: Method Length
Example from src/main/java/duke/Parser.java
lines 26-146
:
public String parser(String input) {
String[] inputArr = input.split(" ");
String action = inputArr[0];
int number;
Task task;
String[] params;
try {
switch (action) {
case "list":
return printList();
case "mark":
if (inputArr.length > 2 || inputArr.length == 1) {
throw new DukeException("The format should be: mark <number>");
}
number = Integer.parseInt(inputArr[1]);
if (number > tasks.getSize()) {
throw new DukeException("The index is invalid!");
}
task = tasks.getTask(number - 1);
task.markAsDone();
return BREAK_LINE + "\n"
+ " Nice! I've marked this task as done:\n "
+ task + "\n" + BREAK_LINE;
case "unmark":
if (inputArr.length > 2 || inputArr.length == 1) {
throw new DukeException("The format should be: unmark <number>");
}
number = Integer.parseInt(inputArr[1]);
if (number > tasks.getSize()) {
throw new DukeException("The index is invalid!");
}
task = tasks.getTask(number - 1);
task.markAsNotDone();
return BREAK_LINE + "\n"
+ " Nice! I've marked this task as not done yet:\n "
+ task + "\n" + BREAK_LINE;
case "todo":
if (input.substring(4).replaceAll("\\s+", "").equals("")) {
throw new DukeException("The description of a todo cannot be empty.");
}
task = new Todo(input.substring(5));
tasks.addTask(task);
return printTask(task);
case "deadline":
if (input.substring(8).replaceAll("\\s+", "").equals("")) {
throw new DukeException("The description of a deadline cannot be empty.");
}
if (!input.contains("/by")) {
throw new DukeException("The timing of a deadline cannot be omitted.");
}
params = input.substring(9).split(" /by ");
task = new Deadline(params[0], params[1]);
tasks.addTask(task);
return printTask(task);
case "event":
if (input.substring(5).replaceAll("\\s+", "").equals("")) {
throw new DukeException("The description of an event cannot be empty.");
}
if (!input.contains("/at")) {
throw new DukeException("The timing of an event cannot be omitted.");
}
params = input.substring(6).split(" /at ");
task = new Event(params[0], params[1]);
tasks.addTask(task);
return printTask(task);
case "delete":
if (inputArr.length > 2 || inputArr.length == 1) {
throw new DukeException("The format should be: delete <number>");
}
number = Integer.parseInt(inputArr[1]);
if (number > tasks.getSize()) {
throw new DukeException("The index is invalid!");
}
task = tasks.getTask(number - 1);
tasks.deleteTask(number - 1);
return BREAK_LINE + "\n"
+ " Okay! I've removed this task from the list:\n "
+ task + "\n" + BREAK_LINE + "\n";
case "find":
String keyWord = input.substring(5);
if (keyWord.replaceAll("\\s+", "").equals("")) {
throw new DukeException("The description of a find query cannot be empty.");
}
ArrayList<Task> matches = new ArrayList<Task>();
for (int i = 0; i < tasks.getSize(); i++) {
task = tasks.getTask(i);
if (task.getDescription().contains(keyWord)) {
matches.add(task);
}
}
return printMatch(matches);
case "update":
if (input.substring(6).replaceAll("\\s+", "").equals("")) {
throw new DukeException("The description of an update cannot be empty.");
}
for (int i = 0; i < tasks.getSize(); i++) {
task = tasks.getTask(i);
if (task.getDescription().contains(inputArr[1])) {
tasks.deleteTask(i);
if (task instanceof Deadline) {
tasks.addTask(new Deadline(inputArr[1], inputArr[2]));
} else if (task instanceof Event) {
tasks.addTask(new Event(inputArr[1], inputArr[2]));
} else {
throw new DukeException("No more to update for this task");
}
return printTask(task);
}
}
throw new DukeException("Cannot find an existing task matching the update");
default:
throw new DukeException("I'm sorry, but I don't know what that means :-(");
}
} catch (DukeException err) {
return BREAK_LINE + "\n" + " โน OOPS!!! "
+ err + "\n" + BREAK_LINE + "\n";
}
}
Example from src/main/java/duke/Storage.java
lines 31-74
:
public ArrayList<Task> loadData() throws DukeException {
ArrayList<Task> tasks = new ArrayList<>();
try {
File taskFile = new File(this.path);
Scanner sc = new Scanner(taskFile);
while (sc.hasNext()) {
String input = sc.nextLine();
String[] inputArr = input.split(" \\| ");
String type = inputArr[0];
Task task;
switch (type) {
case "T":
task = new Todo(inputArr[2]);
tasks.add(task);
if (inputArr[1].equals("1")) {
task.markAsDone();
}
break;
case "D":
task = new Deadline(inputArr[2], inputArr[3]);
tasks.add(task);
if (inputArr[1].equals("1")) {
task.markAsDone();
}
break;
case "E":
task = new Event(inputArr[2], inputArr[3]);
tasks.add(task);
if (inputArr[1].equals("1")) {
task.markAsDone();
}
break;
default:
throw new DukeException("It is an invalid type!");
}
}
sc.close();
} catch (FileNotFoundException err) {
printError(err);
} catch (DukeException err) {
printError(err);
}
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/Ui.java
lines 11-13
:
/**
* Welcome Message: greet the user
*/
Example from src/main/java/duke/Ui.java
lines 23-25
:
/**
* Goodbye Message: bid farewell to the user
*/
Example from src/main/java/duke/Ui.java
lines 34-36
:
/**
* Error Message: remind the user
*/
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)
possible problems in commit 57cac3f
:
Added GUI
- Not in imperative mood (?)
possible problems in commit 82f3c2b
:
Added Main.java and fxml files
- Not in imperative mood (?)
Suggestion: Follow the given conventions for Git commit messages for future commits (no need to modify past commit messages).
Aspect: Binary files in repo
Suggestion: Avoid committing binary files (e.g., *.class
, *.jar
, *.exe
) or third-party library files in to the repo.
โ You are not required to (but you are welcome to) fix the above problems in your iP, unless you have been separately asked to resubmit the iP due to code quality 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.