@myc37 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/chatbot/util/Parser.java
lines 41-190
:
public String parse(String rawInput) {
String[] input = rawInput.split(" ");
String response;
switch (input[0]) {
case "bye":
return ui.bye();
case "list":
try {
return list(input, taskList, contactList);
} catch (ChatBotException e) {
return ui.error(e.getMessage());
}
case "get":
try {
if (input.length > 2) {
return "That's too many inputs traveller! You only need to key in the "
+ "date or timestamp for which you want to view your tasks!";
}
Timestamp date = new Timestamp(input[1]);
return taskList.getTasksOnDate(date);
} catch (ChatBotException e) {
return ui.error(e.getMessage());
}
case "find":
return taskList.getTasksByKeyword(input);
case "mark":
case "unmark":
try {
if (taskList.isEmpty()) {
return "Your task list is empty traveller! "
+ "Add some tasks first before attempting to mark or unmark!";
} else if (input.length > 2) {
return "That's too many inputs traveller! "
+ "You only need to key in the index of the task you wish to mark or unmark!";
}
response = markOrUnmark(
Integer.parseInt(input[1]) - 1,
input[0].equals("mark")
);
return response;
} catch (ChatBotException e) {
return ui.error(e.getMessage());
} catch (NumberFormatException e) {
return ui.error(
"You should mark and unmark tasks using their index rather than title traveller!"
);
} catch (ArrayIndexOutOfBoundsException e) {
return ui.error(
"You need to key in the index of the task you wish to mark or unmark traveller!"
);
}
case "todo":
try {
response = createTaskResponse(taskList.addToDo(input));
tasksStorage.saveChanges(taskList);
return response;
} catch (ChatBotException e) {
return ui.error(e.getMessage());
}
case "contact":
try {
response = createContactResponse(contactList.add(input));
contactsStorage.saveChanges(contactList);
return response;
} catch (ChatBotException e) {
return ui.error(e.getMessage());
}
case "delete":
try {
String type = input[1];
if (input.length > 3) {
throw new ChatBotException(
"That's too many inputs traveller! You only need to key in the index of the"
+ String.format("%s you wish to delete!", type)
);
}
if (type.equals("task")) {
response = createTaskResponse(
taskList.delete(Integer.parseInt(input[2]) - 1)
);
tasksStorage.saveChanges(taskList);
} else if (type.equals("contact")) {
response = createContactResponse(
contactList.delete(Integer.parseInt(input[2]) - 1)
);
contactsStorage.saveChanges(contactList);
} else {
throw new ChatBotException("You can only delete a task or contact traveller!");
}
return response;
} catch (ChatBotException e) {
return ui.error(e.getMessage());
} catch (NumberFormatException e) {
return ui.error(
"You should delete items using their index traveller!"
);
} catch (ArrayIndexOutOfBoundsException e) {
return ui.error(
"You need to specify which list to delete from and the index of the item traveller!"
);
}
case "guide":
return ui.printGuide();
default:
String[] temp = rawInput.split("/", 2);
try {
if (temp.length == 1) {
String[] splitInput = temp[0].split(" ");
String type = splitInput[0];
if (temp[0].isBlank()) {
throw new ChatBotException(
"Don't be shy traveller! Type in a command and I will assist you!"
);
} else if (type.equals("deadline")) {
if (splitInput.length == 1) {
throw new ChatBotException(
"You need to key in the title as well as "
+ "due date and time of your deadline traveller!"
);
} else {
throw new ChatBotException(
"You need to include /by in your command to add a deadline traveller!"
);
}
} else if (type.equals("event")) {
if (splitInput.length == 1) {
throw new ChatBotException(
"You need to key in the title and timestamp of your event traveller!"
);
} else {
throw new ChatBotException(
"You need to include /at in your command to add an event traveller!"
);
}
}
throw new ChatBotException();
}
response = createTaskResponse(
taskList.add(
temp[0].split(" "),
temp[1].split(" ")
)
);
tasksStorage.saveChanges(taskList);
return response;
} catch (ChatBotException e) {
return ui.error(e.getMessage());
}
}
}
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/chatbot/datetime/Timestamp.java
lines 83-87
:
/**
* Convert Timestamp into a String format appropriate for being saved in the save file.
*
* @return The formatted save string.
*/
Example from src/main/java/chatbot/list/ChatBotList.java
lines 40-44
:
/**
* Insert an item into the list.
*
* @param t The item to insert.
*/
Example from src/main/java/chatbot/list/ChatBotList.java
lines 53-59
:
/**
* Delete an item from the list.
*
* @param index The index of the task to be deleted.
* @return The response to be outputted by the UI.
* @throws ChatBotException If the task index is invalid.
*/
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 ๐
โ 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.