I am very new to java trying to build a simple BMI calculator using a constructor, a public instance method and a toString method.
public class BMI {
public BMI(String name, double height, double weight){
}
public String getBMI() {
return (weight/height);
}
public String toString() {
return name + "is" + height + "tall and is " + weight +
"and has a BMI of" + getBMI() ;
}
public static void main(String[] args) {
}
i don't really know what i'm doing, so all help is appreciated. If you know how to complete this and can show me a main method which can demonstrate how to use it that would be even more appreciated.
thanks :)
解决方案
You already have a code so I'll just mention that BMI is weight (in kg) divided by height (in m) squared