Computerizing health records could make it easier for patients to share their he
ID: 3877975 • Letter: C
Question
Computerizing health records could make it easier for patients to share their health profiles and histories among their various health-care professionals. This could improve the quality of health care, help avoid drug conflicts and erroneous drug prescription, reduce costs, and in case of emergencies, could save lives.
Write a Java Program in which you design HealthProfile class for a person. The class attributes should include 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 inches), and weight (in pounds). Your class should have a constructor that receives this data. For each attribute, provide set and get methods. The class should also include methods that calculate and return the user’s age in years, maximum heart rate, and target-heart-rate range, and Boby Mass Index (BMI).
The formula to calculate maximum heart rate (beats per minute) = 220 – age (in years)
The target-heart-rate is a range that is 50-85% of the maximum heart range (American Health Association)
The formula to calculate BMI = (weightInPounds * 703)/(heightInInches * heightInInches)
You’ll need to write a java application that prompts for the person’s information, instantiates an object of class HealthProfile for that person and prints the information from that object (first name, last name, gender, date of birth, height and weight) then calculates and prints the person’s age in years, BMI, maximum heart rate and target-heart-rate range. It should also display the BMI values using chart shown below:
Underweight: BMI < 18.5
Normal: 18.5<BMI<24.9
Overweight: 25<BMI<29.9
Obese: BMI>= 30
Explanation / Answer
HealthProfile .java
import java.util.Calendar;
public class HealthProfile {
private String firstName;
private String lastName;
private char gender; // It can be M or F (For Male or Female)
private int day;
private int month;
private int year;
private double height; //in inches
private double weight; //in pounds
// Constructor
public HealthProfile(String firstName, String lastName, char gender, int day, int month, int year, double height,
double weight) {
super();
this.firstName = firstName;
this.lastName = lastName;
this.gender = gender;
this.day = day;
this.month = month;
this.year = year;
this.height = height;
this.weight = weight;
}
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 char getGender() {
return gender;
}
public void setGender(char gender) {
this.gender = gender;
}
public int getDay() {
return day;
}
public void setDay(int day) {
this.day = day;
}
public int getMonth() {
return month;
}
public void setMonth(int month) {
this.month = month;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
public double getWeight() {
return weight;
}
public void setWeight(double weight) {
this.weight = weight;
}
// This method will calculate the age in years
public int calculateAge() {
// Creating Date of Birth of Object
Calendar dateOfBirth = Calendar.getInstance();
dateOfBirth.set(year, month, day);
// Creating Current Date
Calendar now = Calendar.getInstance();
return now.get(Calendar.YEAR) - dateOfBirth.get(Calendar.YEAR);
}
// This method will calculate maximumHeartRate
public int maximumHeartRate() {
return 220 - calculateAge();
}
public double[] targetHeartRateRange() {
double[] range = new double[2];
// Calculate Stating range(50 % of maximumHeartRate)
range[0] = 0.5 * maximumHeartRate();
// Calculate End range(85 % of maximumHeartRate)
range[1] = 0.85 * maximumHeartRate();
return range;
}
public double calculateBMI() {
return (weight * 703)/(height * height);
}
public String getBMIValue()
{
double bmi=calculateBMI();
if(bmi < 18.5)
{
return "Underweight";
}
else if (bmi>18.5 && bmi<24.9)
{
return "Normal";
}
else if (bmi>25 && bmi<29.9)
{
return "Normal";
}
else if (bmi>=30)
{
return "Obese";
}
return "DafultValue"; //you can give any default value of your choice here if no condition meets the given criteria
}
@Override
public String toString() {
return "HealthProfile [firstName=" + firstName + ", lastName=" + lastName + ", gender=" + gender + ", Date Of Birth="
+ day + "-" + month + "-" + year + ", height=" + height + ", weight=" + weight + "]";
}
}
TestHealthCare.java
import java.util.Scanner;
public class TestHealthCare {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.println("Please enter following details of the Patient");
System.out.println("First Name");
String firstName=sc.nextLine();
System.out.println("Last Name");
String lastName=sc.nextLine();
System.out.println("Gender ...... M or F ?");
char gender=sc.next().charAt(0);
System.out.println("Date of Birth");
System.out.println("Day");
int day=sc.nextInt();
System.out.println("Month");
int month=sc.nextInt();
System.out.println("Year");
int year=sc.nextInt();
System.out.println("Height in inches");
double height =sc.nextDouble();
System.out.println("weight (in pounds)");
double weight =sc.nextDouble();
//Create a New Object of HealthProfile class
//Calling constructor
HealthProfile obj=new HealthProfile(firstName, lastName, gender, day, month, year, height, weight);
//Call calculateAge
int age=obj.calculateAge();
System.out.println("Patient age is "+age + " Years");
//Call maximumHeartRate
int maxHeartRate=obj.maximumHeartRate();
System.out.println("Patient Maximum Heart Rate is "+maxHeartRate + " beats per minute");
//Call targetHeartRateRange
double targetHeartRateRange []=obj.targetHeartRateRange();
System.out.println("Target Heart Range is "+targetHeartRateRange [0] + " - " +targetHeartRateRange [1]);
//Call calculateBMI
double bmi=obj.calculateBMI();
System.out.println("Patient BMI is "+bmi);
//call getBMIValue
System.out.println("Patient BMI Value is "+obj.getBMIValue());
}
}
Output:
Please enter following details of the Patient
First Name
Sarfaraz
Last Name
Pasha
Gender ...... M or F ?
M
Date of Birth
Day
01
Month
01
Year
1990
Height in inches
165
weight (in pounds)
150
Patient age is 28 Years
Patient Maximum Heart Rate is 192 beats per minute
Target Heart Range is 96.0 - 163.2
Patient BMI is 3.8732782369146004
Patient BMI Value is Underweight
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.