Question: Use assignment # 2 (if you do not use the class you will get zero). Make the screen or GUI attached. They must apply Exception

Use assignment # 2 (if you do not use the class you will get zero). Make the screen or GUI attached. They must apply Exception Handling.

Setters should not accept negative numbers.

the variables must be declared one per line.

Use assignment # 2 (if you do not use the class you

assignment # 2:

package edu.pupr.BMI2;

import java.util.Scanner;

public class BMICalculation2 {

/**

* El main de BMI que pide al usuario su peso y altura para calcular el Body Mass Index.

* Con el parametro args.

*

*/

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

System.out.print("How many pounds you weight? ");

double weight = in.nextDouble();

System.out.print("What is your height in inches? ");

double height = in.nextDouble();

try {

BMI2 bmi = new BMI2(weight, height);

bmi.printBMIResult();

} catch (Exception e) {

System.out.println("Error: " + e.getMessage());

}

}

}

public class BMI2

{

private double weight, height;

/**

* Las variables que se utilizaran para calcular el BMI

* parametros de weight

* parametros de height

*

* El constructor y con los get y ser de cada una de los parametros y variables que se utilizaran.

*/

public BMI2(double weight, double height) { //Variables

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;

}

public double calculateBMI() {

if(height == 0) throw new IllegalStateException("Height can not be zero.");

return (weight * 703) / (height * height);

}

/**

* Permite definir las diferentes categorias del BMI

*

* Calcular cuando el usuario de sus peso y altura le de su BMI.

*

*/

public void printBMIResult() {

double bmi = calculateBMI();

String category;

if(bmi

category = "Underweight";

} else if(bmi

category = "Normal weight";

} else if(bmi

category = "Overweight";

} else {

category = "Obese";

}

System.out.printf("Your BMI is %.1f (%s) ", bmi, category);

}

}

BMI Calculator Height: 5ft 8 in. Weight: 200 Ibs Iculate Close 30.4 Obese

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!