I have created a User Java class to store the users' information that was provided by the user when the registered. (The information is then stored in Firebase Realtime Database.) The variables username, email, dob, weight, height and gender are all set when the user registers however I want to create the value for the CalorieIntake using the other variables in the class in a calculation.
To calculate the Calorie Intake I need to use the weight and height and this calculation will be based on if the user is a male or female.
The code I have used doesn't seem to calculate the calorieIntake or show up on the profile page, so I am now very confused as to how to calculate it and get it to show up on my profile page.
Any help would be appreciated.
Below is my code in the User.java
class:
public class User {
public String username;
public String email;
public String dob;
public String weight;
public String height;
public String gender;
public String calorieIntake;
//default constructor
public User() {
}
public User(String username, String email, String dob, String weight, String height, String gender, String calorieIntake ) {
this.username = username;
this.email = email;
this.dob = dob;
this.weight = weight;
this.height = height;
this.gender = gender;
this.calorieIntake = calorieIntake;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getdob() {
return dob;
}
public void setdob(String dob) {
this.dob = dob;
}
public String getWeight() {
return weight;
}
public void setWeight(String weight) {
this.weight = weight;
}
public String getHeight() {
return height;
}
public void setHeight(String height) {
this.height = height;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getCalorieIntake() {
return calorieIntake;
}
public void setCalorieIntake(String calorieIntake) {
if(this.getGender() == "Male"){
calorieIntake = String.valueOf(((((Integer.parseInt(this.getWeight()) * 10) + (6.25 * Integer.parseInt(this.getHeight()))) - (5 * 21)) + 5));
} else if (this.getGender() == "Female"){
calorieIntake = String.valueOf(((((Integer.parseInt(this.getWeight()) * 10) + (6.25 * Integer.parseInt(this.getHeight()))) - (5 * 21)) - 161));
}
this.calorieIntake = calorieIntake;
}
}