Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1.Using Java Write a program to input a person’s age and rest heart rate, then o

ID: 3729412 • Letter: 1

Question

1.Using Java Write a program to input a person’s age and rest heart rate, then output the person’s maximal heart rate and aerobic target zone.

In the main method, a loop is need to keep prompting the user to input age and rest heart rate until the user inputs negative number as either the age or rest heart rate.

The program MUST have the following four methods, in additional to the main method:

(1) A method named inputValue that prompts the user to input an integer

(2) A method named maxHR that returns the maximal heart rate

(3) A method named targetZone that returns either the lower or higher end of the aerobic target zone

(4) A method named printInfo that displays the maximal heart rate, the lower and higher ends of the aerobic target zone

For optimal aerobic benefit, a person should maintain a heart rate (heartRate) between 60% and 80% of his or her maximal heart rate, this range is called the aerobic target zone. heartRate = k*(maxHeartRate-restHeartRate) + restHeartRate where: restHeartRate is the person's rest heart rate maxHeartRate is a person's maximal heart rate calculated by maxHeartRate 220 - age k is the percentage of maximal heart rate(0.06 for the lower rate, and 0.08 for the higher rate) Write a program to input a person's age and rest heart rate, then output the person's maximal heart rate and aerobic target zone. In the main method, a loop is need to keep prompting the user to input age and rest heart rate until the user inputs negative number as either the age or rest heart rate. (2 points) The program MUST have the following four methods, in additional to the main method: (1) (2 points) A method named inputValue that prompts the user to input an integer (the main method will invoke this method twice to get age and rest heart rate), the header of the method should be public static int inputValue (Scanner) (2) (2 points) A method named maxHR that returns the maximal heart rate, the header of the method should be public static int maxHR (int 3) (3 points) A method named targetZone that returns either the lower or higher end of the aerobic target zonee (rounded to the nearest integer after the calculation), the header of the method should be public static int targetZone (double, int, int ) // the parameter list is in the order of // k, restHeartRate, maxHeartRate 4) (1 points) A method named printinfo that displays the maximal heart rate, the lower and higher ends of the aerobic target zone, the header of the method should be public static void printInfo (int, int, int) // the parameter list is in the order of // maxHeartRate, lowerHeartRate, higherHeartRate

Explanation / Answer

Given below is the code for the question.
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
Please do rate the answer if it was helpful. Thank you

import java.util.Scanner;

public class HeartRate {

public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int age, restHeartRate, maxHeartRate, lowerHeartRate, higherHeartRate;
boolean again = true;
while(again)
{
System.out.print("Enter your age (enter -ve value to quit): ");
age = inputValue(keyboard);
if(age > 0)
{
System.out.print("Enter your resting heart rate (enter -ve value to quit): ");
restHeartRate = inputValue(keyboard);
if(restHeartRate <= 0)
again = false;
else
{
maxHeartRate = maxHR(age);
lowerHeartRate = targetZone(0.6, restHeartRate, maxHeartRate);
higherHeartRate = targetZone(0.8, restHeartRate, maxHeartRate);
printInfo(maxHeartRate, lowerHeartRate, higherHeartRate);
}
}
else
again = false;

}

}

public static int inputValue(Scanner keyboard)
{
return keyboard.nextInt();
}

public static int maxHR(int age)
{
return 220 - age;
}

public static int targetZone(double k, int restHeartRate, int maxHeartRate)
{
return (int)(k * (maxHeartRate - restHeartRate) + restHeartRate);
}

public static void printInfo(int maxHeartRate, int lowerHeartRate, int higherHeartRate)
{
System.out.println("Your maximum heart rate: " + maxHeartRate);
System.out.println("Aerobic target zone: " + lowerHeartRate + " - " + higherHeartRate);
}
}

---output----
Enter your age (enter -ve value to quit): 25
Enter your resting heart rate (enter -ve value to quit): 70
Your maximum heart rate: 195
Aerobic target zone: 145 - 170
Enter your age (enter -ve value to quit): 40
Enter your resting heart rate (enter -ve value to quit): 72
Your maximum heart rate: 180
Aerobic target zone: 136 - 158
Enter your age (enter -ve value to quit): -2

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote