Menu

Use Following Templates Write Test Java Program Calculate Body Mass Index Bmi Given Weigh Q43870190

Use the following templates to write and test a Java programto:

a. Calculate the Body Mass Index (BMI) given a weight in poundsand a

height in inches. The BMI is defined as the body weight inkilograms

divided by the square of the height in meters. Convert poundsto

kilograms by dividing pounds by 2.2; convert inches to metersby

multiplying by 0.0254. Use the Scanner class to get the userinput

from the keyboard, and display as output the weight inkilograms, the

height in meters, and the BMI in kg/m

2

. Use the static method

Math.pow( ) to find the square of the height.

// template for assignment 1a

import java.util.*;

public class BMI {

// pounds to kilograms

final static double CONVWGT = 2.2

// inches to meters

final static double CONVHGT = 0.0254;

public static void main (String [] args) {

double bmi;

Scanner input = new Scanner(System.in);

// put the problem solution here

System.out.printf(” BMI: %.2fn”, bmi);

return;

}

}

b. Calculate the area of circle given its radius. Use Math.PIfor pi,

Math.pow( ) to square the radius, and the followingtemplate.

// template for assignment 1b

import javax.swing.*;

public class CircleArea {

public static void main (String [] args) {

double radius;

double area;

String input =

JOptionPane.showInputDialog(“Enter the radius”);

radius = Double.parseDouble(input);

// put the problem solution here

JOptionPane.showMessageDialog(null,

String.format(“Area: %.2f”, area));

return;

}

}

c. Use the JOptionPane method above to prompt the user for thename of

a city and then output: 1) the number of characters in the cityname;

2) the name of the city in all uppercase letters; and, 3) thefirst

character in the name of the city. See the Java reference pagefor the

String class.

Expert Answer


Answer to Use the following templates to write and test a Java program to: a. Calculate the Body Mass Index (BMI) given a weight i…

OR