Problem

Is the BMI class defined in Listing 1 immutable?LISTING 1 BMI.java1 public class BMI {2 pr...

Is the BMI class defined in Listing 1 immutable?

LISTING 1 BMI.java

1 public class BMI {

2 private String name;

3 private int age;

4 private double weight; // in pounds

5 private double height; // in inches

6 public static final double KILOGRAMS_PER_POUND = 0.45359237;

7 public static final double METERS_PER_INCH = 0.0254;

8

9 public BMI(String name, int age, double weight, double height) {

10 this.name = name;

11 this.age = age;

12 this.weight = weight;

13 this.height = height;

14 }

15

16 public BMI(String name, double weight, double height) {

17 this(name, 20, weight, height);

18 }

19

20 public double getBMI() {

21 double bmi = weight * KILOGRAMS_PER_POUND /

22 ((height * METERS_PER_INCH) * (height * METERS_PER_INCH));

23 return Math.round(bmi * 100) / 100.0;

24 }

25

26 public String getStatus() {

27 double bmi = getBMI();

28 if (bmi<18.5)

29 return "Underweight";

30 else if (bmi<25)

31 return "Normal";

32 else if (bmi<30)

33 return "Overweight";

34 else

35 return "Obese";

36 }

37

38 public String getName() {

39 return name;

40 }

41

42 public int getAge() {

43 return age;

44 }

45

46 public double getWeight() {

47 return weight;

48 }

49

50 public double getHeight() {

51 return height;

52 }

53 }

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT