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

te lutumpne ploperties and assumes that the values provided are correct. Provide

ID: 3595944 • Letter: T

Question

te lutumpne ploperties and assumes that the values provided are correct. Provide a method DisplayDate that lashes ). Write a test app named DateTest that demonstrates class Date's capabilities. displays the month, day and year separated by forwarc Making a Difference Exercises 4.15 larget-Heart Rate Calculator) While exercising you can use a heart-rate monitor to se that c cXCTc sin ur heart rate stays within a safe range suggested by your trainers and doctors. According to the American Heart Association (AHA) (www.heart.org/HEARTORG/GettingHeal thy/PhysicalActivity/ arget-Heart-Rates UOM 434341 Article.jsp), the formula for calculating your maximum heart rate beats per minute is 220 minus your age in years. Your target herr rate is a range that is 50-85% of ur maximum heart rate [Note: These formulas are estimates provided by the AHA. Maximum and target heart rates may vary based on the health, fitness and gender of the individual. Always consult a physician or qualified health care professional before beginning or modifying an exercise program.) Create a class called HeartRates. The dass attributes should include the person's first name, last name year of birth and the current year. Your class should have a constructor that receives this data as pa- rameters. For each attribute provide a property with set and get accessors. The dass also should in- clude a property that calculates and returns the person's age (in years), a property that calculates and returns the person's maximum heart rate and properties that calculate and return the person's mini- mum and maximim target heart rates. Write an app that prompts for the person's information, instan tiates an object of class HeartRates and displays the information from that object-including the person's first name, last name and year of birth _-then caleulates and displays the person's age in (years), maximum heart rate and target-heart-rate ran

Explanation / Answer

package exception;

public class HeartRates {

private String firstName;

private String lastName;

private int yearOfBirth;

private int currentYear;

public String getFirstName() {

return firstName;

}

public void setFirstName(String firstName) {

this.firstName = firstName;

}

public String getLastName() {

return lastName;

}

public void setLastName(String lastName) {

this.lastName = lastName;

}

public int getYearOfBirth() {

return yearOfBirth;

}

public void setYearOfBirth(int yearOfBirth) {

this.yearOfBirth = yearOfBirth;

}

public int getCurrentYear() {

return currentYear;

}

public void setCurrentYear(int currentYear) {

this.currentYear = currentYear;

}

public HeartRates(String firstName, String lastName, int yearOfBirth, int currentYear) {

this.firstName = firstName;

this.lastName = lastName;

this.yearOfBirth = yearOfBirth;

this.currentYear = currentYear;

}

@Override

public String toString() {

return "HeartRates [firstName=" + firstName + ", lastName=" + lastName + ", yearOfBirth=" + yearOfBirth

+ ", currentYear=" + currentYear + "]";

}

public void display()

{

int age=getCurrentYear()-getYearOfBirth();

int maximumHeartRate=220-age;

double targetHeartRate=0.85*maximumHeartRate;

System.out.println("Age of the person is "+age);

System.out.println("Maximum Heart Rate of the person is "+maximumHeartRate);

System.out.println("Target Heart Rate of the person is "+targetHeartRate);

}

}

package exception;

import java.util.Scanner;

public class TestHeartRate {

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

System.out.println("Enter persons details:");

System.out.println("Enter persons firstName");

String firstName=sc.nextLine();

System.out.println("Enter persons lastName");

String lastName=sc.nextLine();

System.out.println("Enter year of birth");

int yearOfBirth=sc.nextInt();

System.out.println("Enter current year");

int currentYear=sc.nextInt();

HeartRates heartRates=new HeartRates(firstName,lastName,yearOfBirth,currentYear);

System.out.println(heartRates);

heartRates.display();

}

}