Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class BMICalculator {
- public static void printIntroduction() {
- System.out.println("Hello!This is a program for body mass index calculator.");
- }
- public static double getBMI(Scanner scanner) {
- System.out.println("Input weight: ");
- double weight = scanner.nextInt();
- System.out.println("Input height: ");
- double height = scanner.nextInt();
- return bmiFor(weight, height);
- }
- public static double bmiFor(double W, double H) {
- double bodymassindex = W * 703 / (H * H);
- return bodymassindex;
- }
- public static String getStatus(double bmi) {
- if (bmi < 18.5) {
- return "underweight";
- }else if (bmi < 25){
- return "normal";
- }else if (bmi < 30){
- return "overweight";
- }else{
- return "obese";
- }
- }
- public static void reportResults(int number, int bmi, String status){
- System.out.println("Number "+number+" have BMI = "+bmi+", status: "+status);
- }
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- for(int i=1; true;i++) {
- printIntroduction();
- int bmi = (int) getBMI(scanner);
- String status = getStatus(bmi);
- reportResults(i, bmi, status);
- System.out.println("Continue program Y/N");
- scanner.nextLine();
- if (scanner.nextLine().equals("N")) {
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment