mardi 27 octobre 2015

BMR Calculator testing

Was just finishing up a test class for a project on exercise and BMR when I got the error that it "cannot find symbol" while pointing at the second "BMR" while making each different person to use the test on. AFAIK the actual bmr class works fine because it doesn't give me any errors.

Test class:

public class BMRTest {
  public static void main(String[] args) {
    BMR bmr1 = new BMR("Test Person1", 123, 128, 30, 'm', 2);
    BMR bmr1 = new BMR("Test Person2", 156, 115, 24, 'f', 1);
    BMR bmr1 = new BMR("Test Person3", 136, 147, 19, 'm', 5);
    BMR bmr1 = new BMR("Test Person4", 145, 192, 24, 'm', 4);
    BMR bmr1 = new BMR("Test Person5", 125, 121, 44, 'f', 3);

    System.out.println("1" + bmr1.calculateBMRWithExercise());
    System.out.println("2" + bmr1.calculateBMRWithExercise());
    System.out.println("3" + bmr1.calculateBMRWithExercise());
    System.out.println("4" + bmr1.calculateBMRWithExercise());
    System.out.println("5" + bmr1.calculateBMRWithExercise());
  }
}

Actual BMR Class:

public class BMR {

  private String Name;
  private float weight;
  private float height;
  private int age;
  private char gender;
  private int exercise; //1-5

  //BP
  public BMR(String n, float w, float h, int a, char g, int e) {
    n = Name;
    w = weight;
    h = height;
    a = age;
    g = gender;
    e = exercise; //1-5
  }

  //CALCULATE
  public float calculateBMR() {
    float rv;

    if (gender == 'f') {
      rv = femaleBMR();
    } else {
      rv = maleBMR();
    }
    return rv;
  }

  //MALE BMR
  private float maleBMR() {
    return 66 + 6.23f * weight + 4.7f * height - 6.8f * age;
  }

  //FEMALE BMR
  private float femaleBMR() {
    return 655 + 4.35f * weight + 12.7f * height - 4.7f * age;
  }

  //EXERCISE ADJUSTMENT
  public float calculateBMRWithExcercise() {
    float rv = 0;
    float bmr = calculateBMR();

    switch (exercise) {
      case 1:
        rv = bmr * 1.2f;
        break;

      case 2:
        rv = bmr * 1.375f;
        break;

      case 3:
        rv = bmr * 1.55f;
        break;

      case 4:
        rv = bmr * 1.725f;
        break;

      case 5:
        rv = bmr * 1.9f;
        break;

      default:
        System.out.println("Error");
        break;
    }
    return rv;
  }
}

Aucun commentaire:

Enregistrer un commentaire