(Computerization of Health Records) A health-care issue that has been in the news lately is the computerization of health records. This possibility is being approached cautiously because of sensitive privacy and security concerns, among others. [We address such concerns in later exercises.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 prescriptions, reduce costs and, in emergencies, could save lives. In this exercise, you’ll design a “starter” 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 also should include methods that calculate and return the user’s age in years, maximum heart rate and target-heart-rate range (see Exercise 3.16), and body mass index (BMI; see Exercise 2.33). Write a Java app that prompts for the person’s information, instantiates an object of class HealthProfile for that person and prints the information from that object—including the person’s 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 chart from Exercise 2.33.
Computerization of Health Records Program in java
/*
* Filename: HealthProfile.java
*
* Description: Exercise 3.17 - Computerization of Health Records
*
* @Author: Bilal Tahir Khan Meo
* Website: https://codeblah.com
*
* =====================================================================================
*/
public class HealthProfile{
private String fName, lName, gender;
private int[] dob = new int[3];
private int measurementSystem; // 1 - imperial, 2 - metric
private double height, weight; // inches and pounds
public HealthProfile(String fName, String lName, String gender,
int[] dob, double height, double weight, int measurementSystem){
setFirstName(fName);
setLastName(lName);
setGender(gender);
setDOB(dob);
setHeight(height);
setWeight(weight);
setMeasurementSystem(measurementSystem);
}
// SETTERS
public void setFirstName(String fName){
this.fName = fName;
}
public void setLastName(String lName){
this.lName = lName;
}
public void setGender(String gender){
this.gender = gender;
}
public void setDOB(int[] dob){
this.dob = dob;
}
public void setHeight(double height){
this.height = height;
}
public void setWeight(double weight){
this.weight = weight;
}
public void setMeasurementSystem(int measurementSystem){
this.measurementSystem = measurementSystem;
}
// GETTERS
public String getFirstName(){
return fName;
}
public String getLastName(){
return lName;
}
public String getGender(){
return gender;
}
public int[] getDOB(){
return dob;
}
public double getHeight(){
return height;
}
public double getWeight(){
return weight;
}
public int getAge(){
return java.util.Calendar.getInstance().get(java.util.Calendar.YEAR) - dob[2];
}
// BMI - determine system of measurement
public double getBMI(){
return (measurementSystem == 1) ? calculateImperial() : calculateMetric();
}
// calculate using imperial measures
private double calculateImperial(){
return ((weight * 700) / (height * height));
}
// calculate using metric measures
private double calculateMetric(){
return weight / (height * height);
}
public int getMaxHeartRate(){
// max heartrate in bpm = 220 - age in years.
return 220 - getAge();
}
public String getTargetHeartRate(){
return String.format("%.0f - %.0f",
getMaxHeartRate() * 0.5, getMaxHeartRate() * 0.85);
}
// print health information
public void showHealthProfile(){
System.out.println("\n********** YOUR HEALTH PROFILE **********");
System.out.printf("Name:\t%s %s\n", fName, lName);
System.out.printf("DOB:\t%d/%d/%d\nAge:\t%d\n", dob[0], dob[1], dob[2], getAge());
System.out.printf("Height:\t%.2f inches\nWeight: %.2f pounds\n", height, weight);
System.out.printf("\n***** HEARTRATE *****\n");
System.out.printf("Max:\t%d\nTarget:\t%s\n", getMaxHeartRate(), getTargetHeartRate());
System.out.printf("\n***** BMI *****\n");
System.out.printf("Your BMI: %.1f\n\n", getBMI());
printBmiTable();
}
// print BMI information from Department of Health and Human Services /
// National Institutes of Health.
private void printBmiTable(){
System.out.println("BMI VALUES:");
System.out.println("Underweight: less than 18.5");
System.out.println("Normal: between 18.5 and 24.9");
System.out.println("Overweight: between 25 and 29.9");
System.out.println("Obese: 30 or greater");
}
}
HealthProfileTest.java
/*
* Filename: HealthProfileTest.java
*
* Description: Exercise 3.17 - Computerization of Health Records
*
* @Author: Bilal Tahir Khan Meo
* Website: https://codeblah.com
*
* =====================================================================================
*/
import java.util.Scanner;
public class HealthProfileTest{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.print("Enter your first name: ");
String fName = sc.nextLine();
System.out.print("Enter you last name: ");
String lName = sc.nextLine();
System.out.print("Enter your gender (male/female): ");
String gender = sc.nextLine();
System.out.print("Enter Date of birth dd mm yyyy: ");
int[] dob = new int[3];
for(int i=0; i<3; i++){
dob[i] = sc.nextInt();
}
System.out.print("1 for imperial, 2 for metric: ");
int choice = sc.nextInt();
System.out.printf("Input weight in %s: ",
(choice == 1) ? "pounds" : "kilograms");
double weight = sc.nextDouble();
System.out.printf("Input height in %s: ",
(choice == 1) ? "inches(ft * 12 * in)" : "metres");
double height = sc.nextDouble();
HealthProfile profile = new HealthProfile(fName, lName, gender, dob, height, weight, choice);
profile.showHealthProfile();
}
}