Open nus-pe-bot opened 1 week ago
It is unclear which activation bar is referred to in the screenshot.
The activation bar for askForUserData() correctly shows that the function returns a user if executed correctly.
Similarly, the long activation bar of the checkForUserData() function correctly shows that it is the overarching function in which all the other method calls and possible paths are embedded.
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: ");
}
}
--
Page 7, SD for creating a user profile, User class
[original: nus-cs2113-AY2425S1/pe-interim#352] [original labels: severity.Low type.DocumentationBug]