22.6k views
1 vote
You are requested to design a class that keeps records of a person's health profile. Create a class named HealthRecord for a person. The class attributes should include:

a. The person's first name, last name, gender, date of birth (consisting of separate attributes for the month, day and year of birth), height (in meters) and weight (in kilograms).
b. Your class should have a constructor that receives the first three attributes (first name, last name, and gender).
c. For each attribute, provide set and get methods.
d. The class should include methods that calculate and return the user's age in years.

User Araspion
by
7.4k points

1 Answer

1 vote

Final answer:

The question involves designing a 'HealthRecord' class in an object-oriented programming language with methods for setting and retrieving a person's personal details and calculating their age. so, option a is the correct answer.

Step-by-step explanation:

Create a HealthRecord Class

To design a HealthRecord class for keeping records of a person's health profile, you will need to incorporate several key attributes and create a well-structured program. Below is a conception of how this class could be structured in an object-oriented programming language.

Here's an example of what the class might look like:

class HealthRecord:
def __init__(self, first_name, last_name, gender):
self.first_name = first_name
self.last_name = last_name
self.gender = gender
self.birth_month = None
self.birth_day = None
self.birth_year = None
self.height_meters = None
self.weight_kilograms = None

# Set and get methods for each attribute
def set_birth_date(self, month, day, year):
self.birth_month = month
self.birth_day = day
self.birth_year = year

def get_age(self):
current_year = datetime.datetime.now().year
return current_year - self.birth_year

In this example, the constructor initializes the first name, last name, and gender, with the date of birth, height, and weight set to None initially. These values can be set later using set methods for each respective attribute. The get_age method calculates the person's age by subtracting their year of birth from the current year.

Remember to also include error checking and validation within your set methods to ensure that the data being inputted is valid and meets any necessary requirements or constraints.

User Egli
by
8.2k points