Question

In: Computer Science

Part 2: BasalMetabolicRate Write a Java program that estimates the number of calories your body needs...

Part 2: BasalMetabolicRate Write a Java program that estimates the number of calories your body needs to maintain your weight if you do no exercise. This is called your BMR (or Basal Metabolic Rate) and can be calculated with the Harris-Benedict equation. The calories needed for a woman to maintain her weight is: BMR (calories) = 655 + (4.35 * weight in pounds) + (4.7 * height in inches) - (4.7 * age in years) The calories needed for a man to maintain his weight is: BMR (calories) = 66 + (6.23 * weight in pounds) + (12.7 * height in inches) - (6.8 * age in years) Write a program that allows the user to input his or her weight in pounds, height in inches, and age in years. Your program should output two things: 1) The number of calories needed to maintain one's weight for both a woman and a man of the same input weight, height and age AND 2) The number of chocolate bars that should be consumed to maintain this amount of calories (a typical chocolate bar contains about 230 calories) Here is a sample transaction with the user: Please enter your weight (lb): 160 Please enter your height (in): 70 Please enter your age: 40 BMR (female):1492 calories BMR (male) : 1680 calories If you are female, you need to consume 6.5 chocolate bars to maintain weight. If you are male, you need to consume 7.3 chocolate bars to maintain weight.

Solutions

Expert Solution

import java.util.Scanner;

public class BMR {

   public static void main(String[] args) {
       Scanner scan = new Scanner(System.in);

       // Take user input
       System.out.print("Please enter your weight (lb): ");
       double weight = Double.parseDouble(scan.nextLine());
       System.out.print("Please enter your height (in): ");
       double height = Double.parseDouble(scan.nextLine());
       System.out.print("Please enter your age: ");
       int age = Integer.parseInt(scan.nextLine());

       double bmr_female, bmr_male = 0;

       // Calculate bmr for both male and female and print it
       bmr_female = 655 + (4.35 * weight) + (4.7 * height) - (4.7 * age);
       bmr_male = 66 + (6.23 * weight) + (12.7 * height) - (6.8 * age);

       System.out.println("\nBMR (female): " + String.format("%.2f", bmr_female) + " calories");
       System.out.println("BMR (male): " + String.format("%.2f", bmr_male) + " calories");

       // Calculate number of choco bars for both male and female and print it
       double choco_bar_female = bmr_female / 230;
       double choco_bar_male = bmr_male / 230;

       System.out.println("If you are female, you need to consume " + String.format("%.1f", choco_bar_female)
               + " chocolate bars to maintain weight.");
       System.out.println("If you are male, you need to consume " + String.format("%.1f", choco_bar_male)
               + " chocolate bars to maintain weight.");
   }
}

OUTPUT


Related Solutions

Using a Java. 2. Write a Java program calculate_fare.java to take the input for number of...
Using a Java. 2. Write a Java program calculate_fare.java to take the input for number of miles, and the class of journey (1,2, or 3, for first, second, and third class respectively), for a train journey. The program should then calculate and display the fare of journey based on the following criteria: Note: Use Switch...case and if...else construct First (1) Class Second (1) Class Third (3) Class First 100 mile $ 3 per mile $ 2 per mile $ 1.50...
Write a java program to convert a positive integer value to a roman number. Your program...
Write a java program to convert a positive integer value to a roman number. Your program should print a description, prompt them for how many numbers they need to convert and then loop that many times. Each time the program needs to prompt for a number and output the equivalent roman numeral. If the user enters a number less than 1 then output an error message. See sample output below: **************************************************** * Welcome to the Roman Numeral Converter!          * *...
Needs to be in JAVA. Write a Java program that accepts the total amount of cars...
Needs to be in JAVA. Write a Java program that accepts the total amount of cars sold and total sales amount of a car salesperson for a given month. The salesperson’s paycheck is computed as follows: a. Every sales person gets 10% (commission) of total sales b. Sales totals greater than $50,000 get 5% of total sales amount c. 8 or more cars sold earns the salesperson an extra 3% Please remove 30% (taxes) of the gross pay and list...
Create JAVA PROGRAM, and write comment for codes also. 2) Every extra 3500 calories means gaining...
Create JAVA PROGRAM, and write comment for codes also. 2) Every extra 3500 calories means gaining a pound. Falling short by 3500 means losing a pound. Get the base amount of calories the person needs in a day (BMR). Then have the user enter in calorie totals for each day and display their weight every week. They might eat more than once in a day.
Write a JAVA program to display your complete names, your matric number and your course of...
Write a JAVA program to display your complete names, your matric number and your course of study, using the two access modifiers stated in (a) and (b) (a) Use static access modifier for the method declaration of the program class, also use class name Eee532MakeUp. Use any method name of your choice. (b) Use public access modifier for the method declaration of the program class, also use class name EceCourseJava. (2) Which of the programs in (a) or (b) is...
Part 2 Write a C++ program that prompts the user for an Account Number(a whole number)....
Part 2 Write a C++ program that prompts the user for an Account Number(a whole number). It will then prompt the user for the initial account balance (a double). The user will then enter either w, d, or z to indicate the desire to withdraw an amount from the bank, deposit an amount or end the transactions for that account((accept either uppercase or lowercase). You must use a switch construct to determine the account transaction and a do…while loop to...
2. Answer the following question (a) Write a Java program to find the number of integers...
2. Answer the following question (a) Write a Java program to find the number of integers within the range of two specified numbers and that are divisible by another number. For example, x = 5, y=20 and p =3, find the number of integers within the range [x, y] and that are divisible by p. (b) Write explicitly on the following OOP concepts: i. Encapsulation ii. Inheritance iii. Polymorphism (c) Develop a Java application that computes the two roots of...
Write a JAVA program that allow a user to enter 2 number, starting point and end...
Write a JAVA program that allow a user to enter 2 number, starting point and end point. For example a user me enter 1 and 100. Your program will Add numbers from 1 to 100, add all the even number, and add all the odd numbers Output: The sum of number 1 to 100 is: The sum of even number 1 to 100 is: The sum of odd number 1 to 100 is:
Write a program IN JAVA that asks the user for a number. The program should check...
Write a program IN JAVA that asks the user for a number. The program should check the number to ensure that it is valid (if not, the user should enter a valid number to continue.) The program should print out all of the prime numbers from 2 up to the number, with up to 10 numbers per line. (Recall: A prime number is a number that is only divisible by itself and 1.) The code should ask the user if...
Calculate your estimated energy needs using 25-35 calories per kg ideal body weight for your height...
Calculate your estimated energy needs using 25-35 calories per kg ideal body weight for your height (show work): Body Weight 250 Height 6ft 7in
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT