Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8795419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:23:03+00:00 2026-06-13T23:23:03+00:00

The maximum heart rate is the highest heart rate obtained during maximum exercise. The

  • 0

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.

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:

Target Heart Rate = [(Maximum Heart Rate – Resting Heart Rate) × 80%]

The program must be able to display the use’s maximum heart Rate, resting heart rate and Target Heart Rate.

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.

ive looked over and over it and cannot seem to figure out this logical error. here is my 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;
    }

}
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:23:04+00:00Added an answer on June 13, 2026 at 11:23 pm

    Well, I could understand it if you were getting 176 for a male and 169 for a female… but not 179. Are you sure about that?

    I suspect Integer.parseInt is failing for you – but you can’t tell, because of this:

    catch (NumberFormatException e){}
    

    Never just catch an exception and completely ignore it. Put logging in there at the very least.

    You’re doing the same for both inputs. Why would you want to continue (and put up bogus data) if either parse operation failed? Surely you should just stop at that point, and inform the user that they should fix their input.

    Next there’s the way that you’re performing the arithmetic. You’re doing it all in integer arithmetic, but then using Double.toString – why? That’s only ever going to give you a value ending in .0. If you want to actually get a non-integer result, you need to perform the arithmetic in floating point. e.g.

    // I've changed the names of some variables to comply with conventions
    double maximumRate = MALE_MAXIMUM_RATE_LIMIT - parsedAge;
    double targetRate = (maximumRate - parsedRestingRate) * 0.8;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any maximum count of web worker that can be run at the
Apparently there's a maximum number of arguments for std::thread for the std::thread implementation in
Possible Duplicate: Maximum Number of Tables in MySQL Is there a recommended number of
I heard from someone that the maximum array size in .NET is 4 GB?
The maximum interval of timer is 2,147,483,647. it's about 25 days. But in my
For maximum load speed and page efficiency, is it better to have: An 18MB
Default JVM uses maximum 1.5 GB RAM/JVM Java application. But my Server have 8
The goal here is maximum conversion of users to an application. I tried to
What is the maximum size of a DataTable I can load into memory in
What is the maximum memory one application can use? Please find instrument screenshot with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.