I keep on messing up the math calculations :@.
Error
The output was shown as this"

BMR: 40.35 pounds
BMI: -83.60 inches
TDEE: -114.95 years
Your BMI classifies you as Obese

But it should be this way:

BMR is 2308.15
BMI is 40.35
TDEE is 3173.71
Your BMI classifies you as Obese

Can people help me with math part?

Functional class

import java.lang.Math;

public class Healthy
{
	//Instance variables
	private String name;
	private char gender;
	private double weightNum;
	private double heightNum;
	private double weightMetricNum;
	private double heightMetricNum;
	private int ageNum;
	private double finalBMR;	
	private double finalBMI;		
	private double finalTDEE;
	private final double CENTIMETER_CONVERSION = 2.54;
	private final double KILOGRAM_CONVERSION = 0.45359237;

	
	
	/**
    * Creating a constructor that has 
	 * the default variables
    */	
	public Healthy()
	{
		name = "";
		weightNum = 0.0;
		heightNum = 0.0;
		ageNum = 0;
	}

	
	/**
    * Creating a constructor that has 
	 * the assigned variables
    */	
	public Healthy(String id, char status, double weight, double height, int year)
	{
		name = id;
		gender = status;
		weightNum = weight;
		heightNum = height;
		ageNum = year;
	}
	
		
	/**
    *  Convert the weight into kilograms 
	 *  based on the Metric System.
    */		
	private void setWeight()
	{
		weightMetricNum = KILOGRAM_CONVERSION * weightNum;
	}
	
	/**
    *  Convert the height into centimeters 
	 *  based on the Metric System.
    */
	private void setHeight()
	{
		heightMetricNum = CENTIMETER_CONVERSION * heightNum;
	}	


	/**
    *  Calculate the TDEE by user's level and BMR..
    *  @return the TDEE
    */	
	 
	public double getTDEE(int level)
	{
		switch (level) 
		{
            case 1:  
					finalTDEE  = finalBMR * 1.2;
					break;
            case 2:  
					finalTDEE  = finalBMR * 1.375;
					break;
            case 3:  
					finalTDEE  = finalBMR * 1.55;
					break;
            case 4:  
					finalTDEE = finalBMR * 1.725;
					break;
            case 5:  
					finalTDEE  = finalBMR * 1.9;
					break;
     	   }
			
		return finalTDEE;
	}
	
	/**
	 *  Calculate the BMI by using the weight and height.
    *  @return the BMI
    */		
	public double getBMI(double weight, double height)
	{
		finalBMI = (weight / (height * height))* 703;
		return finalBMI;
	}
	
	/**
    *  Calculate the BMR by Harris-Benedict formula 
	 *  based on total body weight and the Metric system 
    *  @return the BMR
    */		
	public double getBMR(char gender)
	{
	
		if(gender == 'M')
		{
			finalBMR = 66 + (13.7 * weightMetricNum) + (5 * heightMetricNum) - (6.8 * ageNum);
			
			if(gender == 'F')
			{
				finalBMR = 655 + (9.6 * weightMetricNum) + (1.8 * heightMetricNum) - (4.7 * ageNum);		
			}

		}
				 
		return finalBMR;
	}

	/**
    *  Gets the metric weight.
    *  @return the metric weight
    */			
	public double getMetricWeight()
	{
		setWeight();
		return weightMetricNum;
	}
	
	/**
    *  Gets the metric height.
    *  @return the metric height
    */		
	public double getMetricHeight()
	{
		setHeight();
		return heightMetricNum;
	}

	/**
    *  Gets the weight.
    *  @return the weight
    */			
	public double getWeight()
	{
		return weightNum;
	}
	
	/**
    *  Gets the height.
    *  @return the height
    */		
	public double getHeight()
	{
		return heightNum;
	}
	
	/**
    *  Gets the age.
    *  @return the age
    */		
	public int getAge()
	{
		return ageNum;
	}	
	

}

Tester Class

import java.util.Scanner;
/*
 * Description: A class to test the Healthy class
 */
