Question

I am having problems with my java homework in class. Write a program that will interactively...

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.

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:-

Output:-

Code to copy:-

import java.io.*;

public class BMIcalculator

{

     public static void main(String args[]) throws IOException

     {

          int CONVERSION_FACTOR=703;

          double[] BMI=new double[5];

          String[] name=new String[5];

          int[] age=new int[5];

          int[] weight=new int[5];

          int[] height=new int[5];

          int sq;

          String strDouble;

          double sum1=0,sum2=0,sum3=0,sum4=0;

          double avg_age,avg_weight,avg_height,avg_BMI;

          BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

         

          for(int i=0;i<5;i++)

          {

              System.out.println("Enter your name > ");

              name[i]=br.readLine();

              System.out.println("Enter your age in years > ");

              age[i]=Integer.parseInt(br.readLine());

              System.out.println("Enter your weight in pounds > ");

              weight[i]=Integer.parseInt(br.readLine());

              System.out.println("Enter your height in inches > ");

              height[i]=Integer.parseInt(br.readLine());

              sq=height[i]*height[i];

              BMI[i]=(double)((double)weight[i]/sq)*CONVERSION_FACTOR;

              strDouble = String.format("%.2f", BMI[i]);

              System.out.println(name[i] + ", your BMI is: " + strDouble);             

          }

         

          for(int i=0;i<5;i++)

          {

              sum1=sum1+age[i];

              sum2=sum2+weight[i];

              sum3=sum3+height[i];

              sum4=sum4+BMI[i];

          }

         

          avg_age=sum1/5;

          avg_weight=sum2/5;

          avg_height=sum3/5;

          avg_BMI=sum4/5;

         

          System.out.println("Summary Statistics");

          strDouble = String.format("%.2f", avg_age);

          System.out.println("The average age of the participants is: " + strDouble);

          strDouble = String.format("%.2f", avg_weight);

          System.out.println("The average weight of the participants is: " + strDouble);

          strDouble = String.format("%.2f", avg_height);

          System.out.println("The average height of the participants is: " + strDouble);

          strDouble = String.format("%.2f", avg_BMI);

          System.out.println("The average BMI calculated by this study is: " + strDouble);

          System.out.println("That's all folks!");

     }

}

Add a comment
Know the answer?
Add Answer to:
I am having problems with my java homework in class. Write a program that will interactively...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program in java. You are tasked with writing an application that will keep track...

    Write a program in java. You are tasked with writing an application that will keep track of Insurance Policies. Create a Policy class called InsurancePolicies.java that will model an insurance policy for a single person. Use the following guidelines to create the Policy class: • An insurance policy has the following attributes: o Policy Number o Provider Name o Policyholder’s First Name o Policyholder’s Last Name o Policyholder’s Age o Policyholder’s Smoking Status (will be “smoker” or “non-smoker”) o Policyholder’s...

  • This is a java homework for my java class. Write a program to perform statistical analysis...

    This is a java homework for my java class. Write a program to perform statistical analysis of scores for a class of students.The class may have up to 40 students.There are five quizzes during the term. Each student is identified by a four-digit student ID number. The program is to print the student scores and calculate and print the statistics for each quiz. The output is in the same order as the input; no sorting is needed. The input is...

  • JAVA QUESTION 16 Write and submit the java source for the following class specification: The name...

    JAVA QUESTION 16 Write and submit the java source for the following class specification: The name of the class is Question_16 Class Question_16 has 3 instance variables: name of type String, age of type int and height of type double. Class Question_16 has the following methods: print - outputs the data values stored in the instance variables with the appropriate label setName - method to set the name setAge - method to set the age setHeight - method to set...

  • NOTE: The blue marker is blocking a name. I need to replace with my own. So...

    NOTE: The blue marker is blocking a name. I need to replace with my own. So just put "yourlastname" as a substitution! PART1-Requirement Create a project named SP2019_LAB2PAR1 Add the source file name Sharelnvestment yourLastName.java and display the source file name as the first comment line Provide the pseudo-code of the following application before writing the code Using java code to provide an application that calculates the money returned to an inverster after a year where the name, number of...

  • Hello, I am having trouble with a problem in my C language class. I am trying...

    Hello, I am having trouble with a problem in my C language class. I am trying to make a program with the following requirements: 1. Use #define to define MAX_SIZE1 as 20, and MAX_SIZE2 as 10 2. Use typedef to define the following struct type: struct {     char name[MAX_SIZE1];     int scores[MAX_SIZE2]; } 3. The program accepts from the command line an integer n (<= 30) as the number of students in the class. You may assume that the...

  • Java. Java is a new programming language I am learning, and so far I am a...

    Java. Java is a new programming language I am learning, and so far I am a bit troubled about it. Hopefully, I can explain it right. For my assignment, we have to create a class called Student with three private attributes of Name (String), Grade (int), and CName(String). In the driver class, I am suppose to have a total of 3 objects of type Student. Also, the user have to input the data. My problem is that I can get...

  • I am currently doing homework for my java class and i am getting an error in...

    I am currently doing homework for my java class and i am getting an error in my code. import java.util.Scanner; import java.util.Random; public class contact {       public static void main(String[] args) {        Random Rand = new Random();        Scanner sc = new Scanner(System.in);        System.out.println("welcome to the contact application");        System.out.println();               int die1;        int die2;        int Total;               String choice = "y";...

  • I'm having trouble with my Java Homework in which my professor wants us to solve the...

    I'm having trouble with my Java Homework in which my professor wants us to solve the 0-1 Knapsack problem with Dynamic Programming. The code below is what she provided and she requested that we not change any of her existing code but simply add to it. As you can see she gave us the stub file for the knapsack class and the Item class. You are a thief with a knapsack with a carrying capacity of knapsackCapacity pounds. You want...

  • Visual C# Homework 2 You are to write a program which will create a class called...

    Visual C# Homework 2 You are to write a program which will create a class called Student Each student has a name age height and weight. These variables should be declared as private. Create the correct constructors and functions. In the main, you will create 5 students. Input the data for the 5 students from a file which already has information in it. Name the file “Information.txt”. After setting up all the data, it is time to sort based on...

  • Write the definition of the class Tests such that an object of this class can store...

    Write the definition of the class Tests such that an object of this class can store a student's first name, last name, five test scores, average test score, and grade. (Use an array to store the test scores.) Add constructors and methods to manipulate data stored in an object. Among other things, your class must contain methods to calculate test averages, return test averages, calculate grades, return grades, and modify individual test scores. The method toString must return test data...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT