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 = weight/height2) 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.
Sample Run 1
Welcome to NDF Captain's Selection Aid.
***************************************
Gender: male
Mass in kilograms: 82
Height in metres: 1.82
Time for completing 10 km in minutes: 45
Output1: Candidate Selected! The number of males is now 7.
SOLUTION CODE FOR ABOVE QUESTION
package com.company;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Welcome to NDF Captain's Selection Aid.");
System.out.println("**************************************");
System.out.print("Enter Gender: ");
String gender = sc.next();
System.out.print("\nEnter Mass in kilograms: ");
float mass = sc.nextFloat();
System.out.print("\nEnter Height in metres: ");
float height = sc.nextFloat();
System.out.print("\nEnter Time for completing 10 km in minutes: ");
int time = sc.nextInt();
//Declare and initialize the number of males accepted already
int number_of_males = 6;
//Declare and initialize the number of males accepted already
int number_of_females = 1;
//Now lets calculate the BMI based on the given formular BMI = (Weight*height^2)
float BMI = (mass/(height*height));
//Now lets check the condition to decide whether the person will be accepted
if(gender.equals("male"))
{
if(BMI<25 && BMI > 18.5 && time < 60)
{
//Increment the number of males because the candidate is accepted
number_of_males = number_of_males + 1;
System.out.println("\nCandidate Selected! The number of males is now "+number_of_males+".");
}
else
{
System.out.println("The male candidate is not accepted");
}
}
else if(gender.equals("female"))
{
if(BMI<25 && BMI > 18.5 && time < 80)
{
//Increment the number of females because the candidate is accepted
number_of_females = number_of_females + 1;
System.out.println("Candidate Selected! The number of females is now "+number_of_females+".");
}
else
{
System.out.println("The female candidate is not accepted");
}
}
else
{
System.out.println("Invalid gender, you shuld enter either 'male' or 'female'.");
}
}
}
Comments
Leave a comment