Okay, I'm very, very new to java. I'm in an intro to computer science class and we got out first assignment to write a program. its from "An Into to Object Oriented Programming with java" by C. Thomas Wu.
all we have to do is create a program that calculate body mass index using the formula Bmi=Weight/(Height/100)^2 where weight is in kg and height is in cm.
Here is my code:
import javax.swing.*; class Bmi { public static void main(String[] args) { //***** // Declarations: //***** final double NUM1=100.0; //The constant 100 in the formula String weightin; //weight input String heightin; //height input String description; //if the output bmi is normal int weightp; //weight primitive int heightp; //height primitive double denom; //height/NUM1 double denommod; //(height/NUM1)(height/NUM1) double bmi; //final value-bmi heightin=JOptionPane.showInputDialog(null,"Please Enter your weight:\n (Kilograms)"); //get weight weightin=JOptionPane.showInputDialog(null,"Thanks you. Now, Please enter your Height:\n (centimeters)"); //get height weightp=Integer.parseInt(weightin); // convert height and weight to primitive values heightp=Integer.parseInt(heightin); denom=(heightp/NUM1); //calulations denommod=(denom*denom); bmi=(weightp/denommod); if(bmi<=18.5); //Understanding what the value means description="underweight"; if((bmi>18.5)&(bmi<=25)); description="normal"; if((bmi>25)&(bmi<=30)); description="overweight"; if(bmi>30); description="obese"; JOptionPane.showMessageDialog(null,"Your Body mass index is:" +bmi+ " \n This is considered " +description+"."); } }
I think the problem is in the middle chunk there with the operators labelled "calculations"
but it could be my data types?
my professor (who i think to be completely incompetent) told us to use these test parameters to start:
50 kg and 160 cm
i keep getting 640 with this program but the correct answer is roughly 19.5
if you could point out any convention errors, too, that would be great!
thanks!


LinkBack URL
About LinkBacks
Reply With Quote