Create a java program using the following instructions:

GymsRUs has a need to provide fitness/health information to their clients including BMI, BMI category and maximum heart rate. Your task is to write a console program to do this. Body Mass Index (BMI) is a measure of body fat based on a person’s height and weight. BMI can be used to indicate if you are overweight, obese, underweight, or normal. The formula to calculate BMI is BMI = weight(lb) x 703 / (height(inches))^2.

The following BMI categories are based on this calculation:

Category BMI Range

Underweight less than 18.5

Normal 18.5 to less than 25

Overweight 25 to less than 30

Obese 30 or more

Max heart rate is calculated as 220 minus a person’s age.

FUNCTIONAL REQUIREMENTS: This problem will have TWO classes. Design and code a class called HealthProfile (your "cookie cutter") to store information about clients and their fitness data. The following attributes are private instance variables:

 Name

 Age

 Weight

 Height (total inches)

The class must include the following public methods:

method description

setName Recieves a value to assign to private instance variable

setAge Recieves a value to assign to private instance variable

setWeight Recieves a value to assign to private instance variable

setHeight Receives TWO inputs (height in feet, inches). Converts and stores the TOTAL INCHES in private instance variable

getName Returns private instance variable

getAge Returns private instance variable

getWeight Returns private instance variable

getHeight Returns private instance variable (inches)

getBMI Calculates and returns BMI

getCategory Calculates and returns category based on BMI

getMaxHR Calculates and returns maximum heart rate

Create a SEPARATE TEST CLASS, HealthProfileTest, to prompt for user input and display output using the HealthProfile class. Process multiple inputs using a loop. You can assume all user input is valid.

SAMPLE OUTPUT:

Enter name or X to quit: John Smith

Your age: 35

Your weight: 200

Your height (feet): 6

Your height (inches): 0

Health Profile for John Smith

BMI: 27.1

BMI Category: overweight

Max heart rate: 185

Enter name or X to quit: Ann Jones

Your age: 50

Your weight: 120

Your height (feet): 5

Your height (inches): 2

Health Profile for Ann Jones

BMI: 21.9

BMI Category: normal

Max heart rate: 170

Enter name or X to quit: X

Goodbye!

Respuesta :

Answer:

import java.util.Scanner;

public class HealthProfile  

{

private String name;

private int age;

private double weight;

private double height;

private double bmi;

private String category;

 

 

public void setName(String name)

{

 this.name = name;

}

public String getName()

{

 return name;

}

public void setAge(int age)

{

 this.age = age;

}

public int getAge()

{

 return age;

}

public void setWeight(double weight)

{

 this.weight = weight;

}

public double getWeight()

{

 return weight;

}

public void setHeight(double height)

{

 this.height = height;

}

public double getHeight()

{

 return height;

}

public void setBmi(double bmi)

{

 this.bmi = bmi;

}

public double getBmi()

{

 bmi = (weight * 703) / (height * height);

 return bmi;

}

public void setCategory(String category)

{

 this.category = category;

}

public String getCategory()

{

 if (bmi < 18.5){

  category = "underweight";

 } else if (bmi < 25){

  category = "normal";

 } else if (bmi < 30){

  category ="overweight";

 }else{

  category = "obese";

 }

 

 return category;

}

 

 

public static void main(String[] args)

{

Scanner input = new Scanner(System.in);

 

HealthProfile myHealthProfile = new HealthProfile();

System.out.println("This program reads in your data and calculates your Body Mass Index (BMI)");

System.out.println("Please enter your name: ");

String theName = input.nextLine();

myHealthProfile.setName(theName);

System.out.println("Please enter your age: ");

int theAge = input.nextInt();

myHealthProfile.setAge(theAge);

System.out.println("Please enter your weight in pounds: ");

double theWeight = input.nextDouble();

myHealthProfile.setWeight(theWeight);

System.out.println("Please enter your height in inches: ");

double theHeight = input.nextDouble();

myHealthProfile.setHeight(theHeight);

System.out.println();

System.out.println(theName);

System.out.printf("Your age is %s\n", myHealthProfile.getAge());

System.out.printf("Your weight is %s\n", myHealthProfile.getWeight(), "LBS");

System.out.printf("Your height is %s\n", myHealthProfile.getHeight());

System.out.printf("Your Body Mass Index (BMI) is %.2f\n", myHealthProfile.getBmi());

System.out.printf("You are %s\n", myHealthProfile.getCategory());

 

 

 

System.out.println();

System.out.printf("Name in object myHealthProfile is: %n%s%n", myHealthProfile.getName());

}

}  

In this exercise we want to use computer and Java knowledge to write the code correctly, so it is necessary to add the following to the informed code:

The image attached below shows the corresponding code for the question.

Thus, writing the code to make it easier to copy in the future, we find that:

import java.util.Scanner;

    public class HealthProfile  {

    private String name;

    private int age;

    private double weight;

    private double height;

    private double bmi;

    private String category;

          public void setName(String name){

           this.name = name;

}

public String getName() {

return name;

}

public void setAge(int age)

{

this.age = age;

}

public int getAge()

{

return age;

}

public void setWeight(double weight)

{

this.weight = weight;

}

public double getWeight()

{

return weight;

}

public void setHeight(double height)

{

this.height = height;

}

public double getHeight()

{

return height;

}

public void setBmi(double bmi)

{

this.bmi = bmi;

}

public double getBmi()

{

bmi = (weight * 703) / (height * height);

return bmi;

}

public void setCategory(String category)

{

this.category = category;

}

public String getCategory()

{

if (bmi < 18.5){

 category = "underweight";

} else if (bmi < 25){

 category = "normal";

} else if (bmi < 30){

 category ="overweight";

}else{

 category = "obese";

}

return category;

}

public static void main(String[] args)

{

Scanner input = new Scanner(System.in);

HealthProfile myHealthProfile = new HealthProfile();

System.out.println("This program reads in your data and calculates your Body Mass Index (BMI)");

System.out.println("Please enter your name: ");

String theName = input.nextLine();

myHealthProfile.setName(theName);

System.out.println("Please enter your age: ");

int theAge = input.nextInt();

myHealthProfile.setAge(theAge);

System.out.println("Please enter your weight in pounds: ");

double theWeight = input.nextDouble();

myHealthProfile.setWeight(theWeight);

System.out.println("Please enter your height in inches: ");

double theHeight = input.nextDouble();

myHealthProfile.setHeight(theHeight);

System.out.println();

System.out.println(theName);

System.out.printf("Your age is %s\n", myHealthProfile.getAge());

System.out.printf("Your weight is %s\n", myHealthProfile.getWeight(), "LBS");

System.out.printf("Your height is %s\n", myHealthProfile.getHeight());

System.out.printf("Your Body Mass Index (BMI) is %.2f\n", yHealthProfile.getBmi());

System.out.printf("You are %s\n", myHealthProfile.getCategory());

System.out.println();

System.out.printf("Name in object myHealthProfile is: %n%s%n", myHealthProfile.getName());

}

}

See more about computer at brainly.com/question/950632

Ver imagen lhmarianateixeira
Ver imagen lhmarianateixeira
ACCESS MORE