Question

The body mass index (BMI) is a measure of relative weight based on height and weight....

The body mass index (BMI) is a measure of relative weight based on height and weight.

The body fat percentage (BFP) of a human or other living being is the total mass of fat divided by total body mass, multiplied by 100; body fat includes essential body fat and storage body fat. Essential body fat is necessary to maintain life and reproductive functions.

Write a program that calculates and prints the BFP for multiple persons; the program allows user to enter values for the name, gender, age, BMI of each person,

The formula for BFP is:           

Child body fat percentage = 1.51 * BMI - 0.70*age – 3.6* gender +1.4

Adult body fat percentage = 1.20 * BMI +0.23 * age – 10.8 *gender – 5.4

where gender is 0 for females and 1 for males.

If the user is 15 years old or younger, he/she will be considered as Child in calculation.

If the user is older than 15, he/she will be considered as Adult in calculation.

Implement the following steps:

  1. Prompts user to enter the number of BFPs that need to be calculated (number of persons). (a int)
  2. Define and call a method to prompt user to enter name (a String). (10 points)
  3. Define and call a method to prompt user to enter gender (a int or String). (10 points)
  4. Define and call a method to prompt user to enter age (a int). (10 points)
  5. Define and call a method to prompt user to enter BMI (a double). (10 points)
  6. Define and call a method to calculate one BFP using the given formula and values (arithmetic expressions). (15 points)
  7. Print out name, age, gender, BMI, BFP of each person. (5 points)
  8. Save BFP values in a double array. (10 points)
  9. Define and call a method to calculate and print the average BFP value of the above double array.(20 points)
  10. Include the following methods in your application, and call/invoke those methods in the main method.

public static String getName( );

public static String getGender( ); or public int getGender ( );

public static int getAge( );

public static double getBMI ( );

public static double calculateBFP (int gender, int age, double bmi);

public static double calculateAverage (double[] bfpArray);

Sample output:

Please enter number of customers:

2

# 1 Customer:

Please enter your age:

21

Please enter your Gender (1 for Male, 0 for Female):

1

Please enter your BMI:

24.5

You are 21 years old

You are a Male adult

Your BMI is 24.5

Your BFP is 18.03%

# 2 Customer:

Please enter your age:

14

Please enter your Gender (1 for Male, 0 for Female):

0

Please enter your BMI:

18.5

You are 14 years old

You are a Female child

Your BMI is 18.5

Your BFP is 19.53%

The average BFP of all 2 customers is 18.78%.

Extra points (5 points):

1) Create a String array to store all the BFP categories

2) Print the percentage of person that are in category “Fitness”

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

// CalculateBFP.java

import java.text.DecimalFormat;
import java.util.Scanner;

public class CalculateBFP {
   /*
   * Creating an Scanner class object which is used to get the inputs entered
   * by the user
   */
   static Scanner sc = new Scanner(System.in);

   public static void main(String[] args) {
       // DecimalFormat class is used to format the output
       DecimalFormat df = new DecimalFormat(".00");
       String name;
       int gender, age;
       double bmi, BFP;
       int noOfCustomers;
       System.out.print("Please enter number of customers:");
       noOfCustomers = sc.nextInt();

       double BFPArray[] = new double[noOfCustomers];
       for (int i = 0; i < noOfCustomers; i++) {
           System.out.println("# " + (i + 1) + " Customer:");
           name = getName();
           gender = getGender();
           age = getAge();
           bmi = getBMI();
           BFP = calculateBFP(gender, age, bmi);
           BFPArray[i] = BFP;
           System.out.println("Your Name:" + name);

           System.out.println("You are " + age + " years old");
           if (age > 15) {
               if (gender == 1) {
                   System.out.println("You are a Male child");
               } else {
                   System.out.println("You are a Female child");
               }
           } else {
               if (gender == 1) {
                   System.out.println("You are a Male adult");
               } else {
                   System.out.println("You are a Female adult");
               }
           }

           System.out.println("Your BMI is " + bmi);
           System.out.println(" Your BFP is " + df.format(BFP) + "%");

       }
       double avg = 0, sum = 0;
       for (int i = 0; i < noOfCustomers; i++) {
           sum += BFPArray[i];
       }
       avg = sum / noOfCustomers;
       System.out.println("The average BFP of all " + noOfCustomers
               + " customers is " + df.format(avg) + "%");
   }

   public static String getName() {
       sc.nextLine();
       System.out.print("Enter Name :");
       return sc.nextLine();
   }

   public static int getGender() {
       System.out
               .print("Please enter your Gender (1 for Male, 0 for Female):");
       return sc.nextInt();
   }

   public static int getAge() {
       System.out.print("Please enter your age:");
       return sc.nextInt();
   }

   public static double getBMI() {
       System.out.print("Please enter your BMI:");
       return sc.nextDouble();
   }

   public static double calculateBFP(int gender, int age, double bmi) {
       double BFP = 0;
       if (age <= 15) {
           BFP = 1.51 * bmi - 0.70 * age - 3.6 * gender + 1.4;
       } else if (age > 15) {
           BFP = 1.20 * bmi + 0.23 * age - 10.8 * gender - 5.4;
       }
       return BFP;
   }
}

________________________

Output:

