@NihaalManaf 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
Example from src/main/java/optimusprime/tasks/TaskList.java lines 182-182:
boolean foundKeyword = false;
Suggestion: Follow the given naming convention for boolean variables/methods (e.g., use a boolean-sounding prefix).You may ignore the above if you think the name already follows the convention (the script can report false positives in some cases)
Aspect: Brace Style
No easy-to-detect issues 👍
Aspect: Package Name Style
No easy-to-detect issues 👍
Aspect: Class Name Style
Example from src/main/java/optimusprime/ui/ui.java lines 3-3:
Suggestion: Follow the class naming convention specified by the coding standard.
Aspect: Dead Code
No easy-to-detect issues 👍
Aspect: Method Length
Example from src/main/java/optimusprime/OptimusPrime.java lines 17-120:
public String getResponse(String input) {
enum CommandType {
BYE,
MARK,
UNMARK,
LIST,
TASK,
DELETE,
FIND,
UNKNOWN;
public static CommandType fromString(String input) {
if (input == null) {
return UNKNOWN;
}
return switch (input.toLowerCase()) {
case "bye" -> BYE;
case "mark" -> MARK;
case "unmark" -> UNMARK;
case "list" -> LIST;
case "todo" -> TASK;
case "deadline" -> TASK;
case "event" -> TASK;
case "delete" -> DELETE;
case "find" -> FIND;
default -> UNKNOWN;
};
}
}
TaskList tasks;
try {
tasks = DatabaseHandler.readDatabase();
} catch (Exception e){
tasks = new TaskList();
}
System.out.println("User:");
String inputCommand = input.split(" ")[0];
CommandType commandType = CommandType.fromString(inputCommand);
switch (commandType){
case BYE -> {
return "Autobots, Roll Out!";
}
case UNMARK -> {
char itemToAdd = input.charAt(input.length() - 1);
int item = itemToAdd - '0';
Task task = tasks.markIncomplete(item);
DatabaseHandler.writeDatabase(tasks);
return "OK, I've marked this task as not done yet:\n" + task;
}
case MARK -> {
char itemToAdd = input.charAt(input.length() - 1);
int item = itemToAdd - '0';
Task task = tasks.markComplete(item);
DatabaseHandler.writeDatabase(tasks);
return "Nice! I've marked this task as done:\n" + task;
}
case LIST -> {
return tasks.getTasks(tasks);
}
case TASK -> {
String taskName = input.split(" ")[0];
String metaData = input.replaceAll(taskName, "").trim();
try {
String response = tasks.createTask(taskName, metaData);
DatabaseHandler.writeDatabase(tasks);
return response;
} catch (InvalidArgumentException e){
return e.getMessage();
} catch (Exception e) {
System.out.println("Uh oh...The Decepticons are coming...\nLet's add your task later");
}
}
case DELETE -> {
try {
int toDelete = Integer.parseInt(input.split(" ")[1]);
String response = tasks.deleteTask(toDelete);
DatabaseHandler.writeDatabase(tasks);
return response;
} catch (InvalidArgumentException e) {
return e.getMessage();
}
}
case FIND -> {
try {
String parsedInput = Parser.parseKeyword(input);
return tasks.findTasks(parsedInput);
} catch (Exception e) {
return "Please enter an argument after 'find'";
}
}
case UNKNOWN -> {
return "Human... Please enter a valid command...";
}
}
return "";
}
Example from src/main/java/optimusprime/tasks/TaskList.java lines 45-92:
public String createTask(String taskName, String metadata) throws InvalidArgumentException {
Task task;
String name = "";
if (!metadata.contains("/")) {
name = metadata;
} else {
name = metadata.substring(0, metadata.indexOf("/")).trim();
}
if (Objects.equals(taskName, "todo")) {
task = new Todos(name, false);
if (metadata.isEmpty()) {
throw new InvalidArgumentException(
"Human... You must do something...\nTell me what you want to do after the todo command...");
}
} else if (Objects.equals(taskName, "deadline")) {
if (!metadata.contains("/by")) {
throw new MissingDeadlineArgumentException(
"The autobots normally enter their deadline proceeding a '/by' command...");
}
LocalDate[] localDate = Parser.deadlineDateParser(metadata);
task = new Deadlines(name, localDate, false);
} else if (Objects.equals(taskName, "event")) {
String firstSubString = "/from";
String secondSubString = "/to";
LocalDate[] localDate = Parser.eventDateParser(metadata);
if (!metadata.contains(firstSubString) || !metadata.contains(secondSubString)) {
throw new MissingEventArgumentException(
"The autobots normally enter their event proceeding a '/from' and '/to' command...");
}
task = new Events(name, localDate, false);
} else {
return "Error in reading task!";
}
taskList.add(task);
return "Got it. I've added this task:\n"
+ task.toString() + "\n"
+ "Now you have " + taskList.size() + " tasks in the list";
}
Example from src/main/java/optimusprime/gui/MainWindow.java lines 52-110:
public void start(Stage stage) {
try {
userImage = new Image(this.getClass().getResourceAsStream("/optimusprime/gui/resources/images/DaUser.png"));
dukeImage = new Image(this.getClass().getResourceAsStream("/optimusprime/gui/resources/images/DaDuke.png"));
} catch (Exception e) {
System.err.println("Failed to load images: " + e.getMessage());
e.printStackTrace();
}
scrollPane = new ScrollPane();
dialogContainer = new VBox();
scrollPane.setContent(dialogContainer);
sendButton = new Button("Send");
userInput = new TextField();
AnchorPane mainLayout = new AnchorPane();
stage.setTitle("Duke");
stage.setResizable(false);
stage.setMinHeight(600.0);
stage.setMinWidth(400.0);
mainLayout.setPrefSize(400.0, 600.0);
scrollPane.setPrefSize(385, 535);
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS);
scrollPane.setVvalue(1.0);
scrollPane.setFitToWidth(true);
dialogContainer.setPrefHeight(Region.USE_COMPUTED_SIZE);
dialogContainer.heightProperty().addListener((observable) -> scrollPane.setVvalue(1.0));
userInput.setPrefWidth(325.0);
sendButton.setPrefWidth(55.0);
AnchorPane.setTopAnchor(scrollPane, 1.0);
AnchorPane.setBottomAnchor(sendButton, 1.0);
AnchorPane.setRightAnchor(sendButton, 1.0);
AnchorPane.setLeftAnchor(userInput, 1.0);
AnchorPane.setBottomAnchor(userInput, 1.0);
sendButton.setOnMouseClicked((event) -> {
handleUserInput();
});
userInput.setOnAction((event) -> {
handleUserInput();
});
mainLayout.getChildren().addAll(scrollPane, userInput, sendButton);
Scene scene = new Scene(mainLayout); // Setting the scene to be our Label
stage.setScene(scene); // Setting the stage to show our scene
stage.show(); // Render the stage.
}
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
No easy-to-detect issues 👍
Aspect: Recent Git Commit Messages
possible problems in commit 51c4e9b:
Alter behaviour of OptimusPrime class to return String instead of print directly
- Longer than 72 characters
Suggestion: Follow the given conventions for Git commit messages for future commits (do not modify past commit messages as doing so will change the commit timestamp that we used to detect your commit timings).
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.
@NihaalManaf 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
Example from
src/main/java/optimusprime/tasks/TaskList.javalines182-182:Suggestion: Follow the given naming convention for boolean variables/methods (e.g., use a boolean-sounding prefix).You may ignore the above if you think the name already follows the convention (the script can report false positives in some cases)
Aspect: Brace Style
No easy-to-detect issues 👍
Aspect: Package Name Style
No easy-to-detect issues 👍
Aspect: Class Name Style
Example from
src/main/java/optimusprime/ui/ui.javalines3-3:Suggestion: Follow the class naming convention specified by the coding standard.
Aspect: Dead Code
No easy-to-detect issues 👍
Aspect: Method Length
Example from
src/main/java/optimusprime/OptimusPrime.javalines17-120:Example from
src/main/java/optimusprime/tasks/TaskList.javalines45-92:Example from
src/main/java/optimusprime/gui/MainWindow.javalines52-110: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
No easy-to-detect issues 👍
Aspect: Recent Git Commit Messages
possible problems in commit
51c4e9b:Suggestion: Follow the given conventions for Git commit messages for future commits (do not modify past commit messages as doing so will change the commit timestamp that we used to detect your commit timings).
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.