Answer to Question #249736 in Java | JSP | JSF for Nguu

Question #249736

Body Mass Index (BMI) is one of the criteria that is used to calculate whether one is fit or not basing on a person’s height (m) and weight (kg). The criterion is very simple; if one’s BMI is 25 or greater, it signifies overweight. A BMI less or equal to 18.5 indicates underweight. Lastly, a BMI greater than 30 shows obesity. You have been requested to create a program that that helps the Namibian Defence Forces’ (NDF) Captain to calculates the BMI of a person (BMI = height/weight2) and also determine whether the person has also completed running 10 km in the required time. Men should complete 10km in less than 60 minutes for them to be accepted. Women should do that under 80 minutes. Both males and females are accepted if their BMI is less than 25 and greater than 18.5. For 2018 intake, there are already 6 males selected and 1 female. The values for gender, mass and weight are enter by user inputs 


1
Expert's answer
2021-10-13T02:00:12-0400
import java.util.Scanner;


public class App {


	public static void main(String[] args) {
		Scanner keyBoard = new Scanner(System.in);
		int malesSelected = 6;
		int femalesSelected = 1;
		System.out.print("Enter gender: ");
		String gender = keyBoard.nextLine();
		System.out.print("Enter mass in kilograms: ");
		double weight = keyBoard.nextDouble();
		System.out.print("Enter height in metres: ");
		double height = keyBoard.nextDouble();
		System.out.print("Enter time for completing 10 km in minutes: ");
		double minutes = keyBoard.nextDouble();
		double BMI = weight / (height * height);
		// Men should complete 10km in less than 60 minutes for them to be accepted.
		/// Women should do that under 80 minutes.
		// Both males and females are accepted if their BMI is less than 25 and greater
		// than 18.5.
		if (gender.compareToIgnoreCase("male") == 0) {
			if (minutes < 60 && BMI >= 18.5 && BMI < 25) {
				malesSelected++;
				System.out.println("Candidate Selected! The number of male is now " + malesSelected);
			} else if (minutes < 60 && BMI >= 25 && BMI < 30) {
				System.out.println("Candidate Overweight. Recommend more training");
			} else {
				System.out.println("Candidate Obese. Reject!");
			}
		} else if (gender.compareToIgnoreCase("female") == 0) {
			if (minutes < 80 && BMI >= 18.5 && BMI < 25) {
				femalesSelected++;
				System.out.println("Candidate Selected! The number of females is now " + femalesSelected);
			} else if (minutes < 80 && BMI >= 25 && BMI < 30) {
				System.out.println("Candidate Overweight. Recommend more training");
			} else {
				System.out.println("Candidate Obese. Reject!");
			}
		} else {
			System.out.print("Invalid Gender");
		}


		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