nus-cs2113-AY2425S1 / pe-dev-response

0 stars 0 forks source link

Sequence diagram activation bar does not start and end at method call and return #201

Open nus-pe-bot opened 1 week ago

nus-pe-bot commented 1 week ago

image.png Page 7, SD for creating a user profile, User class


[original: nus-cs2113-AY2425S1/pe-interim#352] [original labels: severity.Low type.DocumentationBug]

kennethSty commented 1 week ago

Team's Response

It is unclear which activation bar is referred to in the screenshot.

Nevertheless, we point out that we omitted several helper functions like 'saveUserToFile()' for clarity and focused on their key underlying procedure. This might have been counterproductive and could have achieved the opposite instead of providing the clarity we aimed at.

Here are the relevant code snippets:

 /**
     * Loads a User instance if a file with user data exists.
     * Creates a new User instance otherwise
     * @return A newly created or "loaded" user object
     */
    public User checkForUserData() {
        return getLatestUser().orElseGet(() -> User.askForUserData());
    }

    public Optional<User> getLatestUser() {
        Optional<UserEntryList> optionalUserEntryList = this.loadUserEntries();
        return optionalUserEntryList.map(userEntryList -> userEntryList.getLastEntry());
    }
 /**
     * Asks user to input specifics for creating a new User instance
     * @return A new user instance created with the data inputted by user.
     */
    public static User  askForUserData() {
        try {
            Scanner scanner = new Scanner(System.in);

            UI.printString("Create your profile: please enter...");

            double height = askForHeight(scanner);
            double weight = askForWeight(scanner);
            boolean isMale = askForGender(scanner);
            int age = askForAge(scanner);
            HealthGoal healthGoal = askForHealthGoal(scanner);
            boolean isAbleToSeeSpecialChars = askForSpecialChars(scanner);

            User user = new User(height, weight, isMale, age, healthGoal, isAbleToSeeSpecialChars);
            UI.printString("Profile creation Successful!");
            UI.printReply("Great! You can now begin to use the app!", "");

            UserHistoryTracker userHistoryTracker = new UserHistoryTracker();
            userHistoryTracker.saveUserToFile(user);

            return user;
        } catch (Exception exception) {
            UI.printReply("Wrong user input: " + exception.getMessage(), "Retry: ");
            return askForUserData();
        }
    }
/**
     * Saves the provided User entry to a file. If the file does not exist,
     * it will be created first, and then the user data will be appended to the save file.
     *
     * @param userEntry The User object containing data to be saved.
     */
    public void saveUserToFile(User userEntry) {
        try {
            createFileIfNotExists();
            addUserEntry(userEntry);
        } catch (IOException e) {
            UI.printReply("Saving to the user file was unsuccessful", "Error: ");
        }
    }

Duplicate status (if any):

--