Ask your own question, for FREE!
Computer Science 21 Online
OpenStudy (anonymous):

Programming question: Really need help! (Health application: computing BMI) Body Mass index (BMI) is a measure of health on weight. It can be calculated by taking your weight in kilograms and dividing by the square of your height in meters. Write a program that read three persons’ weight and height in pounds and inches, respectively, and calculate BMI for each person, then output each person’s weight (pounds), height (inches), and BMI to a file. Note that one pound is 0.45359237 kilograms and one inch is 0.0254 meters.

OpenStudy (anonymous):

I just need help with coding this. Thanks.

OpenStudy (anonymous):

@tejasvir

OpenStudy (anonymous):

import java.util.Scanner; public class MeasureBmi{ public static void main(String[] args){ final double kilograms_per_pound = 0.45359237 kg final double meters_per_inch = 0.0254 m double weight1, weight2, weight3 double height1, height2, height3 Scanner input=new Scanner(System.in); weight1=input.nextDouble(); weight2=input.nextDouble(); weight3=input.nextDouble(); height1=input.nextDouble(); height2=input.nextDouble(); height3=input.nextDouble(); double weight1=weight1*weight1*kilograms_per_pound double weight2=weight2*weight2*kilograms_per_pound double weight3=weight3*weight3*kilograms_per_pound double height1=height1*height1*meters_per_inch double height2=height2*height2*meters_per_inch double height3=height3*height3*meters_per_inch System.out.println("Weight\tHeight") System.out.println(weight1+"\t"+height1) System.out.println(weight2+"\t"+height2) System.out.println(weight3+"\t"+height3) } }

OpenStudy (anonymous):

well the first problem is in the decleration of your variables. you cant have kg tehre. kg isnt a valid java identifier.

OpenStudy (anonymous):

nor can you have meters there

OpenStudy (anonymous):

i removed both kg and m

OpenStudy (anonymous):

okay and the next thing is you cant just say double weight 1 wihtough assigining it to a variable.

OpenStudy (anonymous):

sorry to a value

OpenStudy (anonymous):

and your missing a bagillion semicolons at the end of your arguments

OpenStudy (anonymous):

fixed the semi-colons

OpenStudy (anonymous):

im just going to fix the code for you first and then tell you your mistakes

OpenStudy (anonymous):

alright. i'll keep working on the code too. thanks

OpenStudy (anonymous):

import java.util.Scanner; public class MeasureBmi{ public static void main(String[] args){ final double kilograms_per_pound = 0.45359237; final double meters_per_inch = 0.0254; Scanner input=new Scanner(System.in); double weight1=input.nextDouble(); double weight2=input.nextDouble(); double weight3=input.nextDouble(); double height1=input.nextDouble(); double height2=input.nextDouble(); double height3=input.nextDouble(); weight1=weight1*weight1*kilograms_per_pound; weight2=weight2*weight2*kilograms_per_pound; weight3=weight3*weight3*kilograms_per_pound; height1=height1*height1*meters_per_inch; height2=height2*height2*meters_per_inch; height3=height3*height3*meters_per_inch; System.out.println("Weight\tHeight"); System.out.println(weight1+"\t"+height1); System.out.println(weight2+"\t"+height2); System.out.println(weight3+"\t"+height3); } }

OpenStudy (anonymous):

if you are trying to change the value of weight 1 you cant say double weight 1 = weight1*weight1*kilograms_per_pound; you need to remove the double part of it.

OpenStudy (anonymous):

yeah, my prof did it that way so idk why

OpenStudy (anonymous):

hmm i dont think so.. re check the notes.

OpenStudy (anonymous):

it should work now .

OpenStudy (anonymous):

no errors, but i'm still trying to base it on the question. it says i have to take my weight in kilograms and dividing by the square of my height in meters, and doing so for 3 people.

OpenStudy (anonymous):

idk man.

OpenStudy (anonymous):

i'll see what i can do, thanks though

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!