@tanyutao544 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
No easy-to-detect issues ๐
Aspect: Method Length
Example from src/main/java/duke/commands/AddCommand.java
lines 66-114
:
public String execute(TaskList tasks, Ui ui, Storage storage) throws DukeException {
assert tasks != null;
this.tasks = tasks;
String[] processedInput;
String time = null;
String details;
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d/M/yyyy HHmm");
try {
switch (type) {
case "todo":
added = new ToDo(input);
break;
case "event":
processedInput = input.split("/at", 2);
if(processedInput.length != 2) {
throw new IncorrectFormatException();
}
details = processedInput[0];
if(details.isEmpty()){
throw new EmptyDescriptionException(type);
}
time = processedInput[1].trim();
LocalDateTime date = LocalDateTime.parse(time, formatter);
added = new Event(details, date);
break;
case "deadline":
processedInput = input.split("/by", 2);
if(processedInput.length != 2) {
throw new IncorrectFormatException();
}
details = processedInput[0];
if(details.isEmpty()){
throw new EmptyDescriptionException(type);
}
time = processedInput[1].trim();
LocalDateTime deadline = LocalDateTime.parse(time, formatter);
added = new Deadline(details, deadline);
break;
default:
break;
}
} catch (DateTimeParseException e) {
throw new WrongDateFormatException(time);
}
this.tasks.add(added);
storage.saveFile(tasks);
return ui.addMessage(added, tasks.size());
}
Example from src/main/java/duke/storage/Storage.java
lines 34-88
:
public TaskList load() throws IOException {
//load files
File directory = new File("data");
if (!directory.exists()) {
directory.mkdir();
}
File file = new File(filePath);
if (!file.exists()) {
file.createNewFile();
} else {
Scanner s = new Scanner(file);
String type;
String mark;
String detail;
String date;
Task toAdd = null;
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d/M/yyyy HHmm");
LocalDateTime parsedDate;
while (s.hasNext()) {
String input = s.nextLine();
String[] inputSplit = input.split(" \\| ", 3);
type = inputSplit[0];
mark = inputSplit[1];
switch (type) {
case "T":
detail = inputSplit[2];
toAdd = new ToDo(detail);
break;
case "E":
inputSplit = inputSplit[2].split(" \\| ");
detail = inputSplit[0];
date = inputSplit[1];
parsedDate = LocalDateTime.parse(date, formatter);
toAdd = new Event(detail, parsedDate);
break;
case "D":
inputSplit = inputSplit[2].split(" \\| ");
detail = inputSplit[0];
date = inputSplit[1];
parsedDate = LocalDateTime.parse(date, formatter);
toAdd = new Deadline(detail, parsedDate);
break;
default:
break;
}
System.out.println(mark);
if (mark.equals("1")) {
toAdd.mark();
}
tasks.add(toAdd);
}
}
return tasks;
}
Suggestion: Consider applying SLAP (and other abstraction mechanisms) to shorten 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/commands/Command.java
lines 14-20
:
/**
* Abstract method for the execution of command
*
* @param tasks tasks list to be modified
* @param ui to help with printing of messages
* @param storage To deal with saving of task list
*/
Example from src/main/java/duke/tasks/Task.java
lines 35-37
:
/**
* Abstract method to update Date of the task
*/
Example from src/main/java/duke/tasks/Task.java
lines 40-42
:
/**
* Abstract method to update Detail of the task
*/
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 46f9232
:
Renamed Ui.png to resolve issue with product site
- 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
No easy-to-detect issues ๐
โ 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.