Boyan5

OOP1

Oct 12th, 2021
795
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.55 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class BMICalculator {
  3.     public static void printIntroduction() {
  4.         System.out.println("Hello!This is a program for body mass index calculator.");
  5.     }
  6.     public static double getBMI(Scanner scanner) {
  7.         System.out.println("Input weight: ");
  8.         double weight = scanner.nextInt();
  9.         System.out.println("Input height: ");
  10.         double height = scanner.nextInt();
  11.         return bmiFor(weight, height);
  12.     }
  13.     public static double bmiFor(double W, double H) {
  14.         double bodymassindex = W * 703 / (H * H);
  15.         return bodymassindex;
  16.     }
  17.     public static String getStatus(double bmi) {
  18.         if (bmi < 18.5) {
  19.             return "underweight";
  20.         }else if (bmi < 25){
  21.             return "normal";
  22.         }else if (bmi < 30){
  23.             return "overweight";
  24.         }else{
  25.             return "obese";
  26.         }
  27.     }
  28.     public static void reportResults(int number, int bmi, String status){
  29.         System.out.println("Number "+number+" have BMI = "+bmi+", status: "+status);
  30.     }
  31.     public static void main(String[] args) {
  32.         Scanner scanner = new Scanner(System.in);
  33.         for(int i=1; true;i++) {
  34.             printIntroduction();
  35.             int bmi = (int) getBMI(scanner);
  36.             String status = getStatus(bmi);
  37.             reportResults(i, bmi, status);
  38.             System.out.println("Continue program Y/N");
  39.             scanner.nextLine();
  40.             if (scanner.nextLine().equals("N")) {
  41.                 break;
  42.             }
  43.         }
  44. }
  45.     }
Advertisement
Add Comment
Please, Sign In to add comment