Advertisement
Spocoman

Calorie Calculator

Sep 2nd, 2024
309
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 1 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String gender = scanner.nextLine();
  7.         double weight = Double.parseDouble(scanner.nextLine()),
  8.                 height = Double.parseDouble(scanner.nextLine()),
  9.                 basalMetabolicRate, coefficientActivity;
  10.         int age = Integer.parseInt(scanner.nextLine());
  11.         String physicalActivity = scanner.nextLine();
  12.  
  13.         if (gender.equals("m")) {
  14.             basalMetabolicRate = 66 + weight * 13.7 + height * 500 - 6.8 * age;
  15.         } else {
  16.             basalMetabolicRate = 655 + weight * 9.6 + height * 180 - 4.7 * age;
  17.         }
  18.  
  19.         coefficientActivity = switch (physicalActivity) {
  20.             case "sedentary" -> 1.2;
  21.             case "lightly active" -> 1.375;
  22.             case "moderately active" -> 1.55;
  23.             default -> 1.725;
  24.         };
  25.  
  26.         int calories = (int) Math.ceil(basalMetabolicRate * coefficientActivity);
  27.         System.out.printf("To maintain your current weight you will need %d calories per day.\n", calories);
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement