Valeri173

Danov Homewok Ex1

Nov 12th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class BMICalculator {
  4.     public static void main(String[] args) {
  5.         Scanner console = new Scanner(System.in);
  6.         double bmi1 = getBMI(console);
  7.         String status1 = getStatus(bmi1);
  8.         reportResults(1, bmi1, status1);
  9.     }
  10.  
  11.     public static double getBMI(Scanner console) {
  12.         System.out.println("Enter next person's information:");
  13.         System.out.print("Height in inches: ");
  14.         double height = console.nextDouble();
  15.  
  16.         System.out.print("Weight in pounds: ");
  17.         double weight = console.nextDouble();
  18.         System.out.println();
  19.  
  20.         return bmiFor(weight, height);
  21.     }
  22.  
  23.     public static double bmiFor(double weight, double height) {
  24.         return weight / Math.pow(height, 2) * 703;
  25.     }
  26.  
  27.     public static String getStatus(double bmi) {
  28.         if (bmi < 18.5) {
  29.             return "Underweight";
  30.         } else if (bmi > 18.5 && bmi < 25) {
  31.             return "Normal";
  32.         } else if (bmi > 25 && bmi < 30) {
  33.             return "Overweight";
  34.         } else {
  35.             return "Obese";
  36.         }
  37.     }
  38.  
  39.     // Prints bmi and bmi status for a person.
  40.     public static void reportResults(int person, double bmi, String status) {
  41.         System.out.println("Person " + person + " BMI = " + Math.round(bmi));
  42.         System.out.println(status);
  43.     }
  44. }
Add Comment
Please, Sign In to add comment