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

need help writing this java program Programming Project l. (Target-Heart-Rate Ca

ID: 3777304 • Letter: N

Question

need help writing this java program

Programming Project l. (Target-Heart-Rate Calculator While exercising, you can use a heart-rate monitor to see that your heart rate stays within a safe range suggested by your trainers and doctors. According to the American Heart Association (AHA), the formula for calculating your maximum heart in beats per minute is 220 minus your age in years. Your target heart is a range that is 50-85% of your 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 class attributes should include the person's first name,last name, and date of birth (consisting of separate attributes for the month, day, and year of birth). Your class should have a constructor that receives this data as parameters. For each attribute provide set and get methods. The class also should include a method that calculates and returns the person's age in years), a method that calculates and returns the person's target heart rate. Write a Java application that prompts for the person's information, instantiates an object of class HeartRates and prints the information from that object including the person's first name, last name and date of birth- then calculates and prints the person's age in (years), maximum heart rate and target-heart rate range run: First name: Bob Last name: Blue Age: 34 Maximum heart rate: 186 Target heart rate range: Minimum: 93 Maximum: 158 BUILDSUCCESSFUL (total time: 1 second)

Explanation / Answer

package abc;

import java.util.Calendar;
import java.util.Scanner;

public class HC {

   public static void main(String[] args) {
      
       //Getting all the inputs
       Scanner cin = new Scanner(System.in);
       System.out.println("Please enter your first name");
       String fname = cin.next();
       System.out.println("Please enter your last name");
       String lname = cin.next();
       System.out.println("Please enter date part of your Date of Birth in dd Format");
       int date = cin.nextInt();
       System.out.println("Please enter month part of your Date of Birth in MM Format");
       int mon = cin.nextInt();
       System.out.println("Please enter year part of your Date of Birth in yyyy Format");
       int year = cin.nextInt();
       cin.close();
      
       //Creating HeartRates class object and passing values in constructor
       HeartRates h = new HeartRates(fname, lname, date, mon, year);
      
       //Calling the function for calculating heart rates
       int hRates[] = h.calcHeartRate();
       //Printing all details
       System.out.println("First Name: "+h.getFirstName());
       System.out.println("Last Name: "+h.getLastName());
       System.out.println("Age: "+h.calcAge());
       System.out.println("Maximum heart rate: "+hRates[0]);
       System.out.println("Target heart rate range");
       System.out.println(" Minimum: "+hRates[1]);
       System.out.println(" Maximum: "+hRates[2]);
              
      
   }
}

class HeartRates{
  
   private String firstName;
   private String lastName;
   private String dob;
  
   public HeartRates(String firstName, String lastName, int d, int m, int y) {

       this.firstName = firstName;
       this.lastName = lastName;
       this.dob = ""+d+"/"+m+"/"+y;
   }
  
   /*String str[] = dob.split("/");
   int day = Integer.parseInt(str[0]);
   int month = Integer.parseInt(str[1]);
   int year = Integer.parseInt(str[2]);*/

   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 String getDob() {
       return dob;
   }

   public void setDob(String dob) {
       this.dob = dob;
   }
  
   public int calcAge(){
      
       String str[] = dob.split("/");
       int year = Integer.parseInt(str[2]);
       Calendar now = Calendar.getInstance();
       int curryear = now.get(Calendar.YEAR);      
       int age = curryear - (int)year;
       return age;
   }
  
   public int[] calcHeartRate(){
      
       int age = calcAge();
       int max = 220 - age;
       int tarMin = (int)(.5 * max);
       int tarMax = (int) (.85 * max);
      
       return new int[] {max, tarMin, tarMax};
   }
  
}