In: Computer Science
You are working as a software developer for a large insurance company. Your company is planning to migrate the existing systems from Visual Basic to Java and this will require new calculations. You will be creating a program that calculates the insurance payment category based on the BMI score.
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.
Store all the information in the file. You need to use the loop and keep asking users to enter patient name, height, weight, and birthdate. Your program should calculate BMI Category and Insurance payment category and write it to the file. Your program should stop once user enter q character.
You need to submit the following things:
An entire Java solution
An output screenshot created using Microsoft Word
Code
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Scanner;
public class BMI
{
public static void main(String[] args) throws
FileNotFoundException, IOException
{
String name,date,bmiStatus,insuranceStatus;
double weight,height,BMI;
Scanner sc=new Scanner(System.in);
File fout = new File("out.txt");
FileOutputStream fos = new
FileOutputStream(fout);
BufferedWriter bw = new BufferedWriter(new
OutputStreamWriter(fos));
while(true)
{
System.out.print("Enter the name of the patient (or q to stop):
");
name=sc.next();
if(name.equalsIgnoreCase("q"))
break;
System.out.print("Enter the birth date of the patient (dd/mm/yyyy):
");
date=sc.next();
System.out.print("Enter the weight of the patient (in pound):
");
weight=sc.nextDouble();
System.out.print("Enter the height of the patient (in inches):
");
height=sc.nextDouble();
BMI= weight * 730 /(height * height);
if(BMI<18.5)
{
bmiStatus="underweight";
insuranceStatus="low";
}
else if (BMI>=18.5 && BMI<=24.9 )
{
bmiStatus="Normal";
insuranceStatus="low";
}
else if (BMI>=25 && BMI<=29.9 )
{
bmiStatus="Overweight";
insuranceStatus="high";
}
else
{
bmiStatus="Obesity";
insuranceStatus="highest";
}
String strDouble = String.format("%.2f", BMI);
System.out.println("BMI index calculated and write to file
succesfull to file.");
bw.write("Patient Name: "+name+"\r\n"+"Birth Date: "+date+"\r\nBMI
Index: "+strDouble+"\r\nBMI Category: "+bmiStatus+"\r\nInsurance
payment category is:" +insuranceStatus);
bw.newLine();
bw.newLine();
System.out.println("");
}
bw.close();
}
}
output
text file