In: Computer Science
Your Java program should perform the following things:
Take the input from the user about the patient name, weight, birthdate, and height.
Calculate Body Mass Index.
Display person name and BMI Category.
If the BMI Score is less than 18.5, then underweight.
If the BMI Score is between 18.5-24.9, then Normal.
If the BMI score is between 25 to 29.9, then Overweight.
If the BMI score is greater than 29.9, then Obesity.
Calculate Insurance Payment Category based on BMI Category.
If underweight, then insurance payment category is low.
If Normal weight, then insurance payment category is low.
If Overweight, then insurance payment category is high.
If Obesity, then insurance payment category is highest.
Implement exception handling using try-catch.
Include the finally block.
You need to submit the following things:
An entire Java solution
An output screenshot created using Microsoft Word
/*************************************BMI.java************************************/
import java.util.Scanner;
public class BMI {
public static void main(String[] args) {
/*
* local variable for saving the
patient information
*/
double weight = 0;
String birthDate = "", name =
"";
int height = 0;
Scanner scan = new
Scanner(System.in);
System.out.print("Please enter
patient name: ");
/*
* try catch block for valid data
for weight catch block for null value catch
* block for divide by zero
excepetion if height is zero finally block
*/
try {
name =
scan.nextLine();
System.out.print("Please enter the weight of the patient in kg:
");
weight =
scan.nextDouble();
scan.nextLine();
System.out.print("Please entet the birth date of patient: ");
birthDate =
scan.nextLine();
System.out.print("Please enter the height of patient in cm:
");
height =
scan.nextInt();
} catch (NumberFormatException e)
{
System.out.println("Please enter valid data!");
} catch (ArithmeticException e)
{
System.out.println("Height can not be zero!");
} catch (NullPointerException e)
{
System.out.println("Name can not be blank!");
} finally {
System.out.println("Welcome to BMI calculator!!");
}
// calculate height in meter
double heightInMeter = (double)
height / 100;
// calculate BMI
double bmi = weight /
(heightInMeter * heightInMeter);
String bmiCategory = "";
String insuranceCategory =
"";
/*
* set BMI category as BMI set
Insurance Payment category as BMI category
*/
if (bmi <= 18.5) {
bmiCategory =
"underweight";
insuranceCategory = "Low";
} else if (bmi > 18.5 &&
bmi <= 24.9) {
bmiCategory =
"Normal";
insuranceCategory = "Low";
} else if (bmi > 25 &&
bmi <= 29.9) {
bmiCategory =
"Overweight";
insuranceCategory = "High";
} else if (bmi > 29.9) {
bmiCategory =
"Obesity";
insuranceCategory = "Highest";
}
scan.close();
/*
* Print the patient name and date
of birth print the patient BMI category print
* the patient insurance payment
category
*/
System.out.println("Patient " +
name + "and Date of birth is - " + birthDate + "\nPatient BMI
category is - "
+ bmiCategory);
System.out.println("And Patient
insurance payment category is - " + insuranceCategory);
}
}
/*******************************output***********************************/
Please enter patient name: Virat Kohli
Please enter the weight of the patient in kg: 78
Please entet the birth date of patient: 05/10/1993
Please enter the height of patient in cm: 178
Welcome to BMI calculator!!
Patient Virat Kohliand Date of birth is - 05/10/1993
Patient BMI category is - Normal
And Patient insurance payment category is - Low