@sarthak181 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/duke/Event.java lines 23-23:
Example from src/main/java/duke/Event.java lines 24-24:
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
No easy-to-detect issues 👍
Aspect: Dead Code
Example from src/main/java/duke/Storage.java lines 58-58:
//new FileWriter(filePath, false).close();
Suggestion: Remove dead code from the codebase.
Aspect: Method Length
Example from src/main/java/duke/Duke.java lines 44-102:
public void start(Stage stage) {
//Step 1. Setting up required components
//The container for the content of the chat to scroll.
scrollPane = new ScrollPane();
dialogContainer = new VBox();
scrollPane.setContent(dialogContainer);
userInput = new TextField();
sendButton = new Button("Send");
AnchorPane mainLayout = new AnchorPane();
mainLayout.getChildren().addAll(scrollPane, userInput, sendButton);
scene = new Scene(mainLayout);
stage.setScene(scene);
stage.show();
//Step 2
stage.setTitle("Duke");
stage.setResizable(false);
stage.setMinHeight(600.0);
stage.setMinWidth(400.0);
mainLayout.setPrefSize(400.0, 800.0);
scrollPane.setPrefSize(385, 535);
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS);
scrollPane.setVvalue(1.0);
scrollPane.setFitToWidth(true);
// You will need to import `javafx.scene.layout.Region` for this.
dialogContainer.setPrefHeight(Region.USE_COMPUTED_SIZE);
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);
//step 3
sendButton.setOnMouseClicked((event) -> {
handleUserInput();
});
userInput.setOnAction((event) -> {
handleUserInput();
});
//Scroll down to the end every time dialogContainer's height changes.
dialogContainer.heightProperty().addListener((observable) -> scrollPane.setVvalue(1.0));
}
Example from src/main/java/duke/Parser.java lines 58-124:
public static String parse(String str, TaskList taskList) {
switch (getSwitch(str)) {
case "list":
return taskList.recite();
case "mark":
String num = str.split(" ", 2)[1];
int n = Integer.parseInt(num) - 1;
return taskList.mark(n, true);
case "unmark":
String num1 = str.split(" ", 2)[1];
int n1 = Integer.parseInt(num1) - 1;
return taskList.mark(n1, false);
case "todo":
Task a;
try {
a = new Todo(str.replace("todo ", ""));
} catch (DukeException e) {
return e.getMessage();
}
return taskList.addTask(a);
case "deadline":
Task b = null;
try {
String[] descriptionBy = str.replace("deadline ", "").split(" /by ");
b = new Deadline(descriptionBy[0], descriptionBy[1]);
b.isDate();
} catch (Exception e) {
return "Your command did not work, please try again";
}
return taskList.addTask(b);
case "event":
Task c = null;
try {
String[] descriptionFromTo = str.replace("event ", "").split(" /from ");
String[] fromTo = descriptionFromTo[1].split(" /to ");
c = new Event(descriptionFromTo[0], fromTo[0], fromTo[1]);
c.isDate();
} catch (DukeException e) {
return "Your command did not work, please try again";
}
return taskList.addTask(c);
case "delete":
String numD = str.split(" ", 2)[1];
int nD = Integer.parseInt(numD) - 1;
return taskList.delete(nD);
case "find":
String keyword = str.replace("find ", "");
return taskList.find(keyword);
case "na":
return ui.unknownCommand();
case "bye":
return ui.bye();
case "help":
return ui.help();
}
return "invalid";
}
Example from src/main/java/duke/Storage.java lines 51-106:
public ArrayList<Task> readFile() throws DukeException {
ArrayList<Task> dukeList = new ArrayList<>();
String basePath = new File("").getAbsolutePath();
File f = new File(basePath.concat(filePath));
if (f.exists()) {
try {
Scanner s = new Scanner(new File(basePath.concat(filePath)));
//new FileWriter(filePath, false).close();
while (s.hasNextLine()) {
String str = s.nextLine();
System.out.println(str);
if (str.startsWith("E")) {
Event e = new Event(str.substring(8, str.indexOf(" |f")),
str.substring(str.indexOf(" |f") + 4, str.indexOf(" |t")),
str.substring(str.indexOf(" |t") + 4));
if (str.startsWith("E | X")) {
e.markAsDone();
}
dukeList.add(e);
}
if (str.startsWith("D")) {
Deadline d = new Deadline(str.substring(8, str.indexOf(" |b")),
str.substring(str.indexOf(" |by ") + 5));
if (str.startsWith("D | X")) {
d.markAsDone();
}
dukeList.add(d);
}
if (str.startsWith("T")) {
Todo t = new Todo(str.substring(8));
if (str.startsWith("T | X")) {
t.markAsDone();
}
dukeList.add(t);
}
}
s.close();
} catch (IOException e) {
e.printStackTrace();
System.out.println("An error occurred while reading File.");
}
} else {
try {
File dir = new File(basePath.concat("/data"));
File c = new File(basePath.concat(filePath));
dir.mkdir();
c.createNewFile();
} catch (IOException d) {
System.out.println("Error while creating file");
d.printStackTrace();
}
}
return dukeList;
}
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/Parser.java lines 10-15:
/**
* The method simply returns the case to use for the switch in the parse method.
*
* @param str the string that the user inputted.
* @return the string that defines the case.
*/
Example from src/main/java/duke/Parser.java lines 51-57:
/**
* The method makes sense of the command that the user has inputted and takes the
* necessary action.
*
* @param str is the string that the user inputted
* @param taskList is that list that will be acted on by the command.
*/
Example from src/main/java/duke/Storage.java lines 16-20:
/**
* The method updates the task list in the filepath according to the latest command by the user.
*
* @param dukeList the task list being acted on by 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 0781156:
a
possible problems in commit 71ec489:
Amended Bugs
- Not in imperative mood (?)
possible problems in commit 8d40da5:
Amended Bugs
- 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 cs2103@comp.nus.edu.sg if you want to follow up on this post.
@sarthak181 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/duke/Event.javalines23-23:Example from
src/main/java/duke/Event.javalines24-24: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
No easy-to-detect issues 👍
Aspect: Dead Code
Example from
src/main/java/duke/Storage.javalines58-58://new FileWriter(filePath, false).close();Suggestion: Remove dead code from the codebase.
Aspect: Method Length
Example from
src/main/java/duke/Duke.javalines44-102:Example from
src/main/java/duke/Parser.javalines58-124:Example from
src/main/java/duke/Storage.javalines51-106: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/Parser.javalines10-15:Example from
src/main/java/duke/Parser.javalines51-57:Example from
src/main/java/duke/Storage.javalines16-20: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
0781156:apossible problems in commit
71ec489:Amended Bugspossible problems in commit
8d40da5:Amended BugsSuggestion: 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
cs2103@comp.nus.edu.sgif you want to follow up on this post.