Cal State L.A. logo and University Seal - Link back to main page

CIS 283 - Programing assignment07

Email: jperezc at calstatela.edu

 

This is similar to programming challenge 3, page 188 of our book. (in the international version it is page 212)

For this assignment you are going to write the code for the following class:

    • BodyMass

Here are the specifications of class BodyMass:

You are free to give to BodyMass any instance variables you may think it needs. They can be public or private, and have any name you choose.

Methods of class BodyMass:

setWeight
returns: nothing
arguments: a double
what it does: it somehow stores the value of its argument in the class BodyMass. We will call this value weight in the rest of the specification.

setHeight
returns: nothing
arguments: a double
what it does: it somehow stores the value of its argument in the class BodyMass. We will call this value height in the rest of the specification.

stats
returns: nothing
arguments: none
what it does: it uses the values of weight and height we mentioned earlier.

Example1: if weight is 220 pounds and height is 73 inches, then stats prints the following:

      weight: 220.0
      height: 73.0
      bmi: 29.022330643647965
      bmi indicates person is: overweight         

bmi represents the body mass index, and it is computed by the following formula;

BMI = Weight x 703/Height2

If the BMI is between 18.5 and 25 the weight of the person is considered "optimal"

if the BMI is less than 18,5, the person is underweight

if the BMI is greater than 25, the person is overweight.

 

Example2: if weight is 180 pounds and height is 74 inches, then stats prints the following:

     weight: 180.0
height: 74.0
bmi: 23.10810810810811
bmi indicates person is: optimal

Example3: if weight is 130 pounds and height is 74 inches, then stats prints the following:

weight: 130.0
height: 74.0
bmi: 16.68918918918919
bmi indicates person is: underweight


Read the instructions carefully:

    • create a folder called Assignment07
    • create a file called BodyMass.java and save it in folder Assignment07
    • download file Test07.class.zip (Test07_java6.class.zip) and put it in your folder Assignment07
    • compile all java files in folder Assignment07
    • type the following command in the DOS prompt window:
    • java Test07

    • tests will be run on your code and appropriate messages will be printed out showing which tests passed and which failed. At the end the program will tell you which option to choose in the moodle quizz corresponding to programming exercise 07
    • You must use Test07.print or Test07.println instead of System.out.print and System.out.println. Use Test07_java6.print and Test07_java6.println if you are using java6.

     

    You could use the following main method in order to test your program. You don't need to use it, you don't need to show it to me or submit it. Use it if you want to test your code:

    public static void main(String[] args){
    BodyMass bm = new BodyMass();
    bm.setWeight(220.0);
    bm.setHeight(73.0);
    bm.stats();
    }

    This main method could be a method of your BodyMass class. In that class you could test your class by typing:

    java BodyMass

     

Email: jperezc at calstatela.edu