Question: Make the attached screen or GUI work. You must apply Exception Handling for this program (BMI Calculator and BMI Calculator Driver. Here are the programs
Make the attached screen or GUI work.
You must apply Exception Handling for this program (BMI Calculator and BMI Calculator Driver.
Here are the programs that must be used for the things that are mentioned above:
BMICalculator:
package edu.pupr.BMICalc;
import java.util.*; // Here we have the attributes set for the results public class BMICalc { double height; double weight; double BMICalc; //Here are the attributes that are going to be calculated public static double calculate(double height, double weight) { height = height * height; weight = (weight * 703); return weight / height; } //The determination of the BMI based on the output public static String message (double bmi) { String category; if (bmi < 18.5) { category = "underweight"; } else if (bmi < 25) { category = "normal"; } else if (bmi < 30) { category = "overweight"; } else { category = "obese"; } return category; } //Setters for the program public void setHeight(int height){ this.height = height; } public void setWeight(int weight){ this.weight = weight; } public void setBMI(double bMI) { BMICalc = bMI; } //Getters for the program public double getHeight(){ return height; } public double getWeight(){ return weight; } public double getBMI() { return BMICalc; } //Ask function for the source leak public void ask(){ @SuppressWarnings("resource") Scanner scanner = new Scanner(System.in); System.out.println(); System.out.println("What is your height in inches?"); height = scanner.nextInt(); System.out.println("What is your weight in pounds?"); weight = scanner.nextInt(); BMICalc = calculate(weight, height); } //Show function for the source leak public void show(){ System.out.println(); System.out.printf("You weight: %", weight); System.out.println(); System.out.printf("Your height is: %", height); System.out.println(); System.out.printf("Your BMI is: %", BMICalc, message(BMICalc)); System.out.println(); } } //Output: //Your BMI is: 30.406574 (obese).
BMICalculatorDriver:
package edu.pupr.BMICalc; //Here is the driver for the BMICalc class BMICalculatorDriver { public static void main(String[] args) { BMICalc scanner = new BMICalc(); scanner.ask(); scanner.show(); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
