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

