JAVA- Write a program that reads in a series of patient vitals and determines a
ID: 3827429 • Letter: J
Question
JAVA- Write a program that reads in a series of patient vitals and determines a health score based on those vitals. The following data will be read from the input (all except name will be integers): Name Heart rate Respiratory rate Height (in inches) Weight (in pounds) Systolic pressure (top number of blood pressure reading) Diastolic pressure (bottom number of blood pressure reading)
Details There are an unknown number of patient records. Use Scanner.hasNext() to continue reading input until all records have been processed. You must validate for each patient record that all vitals are positive, nonzero integers. If any data point is not valid according to this criteria, print the message “Invalid record!” and do no calculations. Each patient will be given a health score between 1 and 5, displayed as a series of asterisks (e.g. *** for a score of 3). To calculate the health score, determine how many of the vitals are within the healthy ranges below. If all vitals are healthy, the patient receives a score of 5. If no vitals are within the healthy range, the patient receives a score of 1. For each unhealthy vital, print “!!” before that measurement in the output. Using the patient’s height and weight, you must calculate their body mass index (BMI), formatted to 1 decimal place. The formula for BMI is as follows: BMI = weight in kg / (height in meters * height in meters) (1 kilogram = 0.453592 pounds) (1 inch = 0.0254 meters) Healthy ranges for vitals: Heart rate: 60 <= rate <= 100 Respiratory rate: 12 <= rate <= 18 BMI: 18.5 <= bmi <= 25.0 Systolic pressure: 90 <= p <= 120 Diastolic pressure: 60 <= p <= 80 Program Structure You are required to use at least two methods: 1) your main method, and 2) a method for calculating BMI. If possible, do this program WITHOUT using FLAGS.
Explanation / Answer
import java.util.Scanner;
public class HealthCheck {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(true){
System.out.println("Enter name: ");
String name = sc.next();
System.out.println("Enter Heart Rate : ");
int heartRate = sc.nextInt();
System.out.println("Enter RespiratoryvRate: ");
int respiratoryRate = sc.nextInt();
System.out.println("Enter height(in inches): ");
int height = sc.nextInt();
System.out.println("Enter Weight(in pounds): ");
int weight = sc.nextInt();
System.out.println("Enter Systolic pressure: ");
int systolicPressure = sc.nextInt();
System.out.println("Enter Diastolic pressure: ");
int diastolicPressure = sc.nextInt();
System.out.print("================ "+name.toUpperCase()+" ================= ");
double BMI = (((double)weight)*0.453592d)/((((double)height)*0.0254)*(((double)height)*0.0254));
System.out.println("BMI :"+BMI);
int score = 1;
if(heartRate>=60 && heartRate<=100){
score++;
System.out.println("Heart Rate :"+heartRate);
}
else{
System.out.println("Heart Rate :"+heartRate+" !!");
}
if(respiratoryRate>=12 && respiratoryRate<=18){
score++;
System.out.println("Respiratory Rate :"+respiratoryRate);
}
else{
System.out.println("Respiratory Rate :"+respiratoryRate+" !!");
}
if(systolicPressure>=90 && systolicPressure<=120){
score++;
System.out.println("Systolic pressure :"+systolicPressure);
}
else{
System.out.println("Systolic pressure :"+systolicPressure+" !!");
}
if(diastolicPressure>=60 && diastolicPressure<=80){
score++;
System.out.println("Diastolic pressure :"+diastolicPressure);
}
else{
System.out.println("Diastolic pressure :"+diastolicPressure+" !!");
}
System.out.println("===============================================");
System.out.print("Total Health Score :");
for(int i=0;i<score;i++)
System.out.print("*");
System.out.println(" -----------------------------------------------");
System.out.println(" Do you want to continue (Y/N):");
String ans = sc.next();
if(ans.charAt(0)=='Y'||ans.charAt(0)=='y')
continue;
break;
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.