Question: JAVA- How do I edit the following code as minimally as possible to add this method for calculating BMI? BMI Method: public static double calculateBMI(int

JAVA- How do I edit the following code as minimally as possible to add this method for calculating BMI?

BMI Method:

public static double calculateBMI(int height, int weight) { double BMI = (((double) weight) * 0.453592d) / ((((double) height) * 0.0254) * (((double) height) * 0.0254)); Format f = new DecimalFormat("##.######"); return (f.format(BMI)); }

Code:

import java.text.DecimalFormat; import java.util.Scanner; public class test2 { public static void main(String[] args) { DecimalFormat f = new DecimalFormat("##.0"); Scanner reader = new Scanner(System.in);

System.out.printf("%10s %15s %12s %8s %8s %8s %9s %8s %n", "Name", "Heart Rate", "Resp Rate", "Height", "Weight", "BMI", "BP", "Score");

while(reader.hasNext()){ String name = reader.next(); int heartRate = reader.nextInt(); int respiratoryRate = reader.nextInt(); int height = reader.nextInt(); int weight = reader.nextInt(); int systolicPressure = reader.nextInt(); int diastolicPressure = reader.nextInt(); double BMI = (((double)weight)*0.453592d)/((((double)height)*0.0254)*(((double)height)*0.0254));

if(heartRate == 0 ||respiratoryRate == 0 ||height == 0 ||weight == 0 ||systolicPressure == 0 || diastolicPressure== 0){ System.out.print("Invalid record!"); } else{ System.out.printf("%10s", name);

int score = 1;

if(heartRate>=60 && heartRate<=100){ score++; System.out.printf("%16s", heartRate); } else{ System.out.printf("%16s", "!!" +heartRate); }

if(respiratoryRate>=12 && respiratoryRate<=18){ score++; System.out.printf("%13s", respiratoryRate);

} else{ System.out.printf("%13s", "!!" +respiratoryRate); }

System.out.printf("%9s", height); System.out.printf("%9s", weight);

if(BMI>=18.5 && BMI <=25.0){ System.out.printf("%9s", f.format(BMI)); } else{ System.out.printf("%9s", "!!" + f.format(BMI)); }

if((systolicPressure>=90 && systolicPressure<=120) && (diastolicPressure>=60 && diastolicPressure<=80)){ score++; System.out.printf("%11s", systolicPressure + "/" + diastolicPressure + "\t"); } else{ System.out.printf("%11s", "!!" + systolicPressure + "/" + diastolicPressure + "\t"); }

for(int i=0;i

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!