Please enter number of customers:2
# 1 Customer:
Enter Name :Williams
Please enter your Gender (1 for Male, 0 for Female):1
Please enter your age:21
Please enter your BMI:24.5
Your Name:Williams
You are 21 years old
You are a Male child
Your BMI is 24.5
Your BFP is 18.03%
# 2 Customer:
Enter Name :Bob
Please enter your Gender (1 for Male, 0 for Female):0
Please enter your age:14
Please enter your BMI:18.5
Your Name:Bob
You are 14 years old
You are a Female adult
Your BMI is 18.5
Your BFP is 19.53%
The average BFP of all 2 customers is 18.78%


_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
The body mass index (BMI) is a measure of relative weight based on height and weight....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • javafx 1. Implement a BMI (Body Mass Index) server that will accept height and weight from...

    javafx 1. Implement a BMI (Body Mass Index) server that will accept height and weight from the client, calculate the BMI and return a string with the BMI and a status (l.e. normal, over weight, etc.). Build a GUI using JavaFX. You are given a working BMI class that will do the BMI calculations, etc. A single BMI client connection is sufficient. 2. Implement a JavaFX BMI client that will allow the user to enter height (in inches), weight (in...

  • 1. Your Body Mass Index (BMI) is a measure of your weight relative to your height....

    1. Your Body Mass Index (BMI) is a measure of your weight relative to your height. The formula can be found here: http://www.whathealth.com/bmi/formula.html (use the Imperial U.S. Method). Write an algorithm in pseudocode to calculate and display a person's BMI accepting as input their height in feet and inches and their weight in pounds. The output of your algorithm should be as follows: a. BMI b. A statement of whether the result is underweight, normal, overweight or obese.

  • Interested in obesity, investigators measured body mass index (BMI), a measure of weight relative to height,...

    Interested in obesity, investigators measured body mass index (BMI), a measure of weight relative to height, for both the girls and their mothers. People with high BMI are overweight. The data for 15 of the random subjects and their mothers is below: Mother BMI 23 24 21 18 26 29 25 20 24 23 22 27 28 23 21 Daughter BMI 22 24 20 21 24 27 22 21 22 21 21 25 24 20 18 The correlation between the...

  • I need to create a code for this prompt: In this project we will build a...

    I need to create a code for this prompt: In this project we will build a generic UserInput class for getting keyboard input from the user. Implementation: The class UserInput is a 'Methods only' class, and all the methods should be declared static. Look at the TestScanner.java program at the bottom of this page that inputs a string, int and double. It shows you how to use Scanner class to get input from the keyboard. Write FOUR simple methods, one...

  • Write a program called RentalRate.java which reads in a date of birth, today’s date and a...

    Write a program called RentalRate.java which reads in a date of birth, today’s date and a male/female designation from the user, and will then determine the basic daily and weekly rates for rental of an economy class car. Rental rate classes are: Best rate (male drivers, age 33–65 and female drivers, age 30-62)--$40.00per day, $200.00 per week Risk rate 1 (female drivers, age 25–29)–Best rate plus $10.00 per day or best rate plus $55.00 per week. Risk rate 2 (male...

  • Please show screenshot outputs and fully functional code for the Java programs. Question 1: Write a...

    Please show screenshot outputs and fully functional code for the Java programs. Question 1: Write a method that computes and returns the area of a square using the following header: public static double area ( double side) Write a main method that prompts the user to enter the side of a square, calls the area method then displays the area. Question 1a: Write a method that converts miles to kilometers using the following header: public static double convertToKilometers (double miles)...

  • This is for a java program public class Calculation {    public static void main(String[] args)...

    This is for a java program public class Calculation {    public static void main(String[] args) { int num; // the number to calculate the sum of squares double x; // the variable of height double v; // the variable of velocity double t; // the variable of time System.out.println("**************************"); System.out.println(" Task 1: Sum of Squares"); System.out.println("**************************"); //Step 1: Create a Scanner object    //Task 1. Write your code here //Print the prompt and ask the user to enter an...

  • Having trouble with the do while/while loop and the switch statement. I got some of the...

    Having trouble with the do while/while loop and the switch statement. I got some of the switch statement but cant get the program to repeat itself like it should.What i have so far for my code is below. Any help is appreciated... i am not sure what I am doing wrong or what i am missing. I am completely lost on the while loop and where and how to use it in this scenario. import java.util.Scanner; public class sampleforchegg {...

  • In Java Body mass index is a measure of whether someone's weight is appropriate for their...

    In Java Body mass index is a measure of whether someone's weight is appropriate for their height. A body- mass-index value between 19 and 25 is considered to be in the normal range. Here's the formula for calculating body mass index: BMI- (704 x weight in pounds) / height in inches*2 a) Implement a program that prompts the user for height and weight values and displays the associated body mass index. Perform input validation by making sure that the user...

  • You will need to think about problem solving. There are several multi-step activities. Design, compile and...

    You will need to think about problem solving. There are several multi-step activities. Design, compile and run a single Java program, StringEx.java, to accomplish all of the following tasks. Add one part at a time and test before trying the next one. The program can just include a main method, or it is neater to split things into separate methods (all static void, with names like showLength, sentenceType, lastFirst1, lastFirst), and have main call all the ones you have written...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT