@trpmy 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/langley/Langley.java lines 30-111:
public static String handleInput(String userInput) {
String[] command = Parser.parseCommand(userInput);
StringBuilder response = new StringBuilder();
assert userInput != null && !userInput.trim().isEmpty() : "Input cannot be null or empty";
assert command.length > 0 : "Command array should have at least one element";
if (command[0].equalsIgnoreCase("bye")) {
response.append("We will meet again.");
Platform.exit();
} else if (command[0].equalsIgnoreCase("list")) {
response.append(taskList.listTasks());
} else if (command[0].equalsIgnoreCase("mark")) {
try {
int index = Integer.parseInt(command[1]) - 1;
taskList.markTask(index);
response.append("I've marked this:");
response.append(" " + taskList.getTask(index));
storage.saveTasks(taskList.getTasks());
} catch (Exception e) {
response.append("Error: Invalid index.");
}
} else if (command[0].equalsIgnoreCase("unmark")) {
try {
int index = Integer.parseInt(command[1]) - 1;
taskList.unmarkTask(index);
response.append("I've unmarked this:");
response.append(" " + taskList.getTask(index));
storage.saveTasks(taskList.getTasks());
} catch (Exception e) {
response.append("Error: Invalid index.");
}
} else if (command[0].equalsIgnoreCase("todo")) {
String description = command[1].trim();
if (!description.isEmpty()) {
taskList.addTask(new ToDo(description));
response.append("Added a new ToDo: " + description);
storage.saveTasks(taskList.getTasks());
} else {
response.append("Error: ToDo description cannot be empty.");
}
} else if (command[0].equalsIgnoreCase("deadline")) {
String[] parts = command[1].split("/by", 2);
if (parts.length == 2 && !parts[0].trim().isEmpty() && !parts[1].trim().isEmpty()) {
taskList.addTask(new Deadline(parts[0].trim(), parts[1].trim()));
response.append("Added a new Deadline: " + parts[0].trim() + " (by: " + parts[1].trim() + ")");
storage.saveTasks(taskList.getTasks());
} else {
response.append("Error: Deadline command format is 'deadline x /by time'.");
}
} else if (command[0].equalsIgnoreCase("event")) {
String[] parts = command[1].split("/from|/to", 3);
if (parts.length == 3 && !parts[0].trim().isEmpty() && !parts[1].trim().isEmpty() && !parts[2].trim().isEmpty()) {
taskList.addTask(new Event(parts[0].trim(), parts[1].trim(), parts[2].trim()));
response.append("Added a new Event: " + parts[0].trim() + " (from: " + parts[1].trim() + " to: " + parts[2].trim() + ")");
storage.saveTasks(taskList.getTasks());
} else {
response.append("Error: Event command format is 'event x /from time /to time'.");
}
} else if (command[0].equalsIgnoreCase("delete")) {
try {
int index = Integer.parseInt(command[1]) - 1;
Task task = taskList.getTask(index);
taskList.deleteTask(index);
response.append("Deleted: " + task);
storage.saveTasks(taskList.getTasks());
} catch (Exception e) {
response.append("Error: Invalid index.");
}
} else if (command[0].equalsIgnoreCase("find")) {
String keyword = command[1].trim();
if (!keyword.isEmpty()) {
response.append(taskList.findTasks(keyword));
} else {
response.append("Error: Please provide a keyword to search for.");
}
} else {
response.append("Unknown command. Available commands: list, mark, unmark, todo, deadline, event, delete, find, bye.");
}
return response.toString();
}
}
Example from src/main/java/langley/LangleyGuiApp.java lines 35-90:
public void start(Stage primaryStage) {
// Load avatar images
userAvatar = new Image(this.getClass().getResourceAsStream("/langley/user.png"));
chatbotAvatar = new Image(this.getClass().getResourceAsStream("/langley/langley.jpg"));
// Setting up the window (Stage) and layout
primaryStage.setTitle("Langley");
// VBox to hold the conversation
dialogContainer = new VBox();
dialogContainer.setSpacing(10);
dialogContainer.setPadding(new Insets(10, 20, 10, 20));
// ScrollPane to make the conversation scrollable
ScrollPane scrollPane = new ScrollPane();
scrollPane.setContent(dialogContainer);
scrollPane.setFitToWidth(true);
scrollPane.setFitToHeight(true);
scrollPane.setPrefHeight(500);
scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS);
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scrollPane.setStyle("-fx-background: #FFFFFF; -fx-background-color: transparent;");
// TextField to capture user input
userInput = new TextField();
userInput.setPromptText("Enter your message here...");
userInput.setPrefHeight(40);
userInput.setStyle("-fx-font-size: 14px;");
userInput.setOnAction(event -> handleUserInput());
// Send button
Button sendButton = new Button("Send");
sendButton.setPrefHeight(40);
sendButton.setDefaultButton(true);
sendButton.setStyle("-fx-background-color: #4CAF50; -fx-text-fill: white; -fx-font-weight: bold;");
sendButton.setOnAction(event -> handleUserInput());
// HBox to arrange the TextField and Button in one line
HBox inputContainer = new HBox(10, userInput, sendButton);
inputContainer.setPadding(new Insets(10));
inputContainer.setStyle("-fx-background-color: #eeeeee;");
// Ensure that the TextField grows to fill space
HBox.setHgrow(userInput, Priority.ALWAYS);
// Root layout
VBox root = new VBox(10, scrollPane, inputContainer);
root.setPrefSize(400, 600);
root.setStyle("-fx-background-color: #f0f0f0;");
Scene scene = new Scene(root);
scene.getStylesheets().add("langley/ChatbotStyle.css"); // Adding external CSS for styling
primaryStage.setScene(scene);
primaryStage.show();
}
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/langley/Langley.java lines 24-29:
/**
* Main entry point for the Langley application.
* Initializes the necessary components and starts the command loop for user interaction.
*
* @param userInput Command-line arguments (not used).
*/
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
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 cs2103@comp.nus.edu.sg if you want to follow up on this post.
@trpmy 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/langley/Langley.javalines30-111:Example from
src/main/java/langley/LangleyGuiApp.javalines35-90: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/langley/Langley.javalines24-29: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
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
cs2103@comp.nus.edu.sgif you want to follow up on this post.