JAVA Help USE OBJECT ORIENTATED PROGRAM DESIGN TO SOLVE PROBLEM Create a class B
ID: 3696892 • Letter: J
Question
JAVA Help
USE OBJECT ORIENTATED PROGRAM DESIGN TO SOLVE PROBLEM
Create a class BMI. (Body Mass Index)
BMI = 703*weight / height * height //Weight in lbs, height in inches
The BMI class should also return the person’s name using the program.
Create a method for calculating BMI and round BMI to 1 decimal place
Create a method for returning the BMI possibilities
Severe Thinness < 16
Moderate Thinness 16.1 – 17
Mild Thinness 17.1 – 18.5
Normal 18.6 – 26
Overweight 26.1 – 30
Obese Class I 30.1 – 35
Obese Class II 35.1 – 40
Obese Class III > 40.1
Construct your class to contain multiple constructors.
Use the this. Keyword if you like.
Execute a few versions of the program
Passing different values into the program using different parameter and argument configurations.
Output:
The BMI for John is 26.5 which is the Over Weight Category.
or
The BMI for Susan is 17 which is in the Moderate Thiness Category
Explanation / Answer
public class BMI {
private String name;
private double height;
private double weight;
/**
* @param name
* @param height
* @param weight
*/
public BMI(String name, double height, double weight) {
super();
this.name = name;
this.height = height;
this.weight = weight;
}
public double getBMI(){
return 703*weight / height * height; //Weight in lbs, height in inches
}
public String getBMIType(){
double bmi = getBMI();
if(bmi <= 16)
return "Severe Thinness";
else if(bmi>=16.1 && bmi <= 17)
return "Moderate Thinness";
else if(bmi>=17.1 && bmi<=18.5)
return "Mild Thinness";
else if(bmi>=18.6 && bmi<=26)
return "Normal";
else if(bmi>=26.1 && bmi<= 30)
return "Overweight";
else if(bmi>=30.1 && bmi<=35)
return "Obese Class I";
else if(bmi>=35.1 && bmi<=40)
return "Obese Class II";
else
return "Obese Class III";
}
public void displayBMI(){
System.out.println("The BMI for "+name+" is "+String.format(".1f", getBMI())+" which is the "+getBMIType());
}
}
################## Test Class #################
public class TestBMI {
public static void main(String[] args) {
BMI b1 = new BMI("Alex", 23, 43.23);
b1.displayBMI();
}
}
/*
Output:
The BMI for Alex is .1f which is the Obese Class III
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.