Note that there are some explanatory texts on larger screens.

plurals
  1. POReceiving wrong result from calculation
    primarykey
    data
    text
    <blockquote> <p>The maximum heart rate is the highest heart rate obtained during maximum exercise. The difference in maximum heart rate depends on age and gender. There are simple methods to gauge your predicted maximum heart rate such as the formula 220 - your age = predicted maximum heart rate for a male. For instance, a 40-year-old male’s predicted maximum heart rate is 180 beats/minute. </p> </blockquote> <p>The program will need to calculate the maximum heart rate for a male using the formula: 220-their age=maximum heart rate and: 212-their age=maximum heart rate for a female. The user must be able to input their age and select their gender and select their resting heart rate. The program must then use this formula to determine your target heart rate:</p> <p>Target Heart Rate = [(Maximum Heart Rate – Resting Heart Rate) × 80%]</p> <p>The program must be able to display the use’s maximum heart Rate, resting heart rate and Target Heart Rate.</p> <p>but for some reason im receiving when i run my program it does not seem to fully take in the inputs and gives me a wrong answer when the button is clicked for male it gives me the answer of 179.0 for male and 169.0 for female.</p> <p>ive looked over and over it and cannot seem to figure out this logical error. here is my code.</p> <pre><code>public class MainHMR extends Activity implements View.OnClickListener { Button chkCmd; CheckBox Male, Femail; EditText age, RestHeart; TextView MaxHeart, TargetHeart; int m = 220; int f = 212; int AgeResult =0, RestResultFinal =0, TargetHeartFinal =0; double MaleResult, FemailResult; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_hmr); Initilise(); format(); Male.setOnClickListener(this); Femail.setOnClickListener(this); chkCmd.setOnClickListener(this); } private void Initilise() { // TODO Auto-generated method stub /* Button */chkCmd = (Button) findViewById(R.id.bResults); /* checkBox */Male = (CheckBox) findViewById(R.id.cbM); /* checkBox */Femail = (CheckBox) findViewById(R.id.cbF); /* EditText */age = (EditText) findViewById(R.id.etAge); /* EditText */RestHeart = (EditText) findViewById(R.id.etRestHeart); /* TextView */TargetHeart = (TextView) findViewById(R.id.etTargetHeard); } private void format() { // TODO Auto-generated method stub String change = age.getText().toString(); AgeResult = 0; // set it to 0 as the default try { AgeResult = Integer.parseInt(change); System.out.println(AgeResult); } catch (NumberFormatException e){} String changeTwo = RestHeart.getText().toString(); RestResultFinal = 0; // set it to 0 as the default try { RestResultFinal = Integer.parseInt(changeTwo); System.out.println(RestResultFinal); } catch (NumberFormatException e){} } @Override public void onClick(View v) { // TODO Auto-generated method stub switch(v.getId()){ case R.id.bResults: if (Male.isChecked()) { int result = m - AgeResult; MaleResult = ((result - RestResultFinal) * 0.8); String finalResult = Double.toString(MaleResult); TargetHeart.setText(finalResult); } else if (Femail.isChecked()) { int result = f - AgeResult; FemailResult = (int) ((result - RestResultFinal) * 0.8); String finalResult = Double.toString(FemailResult); TargetHeart.setText(finalResult); break; } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload