Advertisement
Dimitar182

Danov1

Oct 26th, 2021
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. package danov_hw;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Oop {
  6. static String status;
  7.  
  8. public static void main(String[] args) {
  9. Scanner scan = new Scanner(System.in);
  10. printIntroduction();
  11. getBMI(scan);
  12. }
  13.  
  14. public static void printIntroduction() {
  15. System.out.println(
  16. "Hello!\nTo calculate your BMI, you'll have to input your:\nHeight in centimeters\nWeight in kilograms\nHealth status\n");
  17. }
  18.  
  19. public static double getBMI(Scanner scan) {
  20. System.out.print("Your weight is:");
  21. double weight = scan.nextDouble();
  22. System.out.print("Your height is:");
  23. double height = scan.nextDouble();
  24. double weightInPounds = weight * 2.2046;
  25. double heightInInches = height * 0.3937;
  26. return bmiFor(weightInPounds, heightInInches);
  27. }
  28.  
  29. public static double bmiFor(double a, double b) {
  30. double bmi = a * 703 / (b * b);
  31. //System.out.printf("Your body mass index is : %.2f", bmi);
  32. getStatus(bmi);
  33. return bmi;
  34. }
  35.  
  36. public static String getStatus(double bmi) {
  37. reportResults(bmi, Oop.status);
  38. if(bmi <= 18.5) {
  39. Oop.status = "underweight";
  40. } else if(bmi <= 25) {
  41. Oop.status = "normal";
  42. } else if(bmi <= 30) {
  43. Oop.status = "overweight";
  44. } else if(bmi > 30) {
  45. Oop.status = "obese";
  46. }
  47. return Oop.status;
  48. }
  49.  
  50. public static void reportResults(double bmi, String status) {
  51. System.out.printf("Your body mass index is : %.2f", bmi);
  52. System.out.print("\nAnd your health state is : " + status);
  53. }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement