Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Andy Stevens
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Andy Stevens
Front End Web Development Techdegree Graduate 20,417 Points

What's wrong with my logic?

Hi,

I have written a method that takes 3 parameters, Gender, Age and weight. Depending on this arguments passed in the code will calculate the users basal metabolic rate.

However, I keep getting the output for a female who is 17 or under. I'm not entirely sure were I'm going wrong and could use some guidance.

  public class BasalMetabolicRate {
  private double Pal;
  private int Weight;
  private int Age;
  private String Gender;

public double getBasalRate(String Gender, int Age, int Weight) {
    this.Age = Age;
    this.Weight = Weight;
    this.Gender = Gender;
    double Bmr = 0;
    if ((Age <= 17) && (Gender.equals("male".toUpperCase()))) {
        Bmr = (17.7 * Weight + 657);
    } else {
        Bmr = (13.4 * Weight + 692);
    }
    return Bmr;
}

}

1 Answer

The toUpperCase method is applied to the String literal "male" instead of the variable Gender. Also, should use toLowerCase instead of toUpperCase method since "male" is all lowercases.