Skip to content

Sharing iP code quality feedback [for @brian16600] - Round 2 #3

@soc-se-bot

Description

@soc-se-bot

@brian16600 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/Duke.java lines 62-118:

    public void start(Stage stage) {
        //Setting up required components
        Label dukeLabel = new Label("Duke");

        //Creating container for the chat to scroll
        scrollPane = new ScrollPane();
        dialogBox = new VBox();
        scrollPane.setContent(dialogBox);

        userInput = new TextField();
        sendButton = new Button("Send");

        AnchorPane mainLayout = new AnchorPane();
        mainLayout.getChildren().addAll(scrollPane, userInput, sendButton);

        Scene scene = new Scene(mainLayout);
        stage.setScene(scene);
        stage.show();

        //Formatting window
        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);

        dialogBox.setPrefHeight(Region.USE_COMPUTED_SIZE);

        userInput.setPrefWidth(325.0);
        userInput.setPrefHeight(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);

        //Set functionality on User Input
        sendButton.setOnMouseClicked((event) -> {
            handleUserInput();
        });

        userInput.setOnAction((event) -> {
            handleUserInput();
        });

        //scroll down if dialogBox's height changes
        dialogBox.heightProperty().addListener((observable) -> scrollPane.setVvalue(1.0));

    }

Example from src/main/java/duke/ui/InputHandler.java lines 47-109:

    public String handleInput(String input) throws DukeException, IOException {
        String endMessage = "Bye. Hope to see you again soon!";

        String[] splitInput = input.split(" ");
        String inputCommand = splitInput[0];

        switch (inputCommand) {
        case "todo":
            return taskCaseHandler(CommandType.TODO, splitInput );
        case "event":
            return taskCaseHandler(CommandType.EVENT, splitInput);
        case "deadline":
            return taskCaseHandler(CommandType.DEADLINE, splitInput);
        case "list":
            //Confirms that input command is simply "list"
            if (splitInput.length == 1) {
                return parser.parse(CommandType.LIST, this.storage, splitInput);
            } else {
                throw new DukeException(unableToListErrorMessage);
            }
        case "mark":
            //Confirms that input is in the format mark [index]
            if (splitInput.length == 2) {
                return this.parser.parse(CommandType.MARK, this.storage, splitInput);
            } else {
                throw new DukeException(unableToMarkErrorMessage);
            }
        case "unmark":
            //Confirms that input is in the format mark [index]
            if (splitInput.length == 2) {
                return this.parser.parse(CommandType.UNMARK, this.storage, splitInput);
            } else {
                throw new DukeException(unableToUnmarkErrorMessage);
            }
        case "delete":
            //Confirms that input is in the format mark [index]
            if (splitInput.length == 2) {
                return this.parser.parse(CommandType.DELETE, this.storage, splitInput);
            } else {
                throw new DukeException(unableToDeleteErrorMessage);
            }
        case "find":
            if (splitInput.length > 1) {
                return this.parser.parse(CommandType.FIND, this.storage, splitInput);
            } else {
                throw new DukeException(unableToFindErrorMessage);
            }
        case "snooze":
            String splitInputBySlash[] = input.split(" /t ");
            if (splitInputBySlash.length > 1 && splitInput.length > 5) {
                return parser.parse(CommandType.SNOOZE, this.storage, splitInputBySlash);
            } else {
                throw new DukeException(unableToSnoozeErrorMessage);
            }
        case "bye":
            return endMessage;
        default:
            throw new DukeException(":( OOPS!!! I'm sorry, but I don't know what that means! Possible commands: " +
                    "todo [task], event [task] /at [time]," +
                    " deadline [task] /by [time], mark [index], unmark [index], delete [index], bye");
        }

    }

Example from src/main/java/duke/ui/Parser.java lines 243-289:

    private String parseSnooze(Storage storage, String[] splitInput) throws DukeException, IOException {
        String[] nameAndPrevTimeArr = splitInput[0].split(" ");
        String[] newDateAndTimeArr = splitInput[1].split(" ");

        String previousDateString = nameAndPrevTimeArr[nameAndPrevTimeArr.length - 1];
        LocalDate previousDate = LocalDate.parse(previousDateString);
        String newDateString = newDateAndTimeArr[newDateAndTimeArr.length - 2];
        LocalDate newDate = LocalDate.parse(newDateString);
        String newTimeString = newDateAndTimeArr[newDateAndTimeArr.length - 1];
        LocalTime newTime = LocalTime.parse(newTimeString);

        String taskName = "";
        for (int i = 1; i < nameAndPrevTimeArr.length - 1; i++) {
            if (i == nameAndPrevTimeArr.length - 2) {
                taskName += nameAndPrevTimeArr[i];
            } else {
                taskName += nameAndPrevTimeArr[i] + " ";
            }
        }

        for (int j = 0; j < storage.taskListSize(); j++) {
            if (storage.get(j).name.equals(taskName) && storage.get(j) instanceof Deadline) {
                Deadline deadlineToBeChanged = (Deadline) storage.get(j);
                if (deadlineToBeChanged.getDueDate().equals(previousDate)) {
                    deadlineToBeChanged.changeDueDate(newDate);
                    deadlineToBeChanged.changeDueTime(newTime);
                    storage.rewriteData();
                    return "Changed Deadline " + taskName + " from " + deadlineToBeChanged.dateConverterToString(previousDate)
                            + " " + deadlineToBeChanged.dateConverterToString(newDate)
                            + " " + deadlineToBeChanged.timeConverterToString(newTime);
                }
            }
            if (storage.get(j).name.equals(taskName) && storage.get(j) instanceof Event) {
                Event eventToBeChanged = (Event) storage.get(j);
                if (eventToBeChanged.getDueDate().equals(previousDate)) {
                    eventToBeChanged.changeDueDate(newDate);
                    eventToBeChanged.changeDueTime(newTime);
                    storage.rewriteData();
                    return "Changed Event " + taskName + " from " + eventToBeChanged.dateConverterToString(previousDate)
                            + " " + eventToBeChanged.dateConverterToString(newDate)
                            + " " + eventToBeChanged.timeConverterToString(newTime);
                }
            }
        }
        throw new DukeException(snoozeErrorMessage);

    }

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/duke/storage/Storage.java lines 211-215:

    /**
     * Size of TaskList
     *
     * @return size of task list
     */

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 cs2103@comp.nus.edu.sg if you want to follow up on this post.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions