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...
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...
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...
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 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...
Language is Java Design and write a Java console program to estimate the number of syllables...
Language is Java Design and write a Java console program to estimate the number of syllables in an English word. Assume that the number of syllables is determined by vowels as follows. Each sequence of adjacent vowels (a, e, i, o, u, or y), except for a terminal e, is a syllable. However, the minimum number of syllables in an English word is one. The program should prompt for a word and respond with the estimated number of syllables in...
Write a Java program that takes in a string and a number and prints back the...
Write a Java program that takes in a string and a number and prints back the string from the number repeatedly until the first character... for example Pasadena and 4 will print PasaPasPaP. Ask the user for the string and a number Print back the string from the number repeatedly until the first character For both programs please utilize: methods arrays loops Turn in screenshots
In Java: Write a program that will count the number of characters, words, and lines in...
In Java: Write a program that will count the number of characters, words, and lines in a file. Words are separated by whitespace characters. The file name should be passed as a command-line argument, as shown below. c:\exercise>java Exercise12_13 Loan.java File loan.java has 1919 characters 210 words 71 lines c:\exercise> Class Name: Exercise12_13
java 2. Write a program to implement heapsort. Sort the following elements using your program. 6,...
java 2. Write a program to implement heapsort. Sort the following elements using your program. 6, 12, 34, 29, 28, 11, 23, 7, 0, 33, 30, 45
JAVA Write a java program that will sum all positive number. Prompt the user to enter...
JAVA Write a java program that will sum all positive number. Prompt the user to enter numbers and add all positive numbers. The program will not add negative numbers and the program will stop when you enter ‘0’.   Enter a number> 25 Enter a number> 9 Enter a number> 5 Enter a number> -3 Enter a number> 0 Sum = 39
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT