Commit c8e6bf0
Changed files (1)
src
Q7
src/Q7/Person.java
@@ -14,9 +14,15 @@ public class Person {
private double bmi;
private double height;
private double weight;
- private String category;
private String name;
+ /**
+ * Create an instance of a person and calculates their BMI.
+ *
+ * @param name the name of the person
+ * @param weight the weight of the person
+ * @param height the height of the person
+ */
public Person(String name, double weight, double height) {
this.name = name;
this.weight = weight;
@@ -24,10 +30,21 @@ public class Person {
this.updateBMI();
}
+ /**
+ * Returns the category the person is categorized as based on BMI.
+ *
+ * @return A category of "Underweight", "Normal", "Overweight" or "Obese"
+ */
public String getCategory() {
return this.getCategory(this.bmi);
}
+ /**
+ * Returns the category for the BMI.
+ *
+ * @param bmi the BMI to determine a category for.
+ * @return A category of "Underweight", "Normal", "Overweight" or "Obese"
+ */
public String getCategory(double bmi) {
if (bmi < 18.5) return "Underweight";
else if (bmi < 25.0) return "Normal";
@@ -35,41 +52,80 @@ public class Person {
return "Obese";
}
+ /**
+ * Returns the persons name
+ *
+ * @return the persons name
+ */
public String getName() {
return this.name;
}
+ /**
+ * Returns the persons BMI
+ *
+ * @return the persons BMI
+ */
public double getBMI() {
return this.bmi;
}
+ /**
+ * Returns the persons height
+ *
+ * @return the persons height
+ */
public double getHeight() {
return this.height;
}
+ /**
+ * Returns the persons weight
+ *
+ * @return the persons weight
+ */
public double getWeight() {
return this.weight;
}
- public void setBMI(double bmi) {
+ /**
+ * Change the BMI
+ *
+ * @param bmi the new BMI
+ */
+ private void setBMI(double bmi) {
this.bmi = bmi;
}
+ /**
+ * Change the Height
+ *
+ * @param height the new height
+ */
public void setHeight(double height) {
this.height = height;
this.updateBMI();
}
+ /**
+ * Change the name
+ *
+ * @param name the new name
+ */
public void setName(String name) {
this.name = name;
}
+ /**
+ * Change the weight
+ *
+ * @param weight the new weight
+ */
public void setWeight(double weight) {
this.weight = weight;
this.updateBMI();
}
- // BMI = (weight (lb) * 703) / ((height (in))^2)
private void updateBMI() {
this.setBMI((this.weight * 703) / Math.pow(height, 2));
}