@aaron-ljx 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/Duke.java lines 41-110:
public void start(Stage stage) {
Storage storage = new Storage();
storage.load();
//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();
// more code to be added here later
//Step 2. Formatting the window to look as expected
stage.setTitle("Duke");
stage.setResizable(false);
stage.setMinHeight(600.0);
stage.setMinWidth(400.0);
stage.getIcons().add(knight);
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);
// 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);
// more code to be added here later
//Part 3. Add functionality to handle user input.
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 107-169:
public ParsedAnswer parse() {
assertInputNotEmpty();
String[] parsedString = input.toLowerCase().split(" ", 2);
switch (parsedString[0]) {
case "bye":
return new ParsedAnswer("bye", -1);
case "list":
return new ParsedAnswer("list", -1);
case "unmark":
try {
int idx = Integer.parseInt(parsedString[1]);
return new ParsedAnswer("unmark", idx);
} catch (Exception e) {
return new ParsedAnswer("unmark", -1);
}
case "mark":
try {
int idx = Integer.parseInt(parsedString[1]);
return new ParsedAnswer("mark", idx);
} catch (Exception e) {
return new ParsedAnswer("mark", -1);
}
case "delete":
try {
int idx = Integer.parseInt(parsedString[1]);
return new ParsedAnswer("delete", idx);
} catch (Exception e) {
return new ParsedAnswer("delete", -1);
}
case "todo":
return parseInputWithRegex("none", parsedString);
case "event":
return parseInputWithRegex("/at", parsedString);
case "deadline":
return parseInputWithRegex("/by", parsedString);
case "find":
try {
ParsedAnswer pa = new ParsedAnswer("find", -1);
pa.setDesc(parsedString[1]);
return pa;
} catch (Exception e) {
ParsedAnswer pa = new ParsedAnswer("error", -1);
pa.setDesc("Please specify what you're searching for.");
return pa;
}
case "update":
return parseUpdate(input);
default:
ParsedAnswer pa = new ParsedAnswer("error", -1);
pa.setDesc("Sorry, but I have no idea what you mean.");
return pa;
}
}
Example from src/main/java/duke/Storage.java lines 23-81:
void load() {
boolean directoryExists = new java.io.File(this.homeDir + "/data").exists();
if (!directoryExists) {
try {
Files.createDirectories(Paths.get(this.homeDir + "/data"));
File myObj = new File(this.homeDir + "/data/storage.txt");
myObj.createNewFile();
} catch (IOException e) {
System.out.println("Load failed.");
}
} else {
// parse the content in the file and add tasks into the arraylist.
try {
FileInputStream fis = new FileInputStream(this.homeDir + "/data/storage.txt");
Scanner sc = new Scanner(fis);
while(sc.hasNextLine()) {
String[] parsedTaskFromFile = sc.nextLine().split(",");
if (parsedTaskFromFile.length > 0) {
String taskType = parsedTaskFromFile[0];
switch (taskType) {
case "T":
ToDos td = new ToDos(parsedTaskFromFile[2]);
if (Integer.parseInt(parsedTaskFromFile[1]) == 0) {
td.markAsDone();
} else {
td.markAsUndone();
}
taskList.add(td);
break;
case "E":
Event ev = new Event(parsedTaskFromFile[2], parsedTaskFromFile[3]);
if (Integer.parseInt(parsedTaskFromFile[1]) == 0) {
ev.markAsDone();
} else {
ev.markAsUndone();
}
taskList.add(ev);
break;
case "D":
Deadline dl = new Deadline(parsedTaskFromFile[2], parsedTaskFromFile[3]);
if (Integer.parseInt(parsedTaskFromFile[1]) == 0) {
dl.markAsDone();
} else {
dl.markAsUndone();
}
taskList.add(dl);
break;
}
}
}
sc.close();
} catch (FileNotFoundException e) {
System.out.println("File not found.");
}
}
}
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
No easy-to-detect issues 👍
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 cs2103@comp.nus.edu.sg if you want to follow up on this post.
@aaron-ljx 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/Duke.javalines41-110:Example from
src/main/java/duke/Parser.javalines107-169:Example from
src/main/java/duke/Storage.javalines23-81: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
No easy-to-detect issues 👍
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
cs2103@comp.nus.edu.sgif you want to follow up on this post.