2016-04-07 7 views
-1

問題:私の計算結果は、アプリの結果とbmiのウェブサイトを比較したときにオフになります。あまりにも事前に感謝します、私の数学は本当に悪いので、私は事前に謝罪します。BMI電卓を作成するときに計算がオフになる

http://www.tiikoni.com/tis/view/?id=8bd04d4

ここでBMIサイトNIH

http://www.tiikoni.com/tis/view/?id=86d4458

BMIFRAG.java

 public class BmiFrag extends Fragment implements View.OnClickListener 
     { 

     Button BmiButton; 

     public static EditText heightFT; 
     public static EditText heightIn; 
     public static EditText weightIn; 


     @Override 
     public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     } 

     @Override 
     public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 


     View myView = inflater.inflate(R.layout.fragment_bmi, container, 
     false); 
     BmiButton = (Button) myView.findViewById(R.id.CalculateBmi); 
     BmiButton.setOnClickListener(this); 
     return myView; 
    } 

     @Override 
     public void onClick(View v) { 
     switch (v.getId()) { 

     case R.id.CalculateBmi: 







        weightIn = (EditText) 
       getActivity().findViewById(R.id.ETtweight); 

       heightIn = (EditText) 
       getActivity().findViewById(R.id.ETHeightIn); 

       heightFT = (EditText) 
       getActivity().findViewById(R.id.ETHeightFT); 

       final TextView tv4 = (TextView) 
       getActivity().findViewById(R.id.TFDisplayBmi); 


       String getWeightIN = weightIn.getText().toString(); 




      String getHeightIN = heightIn.getText().toString(); 

      String getHeightFT = heightFT.getText().toString(); 



      if (TextUtils.isEmpty(getWeightIN)) { 



       weightIn.setError("Please enter your weight"); 
       weightIn.requestFocus(); 
       return; 
      } 

      else if (TextUtils.isEmpty(getHeightIN)) { 
       heightIn.setError("Please enter your height in Inches"); 
       heightIn.requestFocus(); 
       return; 
      } 

      else if (TextUtils.isEmpty(getHeightFT)) { 
       heightFT.setError("Please enter your height in Feet"); 
       heightFT.requestFocus(); 
       return; 
      } 


      else { 

       float weight = Float.parseFloat(getWeightIN); 

       float heightIN = Float.parseFloat(getHeightIN) ; 
       float heightFT = Float.parseFloat(getHeightFT) ; 

       float bmiValue = calculateBMI(weight,heightIN,heightFT); 

       String bmiInterpretation = interpretBMI(bmiValue); 

        tv4.setText(String.valueOf(bmiValue + "-" + 
       bmiInterpretation)); 


       } 



       break; 

      } 
     } 


     private float calculateBMI(float weight, float heightIN, float v) { 



     float bmi= (float) (weight/ (heightIN*v)*4.88); 

     float total= Math.round(bmi); 



     return total; 
     } 


      private String interpretBMI(float bmiValue) { 

      if (bmiValue < 16) { 
      return "Severely underweight"; 
      } else if (bmiValue < 18.5) { 

      return "Underweight"; 
     } else if (bmiValue < 25) { 

      return "Normal"; 
     } else if (bmiValue < 30) { 

     return "Overweight"; 
     } else { 
      return "Obese"; 


     } 


     } 


     @Override 
     public void onActivityCreated(Bundle savedInstanceState) { 
     super.onActivityCreated(savedInstanceState); 
     } 

     @Override 
      public void onDestroy() { 
     super.onDestroy(); 

      } 

      @Override 
       public void onDetach() { 
      super.onDetach(); 
       } 
のベースと結果は以下のとおりです。ここ

は私のアプリが私を与えている結果であります

+0

正しい式 'float bmi =(float)(weight /(heightIN * v)* 4.88);を使用していますか? – vcp

+0

私はそれが正しいと信じています。私は何かを数えようとしました – user6079154

答えて

2

同じ数式。これを試してください:

float bmi = weight * 703f/(float)Math.pow(heightIN+12f*v,2); 

上記の式はhereです。

私はそれが役に立ちそうです。

+0

時間をかけて助けてくれてありがとう、もう一度感謝してくれました。 – user6079154

+0

今すぐリンクしてくれてありがとうございます – user6079154

+0

私の喜びです。あなたのアプリで幸運! – joel314

関連する問題