1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
melisa1 [442]
3 years ago
13

In this exercise, you’ll design a "starter" HealthProfile class for a person. The class attributes should include the person’s fir

st 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 setters and getters.The class should include methods that calculate and return the user’s age in years, maximum heart rate and target heart rate range, and body mass index (BMI). 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—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.
Computers and Technology
1 answer:
Marina86 [1]3 years ago
8 0

Answer:

package healthcare;

import java.util.Calendar;

public class HealthProfile {

  private String firstName;

  private String lastName;

  private char gender;

  private int day;

  private int month;

  private int year;

  private double height;

  private double weight;

  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;

  }

  public int calculateAge() {

       

      Calendar dateOfBirth = Calendar.getInstance();

      dateOfBirth.set(year, month, day);

      Calendar now = Calendar.getInstance();

      return now.get(Calendar.YEAR) - dateOfBirth.get(Calendar.YEAR);

  }

  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 + "]";

  }

}

package healthcare;

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();

     

      HealthProfile obj=new HealthProfile(firstName, lastName, gender, day, month, year, height, weight);

      int age=obj.calculateAge();

      System.out.println("Patient age is   "+age + " Years");

     

      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());

  }

}

Explanation:

  • Inside the calculate the age in years  method, create Date of Birth of Object.
  • Create Current Date .
  • Inside the method maximumHeartRate , create a New Object of HealthProfile class and Call its constructor .
You might be interested in
What is the difference between HTML and CSS? * 1. CSS is a markup language unlike HTML. 2. HTML is a backend technology and CSS
GarryVolchara [31]
The anserw is the third one. 
5 0
3 years ago
Read 2 more answers
What is an embedded system. Give examples
IRINA_888 [86]

Answer:

An embedded system is a part of a larger system which has either one or a limited number of dedicated functions.

It doesn't require much power to run and is cheap to make and design.

Explanation:

Examples include: cars, microwaves, traffic lights, washing machines, phones etc

6 0
3 years ago
What does the /var directory contain?
Ghella [55]

Answer:A

Explanation:

The /var Directory. /var is a standard subdirectory of the root directory in Linux and other Unix-like operating systems that contains files to which the system writes data during the course of its operation

3 0
4 years ago
What cell address indicates the intersection of the first row and the first column in a worksheet?
Roman55 [17]
The answer is A1. 

The columns are arranged alphabetically, and the rows are ordered numerically. The cell address states the column, a letter, followed by the row, a number. The first cell address, the top-left cell of the sheet, is A1
7 0
3 years ago
Read 2 more answers
How can you insert an image file in your word document?​
Margarita [4]

Click the insert tab, it'll show a pop up window. Go to the location of where your picture may be. Double click on the photo, and it will be inserted into the word document.

6 0
3 years ago
Other questions:
  • When law enforcement becomes involved, the need may arise to freeze systems as part of the evidence. There is also the likelihoo
    5·1 answer
  • The protocol that enables computers on the Internet to communicate with one another is called _____.
    10·2 answers
  • The purpose of a lockout tagout checklist is to​
    9·2 answers
  • To increase the view of a document on the screen, use the _____. View icon Zoom slider full-screen reading boldface font
    9·1 answer
  • Which of the following illustrates an example of a Boolean data type?
    15·1 answer
  • What internal hardware device does a computer use to connect to a wired or a wireless network?
    10·1 answer
  • Hardware consists of the physical devices associated with a computer system, where software is the set of instructions the hardw
    13·1 answer
  • How can you tell that a spreadsheet was saved as a 2007 Excel file?
    7·1 answer
  • . Select the advantages of RAID-5 relative to other RAID schemes. (MAY SELECT MULTIPLE)
    7·1 answer
  • Write two statements that each use malloc to allocate an int location for each pointer. Sample output for given program:
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!