I am having problems with my java homework in class. Write a program that will i
ID: 639459 • Letter: I
Question
I am having problems with my java homework in class.
Write a program that will interactively read the name, age, weight in pounds, and height in inches for five people and output the BMI for each one. At the end of the program, it should output the average age, average height and average weight of the five participants.
IT HAS TO INCLUDE:
Declare and use a program constant of data type int named CONVERSION_FACTOR to represent the value 703.
Use the int data type for variables age, weight and height.
Print the calculated BMI and all averages using two decimal places.
Use the name BMIcalculator followed by your three initials for the class name.
but it can not include loops sadly because we have not learned that yet.
I have no idea where to start. This is the first time I have tried working with java and my teacher just plopped me into this.
Explanation / Answer
/*
* The java program that reads the five peoples
* name,age,weight,height and display the BMI
* of the each person. After reading the five
* peoples data, then finds the average values of
* ages,weight and height values and display upto
* two decimal places.
* */
//BMIcalculator_ABC.java
import java.util.Scanner;
public class BMIcalculator_ABC
{
public static void main(String[] args)
{
Scanner keyboard=new Scanner(System.in);
final int CONVERSION_FACTOR=703;
int sumAge=0;
int sumWt=0;
int sumHt=0;
double BMI;
//reading the name,age ,weight and height of the person
System.out.println("Name: ");
String name=keyboard.nextLine();
System.out.println("Age: ");
int age=keyboard.nextInt();
sumAge+=age;
System.out.println("Weight: ");
int pounds=keyboard.nextInt();
sumWt+=pounds;
System.out.println("Height:");
int height=keyboard.nextInt();
sumHt+=height;
//Read the end of line character
keyboard.nextLine();
//Calculate the bmi
BMI = (double)pounds* CONVERSION_FACTOR /((height *height ));
//print the name and bmi value
System.out.println("Name :"+name);
System.out.println("BMI :"+BMI);
//reading the name,age ,weight and height of the person
System.out.println("Name: ");
name=keyboard.nextLine();
System.out.println("Age: ");
age=keyboard.nextInt();
sumAge+=age;
System.out.println("Weight: ");
pounds=keyboard.nextInt();
sumWt+=pounds;
System.out.println("Height:");
height=keyboard.nextInt();
sumHt+=height;
//Read the end of line character
keyboard.nextLine();
BMI = (double)pounds* CONVERSION_FACTOR /((height *height ));
System.out.println("Name :"+name);
System.out.println("BMI :"+BMI);
//reading the name,age ,weight and height of the person
System.out.println("Name: ");
name=keyboard.nextLine();
System.out.println("Age: ");
age=keyboard.nextInt();
sumAge+=age;
System.out.println("Weight: ");
pounds=keyboard.nextInt();
sumWt+=pounds;
System.out.println("Height:");
height=keyboard.nextInt();
sumHt+=height;
//Read the end of line character
keyboard.nextLine();
BMI = (double)pounds* CONVERSION_FACTOR /((height *height ));
System.out.println("Name :"+name);
System.out.println("BMI :"+BMI);
//reading the name,age ,weight and height of the person
System.out.println("Name: ");
name=keyboard.nextLine();
System.out.println("Age: ");
age=keyboard.nextInt();
sumAge+=age;
System.out.println("Weight: ");
pounds=keyboard.nextInt();
sumWt+=pounds;
System.out.println("Height:");
height=keyboard.nextInt();
sumHt+=height;
//Read the end of line character
keyboard.nextLine();
BMI = (double)pounds* CONVERSION_FACTOR /((height *height ));
System.out.println("Name :"+name);
System.out.println("BMI :"+BMI);
//reading the name,age ,weight and height of the person
System.out.println("Name: ");
name=keyboard.nextLine();
System.out.println("Age: ");
age=keyboard.nextInt();
sumAge+=age;
System.out.println("Weight: ");
pounds=keyboard.nextInt();
sumWt+=pounds;
System.out.println("Height:");
height=keyboard.nextInt();
sumHt+=height;
//Read the end of line character
keyboard.nextLine();
BMI = (double)pounds* CONVERSION_FACTOR /((height *height ));
System.out.println("Name :"+name);
System.out.println("BMI :"+BMI);
//Display the average of age , weight and height for two decimal places
System.out.printf("Average of Age %.2f : ",sumAge/5.0);
System.out.printf("Average of Weight %.2f ",sumWt/5.0);
System.out.printf("Average of Height %.2f ",sumHt/5.0);
}
}
----------------------------------------------------------------------------------------
Sample output:
Name:
Rhonda
Age:
45
Weight:
160
Height:
66
Name :Rhonda
BMI :25.821854912764003
Name:
Byrne
Age:
56
Weight:
160
Height:
55
Name :Byrne
BMI :37.183471074380165
Name:
JOhnson
Age:
45
Weight:
180
Height:
55
Name :JOhnson
BMI :41.83140495867769
Name:
Natal
Age:
63
Weight:
180
Height:
80
Name :Natal
BMI :19.771875
Name:
Sundry
Age:
71
Weight:
180
Height:
70
Name :Sundry
BMI :25.824489795918367
Average of Age 56.00
Average of Weight 172.00
Average of Height 65.20
Hope this helps you
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.