Lab #2 (10 points)

Tuesday, January 31 (2-day). Prelab exercises ? complete these before you start
working at a computer: Convert the following formulas to Java arithmetic
expressions. ... Write a program that reads in the user's age in years and
calculates and displays the user's age in days, hours and seconds. You may
assume that today ...

Part of the document


Lab #2 (10 points) Name: _____________________________
Due: Monday, January 30 (4-day)
Tuesday, January 31 (2-day)

Prelab exercises - complete these before you start working at a computer:

1. Convert the following formulas to Java arithmetic expressions. Where
letters are used, assume they have been declared as variables or
constants:

[pic]


(a+b)2
(a-b)3


[pic]


2. Write a program that calculates a user's body mass index. The program
will use the following formula to calculate BMI:


BMI = weight in kilograms / (height in centimeters / 100)2

You will need to read in the following data:
. The user's weight in pounds (a whole number)
. The user's height in inches (a floating-point number)

Besides (and before) the BMI calculation, you will need to convert the
user's weight to kilograms, and the user's height to centimeters.
Note: there are 2.2 pounds in a kilogram and 2.54 centimeters in an
inch. Use named constants to represent these values.


You should display the user's BMI as a whole number (no decimal
places).


3. Write a program that reads in the user's age in years and calculates
and displays the user's age in days, hours and seconds. You may
assume that today is the user's birthday and that it is midnight.
There are 365.25 days in a year, 24 hours in a day, 60 minutes in an
hour and 60 seconds in a minute; these should be stored in named
constants.