Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

- weight: double - bmi: double - category - calcBMIO: void + BMIO + setHeight(do

ID: 3734572 • Letter: #

Question

- weight: double - bmi: double - category - calcBMIO: void + BMIO + setHeight(double h): void + setWeight(double w) : void + getHeight): double + getWeight(): double + getBMI0 : double - setCategory): void +getCategory):String Add methods definition and variable declaration to reflect the new BMI class definition as shown in the UML diagram. Add statement(s) in your driver class so that the category is also shown. Task 3: Change the Unit In most BMI calculator that you googled, it would provide you with two types of unit measurement which are the Standard (height in feet and inches and weight in pounds) and the metric (height in centimeters and weight in kilograms). 1 foot 0.3048m and 1 pound 0.454 kilograms. Add option to your BMI calculator where user now can choose which type of unit measurement that they want to use. Make necessary addition or changes in your BMI class definition to accommodate this option.

Explanation / Answer

Here is your solution:

BMI.java

/**

* @author Lokesh Kumar

*

*/

public class BMI {

private double height;

private double weight;

private double bmi;

private int category;

BMI() {

}

public void calcBMI() {

if (this.category == 1) {

this.weight = this.weight * 0.454; //Pounds into kilograms

this.height = this.height * 0.3048; //feet into meters

this.bmi = weight / height;

} else if (this.category == 2) {

this.height = this.height * 0.01 ; //centimeters into meters

this.bmi = weight / height;

}

}

public double getHeight() {

return height;

}

public void setHeight(double height) {

this.height = height;

}

public double getWeight() {

return weight;

}

public void setWeight(double weight) {

this.weight = weight;

}

public double getBmi() {

return bmi;

}

public void setBmi(double bmi) {

this.bmi = bmi;

}

public int getCategory() {

return category;

}

public void setCategory(int category) {

this.category = category;

}

}

BMIinput.java

import java.util.InputMismatchException;

import java.util.Scanner;

public class BMIinput {

public static void main(String[] args) {

Scanner stdin = null;

try {

BMI bmi = new BMI();

stdin = new Scanner(System.in);

int category = 1;

System.out.println("Select Units : ");

System.out.println("1.Standard (height in feet & weight in pounds)");

System.out.println("2.Metric (height in centimeters & weight in kilograms) ");

category = stdin.nextInt();

double weight;

System.out.println("Key in your weight: ");

weight = stdin.nextDouble();

System.out.println("Your weight is " + weight + " ");

double height;

System.out.println("Key in your height: ");

height = stdin.nextDouble();

System.out.println("Your height is " + height + " ");

double myBMI;

bmi.setWeight(weight);

bmi.setHeight(height);

bmi.setCategory(category);

bmi.calcBMI();

myBMI = bmi.getBmi();

System.out.printf("Your BMI is %.2f", myBMI);

} catch (InputMismatchException exception) {

stdin.close();

System.out.println("Wrong input please try again");

}

}

}