Latest :

Heart Rate Calculator Java Code | 4 Ways

Java program to calculate Heart Rate –  In this article, we will explain the various ways.

The methods that have been used in this article are as follows:

  • Using Scanner Class
  • Using Static Method

It is absolutely known to all of us that the Heart is responsible for pumping blood to all parts of our body. It is the central element of the Circulatory system of our body.

It pumps out pure blood to various organs and tissues and impure blood to the lungs, kidneys and liver.

Heart Rate Calculator Java Code

Thus, the Heart Rate can be defined as the number of times the Heart pumps out the blood to and from the organs in a given unit period of time. One heartbeat results in the completion of one cycle of the transported blood.

A normal adult human being has a heart rate of around 60 – 100 beats per minute. Anything lower or higher than that needs medical attention.

Java Calculate Heart Rate – Using Scanner Class

To calculate the target heart rate zone, we require the following inputs- age (age), resting heart rate (rhr), low end heart rate zone (minPer), high end hear rate zone (maxPer) and gender (g). These inputs are read at runtime by making use of Scanner class in Java


Using Static Method

In the above method, it is observed that, the entire code is written within the main method itself. If ever, in future we would like to make use of the same logic in some other part of the code, we would require to write the same set of statements again.

So, it is convenient to reuse the same block than rewriting it and for this we make use of separate static method blocks.

In our example, the main method will read all the required inputs as done in the above method. It then checks for the gender. If the gender is male (g=1) then, a static method named maleHeartRate is called by sending age, rhr, minPer and maxPer as parameters.

Else, if the gender is female (g=2) then, another static method named femaleHeartRate is called sending age, rhr, minPer and maxPer as parameters.



Check Also

Rhombus Star Pattern Program In Java – Patterns

Java program to print Rhombus star pattern program. We have written the below print/draw Rhombus ...