Answer to Question #291272 in Java | JSP | JSF for Chris

Question #291272

One way to determine how healthy a person is by measuring the body fat of the person. The formulas to determine the body fat for female and male are as follows: Body fat formula for women: A1 ¼ (Body weight  0.732) + 8.987 A2 ¼ Wrist measurement (at fullest point) / 3.140 A3 ¼ Waist measurement (at navel)  0.157 A4 ¼ Hip measurement (at fullest point)  0.249 A5 ¼ Forearm measurement (at fullest point)  0.434 B ¼ A1 + A2 – A3 – A4 + A5

Body fat ¼ body weight – B Body fat percentage ¼ body fat  100 / body weight Body fat formula for men: A1 ¼ (Body weight  1.082) + 94.42 A2 ¼ Waist measurement  4.15 B ¼ A1 – A2 Body fat ¼ body weight – B Body fat percentage ¼ body fat  100 / body weight Write a program to calculate the body fat of a person.


1
Expert's answer
2022-01-27T07:46:30-0500


import java.util.Scanner;


public class App {


	/**
	 * The start point of the program
	 * 
	 * @param args
	 * 
	 */
	public static void main(String[] args) {
		Scanner keyBoard = new Scanner(System.in);
		char gender;
		double bodyweight, wrist, waist, hip, forearm, B, bodyfat, bfPercentage, A1, A2, A3, A4, A5;


		System.out.print("Input gender (m/f): ");
		gender = keyBoard.nextLine().charAt(0);


		switch (gender) {
		case 'F':
		case 'f':
			System.out.print("Enter body weight: ");
			bodyweight = keyBoard.nextDouble();
			System.out.print("Enter wrist measurement (at fullest point): ");
			wrist = keyBoard.nextDouble();
			System.out.print("Enter waist measurement (at navel): ");
			waist = keyBoard.nextDouble();
			System.out.print("Enter hip measurement (at fullest point): ");
			hip = keyBoard.nextDouble();
			System.out.print("Enter forearm measurement (at fullest point): ");
			forearm = keyBoard.nextDouble();
			A1 = (bodyweight * 0.723) + 8.987;
			A2 = (wrist) / 3.140;
			A3 = (waist) * 0.157;
			A4 = (hip) * 0.249;
			A5 = (forearm) * 0.434;
			B = A1 + A2 - A3 - A4 + A5;
			bodyfat = bodyweight - B;
			bfPercentage = (bodyfat * 100) / bodyweight;


			System.out.println("Your body fat is: " + bodyfat);
			System.out.println("Body fat percentage: " + bfPercentage + "%");
			break;
		case 'M':
		case 'm':
			System.out.print("Enter body weight: ");
			bodyweight = keyBoard.nextDouble();
			System.out.print("Enter wrist measurement (at fullest point): ");
			wrist = keyBoard.nextDouble();
			A1 = (bodyweight * 1.082) + 94.42;
			A2 = wrist * 4.14;
			B = A1 - A2;
			bodyfat = bodyweight - B;
			bfPercentage = (bodyfat * 100) / bodyweight;
			System.out.println("Your body fat is: " + bodyfat);
			System.out.println("Body fat percentage: " + bfPercentage + "%");
			break;
		default:
			System.out.println("Invalid gender.");
			break;
		}


		keyBoard.close();
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS