Computerizing health records could make it easier for patients to share their he
ID: 3880028 • 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 NetBeans 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
/**
* The java program that prompts user to enter
* firat name, last name, gender , date of birth
* height and weight . The calculates the age,bmi,
* max heart rate and target heart rate and print
* resutls to console.
* */
//Tester.java
import java.util.Scanner;
public class Tester
{
public static void main(String[] args)
{
//create an instance of Scanner class
Scanner scan=new Scanner(System.in);
//read data from user
System.out.println("First Name :");
String fName=scan.nextLine();
System.out.println("Last Name :");
String lName=scan.nextLine();
System.out.println("Gender [M or F]");
String gender=scan.nextLine();
System.out.println("DOB");
System.out.print("Enter month :");
int month=Integer.parseInt(scan.nextLine());
System.out.print("Enter day :");
int day=Integer.parseInt(scan.nextLine());
System.out.print("Enter year :");
int year=Integer.parseInt(scan.nextLine());
System.out.println("Height[inches] :");
double height=Double.parseDouble(scan.nextLine());
System.out.println("Weight[pounds] :");
double weight=Double.parseDouble(scan.nextLine());
//create an instace of HealthProfile
HealthProfile hp=new HealthProfile(fName,lName,gender,
month,day,year,height,weight);
//call toString on healthprofile
System.out.println(hp.toString());
}
}//end of class
------------------------------------------------------------------------
//HealthProfile.java
import java.util.Calendar;
public class HealthProfile
{
//declare instance variables of class
private String fName;
private String lName;
private String gender;
private int month;
private int day;
private int year;
private double height;
private double weight;
//constructor of class
public HealthProfile(String fName, String lName, String gender, int month,
int day, int year, double height, double weight) {
setFname(fName);
setLname(lName);
setGender(gender);
setMonth(month);
setDay(day);
setYear(year);
setHeight(height);
setWeight(weight);
}
public String getLname()
{
return lName;
}
public String getGender() {
return fName;
}
public int getMonth()
{
return month;
}
public int getDay()
{
return day;
}
public int getYear()
{
return year;
}
public double getHeight()
{
return height;
}
public double getWeight()
{
return weight;
}
//calculate age
public int getage()
{
int curYear = Calendar.getInstance().get(Calendar.YEAR);
int age=curYear-year;
return age;
}
//calculate max heart rate
public int getMaxHeartRate()
{
return 220-getage();
}
//get target heart rate
public String getTargetHeartRate()
{
return String.format("Range :Min: %f Max: %f",
getMaxHeartRate()*0.5,
getMaxHeartRate()*0.85);
}
//Returns the bmi value
public String getBMI()
{
double bmi= (weight * 703)/(height* height);
String result="";
if(bmi<18.5)
result="Underweight";
else if(bmi>18.5 && bmi<24.9)
result="Normal";
else if(bmi>25 && bmi<29.9)
result="Overweight";
else
result="Obese";
return result;
}
public void setFname(String fName)
{
this.fName=fName;
}
public void setLname(String lName)
{
this.lName=lName;
}
public void setGender(String gender)
{
this.gender=gender;
}
public void setMonth(int month)
{
this.month=month;
}
public void setDay(int day)
{
this.day=day;
}
public void setYear(int year)
{
this.year=year;
}
public void setHeight(double height)
{
this.height=height;
}
public void setWeight(double weight)
{
this.weight=weight;
}
//toString method
public String toString()
{
return String.format("Age : %d BMI: %s MaxHeartRate : %d Target Heart Rate: %s",
getage(),
getBMI(),
getMaxHeartRate(),
getTargetHeartRate());
}
}//end of the class
------------------------------------------------------------------------
Sample Output:
First Name :
Tim
Last Name :
John
Gender [M or F]
M
DOB
Enter month :1
Enter day :1
Enter year :1990
Height[inches] :
67
Weight[pounds] :
85
Age : 28
BMI: Underweight
MaxHeartRate : 192
Target Heart Rate: Range :Min: 96.000000 Max: 163.200000
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.