Question: JAVA- How do I edit my code to replace the line to calculate BMI with an entire a new method to calculate BMI similar to
JAVA- How do I edit my code to replace the line to calculate BMI with an entire a new method to calculate BMI similar to this---
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 Double.parseDouble(f.format(BMI)); } }
Here is my 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 %8s %9s %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)); //Replace this line with a new method 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); 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
Get step-by-step solutions from verified subject matter experts
