Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class BMICalculator {
- public static void main(String[] args) {
- Scanner console = new Scanner(System.in);
- double bmi1 = getBMI(console);
- String status1 = getStatus(bmi1);
- reportResults(1, bmi1, status1);
- }
- public static double getBMI(Scanner console) {
- System.out.println("Enter next person's information:");
- System.out.print("Height in inches: ");
- double height = console.nextDouble();
- System.out.print("Weight in pounds: ");
- double weight = console.nextDouble();
- System.out.println();
- return bmiFor(weight, height);
- }
- public static double bmiFor(double weight, double height) {
- return weight / Math.pow(height, 2) * 703;
- }
- public static String getStatus(double bmi) {
- if (bmi < 18.5) {
- return "Underweight";
- } else if (bmi > 18.5 && bmi < 25) {
- return "Normal";
- } else if (bmi > 25 && bmi < 30) {
- return "Overweight";
- } else {
- return "Obese";
- }
- }
- // Prints bmi and bmi status for a person.
- public static void reportResults(int person, double bmi, String status) {
- System.out.println("Person " + person + " BMI = " + Math.round(bmi));
- System.out.println(status);
- }
- }
Add Comment
Please, Sign In to add comment