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. The formula for calculating your maximum heart rate in beats per minute is 220 minus your age in years. Your target heart rate in beats per minute is 50-85% of your maximum heart rate.
FirstFile.cs
Create a class called HeartBeats. The class properties should include the person's
first name, last name, year of birth and current year. Your class should have
a constructor that receives this data as parameters. For each attribute provide a
property with set and get accessors. The class also should include 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 methods that calculate and return the
person's minimum and maximum target heart rates.
SecondFile.cs:
Write a test class that prompts for the person's information, instantiates an object of
class HeartBeats and displays the information from that object- including the person's
first name, last name, and year of birth then calculates and displays the person's age
in years, maximum heart rate and target heart rate range.
using System;
namespace ConsoleApplication253
{
// test Program
class Program
{
// main method
static void Main(string[] args)
{
HeartRates hr1 = new HeartRates("kane","jackie",1976,2020); // object creation with constructor
Console.WriteLine("Persons age is "+hr1.personsAge()); // printing person's age
Console.WriteLine("Maximum heart rate is " + hr1.maximumHeartRate()); // maximum heart rate
Console.WriteLine("Target heart rate range is " + hr1.maximumTargetHearrate() +" to "+hr1.minimumTargetHearrate()); // maximum to minimum target heart rate
Console.Read();
}
}
// class HeartRates
class HeartRates
{
//local variables
string firstName;
string lastName;
int yearOfBirth;
int currentYear;
// public constructor
public HeartRates(string fn, string ln, int yob, int cy)
{
this.firstName=fn;
this.lastName = ln;
this.yearOfBirth = yob;
this.currentYear = cy;
}
// getters and setters
public string getFirstName()
{
return firstName;
}
public void setFirstName(string fn)
{
this.firstName=fn;
}
public string getlastName()
{
return lastName;
}
public void setlastName(string ln)
{
this.firstName = ln;
}
public int getyearOfBirth()
{
return yearOfBirth;
}
public void setyearOfBirth(int yb)
{
this.yearOfBirth = yb;
}
public int getcurrentYear()
{
return currentYear;
}
public void setcurrentYear(int cy)
{
this.currentYear = cy;
}
// method to calculate person's age
public int personsAge()
{
return currentYear - yearOfBirth;
}
// method to calculate maximum heart rate
public int maximumHeartRate()
{
return 220 - personsAge();
}
// method to calculate minimum target range
public double minimumTargetHearrate()
{
return (0.50 * maximumHeartRate());
}
// method to calculate maximum target range
public double maximumTargetHearrate()
{
return (0.85 * maximumHeartRate());
}
}
}
I need help displaying "the person's first name, last name, and year of birth then calculates and displays the person's age in years, maximum heart rate and target heart rate range". I need HeartBeats and TestClass in two different CS files.
While exercising, you can use a heart rate monitor to see that your heart rate stays within a safe range suggested by yo
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am