Advertisement
desislava_topuzakova

2.CalorieCalculator

May 13th, 2018
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class CalorieCalculator {
  4.     public static void main(String[] agrs) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         char gender = scanner.nextLine().charAt(0);
  8.         double weight = Double.parseDouble(scanner.nextLine());
  9.         double height = Double.parseDouble(scanner.nextLine());
  10.         int age = Integer.parseInt(scanner.nextLine());
  11.         String activity = scanner.nextLine();
  12.  
  13.         height = height * 100;
  14.         double bnm = 0;
  15.  
  16.         if (gender == 'm') {
  17.             bnm = 66 + (13.7 * weight) + (5 * height) - (6.8 * age);
  18.         } else if (gender == 'f') {
  19.             bnm = 655 + (9.6 * weight) + (1.8 * height) - (4.7 * age);
  20.         }
  21.  
  22.         double calories = 0;
  23.  
  24.         if (activity.equals("sedentary")) {
  25.             calories = bnm * 1.2;
  26.         } else if (activity.equals("lightly active")) {
  27.             calories = bnm * 1.375;
  28.         } else if (activity.equals("moderately active")) {
  29.             calories = bnm * 1.55;
  30.         } else if (activity.equals("very active")) {
  31.             calories = bnm * 1.725;
  32.         }
  33.         calories = Math.ceil(calories);
  34.         System.out.printf("To maintain your current weight you will need %.0f calories per day.", calories);
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement