私の結果があるので、私はBMI計算機を作成していますが、私はプログラムを実行すると、私は問題を抱えている:BMI電卓のJava
は0.0をnullweighsと背の高い0.0を測定します。あなたのBMIは
名前、体重、BMI、およびそれが体重不足、健康、過体重、または肥満であるかどうかを明記する必要があります。
public class Person {
private String firstName;
private double heightInches;
private double weightPounds;
public Person (String userFirstName, double userHeightInches, double userWeightPounds)
{
this.firstName = firstName;
this.heightInches = heightInches;
this.weightPounds = weightPounds;
}
public String getFirstName()
{
return this.firstName;
}
public double getHeightInches()
{
return this.heightInches;
}
public double getWeightPounds()
{
return this.weightPounds;
}
public void setFirstName (String firstName)
{
this.firstName = firstName;
}
public void setHeightInches(double userHeightInches)
{
this.heightInches = userHeightInches;
}
public void setWeightPounds(double userWeightPounds)
{
this.weightPounds = userWeightPounds;
}
@Override
public String toString()
{
return this.firstName + "weighs " + this.weightPounds + " and measures "
+ this.heightInches + " tall. Your BMI is ";
}
public double calculateBMI(double userHeightInches, double userWeightPounds)
{
double BMI = ((userWeightPounds/userHeightInches) * (userHeightInches)) * 703;
return BMI;
}
と....
public class BodyMassIndex {
public static Person anyPerson;
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
createPersonObject();
displayBMI();
}
public static void createPersonObject()
{
Scanner keyboard = new Scanner(System.in);
System.out.println("What is your first name?");
String firstName = keyboard.next();
System.out.println ("How tall are you (in inches)?");
Double heightInches = keyboard.nextDouble();
System.out.println("How much do you weigh (in pounds)?");
Double weightPounds = keyboard.nextDouble();
anyPerson = new Person(firstName, heightInches, weightPounds);
}
public static void displayBMI()
{
double userWeightPounds = 0;
double userHeightInches = 0;
double BMI = anyPerson.calculateBMI(userWeightPounds, userHeightInches);
System.out.println(anyPerson.toString());
if (BMI < 18.5)
{
System.out.println("Underweight");
}
else if (BMI >= 18.5 && BMI < 24.9) {
System.out.println("Healthy");
}
else if (BMI >= 25 && BMI < 29.9) {
System.out.println("Overweight");
}
else if (BMI >= 30) {
System.out.println("Obese");
}
}
プログラムをデバッグする必要があります。 –