A local health club wants to computerize the Body Mass Index (BMI) calculation f
ID: 3851981 • Letter: A
Question
A local health club wants to computerize the Body Mass Index (BMI)
calculation for its members.
The BMI calculator uses height and weight to calculate the BMI. The BMI
formula is:
Write java code for a BMI Class with both a default & non-default
constructor, standard accessors, mutators (with valid argument checking), a
method to return the BMI value, and a toString() method. The toString()
method should also return the Weight Status from the below table.
BMI Weight Status Categories
BMI Weight Status
Below 18.5 Underweight
18.5 -24.9 Normal
25 - 29.9 Overweight
30 & Above Obese
Here is a sample code segment you might use to test your BMI class.
BMI data1 = new BMI();
BMI data2 = new BMI(250, 60);
data1.setHeight(76);
double value=data2.getBMI();
System.out.println(data1);
System.out.println(data2);
8. Write your own class called WeatherStats to manage the ordered collection
of high temperatures. Have two constructors, one for a default maximum size
collection of 10, and the second for a user argument defined maximum size
collection. The user class will not do any prompting to the user or reading
of data, instead create the following methods:
• boolean addNextTemp (double temp) – add the temp to the next available
position in the collection, if room allows.
• getMaxDifference() – returns the maximum change in temperature (in
absolute value) on two consecutive days.
• getMaxDiffDay() – returns the day number for the second day of the two
consecutive days that the maximum change in temperature (in absolute value)
occurred.
Explanation / Answer
Answer-> I write this program according to the requirements of the question .
--------------------------------------------------------------------------------------------------------------------------------------------------------------
package my_chegg_package;
public class BMIClass {
public double weight ; /* i am taking weight in kg because it is not given in the question*/
public double height ; /* i am taking height in cm because it is not given in the question*/
public double bmiValue;
public BMIClass()
{
weight = 0;
height = 0;
}
public BMIClass(double weight,double height)
{
this.weight = weight;
this.height = height;
}
public double getWeight() {
return weight;
}
public void setWeight(double weight) {
this.weight = weight;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
double getBMI()
{
double tempValue1 = height/100;
bmiValue = weight /(tempValue1*tempValue1);
return bmiValue;
}
@Override
public String toString(){
if(bmiValue < 18.5)
{
return "BMI value : "+ bmiValue + ""+ " Wait Status : "+ "Under Weight";
}
else if(bmiValue >= 18.5 && bmiValue <= 24.9)
{
return "BMI value : "+ bmiValue + ""+ " Wait Status : "+ "Normal";
}
else if(bmiValue >= 25 && bmiValue <= 29.9)
{
return "BMI value : "+ bmiValue + ""+ " Wait Status : "+ "OverWeight";
}
else if (bmiValue >= 30)
{
return "BMI value : "+ bmiValue + ""+ " Wait Status : "+ "Obese";
}
return null;
}
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------
package my_chegg_package;
public class TestBmiClass {
public static void main(String[] args) {
BMIClass data1 = new BMIClass();
BMIClass data2 = new BMIClass(70,175);
data1.setWeight(65);
data1.setHeight(125);
double value1=data1.getBMI();
double value2=data2.getBMI();
System.out.println(data1);
System.out.println(data2);
}
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------
OUTPUT ->
BMI value : 41.6 Wait Status : Obese
BMI value : 22.85714 Wait Status : Normal
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.