Java Reference
In-Depth Information
BodyMass.java
10/20/2007
1
/*
2
Chapter 3: The Body Mass Index Calculator
3
Programmer: J. Starks
4
Date:
October 20, 2007
2
5
Filename:
BodyMass.java
6
Purpose:
This project calculates the body mass index based
7
on a person's height and weight.
8
*/
9
10
import
java.io.*;
11
12
public class
BodyMass
13
{
14
3
public static void
main
(
String
[]
args
)
throws
IOException
15
{
4
16
// declare and construct variables
17
String
height, weight;
18
int
inches, pounds;
1
19
double
kilograms, meters, index;
5
20
BufferedReader
dataIn=
new
BufferedReader
(
new
InputStreamReader
(
System
.in
))
;
21
22
// print prompts and get input
23
System
.out.println
(
"\tTHE SUN FITNESS CENTER BODY MASS INDEX CALCULATOR"
)
;
24
System
.out.println
()
;
25
System
.out.print
(
"\t\tEnter you
r height t
o the nearest inch: "
)
;
6
26
height = dataIn.readLine
()
;
27
inches =
Integer
.parseInt
(
height
)
;
28
System
.out.print
(
"\t\tEnter your weight to the nearest pound: "
)
;
29
weight = dataIn.readLine
()
;
7
30
pounds =
Integer
.parseInt
(
weight
)
;
31
32
// calculations
8
33
meters = inches / 39.36;
34
kilograms = pounds / 2.2;
35
index = kilograms /
Math
.pow
(
meters,2
)
;
36
37
// output
38
System
.out.println
()
;
39
System
.out.println
(
"\tYOUR BODY MASS INDEX IS "
+
Math
.round
(
index
)
+
"."
)
;
10
40
System
.out.println
()
;
41
}
42
}
9
FIGURE 3-52
1 . ______________________________
6 . ______________________________
2 . ______________________________
7 . ______________________________
3 . ______________________________
8 . ______________________________
4 . ______________________________
9 . ______________________________
5 . ______________________________
1 0 . ______________________________
Search WWH ::
Custom Search