public class HowHealthy
{
    public static void main(String args[])
    {
        //Initializes the variables.
		  String name;
        double weightNum;	
		  double heightNum;
		  String weightStatus;
		  int ageNum;
		  char genderStatus;
		  String gender;
		  int levelNum;
		  
		  
		  //Creating a Health object
 		  Healthy healthObj = new Healthy();

		  
		  Scanner scan = new Scanner(System.in);
		  System.out.print("Person's name: ");
		  String nameTemp = scan.nextLine(); /* Ask the user's name and set the
		  													input to the name variable */

		  /*Validate the name input */															
		   if (nameTemp.length() >= 1)
		   {
				name = nameTemp;
			} //if
			else
			{
				System.out.println("Invalid name - must be a proper name");
				System.exit(0);
			} //else
			
															
		  System.out.print(nameTemp + ", are you male or female (M/F): ");
		  char genderTempStatus = scan.nextLine().toUpperCase().charAt(0); /* Ask the user's gender and set the
		  													input to the genderStatus variable */
															
		  /*Validate the gender input */
		   if ((genderTempStatus == 'M') || (genderTempStatus == 'F'))
		   {
				genderStatus = genderTempStatus;
			} //if
			else
			{
				System.out.println("Invalid gender - must be either M or F");
				System.exit(0);
			} //else
		  												 	
		  System.out.print(nameTemp + ", weight (pounds): ");
  		  int weightTempNum = scan.nextInt(); /* Ask the user's weight and set the
		  													input to the weightNum variable */
															
		  
		  /*Validate the weight input */
		   if (weightTempNum >= 100)
		   {
				weightNum = weightTempNum;
			} //if
			else
			{
				System.out.println("Invalid weight - must be at least 100 pounds");
				System.exit(0);
			} //else
			
																		
		  System.out.print(nameTemp + ", height (inches): ");
		  double heightTempNum = scan.nextDouble(); /* Ask the user's height and set the
		  													input to the heightNum variable */

		  /*Validate the height input */
		   if ((heightTempNum >= 60) && (heightTempNum <= 84))
		   {
				heightNum = heightTempNum;
			} //if
			else
			{
				System.out.println("Invalid height - must be between 60 to 84");
				System.exit(0);
			} //else		  

		  System.out.print(nameTemp + ", age (years): ");
		  int ageTempNum = scan.nextInt(); /* Ask the user's age and set the
		  													input to the ageNum variable */															

		  /*Validate the age input */
		   if (ageTempNum >= 18)
		   {
				ageNum = ageTempNum;
			} //if
			else
			{
				System.out.println("Invalid age - must be at least 18 years");
				System.exit(0);
			} //else

		  //Creating another Health object
 		  Healthy healthObj1 = new Healthy(name, genderStatus, weightNum, heightNum, ageNum);

				
		  System.out.println("\nActivity Level: Use this categories: ");
   	  System.out.println("\t1 - Sedentary (little or no exercise, desk job)");
   	  System.out.println("\t2 - Lightly active (little exercise / sports 3-5 days/wk");
   	  System.out.println("\t3 - Moderately active(moderate exercise / sports 3-5 days/wk)");
   	  System.out.println("\t4 - Very active (hard exercise / sports 6 -7 day/wk)");
   	  System.out.println("\t5 - Extra active (hard daily exercise / sports  physical \n\t     job or 2X day training i.e marathon, contest, etc.)");
   	  System.out.print("\n\nHow active are you? ");
		  int levelTempNum = scan.nextInt();
		  
		  /*Validate the level input */
		   if ((levelTempNum >= 1) && (levelTempNum <= 5))
		   {
				levelNum = levelTempNum;
			} //if
			else
			{
				System.out.println("Invalid leve - must between 1 to 5");
				System.exit(0);
			} //else		  
		  
			
			
			System.out.printf("\n\n%s's information\n", name);
			System.out.printf("Weight: %.1f pounds \n", healthObj1.getWeight());
			System.out.printf("Height: %.1f inches \n", healthObj1.getHeight());
			System.out.printf("Age: %d years \n", healthObj1.getAge());
			
			/*Give the proper syntax for gender */
			if (genderStatus == 'M')
			{
				gender = "Male";
				
				if(genderStatus =='F')
				{
					gender = "Female";
				}

			}
			
			System.out.print("These are for a " + gender + ".\n\n");
			System.out.printf("BMR: %.2f pounds\n", healthObj1.getBMI(weightNum, heightNum)); //Pass the weight and height
			System.out.printf("BMI: %.2f inches\n", healthObj1.getBMR(genderStatus)); //Pass the gender
			System.out.printf("TDEE: %.2f years\n", healthObj1.getTDEE(levelNum));	// Pass the level
			
			/*Give the overall status of the weight */

			if ((healthObj1.getBMI(weightNum, heightNum)< 18.5))
			{
				weightStatus = "Underweight";
			
			}
			else if((healthObj1.getBMI(weightNum, heightNum)>= 18.5) && (healthObj1.getBMI(weightNum, heightNum)< 25))
			{
				weightStatus = "Normal weight";
			}
			else if((healthObj1.getBMI(weightNum, heightNum)>= 25) && (healthObj1.getBMI(weightNum, heightNum)< 30))
			{
				weightStatus = "Overweight";
			}
			else if((healthObj1.getBMI(weightNum, heightNum)>= 30))
			{
				weightStatus = "Obese";
			}						

			System.out.println("Your BMI classifies you as " + weightStatus);

		 }//main
}//class

what are your inputs for weight, height, age, and gender??

what are your inputs for weight, height, age, and gender??

Person's name: Will Smith
Will Smith, are you male or female (M/F): M
Will Smith's weight (pounds): 250
Will Smith's height (inches): 66
Will Smith's age (years): 22

Active Level: 2

People, I really need your help with the calculation or math involved. It is only problem I have left. I cannot move on without finishing this one.

Notice that this line

System.out.printf("BMR: %.2f pounds\n", healthObj1.getBMI(weightNum, heightNum)); //Pass the weight and height

you are printing BMR but you are getting BMI. Same with this line

System.out.printf("BMI: %.2f inches\n", healthObj1.getBMR(genderStatus)); //Pass the gender

Still working on the computations.

In your MBR computation, you dont have values yet for weightMetricNum and heightMetricNum. I dont see any code in your program that sets this.

My suggestion is to call these methods

setWeight, setHeight to convert your weightNum and heightNum to weightMetricNum and heightMetricNum.

You can also do this in your BMR code.

finalBMR = 66 + (13.7 * getMetricWeight()) + (5 * getMetricHeight()) - (6.8 * ageNum);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.