I have an assignment in Java, where I have to calculate the BMI of a particular user, in an array of users, an array of heights and an array of weights.
Below is the assignment:
String[] names; // users names
String[] familyNames; // familyNames
int[] weight; // users weights in kilograms (kg)
double[] height; // users height in meter (m)
names = new String[] { "Alex", "Maria", "Anna", "Adam", "Sara", "Johan", "Frederik"};
familyNames = new String[] {"Andersson", "Johansson", "Nordin", "Holmgren", "Svensson"};
weight = new int[] {70, 50, 60, 50, 60, 87, 130 };
height = new double[] { 1.80, 1.70, 1.57, 1.80, 1.69, 1.85, 1.85 };
public static void calculateBMI(String name, String[] names, int[] weight, double[] height) {
/*
* This method should be changed
*
* Calculate and print out BMI (body mass index) for each user
* BMI = weight in kg/height in meter * height in meter
*
* Check if the user is Underweight, Normal, Overweightor or Obese based on the BMI
* Underweight, when bmi is less than 18.5
* Normal, when bmi is between 18.5 and 24.9
* Overweight, when bmi is between 25 and 29.9
* Obese, when bmi is more than 30
*
*
* To check if a string is equal to another string use:
* stringVariable.equalsIgnoreCase(anotherStringVariable)
*
*/
}
public static void calculateWeight(String name, String[] names, int[] weight, double[] height) {
/*
* This method should be changed
*
* Calculate and print out the weight that the user has to loose or gain
*
* Let's consider that the formula for ideal body weight is (Broca Index:):
* Ideal Body Weight (kg) = (Height (cm) - 100) - ((Height (cm) - 100) x 10%)
*
* 1 meter = 100 cm
*
*
*/
//Your code starts here
}// end calculateWeightLoss
I have tried doing this:
double userBMI = 0;
for(int i = 0; i < weight.length; i++){
for(int j = 0; j < height.length; j++){
userBMI = weight[i]/height[j] * height[j];
}
}
But I feel I am not on track, because the method when in use will be:
calculateBMI("Frederik",names, weight,height); // calculate user BMI
calculateWeight("Frederik", names, weight, height); // calculate the weight loss or gain for the user
System.out.println("");
So I have to find for example "frederik" in the array of names, and calculate his BMI. Any ideas will be aappreciated.